Commit b7470440ffbc9cb9f58f9de4b3064760670a20a4
Committed by
Dmitriy Zaporozhets
1 parent
cca99359
Exists in
master
and in
4 other branches
Move team project management to own controller
Showing
8 changed files
with
121 additions
and
0 deletions
Show diff stats
@@ -0,0 +1,42 @@ | @@ -0,0 +1,42 @@ | ||
1 | +class Admin::Teams::ProjectsController < Admin::Teams::ApplicationController | ||
2 | + before_filter :team_project, only: [:edit, :destroy, :update] | ||
3 | + | ||
4 | + def new | ||
5 | + @projects = Project.scoped | ||
6 | + @projects = @projects.without_team(@team) if @team.projects.any? | ||
7 | + #@projects.reject!(&:empty_repo?) | ||
8 | + end | ||
9 | + | ||
10 | + def create | ||
11 | + unless params[:project_ids].blank? | ||
12 | + project_ids = params[:project_ids] | ||
13 | + access = params[:greatest_project_access] | ||
14 | + @team.assign_to_projects(project_ids, access) | ||
15 | + end | ||
16 | + | ||
17 | + redirect_to admin_team_path(@team), notice: 'Projects was successfully added.' | ||
18 | + end | ||
19 | + | ||
20 | + def edit | ||
21 | + end | ||
22 | + | ||
23 | + def update | ||
24 | + if @team.update_project_access(@project, params[:greatest_project_access]) | ||
25 | + redirect_to admin_team_path(@team), notice: 'Membership was successfully updated.' | ||
26 | + else | ||
27 | + render :edit | ||
28 | + end | ||
29 | + end | ||
30 | + | ||
31 | + def destroy | ||
32 | + @team.resign_from_project(@project) | ||
33 | + redirect_to admin_team_path(@team), notice: 'Project was successfully removed.' | ||
34 | + end | ||
35 | + | ||
36 | + private | ||
37 | + | ||
38 | + def team_project | ||
39 | + @project = @team.projects.find_by_path(params[:id]) | ||
40 | + end | ||
41 | + | ||
42 | +end |
app/models/user_team.rb
@@ -68,6 +68,10 @@ class UserTeam < ActiveRecord::Base | @@ -68,6 +68,10 @@ class UserTeam < ActiveRecord::Base | ||
68 | Gitlab::UserTeamManager.update_team_user_membership(self, user, options) | 68 | Gitlab::UserTeamManager.update_team_user_membership(self, user, options) |
69 | end | 69 | end |
70 | 70 | ||
71 | + def update_project_access(project, permission) | ||
72 | + Gitlab::UserTeamManager.update_project_greates_access(self, project, permission) | ||
73 | + end | ||
74 | + | ||
71 | def max_project_access(project) | 75 | def max_project_access(project) |
72 | user_team_project_relationships.find_by_project_id(project).greatest_access | 76 | user_team_project_relationships.find_by_project_id(project).greatest_access |
73 | end | 77 | end |
@@ -0,0 +1,16 @@ | @@ -0,0 +1,16 @@ | ||
1 | += form_tag admin_team_project_path(@team, @project), method: :put do | ||
2 | + -if @project.errors.any? | ||
3 | + .alert-message.block-message.error | ||
4 | + %ul | ||
5 | + - @project.errors.full_messages.each do |msg| | ||
6 | + %li= msg | ||
7 | + | ||
8 | + .clearfix | ||
9 | + %label Max access for Team members: | ||
10 | + .input | ||
11 | + = select_tag :greatest_project_access, options_for_select(UserTeam.access_roles, @team.max_project_access(@project)), class: "project-access-select chosen span3" | ||
12 | + | ||
13 | + %br | ||
14 | + .actions | ||
15 | + = submit_tag 'Save', class: "btn primary" | ||
16 | + = link_to 'Cancel', :back, class: "btn" |
@@ -0,0 +1,16 @@ | @@ -0,0 +1,16 @@ | ||
1 | +%h3 | ||
2 | + Edit max access in #{@project.name} for #{@team.name} team | ||
3 | + | ||
4 | +%hr | ||
5 | +%table.zebra-striped | ||
6 | + %tr | ||
7 | + %td Project: | ||
8 | + %td= @project.name | ||
9 | + %tr | ||
10 | + %td Team: | ||
11 | + %td= @team.name | ||
12 | + %tr | ||
13 | + %td Since: | ||
14 | + %td= assigned_since(@team, @project).stamp("Nov 11, 2010") | ||
15 | + | ||
16 | += render 'form' |
@@ -0,0 +1,23 @@ | @@ -0,0 +1,23 @@ | ||
1 | +%h3.page_title | ||
2 | + Team: #{@team.name} | ||
3 | + | ||
4 | +%fieldset | ||
5 | + %legend Projects (#{@team.projects.count}) | ||
6 | + = form_tag admin_team_projects_path(@team), id: "assign_projects", class: "bulk_import", method: :post do | ||
7 | + %table#projects_list | ||
8 | + %thead | ||
9 | + %tr | ||
10 | + %th Project name | ||
11 | + %th Max access | ||
12 | + %th | ||
13 | + - @team.projects.each do |project| | ||
14 | + %tr.project | ||
15 | + %td | ||
16 | + = link_to project.name_with_namespace, [:admin, project] | ||
17 | + %td | ||
18 | + %span= @team.human_max_project_access(project) | ||
19 | + %td | ||
20 | + %tr | ||
21 | + %td= select_tag :project_ids, options_from_collection_for_select(@projects , :id, :name_with_namespace), multiple: true, data: {placeholder: 'Select projects'}, class: 'chosen span5' | ||
22 | + %td= select_tag :greatest_project_access, options_for_select(Project.access_options), {class: "project-access-select chosen span3" } | ||
23 | + %td= submit_tag 'Add', class: "btn primary", id: :assign_projects_to_team |
config/routes.rb
@@ -78,6 +78,7 @@ Gitlab::Application.routes.draw do | @@ -78,6 +78,7 @@ Gitlab::Application.routes.draw do | ||
78 | end | 78 | end |
79 | scope module: :teams do | 79 | scope module: :teams do |
80 | resources :members, only: [:edit, :update, :destroy, :new, :create] | 80 | resources :members, only: [:edit, :update, :destroy, :new, :create] |
81 | + resources :projects, only: [:edit, :update, :destroy, :new, :create] | ||
81 | end | 82 | end |
82 | end | 83 | end |
83 | resources :team_members, only: [:edit, :update, :destroy] | 84 | resources :team_members, only: [:edit, :update, :destroy] |
lib/gitlab/user_team_manager.rb
@@ -48,6 +48,20 @@ module Gitlab | @@ -48,6 +48,20 @@ module Gitlab | ||
48 | end | 48 | end |
49 | end | 49 | end |
50 | 50 | ||
51 | + def update_project_greates_access(team, project, permission) | ||
52 | + project_relation = team.user_team_project_relationships.find_by_project_id(project) | ||
53 | + if permission != team.max_project_access(project) | ||
54 | + if project_relation.update_attributes(greatest_access: permission) | ||
55 | + update_team_users_access_in_project(team, project) | ||
56 | + true | ||
57 | + else | ||
58 | + false | ||
59 | + end | ||
60 | + else | ||
61 | + true | ||
62 | + end | ||
63 | + end | ||
64 | + | ||
51 | def rebuild_project_permissions_to_member(team, member) | 65 | def rebuild_project_permissions_to_member(team, member) |
52 | team.projects.each do |project| | 66 | team.projects.each do |project| |
53 | update_team_user_access_in_project(team, member, project) | 67 | update_team_user_access_in_project(team, member, project) |