Skip to content

Commit b747044

Browse files
zzetdzaporozhets
authored andcommitted
Move team project management to own controller
1 parent cca9935 commit b747044

File tree

8 files changed

+121
-0
lines changed

8 files changed

+121
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -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
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module Admin::Teams::ProjectsHelper
2+
def assigned_since(team, project)
3+
team.user_team_project_relationships.find_by_project_id(project).created_at
4+
end
5+
end

app/models/user_team.rb

+4
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ def update_membership(user, options)
6868
Gitlab::UserTeamManager.update_team_user_membership(self, user, options)
6969
end
7070

71+
def update_project_access(project, permission)
72+
Gitlab::UserTeamManager.update_project_greates_access(self, project, permission)
73+
end
74+
7175
def max_project_access(project)
7276
user_team_project_relationships.find_by_project_id(project).greatest_access
7377
end
Original file line numberDiff line numberDiff line change
@@ -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"
Original file line numberDiff line numberDiff line change
@@ -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'
Original file line numberDiff line numberDiff line change
@@ -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

+1
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@
7878
end
7979
scope module: :teams do
8080
resources :members, only: [:edit, :update, :destroy, :new, :create]
81+
resources :projects, only: [:edit, :update, :destroy, :new, :create]
8182
end
8283
end
8384
resources :team_members, only: [:edit, :update, :destroy]

lib/gitlab/user_team_manager.rb

+14
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,20 @@ def update_team_user_membership(team, member, options)
4848
end
4949
end
5050

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+
5165
def rebuild_project_permissions_to_member(team, member)
5266
team.projects.each do |project|
5367
update_team_user_access_in_project(team, member, project)

0 commit comments

Comments
 (0)