Skip to content

Commit 9c8baf5

Browse files
josegar74fxprunayre
authored andcommitted
Metadata workflow API / Update security exceptions to use translations
1 parent ffdb391 commit 9c8baf5

File tree

5 files changed

+19
-11
lines changed

5 files changed

+19
-11
lines changed

core/src/test/resources/org/fao/geonet/api/Messages.properties

+2
Original file line numberDiff line numberDiff line change
@@ -214,3 +214,5 @@ api.metadata.share.errorMetadataNotApproved=The metadata '%s' it's not approved,
214214
api.metadata.share.ErrorUserNotAllowedToPublish=User not allowed to publish the metadata %s. %s
215215
api.metadata.share.strategy.groupOwnerOnly=You need to be administrator, or reviewer of the metadata group.
216216
api.metadata.share.strategy.reviewerInGroup=You need to be administrator, or reviewer of the metadata group or reviewer with edit privilege on the metadata.
217+
api.metadata.status.errorGetStatusNotAllowed=Only the owner of the metadata can get the status. User is not the owner of the metadata.
218+
api.metadata.status.errorSetStatusNotAllowed=Only the owner of the metadata can set the status of this record. User is not the owner of the metadata.

core/src/test/resources/org/fao/geonet/api/Messages_fre.properties

+2
Original file line numberDiff line numberDiff line change
@@ -201,3 +201,5 @@ api.metadata.share.errorMetadataNotApproved=La fiche '%s' n'est pas approuv\u00E
201201
api.metadata.share.ErrorUserNotAllowedToPublish=L'utilisateur n'est pas autoris\u00E9 \u00E0 publier la fiche %s. %s
202202
api.metadata.share.strategy.groupOwnerOnly=Vous devez \u00EAtre administrateur ou relecteur du groupe de la fiche.
203203
api.metadata.share.strategy.reviewerInGroup=Vous devez \u00EAtre administrateur ou relecteur du groupe de la fiche ou relecteur avec un privil\u00E8ge de modification sur les fiches.
204+
api.metadata.status.errorGetStatusNotAllowed=Seul le propri\u00E9taire des m\u00E9tadonn\u00E9es peut obtenir le statut de cet enregistrement. L'utilisateur n'est pas le propri\u00E9taire des m\u00E9tadonn\u00E9es
205+
api.metadata.status.errorSetStatusNotAllowed=Seul le propri\u00E9taire des m\u00E9tadonn\u00E9es peut d\u00E9finir le statut de cet enregistrement. L'utilisateur n'est pas le propri\u00E9taire des m\u00E9tadonn\u00E9es

services/src/main/java/org/fao/geonet/api/records/MetadataWorkflowApi.java

+11-11
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2001-2023 Food and Agriculture Organization of the
2+
* Copyright (C) 2001-2024 Food and Agriculture Organization of the
33
* United Nations (FAO-UN), United Nations World Food Programme (WFP)
44
* and United Nations Environment Programme (UNEP)
55
*
@@ -60,7 +60,6 @@
6060
import org.fao.geonet.kernel.setting.Settings;
6161
import org.fao.geonet.repository.*;
6262
import org.fao.geonet.util.MetadataPublicationMailNotifier;
63-
import org.fao.geonet.util.UserUtil;
6463
import org.fao.geonet.utils.Log;
6564
import org.fao.geonet.utils.Xml;
6665
import org.jdom.Element;
@@ -224,12 +223,13 @@ public MetadataWorkflowStatusResponse getStatus(
224223
HttpServletRequest request) throws Exception {
225224
AbstractMetadata metadata = ApiUtils.canEditRecord(metadataUuid, request);
226225
Locale locale = languageUtils.parseAcceptLanguage(request.getLocales());
226+
ResourceBundle messages = ApiUtils.getMessagesResourceBundle(request.getLocales());
227227
ServiceContext context = ApiUtils.createServiceContext(request, locale.getISO3Language());
228228

229229
// --- only allow the owner of the record to set its status
230230
if (!accessManager.isOwner(context, String.valueOf(metadata.getId()))) {
231231
throw new SecurityException(
232-
"Only the owner of the metadata can get the status. User is not the owner of the metadata");
232+
messages.getString("api.metadata.status.errorGetStatusNotAllowed"));
233233
}
234234

