diff --git a/app/controllers/admin/projects/application_controller.rb b/app/controllers/admin/projects/application_controller.rb new file mode 100644 index 00000000..0f3da998 --- /dev/null +++ b/app/controllers/admin/projects/application_controller.rb @@ -0,0 +1,11 @@ +# Provides a base class for Admin controllers to subclass +# +# Automatically sets the layout and ensures an administrator is logged in +class Admin::Projects::ApplicationController < Admin::ApplicationController + + protected + + def project + @project ||= Project.find_by_path(params[:project_id]) + end +end diff --git a/app/controllers/admin/projects/members_controller.rb b/app/controllers/admin/projects/members_controller.rb new file mode 100644 index 00000000..5c20c071 --- /dev/null +++ b/app/controllers/admin/projects/members_controller.rb @@ -0,0 +1,32 @@ +class Admin::Projects::MembersController < Admin::Projects::ApplicationController + def edit + @member = team_member + @project = project + @team_member_relation = team_member_relation + end + + def update + if team_member_relation.update_attributes(params[:team_member]) + redirect_to [:admin, project], notice: 'Project Access was successfully updated.' + else + render action: "edit" + end + end + + def destroy + team_member_relation.destroy + + redirect_to :back + end + + private + + def team_member + @member ||= project.users.find(params[:id]) + end + + def team_member_relation + team_member.users_projects.find_by_project_id(project) + end + +end diff --git a/app/controllers/admin/team_members_controller.rb b/app/controllers/admin/team_members_controller.rb deleted file mode 100644 index 3c85681c..00000000 --- a/app/controllers/admin/team_members_controller.rb +++ /dev/null @@ -1,22 +0,0 @@ -class Admin::TeamMembersController < Admin::ApplicationController - def edit - @admin_team_member = UsersProject.find(params[:id]) - end - - def update - @admin_team_member = UsersProject.find(params[:id]) - - if @admin_team_member.update_attributes(params[:team_member]) - redirect_to [:admin, @admin_team_member.project], notice: 'Project Access was successfully updated.' - else - render action: "edit" - end - end - - def destroy - @admin_team_member = UsersProject.find(params[:id]) - @admin_team_member.destroy - - redirect_to :back - end -end diff --git a/app/models/project.rb b/app/models/project.rb index a21cc3f6..ba46fea2 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -494,6 +494,11 @@ class Project < ActiveRecord::Base http_url = [Gitlab.config.gitlab.url, "/", path_with_namespace, ".git"].join('') end + def project_access_human(member) + project_user_relation = self.users_projects.find_by_user_id(member.id) + self.class.access_options.key(project_user_relation.project_access) + end + # Check if current branch name is marked as protected in the system def protected_branch? branch_name protected_branches.map(&:name).include?(branch_name) diff --git a/app/views/admin/projects/members/_form.html.haml b/app/views/admin/projects/members/_form.html.haml new file mode 100644 index 00000000..f1bb6cfa --- /dev/null +++ b/app/views/admin/projects/members/_form.html.haml @@ -0,0 +1,16 @@ += form_for @team_member_relation, as: :team_member, url: admin_project_member_path(@project, @member) do |f| + -if @team_member_relation.errors.any? + .alert-message.block-message.error + %ul + - @team_member_relation.errors.full_messages.each do |msg| + %li= msg + + .clearfix + %label Project Access: + .input + = f.select :project_access, options_for_select(Project.access_options, @team_member_relation.project_access), {}, class: "project-access-select chosen span3" + + %br + .actions + = f.submit 'Save', class: "btn primary" + = link_to 'Cancel', :back, class: "btn" diff --git a/app/views/admin/projects/members/edit.html.haml b/app/views/admin/projects/members/edit.html.haml new file mode 100644 index 00000000..2d76deb2 --- /dev/null +++ b/app/views/admin/projects/members/edit.html.haml @@ -0,0 +1,8 @@ +%p.slead + Edit access for + = link_to @member.name, admin_user_path(@member) + in + = link_to @project.name_with_namespace, admin_project_path(@project) + +%hr += render 'form' diff --git a/app/views/admin/projects/show.html.haml b/app/views/admin/projects/show.html.haml index 12cad07c..a213c09d 100644 --- a/app/views/admin/projects/show.html.haml +++ b/app/views/admin/projects/show.html.haml @@ -114,7 +114,7 @@ %h5 Team %small - (#{@project.users_projects.count}) + (#{@project.users.count}) %br %table.zebra-striped.team_members %thead @@ -124,13 +124,13 @@ %th Repository Access %th - - @project.users_projects.each do |tm| + - @project.users.each do |tm| %tr %td - = link_to tm.user_name, admin_user_path(tm.user) - %td= tm.project_access_human - %td= link_to 'Edit Access', edit_admin_team_member_path(tm), class: "btn small" - %td= link_to 'Remove from team', admin_team_member_path(tm), confirm: 'Are you sure?', method: :delete, class: "btn danger small" + = link_to tm.name, admin_user_path(tm) + %td= @project.project_access_human(tm) + %td= link_to 'Edit Access', edit_admin_project_member_path(@project, tm), class: "btn small" + %td= link_to 'Remove from team', admin_project_member_path(@project, tm), confirm: 'Are you sure?', method: :delete, class: "btn danger small" %br %h5 Add new team member diff --git a/app/views/admin/team_members/_form.html.haml b/app/views/admin/team_members/_form.html.haml deleted file mode 100644 index 9cd94fdd..00000000 --- a/app/views/admin/team_members/_form.html.haml +++ /dev/null @@ -1,16 +0,0 @@ -= form_for @admin_team_member, as: :team_member, url: admin_team_member_path(@admin_team_member) do |f| - -if @admin_team_member.errors.any? - .alert-message.block-message.error - %ul - - @admin_team_member.errors.full_messages.each do |msg| - %li= msg - - .clearfix - %label Project Access: - .input - = f.select :project_access, options_for_select(Project.access_options, @admin_team_member.project_access), {}, class: "project-access-select chosen span3" - - %br - .actions - = f.submit 'Save', class: "btn primary" - = link_to 'Cancel', :back, class: "btn" diff --git a/app/views/admin/team_members/edit.html.haml b/app/views/admin/team_members/edit.html.haml deleted file mode 100644 index aea9bd70..00000000 --- a/app/views/admin/team_members/edit.html.haml +++ /dev/null @@ -1,8 +0,0 @@ -%p.slead - Edit access for - = link_to @admin_team_member.user_name, admin_user_path(@admin_team_member) - in - = link_to @admin_team_member.project.name_with_namespace, admin_project_path(@admin_team_member) - -%hr -= render 'form' diff --git a/config/routes.rb b/config/routes.rb index 21bfc89c..69ac1812 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -68,6 +68,9 @@ Gitlab::Application.routes.draw do get :team put :team_update end + scope module: :projects do + resources :members, only: [:edit, :update, :destroy] + end end resources :teams do #, constraints: { id: /[^\/]+/ } do end scope module: :teams do @@ -75,7 +78,6 @@ Gitlab::Application.routes.draw do resources :projects, only: [:edit, :update, :destroy, :new, :create] end end - resources :team_members, only: [:edit, :update, :destroy] resources :hooks, only: [:index, :create, :destroy] do get :test end diff --git a/spec/controllers/admin/projects/members_controller_spec.rb b/spec/controllers/admin/projects/members_controller_spec.rb new file mode 100644 index 00000000..73625e33 --- /dev/null +++ b/spec/controllers/admin/projects/members_controller_spec.rb @@ -0,0 +1,26 @@ +require 'spec_helper' + +describe Admin::Projects::MembersController do + + describe "GET 'edit'" do + it "returns http success" do + get 'edit' + response.should be_success + end + end + + describe "GET 'update'" do + it "returns http success" do + get 'update' + response.should be_success + end + end + + describe "GET 'destroy'" do + it "returns http success" do + get 'destroy' + response.should be_success + end + end + +end