Search in sources :

Example 1 with UserPermissionModel

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);
}
Also used : FolderDTO(org.activityinfo.legacy.shared.model.FolderDTO) GrantModel(org.activityinfo.model.database.GrantModel) ArrayList(java.util.ArrayList) UserPermissionModel(org.activityinfo.model.database.UserPermissionModel)

Example 2 with UserPermissionModel

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());
    }
}
Also used : GrantModel(org.activityinfo.model.database.GrantModel) UserPermissionModel(org.activityinfo.model.database.UserPermissionModel)

Example 3 with UserPermissionModel

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;
    }
}
Also used : FolderDTO(org.activityinfo.legacy.shared.model.FolderDTO) GrantModel(org.activityinfo.model.database.GrantModel) ArrayList(java.util.ArrayList) Folder(org.activityinfo.server.database.hibernate.entity.Folder) IllegalAccessCommandException(org.activityinfo.legacy.shared.exception.IllegalAccessCommandException) UserPermissionModel(org.activityinfo.model.database.UserPermissionModel)

Aggregations

GrantModel (org.activityinfo.model.database.GrantModel)3 UserPermissionModel (org.activityinfo.model.database.UserPermissionModel)3 ArrayList (java.util.ArrayList)2 FolderDTO (org.activityinfo.legacy.shared.model.FolderDTO)2 IllegalAccessCommandException (org.activityinfo.legacy.shared.exception.IllegalAccessCommandException)1 Folder (org.activityinfo.server.database.hibernate.entity.Folder)1