Skip to content

Commit

Permalink
Implement cancel ack at the entity level (#5049)
Browse files Browse the repository at this point in the history
Signed-off-by: Giovanni Ferrari <giovanni.ferrari@soft.it>
  • Loading branch information
quinarygio committed Jan 29, 2024
1 parent 2f49581 commit 4817464
Show file tree
Hide file tree
Showing 12 changed files with 71 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -194,16 +194,17 @@ public Void postUserCardRead(Principal principal,
}

/**
* DELETE userAcknowledgement for a card to updating that card
* POST cancelUserAcknowledgement for a card to updating that card
*
* @param cardUid Id to create publisher
*/
@DeleteMapping("/userAcknowledgement/{cardUid}")
@PostMapping("/cancelUserAcknowledgement/{cardUid}")
public Void deleteUserAcknowledgement(Principal principal, @PathVariable("cardUid") String cardUid,
@RequestBody List<String> entitiesAcks,
HttpServletResponse response) {
OpFabJwtAuthenticationToken jwtPrincipal = (OpFabJwtAuthenticationToken) principal;
CurrentUserWithPerimeters user = (CurrentUserWithPerimeters) jwtPrincipal.getPrincipal();
UserBasedOperationResult result = cardProcessingService.deleteUserAcknowledgement(cardUid, user.getUserData().getLogin());
UserBasedOperationResult result = cardProcessingService.deleteUserAcknowledgement(cardUid, user, entitiesAcks);
if (!result.isCardFound())
response.setStatus(404);
else {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright (c) 2018-2023, RTE (http://www.rte-france.com)
/* Copyright (c) 2018-2024, RTE (http://www.rte-france.com)
* See AUTHORS.txt
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
Expand Down Expand Up @@ -127,9 +127,12 @@ public UserBasedOperationResult addUserRead(String name, String cardUid) {
return toUserBasedOperationResult(updateFirst);
}

public UserBasedOperationResult deleteUserAck(String userName, String cardUid) {
public UserBasedOperationResult deleteUserAck(String userName, String cardUid, List<String> entitiesAcks) {
Update update = new Update().pull(USERS_ACKS, userName);
if (entitiesAcks != null)
update = update.pullAll(ENTITIES_ACKS, entitiesAcks.toArray());
UpdateResult updateFirst = template.updateFirst(Query.query(Criteria.where("uid").is(cardUid)),
new Update().pull(USERS_ACKS, userName), CardPublicationData.class);
update, CardPublicationData.class);
log.debug("removed {} occurrence of {}'s userAcks in the card with uid: {}", updateFirst.getModifiedCount(),
cardUid);
return toUserBasedOperationResult(updateFirst);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

/* Copyright (c) 2023, RTE (http://www.rte-france.com)
/* Copyright (c) 2023-2024, RTE (http://www.rte-france.com)
* See AUTHORS.txt
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
Expand Down Expand Up @@ -40,7 +40,7 @@ public interface CardRepository {

public UserBasedOperationResult addUserRead(String name, String cardUid);

public UserBasedOperationResult deleteUserAck(String userName, String cardUid);
public UserBasedOperationResult deleteUserAck(String userName, String cardUid, List<String> entitiesAcks);

public UserBasedOperationResult deleteUserRead(String userName, String cardUid);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -320,9 +320,16 @@ public UserBasedOperationResult deleteUserRead(String cardUid, String userName)
return cardRepository.deleteUserRead(userName, cardUid);
}

public UserBasedOperationResult deleteUserAcknowledgement(String cardUid, String userName) {
log.info("Delete ack on card with uid {} for user {} ", cardUid, userName);
return cardRepository.deleteUserAck(userName, cardUid);
public UserBasedOperationResult deleteUserAcknowledgement(String cardUid, CurrentUserWithPerimeters user, List<String> entitiesAcks) {
log.info("Delete ack on card with uid {} for user {} and entities {} ", cardUid, user.getUserData().getLogin(), entitiesAcks);

if (!user.getUserData().getEntities().containsAll(entitiesAcks))
throw new ApiErrorException(ApiError.builder()
.status(HttpStatus.FORBIDDEN)
.message("Cancel acknowledgement impossible : User is not member of all the entities given in the request")
.build());

return cardRepository.deleteUserAck(user.getUserData().getLogin(), cardUid, entitiesAcks);

}

Expand Down
16 changes: 15 additions & 1 deletion services/cards-publication/src/main/modeling/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1107,7 +1107,21 @@ paths:
description: No action done, the item already exists
'404':
description: Try to remove item from unexisting card
delete:
'/cards/cancelUserAcknowledgement/{uid}':
parameters:
- in: path
name: uid
type: string
required: true
description: "The card uid"
- in: body
name: entitiesAcks
description: List of user entities for which the card will be acknowledged
schema:
type: array
items:
type: string
post:
operationId: deleteUserAcknowledgement
tags:
- cards
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright (c) 2023, RTE (http://www.rte-france.com)
/* Copyright (c) 2023-2024, RTE (http://www.rte-france.com)
* See AUTHORS.txt
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
Expand Down Expand Up @@ -98,7 +98,7 @@ public Optional<List<CardPublicationData>> findChildCard(CardPublicationData car

@Override
public UserBasedOperationResult addUserAck(User user, String cardUid, List<String> entitiesAcks) {
throw new UnsupportedOperationException("Unimplemented method 'addUserRead'");
throw new UnsupportedOperationException("Unimplemented method 'addUserAck'");
}

@Override
Expand All @@ -107,7 +107,7 @@ public UserBasedOperationResult addUserRead(String name, String cardUid) {
}

@Override
public UserBasedOperationResult deleteUserAck(String userName, String cardUid) {
public UserBasedOperationResult deleteUserAck(String userName, String cardUid, List<String> entitiesAcks) {
throw new UnsupportedOperationException("Unimplemented method 'deleteUserAck'");
}

Expand Down
29 changes: 18 additions & 11 deletions src/test/api/karate/cards/cardsUserAcks.feature
Original file line number Diff line number Diff line change
Expand Up @@ -173,33 +173,40 @@ Feature: CardsUserAcknowledgement
When method post
Then status 404

#cancel acknowledgement to the card with operator1_fr with entities for which the user is not a member
Given url opfabUrl + 'cardspub/cards/cancelUserAcknowledgement/' + uid
And header Authorization = 'Bearer ' + authToken
And request entity1entity2Array
When method post
Then status 403


Given url opfabUrl + 'cardspub/cards/userAcknowledgement/' + uid
Given url opfabUrl + 'cardspub/cards/cancelUserAcknowledgement/' + uid
And header Authorization = 'Bearer ' + authToken
When method delete
And request entity1Array
When method post
Then status 200

Given url opfabUrl + 'cards/cards/api_test.process1'
And header Authorization = 'Bearer ' + authToken
When method get
Then status 200
# unacknowledgment is onluy possible at the user level and not at the entity level
And match response.card.entitiesAcks == ["ENTITY1_FR","ENTITY2_FR"]
# card is unacknowledged also at the entity level
And match response.card.entitiesAcks == ["ENTITY2_FR"]
And match response.card.hasBeenAcknowledged == false
And match response.card.uid == uid

Given url opfabUrl + 'cardspub/cards/userAcknowledgement/' + uid
Given url opfabUrl + 'cardspub/cards/cancelUserAcknowledgement/' + uid
And header Authorization = 'Bearer ' + authToken
When method delete
And request entity1Array
When method post
Then status 204


#ack unexisting card

Given url opfabUrl + 'cardspub/cards/userAcknowledgement/unexisting_card____uid'
#unack unexisting card
Given url opfabUrl + 'cardspub/cards/cancelUserAcknowledgement/unexisting_card____uid'
And header Authorization = 'Bearer ' + authToken
When method delete
And request entity1Array
When method post
Then status 404

Scenario: Delete the test card
Expand Down
3 changes: 2 additions & 1 deletion src/test/cypress/cypress/integration/Acknowledgment.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright (c) 2021-2023, RTE (http://www.rte-france.com)
/* Copyright (c) 2021-2024, RTE (http://www.rte-france.com)
* See AUTHORS.txt
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
Expand Down Expand Up @@ -566,6 +566,7 @@ describe('Acknowledgment tests', function () {

// Click on card message
cy.get('#opfab-feed-light-card-cypress-message2').click();
cy.delayRequestResponse('/cardspub/cards/cancelUserAcknowledgement/*');

card.unacknowledge();

Expand Down
4 changes: 2 additions & 2 deletions ui/main/src/app/business/server/acknowledge.server.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright (c) 2023, RTE (http://www.rte-france.com)
/* Copyright (c) 2023-2024, RTE (http://www.rte-france.com)
* See AUTHORS.txt
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
Expand All @@ -14,5 +14,5 @@ export abstract class AcknowledgeServer {

abstract postUserAcknowledgement(cardUid: string, entitiesAcks: string[]): Observable<ServerResponse<void>>;

abstract deleteUserAcknowledgement(cardUid: string): Observable<ServerResponse<void>>;
abstract deleteUserAcknowledgement(cardUid: string, entitiesAcks: string[]): Observable<ServerResponse<void>>;
}
4 changes: 2 additions & 2 deletions ui/main/src/app/business/services/acknowledge.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ export class AcknowledgeService {
return AcknowledgeService.acknowledgeServer.postUserAcknowledgement(cardUid, entitiesAcks);
}

public static deleteUserAcknowledgement(cardUid: string): Observable<ServerResponse<void>> {
return AcknowledgeService.acknowledgeServer.deleteUserAcknowledgement(cardUid);
public static deleteUserAcknowledgement(cardUid: string, entitiesAcks: string[]): Observable<ServerResponse<void>> {
return AcknowledgeService.acknowledgeServer.deleteUserAcknowledgement(cardUid, entitiesAcks);
}

public static isAcknowledgmentAllowed(user: UserWithPerimeters, card: Card | LightCard, processDefinition: Process): boolean {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,8 @@ export class CardAckComponent implements OnInit, OnChanges, OnDestroy {

public cancelAcknowledgement() {
this.ackOrUnackInProgress = true;
AcknowledgeService.deleteUserAcknowledgement(this.card.uid).subscribe((resp) => {
const entitiesAcks = this.computeAcknowledgedEntities();
AcknowledgeService.deleteUserAcknowledgement(this.card.uid, entitiesAcks).subscribe((resp) => {
this.ackOrUnackInProgress = false;
if (resp.status === ServerResponseStatus.OK) {
this.card = {...this.card, hasBeenAcknowledged: false};
Expand Down
8 changes: 5 additions & 3 deletions ui/main/src/app/server/angularAcknowledgement.server.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright (c) 2018-2023, RTE (http://www.rte-france.com)
/* Copyright (c) 2018-2024, RTE (http://www.rte-france.com)
* See AUTHORS.txt
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
Expand All @@ -20,12 +20,14 @@ import {ServerResponse} from 'app/business/server/serverResponse';
})
export class AngularAcknowledgeServer extends AngularServer implements AcknowledgeServer {
readonly userAckUrl: string;
readonly cancelUserAckUrl: string;

constructor(
private httpClient: HttpClient,
) {
super();
this.userAckUrl = `${environment.url}/cardspub/cards/userAcknowledgement`;
this.cancelUserAckUrl = `${environment.url}/cardspub/cards/cancelUserAcknowledgement`;
}

postUserAcknowledgement(cardUid: string, entitiesAcks: string[]): Observable<ServerResponse<void>> {
Expand All @@ -34,8 +36,8 @@ export class AngularAcknowledgeServer extends AngularServer implements Acknowled
);
}

deleteUserAcknowledgement(cardUid: string): Observable<ServerResponse<void>> {
return this.processHttpResponse(this.httpClient.delete<void>(`${this.userAckUrl}/${cardUid}`));
deleteUserAcknowledgement(cardUid: string, entitiesAcks: string[]): Observable<ServerResponse<void>> {
return this.processHttpResponse(this.httpClient.post<void>(`${this.cancelUserAckUrl}/${cardUid}`, entitiesAcks));
}


Expand Down

0 comments on commit 4817464

Please sign in to comment.