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

AP-6692 Update artifact's owner field when change ACL #2115

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
Next Next commit
AP-6692 Update log's owner column when a log has multiple owners and …
…the original owner is deleted from access mgmt window
  • Loading branch information
franklma committed May 30, 2022
commit 7a9f5ae1f4c92efcb280714d2aa2ea096d0528fa
Binary file added Apromore-Boot/.ProcessLog.parquet.crc
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,9 @@ boolean logoutUserAllSessions(final String username,

String saveLogPermissions(int logId, String userId, boolean hasRead, boolean hasWrite, boolean hasOwnership);

String removeFolderPermissions(int folderId, String userId);
String removeFolderPermissions(int folderId, String userId, AccessType accessType);

String removeProcessPermissions(int processId, String userId);
String removeProcessPermissions(int processId, String userId, AccessType accessType);

String removeLogPermissions(int logId, String userId, String username, AccessType accessType) throws UserNotFoundException;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -420,15 +420,15 @@ public String saveLogPermissions(int logId, String userId, boolean hasRead, bool
}

@Override
public String removeFolderPermissions(int folderId, String userId) {
public String removeFolderPermissions(int folderId, String userId, AccessType accessType) {
LOGGER.info("User id {} remove folder id {} permissions", userId, folderId);
return authorizationSrv.removeFolderPermissions(folderId, userId);
return authorizationSrv.removeFolderPermissions(folderId, userId, accessType);
}

@Override
public String removeProcessPermissions(int processId, String userId) {
public String removeProcessPermissions(int processId, String userId, AccessType accessType) {
LOGGER.info("User id {} remove permissions from process model id {}", userId, processId);
return authorizationSrv.removeProcessPermissions(processId, userId);
return authorizationSrv.removeProcessPermissions(processId, userId, accessType);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,15 +255,15 @@ public interface AuthorizationService {
* @param processId Process ID
* @param groupRowGuid Group UID
*/
void deleteProcessAccess(Integer processId, String groupRowGuid);
void deleteProcessAccess(Integer processId, String groupRowGuid, AccessType accessType);

/**
* Delete one GroupLog record
*
* @param folderId Folder ID
* @param groupRowGuid Group UID
*/
void deleteFolderAccess(Integer folderId, String groupRowGuid);
void deleteFolderAccess(Integer folderId, String groupRowGuid, AccessType accessType);

/**
* Delete one GroupUsermetadata record
Expand All @@ -282,9 +282,9 @@ String saveProcessPermissions(Integer processId, String groupRowGuid, boolean ha
String saveLogPermissions(Integer logId, String groupRowGuid, boolean hasRead, boolean hasWrite,
boolean hasOwnership);

String removeFolderPermissions(Integer folderId, String groupRowGuid);
String removeFolderPermissions(Integer folderId, String groupRowGuid, AccessType accessType);

String removeProcessPermissions(Integer processId, String groupRowGuid);
String removeProcessPermissions(Integer processId, String groupRowGuid, AccessType accessType);

String removeLogPermissions(Integer logId, String groupRowGuid, String username, AccessType accessType);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Lesser Public License for more details.
*
*
* You should have received a copy of the GNU General Lesser Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-3.0.html>.
Expand Down Expand Up @@ -494,15 +494,15 @@ public void deleteLogAccess(Integer logId, String groupRowGuid, String username,
}

@Override
public void deleteProcessAccess(Integer processId, String groupRowGuid) {
public void deleteProcessAccess(Integer processId, String groupRowGuid, AccessType accessType) {

removeProcessPermissions(processId, groupRowGuid);
removeProcessPermissions(processId, groupRowGuid, accessType);
}

@Override
public void deleteFolderAccess(Integer folderId, String groupRowGuid) {
public void deleteFolderAccess(Integer folderId, String groupRowGuid, AccessType accessType) {

removeFolderPermissions(folderId, groupRowGuid);
removeFolderPermissions(folderId, groupRowGuid, accessType);
}

@Override
Expand Down Expand Up @@ -546,35 +546,51 @@ public String saveFolderPermissions(Integer folderId, String groupRowGuid, boole

@Override
@Transactional(readOnly = false)
public String removeFolderPermissions(Integer folderId, String groupRowGuid) {
public String removeFolderPermissions(Integer folderId, String groupRowGuid, AccessType accessType) {

//
List<Folder> subFoldersWithCurrentFolders = folderService.getSubFolders(folderId, true);
Group group = groupRepository.findByRowGuid(groupRowGuid);
List<Integer> folderIds = new ArrayList<Integer>();
List<Integer> folderIds = new ArrayList<>();

for (Folder folder : subFoldersWithCurrentFolders) {
folderIds.add(folder.getId());
removeGroupFolder(group, folder);
}

for (Process process : processRepository.findByFolderIdIn(folderIds)) {
removeGroupProcess(group, process);
}
// Set<GroupFolder> groupFolderSet = folder.getGroupFolders();
// groupFolderSet.remove(1);
// folder.setGroupFolders(groupFolderSet);
// folderRepository.save(folder);

for (Log log : logRepository.findByFolderIdIn(folderIds)) {
removeGroupLog(group, log);
}
//
// for (Process process : processRepository.findByFolderIdIn(folderIds)) {
// removeGroupProcess(group, process);
// }
//
// for (Log log : logRepository.findByFolderIdIn(folderIds)) {
// removeGroupLog(group, log);
// }
return "";

}

@Override
@Transactional(readOnly = false)
public String removeProcessPermissions(Integer processId, String groupRowGuid) {
public String removeProcessPermissions(Integer processId, String groupRowGuid, AccessType accessType) {
Process process = processRepository.findById(processId).get();
Group group = groupRepository.findByRowGuid(groupRowGuid);
removeGroupProcess(group, process);

// Update Process's user attribute when this user is removed from owner list
if (group.getUser().equals(process.getUser()) && accessType.isOwner()) {
for (GroupProcess groupProcess : process.getGroupProcesses()) {
if ("USER".equals(groupProcess.getGroup().getType().toString())
&& groupProcess.getGroup().getUser() != process.getUser()) {
process.setUser(groupProcess.getGroup().getUser());
}
}
}

return "";
}

Expand All @@ -586,6 +602,16 @@ public String removeLogPermissions(Integer logId, String groupRowGuid, String us
Group group = groupRepository.findByRowGuid(groupRowGuid);
removeGroupLog(group, log);

// Update Log's user attribute when this user is removed from owner list
if (group.getUser().equals(log.getUser()) && accessType.isOwner()) {
for (GroupLog groupLog : log.getGroupLogs()) {
if ("USER".equals(groupLog.getGroup().getType().toString())
&& groupLog.getGroup().getUser() != log.getUser()) {
log.setUser(groupLog.getGroup().getUser());
}
}
}

// TODO: If access type = restricted, remove GroupUsermetadata
// If access type = restricted, remove permission with user metadata that linked to specified
// log
Expand Down Expand Up @@ -741,20 +767,23 @@ private void removeGroupFolder(Group group, Folder folder) {
GroupFolder groupFolder = groupFolderRepository.findByGroupAndFolder(group, folder);
if (groupFolder != null) {
groupFolderRepository.delete(groupFolder);
groupFolderRepository.flush();
}
}

private void removeGroupProcess(Group group, Process process) {
GroupProcess groupProcess = groupProcessRepository.findByGroupAndProcess(group, process);
if (groupProcess != null) {
groupProcessRepository.delete(groupProcess);
groupProcessRepository.flush();
}
}

private void removeGroupLog(Group group, Log log) {
GroupLog groupLog = groupLogRepository.findByGroupAndLog(group, log);
if (groupLog != null) {
groupLogRepository.delete(groupLog);
groupLogRepository.flush();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -573,9 +573,9 @@ private void applyChanges() {
String rowGuid = group.getRowGuid();
String name = group.getName();
if (selectedItem instanceof FolderType) {
authorizationService.deleteFolderAccess(selectedItemId, rowGuid);
authorizationService.deleteFolderAccess(selectedItemId, rowGuid, accessType);
} else if (selectedItem instanceof ProcessSummaryType) {
authorizationService.deleteProcessAccess(selectedItemId, rowGuid);
authorizationService.deleteProcessAccess(selectedItemId, rowGuid, accessType);
} else if (selectedItem instanceof LogSummaryType) {
authorizationService.deleteLogAccess(selectedItemId, rowGuid, name, accessType);
} else if (selectedItem instanceof UserMetadataSummaryType) {
Expand Down