Commit 9804b7df authored by Andrey Kumanyaev's avatar Andrey Kumanyaev Committed by Dmitriy Zaporozhets

Move admin team members management to own controller

parent 9d318db4
# Provides a base class for Admin controllers to subclass
#
# Automatically sets the layout and ensures an administrator is logged in
class Admin::Teams::ApplicationController < Admin::ApplicationController
before_filter :user_team
private
def user_team
@team = UserTeam.find_by_path(params[:team_id])
end
end
class Admin::Teams::MembersController < Admin::Teams::ApplicationController
def new
@users = User.active
@users = @users.not_in_team(@team) if @team.members.any?
@users = UserDecorator.decorate @users
end
def create
unless params[:user_ids].blank?
user_ids = params[:user_ids]
access = params[:default_project_access]
is_admin = params[:group_admin]
@team.add_members(user_ids, access, is_admin)
end
redirect_to admin_team_path(@team), notice: 'Members was successfully added.'
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.'
else
render :edit
end
end
def destroy
end
end
......@@ -64,6 +64,10 @@ class UserTeam < ActiveRecord::Base
Gitlab::UserTeamManager.remove_member_from_team(self, user)
end
def update_membership(user, options)
Gitlab::UserTeamManager.update_team_user_membership(self, user, options)
end
def max_project_access(project)
user_team_project_relationships.find_by_project_id(project).greatest_access
end
......
= form_tag admin_team_member_path(@team, @member), method: :put do
-if @member.errors.any?
.alert-message.block-message.error
%ul
- @member.errors.full_messages.each do |msg|
%li= msg
.clearfix
%label Default access for Team projects:
.input
= select_tag :default_project_access, options_for_select(UserTeam.access_roles, @team.default_projects_access(@member)), class: "project-access-select chosen span3"
.clearfix
%label Team admin?
.input
= check_box_tag :group_admin, true, @team.admin?(@member)
%br
.actions
= submit_tag 'Save', class: "btn primary"
= link_to 'Cancel', :back, class: "btn"
%h3
Edit access #{@member.name} in #{@team.name} team
%hr
%table.zebra-striped
%tr
%td User:
%td= @member.name
%tr
%td Team:
%td= @team.name
%tr
%td Since:
%td= member_since(@team, @member).stamp("Nov 11, 2010")
= render 'form'
%h3.page_title
Team: #{@team.name}
%fieldset
%legend Members (#{@team.members.count})
= form_tag add_members_admin_team_path(@team), id: "team_members", class: "bulk_import", method: :post do
%table#members_list
%thead
%tr
%th User name
%th Default project access
%th Team access
%th
- @team.members.each do |member|
%tr.member
%td
= link_to [:admin, member] do
= member.name
%small= "(#{member.email})"
%td= @team.human_default_projects_access(member)
%td= @team.admin?(member) ? "Admin" : "Member"
%td
%tr
%td= select_tag :user_ids, options_from_collection_for_select(@users , :id, :name_with_email), multiple: true, data: {placeholder: 'Select users'}, class: 'chosen span5'
%td= select_tag :default_project_access, options_for_select(Project.access_options), {class: "project-access-select chosen span3" }
%td
%span= check_box_tag :group_admin
%span Admin?
%td= submit_tag 'Add', class: "btn primary", id: :add_members_to_team
......@@ -41,7 +41,6 @@
%fieldset
%legend Members (#{@team.members.count})
= form_tag add_members_admin_team_path(@team), id: "team_members", class: "bulk_import", method: :post do
%table#members_list
%thead
%tr
......@@ -58,14 +57,14 @@
%td= @team.human_default_projects_access(member)
%td= @team.admin?(member) ? "Admin" : "Member"
%td.bgred
= link_to 'Remove', remove_member_admin_team_path(@team, member_id: member.id), confirm: 'Remove project from team and move to global namespace. Are you sure?', method: :delete, class: "btn danger small"
= link_to 'Edit', edit_admin_team_member_path(@team, member), class: "btn small"
&nbsp;
= link_to 'Remove', admin_team_member_path(@team, member), confirm: 'Remove member from team. Are you sure?', method: :delete, class: "btn danger small"
%tr
%td= select_tag :user_ids, options_from_collection_for_select(@users , :id, :name_with_email), multiple: true, data: {placeholder: 'Select users'}, class: 'chosen span5'
%td= select_tag :default_project_access, options_for_select(Project.access_options), {class: "project-access-select chosen span3" }
%td
%span= check_box_tag :group_admin
%span Admin?
%td= submit_tag 'Add', class: "btn primary", id: :add_members_to_team
%td
%td
%td= link_to 'Add members', new_admin_team_member_path(@team), class: "btn primary", id: :add_members_to_team
%fieldset
%legend Projects (#{@team.projects.count})
......
......@@ -77,6 +77,9 @@ Gitlab::Application.routes.draw do
post :add_members
delete :remove_member
end
scope module: :teams do
resources :members, only: [:edit, :update, :destroy, :new, :create]
end
end
resources :team_members, only: [:edit, :update, :destroy]
resources :hooks, only: [:index, :create, :destroy] do
......
......@@ -22,6 +22,38 @@ module Gitlab
update_team_users_access_in_project(team, project)
end
def update_team_user_membership(team, member, options)
updates = {}
if options[:default_projects_access] && options[:default_projects_access] != team.default_projects_access(member)
updates[:permission] = options[:default_projects_access]
end
if options[:group_admin].to_s != team.admin?(member).to_s
updates[:group_admin] = options[:group_admin].present?
end
unless updates.blank?
user_team_relationship = team.user_team_user_relationships.find_by_user_id(member)
if user_team_relationship.update_attributes(updates)
if updates[:permission]
rebuild_project_permissions_to_member(team, member)
end
true
else
false
end
else
true
end
end
def rebuild_project_permissions_to_member(team, member)
team.projects.each do |project|
update_team_user_access_in_project(team, member, project)
end
end
def update_team_users_access_in_project(team, project)
members = team.members
members.each do |member|
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment