Commit ff731225 authored by Phil Hughes's avatar Phil Hughes

Show attention request button if user does not have permission

Instead of hiding the attention request button if the user does not
have permission we will not instead show the button
but making it read only.

Closes https://gitlab.com/gitlab-org/gitlab/-/issues/354727
parent 1c3f6164
...@@ -114,7 +114,7 @@ export default { ...@@ -114,7 +114,7 @@ export default {
class="gl-display-inline-block" class="gl-display-inline-block"
> >
<attention-requested-toggle <attention-requested-toggle
v-if="showVerticalList && user.can_update_merge_request" v-if="showVerticalList"
:user="user" :user="user"
type="assignee" type="assignee"
@toggle-attention-requested="toggleAttentionRequested" @toggle-attention-requested="toggleAttentionRequested"
......
...@@ -8,6 +8,8 @@ export default { ...@@ -8,6 +8,8 @@ export default {
attentionRequestedReviewer: __('Request attention to review'), attentionRequestedReviewer: __('Request attention to review'),
attentionRequestedAssignee: __('Request attention'), attentionRequestedAssignee: __('Request attention'),
removeAttentionRequested: __('Remove attention request'), removeAttentionRequested: __('Remove attention request'),
attentionRequestedNoPermission: __('Attention requested'),
noAttentionRequestedNoPermission: __('No attention request'),
}, },
components: { components: {
GlButton, GlButton,
...@@ -33,17 +35,25 @@ export default { ...@@ -33,17 +35,25 @@ export default {
computed: { computed: {
tooltipTitle() { tooltipTitle() {
if (this.user.attention_requested) { if (this.user.attention_requested) {
return this.$options.i18n.removeAttentionRequested; if (this.user.can_update_merge_request) {
return this.$options.i18n.removeAttentionRequested;
}
return this.$options.i18n.attentionRequestedNoPermission;
}
if (this.user.can_update_merge_request) {
return this.type === 'reviewer'
? this.$options.i18n.attentionRequestedReviewer
: this.$options.i18n.attentionRequestedAssignee;
} }
return this.type === 'reviewer' return this.$options.i18n.noAttentionRequestedNoPermission;
? this.$options.i18n.attentionRequestedReviewer
: this.$options.i18n.attentionRequestedAssignee;
}, },
}, },
methods: { methods: {
toggleAttentionRequired() { toggleAttentionRequired() {
if (this.loading) return; if (this.loading || !this.user.can_update_merge_request) return;
this.$root.$emit(BV_HIDE_TOOLTIP); this.$root.$emit(BV_HIDE_TOOLTIP);
this.loading = true; this.loading = true;
...@@ -60,12 +70,13 @@ export default { ...@@ -60,12 +70,13 @@ export default {
</script> </script>
<template> <template>
<span v-gl-tooltip.left.viewport="tooltipTitle"> <span v-gl-tooltip.left.viewport="tooltipTitle" class="gl-display-inline-block">
<gl-button <gl-button
:loading="loading" :loading="loading"
:variant="user.attention_requested ? 'warning' : 'default'" :variant="user.attention_requested ? 'warning' : 'default'"
:icon="user.attention_requested ? 'attention-solid' : 'attention'" :icon="user.attention_requested ? 'attention-solid' : 'attention'"
:aria-label="tooltipTitle" :aria-label="tooltipTitle"
:class="{ 'gl-pointer-events-none': !user.can_update_merge_request }"
size="small" size="small"
category="tertiary" category="tertiary"
@click="toggleAttentionRequired" @click="toggleAttentionRequired"
......
...@@ -98,7 +98,7 @@ export default { ...@@ -98,7 +98,7 @@ export default {
data-testid="reviewer" data-testid="reviewer"
> >
<attention-requested-toggle <attention-requested-toggle
v-if="glFeatures.mrAttentionRequests && user.can_update_merge_request" v-if="glFeatures.mrAttentionRequests"
:user="user" :user="user"
type="reviewer" type="reviewer"
@toggle-attention-requested="toggleAttentionRequested" @toggle-attention-requested="toggleAttentionRequested"
......
...@@ -5026,6 +5026,9 @@ msgstr "" ...@@ -5026,6 +5026,9 @@ msgstr ""
msgid "Attention" msgid "Attention"
msgstr "" msgstr ""
msgid "Attention requested"
msgstr ""
msgid "Audit Events" msgid "Audit Events"
msgstr "" msgstr ""
...@@ -24633,6 +24636,9 @@ msgstr "" ...@@ -24633,6 +24636,9 @@ msgstr ""
msgid "No assignee" msgid "No assignee"
msgstr "" msgstr ""
msgid "No attention request"
msgstr ""
msgid "No authentication methods configured." msgid "No authentication methods configured."
msgstr "" msgstr ""
......
...@@ -16,7 +16,10 @@ describe('Attention require toggle', () => { ...@@ -16,7 +16,10 @@ describe('Attention require toggle', () => {
}); });
it('renders button', () => { it('renders button', () => {
factory({ type: 'reviewer', user: { attention_requested: false } }); factory({
type: 'reviewer',
user: { attention_requested: false, can_update_merge_request: true },
});
expect(findToggle().exists()).toBe(true); expect(findToggle().exists()).toBe(true);
}); });
...@@ -28,7 +31,10 @@ describe('Attention require toggle', () => { ...@@ -28,7 +31,10 @@ describe('Attention require toggle', () => {
`( `(
'renders $icon icon when attention_requested is $attentionRequested', 'renders $icon icon when attention_requested is $attentionRequested',
({ attentionRequested, icon }) => { ({ attentionRequested, icon }) => {
factory({ type: 'reviewer', user: { attention_requested: attentionRequested } }); factory({
type: 'reviewer',
user: { attention_requested: attentionRequested, can_update_merge_request: true },
});
expect(findToggle().props('icon')).toBe(icon); expect(findToggle().props('icon')).toBe(icon);
}, },
...@@ -41,27 +47,47 @@ describe('Attention require toggle', () => { ...@@ -41,27 +47,47 @@ describe('Attention require toggle', () => {
`( `(
'renders button with variant $variant when attention_requested is $attentionRequested', 'renders button with variant $variant when attention_requested is $attentionRequested',
({ attentionRequested, variant }) => { ({ attentionRequested, variant }) => {
factory({ type: 'reviewer', user: { attention_requested: attentionRequested } }); factory({
type: 'reviewer',
user: { attention_requested: attentionRequested, can_update_merge_request: true },
});
expect(findToggle().props('variant')).toBe(variant); expect(findToggle().props('variant')).toBe(variant);
}, },
); );
it('emits toggle-attention-requested on click', async () => { it('emits toggle-attention-requested on click', async () => {
factory({ type: 'reviewer', user: { attention_requested: true } }); factory({
type: 'reviewer',
user: { attention_requested: true, can_update_merge_request: true },
});
await findToggle().trigger('click'); await findToggle().trigger('click');
expect(wrapper.emitted('toggle-attention-requested')[0]).toEqual([ expect(wrapper.emitted('toggle-attention-requested')[0]).toEqual([
{ {
user: { attention_requested: true }, user: { attention_requested: true, can_update_merge_request: true },
callback: expect.anything(), callback: expect.anything(),
}, },
]); ]);
}); });
it('does not emit toggle-attention-requested on click if can_update_merge_request is false', async () => {
factory({
type: 'reviewer',
user: { attention_requested: true, can_update_merge_request: false },
});
await findToggle().trigger('click');
expect(wrapper.emitted('toggle-attention-requested')).toBe(undefined);
});
it('sets loading on click', async () => { it('sets loading on click', async () => {
factory({ type: 'reviewer', user: { attention_requested: true } }); factory({
type: 'reviewer',
user: { attention_requested: true, can_update_merge_request: true },
});
await findToggle().trigger('click'); await findToggle().trigger('click');
...@@ -69,14 +95,24 @@ describe('Attention require toggle', () => { ...@@ -69,14 +95,24 @@ describe('Attention require toggle', () => {
}); });
it.each` it.each`
type | attentionRequested | tooltip type | attentionRequested | tooltip | canUpdateMergeRequest
${'reviewer'} | ${true} | ${AttentionRequestedToggle.i18n.removeAttentionRequested} ${'reviewer'} | ${true} | ${AttentionRequestedToggle.i18n.removeAttentionRequested} | ${true}
${'reviewer'} | ${false} | ${AttentionRequestedToggle.i18n.attentionRequestedReviewer} ${'reviewer'} | ${false} | ${AttentionRequestedToggle.i18n.attentionRequestedReviewer} | ${true}
${'assignee'} | ${false} | ${AttentionRequestedToggle.i18n.attentionRequestedAssignee} ${'assignee'} | ${false} | ${AttentionRequestedToggle.i18n.attentionRequestedAssignee} | ${true}
${'reviewer'} | ${true} | ${AttentionRequestedToggle.i18n.attentionRequestedNoPermission} | ${false}
${'reviewer'} | ${false} | ${AttentionRequestedToggle.i18n.noAttentionRequestedNoPermission} | ${false}
${'assignee'} | ${true} | ${AttentionRequestedToggle.i18n.attentionRequestedNoPermission} | ${false}
${'assignee'} | ${false} | ${AttentionRequestedToggle.i18n.noAttentionRequestedNoPermission} | ${false}
`( `(
'sets tooltip as $tooltip when attention_requested is $attentionRequested and type is $type', 'sets tooltip as $tooltip when attention_requested is $attentionRequested, type is $type and, can_update_merge_request is $canUpdateMergeRequest',
({ type, attentionRequested, tooltip }) => { ({ type, attentionRequested, tooltip, canUpdateMergeRequest }) => {
factory({ type, user: { attention_requested: attentionRequested } }); factory({
type,
user: {
attention_requested: attentionRequested,
can_update_merge_request: canUpdateMergeRequest,
},
});
expect(findToggle().attributes('aria-label')).toBe(tooltip); expect(findToggle().attributes('aria-label')).toBe(tooltip);
}, },
......
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