Skip to content

Commit

Permalink
UserCard: do not show "Create copy" button if user not allowed to pub…
Browse files Browse the repository at this point in the history
…lish the card (#7427)

Signed-off-by: Giovanni Ferrari <[email protected]>
  • Loading branch information
quinarygio committed Oct 23, 2024
1 parent 692719d commit 25bfa7b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/test/cypress/cypress/integration/UserCard.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1334,7 +1334,6 @@ describe('User Card ', function () {
})
})


describe('Check "create a copy" feature', function () {

it('Check "create a copy" button is present only when it should', () => {
Expand All @@ -1361,6 +1360,18 @@ describe('User Card ', function () {

feed.openNthCard(5);
card.checkCopyButtonDoesExist();

// chack "create a copy" button is not visible if user not in publisherList entities
opfab.navigateToUserCard();
usercard.selectService('Base Examples');
usercard.selectProcess('Process example');
usercard.selectState('Process example');
usercard.selectRecipient('Control Center FR South');
usercard.previewThenSendCard();
opfab.logout();
opfab.loginWithUser('operator2_fr');
feed.openFirstCard();
card.checkCopyButtonDoesNotExist();
})


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import {NgIf} from '@angular/common';
import {TranslateModule} from '@ngx-translate/core';
import {UserCardComponent} from '../../../usercard/usercard.component';
import {SpinnerComponent} from '../../../share/spinner/spinner.component';
import {EntitiesService} from 'app/business/services/users/entities.service';

@Component({
selector: 'of-card-actions',
Expand Down Expand Up @@ -81,9 +82,18 @@ export class CardActionsComponent implements OnChanges, OnDestroy {
!this.isReadOnlyUser &&
this.cardState.copyCardEnabledOnUserInterface &&
this.cardState.userCard &&
this.doesTheUserHavePermissionToPublishCard() &&
UserService.isWriteRightsForProcessAndState(this.card.process, this.card.state);
}

private doesTheUserHavePermissionToPublishCard(): boolean {
if (!this.cardState.userCard.publisherList) return true;
const userEntities = UserService.getCurrentUserWithPerimeters().userData.entities;
const allowedPublishers = EntitiesService.resolveEntities(this.cardState.userCard.publisherList);
const userAllowedEntities = allowedPublishers.filter((publisher) => userEntities.includes(publisher.id));
return userAllowedEntities.length > 0;
}

private doesTheUserHavePermissionToEditCard(): boolean {
return UserPermissionsService.doesTheUserHavePermissionToEditCard(
UserService.getCurrentUserWithPerimeters(),
Expand Down

0 comments on commit 25bfa7b

Please sign in to comment.