use of org.activityinfo.model.database.UserPermissionModel in project activityinfo by bedatadriven.
the class UpdateUserPermissionsHandler method constructModel.
private UserPermissionModel constructModel(UserPermission perm, UserPermissionDTO dto) {
List<GrantModel> grants = new ArrayList<>();
for (FolderDTO folderDTO : dto.getFolders()) {
GrantModel grant = new GrantModel.Builder().setResourceId(CuidAdapter.folderId(folderDTO.getId())).build();
grants.add(grant);
}
return new UserPermissionModel(perm.getUser().getId(), perm.getDatabase().getId(), grants);
}
use of org.activityinfo.model.database.UserPermissionModel in project activityinfo by bedatadriven.
the class CloneDatabaseHandler method mapFolderPermissions.
private void mapFolderPermissions() {
for (UserPermission permission : targetDb.getUserPermissions()) {
if (Strings.isNullOrEmpty(permission.getModel())) {
continue;
}
UserPermissionModel sourceModel = UserPermissionModel.fromJson(Json.parse(permission.getModel()));
List<GrantModel> destinationGrants = new ArrayList<>();
for (GrantModel sourceGrant : sourceModel.getGrants()) {
int folderId = CuidAdapter.getLegacyIdFromCuid(sourceGrant.getResourceId());
if (!folderMapping.containsKey(folderId)) {
// folder not copied - do not add grant to new permission model
continue;
}
Folder destinationFolder = folderMapping.get(folderId);
destinationGrants.add(new GrantModel.Builder().setResourceId(CuidAdapter.folderId(destinationFolder.getId())).build());
}
UserPermissionModel destinationModel = new UserPermissionModel(permission.getUser().getId(), targetDb.getId(), destinationGrants);
permission.setModel(destinationModel.toJson().toJson());
}
}
use of org.activityinfo.model.database.UserPermissionModel in project activityinfo by bedatadriven.
the class GetUsersHandler method folderList.
private List<FolderDTO> folderList(Map<ResourceId, Folder> folderMap, UserPermission perm) {
if (Strings.isNullOrEmpty(perm.getModel())) {
// Include all folders, as user has access to all
List<FolderDTO> folderList = new ArrayList<>(folderMap.size());
folderMap.values().forEach(folder -> folderList.add(createFolderDTO(folder)));
return folderList;
}
try {
UserPermissionModel model = UserPermissionModel.fromJson(Json.parse(perm.getModel()));
List<FolderDTO> folderList = new ArrayList<>();
for (GrantModel grantModel : model.getGrants()) {
Folder folder = folderMap.get(grantModel.getResourceId());
if (folder != null) {
folderList.add(createFolderDTO(folder));
}
}
return folderList;
} catch (Exception e) {
LOGGER.log(Level.SEVERE, "Permissions model: " + perm.getModel());
LOGGER.log(Level.SEVERE, "Failed to parse permissions model", e);
return null;
}
}
Aggregations