Commit 27c3c5bd authored by Filipa Lacerda's avatar Filipa Lacerda

Merge branch 'ee-protected-branches-tags' into 'master'

Converted EE protected tags & branches to axios

See merge request gitlab-org/gitlab-ee!4421
parents 82e856ff c4a8939a
/* eslint-disable no-underscore-dangle, class-methods-use-this */ /* eslint-disable no-underscore-dangle, class-methods-use-this */
import _ from 'underscore'; import _ from 'underscore';
import axios from '~/lib/utils/axios_utils';
import Flash from '~/flash'; import Flash from '~/flash';
import { LEVEL_TYPES, LEVEL_ID_PROP, ACCESS_LEVEL_NONE } from './constants'; import { LEVEL_TYPES, LEVEL_ID_PROP, ACCESS_LEVEL_NONE } from './constants';
...@@ -274,20 +275,13 @@ export default class ProtectedBranchAccessDropdown { ...@@ -274,20 +275,13 @@ export default class ProtectedBranchAccessDropdown {
} }
getData(query, callback) { getData(query, callback) {
this.getUsers(query) Promise.all([
.done((usersResponse) => { this.getUsers(query),
if (this.groups.length) { this.groupsData ? Promise.resolve(this.groupsData) : this.getGroups(),
callback(this.consolidateData(usersResponse, this.groups)); ]).then(([usersResponse, groupsResponse]) => {
} else { this.groupsData = groupsResponse;
this.getGroups(query) callback(this.consolidateData(usersResponse.data, groupsResponse.data));
.done((groupsResponse) => { }).catch(() => Flash('Failed to load groups & users.'));
// Cache groups to avoid multiple requests
this.groups = groupsResponse;
callback(this.consolidateData(usersResponse, groupsResponse));
})
.error(() => new Flash('Failed to load groups.'));
}
}).error(() => new Flash('Failed to load users.'));
} }
consolidateData(usersResponse, groupsResponse) { consolidateData(usersResponse, groupsResponse) {
...@@ -375,10 +369,8 @@ export default class ProtectedBranchAccessDropdown { ...@@ -375,10 +369,8 @@ export default class ProtectedBranchAccessDropdown {
} }
getUsers(query) { getUsers(query) {
return $.ajax({ return axios.get(this.buildUrl(gon.relative_url_root, this.usersPath), {
dataType: 'json', params: {
url: this.buildUrl(gon.relative_url_root, this.usersPath),
data: {
search: query, search: query,
per_page: 20, per_page: 20,
active: true, active: true,
...@@ -389,10 +381,8 @@ export default class ProtectedBranchAccessDropdown { ...@@ -389,10 +381,8 @@ export default class ProtectedBranchAccessDropdown {
} }
getGroups() { getGroups() {
return $.ajax({ return axios.get(this.buildUrl(gon.relative_url_root, this.groupsPath), {
dataType: 'json', params: {
url: this.buildUrl(gon.relative_url_root, this.groupsPath),
data: {
project_id: gon.current_project_id, project_id: gon.current_project_id,
}, },
}); });
......
import axios from '~/lib/utils/axios_utils';
import AccessorUtilities from '~/lib/utils/accessor'; import AccessorUtilities from '~/lib/utils/accessor';
import Flash from '~/flash'; import Flash from '~/flash';
import CreateItemDropdown from '~/create_item_dropdown'; import CreateItemDropdown from '~/create_item_dropdown';
...@@ -124,15 +125,11 @@ export default class ProtectedBranchCreate { ...@@ -124,15 +125,11 @@ export default class ProtectedBranchCreate {
onFormSubmit(e) { onFormSubmit(e) {
e.preventDefault(); e.preventDefault();
$.ajax({ axios[this.$form.attr('method')](this.$form.attr('action'), this.getFormData())
url: this.$form.attr('action'), .then(() => {
method: this.$form.attr('method'),
data: this.getFormData(),
})
.success(() => {
location.reload(); location.reload();
}) })
.fail(() => new Flash('Failed to protect the branch')); .catch(() => Flash('Failed to protect the branch'));
} }
savePreviousSelection(mergeSelection, pushSelection) { savePreviousSelection(mergeSelection, pushSelection) {
......
/* eslint-disable no-new */ /* eslint-disable no-new */
import _ from 'underscore'; import _ from 'underscore';
import axios from '~/lib/utils/axios_utils';
import Flash from '~/flash'; import Flash from '~/flash';
import { ACCESS_LEVELS, LEVEL_TYPES } from './constants'; import { ACCESS_LEVELS, LEVEL_TYPES } from './constants';
import ProtectedBranchAccessDropdown from './protected_branch_access_dropdown'; import ProtectedBranchAccessDropdown from './protected_branch_access_dropdown';
...@@ -61,30 +62,23 @@ export default class ProtectedBranchEdit { ...@@ -61,30 +62,23 @@ export default class ProtectedBranchEdit {
return acc; return acc;
}, {}); }, {});
return $.ajax({ axios.patch(this.$wrap.data('url'), {
type: 'POST',
url: this.$wrap.data('url'),
dataType: 'json',
data: {
_method: 'PATCH',
protected_branch: formData, protected_branch: formData,
}, }).then(({ data }) => {
success: (response) => {
this.hasChanges = false; this.hasChanges = false;
Object.keys(ACCESS_LEVELS).forEach((level) => { Object.keys(ACCESS_LEVELS).forEach((level) => {
const accessLevelName = ACCESS_LEVELS[level]; const accessLevelName = ACCESS_LEVELS[level];
// The data coming from server will be the new persisted *state* for each dropdown // The data coming from server will be the new persisted *state* for each dropdown
this.setSelectedItemsToDropdown(response[accessLevelName], `${accessLevelName}_dropdown`); this.setSelectedItemsToDropdown(data[accessLevelName], `${accessLevelName}_dropdown`);
}); });
},
error() {
new Flash('Failed to update branch!', null, $('.js-protected-branches-list'));
},
}).always(() => {
this.$allowedToMergeDropdown.enable(); this.$allowedToMergeDropdown.enable();
this.$allowedToPushDropdown.enable(); this.$allowedToPushDropdown.enable();
}).catch(() => {
this.$allowedToMergeDropdown.enable();
this.$allowedToPushDropdown.enable();
Flash('Failed to update branch!', null, $('.js-protected-branches-list'));
}); });
} }
......
/* eslint-disable no-underscore-dangle, class-methods-use-this */ /* eslint-disable no-underscore-dangle, class-methods-use-this */
import _ from 'underscore'; import _ from 'underscore';
import axios from '~/lib/utils/axios_utils';
import Flash from '~/flash'; import Flash from '~/flash';
import { LEVEL_TYPES, LEVEL_ID_PROP, ACCESS_LEVEL_NONE } from './constants'; import { LEVEL_TYPES, LEVEL_ID_PROP, ACCESS_LEVEL_NONE } from './constants';
...@@ -270,21 +271,13 @@ export default class ProtectedTagAccessDropdown { ...@@ -270,21 +271,13 @@ export default class ProtectedTagAccessDropdown {
} }
getData(query, callback) { getData(query, callback) {
this.getUsers(query) Promise.all([
.done((usersResponse) => { this.getUsers(query),
if (this.groups.length) { this.groupsData ? Promise.resolve(this.groupsData) : this.getGroups(),
callback(this.consolidateData(usersResponse, this.groups)); ]).then(([usersResponse, groupsResponse]) => {
} else { this.groupsData = groupsResponse;
this.getGroups(query) callback(this.consolidateData(usersResponse.data, groupsResponse.data));
.done((groupsResponse) => { }).catch(() => Flash('Failed to load groups & users.'));
// Cache groups to avoid multiple requests
this.groups = groupsResponse;
callback(this.consolidateData(usersResponse, groupsResponse));
})
.error(() => new Flash('Failed to load groups.'));
}
})
.error(() => new Flash('Failed to load users.'));
} }
consolidateData(usersResponse, groupsResponse) { consolidateData(usersResponse, groupsResponse) {
...@@ -372,10 +365,8 @@ export default class ProtectedTagAccessDropdown { ...@@ -372,10 +365,8 @@ export default class ProtectedTagAccessDropdown {
} }
getUsers(query) { getUsers(query) {
return $.ajax({ return axios.get(this.buildUrl(gon.relative_url_root, this.usersPath), {
dataType: 'json', params: {
url: this.buildUrl(gon.relative_url_root, this.usersPath),
data: {
search: query, search: query,
per_page: 20, per_page: 20,
active: true, active: true,
...@@ -386,10 +377,8 @@ export default class ProtectedTagAccessDropdown { ...@@ -386,10 +377,8 @@ export default class ProtectedTagAccessDropdown {
} }
getGroups() { getGroups() {
return $.ajax({ return axios.get(this.buildUrl(gon.relative_url_root, this.groupsPath), {
dataType: 'json', params: {
url: this.buildUrl(gon.relative_url_root, this.groupsPath),
data: {
project_id: gon.current_project_id, project_id: gon.current_project_id,
}, },
}); });
......
import axios from '~/lib/utils/axios_utils';
import Flash from '~/flash'; import Flash from '~/flash';
import CreateItemDropdown from '~/create_item_dropdown'; import CreateItemDropdown from '~/create_item_dropdown';
import { ACCESS_LEVELS, LEVEL_TYPES } from './constants'; import { ACCESS_LEVELS, LEVEL_TYPES } from './constants';
...@@ -89,14 +90,9 @@ export default class ProtectedTagCreate { ...@@ -89,14 +90,9 @@ export default class ProtectedTagCreate {
onFormSubmit(e) { onFormSubmit(e) {
e.preventDefault(); e.preventDefault();
$.ajax({ axios[this.$form.attr('method')](this.$form.attr('action'), this.getFormData())
url: this.$form.attr('action'), .then(() => {
method: this.$form.attr('method'),
data: this.getFormData(),
})
.success(() => {
location.reload(); location.reload();
}) }).catch(() => Flash('Failed to protect the tag'));
.fail(() => new Flash('Failed to protect the tag'));
} }
} }
/* eslint-disable no-new */ /* eslint-disable no-new */
import _ from 'underscore'; import _ from 'underscore';
import axios from '~/lib/utils/axios_utils';
import Flash from '~/flash'; import Flash from '~/flash';
import { ACCESS_LEVELS, LEVEL_TYPES } from './constants'; import { ACCESS_LEVELS, LEVEL_TYPES } from './constants';
import ProtectedTagAccessDropdown from './protected_tag_access_dropdown'; import ProtectedTagAccessDropdown from './protected_tag_access_dropdown';
...@@ -49,30 +50,20 @@ export default class ProtectedTagEdit { ...@@ -49,30 +50,20 @@ export default class ProtectedTagEdit {
return acc; return acc;
}, {}); }, {});
return $.ajax({ axios.patch(this.$wrap.data('url'), {
type: 'POST',
url: this.$wrap.data('url'),
dataType: 'json',
data: {
_method: 'PATCH',
protected_tag: formData, protected_tag: formData,
}, }).then(({ data }) => {
success: (response) => {
this.hasChanges = false; this.hasChanges = false;
Object.keys(ACCESS_LEVELS).forEach((level) => { Object.keys(ACCESS_LEVELS).forEach((level) => {
const accessLevelName = ACCESS_LEVELS[level]; const accessLevelName = ACCESS_LEVELS[level];
// The data coming from server will be the new persisted *state* for each dropdown // The data coming from server will be the new persisted *state* for each dropdown
this.setSelectedItemsToDropdown(response[accessLevelName], `${accessLevelName}_dropdown`); this.setSelectedItemsToDropdown(data[accessLevelName], `${accessLevelName}_dropdown`);
}); });
}, }).catch(() => {
error() {
$.scrollTo(0); $.scrollTo(0);
new Flash('Failed to update tag!'); Flash('Failed to update tag!');
},
}).always(() => {
this.$allowedToCreateDropdownButton.enable();
}); });
} }
......
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