diff options
author | Lennart Rosam <lennart.rosam@medien-systempartner.de> | 2013-01-28 16:04:23 +0400 |
---|---|---|
committer | Lennart Rosam <lennart.rosam@medien-systempartner.de> | 2013-01-28 16:04:23 +0400 |
commit | 66ebf8d83f894ed361031eb9ede5a8b829fefd36 (patch) | |
tree | d558f782b58427169886504fb74df6723cfdfdee /lib | |
parent | dc13af90b12a2366f77a9b68a7b74d7b5f54bc1a (diff) | |
parent | bd948549293e1abfa32ec566b687670fed47a3d7 (diff) |
Merge remote-tracking branch 'github/master'
Diffstat (limited to 'lib')
-rw-r--r-- | lib/gitlab/backend/gitolite_config.rb | 5 | ||||
-rw-r--r-- | lib/gitlab/user_team_manager.rb | 135 | ||||
-rw-r--r-- | lib/tasks/gitlab/check.rake | 8 | ||||
-rw-r--r-- | lib/tasks/sidekiq.rake | 2 |
4 files changed, 144 insertions, 6 deletions
diff --git a/lib/gitlab/backend/gitolite_config.rb b/lib/gitlab/backend/gitolite_config.rb index f12c10ce01c..e4ebd595a93 100644 --- a/lib/gitlab/backend/gitolite_config.rb +++ b/lib/gitlab/backend/gitolite_config.rb @@ -88,7 +88,10 @@ module Gitlab end def destroy_project(project) - FileUtils.rm_rf(project.repository.path_to_repo) + # do rm-rf only if repository exists + if project.repository + FileUtils.rm_rf(project.repository.path_to_repo) + end conf.rm_repo(project.path_with_namespace) end diff --git a/lib/gitlab/user_team_manager.rb b/lib/gitlab/user_team_manager.rb new file mode 100644 index 00000000000..a8ff4a3d94d --- /dev/null +++ b/lib/gitlab/user_team_manager.rb @@ -0,0 +1,135 @@ +# UserTeamManager class +# +# Used for manage User teams with project repositories +module Gitlab + class UserTeamManager + class << self + def assign(team, project, access) + project = Project.find(project) unless project.is_a? Project + searched_project = team.user_team_project_relationships.find_by_project_id(project.id) + + 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) + end + end + + def resign(team, project) + project = Project.find(project) unless project.is_a? Project + + team.user_team_project_relationships.with_project(project).destroy_all + + update_team_users_access_in_project(team, project) + end + + def update_team_user_membership(team, member, options) + updates = {} + + if options[:default_projects_access] && options[:default_projects_access] != team.default_projects_access(member) + updates[:permission] = options[:default_projects_access] + end + + if options[:group_admin].to_s != team.admin?(member).to_s + updates[:group_admin] = options[:group_admin].present? + end + + unless updates.blank? + user_team_relationship = team.user_team_user_relationships.find_by_user_id(member) + if user_team_relationship.update_attributes(updates) + if updates[:permission] + rebuild_project_permissions_to_member(team, member) + end + true + else + false + end + else + true + end + end + + def update_project_greates_access(team, project, permission) + 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) + true + else + false + end + else + true + end + end + + def rebuild_project_permissions_to_member(team, member) + team.projects.each do |project| + update_team_user_access_in_project(team, member, project) + end + end + + def update_team_users_access_in_project(team, project) + members = team.members + members.each do |member| + update_team_user_access_in_project(team, member, project) + end + end + + def update_team_user_access_in_project(team, user, project) + granted_access = max_teams_member_permission_in_project(user, project) + + project_team_user = UsersProject.find_by_user_id_and_project_id(user.id, project.id) + project_team_user.destroy if project_team_user.present? + + # project_team_user.project_access != granted_access + project.team << [user, granted_access] if granted_access > 0 + end + + 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 + + if teams.any? + teams.each do |team| + granted_access = max_team_member_permission_in_project(team, user, project) + result_access = [granted_access, result_access].max + end + end + result_access + end + + def max_team_member_permission_in_project(team, user, project) + member_access = team.default_projects_access(user) + team_access = team.user_team_project_relationships.find_by_project_id(project.id).greatest_access + + [team_access, member_access].min + end + + def add_member_into_team(team, user, access, admin) + user = User.find(user) unless user.is_a? User + + 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) + end + end + + def remove_member_from_team(team, user) + user = User.find(user) unless user.is_a? User + + team.user_team_user_relationships.with_user(user).destroy_all + other_teams = [] + team.projects.each do |project| + other_teams << project.user_teams.with_member(user) + end + other_teams.uniq + unless other_teams.any? + UsersProject.in_projects(team.projects).with_user(user).destroy_all + end + end + end + end +end diff --git a/lib/tasks/gitlab/check.rake b/lib/tasks/gitlab/check.rake index 826b78ec5b1..1ca723f271a 100644 --- a/lib/tasks/gitlab/check.rake +++ b/lib/tasks/gitlab/check.rake @@ -169,7 +169,7 @@ namespace :gitlab do else puts "no".red try_fixing_it( - sudo_gitlab("bundle exec rake db:migrate") + sudo_gitlab("bundle exec rake db:migrate RAILS_ENV=production") ) fix_and_rerun end @@ -194,7 +194,7 @@ namespace :gitlab do else puts "no".red try_fixing_it( - sudo_gitlab("bundle exec rake gitlab:satellites:create"), + sudo_gitlab("bundle exec rake gitlab:satellites:create RAILS_ENV=production"), "If necessary, remove the tmp/repo_satellites directory ...", "... and rerun the above command" ) @@ -789,7 +789,7 @@ namespace :gitlab do else puts "wrong or missing".red try_fixing_it( - sudo_gitlab("bundle exec rake gitlab:gitolite:update_repos") + sudo_gitlab("bundle exec rake gitlab:gitolite:update_repos RAILS_ENV=production") ) for_more_information( "doc/raketasks/maintenance.md" @@ -895,7 +895,7 @@ namespace :gitlab do else puts "no".red try_fixing_it( - sudo_gitlab("bundle exec rake sidekiq:start") + sudo_gitlab("bundle exec rake sidekiq:start RAILS_ENV=production") ) for_more_information( see_installation_guide_section("Install Init Script"), diff --git a/lib/tasks/sidekiq.rake b/lib/tasks/sidekiq.rake index 01da919d7f8..0d2ec6f332c 100644 --- a/lib/tasks/sidekiq.rake +++ b/lib/tasks/sidekiq.rake @@ -6,7 +6,7 @@ namespace :sidekiq do desc "GITLAB | Start sidekiq" task :start do - run "nohup bundle exec sidekiq -q post_receive,mailer,system_hook,common,default -e #{Rails.env} -P #{pidfile} >> #{Rails.root.join("log", "sidekiq.log")} 2>&1 &" + run "nohup bundle exec sidekiq -q post_receive,mailer,system_hook,project_web_hook,common,default -e #{Rails.env} -P #{pidfile} >> #{Rails.root.join("log", "sidekiq.log")} 2>&1 &" end def pidfile |