Search in sources :

Example 26 with AccessPermission

use of org.jbei.ice.lib.dto.access.AccessPermission in project ice by JBEI.

the class RemoteAccess method createPermissionModel.

protected Permission createPermissionModel(AccessPermission accessPermission, Folder folder, Account account) {
    Permission permission = new Permission();
    permission.setFolder(folder);
    permission.setCanWrite(accessPermission.isCanWrite());
    permission.setCanRead(accessPermission.isCanRead());
    permission.setAccount(account);
    return this.permissionDAO.create(permission);
}
Also used : AccessPermission(org.jbei.ice.lib.dto.access.AccessPermission)

Example 27 with AccessPermission

use of org.jbei.ice.lib.dto.access.AccessPermission in project ice by JBEI.

the class Permissions method addPermission.

protected Permission addPermission(AccessPermission access, Entry entry, Folder folder, BulkUpload upload) {
    // account or group
    Account account = null;
    Group group = null;
    switch(access.getArticle()) {
        case ACCOUNT:
        default:
            account = accountDAO.get(access.getArticleId());
            break;
        case GROUP:
            group = groupDAO.get(access.getArticleId());
            break;
    }
    // does the permissions already exists
    if (permissionDAO.hasPermission(entry, folder, upload, account, group, access.isCanRead(), access.isCanWrite())) {
        return permissionDAO.retrievePermission(entry, folder, upload, account, group, access.isCanRead(), access.isCanWrite());
    }
    // add the permission if not
    Permission permission = new Permission();
    permission.setEntry(entry);
    if (entry != null)
        entry.getPermissions().add(permission);
    permission.setGroup(group);
    permission.setFolder(folder);
    permission.setUpload(upload);
    permission.setAccount(account);
    permission.setCanRead(access.isCanRead());
    permission.setCanWrite(access.isCanWrite());
    return permissionDAO.create(permission);
}
Also used : AccessPermission(org.jbei.ice.lib.dto.access.AccessPermission)

Example 28 with AccessPermission

use of org.jbei.ice.lib.dto.access.AccessPermission in project ice by JBEI.

the class BulkUploadController method getUploadPermissions.

public List<AccessPermission> getUploadPermissions(String userId, long uploadId) {
    List<AccessPermission> permissions = new ArrayList<>();
    BulkUpload upload = dao.get(uploadId);
    if (upload == null)
        return permissions;
    authorization.expectWrite(userId, upload);
    if (upload.getPermissions() != null) {
        for (Permission permission : upload.getPermissions()) permissions.add(permission.toDataTransferObject());
    }
    return permissions;
}
Also used : AccessPermission(org.jbei.ice.lib.dto.access.AccessPermission) AccessPermission(org.jbei.ice.lib.dto.access.AccessPermission)

Example 29 with AccessPermission

use of org.jbei.ice.lib.dto.access.AccessPermission in project ice by JBEI.

the class BulkUploadController method approveBulkImport.

public boolean approveBulkImport(String userId, long id) {
    // only admins allowed
    if (!accountController.isAdministrator(userId)) {
        Logger.warn("Only administrators can approve bulk imports");
        return false;
    }
    // retrieve bulk upload in question (at this point it is owned by system)
    BulkUpload bulkUpload = dao.get(id);
    if (bulkUpload == null) {
        Logger.error("Could not retrieve bulk upload with id \"" + id + "\" for approval");
        return false;
    }
    // get permissions for bulk upload and set it to the individual entries
    PermissionsController permissionsController = new PermissionsController();
    ArrayList<AccessPermission> permissions = new ArrayList<>();
    for (Permission permission : bulkUpload.getPermissions()) {
        AccessPermission accessPermission = permission.toDataTransferObject();
        // read or write access
        if (accessPermission.getType() == AccessPermission.Type.READ_UPLOAD)
            accessPermission.setType(AccessPermission.Type.READ_ENTRY);
        else
            accessPermission.setType(AccessPermission.Type.WRITE_ENTRY);
        permissions.add(accessPermission);
    }
    // TODO : this needs to go into a task that auto updates
    for (Entry entry : bulkUpload.getContents()) {
        entry.setVisibility(Visibility.OK.getValue());
        Set<Entry> linked = entry.getLinkedEntries();
        Entry plasmid = null;
        if (linked != null && !linked.isEmpty()) {
            plasmid = (Entry) linked.toArray()[0];
            plasmid.setVisibility(Visibility.OK.getValue());
        }
        // set permissions
        for (AccessPermission accessPermission : permissions) {
            accessPermission.setTypeId(entry.getId());
            permissionsController.addPermission(userId, accessPermission);
            if (plasmid != null) {
                accessPermission.setTypeId(plasmid.getId());
                permissionsController.addPermission(userId, accessPermission);
            }
        }
        entryController.update(userId, entry);
        if (plasmid != null)
            entryController.update(userId, plasmid);
    }
    // when done approving, delete the bulk upload record but not the entries associated with it.
    bulkUpload.getContents().clear();
    dao.delete(bulkUpload);
    return true;
}
Also used : AccessPermission(org.jbei.ice.lib.dto.access.AccessPermission) AccessPermission(org.jbei.ice.lib.dto.access.AccessPermission) PermissionsController(org.jbei.ice.lib.access.PermissionsController)

Example 30 with AccessPermission

use of org.jbei.ice.lib.dto.access.AccessPermission in project ice by JBEI.

the class FolderPermissions method createPermissionModel.

protected Permission createPermissionModel(AccessPermission accessPermission, RemoteShareModel remoteShare) {
    Permission permission = new Permission();
    permission.setFolder(folder);
    permission.setCanWrite(accessPermission.isCanWrite());
    permission.setCanRead(accessPermission.isCanRead());
    permission.setRemoteShare(remoteShare);
    remoteShare.setPermission(permission);
    return this.permissionDAO.create(permission);
}
Also used : AccessPermission(org.jbei.ice.lib.dto.access.AccessPermission)

Aggregations

AccessPermission (org.jbei.ice.lib.dto.access.AccessPermission)34 Account (org.jbei.ice.storage.model.Account)8 Test (org.junit.Test)6 PermissionsController (org.jbei.ice.lib.access.PermissionsController)5 AccountTransfer (org.jbei.ice.lib.account.AccountTransfer)5 ArrayList (java.util.ArrayList)4 GroupController (org.jbei.ice.lib.group.GroupController)4 FolderDetails (org.jbei.ice.lib.dto.folder.FolderDetails)3 Group (org.jbei.ice.storage.model.Group)3 Permission (org.jbei.ice.storage.model.Permission)3 Date (java.util.Date)1 PartData (org.jbei.ice.lib.dto.entry.PartData)1 FolderAuthorization (org.jbei.ice.lib.dto.folder.FolderAuthorization)1 RegistryPartner (org.jbei.ice.lib.dto.web.RegistryPartner)1 EntryPermissionTask (org.jbei.ice.lib.entry.EntryPermissionTask)1 Collections (org.jbei.ice.lib.folder.collection.Collections)1 Folder (org.jbei.ice.storage.model.Folder)1 Plasmid (org.jbei.ice.storage.model.Plasmid)1 RemotePartner (org.jbei.ice.storage.model.RemotePartner)1 Strain (org.jbei.ice.storage.model.Strain)1