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
@@ -231,24 +231,46 @@ export default {
this.loading = true;
if (this.hasLicense) {
Promise.all([
getDeployKeys(this.query),
getUsers(this.query),
this.groups.length
? Promise.resolve({ data: this.groups })
: getGroups({ withProjectAccess: this.groupsWithProjectAccess }),
])
.then(([deployKeysResponse, usersResponse, groupsResponse]) => {
this.consolidateData(deployKeysResponse.data, usersResponse.data, groupsResponse.data);
this.setSelected({ initial });
})
.catch(() =>
createAlert({ message: __('Failed to load groups, users and deploy keys.') }),
)
.finally(() => {
this.initialLoading = false;
this.loading = false;
});
if (gon.abilities.adminProject) {
Promise.all([
getDeployKeys(this.query),
getUsers(this.query),
this.groups.length
? Promise.resolve({ data: this.groups })
: getGroups({ withProjectAccess: this.groupsWithProjectAccess }),
])
.then(([deployKeysResponse, usersResponse, groupsResponse]) => {
this.consolidateData(
deployKeysResponse.data,
usersResponse.data,
groupsResponse.data,
);
this.setSelected({ initial });
})
.catch(() =>
createAlert({ message: __('Failed to load groups, users and deploy keys.') }),
)
.finally(() => {
this.initialLoading = false;
this.loading = false;
});
} else if (gon.abilities.adminProtectedBranch) {
Promise.all([
getUsers(this.query),
this.groups.length
? Promise.resolve({ data: this.groups })
: getGroups({ withProjectAccess: this.groupsWithProjectAccess }),
])
.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 {
getDeployKeys(this.query)
.then((deployKeysResponse) => {
@@ -284,27 +306,31 @@ export default {
}
}
this.deployKeys = deployKeysResponse.map((response) => {
const {
id,
fingerprint,
fingerprint_sha256: fingerprintSha256,
title,
owner: { avatar_url, name, username },
} = response;
if (gon.abilities.adminProject) {
this.deployKeys = deployKeysResponse.map((response) => {
const {
id,
fingerprint,
fingerprint_sha256: fingerprintSha256,
title,
owner: { avatar_url, name, username },
} = response;
const availableFingerprint = fingerprintSha256 || fingerprint;
const shortFingerprint = `(${availableFingerprint.substring(0, 14)}...)`;
const availableFingerprint = fingerprintSha256 || fingerprint;
const shortFingerprint = `(${availableFingerprint.substring(0, 14)}...)`;
return {
id,
title: title.concat(' ', shortFingerprint),
avatar_url,
fullname: name,
username,
type: LEVEL_TYPES.DEPLOY_KEY,
};
});
return {
id,
title: title.concat(' ', shortFingerprint),
avatar_url,
fullname: name,
username,
type: LEVEL_TYPES.DEPLOY_KEY,
};
});
} else {
this.deployKeys = [];
}
},
setSelected({ initial } = {}) {
if (initial) {
Loading