BigW Consortium Gitlab

Commit e12c9ee2 by Dmitriy Zaporozhets

Added UsersGroup scaffold. Simplify adding people to group

parent c9fb7e39
......@@ -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()
......
class GroupMembers
constructor: ->
$('li.users_group').bind 'ajax:success', ->
$(this).fadeOut()
@GroupMembers = GroupMembers
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
......
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
......@@ -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
......@@ -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
......
= 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)
......
= 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"
%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
- 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
- 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
......@@ -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
#
......
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