Commit ea76b6bc authored by Phil Hughes's avatar Phil Hughes

Updates override value in DB

parent a046d9c1
......@@ -5,21 +5,50 @@
class Members {
constructor() {
this.addListeners();
this.initGLDropdown();
}
addListeners() {
const ldapPermissionsChangeBtns = document.querySelectorAll('.js-ldap-permissions');
const ldapOverrideBtns = document.querySelectorAll('.js-ldap-override');
ldapPermissionsChangeBtns.forEach((btn) => {
btn.addEventListener('click', this.showLDAPPermissionsWarning.bind(this));
});
ldapOverrideBtns.forEach((btn) => {
btn.addEventListener('click', this.toggleMemberAccessToggle.bind(this));
});
$('.project_member, .group_member').off('ajax:success').on('ajax:success', this.removeRow);
$('.js-member-update-control').off('change').on('change', this.formSubmit);
$('.js-edit-member-form').off('ajax:success').on('ajax:success', this.formSuccess);
gl.utils.disableButtonIfEmptyField('#user_ids', 'input[name=commit]', 'change');
}
initGLDropdown () {
$('.js-member-permissions-dropdown').each((i, btn) => {
const $btn = $(btn);
$btn.glDropdown({
selectable: true,
fieldName: 'test',
id () {
return 1;
},
clicked: (selected, $el) => {
const $link = $($el);
if ($link.data('revert')) {
const memberListitem = this.getMemberListItem($link.get(0));
this.overrideLdap(memberListitem, $link.data('endpoint'), false);
}
}
});
});
}
removeRow(e) {
const $target = $(e.target);
......@@ -40,9 +69,9 @@
}
showLDAPPermissionsWarning (e) {
const btn = e.currentTarget,
memberListItem = this.getMemberListItem(btn),
ldapPermissionsElement = memberListItem.nextElementSibling;
const btn = e.currentTarget;
const memberListItem = this.getMemberListItem(btn);
const ldapPermissionsElement = memberListItem.nextElementSibling;
if (ldapPermissionsElement.style.display === 'none') {
ldapPermissionsElement.style.display = 'block';
......@@ -55,8 +84,33 @@
return document.getElementById(btn.dataset.id);
}
toggleMemberAccessToggle (el) {
const toggle = el.querySelectorAll('.dropdown-menu-toggle')[0];
toggleMemberAccessToggle (e) {
const btn = e.currentTarget;
const memberListItem = this.getMemberListItem(btn);
const toggle = memberListItem.querySelectorAll('.dropdown-menu-toggle')[0];
this.showLDAPPermissionsWarning(e);
toggle.removeAttribute('disabled');
this.overrideLdap(memberListItem, btn.dataset.endpoint, true);
}
overrideLdap (memberListitem, endpoint, override) {
if (override) {
memberListitem.classList.add('is-overriden');
} else {
memberListitem.classList.remove('is-overriden');
}
return $.ajax({
url: endpoint,
type: 'PATCH',
data: {
group_member: {
override
}
}
})
}
}
......
......@@ -4,6 +4,12 @@
}
.member {
&.is-overriden {
.btn-ldap-override {
visibility: hidden;
}
}
.list-item-name {
@media (min-width: $screen-sm-min) {
float: left;
......
......@@ -43,6 +43,7 @@ class Groups::GroupMembersController < Groups::ApplicationController
def update
@group_member = @group.group_members.find(params[:id])
puts @group_member
return render_403 unless can?(current_user, :update_group_member, @group_member)
......@@ -81,7 +82,7 @@ class Groups::GroupMembersController < Groups::ApplicationController
protected
def member_params
params.require(:group_member).permit(:access_level, :user_id, :expires_at)
params.require(:group_member).permit(:access_level, :user_id, :expires_at, :override)
end
# MembershipActions concern
......
......@@ -16,6 +16,6 @@ class GroupMemberPolicy < BasePolicy
can! :destroy_group_member
end
cannot! :update_group_member if @subject.ldap
# cannot! :update_group_member if @subject.ldap
end
end
......@@ -4,7 +4,7 @@
- source = member.source
- can_admin_member = can?(current_user, action_member_permission(:update, member), member)
%li.member{ class: dom_class(member), id: dom_id(member) }
%li.member{ class: [dom_class(member), ("is-overriden" if member.override)], id: dom_id(member) }
%span.list-item-name
- if user
= image_tag avatar_icon(user, 40), class: "avatar s40", alt: ''
......@@ -53,7 +53,7 @@
= form_for member, remote: true, html: { class: 'form-horizontal js-edit-member-form' } do |f|
-# = f.select :access_level, options_for_select(member.class.access_level_roles, member.access_level), {}, class: 'form-control member-form-control append-right-5 js-member-update-control', id: "member_access_level_#{member.id}", disabled: !can_admin_member
.member-form-control.dropdown.append-right-5
%button.dropdown-menu-toggle{ type: "button",
%button.dropdown-menu-toggle.js-member-permissions-dropdown{ type: "button",
disabled: member.ldap && !member.override,
data: { toggle: "dropdown" } }
= member.human_access
......@@ -64,14 +64,15 @@
%ul
- Gitlab::Access.options.each do |role, role_id|
%li
%a{ href: "#",
%a{ href: "javascript:void(0)",
class: ("is-active" if member.access_level == role_id),
data: { id: role_id } }
= role
- if member.ldap
%li.divider
%li
%a{ href: "#" }
%a{ href: "javascript:void(0)",
data: { revert: "true", endpoint: group_group_member_path(@group, member), id: dom_id(member) } }
Revert to LDAP group sync settings
.prepend-left-5.clearable-input.member-form-control
= f.text_field :expires_at, class: 'form-control js-access-expiration-date js-member-update-control', placeholder: 'Expiration date', id: "member_expires_at_#{member.id}", disabled: !can_admin_member
......@@ -107,7 +108,7 @@
Delete
= icon('trash', class: 'hidden-xs')
- elsif member.ldap
%button.btn.btn-default.prepend-left-10.js-ldap-permissions{ type: "button",
%button.btn.btn-default.btn-ldap-override.prepend-left-10.js-ldap-permissions{ type: "button",
"aria-label" => "Override LDAP settings",
data: { name: user.name, id: dom_id(member) } }
= icon("pencil")
......@@ -119,8 +120,9 @@
= user.name
is currently an LDAP user. Editing their permissions will override the settings from the LDAP group sync.
.controls
%button.btn.btn-warning{ type: "button",
"aria-label" => "Change LDAP member permissions" }
%button.btn.btn-warning.js-ldap-override{ type: "button",
"aria-label" => "Change LDAP member permissions",
data: { id: dom_id(member), endpoint: group_group_member_path(@group, member) } }
Change permissions
%button.btn.btn-default.js-ldap-permissions{ type: "button",
"aria-label" => "Close permissions override",
......
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