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