fix: organization recommend api
This commit is contained in:
parent
81ab0b01c0
commit
8698829678
|
@ -69,8 +69,7 @@ class Organizations::OrganizationsController < Organizations::BaseController
|
||||||
def recommend
|
def recommend
|
||||||
recommend = %W(xuos Huawei_Technology openatom_foundation pkecosystem TensorLayer)
|
recommend = %W(xuos Huawei_Technology openatom_foundation pkecosystem TensorLayer)
|
||||||
|
|
||||||
@organizations = Organization.with_visibility(%w(common))
|
@organizations = Organization.includes(:organization_extension).where(organization_extensions: {recommend: true}).to_a.each_slice(group_size).to_a
|
||||||
.where(login: recommend).select(:id, :login, :firstname, :lastname, :nickname)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
@ -81,6 +80,10 @@ class Organizations::OrganizationsController < Organizations::BaseController
|
||||||
:max_repo_creation, :nickname)
|
:max_repo_creation, :nickname)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def group_size
|
||||||
|
params.fetch(:group_size, 4)
|
||||||
|
end
|
||||||
|
|
||||||
def password
|
def password
|
||||||
params.fetch(:password, "")
|
params.fetch(:password, "")
|
||||||
end
|
end
|
||||||
|
|
|
@ -76,7 +76,7 @@ class Organization < Owner
|
||||||
validates_uniqueness_of :login, :if => Proc.new { |user| user.login_changed? && user.login.present? }, case_sensitive: false
|
validates_uniqueness_of :login, :if => Proc.new { |user| user.login_changed? && user.login.present? }, case_sensitive: false
|
||||||
validates :login, format: { with: NAME_REGEX, multiline: true, message: "只能含有数字、字母、下划线且不能以下划线开头和结尾" }
|
validates :login, format: { with: NAME_REGEX, multiline: true, message: "只能含有数字、字母、下划线且不能以下划线开头和结尾" }
|
||||||
|
|
||||||
delegate :description, :website, :location, :repo_admin_change_team_access,
|
delegate :description, :website, :location, :repo_admin_change_team_access, :recommend,
|
||||||
:visibility, :max_repo_creation, :num_projects, :num_users, :num_teams, to: :organization_extension, allow_nil: true
|
:visibility, :max_repo_creation, :num_projects, :num_users, :num_teams, to: :organization_extension, allow_nil: true
|
||||||
|
|
||||||
scope :with_visibility, ->(visibility) { joins(:organization_extension).where(organization_extensions: {visibility: visibility}) if visibility.present? }
|
scope :with_visibility, ->(visibility) { joins(:organization_extension).where(organization_extensions: {visibility: visibility}) if visibility.present? }
|
||||||
|
|
|
@ -15,6 +15,7 @@
|
||||||
# num_projects :integer default("0")
|
# num_projects :integer default("0")
|
||||||
# num_users :integer default("0")
|
# num_users :integer default("0")
|
||||||
# num_teams :integer default("0")
|
# num_teams :integer default("0")
|
||||||
|
# recommend :boolean default("0")
|
||||||
#
|
#
|
||||||
# Indexes
|
# Indexes
|
||||||
#
|
#
|
||||||
|
@ -30,6 +31,8 @@ class OrganizationExtension < ApplicationRecord
|
||||||
|
|
||||||
enum visibility: {common: 0, limited: 1, privacy: 2}
|
enum visibility: {common: 0, limited: 1, privacy: 2}
|
||||||
|
|
||||||
|
before_save :set_recommend
|
||||||
|
|
||||||
def self.build(organization_id, description, website, location, repo_admin_change_team_access, visibility, max_repo_creation)
|
def self.build(organization_id, description, website, location, repo_admin_change_team_access, visibility, max_repo_creation)
|
||||||
self.create!(organization_id: organization_id,
|
self.create!(organization_id: organization_id,
|
||||||
description: description,
|
description: description,
|
||||||
|
@ -39,4 +42,9 @@ class OrganizationExtension < ApplicationRecord
|
||||||
visibility: visibility,
|
visibility: visibility,
|
||||||
max_repo_creation: max_repo_creation)
|
max_repo_creation: max_repo_creation)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
def set_recommend
|
||||||
|
self.recommend = false unless self.common?
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,6 +1,12 @@
|
||||||
json.organizations @organizations do |organization|
|
json.organizations do
|
||||||
json.id organization.id
|
|
||||||
json.name organization.login
|
json.array! @organizations.each do |group|
|
||||||
json.nickname organization.nickname.blank? ? organization.name : organization.nickname
|
json.array! group.each do |organization|
|
||||||
json.avatar_url url_to_avatar(organization)
|
json.id organization.id
|
||||||
|
json.name organization.login
|
||||||
|
json.nickname organization.real_name
|
||||||
|
json.avatar_url url_to_avatar(organization)
|
||||||
|
json.website organization.website
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
|
@ -0,0 +1,5 @@
|
||||||
|
class AddRecommendToOrganizationExtensions < ActiveRecord::Migration[5.2]
|
||||||
|
def change
|
||||||
|
add_column :organization_extensions, :recommend, :boolean, default: false
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in New Issue