|
|
@ -9,9 +9,9 @@ define('admin/manage/privileges', [
|
|
|
|
'mousetrap',
|
|
|
|
'mousetrap',
|
|
|
|
'admin/modules/checkboxRowSelector',
|
|
|
|
'admin/modules/checkboxRowSelector',
|
|
|
|
], function (api, autocomplete, bootbox, translator, categorySelector, mousetrap, checkboxRowSelector) {
|
|
|
|
], function (api, autocomplete, bootbox, translator, categorySelector, mousetrap, checkboxRowSelector) {
|
|
|
|
var Privileges = {};
|
|
|
|
const Privileges = {};
|
|
|
|
|
|
|
|
|
|
|
|
var cid;
|
|
|
|
let cid;
|
|
|
|
// number of columns to skip in category privilege tables
|
|
|
|
// number of columns to skip in category privilege tables
|
|
|
|
const SKIP_PRIV_COLS = 3;
|
|
|
|
const SKIP_PRIV_COLS = 3;
|
|
|
|
|
|
|
|
|
|
|
@ -40,16 +40,16 @@ define('admin/manage/privileges', [
|
|
|
|
|
|
|
|
|
|
|
|
Privileges.setupPrivilegeTable = function () {
|
|
|
|
Privileges.setupPrivilegeTable = function () {
|
|
|
|
$('.privilege-table-container').on('change', 'input[type="checkbox"]:not(.checkbox-helper)', function () {
|
|
|
|
$('.privilege-table-container').on('change', 'input[type="checkbox"]:not(.checkbox-helper)', function () {
|
|
|
|
var checkboxEl = $(this);
|
|
|
|
const checkboxEl = $(this);
|
|
|
|
var wrapperEl = checkboxEl.parent();
|
|
|
|
const wrapperEl = checkboxEl.parent();
|
|
|
|
var privilege = wrapperEl.attr('data-privilege');
|
|
|
|
const privilege = wrapperEl.attr('data-privilege');
|
|
|
|
var state = checkboxEl.prop('checked');
|
|
|
|
const state = checkboxEl.prop('checked');
|
|
|
|
var rowEl = checkboxEl.parents('tr');
|
|
|
|
const rowEl = checkboxEl.parents('tr');
|
|
|
|
var member = rowEl.attr('data-group-name') || rowEl.attr('data-uid');
|
|
|
|
const member = rowEl.attr('data-group-name') || rowEl.attr('data-uid');
|
|
|
|
var isPrivate = parseInt(rowEl.attr('data-private') || 0, 10);
|
|
|
|
const isPrivate = parseInt(rowEl.attr('data-private') || 0, 10);
|
|
|
|
var isGroup = rowEl.attr('data-group-name') !== undefined;
|
|
|
|
const isGroup = rowEl.attr('data-group-name') !== undefined;
|
|
|
|
var isBanned = (isGroup && rowEl.attr('data-group-name') === 'banned-users') || rowEl.attr('data-banned') !== undefined;
|
|
|
|
const isBanned = (isGroup && rowEl.attr('data-group-name') === 'banned-users') || rowEl.attr('data-banned') !== undefined;
|
|
|
|
var delta = checkboxEl.prop('checked') === (wrapperEl.attr('data-value') === 'true') ? null : state;
|
|
|
|
const delta = checkboxEl.prop('checked') === (wrapperEl.attr('data-value') === 'true') ? null : state;
|
|
|
|
|
|
|
|
|
|
|
|
if (member) {
|
|
|
|
if (member) {
|
|
|
|
if (isGroup && privilege === 'groups:moderate' && !isPrivate && state) {
|
|
|
|
if (isGroup && privilege === 'groups:moderate' && !isPrivate && state) {
|
|
|
@ -110,7 +110,7 @@ define('admin/manage/privileges', [
|
|
|
|
throwConfirmModal('copyToChildren', Privileges.copyPrivilegesToChildren.bind(null, cid, ''));
|
|
|
|
throwConfirmModal('copyToChildren', Privileges.copyPrivilegesToChildren.bind(null, cid, ''));
|
|
|
|
});
|
|
|
|
});
|
|
|
|
$privTableCon.on('click', '[data-action="copyToChildrenGroup"]', function () {
|
|
|
|
$privTableCon.on('click', '[data-action="copyToChildrenGroup"]', function () {
|
|
|
|
var groupName = $(this).parents('[data-group-name]').attr('data-group-name');
|
|
|
|
const groupName = $(this).parents('[data-group-name]').attr('data-group-name');
|
|
|
|
throwConfirmModal('copyToChildrenGroup', Privileges.copyPrivilegesToChildren.bind(null, cid, groupName));
|
|
|
|
throwConfirmModal('copyToChildrenGroup', Privileges.copyPrivilegesToChildren.bind(null, cid, groupName));
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
@ -118,7 +118,7 @@ define('admin/manage/privileges', [
|
|
|
|
Privileges.copyPrivilegesFromCategory(cid, '');
|
|
|
|
Privileges.copyPrivilegesFromCategory(cid, '');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
$privTableCon.on('click', '[data-action="copyPrivilegesFromGroup"]', function () {
|
|
|
|
$privTableCon.on('click', '[data-action="copyPrivilegesFromGroup"]', function () {
|
|
|
|
var groupName = $(this).parents('[data-group-name]').attr('data-group-name');
|
|
|
|
const groupName = $(this).parents('[data-group-name]').attr('data-group-name');
|
|
|
|
Privileges.copyPrivilegesFromCategory(cid, groupName);
|
|
|
|
Privileges.copyPrivilegesFromCategory(cid, groupName);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
@ -126,7 +126,7 @@ define('admin/manage/privileges', [
|
|
|
|
throwConfirmModal('copyToAll', Privileges.copyPrivilegesToAllCategories.bind(null, cid, ''));
|
|
|
|
throwConfirmModal('copyToAll', Privileges.copyPrivilegesToAllCategories.bind(null, cid, ''));
|
|
|
|
});
|
|
|
|
});
|
|
|
|
$privTableCon.on('click', '[data-action="copyToAllGroup"]', function () {
|
|
|
|
$privTableCon.on('click', '[data-action="copyToAllGroup"]', function () {
|
|
|
|
var groupName = $(this).parents('[data-group-name]').attr('data-group-name');
|
|
|
|
const groupName = $(this).parents('[data-group-name]').attr('data-group-name');
|
|
|
|
throwConfirmModal('copyToAllGroup', Privileges.copyPrivilegesToAllCategories.bind(null, cid, groupName));
|
|
|
|
throwConfirmModal('copyToAllGroup', Privileges.copyPrivilegesToAllCategories.bind(null, cid, groupName));
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
@ -148,12 +148,12 @@ define('admin/manage/privileges', [
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
Privileges.commit = function () {
|
|
|
|
Privileges.commit = function () {
|
|
|
|
var tableEl = document.querySelector('.privilege-table-container');
|
|
|
|
const tableEl = document.querySelector('.privilege-table-container');
|
|
|
|
var requests = $.map(tableEl.querySelectorAll('td[data-delta]'), function (el) {
|
|
|
|
const requests = $.map(tableEl.querySelectorAll('td[data-delta]'), function (el) {
|
|
|
|
var privilege = el.getAttribute('data-privilege');
|
|
|
|
const privilege = el.getAttribute('data-privilege');
|
|
|
|
var rowEl = el.parentNode;
|
|
|
|
const rowEl = el.parentNode;
|
|
|
|
var member = rowEl.getAttribute('data-group-name') || rowEl.getAttribute('data-uid');
|
|
|
|
const member = rowEl.getAttribute('data-group-name') || rowEl.getAttribute('data-uid');
|
|
|
|
var state = el.getAttribute('data-delta') === 'true' ? 1 : 0;
|
|
|
|
const state = el.getAttribute('data-delta') === 'true' ? 1 : 0;
|
|
|
|
|
|
|
|
|
|
|
|
return Privileges.setPrivilege(member, privilege, state);
|
|
|
|
return Privileges.setPrivilege(member, privilege, state);
|
|
|
|
});
|
|
|
|
});
|
|
|
@ -180,7 +180,7 @@ define('admin/manage/privileges', [
|
|
|
|
Privileges.refreshPrivilegeTable = function (groupToHighlight) {
|
|
|
|
Privileges.refreshPrivilegeTable = function (groupToHighlight) {
|
|
|
|
api.get(`/categories/${cid}/privileges`, {}).then((privileges) => {
|
|
|
|
api.get(`/categories/${cid}/privileges`, {}).then((privileges) => {
|
|
|
|
ajaxify.data.privileges = { ...ajaxify.data.privileges, ...privileges };
|
|
|
|
ajaxify.data.privileges = { ...ajaxify.data.privileges, ...privileges };
|
|
|
|
var tpl = parseInt(cid, 10) ? 'admin/partials/privileges/category' : 'admin/partials/privileges/global';
|
|
|
|
const tpl = parseInt(cid, 10) ? 'admin/partials/privileges/category' : 'admin/partials/privileges/global';
|
|
|
|
app.parseAndTranslate(tpl, { privileges }).then((html) => {
|
|
|
|
app.parseAndTranslate(tpl, { privileges }).then((html) => {
|
|
|
|
// Get currently selected filters
|
|
|
|
// Get currently selected filters
|
|
|
|
const btnIndices = $('.privilege-filters button.btn-warning').map((idx, el) => $(el).index()).get();
|
|
|
|
const btnIndices = $('.privilege-filters button.btn-warning').map((idx, el) => $(el).index()).get();
|
|
|
@ -224,14 +224,14 @@ define('admin/manage/privileges', [
|
|
|
|
Privileges.setPrivilege = (member, privilege, state) => api[state ? 'put' : 'delete'](`/categories/${isNaN(cid) ? 0 : cid}/privileges/${privilege}`, { member });
|
|
|
|
Privileges.setPrivilege = (member, privilege, state) => api[state ? 'put' : 'delete'](`/categories/${isNaN(cid) ? 0 : cid}/privileges/${privilege}`, { member });
|
|
|
|
|
|
|
|
|
|
|
|
Privileges.addUserToPrivilegeTable = function () {
|
|
|
|
Privileges.addUserToPrivilegeTable = function () {
|
|
|
|
var modal = bootbox.dialog({
|
|
|
|
const modal = bootbox.dialog({
|
|
|
|
title: '[[admin/manage/categories:alert.find-user]]',
|
|
|
|
title: '[[admin/manage/categories:alert.find-user]]',
|
|
|
|
message: '<input class="form-control input-lg" placeholder="[[admin/manage/categories:alert.user-search]]" />',
|
|
|
|
message: '<input class="form-control input-lg" placeholder="[[admin/manage/categories:alert.user-search]]" />',
|
|
|
|
show: true,
|
|
|
|
show: true,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
modal.on('shown.bs.modal', function () {
|
|
|
|
modal.on('shown.bs.modal', function () {
|
|
|
|
var inputEl = modal.find('input');
|
|
|
|
const inputEl = modal.find('input');
|
|
|
|
inputEl.focus();
|
|
|
|
inputEl.focus();
|
|
|
|
|
|
|
|
|
|
|
|
autocomplete.user(inputEl, function (ev, ui) {
|
|
|
|
autocomplete.user(inputEl, function (ev, ui) {
|
|
|
@ -243,14 +243,14 @@ define('admin/manage/privileges', [
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
Privileges.addGroupToPrivilegeTable = function () {
|
|
|
|
Privileges.addGroupToPrivilegeTable = function () {
|
|
|
|
var modal = bootbox.dialog({
|
|
|
|
const modal = bootbox.dialog({
|
|
|
|
title: '[[admin/manage/categories:alert.find-group]]',
|
|
|
|
title: '[[admin/manage/categories:alert.find-group]]',
|
|
|
|
message: '<input class="form-control input-lg" placeholder="[[admin/manage/categories:alert.group-search]]" />',
|
|
|
|
message: '<input class="form-control input-lg" placeholder="[[admin/manage/categories:alert.group-search]]" />',
|
|
|
|
show: true,
|
|
|
|
show: true,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
modal.on('shown.bs.modal', function () {
|
|
|
|
modal.on('shown.bs.modal', function () {
|
|
|
|
var inputEl = modal.find('input');
|
|
|
|
const inputEl = modal.find('input');
|
|
|
|
inputEl.focus();
|
|
|
|
inputEl.focus();
|
|
|
|
|
|
|
|
|
|
|
|
autocomplete.group(inputEl, function (ev, ui) {
|
|
|
|
autocomplete.group(inputEl, function (ev, ui) {
|
|
|
@ -347,7 +347,7 @@ define('admin/manage/privileges', [
|
|
|
|
|
|
|
|
|
|
|
|
function hightlightRowByDataAttr(attrName, attrValue) {
|
|
|
|
function hightlightRowByDataAttr(attrName, attrValue) {
|
|
|
|
if (attrValue) {
|
|
|
|
if (attrValue) {
|
|
|
|
var el = $('[' + attrName + ']').filter(function () {
|
|
|
|
const el = $('[' + attrName + ']').filter(function () {
|
|
|
|
return $(this).attr(attrName) === String(attrValue);
|
|
|
|
return $(this).attr(attrName) === String(attrValue);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
@ -370,13 +370,13 @@ define('admin/manage/privileges', [
|
|
|
|
|
|
|
|
|
|
|
|
function addGroupToCategory(group, cb) {
|
|
|
|
function addGroupToCategory(group, cb) {
|
|
|
|
cb = cb || function () {};
|
|
|
|
cb = cb || function () {};
|
|
|
|
var groupRow = document.querySelector('.privilege-table [data-group-name="' + group + '"]');
|
|
|
|
const groupRow = document.querySelector('.privilege-table [data-group-name="' + group + '"]');
|
|
|
|
if (groupRow) {
|
|
|
|
if (groupRow) {
|
|
|
|
hightlightRowByDataAttr('data-group-name', group);
|
|
|
|
hightlightRowByDataAttr('data-group-name', group);
|
|
|
|
return cb();
|
|
|
|
return cb();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Generate data for new row
|
|
|
|
// Generate data for new row
|
|
|
|
var privilegeSet = ajaxify.data.privileges.keys.groups.reduce(function (memo, cur) {
|
|
|
|
const privilegeSet = ajaxify.data.privileges.keys.groups.reduce(function (memo, cur) {
|
|
|
|
memo[cur] = false;
|
|
|
|
memo[cur] = false;
|
|
|
|
return memo;
|
|
|
|
return memo;
|
|
|
|
}, {});
|
|
|
|
}, {});
|
|
|
@ -392,7 +392,7 @@ define('admin/manage/privileges', [
|
|
|
|
],
|
|
|
|
],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}, function (html) {
|
|
|
|
}, function (html) {
|
|
|
|
var tbodyEl = document.querySelector('.privilege-table tbody');
|
|
|
|
const tbodyEl = document.querySelector('.privilege-table tbody');
|
|
|
|
const btnIdx = $('.privilege-filters').first().find('button.btn-warning').index();
|
|
|
|
const btnIdx = $('.privilege-filters').first().find('button.btn-warning').index();
|
|
|
|
tbodyEl.append(html.get(0));
|
|
|
|
tbodyEl.append(html.get(0));
|
|
|
|
Privileges.exposeAssumedPrivileges();
|
|
|
|
Privileges.exposeAssumedPrivileges();
|
|
|
@ -404,13 +404,13 @@ define('admin/manage/privileges', [
|
|
|
|
|
|
|
|
|
|
|
|
async function addUserToCategory(user, cb) {
|
|
|
|
async function addUserToCategory(user, cb) {
|
|
|
|
cb = cb || function () {};
|
|
|
|
cb = cb || function () {};
|
|
|
|
var userRow = document.querySelector('.privilege-table [data-uid="' + user.uid + '"]');
|
|
|
|
const userRow = document.querySelector('.privilege-table [data-uid="' + user.uid + '"]');
|
|
|
|
if (userRow) {
|
|
|
|
if (userRow) {
|
|
|
|
hightlightRowByDataAttr('data-uid', user.uid);
|
|
|
|
hightlightRowByDataAttr('data-uid', user.uid);
|
|
|
|
return cb();
|
|
|
|
return cb();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Generate data for new row
|
|
|
|
// Generate data for new row
|
|
|
|
var privilegeSet = ajaxify.data.privileges.keys.users.reduce(function (memo, cur) {
|
|
|
|
const privilegeSet = ajaxify.data.privileges.keys.users.reduce(function (memo, cur) {
|
|
|
|
memo[cur] = false;
|
|
|
|
memo[cur] = false;
|
|
|
|
return memo;
|
|
|
|
return memo;
|
|
|
|
}, {});
|
|
|
|
}, {});
|
|
|
@ -431,7 +431,7 @@ define('admin/manage/privileges', [
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
var tbodyEl = document.querySelectorAll('.privilege-table tbody');
|
|
|
|
const tbodyEl = document.querySelectorAll('.privilege-table tbody');
|
|
|
|
const btnIdx = $('.privilege-filters').last().find('button.btn-warning').index();
|
|
|
|
const btnIdx = $('.privilege-filters').last().find('button.btn-warning').index();
|
|
|
|
tbodyEl[1].append(html.get(0));
|
|
|
|
tbodyEl[1].append(html.get(0));
|
|
|
|
Privileges.exposeAssumedPrivileges();
|
|
|
|
Privileges.exposeAssumedPrivileges();
|
|
|
|