parent
f094fe1799
commit
3f73484596
|
@ -27,4 +27,8 @@ class Organizations::BaseController < ApplicationController
|
||||||
def user_mark
|
def user_mark
|
||||||
params[:username] || params[:id]
|
params[:username] || params[:id]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def project_mark
|
||||||
|
params[:repo_name] || params[:id]
|
||||||
|
end
|
||||||
end
|
end
|
|
@ -12,7 +12,8 @@ class Organizations::OrganizationsController < Organizations::BaseController
|
||||||
else
|
else
|
||||||
@organizations = Organization.with_visibility("common")
|
@organizations = Organization.with_visibility("common")
|
||||||
end
|
end
|
||||||
@organizations = @organizations.includes(:organization_extension).order(id: :asc)
|
@organizations = @organizations.ransack(login_cont: params[:search]).result if params[:search].present?
|
||||||
|
@organizations = @organizations.includes(:organization_extension).order("organization_extensions.#{sort_by} #{sort_direction}")
|
||||||
@organizations = kaminari_paginate(@organizations)
|
@organizations = kaminari_paginate(@organizations)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -82,4 +83,12 @@ class Organizations::OrganizationsController < Organizations::BaseController
|
||||||
tip_exception("没有查看组织的权限") if org_limited_condition || org_privacy_condition
|
tip_exception("没有查看组织的权限") if org_limited_condition || org_privacy_condition
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def sort_by
|
||||||
|
params.fetch(:sort_by, "created_at")
|
||||||
|
end
|
||||||
|
|
||||||
|
def sort_direction
|
||||||
|
params.fetch(:sort_direction, "desc")
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
|
@ -11,6 +11,7 @@ class Organizations::TeamProjectsController < Organizations::BaseController
|
||||||
end
|
end
|
||||||
|
|
||||||
def create
|
def create
|
||||||
|
tip_exception("该组织团队项目包括组织所有项目,不允许更改") if @team.includes_all_project
|
||||||
ActiveRecord::Base.transaction do
|
ActiveRecord::Base.transaction do
|
||||||
@team_project = TeamProject.build(@organization.id, @team.id, @operate_project.id)
|
@team_project = TeamProject.build(@organization.id, @team.id, @operate_project.id)
|
||||||
Gitea::Organization::TeamProject::CreateService.call(@organization.gitea_token, @team.gtid, @organization.login, @operate_project.identifier)
|
Gitea::Organization::TeamProject::CreateService.call(@organization.gitea_token, @team.gtid, @organization.login, @operate_project.identifier)
|
||||||
|
@ -21,8 +22,9 @@ class Organizations::TeamProjectsController < Organizations::BaseController
|
||||||
end
|
end
|
||||||
|
|
||||||
def destroy
|
def destroy
|
||||||
|
tip_exception("该组织团队项目包括组织所有项目,不允许更改") if @team.includes_all_project
|
||||||
ActiveRecord::Base.transaction do
|
ActiveRecord::Base.transaction do
|
||||||
@team_projects.destroy!
|
@team_project.destroy!
|
||||||
Gitea::Organization::TeamProject::DeleteService.call(@organization.gitea_token, @team.gtid, @organization.login, @operate_project.identifier)
|
Gitea::Organization::TeamProject::DeleteService.call(@organization.gitea_token, @team.gtid, @organization.login, @operate_project.identifier)
|
||||||
render_ok
|
render_ok
|
||||||
end
|
end
|
||||||
|
@ -45,7 +47,7 @@ class Organizations::TeamProjectsController < Organizations::BaseController
|
||||||
end
|
end
|
||||||
|
|
||||||
def load_operate_project
|
def load_operate_project
|
||||||
@operate_project = Project.find_by(name: params[:id]) || Project.find_by(identifier: params[:id])
|
@operate_project = Project.find_by(id: project_mark) || Project.find_by(identifier: project_mark)
|
||||||
tip_exception("项目不存在") if @operate_project.nil?
|
tip_exception("项目不存在") if @operate_project.nil?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -9,6 +9,17 @@ class Users::OrganizationsController < Users::BaseController
|
||||||
@organizations = observed_user.organizations.with_visibility("common")
|
@organizations = observed_user.organizations.with_visibility("common")
|
||||||
end
|
end
|
||||||
|
|
||||||
@organizations = @organizations.includes(:organization_extension).order(id: :asc)
|
@organizations = @organizations.ransack(login_cont: params[:search]).result if params[:search].present?
|
||||||
|
@organizations = @organizations.includes(:organization_extension).order("organization_extensions.#{sort_by} #{sort_direction}")
|
||||||
|
@organizations = kaminari_paginate(@organizations)
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
def sort_by
|
||||||
|
params.fetch(:sort_by, "created_at")
|
||||||
|
end
|
||||||
|
|
||||||
|
def sort_direction
|
||||||
|
params.fetch(:sort_direction, "desc")
|
||||||
end
|
end
|
||||||
end
|
end
|
|
@ -1,13 +1,13 @@
|
||||||
class Projects::CreateForm < BaseForm
|
class Projects::CreateForm < BaseForm
|
||||||
REPOSITORY_NAME_REGEX = /^(?!_)(?!.*?_$)[a-zA-Z0-9_-]+$/ #只含有数字、字母、下划线不能以下划线开头和结尾
|
REPOSITORY_NAME_REGEX = /^(?!_)(?!.*?_$)[a-zA-Z0-9_-]+$/ #只含有数字、字母、下划线不能以下划线开头和结尾
|
||||||
attr_accessor :user_id, :name, :description, :repository_name, :project_category_id,
|
attr_accessor :user_id, :name, :description, :repository_name, :project_category_id,
|
||||||
:project_language_id, :ignore_id, :license_id, :private
|
:project_language_id, :ignore_id, :license_id, :private, :owner
|
||||||
|
|
||||||
validates :user_id, :name, :description,:repository_name,
|
validates :user_id, :name, :description,:repository_name,
|
||||||
:project_category_id, :project_language_id, presence: true
|
:project_category_id, :project_language_id, presence: true
|
||||||
validates :repository_name, format: { with: REPOSITORY_NAME_REGEX, multiline: true, message: "只能含有数字、字母、下划线且不能以下划线开头和结尾" }
|
validates :repository_name, format: { with: REPOSITORY_NAME_REGEX, multiline: true, message: "只能含有数字、字母、下划线且不能以下划线开头和结尾" }
|
||||||
|
|
||||||
validate :check_ignore, :check_license, :check_owner
|
validate :check_ignore, :check_license, :check_owner, :check_max_repo_creation
|
||||||
validate do
|
validate do
|
||||||
check_project_category(project_category_id)
|
check_project_category(project_category_id)
|
||||||
check_project_language(project_language_id)
|
check_project_language(project_language_id)
|
||||||
|
@ -22,6 +22,13 @@ class Projects::CreateForm < BaseForm
|
||||||
end
|
end
|
||||||
|
|
||||||
def check_owner
|
def check_owner
|
||||||
raise "user_id值无效." if user_id && Owner.find_by(id: user_id).blank?
|
@owner = Owner.find_by(id: user_id)
|
||||||
|
raise "user_id值无效." if user_id && owner.blank?
|
||||||
|
end
|
||||||
|
|
||||||
|
def check_max_repo_creation
|
||||||
|
return unless owner.is_a?(Organization)
|
||||||
|
return if owner.max_repo_creation <= -1
|
||||||
|
raise "已超过组织设置最大仓库数" if owner.max_repo_creation == owner.num_projects
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -69,7 +69,8 @@ class Organization < Owner
|
||||||
validates :login, presence: true
|
validates :login, presence: true
|
||||||
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
|
||||||
|
|
||||||
delegate :description, :website, :location, :repo_admin_change_team_access, :visibility, :max_repo_creation, to: :organization_extension, allow_nil: true
|
delegate :description, :website, :location, :repo_admin_change_team_access,
|
||||||
|
:visibility, :max_repo_creation, :num_projects, :num_users, 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? }
|
||||||
|
|
||||||
|
|
|
@ -12,6 +12,8 @@
|
||||||
# max_repo_creation :integer default("-1")
|
# max_repo_creation :integer default("-1")
|
||||||
# created_at :datetime not null
|
# created_at :datetime not null
|
||||||
# updated_at :datetime not null
|
# updated_at :datetime not null
|
||||||
|
# num_projects :integer default("0")
|
||||||
|
# num_users :integer default("0")
|
||||||
#
|
#
|
||||||
# Indexes
|
# Indexes
|
||||||
#
|
#
|
||||||
|
@ -21,6 +23,8 @@
|
||||||
class OrganizationExtension < ApplicationRecord
|
class OrganizationExtension < ApplicationRecord
|
||||||
|
|
||||||
belongs_to :organization
|
belongs_to :organization
|
||||||
|
has_many :organization_users, foreign_key: :organization_id, primary_key: :organization_id
|
||||||
|
has_many :projects, foreign_key: :user_id, primary_key: :organization_id
|
||||||
|
|
||||||
enum visibility: {common: 0, limited: 1, privacy: 2}
|
enum visibility: {common: 0, limited: 1, privacy: 2}
|
||||||
|
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
class OrganizationUser < ApplicationRecord
|
class OrganizationUser < ApplicationRecord
|
||||||
|
|
||||||
belongs_to :organization
|
belongs_to :organization
|
||||||
|
belongs_to :organization_extension, foreign_key: :organization_id, primary_key: :organization_id, counter_cache: :num_users
|
||||||
belongs_to :user
|
belongs_to :user
|
||||||
|
|
||||||
validates :user_id, uniqueness: {scope: :organization_id}
|
validates :user_id, uniqueness: {scope: :organization_id}
|
||||||
|
|
|
@ -86,6 +86,7 @@ class Project < ApplicationRecord
|
||||||
belongs_to :ignore, optional: true
|
belongs_to :ignore, optional: true
|
||||||
belongs_to :license, optional: true
|
belongs_to :license, optional: true
|
||||||
belongs_to :owner, class_name: 'Owner', foreign_key: :user_id, optional: true
|
belongs_to :owner, class_name: 'Owner', foreign_key: :user_id, optional: true
|
||||||
|
belongs_to :organization_extension, foreign_key: :user_id, primary_key: :organization_id, optional: true, counter_cache: :num_projects
|
||||||
belongs_to :project_category, optional: true , :counter_cache => true
|
belongs_to :project_category, optional: true , :counter_cache => true
|
||||||
belongs_to :project_language, optional: true , :counter_cache => true
|
belongs_to :project_language, optional: true , :counter_cache => true
|
||||||
has_many :project_trends, dependent: :destroy
|
has_many :project_trends, dependent: :destroy
|
||||||
|
|
|
@ -58,7 +58,7 @@ class Organizations::CreateService < ApplicationService
|
||||||
TeamUnit.unit_types.keys.each do |u_type|
|
TeamUnit.unit_types.keys.each do |u_type|
|
||||||
TeamUnit.build(organization.id, owner_team.id, u_type)
|
TeamUnit.build(organization.id, owner_team.id, u_type)
|
||||||
end
|
end
|
||||||
OrganizationUser.build(organization.id, user.id, true)
|
OrganizationUser.build(organization.id, user.id)
|
||||||
TeamUser.build(organization.id, user.id, owner_team.id)
|
TeamUser.build(organization.id, user.id, owner_team.id)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -44,7 +44,10 @@ class Repositories::CreateService < ApplicationService
|
||||||
@gitea_repository = Gitea::Repository::CreateService.new(user.gitea_token, gitea_repository_params).call
|
@gitea_repository = Gitea::Repository::CreateService.new(user.gitea_token, gitea_repository_params).call
|
||||||
elsif project.owner.is_a?(Organization)
|
elsif project.owner.is_a?(Organization)
|
||||||
@gitea_repository = Gitea::Organization::Repository::CreateService.call(user.gitea_token, project.owner.login, gitea_repository_params)
|
@gitea_repository = Gitea::Organization::Repository::CreateService.call(user.gitea_token, project.owner.login, gitea_repository_params)
|
||||||
project.owner.teams.map{|t|t.setup_team_project!}
|
project.owner.teams.each do |team|
|
||||||
|
next unless team.includes_all_project
|
||||||
|
TeamProject.build(project.user_id, team.id, project.id)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -6,4 +6,6 @@ json.location organization.location
|
||||||
json.repo_admin_change_team_access organization.repo_admin_change_team_access
|
json.repo_admin_change_team_access organization.repo_admin_change_team_access
|
||||||
json.visibility organization.visibility
|
json.visibility organization.visibility
|
||||||
json.max_repo_creation organization.max_repo_creation
|
json.max_repo_creation organization.max_repo_creation
|
||||||
|
json.num_projects organization.num_projects
|
||||||
|
json.num_user organization.num_users
|
||||||
json.avatar_url url_to_avatar(organization)
|
json.avatar_url url_to_avatar(organization)
|
|
@ -1,6 +1,6 @@
|
||||||
json.total_count @projects.total_count
|
json.total_count @projects.total_count
|
||||||
json.projects @projects.each do |project|
|
json.projects @projects.each do |project|
|
||||||
json.(project, :name, :identifier, :description, :forked_count, :praises_count)
|
json.(project, :id, :name, :identifier, :description, :forked_count, :praises_count)
|
||||||
json.praised project.praised_by?(current_user)
|
json.praised project.praised_by?(current_user)
|
||||||
json.last_update_time render_unix_time(project.updated_on)
|
json.last_update_time render_unix_time(project.updated_on)
|
||||||
json.time_ago time_from_now(project.updated_on)
|
json.time_ago time_from_now(project.updated_on)
|
||||||
|
|
|
@ -0,0 +1,6 @@
|
||||||
|
json.id team_project.id
|
||||||
|
json.project do
|
||||||
|
json.owner_name team_project&.project&.owner&.login
|
||||||
|
json.name team_project&.project&.name
|
||||||
|
json.identifier team_project&.project&.identifier
|
||||||
|
end
|
|
@ -0,0 +1 @@
|
||||||
|
json.partial! "detail", team_project: @team_project, team: @team, organization: @organization
|
|
@ -0,0 +1,4 @@
|
||||||
|
json.total_count @team_projects.total_count
|
||||||
|
json.team_projects @team_projects do |team_project|
|
||||||
|
json.partial! "detail", team_project: team_project, team: @team, organization: @organization
|
||||||
|
end
|
|
@ -0,0 +1,6 @@
|
||||||
|
class AddColumnsToOrganizationExtension < ActiveRecord::Migration[5.2]
|
||||||
|
def change
|
||||||
|
add_column :organization_extensions, :num_projects, :integer, default: 0
|
||||||
|
add_column :organization_extensions, :num_users, :integer, default: 0
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in New Issue