From a7667ffc14017732228058e34e1f724be08bf9a0 Mon Sep 17 00:00:00 2001 From: Andrey Kumanyaev Date: Mon, 21 Jan 2013 01:04:53 +0400 Subject: [PATCH] Repair members management of teams --- .../admin/teams/members_controller.rb | 15 +++++++- app/views/admin/teams/members/new.html.haml | 2 +- app/views/admin/teams/show.html.haml | 37 ++++++++++--------- 3 files changed, 33 insertions(+), 21 deletions(-) diff --git a/app/controllers/admin/teams/members_controller.rb b/app/controllers/admin/teams/members_controller.rb index 4037bff5..6795a520 100644 --- a/app/controllers/admin/teams/members_controller.rb +++ b/app/controllers/admin/teams/members_controller.rb @@ -1,4 +1,6 @@ class Admin::Teams::MembersController < Admin::Teams::ApplicationController + before_filter :team_member, only: [:edit, :destroy, :update] + def new @users = User.active @users = @users.not_in_team(@team) if @team.members.any? @@ -17,11 +19,9 @@ class Admin::Teams::MembersController < Admin::Teams::ApplicationController end def edit - @member = @team.members.find(params[:id]) end def update - @member = @team.members.find(params[:id]) options = {default_projects_access: params[:default_project_access], group_admin: params[:group_admin]} if @team.update_membership(@member, options) redirect_to admin_team_path(@team), notice: 'Membership was successfully updated.' @@ -31,5 +31,16 @@ class Admin::Teams::MembersController < Admin::Teams::ApplicationController end def destroy + if @team.remove_member(@member) + redirect_to admin_team_path(@team), notice: "Member was successfully removed from team." + else + redirect_to admin_team_members(@team), notice: "Something wrong." + end + end + + private + + def team_member + @member = @team.members.find(params[:id]) end end diff --git a/app/views/admin/teams/members/new.html.haml b/app/views/admin/teams/members/new.html.haml index 5cdf0735..066ab19f 100644 --- a/app/views/admin/teams/members/new.html.haml +++ b/app/views/admin/teams/members/new.html.haml @@ -3,7 +3,7 @@ %fieldset %legend Members (#{@team.members.count}) - = form_tag add_members_admin_team_path(@team), id: "team_members", class: "bulk_import", method: :post do + = form_tag admin_team_members_path(@team), id: "team_members", class: "bulk_import", method: :post do %table#members_list %thead %tr diff --git a/app/views/admin/teams/show.html.haml b/app/views/admin/teams/show.html.haml index 05a3a1d3..2bb9c02a 100644 --- a/app/views/admin/teams/show.html.haml +++ b/app/views/admin/teams/show.html.haml @@ -68,25 +68,26 @@ %fieldset %legend Projects (#{@team.projects.count}) - = form_tag delegate_projects_admin_team_path(@team), id: "assign_projects", class: "bulk_import", method: :post do - %table#projects_list - %thead - %tr - %th Project name - %th Max access - %th.cred Danger Zone! - - @team.projects.each do |project| - %tr.project - %td - = link_to project.name_with_namespace, [:admin, project] - %td - %span= @team.human_max_project_access(project) - %td.bgred - = link_to 'Relegate', relegate_project_admin_team_path(@team, project_id: project.id), confirm: 'Remove project from team and move to global namespace. Are you sure?', method: :delete, class: "btn danger small" + %table#projects_list + %thead %tr - %td= select_tag :project_ids, options_from_collection_for_select(@projects , :id, :name_with_namespace), multiple: true, data: {placeholder: 'Select projects'}, class: 'chosen span5' - %td= select_tag :greatest_project_access, options_for_select(Project.access_options), {class: "project-access-select chosen span3" } - %td= submit_tag 'Add', class: "btn primary", id: :assign_projects_to_team + %th Project name + %th Max access + %th.cred Danger Zone! + - @team.projects.each do |project| + %tr.project + %td + = link_to project.name_with_namespace, [:admin, project] + %td + %span= @team.human_max_project_access(project) + %td.bgred + = link_to 'Edit', edit_admin_team_project_path(@team, project), class: "btn small" +   + = link_to 'Relegate', admin_team_project_path(@team, project), confirm: 'Remove project from team. Are you sure?', method: :delete, class: "btn danger small" + %tr + %td + %td + %td= link_to 'Add projects', new_admin_team_project_path(@team), class: "btn primary", id: :assign_projects_to_team :javascript $(function(){