Commit 038bface authored by Tim Zallmann's avatar Tim Zallmann

Merge branch '39734-fix-protected-refs-roles' into 'master'

Prevent adding same role multiple times on repeated clicks

Closes #4294

See merge request gitlab-org/gitlab-ee!3700
parents 025bdb21 ac2dcfef
---
title: Prevent adding same role multiple times on repeated clicks
merge_request: 3700
author:
type: fixed
...@@ -145,8 +145,8 @@ export default class ProtectedBranchAccessDropdown { ...@@ -145,8 +145,8 @@ export default class ProtectedBranchAccessDropdown {
addSelectedItem(selectedItem) { addSelectedItem(selectedItem) {
let itemToAdd = {}; let itemToAdd = {};
// If the item already exists, just use it
let index = -1; let index = -1;
let alreadyAdded = false;
const selectedItems = this.getAllSelectedItems(); const selectedItems = this.getAllSelectedItems();
// Compare IDs based on selectedItem.type // Compare IDs based on selectedItem.type
...@@ -155,6 +155,10 @@ export default class ProtectedBranchAccessDropdown { ...@@ -155,6 +155,10 @@ export default class ProtectedBranchAccessDropdown {
switch (selectedItem.type) { switch (selectedItem.type) {
case LEVEL_TYPES.ROLE: case LEVEL_TYPES.ROLE:
comparator = LEVEL_ID_PROP.ROLE; comparator = LEVEL_ID_PROP.ROLE;
// If the item already exists, just use it
if (item[comparator] === selectedItem.id) {
alreadyAdded = true;
}
break; break;
case LEVEL_TYPES.GROUP: case LEVEL_TYPES.GROUP:
comparator = LEVEL_ID_PROP.GROUP; comparator = LEVEL_ID_PROP.GROUP;
...@@ -171,6 +175,10 @@ export default class ProtectedBranchAccessDropdown { ...@@ -171,6 +175,10 @@ export default class ProtectedBranchAccessDropdown {
} }
}); });
if (alreadyAdded) {
return;
}
if (index !== -1 && selectedItems[index]._destroy) { if (index !== -1 && selectedItems[index]._destroy) {
delete selectedItems[index]._destroy; delete selectedItems[index]._destroy;
return; return;
......
...@@ -140,8 +140,8 @@ export default class ProtectedTagAccessDropdown { ...@@ -140,8 +140,8 @@ export default class ProtectedTagAccessDropdown {
addSelectedItem(selectedItem) { addSelectedItem(selectedItem) {
let itemToAdd = {}; let itemToAdd = {};
// If the item already exists, just use it
let index = -1; let index = -1;
let alreadyAdded = false;
const selectedItems = this.getAllSelectedItems(); const selectedItems = this.getAllSelectedItems();
// Compare IDs based on selectedItem.type // Compare IDs based on selectedItem.type
...@@ -150,6 +150,10 @@ export default class ProtectedTagAccessDropdown { ...@@ -150,6 +150,10 @@ export default class ProtectedTagAccessDropdown {
switch (selectedItem.type) { switch (selectedItem.type) {
case LEVEL_TYPES.ROLE: case LEVEL_TYPES.ROLE:
comparator = LEVEL_ID_PROP.ROLE; comparator = LEVEL_ID_PROP.ROLE;
// If the item already exists, just use it
if (item[comparator] === selectedItem.id) {
alreadyAdded = true;
}
break; break;
case LEVEL_TYPES.GROUP: case LEVEL_TYPES.GROUP:
comparator = LEVEL_ID_PROP.GROUP; comparator = LEVEL_ID_PROP.GROUP;
...@@ -166,6 +170,10 @@ export default class ProtectedTagAccessDropdown { ...@@ -166,6 +170,10 @@ export default class ProtectedTagAccessDropdown {
} }
}); });
if (alreadyAdded) {
return;
}
if (index !== -1 && selectedItems[index]._destroy) { if (index !== -1 && selectedItems[index]._destroy) {
delete selectedItems[index]._destroy; delete selectedItems[index]._destroy;
return; return;
......
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