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

Conversation

wangf1122
Copy link
Collaborator

@wangf1122 wangf1122 commented Oct 23, 2023

This PR will add such configuration to restrict user profile level to see the record history. The default is set to Editor level which was the old default level. But the feature itself gives more control to the system admin to allow certain level of user to see the history.

image

On the setting page:
image

Please note this feature will need 3.12.x backporting. The UI html is different in 3.12.x

<div data-ng-show="isRecordHistoryEnabled && user.isEditorOrMore() && mdView.current.record.draft != 'y'"
data-gn-record-history="mdView.current.record"></div>
</div>

There will be another small pull request for 3.12 after this one merged.

@wangf1122 wangf1122 marked this pull request as ready for review October 23, 2023 13:45
@josegar74 josegar74 added this to the 4.4.1 milestone Oct 23, 2023
@ianwallen ianwallen requested a review from josegar74 October 29, 2023 11:09
@ianwallen
Copy link
Contributor

Note: I would expect to also see permissions checks added to the api to ensure that only the people with the correct permissions are able to run the api.

@wangf1122
Copy link
Collaborator Author

Note: I would expect to also see permissions checks added to the api to ensure that only the people with the correct permissions are able to run the api.

I cannot find the related API. It was using genera search feature and we cannot block search result. Can you point me which specific backend service we can potentially block?

@ianwallen
Copy link
Contributor

@wangf1122
The following api is used to show history information
image

@wangf1122
Copy link
Collaborator Author

@wangf1122 The following api is used to show history information image

@ianwallen

Thanks. This seems the right API.

But FYI, the 4.0 API is different from 3.12. We will need to resolve the merging issue also need a separated PR to deal with 3.12.

Here is the 4.0 API

