diff --git a/app/assets/javascripts/dispatcher.js.coffee b/app/assets/javascripts/dispatcher.js.coffee index fb149b7f677..ce53d14d671 100644 --- a/app/assets/javascripts/dispatcher.js.coffee +++ b/app/assets/javascripts/dispatcher.js.coffee @@ -32,6 +32,8 @@ class Dispatcher new Wall(project_id) when 'teams:members:index' new TeamMembers() + when 'groups:people' + new GroupMembers() switch path.first() when 'admin' then new Admin() diff --git a/app/assets/javascripts/groups.js.coffee b/app/assets/javascripts/groups.js.coffee new file mode 100644 index 00000000000..c0ffccd8f70 --- /dev/null +++ b/app/assets/javascripts/groups.js.coffee @@ -0,0 +1,6 @@ +class GroupMembers + constructor: -> + $('li.users_group').bind 'ajax:success', -> + $(this).fadeOut() + +@GroupMembers = GroupMembers diff --git a/app/controllers/groups_controller.rb b/app/controllers/groups_controller.rb index a191aff2b6b..617cfddd21a 100644 --- a/app/controllers/groups_controller.rb +++ b/app/controllers/groups_controller.rb @@ -1,6 +1,6 @@ class GroupsController < ApplicationController respond_to :html - before_filter :group, except: [:new, :create] + before_filter :group, except: [:new, :create, :people] # Authorize before_filter :authorize_read_group!, except: [:new, :create] @@ -63,20 +63,8 @@ class GroupsController < ApplicationController def people @project = group.projects.find(params[:project_id]) if params[:project_id] - - if @project - @members = @project.users_projects - @team_member = @project.users_projects.new - else - @members = group.users_groups - @team_member = UsersGroup.new - end - end - - def team_members - @group.add_users(params[:user_ids].split(','), params[:group_access]) - - redirect_to people_group_path(@group), notice: 'Users were successfully added.' + @members = group.users_groups + @users_group = UsersGroup.new end def edit diff --git a/app/controllers/users_groups_controller.rb b/app/controllers/users_groups_controller.rb new file mode 100644 index 00000000000..ebc79d621a4 --- /dev/null +++ b/app/controllers/users_groups_controller.rb @@ -0,0 +1,40 @@ +class UsersGroupsController < ApplicationController + before_filter :group + + # Authorize + before_filter :authorize_admin_group! + + layout 'group' + + def create + @group.add_users(params[:user_ids].split(','), params[:group_access]) + + redirect_to people_group_path(@group), notice: 'Users were successfully added.' + end + + def update + # TODO: implement + end + + def destroy + @users_group = @group.users_groups.find(params[:id]) + @users_group.destroy + + respond_to do |format| + format.html { redirect_to people_group_path(@group), notice: 'User was successfully removed from group.' } + format.js { render nothing: true } + end + end + + protected + + def group + @group ||= Group.find_by_path(params[:group_id]) + end + + def authorize_admin_group! + unless can?(current_user, :manage_group, group) + return render_404 + end + end +end diff --git a/app/helpers/groups_helper.rb b/app/helpers/groups_helper.rb index 283119bc24c..2ffbff7af8d 100644 --- a/app/helpers/groups_helper.rb +++ b/app/helpers/groups_helper.rb @@ -14,4 +14,8 @@ module GroupsHelper merge_requests_group_path(@group, options) end end + + def remove_user_from_group_message(group, user) + "You are going to remove #{user.name} from #{group.name} Group. Are you sure?" + end end diff --git a/app/models/users_group.rb b/app/models/users_group.rb index e9caa3fe705..de24ab39282 100644 --- a/app/models/users_group.rb +++ b/app/models/users_group.rb @@ -32,6 +32,7 @@ class UsersGroup < ActiveRecord::Base validates :group_access, inclusion: { in: UsersGroup.group_access_roles.values }, presence: true validates :user_id, presence: true validates :group_id, presence: true + validates :user_id, uniqueness: { scope: [:group_id], message: "already exists in group" } delegate :name, :username, :email, to: :user, prefix: true diff --git a/app/views/groups/_new_group_member.html.haml b/app/views/groups/_new_group_member.html.haml index bc1b12f257d..786a52a6011 100644 --- a/app/views/groups/_new_group_member.html.haml +++ b/app/views/groups/_new_group_member.html.haml @@ -1,16 +1,16 @@ -= form_for @team_member, as: :team_member, url: team_members_group_path(@group) do |f| += form_for @users_group, url: group_users_groups_path(@group) do |f| %fieldset %legend= "New Group member(s) for #{@group.name}" %h6 1. Choose people you want in the group .clearfix = f.label :user_ids, "People" - .input= users_select_tag(:user_ids, multiple: true) + .input= users_select_tag(:user_ids, multiple: true, class: 'input-large') %h6 2. Set access level for them .clearfix = f.label :group_access, "Group Access" - .input= select_tag :group_access, options_for_select(UsersGroup.group_access_roles, @team_member.group_access), class: "project-access-select chosen" + .input= select_tag :group_access, options_for_select(UsersGroup.group_access_roles, @users_group.group_access), class: "project-access-select chosen" .form-actions = hidden_field_tag :redirect_to, people_group_path(@group) diff --git a/app/views/groups/_new_member.html.haml b/app/views/groups/_new_member.html.haml deleted file mode 100644 index 70c3e8cd248..00000000000 --- a/app/views/groups/_new_member.html.haml +++ /dev/null @@ -1,18 +0,0 @@ -= form_for @team_member, as: :team_member, url: project_team_members_path(@project, @team_member) do |f| - %fieldset - %legend= "New Project member(s) for #{@project.name}" - - %h6 1. Choose people you want in the project - .clearfix - = f.label :user_ids, "People" - .input= users_select_tag(:user_ids, multiple: true) - - %h6 2. Set access level for them - .clearfix - = f.label :project_access, "Project Access" - .input= select_tag :project_access, options_for_select(Project.access_options, @team_member.project_access), class: "project-access-select chosen" - - .form-actions - = hidden_field_tag :redirect_to, people_group_path(@group, project_id: @project.id) - = f.submit 'Add users into project', class: "btn btn-create" - diff --git a/app/views/groups/_people_filter.html.haml b/app/views/groups/_people_filter.html.haml deleted file mode 100644 index 598b1e7b979..00000000000 --- a/app/views/groups/_people_filter.html.haml +++ /dev/null @@ -1,22 +0,0 @@ -%fieldset - %legend Group members: - %ul.nav.nav-pills.nav-stacked - %li{class: ("active" if params[:project_id].blank?)} - = link_to people_group_path(@group) do - #{@group.name} Group - %small.pull-right= @group.users.count - - -= form_tag people_group_path(@group), method: 'get' do - %fieldset - %legend Project members: - %ul.nav.nav-pills.nav-stacked - - @projects.each do |project| - %li{class: ("active" if params[:project_id] == project.id.to_s)} - = link_to people_group_path(@group, project_id: project.id) do - = project.name_with_namespace - %small.pull-right= project.users.count - - if @projects.blank? - %p.nothing_here_message This group has no projects yet - - diff --git a/app/views/groups/people.html.haml b/app/views/groups/people.html.haml index 39657a084ca..4c082537a43 100644 --- a/app/views/groups/people.html.haml +++ b/app/views/groups/people.html.haml @@ -1,19 +1,15 @@ +- can_manage_group = current_user.can? :manage_group, @group .row - .span3 - = render 'people_filter' - .span9 - - if can?(current_user, :manage_group, @group) - = render (@project ? "new_member" : "new_group_member") + .span6 + = render "new_group_member" + .span6 .ui-box %h5.title - - if @project - #{@project.name} Project Members - %small - (#{@members.count}) - - else - #{@group.name} Group Members - %small - (#{@members.count}) + #{@group.name} Group Members + %small + (#{@members.count}) %ul.well-list - @members.each do |member| - = render 'users_groups/users_group', member: member + = render 'users_groups/users_group', member: member, show_controls: can_manage_group + %p.light + Group members get access to all projects in this group diff --git a/app/views/users_groups/_users_group.html.haml b/app/views/users_groups/_users_group.html.haml index 75f6d1182db..31a829952ac 100644 --- a/app/views/users_groups/_users_group.html.haml +++ b/app/views/users_groups/_users_group.html.haml @@ -1,6 +1,6 @@ - user = member.user - return unless user -%li +%li{class: dom_class(member)} = image_tag gravatar_icon(user.email, 16), class: "avatar s16" %strong= user.name %span.cgray= user.username @@ -10,3 +10,7 @@ %span.label.label-info Group Owner - else = member.human_access + + - if show_controls && user != current_user + = link_to group_users_group_path(@group, member), confirm: remove_user_from_group_message(@group, user), method: :delete, remote: true, class: "btn-tiny btn btn-remove", title: 'Remove user from group' do + %i.icon-minus.icon-white diff --git a/config/routes.rb b/config/routes.rb index 39c79635c40..b431cb23c83 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -149,10 +149,10 @@ Gitlab::Application.routes.draw do member do get :issues get :merge_requests - get :search get :people - post :team_members end + + resources :users_groups, only: [:create, :update, :destroy] end #