Skip to content
Snippets Groups Projects

Add managing protected branches as custom permission

Merged Jarka Košanová requested to merge 448823-protected-branches-cr into master
Files
24
@@ -9,6 +9,7 @@ import {
@@ -9,6 +9,7 @@ import {
GlSprintf,
GlSprintf,
} from '@gitlab/ui';
} from '@gitlab/ui';
import { debounce, intersectionWith, groupBy, differenceBy, intersectionBy } from 'lodash';
import { debounce, intersectionWith, groupBy, differenceBy, intersectionBy } from 'lodash';
 
import glAbilitiesMixin from '~/vue_shared/mixins/gl_abilities_mixin';
import { createAlert } from '~/alert';
import { createAlert } from '~/alert';
import { __, s__, n__ } from '~/locale';
import { __, s__, n__ } from '~/locale';
import { getUsers, getGroups, getDeployKeys } from '../api/access_dropdown_api';
import { getUsers, getGroups, getDeployKeys } from '../api/access_dropdown_api';
@@ -35,6 +36,7 @@ export default {
@@ -35,6 +36,7 @@ export default {
GlAvatar,
GlAvatar,
GlSprintf,
GlSprintf,
},
},
 
mixins: [glAbilitiesMixin()],
props: {
props: {
accessLevelsData: {
accessLevelsData: {
type: Array,
type: Array,
@@ -187,6 +189,9 @@ export default {
@@ -187,6 +189,9 @@ export default {
...this.getDataForSave(LEVEL_TYPES.DEPLOY_KEY, 'deploy_key_id'),
...this.getDataForSave(LEVEL_TYPES.DEPLOY_KEY, 'deploy_key_id'),
];
];
},
},
 
canAdminContainer() {
 
return this.glAbilities.adminProject || this.glAbilities.adminGroup;
 
},
},
},
watch: {
watch: {
query: debounce(function debouncedSearch() {
query: debounce(function debouncedSearch() {
@@ -226,29 +231,45 @@ export default {
@@ -226,29 +231,45 @@ export default {
focusInput() {
focusInput() {
this.$refs.search?.focusInput();
this.$refs.search?.focusInput();
},
},
 
getGroups() {
 
return this.groups.length
 
? Promise.resolve({ data: this.groups })
 
: getGroups({ withProjectAccess: this.groupsWithProjectAccess });
 
},
getData({ initial = false } = {}) {
getData({ initial = false } = {}) {
this.initialLoading = initial;
this.initialLoading = initial;
this.loading = true;
this.loading = true;
if (this.hasLicense) {
if (this.hasLicense) {
Promise.all([
if (this.canAdminContainer) {
getDeployKeys(this.query),
Promise.all([getDeployKeys(this.query), getUsers(this.query), this.getGroups()])
getUsers(this.query),
.then(([deployKeysResponse, usersResponse, groupsResponse]) => {
this.groups.length
this.consolidateData(
? Promise.resolve({ data: this.groups })
deployKeysResponse.data,
: getGroups({ withProjectAccess: this.groupsWithProjectAccess }),
usersResponse.data,
])
groupsResponse.data,
.then(([deployKeysResponse, usersResponse, groupsResponse]) => {
);
this.consolidateData(deployKeysResponse.data, usersResponse.data, groupsResponse.data);
this.setSelected({ initial });
this.setSelected({ initial });
})
})
.catch(() =>
.catch(() =>
createAlert({ message: __('Failed to load groups, users and deploy keys.') }),
createAlert({ message: __('Failed to load groups, users and deploy keys.') }),
)
)
.finally(() => {
.finally(() => {
this.initialLoading = false;
this.initialLoading = false;
this.loading = false;
this.loading = false;
});
});
} else if (this.glAbilities.adminProtectedBranch) {
 
Promise.all([getUsers(this.query), this.getGroups()])
 
.then(([usersResponse, groupsResponse]) => {
 
this.consolidateData(null, usersResponse.data, groupsResponse.data);
 
this.setSelected({ initial });
 
})
 
.catch(() => createAlert({ message: __('Failed to load groups and users.') }))
 
.finally(() => {
 
this.initialLoading = false;
 
this.loading = false;
 
});
 
}
} else {
} else {
getDeployKeys(this.query)
getDeployKeys(this.query)
.then((deployKeysResponse) => {
.then((deployKeysResponse) => {
@@ -284,27 +305,31 @@ export default {
@@ -284,27 +305,31 @@ export default {
}
}
}
}
this.deployKeys = deployKeysResponse.map((response) => {
if (this.canAdminContainer) {
const {
this.deployKeys = deployKeysResponse.map((response) => {
id,
const {
fingerprint,
id,
fingerprint_sha256: fingerprintSha256,
fingerprint,
title,
fingerprint_sha256: fingerprintSha256,
owner: { avatar_url, name, username },
title,
} = response;
owner: { avatar_url, name, username },
 
} = response;
const availableFingerprint = fingerprintSha256 || fingerprint;
const availableFingerprint = fingerprintSha256 || fingerprint;
const shortFingerprint = `(${availableFingerprint.substring(0, 14)}...)`;
const shortFingerprint = `(${availableFingerprint.substring(0, 14)}...)`;
return {
return {
id,
id,
title: title.concat(' ', shortFingerprint),
title: title.concat(' ', shortFingerprint),
avatar_url,
avatar_url,
fullname: name,
fullname: name,
username,
username,
type: LEVEL_TYPES.DEPLOY_KEY,
type: LEVEL_TYPES.DEPLOY_KEY,
};
};
});
});
 
} else {
 
this.deployKeys = [];
 
}
},
},
setSelected({ initial } = {}) {
setSelected({ initial } = {}) {
if (initial) {
if (initial) {
Loading