Commit e12c9ee2bc76026b146ea1b29fd0acc5ac696d34
1 parent
c9fb7e39
Exists in
master
and in
4 other branches
Added UsersGroup scaffold. Simplify adding people to group
Showing
12 changed files
with
76 additions
and
75 deletions
Show diff stats
app/assets/javascripts/dispatcher.js.coffee
app/controllers/groups_controller.rb
| 1 | 1 | class GroupsController < ApplicationController |
| 2 | 2 | respond_to :html |
| 3 | - before_filter :group, except: [:new, :create] | |
| 3 | + before_filter :group, except: [:new, :create, :people] | |
| 4 | 4 | |
| 5 | 5 | # Authorize |
| 6 | 6 | before_filter :authorize_read_group!, except: [:new, :create] |
| ... | ... | @@ -63,20 +63,8 @@ class GroupsController < ApplicationController |
| 63 | 63 | |
| 64 | 64 | def people |
| 65 | 65 | @project = group.projects.find(params[:project_id]) if params[:project_id] |
| 66 | - | |
| 67 | - if @project | |
| 68 | - @members = @project.users_projects | |
| 69 | - @team_member = @project.users_projects.new | |
| 70 | - else | |
| 71 | - @members = group.users_groups | |
| 72 | - @team_member = UsersGroup.new | |
| 73 | - end | |
| 74 | - end | |
| 75 | - | |
| 76 | - def team_members | |
| 77 | - @group.add_users(params[:user_ids].split(','), params[:group_access]) | |
| 78 | - | |
| 79 | - redirect_to people_group_path(@group), notice: 'Users were successfully added.' | |
| 66 | + @members = group.users_groups | |
| 67 | + @users_group = UsersGroup.new | |
| 80 | 68 | end |
| 81 | 69 | |
| 82 | 70 | def edit | ... | ... |
| ... | ... | @@ -0,0 +1,40 @@ |
| 1 | +class UsersGroupsController < ApplicationController | |
| 2 | + before_filter :group | |
| 3 | + | |
| 4 | + # Authorize | |
| 5 | + before_filter :authorize_admin_group! | |
| 6 | + | |
| 7 | + layout 'group' | |
| 8 | + | |
| 9 | + def create | |
| 10 | + @group.add_users(params[:user_ids].split(','), params[:group_access]) | |
| 11 | + | |
| 12 | + redirect_to people_group_path(@group), notice: 'Users were successfully added.' | |
| 13 | + end | |
| 14 | + | |
| 15 | + def update | |
| 16 | + # TODO: implement | |
| 17 | + end | |
| 18 | + | |
| 19 | + def destroy | |
| 20 | + @users_group = @group.users_groups.find(params[:id]) | |
| 21 | + @users_group.destroy | |
| 22 | + | |
| 23 | + respond_to do |format| | |
| 24 | + format.html { redirect_to people_group_path(@group), notice: 'User was successfully removed from group.' } | |
| 25 | + format.js { render nothing: true } | |
| 26 | + end | |
| 27 | + end | |
| 28 | + | |
| 29 | + protected | |
| 30 | + | |
| 31 | + def group | |
| 32 | + @group ||= Group.find_by_path(params[:group_id]) | |
| 33 | + end | |
| 34 | + | |
| 35 | + def authorize_admin_group! | |
| 36 | + unless can?(current_user, :manage_group, group) | |
| 37 | + return render_404 | |
| 38 | + end | |
| 39 | + end | |
| 40 | +end | ... | ... |
app/helpers/groups_helper.rb
app/models/users_group.rb
| ... | ... | @@ -32,6 +32,7 @@ class UsersGroup < ActiveRecord::Base |
| 32 | 32 | validates :group_access, inclusion: { in: UsersGroup.group_access_roles.values }, presence: true |
| 33 | 33 | validates :user_id, presence: true |
| 34 | 34 | validates :group_id, presence: true |
| 35 | + validates :user_id, uniqueness: { scope: [:group_id], message: "already exists in group" } | |
| 35 | 36 | |
| 36 | 37 | delegate :name, :username, :email, to: :user, prefix: true |
| 37 | 38 | ... | ... |
app/views/groups/_new_group_member.html.haml
| 1 | -= form_for @team_member, as: :team_member, url: team_members_group_path(@group) do |f| | |
| 1 | += form_for @users_group, url: group_users_groups_path(@group) do |f| | |
| 2 | 2 | %fieldset |
| 3 | 3 | %legend= "New Group member(s) for #{@group.name}" |
| 4 | 4 | |
| 5 | 5 | %h6 1. Choose people you want in the group |
| 6 | 6 | .clearfix |
| 7 | 7 | = f.label :user_ids, "People" |
| 8 | - .input= users_select_tag(:user_ids, multiple: true) | |
| 8 | + .input= users_select_tag(:user_ids, multiple: true, class: 'input-large') | |
| 9 | 9 | |
| 10 | 10 | %h6 2. Set access level for them |
| 11 | 11 | .clearfix |
| 12 | 12 | = f.label :group_access, "Group Access" |
| 13 | - .input= select_tag :group_access, options_for_select(UsersGroup.group_access_roles, @team_member.group_access), class: "project-access-select chosen" | |
| 13 | + .input= select_tag :group_access, options_for_select(UsersGroup.group_access_roles, @users_group.group_access), class: "project-access-select chosen" | |
| 14 | 14 | |
| 15 | 15 | .form-actions |
| 16 | 16 | = hidden_field_tag :redirect_to, people_group_path(@group) | ... | ... |
app/views/groups/_new_member.html.haml
| ... | ... | @@ -1,18 +0,0 @@ |
| 1 | -= form_for @team_member, as: :team_member, url: project_team_members_path(@project, @team_member) do |f| | |
| 2 | - %fieldset | |
| 3 | - %legend= "New Project member(s) for #{@project.name}" | |
| 4 | - | |
| 5 | - %h6 1. Choose people you want in the project | |
| 6 | - .clearfix | |
| 7 | - = f.label :user_ids, "People" | |
| 8 | - .input= users_select_tag(:user_ids, multiple: true) | |
| 9 | - | |
| 10 | - %h6 2. Set access level for them | |
| 11 | - .clearfix | |
| 12 | - = f.label :project_access, "Project Access" | |
| 13 | - .input= select_tag :project_access, options_for_select(Project.access_options, @team_member.project_access), class: "project-access-select chosen" | |
| 14 | - | |
| 15 | - .form-actions | |
| 16 | - = hidden_field_tag :redirect_to, people_group_path(@group, project_id: @project.id) | |
| 17 | - = f.submit 'Add users into project', class: "btn btn-create" | |
| 18 | - |
app/views/groups/_people_filter.html.haml
| ... | ... | @@ -1,22 +0,0 @@ |
| 1 | -%fieldset | |
| 2 | - %legend Group members: | |
| 3 | - %ul.nav.nav-pills.nav-stacked | |
| 4 | - %li{class: ("active" if params[:project_id].blank?)} | |
| 5 | - = link_to people_group_path(@group) do | |
| 6 | - #{@group.name} Group | |
| 7 | - %small.pull-right= @group.users.count | |
| 8 | - | |
| 9 | - | |
| 10 | -= form_tag people_group_path(@group), method: 'get' do | |
| 11 | - %fieldset | |
| 12 | - %legend Project members: | |
| 13 | - %ul.nav.nav-pills.nav-stacked | |
| 14 | - - @projects.each do |project| | |
| 15 | - %li{class: ("active" if params[:project_id] == project.id.to_s)} | |
| 16 | - = link_to people_group_path(@group, project_id: project.id) do | |
| 17 | - = project.name_with_namespace | |
| 18 | - %small.pull-right= project.users.count | |
| 19 | - - if @projects.blank? | |
| 20 | - %p.nothing_here_message This group has no projects yet | |
| 21 | - | |
| 22 | - |
app/views/groups/people.html.haml
| 1 | +- can_manage_group = current_user.can? :manage_group, @group | |
| 1 | 2 | .row |
| 2 | - .span3 | |
| 3 | - = render 'people_filter' | |
| 4 | - .span9 | |
| 5 | - - if can?(current_user, :manage_group, @group) | |
| 6 | - = render (@project ? "new_member" : "new_group_member") | |
| 3 | + .span6 | |
| 4 | + = render "new_group_member" | |
| 5 | + .span6 | |
| 7 | 6 | .ui-box |
| 8 | 7 | %h5.title |
| 9 | - - if @project | |
| 10 | - #{@project.name} Project Members | |
| 11 | - %small | |
| 12 | - (#{@members.count}) | |
| 13 | - - else | |
| 14 | - #{@group.name} Group Members | |
| 15 | - %small | |
| 16 | - (#{@members.count}) | |
| 8 | + #{@group.name} Group Members | |
| 9 | + %small | |
| 10 | + (#{@members.count}) | |
| 17 | 11 | %ul.well-list |
| 18 | 12 | - @members.each do |member| |
| 19 | - = render 'users_groups/users_group', member: member | |
| 13 | + = render 'users_groups/users_group', member: member, show_controls: can_manage_group | |
| 14 | + %p.light | |
| 15 | + Group members get access to all projects in this group | ... | ... |
app/views/users_groups/_users_group.html.haml
| 1 | 1 | - user = member.user |
| 2 | 2 | - return unless user |
| 3 | -%li | |
| 3 | +%li{class: dom_class(member)} | |
| 4 | 4 | = image_tag gravatar_icon(user.email, 16), class: "avatar s16" |
| 5 | 5 | %strong= user.name |
| 6 | 6 | %span.cgray= user.username |
| ... | ... | @@ -10,3 +10,7 @@ |
| 10 | 10 | %span.label.label-info Group Owner |
| 11 | 11 | - else |
| 12 | 12 | = member.human_access |
| 13 | + | |
| 14 | + - if show_controls && user != current_user | |
| 15 | + = 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 | |
| 16 | + %i.icon-minus.icon-white | ... | ... |
config/routes.rb
| ... | ... | @@ -149,10 +149,10 @@ Gitlab::Application.routes.draw do |
| 149 | 149 | member do |
| 150 | 150 | get :issues |
| 151 | 151 | get :merge_requests |
| 152 | - get :search | |
| 153 | 152 | get :people |
| 154 | - post :team_members | |
| 155 | 153 | end |
| 154 | + | |
| 155 | + resources :users_groups, only: [:create, :update, :destroy] | |
| 156 | 156 | end |
| 157 | 157 | |
| 158 | 158 | # | ... | ... |