Commit ad58dec2 authored by Jose Ivan Vargas's avatar Jose Ivan Vargas

Added groups to members section, added a members finder

parent def6c43d
......@@ -215,8 +215,9 @@
new gl.Members();
new UsersSelect();
break;
case 'projects:project_members:index':
case 'projects:members:show':
new gl.MemberExpirationDate('.js-access-expiration-date-groups');
new GroupsSelect();
new gl.MemberExpirationDate();
new gl.Members();
new UsersSelect();
......@@ -262,10 +263,6 @@
case 'projects:artifacts:browse':
new BuildArtifacts();
break;
case 'projects:group_links:index':
new gl.MemberExpirationDate();
new GroupsSelect();
break;
case 'search:show':
new Search();
break;
......
......@@ -5,12 +5,16 @@
// `js-clear-input` element, then show that element when there is a value in the
// datepicker, and make clicking on that element clear the field.
//
gl.MemberExpirationDate = function() {
gl.MemberExpirationDate = function(newSelector) {
function toggleClearInput() {
$(this).closest('.clearable-input').toggleClass('has-value', $(this).val() !== '');
}
var inputs = $('.js-access-expiration-date');
var selector = '.js-access-expiration-date';
if (typeof newSelector !== 'undefined' && newSelector !== '') {
selector = newSelector;
}
var inputs = $(selector);
inputs.datepicker({
dateFormat: 'yy-mm-dd',
......@@ -24,7 +28,7 @@
inputs.next('.js-clear-input').on('click', function(event) {
event.preventDefault();
var input = $(this).closest('.clearable-input').find('.js-access-expiration-date');
var input = $(this).closest('.clearable-input').find(selector);
input.datepicker('setDate', null)
.trigger('change');
toggleClearInput.call(input);
......
......@@ -4,10 +4,7 @@ class Projects::GroupLinksController < Projects::ApplicationController
before_action :authorize_admin_project_member!, only: [:update]
def index
@group_links = project.project_group_links.all
@skip_groups = @group_links.pluck(:group_id)
@skip_groups << project.namespace_id unless project.personal?
redirect_to namespace_project_settings_members_path
end
def create
......@@ -19,7 +16,7 @@ class Projects::GroupLinksController < Projects::ApplicationController
project.project_group_links.create(
group: group,
group_access: params[:link_group_access],
expires_at: params[:expires_at]
expires_at: params[:expires_at] || params[:expires_at_groups]
)
else
flash[:alert] = 'Please select a group.'
......
......@@ -2,7 +2,7 @@ module Projects
module Settings
class MembersController < Projects::ApplicationController
include SortingHelper
def show
@sort = params[:sort].presence || sort_value_name
@group_links = @project.project_group_links
......@@ -12,15 +12,18 @@ module Projects
group = @project.group
# group links
@group_links = @project.project_group_links.all
@skip_groups = @group_links.pluck(:group_id)
@skip_groups << @project.namespace_id unless project.personal?
if group
# We need `.where.not(user_id: nil)` here otherwise when a group has an
# invitee, it would make the following query return 0 rows since a NULL
# user_id would be present in the subquery
# See http://stackoverflow.com/questions/129077/not-in-clause-and-null-values
# FIXME: This whole logic should be moved to a finder!
non_null_user_ids = @project_members.where.not(user_id: nil).select(:user_id)
group_members = group.group_members.where.not(user_id: non_null_user_ids)
group_members = group_members.non_invite unless can?(current_user, :admin_group, @group)
group_members = MembersFinder.new(@project, @group)
end
if params[:search].present?
......
class MembersFinder < Projects::ApplicationController
def initialize(project_members, group)
@project_members = project_members
@group = group
end
def execute
non_null_user_ids = @project_members.where.not(user_id: nil).select(:user_id)
group_members = @group.group_members.where.not(user_id: non_null_user_ids)
group_members = group_members.non_invite unless can?(current_user, :admin_group, @group)
group_members
end
end
......@@ -20,7 +20,7 @@
.form-group
= label_tag :expires_at, 'Access expiration date', class: 'label-light'
.clearable-input
= text_field_tag :expires_at, nil, class: 'form-control js-access-expiration-date', placeholder: 'Select access expiration date'
= text_field_tag :expires_at_groups, nil, class: 'form-control js-access-expiration-date-groups', placeholder: 'Select access expiration date'
%i.clear-icon.js-clear-input
.help-block
On this date, all users in the group will automatically lose access to this project.
......
- page_title "Members"
=render "projects/project_members/index"
= render "projects/project_members/index"
= render "projects/group_links/index"
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