Commit 1dd0feacc7ba885c53da74028ee081a5a08e05ca
Committed by
Dmitriy Zaporozhets
1 parent
497f7ab5
Exists in
master
and in
4 other branches
move Team_members controller into project (conflicts with team/members controller)
Showing
11 changed files
with
107 additions
and
53 deletions
Show diff stats
app/controllers/admin/projects/application_controller.rb
0 → 100644
@@ -0,0 +1,11 @@ | @@ -0,0 +1,11 @@ | ||
1 | +# Provides a base class for Admin controllers to subclass | ||
2 | +# | ||
3 | +# Automatically sets the layout and ensures an administrator is logged in | ||
4 | +class Admin::Projects::ApplicationController < Admin::ApplicationController | ||
5 | + | ||
6 | + protected | ||
7 | + | ||
8 | + def project | ||
9 | + @project ||= Project.find_by_path(params[:project_id]) | ||
10 | + end | ||
11 | +end |
@@ -0,0 +1,32 @@ | @@ -0,0 +1,32 @@ | ||
1 | +class Admin::Projects::MembersController < Admin::Projects::ApplicationController | ||
2 | + def edit | ||
3 | + @member = team_member | ||
4 | + @project = project | ||
5 | + @team_member_relation = team_member_relation | ||
6 | + end | ||
7 | + | ||
8 | + def update | ||
9 | + if team_member_relation.update_attributes(params[:team_member]) | ||
10 | + redirect_to [:admin, project], notice: 'Project Access was successfully updated.' | ||
11 | + else | ||
12 | + render action: "edit" | ||
13 | + end | ||
14 | + end | ||
15 | + | ||
16 | + def destroy | ||
17 | + team_member_relation.destroy | ||
18 | + | ||
19 | + redirect_to :back | ||
20 | + end | ||
21 | + | ||
22 | + private | ||
23 | + | ||
24 | + def team_member | ||
25 | + @member ||= project.users.find(params[:id]) | ||
26 | + end | ||
27 | + | ||
28 | + def team_member_relation | ||
29 | + team_member.users_projects.find_by_project_id(project) | ||
30 | + end | ||
31 | + | ||
32 | +end |
app/controllers/admin/team_members_controller.rb
@@ -1,22 +0,0 @@ | @@ -1,22 +0,0 @@ | ||
1 | -class Admin::TeamMembersController < Admin::ApplicationController | ||
2 | - def edit | ||
3 | - @admin_team_member = UsersProject.find(params[:id]) | ||
4 | - end | ||
5 | - | ||
6 | - def update | ||
7 | - @admin_team_member = UsersProject.find(params[:id]) | ||
8 | - | ||
9 | - if @admin_team_member.update_attributes(params[:team_member]) | ||
10 | - redirect_to [:admin, @admin_team_member.project], notice: 'Project Access was successfully updated.' | ||
11 | - else | ||
12 | - render action: "edit" | ||
13 | - end | ||
14 | - end | ||
15 | - | ||
16 | - def destroy | ||
17 | - @admin_team_member = UsersProject.find(params[:id]) | ||
18 | - @admin_team_member.destroy | ||
19 | - | ||
20 | - redirect_to :back | ||
21 | - end | ||
22 | -end |
app/models/project.rb
@@ -494,6 +494,11 @@ class Project < ActiveRecord::Base | @@ -494,6 +494,11 @@ class Project < ActiveRecord::Base | ||
494 | http_url = [Gitlab.config.gitlab.url, "/", path_with_namespace, ".git"].join('') | 494 | http_url = [Gitlab.config.gitlab.url, "/", path_with_namespace, ".git"].join('') |
495 | end | 495 | end |
496 | 496 | ||
497 | + def project_access_human(member) | ||
498 | + project_user_relation = self.users_projects.find_by_user_id(member.id) | ||
499 | + self.class.access_options.key(project_user_relation.project_access) | ||
500 | + end | ||
501 | + | ||
497 | # Check if current branch name is marked as protected in the system | 502 | # Check if current branch name is marked as protected in the system |
498 | def protected_branch? branch_name | 503 | def protected_branch? branch_name |
499 | protected_branches.map(&:name).include?(branch_name) | 504 | protected_branches.map(&:name).include?(branch_name) |
@@ -0,0 +1,16 @@ | @@ -0,0 +1,16 @@ | ||
1 | += form_for @team_member_relation, as: :team_member, url: admin_project_member_path(@project, @member) do |f| | ||
2 | + -if @team_member_relation.errors.any? | ||
3 | + .alert-message.block-message.error | ||
4 | + %ul | ||
5 | + - @team_member_relation.errors.full_messages.each do |msg| | ||
6 | + %li= msg | ||
7 | + | ||
8 | + .clearfix | ||
9 | + %label Project Access: | ||
10 | + .input | ||
11 | + = f.select :project_access, options_for_select(Project.access_options, @team_member_relation.project_access), {}, class: "project-access-select chosen span3" | ||
12 | + | ||
13 | + %br | ||
14 | + .actions | ||
15 | + = f.submit 'Save', class: "btn primary" | ||
16 | + = link_to 'Cancel', :back, class: "btn" |
app/views/admin/projects/show.html.haml
@@ -114,7 +114,7 @@ | @@ -114,7 +114,7 @@ | ||
114 | %h5 | 114 | %h5 |
115 | Team | 115 | Team |
116 | %small | 116 | %small |
117 | - (#{@project.users_projects.count}) | 117 | + (#{@project.users.count}) |
118 | %br | 118 | %br |
119 | %table.zebra-striped.team_members | 119 | %table.zebra-striped.team_members |
120 | %thead | 120 | %thead |
@@ -124,13 +124,13 @@ | @@ -124,13 +124,13 @@ | ||
124 | %th Repository Access | 124 | %th Repository Access |
125 | %th | 125 | %th |
126 | 126 | ||
127 | - - @project.users_projects.each do |tm| | 127 | + - @project.users.each do |tm| |
128 | %tr | 128 | %tr |
129 | %td | 129 | %td |
130 | - = link_to tm.user_name, admin_user_path(tm.user) | ||
131 | - %td= tm.project_access_human | ||
132 | - %td= link_to 'Edit Access', edit_admin_team_member_path(tm), class: "btn small" | ||
133 | - %td= link_to 'Remove from team', admin_team_member_path(tm), confirm: 'Are you sure?', method: :delete, class: "btn danger small" | 130 | + = link_to tm.name, admin_user_path(tm) |
131 | + %td= @project.project_access_human(tm) | ||
132 | + %td= link_to 'Edit Access', edit_admin_project_member_path(@project, tm), class: "btn small" | ||
133 | + %td= link_to 'Remove from team', admin_project_member_path(@project, tm), confirm: 'Are you sure?', method: :delete, class: "btn danger small" | ||
134 | 134 | ||
135 | %br | 135 | %br |
136 | %h5 Add new team member | 136 | %h5 Add new team member |
app/views/admin/team_members/_form.html.haml
@@ -1,16 +0,0 @@ | @@ -1,16 +0,0 @@ | ||
1 | -= form_for @admin_team_member, as: :team_member, url: admin_team_member_path(@admin_team_member) do |f| | ||
2 | - -if @admin_team_member.errors.any? | ||
3 | - .alert-message.block-message.error | ||
4 | - %ul | ||
5 | - - @admin_team_member.errors.full_messages.each do |msg| | ||
6 | - %li= msg | ||
7 | - | ||
8 | - .clearfix | ||
9 | - %label Project Access: | ||
10 | - .input | ||
11 | - = f.select :project_access, options_for_select(Project.access_options, @admin_team_member.project_access), {}, class: "project-access-select chosen span3" | ||
12 | - | ||
13 | - %br | ||
14 | - .actions | ||
15 | - = f.submit 'Save', class: "btn primary" | ||
16 | - = link_to 'Cancel', :back, class: "btn" |
app/views/admin/team_members/edit.html.haml
config/routes.rb
@@ -68,6 +68,9 @@ Gitlab::Application.routes.draw do | @@ -68,6 +68,9 @@ Gitlab::Application.routes.draw do | ||
68 | get :team | 68 | get :team |
69 | put :team_update | 69 | put :team_update |
70 | end | 70 | end |
71 | + scope module: :projects do | ||
72 | + resources :members, only: [:edit, :update, :destroy] | ||
73 | + end | ||
71 | end | 74 | end |
72 | resources :teams do #, constraints: { id: /[^\/]+/ } do end | 75 | resources :teams do #, constraints: { id: /[^\/]+/ } do end |
73 | scope module: :teams do | 76 | scope module: :teams do |
@@ -75,7 +78,6 @@ Gitlab::Application.routes.draw do | @@ -75,7 +78,6 @@ Gitlab::Application.routes.draw do | ||
75 | resources :projects, only: [:edit, :update, :destroy, :new, :create] | 78 | resources :projects, only: [:edit, :update, :destroy, :new, :create] |
76 | end | 79 | end |
77 | end | 80 | end |
78 | - resources :team_members, only: [:edit, :update, :destroy] | ||
79 | resources :hooks, only: [:index, :create, :destroy] do | 81 | resources :hooks, only: [:index, :create, :destroy] do |
80 | get :test | 82 | get :test |
81 | end | 83 | end |
spec/controllers/admin/projects/members_controller_spec.rb
0 → 100644
@@ -0,0 +1,26 @@ | @@ -0,0 +1,26 @@ | ||
1 | +require 'spec_helper' | ||
2 | + | ||
3 | +describe Admin::Projects::MembersController do | ||
4 | + | ||
5 | + describe "GET 'edit'" do | ||
6 | + it "returns http success" do | ||
7 | + get 'edit' | ||
8 | + response.should be_success | ||
9 | + end | ||
10 | + end | ||
11 | + | ||
12 | + describe "GET 'update'" do | ||
13 | + it "returns http success" do | ||
14 | + get 'update' | ||
15 | + response.should be_success | ||
16 | + end | ||
17 | + end | ||
18 | + | ||
19 | + describe "GET 'destroy'" do | ||
20 | + it "returns http success" do | ||
21 | + get 'destroy' | ||
22 | + response.should be_success | ||
23 | + end | ||
24 | + end | ||
25 | + | ||
26 | +end |