Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

metadata history viewing with user profile level #7450

Merged
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
ba0888f
metadata history viewing with user profile level
wangf1122 Oct 23, 2023
b7f7b3e
Access level restriction to /status/search API
wangf1122 Oct 30, 2023
fd48d9f
error message update
wangf1122 Oct 30, 2023
9b4b3f6
comment description
wangf1122 Oct 31, 2023
7c2d184
allow registered user to view metadata history and part of the access…
wangf1122 Nov 1, 2023
9e9d09a
remove log
wangf1122 Nov 2, 2023
4c22429
Not check edit privilege if the user profile is registered user and r…
wangf1122 Nov 3, 2023
7709646
Not check edit privilege if the user profile is registered user and r…
wangf1122 Nov 3, 2023
ac9d91c
remove reviewer to access level setup. Add security check for registe…
wangf1122 Nov 6, 2023
c294463
remove configuration profile level check
wangf1122 Nov 7, 2023
8d13b8e
Merge branch 'geonetwork:main' into main.metadata.history.access.level
wangf1122 Nov 15, 2023
0dcfcab
Removed junk code
wangf1122 Nov 15, 2023
deaf064
refactor system/metadata/history/enabled to metadata/history/enabled …
wangf1122 Nov 16, 2023
4f16b91
Help text update
wangf1122 Nov 16, 2023
e2e76ff
Readme update
wangf1122 Nov 16, 2023
7974efa
Update web-ui/src/main/resources/catalog/templates/admin/settings/sys…
wangf1122 Nov 16, 2023
80eddab
Fix formatting issue
wangf1122 Nov 17, 2023
f4ee086
Merge branch 'main' into main.metadata.history.access.level
wangf1122 Nov 29, 2023
d908561
release
wangf1122 Nov 29, 2023
3d172b8
Merge branch 'main' into main.metadata.history.access.level
wangf1122 Jan 15, 2024
9aa3b6e
revert migration script.
wangf1122 Jan 15, 2024
62dfa16
Merge branch 'main' into main.metadata.history.access.level
wangf1122 Jan 23, 2024
f2a5ffa
443 migration script
wangf1122 Jan 23, 2024
9ac4bcf
Merge remote-tracking branch 'origin/main.metadata.history.access.lev…
wangf1122 Jan 23, 2024
38e31a5
443 migration script
wangf1122 Jan 23, 2024
a499d1e
revert 442 script merge junks
wangf1122 Jan 23, 2024
87e2637
change metadata/history/enabled property path in mdviewModule javascript
wangf1122 Mar 27, 2024
ead9a51
Merge branch 'main' into main.metadata.history.access.level
wangf1122 Apr 5, 2024
eac2007
Update migrate-default.sql
wangf1122 Apr 5, 2024
9fa5a4b
Update migrate-default.sql
wangf1122 Apr 5, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ public class Settings {
public static final String METADATA_IMPORT_RESTRICT = "metadata/import/restrict";
public static final String METADATA_IMPORT_USERPROFILE = "metadata/import/userprofile";
public static final String METADATA_BATCH_EDITING_ACCESS_LEVEL = "metadata/batchediting/accesslevel";
public static final String METADATA_HISTORY_ACCESS_LEVEL = "metadata/history/accesslevel";
public static final String METADATA_PUBLISHED_DELETE_USERPROFILE = "metadata/delete/profilePublishedMetadata";
public static final String METADATA_PUBLISH_USERPROFILE = "metadata/publication/profilePublishMetadata";
public static final String METADATA_UNPUBLISH_USERPROFILE = "metadata/publication/profileUnpublishMetadata";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
import org.fao.geonet.kernel.setting.Settings;
import org.fao.geonet.repository.*;
import org.fao.geonet.util.MetadataPublicationMailNotifier;
import org.fao.geonet.util.UserUtil;
import org.fao.geonet.utils.Log;
import org.fao.geonet.utils.Xml;
import org.jdom.Element;
Expand All @@ -71,6 +72,7 @@
import org.springframework.data.domain.Sort;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.security.access.hierarchicalroles.RoleHierarchy;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
Expand Down Expand Up @@ -149,6 +151,9 @@ public class MetadataWorkflowApi {
@Autowired
MetadataPublicationMailNotifier metadataPublicationMailNotifier;

@Autowired
RoleHierarchy roleHierarchy;

// The restore function currently supports these states
static final Integer[] supportedRestoreStatuses = {
Integer.parseInt(StatusValue.Events.RECORDUPDATED),
Expand Down Expand Up @@ -692,6 +697,7 @@ public List<MetadataStatusResponse> getWorkflowStatusByType(
Integer size,
HttpServletRequest request) throws Exception {
ServiceContext context = ApiUtils.createServiceContext(request);
checkUserProfileToViewMetadataHistory(context.getUserSession());
ianwallen marked this conversation as resolved.
Show resolved Hide resolved

Profile profile = context.getUserSession().getProfile();
if (profile != Profile.Administrator) {
Expand Down Expand Up @@ -1310,4 +1316,23 @@ private void changeMetadataStatus(ServiceContext context, AbstractMetadata metad
listOfStatusChange.add(metadataStatusValue);
sa.onStatusChange(listOfStatusChange);
}


/**
* Checks if the user profile is allowed to view metadata history status.
*
* @param userSession
*/
private void checkUserProfileToViewMetadataHistory(UserSession userSession) {
if (userSession.getProfile() != Profile.Administrator) {
String allowedUserProfileToImportMetadata =
org.apache.commons.lang.StringUtils.defaultIfBlank(settingManager.getValue(Settings.METADATA_HISTORY_ACCESS_LEVEL), Profile.Editor.toString());

// Is the user profile higher than the profile allowed?
if (!UserUtil.hasHierarchyRole(allowedUserProfileToImportMetadata, this.roleHierarchy)) {
throw new NotAllowedException("The user has no permissions to view metadata history.");
}
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ private void checkUserProfileToBatchEditMetadata(UserSession userSession) {
String allowedUserProfileToImportMetadata =
StringUtils.defaultIfBlank(settingManager.getValue(Settings.METADATA_BATCH_EDITING_ACCESS_LEVEL), Profile.Editor.toString());

// Is the user profile is higher than the profile allowed to import metadata?
// Is the user profile higher than the profile allowed to import metadata?
if (!UserUtil.hasHierarchyRole(allowedUserProfileToImportMetadata, this.roleHierarchy)) {
throw new NotAllowedException("The user has no permissions to batch edit metadata.");
}
Expand Down
9 changes: 9 additions & 0 deletions web-ui/src/main/resources/catalog/js/CatController.js
Original file line number Diff line number Diff line change
Expand Up @@ -1841,6 +1841,15 @@
: "";
return angular.isFunction(this[fnName]) ? this[fnName]() : false;
},
canViewMetadataHistory: function () {
var profile = gnConfig["metadata.history.accesslevel"] || 'Editor',
ianwallen marked this conversation as resolved.
Show resolved Hide resolved
fnName =
profile !== ''
? 'is' + profile[0].toUpperCase() + profile.substring(1) + 'OrMore'
: '';
console.log("User profile to view history: "+profile);
ianwallen marked this conversation as resolved.
Show resolved Hide resolved
return angular.isFunction(this[fnName]) ? this[fnName]() : false;
ianwallen marked this conversation as resolved.
Show resolved Hide resolved
},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please update the file with prettier formatting.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The format was indeed lining with all methods. It was copy pasted. Here is what my IDE looks like. The pretty formatting will need to be at the whole file level not limited to the code that I commit.

image

canDeletePublishedMetadata: function () {
var profile =
gnConfig["metadata.delete.profilePublishedMetadata"] || "Editor",
Expand Down
3 changes: 3 additions & 0 deletions web-ui/src/main/resources/catalog/locales/en-admin.json
Original file line number Diff line number Diff line change
Expand Up @@ -874,6 +874,9 @@
"metadata/publication/profilePublishMetadata-help": "Minimum user profile allowed to publish metadata (Reviewer or Administrator). The default value is Reviewer.",
"metadata/publication/profileUnpublishMetadata": "Minimum user profile allowed to un-publish metadata",
"metadata/publication/profileUnpublishMetadata-help": "Minimum user profile allowed to un-publish metadata (Reviewer or Administrator). The default value is Reviewer.",
"metadata/history": "Metadata History",
"metadata/history/accesslevel": "Select the minimum user profile allowed to view metadata history",
"metadata/history/accesslevel-help": "Select the minimum user profile allowed to view metadata history (Registered User, Editor, Reviewer or Administrator). The default value is Editor.",
"filterStatusByAuthor":"Status author",
"filterStatusByOwner":"Status owner",
"filterStatusByRecordId":"Record identifier",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,23 @@ <h3>{{section2.name | translate}}</h3>
</option>
</select>

<select data-ng-switch-when="metadata/history/accesslevel"
class="form-control"
name="{{s.name}}">
<option value="RegisteredUser"
ng-selected="'RegisteredUser' == s.value">{{'RegisteredUser' | translate}}
</option>
<option value="Editor"
ng-selected="'Editor' == s.value">{{'Editor' | translate}}
</option>
<option value="Reviewer"
ng-selected="'Reviewer' == s.value">{{'Reviewer' | translate}}
</option>
<option value="Administrator"
ng-selected="'Administrator' == s.value">{{'Administrator' | translate}}
</option>
</select>

<div data-ng-switch-when="system/metadatacreate/preferredGroup">
<input
type="hidden"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<div
class="row gn-padding-top"
data-ng-if="isRecordHistoryEnabled
&& user.isEditorOrMore()
&& user.canViewMetadataHistory()
&& mdView.current.record.draft != 'y'"
>
<div class="col-md-12">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -695,6 +695,8 @@ INSERT INTO Settings (name, value, datatype, position, internal) VALUES ('metada

INSERT INTO Settings (name, value, datatype, position, internal) VALUES ('metadata/batchediting/accesslevel', 'Editor', 0, 12020, 'n');

INSERT INTO Settings (name, value, datatype, position, internal) VALUES ('metadata/history/accesslevel', 'Editor', 0, 12021, 'n');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see this other setting:

INSERT INTO Settings (name, value, datatype, position, internal) VALUES ('system/metadata/history/enabled', 'false', 2, 9171, 'n');

To enable the history, maybe can be unified, either changing the new one to be in system/metadata/... or add a migration to move this one to metadata/history/...

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The system/... does not work very well on UI. I will try metadata/history/enable

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have migrated all system/metadata/history/enabled to metadata/history/enabled including database migration script with and update statement, ui, and Java constants.


INSERT INTO Settings (name, value, datatype, position, internal) VALUES ('metadata/delete/profilePublishedMetadata', 'Editor', 0, 12011, 'n');

INSERT INTO Settings (name, value, datatype, position, internal) VALUES ('metadata/publication/profilePublishMetadata', 'Reviewer', 0, 12021, 'n');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ UPDATE Settings SET value='4.4.0' WHERE name='system/platform/version';
UPDATE Settings SET value='0' WHERE name='system/platform/subVersion';

INSERT INTO Settings (name, value, datatype, position, internal) SELECT distinct 'metadata/batchediting/accesslevel', 'Editor', 0, 12020, 'n' from settings WHERE NOT EXISTS (SELECT name FROM Settings WHERE name = 'metadata/batchediting/accesslevel');
INSERT INTO Settings (name, value, datatype, position, internal) SELECT distinct 'metadata/history/accesslevel', 'Editor', 0, 12021, 'n' from settings WHERE NOT EXISTS (SELECT name FROM Settings WHERE name = 'metadata/history/accesslevel');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I moved the script to v441. I also added update statement to set the name of system/metadata/history/enabled to metadata/history/enabled as you suggested in another comment

Loading