Commit efb701f1 authored by Vitaly Slobodin's avatar Vitaly Slobodin

Merge branch 'pb-add-permissions-check-for-link' into 'master'

Add permissions for group usage quota link

See merge request gitlab-org/gitlab!80299
parents 5750d8dc ccfac111
...@@ -26,6 +26,10 @@ export default { ...@@ -26,6 +26,10 @@ export default {
type: String, type: String,
default: '', default: '',
}, },
canViewGroupUsageQuotaBoolean: {
type: Boolean,
default: false,
},
}, },
data() { data() {
return { return {
...@@ -85,7 +89,7 @@ export default { ...@@ -85,7 +89,7 @@ export default {
<gl-tab :title="s__('CICDAnalytics|Shared runner usage')"> <gl-tab :title="s__('CICDAnalytics|Shared runner usage')">
<shared-runners-usage /> <shared-runners-usage />
</gl-tab> </gl-tab>
<template #tabs-end> <template v-if="canViewGroupUsageQuotaBoolean" #tabs-end>
<gl-link :href="pipelineGroupUsageQuotaPath" class="gl-align-self-center gl-ml-auto">{{ <gl-link :href="pipelineGroupUsageQuotaPath" class="gl-align-self-center gl-ml-auto">{{
__('View group pipeline usage quota') __('View group pipeline usage quota')
}}</gl-link> }}</gl-link>
......
...@@ -15,9 +15,10 @@ export default () => { ...@@ -15,9 +15,10 @@ export default () => {
if (!el) return false; if (!el) return false;
const { fullPath, groupId, pipelineGroupUsageQuotaPath } = el.dataset; const { fullPath, groupId, pipelineGroupUsageQuotaPath, canViewGroupUsageQuota } = el.dataset;
const shouldRenderDoraCharts = parseBoolean(el.dataset.shouldRenderDoraCharts); const shouldRenderDoraCharts = parseBoolean(el.dataset.shouldRenderDoraCharts);
const canViewGroupUsageQuotaBoolean = parseBoolean(canViewGroupUsageQuota);
return new Vue({ return new Vue({
el, el,
...@@ -27,6 +28,7 @@ export default () => { ...@@ -27,6 +28,7 @@ export default () => {
shouldRenderDoraCharts, shouldRenderDoraCharts,
groupId, groupId,
pipelineGroupUsageQuotaPath, pipelineGroupUsageQuotaPath,
canViewGroupUsageQuotaBoolean,
}, },
render: (createElement) => createElement(CiCdAnalyticsApp), render: (createElement) => createElement(CiCdAnalyticsApp),
}); });
......
...@@ -2,4 +2,5 @@ ...@@ -2,4 +2,5 @@
#js-group-ci-cd-analytics-app{ data: { full_path: @group.full_path, #js-group-ci-cd-analytics-app{ data: { full_path: @group.full_path,
should_render_dora_charts: should_render_dora_charts.to_s, group_id: @group.id, should_render_dora_charts: should_render_dora_charts.to_s, group_id: @group.id,
pipeline_group_usage_quota_path: group_usage_quotas_path(@group, anchor: 'pipelines-quota-tab') } } pipeline_group_usage_quota_path: group_usage_quotas_path(@group, anchor: 'pipelines-quota-tab'),
can_view_group_usage_quota: can?(current_user, :admin_group, @group).to_s } }
...@@ -21,7 +21,7 @@ describe('ee/analytics/group_ci_cd_analytics/components/app.vue', () => { ...@@ -21,7 +21,7 @@ describe('ee/analytics/group_ci_cd_analytics/components/app.vue', () => {
const quotaPath = '/groups/my-awesome-group/-/usage_quotas#pipelines-quota-tab'; const quotaPath = '/groups/my-awesome-group/-/usage_quotas#pipelines-quota-tab';
const createComponent = (mountOptions = {}) => { const createComponent = (mountOptions = {}, canView = true) => {
wrapper = shallowMount( wrapper = shallowMount(
CiCdAnalyticsApp, CiCdAnalyticsApp,
merge( merge(
...@@ -29,6 +29,7 @@ describe('ee/analytics/group_ci_cd_analytics/components/app.vue', () => { ...@@ -29,6 +29,7 @@ describe('ee/analytics/group_ci_cd_analytics/components/app.vue', () => {
provide: { provide: {
shouldRenderDoraCharts: true, shouldRenderDoraCharts: true,
pipelineGroupUsageQuotaPath: quotaPath, pipelineGroupUsageQuotaPath: quotaPath,
canViewGroupUsageQuotaBoolean: canView,
}, },
}, },
mountOptions, mountOptions,
...@@ -133,4 +134,19 @@ describe('ee/analytics/group_ci_cd_analytics/components/app.vue', () => { ...@@ -133,4 +134,19 @@ describe('ee/analytics/group_ci_cd_analytics/components/app.vue', () => {
expect(findUsageQuotaLink().attributes('href')).toBe(quotaPath); expect(findUsageQuotaLink().attributes('href')).toBe(quotaPath);
expect(findUsageQuotaLink().text()).toBe('View group pipeline usage quota'); expect(findUsageQuotaLink().text()).toBe('View group pipeline usage quota');
}); });
it('hides link to group pipelines usage quota page based on permissions', () => {
createComponent(
{
stubs: {
GlTabs: {
template: '<div><slot></slot><slot name="tabs-end"></slot></div>',
},
},
},
false,
);
expect(findUsageQuotaLink().exists()).toBe(false);
});
}); });
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