235235
MetadataStatus recordStatus = metadataStatus.getStatus(metadata.getId());
@@ -476,7 +476,7 @@ public Map<Integer, StatusChangeType> setStatus(@Parameter(description = API_PAR
476476
// --- only allow the owner of the record to set its status
477477
if (!accessManager.isOwner(context, String.valueOf(metadata.getId()))) {
478478
throw new SecurityException(
479-
"Only the owner of the metadata can set the status of this record. User is not the owner of the metadata.");
479+
messages.getString("api.metadata.status.errorSetStatusNotAllowed"));
480480
}
481481

482482
boolean isAllowedSubmitApproveInvalidMd = settingManager
@@ -526,13 +526,13 @@ public Map<Integer, StatusChangeType> setStatus(@Parameter(description = API_PAR
526526

527527
if ((status.getStatus() == Integer.parseInt(StatusValue.Status.APPROVED) && notifyByEmail)
528528
&& (this.metadataUtils.isMetadataPublished(metadataIdApproved))) {
529-
MetadataPublicationNotificationInfo metadataNotificationInfo = new MetadataPublicationNotificationInfo();
530-
metadataNotificationInfo.setMetadataUuid(metadata.getUuid());
531-
metadataNotificationInfo.setMetadataId(metadataIdApproved);
532-
metadataNotificationInfo.setGroupId(metadata.getSourceInfo().getGroupOwner());
533-
metadataNotificationInfo.setPublished(true);
534-
metadataNotificationInfo.setPublicationDateStamp(new ISODate());
535-
metadataNotificationInfo.setReapproval(metadataIdApproved != metadata.getId());
529+
MetadataPublicationNotificationInfo metadataNotificationInfo = new MetadataPublicationNotificationInfo();
530+
metadataNotificationInfo.setMetadataUuid(metadata.getUuid());
531+
metadataNotificationInfo.setMetadataId(metadataIdApproved);
532+
metadataNotificationInfo.setGroupId(metadata.getSourceInfo().getGroupOwner());
533+
metadataNotificationInfo.setPublished(true);
534+
metadataNotificationInfo.setPublicationDateStamp(new ISODate());
535+
metadataNotificationInfo.setReapproval(metadataIdApproved != metadata.getId());
536536

537537

538538
// If the metadata workflow is enabled retrieve the submitter and reviewer users information

web/src/main/webapp/WEB-INF/classes/org/fao/geonet/api/Messages.properties

+2
Original file line numberDiff line numberDiff line change
@@ -216,3 +216,5 @@ api.metadata.share.errorMetadataNotApproved=The metadata '%s' it's not approved,
216216
api.metadata.share.ErrorUserNotAllowedToPublish=User not allowed to publish the metadata %s. %s
217217
api.metadata.share.strategy.groupOwnerOnly=You need to be administrator, or reviewer of the metadata group.
218218
api.metadata.share.strategy.reviewerInGroup=You need to be administrator, or reviewer of the metadata group or reviewer with edit privilege on the metadata.
219+
api.metadata.status.errorGetStatusNotAllowed=Only the owner of the metadata can get the status. User is not the owner of the metadata.
220+
api.metadata.status.errorSetStatusNotAllowed=Only the owner of the metadata can set the status of this record. User is not the owner of the metadata.

web/src/main/webapp/WEB-INF/classes/org/fao/geonet/api/Messages_fre.properties

+2
Original file line numberDiff line numberDiff line change
@@ -201,3 +201,5 @@ api.metadata.share.errorMetadataNotApproved=La fiche '%s' n'est pas approuv\u00E
201201
api.metadata.share.ErrorUserNotAllowedToPublish=L'utilisateur n'est pas autoris\u00E9 \u00E0 publier la fiche %s. %s
202202
api.metadata.share.strategy.groupOwnerOnly=Vous devez \u00EAtre administrateur ou relecteur du groupe de la fiche.
203203
api.metadata.share.strategy.reviewerInGroup=Vous devez \u00EAtre administrateur ou relecteur du groupe de la fiche ou relecteur avec un privil\u00E8ge de modification sur les fiches.
204+
api.metadata.status.errorGetStatusNotAllowed=Seul le propri\u00E9taire des m\u00E9tadonn\u00E9es peut obtenir le statut de cet enregistrement. L'utilisateur n'est pas le propri\u00E9taire des m\u00E9tadonn\u00E9es
205+
api.metadata.status.errorSetStatusNotAllowed=Seul le propri\u00E9taire des m\u00E9tadonn\u00E9es peut d\u00E9finir le statut de cet enregistrement. L'utilisateur n'est pas le propri\u00E9taire des m\u00E9tadonn\u00E9es

0 commit comments

Comments
 (0)