Repository navigation
Refuse root network tags the shared modifications the user cannot write on miss #1135
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
Changes from all commits
d5f9a21
cadab4a
4bf3444
a6bcede
9af215b
179f087
32143dd
1f43de9
109f4d2
507dbbb
1dcac44
77749e8
a94a8d2
d09fea0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| /** | ||
| * Copyright (c) 2026, RTE (http://www.rte-france.com) | ||
| * 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 | ||
| * file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
| */ | ||
| package org.gridsuite.study.server.dto; | ||
|
|
||
| import java.util.List; | ||
| import java.util.UUID; | ||
|
|
||
| /** | ||
| * Modifications to check against root network tags. | ||
| */ | ||
| public record RootNetworkTagsCheckInfos(List<UUID> containerUuids, List<String> tags) { | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| /** | ||
| * Copyright (c) 2026, RTE (http://www.rte-france.com) | ||
| * 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 | ||
| * file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
| */ | ||
| package org.gridsuite.study.server.dto; | ||
|
|
||
| /** | ||
| * Whether a user can write on the shared modifications of a study. | ||
| * | ||
| * @author Florent MILLOT <florent.millot at rte-france.com> | ||
| */ | ||
| public enum SharedModificationsWriteAccess { | ||
| NO_SHARED_MODIFICATION, | ||
| ALL_WRITABLE, | ||
| SOME_WRITABLE, | ||
| NONE_WRITABLE | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -335,6 +335,9 @@ public void deleteRootNetworks(UUID studyUuid, List<UUID> rootNetworksUuids, Str | |
| @Transactional | ||
| public RootNetworkRequestInfos createRootNetworkRequest(UUID studyUuid, RootNetworkInfos rootNetworkInfos, String userId) { | ||
| rootNetworkService.assertCanCreateRootNetwork(studyUuid, rootNetworkInfos.getName(), rootNetworkInfos.getTag()); | ||
| if (rootNetworkInfos.getTag() != null) { | ||
| assertCanAddRootNetworkTag(studyUuid, rootNetworkInfos.getTag(), userId); | ||
|
Comment on lines
+338
to
+339
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔎 Supported by static analysis
Recheck tag authorization when root-network creation completes.
Recheck the current groups at completion, passing the request user ID through, or enforce this invariant in the downstream operation.
|
||
| } | ||
| StudyEntity studyEntity = getStudy(studyUuid); | ||
|
|
||
| rootNetworkInfos.setId(UUID.randomUUID()); | ||
|
|
@@ -391,33 +394,35 @@ private void invalidatePreviousRootNetworkNodeTree(StudyEntity studyEntity) { | |
| networkModificationTreeService.invalidateNodeTree(studyEntity.getId(), rootNodeUuid, studyEntity.getFirstRootNetwork().getId()); | ||
| } | ||
|
|
||
| private void updateRootNetworkBasicInfos(UUID studyUuid, RootNetworkInfos rootNetworkInfos, boolean updateCase) { | ||
| private void updateRootNetworkBasicInfos(UUID studyUuid, RootNetworkInfos rootNetworkInfos, boolean updateCase, String userId) { | ||
| String previousTag = rootNetworkService.getRootNetworkTag(rootNetworkInfos.getId()); | ||
| rootNetworkService.updateRootNetwork(rootNetworkInfos, updateCase); | ||
| // the entity says what the tag really became, unlike the DTO | ||
| String newTag = rootNetworkService.getRootNetworkTag(rootNetworkInfos.getId()); | ||
| renameRootNetworkTagInApplicabilities(studyUuid, previousTag, newTag); | ||
| renameRootNetworkTagInApplicabilities(studyUuid, previousTag, newTag, userId); | ||
| postRootNetworkUpdate(studyUuid, rootNetworkInfos.getId(), updateCase); | ||
| } | ||
|
|
||
| private void renameRootNetworkTagInApplicabilities(UUID studyUuid, String previousTag, String newTag) { | ||
| private void renameRootNetworkTagInApplicabilities(UUID studyUuid, String previousTag, String newTag, String userId) { | ||
| if (previousTag == null || previousTag.equals(newTag)) { | ||
| return; | ||
| } | ||
| networkModificationRestService.renameRootNetworkTag(getStudyModificationGroupUuids(studyUuid), previousTag, newTag); | ||
| networkModificationRestService.renameRootNetworkTag(getStudyModificationGroupUuids(studyUuid), previousTag, newTag, userId); | ||
| } | ||
|
|
||
| /** | ||
| * Renaming a tag rewrites the applicabilities the shared modifications of the study contain for every study | ||
| * referencing them: only a user allowed to write on all of them may do it. | ||
| * A root network tag of a study must be associated with all its shared modifications: the ones the user cannot | ||
| * write on, which they cannot associate with a new tag, must already be. | ||
| */ | ||
| private void assertCanRenameRootNetworkTag(UUID studyUuid, String userId) { | ||
| networkModificationRestService.assertReferencedModificationsAreWritable(getStudyModificationGroupUuids(studyUuid), userId); | ||
| private void assertCanAddRootNetworkTag(UUID studyUuid, String newTag, String userId) { | ||
| networkModificationRestService.assertRootNetworkTagsAllowed(getStudyModificationGroupUuids(studyUuid), List.of(newTag), userId); | ||
| } | ||
|
|
||
| public boolean hasSharedModifications(UUID studyUuid) { | ||
| public SharedModificationsWriteAccess getSharedModificationsWriteAccess(UUID studyUuid, String userId) { | ||
| List<UUID> groupUuids = getStudyModificationGroupUuids(studyUuid); | ||
| return !groupUuids.isEmpty() && networkModificationRestService.hasModificationReferences(groupUuids); | ||
| return groupUuids.isEmpty() | ||
| ? SharedModificationsWriteAccess.NO_SHARED_MODIFICATION | ||
| : networkModificationRestService.getReferencedModificationsWriteAccess(groupUuids, userId); | ||
| } | ||
|
|
||
| private List<UUID> getStudyModificationGroupUuids(UUID studyUuid) { | ||
|
|
@@ -431,15 +436,15 @@ public void updateRootNetworkRequest(UUID studyUuid, RootNetworkInfos rootNetwor | |
| rootNetworkService.assertCanModifyRootNetwork(studyUuid, rootNetworkInfos.getId(), rootNetworkInfos.getName(), rootNetworkInfos.getTag()); | ||
| String newTag = rootNetworkInfos.getTag(); | ||
| if (newTag != null && !newTag.equals(rootNetworkService.getRootNetworkTag(rootNetworkInfos.getId()))) { | ||
| assertCanRenameRootNetworkTag(studyUuid, userId); | ||
| assertCanAddRootNetworkTag(studyUuid, newTag, userId); | ||
| } | ||
| StudyEntity studyEntity = getStudy(studyUuid); | ||
|
|
||
| if (rootNetworkInfos.hasCaseToImport()) { | ||
| RootNetworkRequestEntity requestEntity = rootNetworkService.insertModificationRequest(studyEntity.getId(), rootNetworkInfos, userId); | ||
| updateRootNetworkCaseInfos(studyEntity.getId(), rootNetworkInfos, userId, requestEntity); | ||
| } else { | ||
| updateRootNetworkBasicInfos(studyEntity.getId(), rootNetworkInfos, false); | ||
| updateRootNetworkBasicInfos(studyEntity.getId(), rootNetworkInfos, false, userId); | ||
| } | ||
| notificationService.emitElementUpdated(studyUuid, userId); | ||
| } | ||
|
|
@@ -458,7 +463,7 @@ private void updateRootNetworkCaseInfos(UUID studyUuid, RootNetworkInfos rootNet | |
| @Transactional | ||
| public void modifyRootNetwork(UUID studyUuid, RootNetworkInfos rootNetworkInfos, String userId) { | ||
| invalidateStudyRootNetwork(studyUuid, rootNetworkInfos.getId(), userId, true); | ||
| updateRootNetworkBasicInfos(studyUuid, rootNetworkInfos, true); | ||
| updateRootNetworkBasicInfos(studyUuid, rootNetworkInfos, true, userId); | ||
| } | ||
|
|
||
| private void postRootNetworkUpdate(UUID studyUuid, UUID rootNetworkUuid, boolean updateCase) { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.