commit
f222cc6e4f
|
@ -41,7 +41,10 @@ class UsersController < ApplicationController
|
||||||
@user_composes_count = 0
|
@user_composes_count = 0
|
||||||
user_organizations = User.current.logged? ? @user.organizations.with_visibility(%w(common limited)) + @user.organizations.with_visibility("privacy").joins(:team_users).where(team_users: {user_id: current_user.id}) : @user.organizations.with_visibility("common")
|
user_organizations = User.current.logged? ? @user.organizations.with_visibility(%w(common limited)) + @user.organizations.with_visibility("privacy").joins(:team_users).where(team_users: {user_id: current_user.id}) : @user.organizations.with_visibility("common")
|
||||||
@user_org_count = user_organizations.size
|
@user_org_count = user_organizations.size
|
||||||
user_projects = User.current.logged? && (User.current.admin? || User.current.login == @user.login) ? @user.projects : @user.projects.visible
|
normal_projects = Project.members_projects(@user.id).to_sql
|
||||||
|
org_projects = Project.joins(team_projects: [team: :team_users]).where(team_users: {user_id: @user.id}).to_sql
|
||||||
|
projects = Project.from("( #{ normal_projects} UNION #{ org_projects } ) AS projects").distinct
|
||||||
|
user_projects = User.current.logged? && (User.current.admin? || User.current.login == @user.login) ? projects : projects.visible
|
||||||
@projects_common_count = user_projects.common.size
|
@projects_common_count = user_projects.common.size
|
||||||
@projects_mirrior_count = user_projects.mirror.size
|
@projects_mirrior_count = user_projects.mirror.size
|
||||||
@projects_sync_mirrior_count = user_projects.sync_mirror.size
|
@projects_sync_mirrior_count = user_projects.sync_mirror.size
|
||||||
|
|
|
@ -11,6 +11,14 @@ module ProjectOperable
|
||||||
has_many :team_projects, dependent: :destroy
|
has_many :team_projects, dependent: :destroy
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def set_owner_permission(creator)
|
||||||
|
return unless owner.is_a?(Organization)
|
||||||
|
owner.build_permit_team_projects!(id)
|
||||||
|
# 避免自己创建的项目,却无法拥有访问权,因为该用户所在团队暂未获得项目访问权
|
||||||
|
return if creator.nil? || owner.is_owner?(creator.id)
|
||||||
|
add_member!(creator.id, "Manager")
|
||||||
|
end
|
||||||
|
|
||||||
def add_member!(user_id, role_name='Developer')
|
def add_member!(user_id, role_name='Developer')
|
||||||
member = members.create!(user_id: user_id)
|
member = members.create!(user_id: user_id)
|
||||||
set_developer_role(member, role_name)
|
set_developer_role(member, role_name)
|
||||||
|
|
|
@ -114,6 +114,13 @@ class Organization < Owner
|
||||||
owner_team_users.pluck(:user_id).include?(user_id) && owner_team_users.size == 1
|
owner_team_users.pluck(:user_id).include?(user_id) && owner_team_users.size == 1
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# 为包含组织所有项目的团队创建项目访问权限
|
||||||
|
def build_permit_team_projects!(project_id)
|
||||||
|
teams.where(includes_all_project: true).each do |team|
|
||||||
|
TeamProject.build(id, team.id, project_id)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def real_name
|
def real_name
|
||||||
name = lastname + firstname
|
name = lastname + firstname
|
||||||
name = name.blank? ? (nickname.blank? ? login : nickname) : name
|
name = name.blank? ? (nickname.blank? ? login : nickname) : name
|
||||||
|
|
|
@ -18,7 +18,9 @@ class Projects::ListMyQuery < ApplicationQuery
|
||||||
end
|
end
|
||||||
|
|
||||||
if params[:category].blank?
|
if params[:category].blank?
|
||||||
projects = projects.members_projects(user.id)
|
normal_projects = projects.members_projects(user.id).to_sql
|
||||||
|
org_projects = projects.joins(team_projects: [team: :team_users]).where(team_users: {user_id: user.id}).to_sql
|
||||||
|
projects = Project.from("( #{ normal_projects} UNION #{ org_projects } ) AS projects").distinct
|
||||||
elsif params[:category].to_s == "join"
|
elsif params[:category].to_s == "join"
|
||||||
normal_projects = projects.where.not(user_id: user.id).members_projects(user.id).to_sql
|
normal_projects = projects.where.not(user_id: user.id).members_projects(user.id).to_sql
|
||||||
org_projects = projects.joins(team_projects: [team: :team_users]).where(team_users: {user_id: user.id}).to_sql
|
org_projects = projects.joins(team_projects: [team: :team_users]).where(team_users: {user_id: user.id}).to_sql
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
class Projects::MigrateService < ApplicationService
|
class Projects::MigrateService < ApplicationService
|
||||||
attr_reader :user, :params
|
attr_reader :user, :params
|
||||||
|
attr_accessor :project
|
||||||
|
|
||||||
def initialize(user, params)
|
def initialize(user, params)
|
||||||
@user = user
|
@user = user
|
||||||
|
@ -11,6 +12,7 @@ class Projects::MigrateService < ApplicationService
|
||||||
if @project.save!
|
if @project.save!
|
||||||
ProjectUnit.init_types(@project.id)
|
ProjectUnit.init_types(@project.id)
|
||||||
Project.update_mirror_projects_count!
|
Project.update_mirror_projects_count!
|
||||||
|
@project.set_owner_permission(user)
|
||||||
Repositories::MigrateService.new(user, @project, repository_params).call
|
Repositories::MigrateService.new(user, @project, repository_params).call
|
||||||
else
|
else
|
||||||
#
|
#
|
||||||
|
|
|
@ -33,9 +33,8 @@ class Projects::TransferService < ApplicationService
|
||||||
|
|
||||||
def update_visit_teams
|
def update_visit_teams
|
||||||
if new_owner.is_a?(Organization)
|
if new_owner.is_a?(Organization)
|
||||||
new_owner.teams.where(includes_all_project: true).each do |team|
|
# 为包含组织所有项目的团队创建项目访问权限
|
||||||
TeamProject.build(new_owner.id, team.id, project.id)
|
new_owner.build_permit_team_projects(project.id)
|
||||||
end
|
|
||||||
else
|
else
|
||||||
project.team_projects.each(&:destroy!)
|
project.team_projects.each(&:destroy!)
|
||||||
end
|
end
|
||||||
|
|
|
@ -15,6 +15,7 @@ class Repositories::CreateService < ApplicationService
|
||||||
create_gitea_repository
|
create_gitea_repository
|
||||||
sync_project
|
sync_project
|
||||||
sync_repository
|
sync_repository
|
||||||
|
set_owner_permission(user)
|
||||||
# if project.project_type == "common"
|
# if project.project_type == "common"
|
||||||
# chain_params = {
|
# chain_params = {
|
||||||
# type: "create",
|
# type: "create",
|
||||||
|
@ -44,19 +45,9 @@ 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.each do |team|
|
|
||||||
next unless team.includes_all_project
|
|
||||||
TeamProject.build(project.user_id, team.id, project.id)
|
|
||||||
end
|
|
||||||
create_manager_member
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def create_manager_member
|
|
||||||
return if project.owner.is_owner?(user.id)
|
|
||||||
project.add_member!(user.id, "Manager")
|
|
||||||
end
|
|
||||||
|
|
||||||
def sync_project
|
def sync_project
|
||||||
if gitea_repository
|
if gitea_repository
|
||||||
project.update_columns(
|
project.update_columns(
|
||||||
|
|
|
@ -0,0 +1,8 @@
|
||||||
|
namespace :sync_org_project_permission do
|
||||||
|
desc "sync organization project team permissions"
|
||||||
|
task mirror: :environment do
|
||||||
|
Project.mirror.includes(:team_projects,:owner).where(team_projects: {id: nil}, users: {type: 'Organization'}).find_each do |project|
|
||||||
|
project.set_owner_permission(nil)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in New Issue