use of org.activityinfo.model.database.GrantModel 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.GrantModel 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.GrantModel 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;
}
}
use of org.activityinfo.model.database.GrantModel in project activityinfo by bedatadriven.
the class UserPermission method getGrants.
@Transient
public List<GrantModel> getGrants() {
if (!this.allowView) {
return Collections.emptyList();
}
GrantModel.Builder grantModel = new GrantModel.Builder();
if (isAllowViewAll()) {
grantModel.addOperation(Operation.VIEW);
} else if (isAllowView()) {
grantModel.addOperation(Operation.VIEW, getPartnerFilter());
}
if (isAllowEditAll()) {
grantModel.addOperation(Operation.EDIT_RECORD);
} else if (isAllowEdit()) {
grantModel.addOperation(Operation.EDIT_RECORD, getPartnerFilter());
}
if (isAllowManageAllUsers()) {
grantModel.addOperation(Operation.MANAGE_USERS);
} else if (isAllowManageUsers()) {
grantModel.addOperation(Operation.MANAGE_USERS, getPartnerFilter());
}
if (isAllowDesign()) {
grantModel.addOperation(Operation.CREATE_FORM);
grantModel.addOperation(Operation.EDIT_FORM);
grantModel.addOperation(Operation.DELETE_FORM);
}
if (model == null) {
grantModel.setResourceId(CuidAdapter.databaseId(database.getId()));
} else {
JsonValue modelObject = Json.parse(model);
if (modelObject.hasKey("grants") && modelObject.get("grants").length() == 1 && modelObject.get("grants").get(0).hasKey("folderId")) {
// Temporary format...
grantModel.setResourceId(ResourceId.valueOf(modelObject.get("grants").get(0).getString("folderId")));
} else {
LOGGER.severe("Could not parse permissions model: " + model);
throw new UnsupportedOperationException("Unsupported model");
}
}
return Collections.singletonList(grantModel.build());
}
Aggregations