@RequestMapping(produces = MediaType.APPLICATION_JSON_VALUE, method = RequestMethod.GET, path = "/status/search")
@ResponseStatus(value = HttpStatus.OK)
@PreAuthorize("hasAuthority('Editor')")
@ResponseBody
public List<MetadataStatusResponse> getWorkflowStatusByType(

vs the 3.12

@RequestMapping(produces = MediaType.APPLICATION_JSON_VALUE, method = RequestMethod.GET, path = "/status/search")
@ResponseStatus(value = HttpStatus.OK)
@PreAuthorize("hasAuthority('Editor')")
@ResponseBody
public List<MetadataStatusResponse> getStatusByType(

The method is renamed from getStatusByType in 3.12 to getWorkflowStatusByType in 4.0

@ianwallen
Copy link
Contributor

As you need to enable history in the Metadata configuration section

image

You may want to move your options to that section as well.

@wangf1122
Copy link
Collaborator Author

As you need to enable history in the Metadata configuration section

image

You may want to move your options to that section as well.

I attempt this. No luck. This config was part of system/metadata. It treated /system path as special path. I also attempt to put such configuration to the system path but the select drop down UI didn't work properly.

@@ -704,7 +712,12 @@ public List<MetadataStatusResponse> getWorkflowStatusByType(
if (!CollectionUtils.isEmpty(recordIdentifier)) {
for (Integer recordId : recordIdentifier) {
try {
ApiUtils.canEditRecord(String.valueOf(recordId), request);
if (allowedAccessLevelProfile == Profile.RegisteredUser) {
Copy link
Member

Choose a reason for hiding this comment

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

With this change, when selecting the RegisteredUser access level, users will be able to see the history of metadata that they can view, while selecting other values, only the metadata they can edit.

I think at least should be added some explanation in https://github.com/geonetwork/core-geonetwork/pull/7450/files#diff-e312a431007c32b1300d73d63418ba4ef8154f864ce4734d7461822738478ca9R886

Also at the end of this manual page a section describing the feature would be good: https://docs.geonetwork-opensource.org/4.2/administrator-guide/configuring-the-catalog/system-configuration/

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 update both help text, also add the the section in system-configuration.md

@@ -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

return true;
}
return angular.isFunction(this[fnName]) ? this[fnName]() : false;
},
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

@ianwallen ianwallen requested a review from josegar74 December 13, 2023 14:01
@@ -5,7 +5,7 @@ INSERT INTO Settings (name, value, datatype, position, internal) VALUES ('system
INSERT INTO Settings (name, value, datatype, position, internal) VALUES ('system/publication/doi/doipassword', '', 0, 194, 'n');
INSERT INTO Settings (name, value, datatype, position, internal) VALUES ('system/publication/doi/doikey', '', 0, 195, 'n');
INSERT INTO Settings (name, value, datatype, position, internal) VALUES ('system/publication/doi/doilandingpagetemplate', 'http://localhost:8080/geonetwork/srv/resources/records/{{uuid}}', 0, 195, 'n');
INSERT INTO Settings (name, value, datatype, position, internal) VALUES ('system/metadata/history/enabled', 'false', 2, 9171, 'n');
INSERT INTO Settings (name, value, datatype, position, internal) VALUES ('metadata/history/enabled', 'false', 2, 9171, 'n');
Copy link
Member

Choose a reason for hiding this comment

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

This change is not required, would be done in the 4.4.2 migration.

Copy link
Collaborator Author

@wangf1122 wangf1122 Jan 15, 2024

Choose a reason for hiding this comment

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

I have removed the change. The update itself will be part of 442 script

profile !== ""
? "is" + profile[0].toUpperCase() + profile.substring(1) + "OrMore"
: "";
if (profile === "RegisteredUser") {
Copy link
Member

Choose a reason for hiding this comment

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

Is this check required because there is no RegisteredUserOrMore function defined I guess?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

There is no RegisteredUserOrMore function and this is why I am adding this condition. There is a case when the user is totally not logged in, like the was access by some random internet visitor

@wangf1122 wangf1122 force-pushed the main.metadata.history.access.level branch from 6e08271 to 9aa3b6e Compare January 15, 2024 18:08
@ianwallen ianwallen requested a review from josegar74 January 15, 2024 18:19
@fxprunayre fxprunayre modified the milestones: 4.4.2, 4.4.3 Jan 23, 2024
@fxprunayre fxprunayre modified the milestones: 4.4.3, 4.4.4 Mar 13, 2024
Copy link
Member

@josegar74 josegar74 left a comment

Choose a reason for hiding this comment

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

@wangf1122 Tested, looks ok.

Please check the to update the setting name in https://github.com/wangf1122/core-geonetwork/blob/a499d1eb57a0f4a0a6596ae91ccecbefe0e0ee9b/web-ui/src/main/resources/catalog/components/search/mdview/mdviewModule.js#L108

Also resolve the conflicts and move the SQL migration to 4.4.4.

@wangf1122
Copy link
Collaborator Author

@ianwallen ianwallen merged commit c67fea3 into geonetwork:main Apr 5, 2024
7 checks passed
@geonetworkbuild
Copy link
Collaborator

The backport to 3.12.x failed:

The process '/usr/bin/git' failed with exit code 1
stderr
error: could not apply ba0888f642... metadata history viewing with user profile level
hint: After resolving the conflicts, mark them with
hint: "git add/rm <pathspec>", then run
hint: "git cherry-pick --continue".
hint: You can instead skip this commit with "git cherry-pick --skip".
hint: To abort and get back to the state before "git cherry-pick",
hint: run "git cherry-pick --abort".

stdout
Auto-merging web-ui/src/main/resources/catalog/js/CatController.js
Auto-merging web-ui/src/main/resources/catalog/locales/en-admin.json
CONFLICT (content): Merge conflict in web-ui/src/main/resources/catalog/locales/en-admin.json
Auto-merging web-ui/src/main/resources/catalog/templates/admin/settings/system.html
CONFLICT (content): Merge conflict in web-ui/src/main/resources/catalog/templates/admin/settings/system.html
CONFLICT (modify/delete): web-ui/src/main/resources/catalog/views/default/templates/recordView/footer.html deleted in HEAD and modified in ba0888f642 (metadata history viewing with user profile level).  Version ba0888f642 (metadata history viewing with user profile level) of web-ui/src/main/resources/catalog/views/default/templates/recordView/footer.html left in tree.
Auto-merging web/src/main/webapp/WEB-INF/classes/setup/sql/data/data-db-default.sql
Auto-merging web/src/main/webapp/WEB-INF/classes/setup/sql/migrate/v31211/migrate-default.sql

To backport manually, run these commands in your terminal:

# Fetch latest updates from GitHub
git fetch
# Create a new working tree
git worktree add .worktrees/backport-3.12.x 3.12.x
# Navigate to the new working tree
cd .worktrees/backport-3.12.x
# Create a new branch
git switch --create backport-7450-to-3.12.x
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick ba0888f64271446814ae26ba5f1880b385ccb431,b7f7b3ee21916d01240bf776d14651159d778e0f,fd48d9fef40bc3f8a265c3808fad09d526bb29bd,9b4b3f6501514f04eb6f329b4df67efac356c296,7c2d18419ec384d6cf41d8fe0b3b7bc65ee26000,9e9d09a33ed4a27eddd7421c7623bb81ad8de37f,4c224296468b0cac9a3e5148197af8fcc4e40977,7709646684d747208b7c940ff3c4c9721f5f0bc2,ac9d91ce1e66bdf9f1777c393d803a1026a97e29,c294463be98578e97b39a44abafd77f803217cd6,8d13b8eaa985bcb8ec58c75dde58be95c42bf290,0dcfcab998a0224e698da7773aa99fe32d555409,deaf064c56842a9ab99101b1eaafe2c61d8e720b,4f16b91e014fe8321e3eb6269687b8036b7a7d31,e2e76ffb5361d397c0b9a384e25e24c0274135d7,7974efa28df068f6aaf2a12afb8b3d6aeb54b585,80eddabf769ab2bc6c36fc0c789f540af517386d,f4ee0866392797b07133da680ea429182dd250ad,d908561e2f3b64f6b79122a96fc975ef621bd218,3d172b855cbd502ffc3e5530cd1304583cb42e2f,9aa3b6edd097ee919b0e42fa4b633564235fddcc,62dfa16821c1d0b30dbaec76d41bb2e547a65e36,f2a5ffa67faad40475c3173db0e67cfd35c3e51b,9ac4bcfcfa96aa96531e6d27589163ec7b5cc182,38e31a5b458d380b722750a8922420e7c0ffe70b,a499d1eb57a0f4a0a6596ae91ccecbefe0e0ee9b,87e2637eb0a6db8397dac72a5a2e6d01cfb73ffe,ead9a51b78f01ddcd0e9a979cfd161b0b8015706,eac2007602a740541218bcf5ea16ec9e72c7ad31,9fa5a4b540d0f2b598be8f2e969fc9e192ce9982
# Push it to GitHub
git push --set-upstream origin backport-7450-to-3.12.x
# Go back to the original working tree
cd ../..
# Delete the working tree
git worktree remove .worktrees/backport-3.12.x

Then, create a pull request where the base branch is 3.12.x and the compare/head branch is backport-7450-to-3.12.x.

@geonetworkbuild
Copy link
Collaborator

The backport to 4.2.x failed:

The process '/usr/bin/git' failed with exit code 1
stderr
error: could not apply ba0888f642... metadata history viewing with user profile level
hint: After resolving the conflicts, mark them with
hint: "git add/rm <pathspec>", then run
hint: "git cherry-pick --continue".
hint: You can instead skip this commit with "git cherry-pick --skip".
hint: To abort and get back to the state before "git cherry-pick",
hint: run "git cherry-pick --abort".

stdout
Auto-merging web-ui/src/main/resources/catalog/js/CatController.js
Auto-merging web-ui/src/main/resources/catalog/locales/en-admin.json
Auto-merging web-ui/src/main/resources/catalog/templates/admin/settings/system.html
Auto-merging web/src/main/webapp/WEB-INF/classes/setup/sql/data/data-db-default.sql
CONFLICT (modify/delete): web/src/main/webapp/WEB-INF/classes/setup/sql/migrate/v440/migrate-default.sql deleted in HEAD and modified in ba0888f642 (metadata history viewing with user profile level).  Version ba0888f642 (metadata history viewing with user profile level) of web/src/main/webapp/WEB-INF/classes/setup/sql/migrate/v440/migrate-default.sql left in tree.

To backport manually, run these commands in your terminal:

# Fetch latest updates from GitHub
git fetch
# Create a new working tree
git worktree add .worktrees/backport-4.2.x 4.2.x
# Navigate to the new working tree
cd .worktrees/backport-4.2.x
# Create a new branch
git switch --create backport-7450-to-4.2.x
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick ba0888f64271446814ae26ba5f1880b385ccb431,b7f7b3ee21916d01240bf776d14651159d778e0f,fd48d9fef40bc3f8a265c3808fad09d526bb29bd,9b4b3f6501514f04eb6f329b4df67efac356c296,7c2d18419ec384d6cf41d8fe0b3b7bc65ee26000,9e9d09a33ed4a27eddd7421c7623bb81ad8de37f,4c224296468b0cac9a3e5148197af8fcc4e40977,7709646684d747208b7c940ff3c4c9721f5f0bc2,ac9d91ce1e66bdf9f1777c393d803a1026a97e29,c294463be98578e97b39a44abafd77f803217cd6,8d13b8eaa985bcb8ec58c75dde58be95c42bf290,0dcfcab998a0224e698da7773aa99fe32d555409,deaf064c56842a9ab99101b1eaafe2c61d8e720b,4f16b91e014fe8321e3eb6269687b8036b7a7d31,e2e76ffb5361d397c0b9a384e25e24c0274135d7,7974efa28df068f6aaf2a12afb8b3d6aeb54b585,80eddabf769ab2bc6c36fc0c789f540af517386d,f4ee0866392797b07133da680ea429182dd250ad,d908561e2f3b64f6b79122a96fc975ef621bd218,3d172b855cbd502ffc3e5530cd1304583cb42e2f,9aa3b6edd097ee919b0e42fa4b633564235fddcc,62dfa16821c1d0b30dbaec76d41bb2e547a65e36,f2a5ffa67faad40475c3173db0e67cfd35c3e51b,9ac4bcfcfa96aa96531e6d27589163ec7b5cc182,38e31a5b458d380b722750a8922420e7c0ffe70b,a499d1eb57a0f4a0a6596ae91ccecbefe0e0ee9b,87e2637eb0a6db8397dac72a5a2e6d01cfb73ffe,ead9a51b78f01ddcd0e9a979cfd161b0b8015706,eac2007602a740541218bcf5ea16ec9e72c7ad31,9fa5a4b540d0f2b598be8f2e969fc9e192ce9982
# Push it to GitHub
git push --set-upstream origin backport-7450-to-4.2.x
# Go back to the original working tree
cd ../..
# Delete the working tree
git worktree remove .worktrees/backport-4.2.x

Then, create a pull request where the base branch is 4.2.x and the compare/head branch is backport-7450-to-4.2.x.

ianwallen pushed a commit to ianwallen/core-geonetwork that referenced this pull request Apr 5, 2024
Allow metadata history viewing with user profile level

Co-authored-by: Jose García <[email protected]>
ianwallen added a commit that referenced this pull request Apr 5, 2024
Allow metadata history viewing with user profile level

Co-authored-by: wangf1122 <[email protected]>
Co-authored-by: Jose García <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants