Commit cf22b700 authored by Eduardo Sanz García's avatar Eduardo Sanz García Committed by Eduardo

Remove flag icon from annotation cards for LMS users

1. Added an option (`allowFlagging`) in the service configuration to
   enable/disable flagging.

2. Added logic in `AnnoationActionBar` component to hide the flag icon
   if the service configuration has the option `allowFlagging`.

Closes https://github.com/hypothesis/product-backlog/issues/1126
parent 9aba0ca6
import { IconButton } from '@hypothesis/frontend-shared';
import { confirm } from '../../../shared/prompts';
import serviceConfig from '../../config/service-config';
import {
sharingEnabled,
annotationSharingLink,
......@@ -25,6 +26,15 @@ import AnnotationShareControl from './AnnotationShareControl';
* @prop {import('../../services/toast-messenger').ToastMessengerService} toastMessenger
*/
/** @param {HostConfig} settings */
function flaggingEnabled(settings) {
const service = serviceConfig(settings);
if (service?.allowFlagging === false) {
return false;
}
return true;
}
/**
* A collection of buttons in the footer area of an annotation that take
* actions on the annotation.
......@@ -53,7 +63,9 @@ function AnnotationActionBar({
// Only authenticated users can flag an annotation, except the annotation's author.
const showFlagAction =
!!userProfile.userid && userProfile.userid !== annotation.user;
flaggingEnabled(settings) &&
!!userProfile.userid &&
userProfile.userid !== annotation.user;
const shareLink =
sharingEnabled(settings) && annotationSharingLink(annotation);
......
......@@ -269,6 +269,13 @@ describe('AnnotationActionBar', () => {
assert.isFalse(getButton(wrapper, 'flag').exists());
});
it('hides flag button if flagging is disabled in the settings', () => {
fakeSettings = { services: [{ allowFlagging: false }] };
const wrapper = createComponent();
assert.isFalse(getButton(wrapper, 'flag').exists());
});
it('shows flag button if user is not author', () => {
const wrapper = createComponent();
......
......@@ -15,6 +15,7 @@
* @prop {string[]|Promise<string[]>} [groups] -
* List of groups to show. The embedder can specify an array. In the sidebar
* this may be converted to a Promise if this information is fetched asynchronously.
* @prop {boolean} [allowFlagging]
* @prop {boolean} [allowLeavingGroups]
* @prop {boolean} [enableShareLinks]
* @prop {Function} [onLoginRequest]
......
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