fix: respect data-attribute 'skip-users' in user_selects

* Respect parameters of each individual select,
  instead of the global.
* Update skipped users in approver search when removed from default approvers.
This commit is contained in:
Rik de Groot 2016-08-01 00:38:24 +02:00 committed by Sean McGivern
parent b29ec1937a
commit d3deba04f9

View file

@ -13,14 +13,15 @@
} }
$('.js-user-search').each((function(_this) { $('.js-user-search').each((function(_this) {
return function(i, dropdown) { return function(i, dropdown) {
var options = {};
var $block, $collapsedSidebar, $dropdown, $loading, $selectbox, $value, abilityName, assignTo, assigneeTemplate, collapsedAssigneeTemplate, defaultLabel, firstUser, issueURL, selectedId, showAnyUser, showNullUser; var $block, $collapsedSidebar, $dropdown, $loading, $selectbox, $value, abilityName, assignTo, assigneeTemplate, collapsedAssigneeTemplate, defaultLabel, firstUser, issueURL, selectedId, showAnyUser, showNullUser;
$dropdown = $(dropdown); $dropdown = $(dropdown);
_this.projectId = $dropdown.data('project-id'); options.projectId = $dropdown.data('project-id');
_this.showCurrentUser = $dropdown.data('current-user'); options.showCurrentUser = $dropdown.data('current-user');
showNullUser = $dropdown.data('null-user'); showNullUser = $dropdown.data('null-user');
showAnyUser = $dropdown.data('any-user'); showAnyUser = $dropdown.data('any-user');
firstUser = $dropdown.data('first-user'); firstUser = $dropdown.data('first-user');
_this.authorId = $dropdown.data('author-id'); options.authorId = $dropdown.data('author-id');
selectedId = $dropdown.data('selected'); selectedId = $dropdown.data('selected');
defaultLabel = $dropdown.data('default-label'); defaultLabel = $dropdown.data('default-label');
issueURL = $dropdown.data('issueUpdate'); issueURL = $dropdown.data('issueUpdate');
@ -75,7 +76,7 @@
data: function(term, callback) { data: function(term, callback) {
var isAuthorFilter; var isAuthorFilter;
isAuthorFilter = $('.js-author-search'); isAuthorFilter = $('.js-author-search');
return _this.users(term, function(users) { return _this.users(term, options, function(users) {
var anyUser, index, j, len, name, obj, showDivider; var anyUser, index, j, len, name, obj, showDivider;
if (term.length === 0) { if (term.length === 0) {
showDivider = 0; showDivider = 0;
@ -185,11 +186,14 @@
$('.ajax-users-select').each((function(_this) { $('.ajax-users-select').each((function(_this) {
return function(i, select) { return function(i, select) {
var firstUser, showAnyUser, showEmailUser, showNullUser; var firstUser, showAnyUser, showEmailUser, showNullUser;
_this.projectId = $(select).data('project-id'); var options = {};
_this.groupId = $(select).data('group-id'); options.skipLdap = $(select).hasClass('skip_ldap');
_this.showCurrentUser = $(select).data('current-user'); options.projectId = $(select).data('project-id');
_this.authorId = $(select).data('author-id'); options.groupId = $(select).data('group-id');
_this.skipUsers = $(select).data('skip-users'); options.showCurrentUser = $(select).data('current-user');
options.pushCodeToProtectedBranches = $(select).data('push-code-to-protected-branches');
options.authorId = $(select).data('author-id');
options.skipUsers = $(select).data('skip-users');
showNullUser = $(select).data('null-user'); showNullUser = $(select).data('null-user');
showAnyUser = $(select).data('any-user'); showAnyUser = $(select).data('any-user');
showEmailUser = $(select).data('email-user'); showEmailUser = $(select).data('email-user');
@ -199,7 +203,7 @@
multiple: $(select).hasClass('multiselect'), multiple: $(select).hasClass('multiselect'),
minimumInputLength: 0, minimumInputLength: 0,
query: function(query) { query: function(query) {
return _this.users(query.term, function(users) { return _this.users(query.term, options, function(users) {
var anyUser, data, emailUser, index, j, len, name, nullUser, obj, ref; var anyUser, data, emailUser, index, j, len, name, nullUser, obj, ref;
data = { data = {
results: users results: users
@ -309,7 +313,7 @@
}); });
}; };
UsersSelect.prototype.users = function(query, callback) { UsersSelect.prototype.users = function(query, options, callback) {
var url; var url;
url = this.buildUrl(this.usersPath); url = this.buildUrl(this.usersPath);
return $.ajax({ return $.ajax({
@ -318,11 +322,13 @@
search: query, search: query,
per_page: 20, per_page: 20,
active: true, active: true,
project_id: this.projectId, project_id: options.projectId || null,
group_id: this.groupId, group_id: options.groupId || null,
current_user: this.showCurrentUser, skip_ldap: options.skipLdap || null,
author_id: this.authorId, current_user: options.showCurrentUser || null,
skip_users: this.skipUsers push_code_to_protected_branches: options.pushCodeToProtectedBranches || null,
author_id: options.authorId || null,
skip_users: options.skipUsers || null
}, },
dataType: "json" dataType: "json"
}).done(function(users) { }).done(function(users) {