From a0f2fbc25094066995aefe7c3ad6b0f0de8e5fe3 Mon Sep 17 00:00:00 2001 From: Andrey Kumanyaev Date: Mon, 18 Mar 2013 15:44:26 +0400 Subject: [PATCH 1/2] Fix bug with downgrade permissions on first project assigment to team --- lib/gitlab/user_team_manager.rb | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/gitlab/user_team_manager.rb b/lib/gitlab/user_team_manager.rb index a8ff4a3d94d..e7b9756304b 100644 --- a/lib/gitlab/user_team_manager.rb +++ b/lib/gitlab/user_team_manager.rb @@ -88,9 +88,8 @@ module Gitlab def max_teams_member_permission_in_project(user, project, teams = nil) result_access = 0 - user_teams = project.user_teams.with_member(user) - - teams ||= user_teams + teams ||= project.user_teams.with_member(user) + result_access ||= project.users_project.with_user(user).first.project_access if teams.any? teams.each do |team| From 0f39610532238468a0d058c4df5e6433807fdbd1 Mon Sep 17 00:00:00 2001 From: Andrey Kumanyaev Date: Mon, 18 Mar 2013 16:07:04 +0400 Subject: [PATCH 2/2] Add control of action in project to team assigment --- lib/gitlab/user_team_manager.rb | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/lib/gitlab/user_team_manager.rb b/lib/gitlab/user_team_manager.rb index e7b9756304b..4127d5e1bd8 100644 --- a/lib/gitlab/user_team_manager.rb +++ b/lib/gitlab/user_team_manager.rb @@ -10,7 +10,7 @@ module Gitlab unless searched_project.present? team.user_team_project_relationships.create(project_id: project.id, greatest_access: access) - update_team_users_access_in_project(team, project) + update_team_users_access_in_project(team, project, :added) end end @@ -19,7 +19,7 @@ module Gitlab team.user_team_project_relationships.with_project(project).destroy_all - update_team_users_access_in_project(team, project) + update_team_users_access_in_project(team, project, :updated) end def update_team_user_membership(team, member, options) @@ -52,7 +52,7 @@ module Gitlab project_relation = team.user_team_project_relationships.find_by_project_id(project) if permission != team.max_project_access(project) if project_relation.update_attributes(greatest_access: permission) - update_team_users_access_in_project(team, project) + update_team_users_access_in_project(team, project, :updated) true else false @@ -68,15 +68,15 @@ module Gitlab end end - def update_team_users_access_in_project(team, project) + def update_team_users_access_in_project(team, project, action) members = team.members members.each do |member| - update_team_user_access_in_project(team, member, project) + update_team_user_access_in_project(team, member, project, action) end end - def update_team_user_access_in_project(team, user, project) - granted_access = max_teams_member_permission_in_project(user, project) + def update_team_user_access_in_project(team, user, project, action) + granted_access = max_teams_member_permission_in_project(user, project, action) project_team_user = UsersProject.find_by_user_id_and_project_id(user.id, project.id) project_team_user.destroy if project_team_user.present? @@ -85,11 +85,14 @@ module Gitlab project.team << [user, granted_access] if granted_access > 0 end - def max_teams_member_permission_in_project(user, project, teams = nil) + def max_teams_member_permission_in_project(user, project, action = nil, teams = nil) result_access = 0 teams ||= project.user_teams.with_member(user) - result_access ||= project.users_project.with_user(user).first.project_access + + if action && (action == :added) && (teams.count == 1) + result_access ||= project.users_project.with_user(user).first.project_access + end if teams.any? teams.each do |team| @@ -112,7 +115,7 @@ module Gitlab team.user_team_user_relationships.create(user_id: user.id, permission: access, group_admin: admin) team.projects.each do |project| - update_team_user_access_in_project(team, user, project) + update_team_user_access_in_project(team, user, project, :added) end end