summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/controllers/admin/teams/application_controller.rb12
-rw-r--r--app/controllers/admin/teams/members_controller.rb35
-rw-r--r--app/models/user_team.rb4
-rw-r--r--app/views/admin/teams/members/_form.html.haml20
-rw-r--r--app/views/admin/teams/members/edit.html.haml16
-rw-r--r--app/views/admin/teams/members/new.html.haml29
-rw-r--r--app/views/admin/teams/show.html.haml45
-rw-r--r--config/routes.rb3
-rw-r--r--lib/gitlab/user_team_manager.rb32
9 files changed, 173 insertions, 23 deletions
diff --git a/app/controllers/admin/teams/application_controller.rb b/app/controllers/admin/teams/application_controller.rb
new file mode 100644
index 00000000000..a2920b626b5
--- /dev/null
+++ b/app/controllers/admin/teams/application_controller.rb
@@ -0,0 +1,12 @@
+# 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
diff --git a/app/controllers/admin/teams/members_controller.rb b/app/controllers/admin/teams/members_controller.rb
new file mode 100644
index 00000000000..4037bff510e
--- /dev/null
+++ b/app/controllers/admin/teams/members_controller.rb
@@ -0,0 +1,35 @@
+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
diff --git a/app/models/user_team.rb b/app/models/user_team.rb
index d402fd22ea3..c9dfd671efc 100644
--- a/app/models/user_team.rb
+++ b/app/models/user_team.rb
@@ -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
diff --git a/app/views/admin/teams/members/_form.html.haml b/app/views/admin/teams/members/_form.html.haml
new file mode 100644
index 00000000000..b75d788a94a
--- /dev/null
+++ b/app/views/admin/teams/members/_form.html.haml
@@ -0,0 +1,20 @@
+= 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"
diff --git a/app/views/admin/teams/members/edit.html.haml b/app/views/admin/teams/members/edit.html.haml
new file mode 100644
index 00000000000..a82847ee5f8
--- /dev/null
+++ b/app/views/admin/teams/members/edit.html.haml
@@ -0,0 +1,16 @@
+%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'
diff --git a/app/views/admin/teams/members/new.html.haml b/app/views/admin/teams/members/new.html.haml
new file mode 100644
index 00000000000..5cdf07359c8
--- /dev/null
+++ b/app/views/admin/teams/members/new.html.haml
@@ -0,0 +1,29 @@
+%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
diff --git a/app/views/admin/teams/show.html.haml b/app/views/admin/teams/show.html.haml
index 0f47717ae0e..05a3a1d3e16 100644
--- a/app/views/admin/teams/show.html.haml
+++ b/app/views/admin/teams/show.html.haml
@@ -41,31 +41,30 @@
%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.cred Danger Zone!
- - @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.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"
+ %table#members_list
+ %thead
%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" }
+ %th User name
+ %th Default project access
+ %th Team access
+ %th.cred Danger Zone!
+ - @team.members.each do |member|
+ %tr.member
%td
- %span= check_box_tag :group_admin
- %span Admin?
- %td= submit_tag 'Add', class: "btn primary", id: :add_members_to_team
+ = link_to [:admin, member] do
+ = member.name
+ %small= "(#{member.email})"
+ %td= @team.human_default_projects_access(member)
+ %td= @team.admin?(member) ? "Admin" : "Member"
+ %td.bgred
+ = 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
+ %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})
diff --git a/config/routes.rb b/config/routes.rb
index 69ad2e68642..b15431e3455 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -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
diff --git a/lib/gitlab/user_team_manager.rb b/lib/gitlab/user_team_manager.rb
index d010c79223e..753081ea718 100644
--- a/lib/gitlab/user_team_manager.rb
+++ b/lib/gitlab/user_team_manager.rb
@@ -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|