Search in sources :

Example 6 with AccessPermission

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

the class EntryController method updatePart.

/**
     * Update the information associated with the specified part.<br>
     * <b>Note</b> that any missing information will be deleted from the original entry.
     * In other words, if the part referenced by id <code>partId</code> has an alias value
     * of <code>alias</code> and the part object passed in the parameter does not contain this value,
     * when this method returns, the original entry's alias field will be removed.
     *
     * @param userId unique identifier for user making request
     * @param partId unique identifier for part being updated. This overrides the id in the partData object
     * @param part   information to update part with
     * @return unique identifier for part that was updated
     * @throws IllegalArgumentException if the entry associated with the partId cannot be located
     */
public long updatePart(String userId, long partId, PartData part) {
    Entry existing = dao.get(partId);
    if (existing == null)
        throw new IllegalArgumentException();
    authorization.expectWrite(userId, existing);
    Entry entry = InfoToModelFactory.updateEntryField(part, existing);
    entry.setModificationTime(Calendar.getInstance().getTime());
    if (entry.getVisibility() == Visibility.DRAFT.getValue()) {
        List<EntryField> invalidFields = EntryUtil.validates(part);
        if (invalidFields.isEmpty())
            entry.setVisibility(Visibility.OK.getValue());
    }
    entry = dao.update(entry);
    // check pi email
    String piEmail = entry.getPrincipalInvestigatorEmail();
    if (StringUtils.isNotEmpty(piEmail)) {
        Account pi = DAOFactory.getAccountDAO().getByEmail(piEmail);
        if (pi != null) {
            // add write permission for the PI (method also checks to see if permission already exists)
            AccessPermission accessPermission = new AccessPermission();
            accessPermission.setArticle(AccessPermission.Article.ACCOUNT);
            accessPermission.setArticleId(pi.getId());
            accessPermission.setType(AccessPermission.Type.WRITE_ENTRY);
            accessPermission.setTypeId(entry.getId());
            permissionsController.addPermission(userId, accessPermission);
        }
    }
    return entry.getId();
}
Also used : AccessPermission(org.jbei.ice.lib.dto.access.AccessPermission)

Example 7 with AccessPermission

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

the class EntryPermissions method getEntryPermissions.

/**
     * Retrieves permissions associated with a part. Requires that the requesting user has write permissions
     * on the specified part
     *
     * @return list of available permissions for the specified part
     * @throws PermissionException if the requesting user does not have write permissions for the part
     */
public List<AccessPermission> getEntryPermissions() {
    // viewing permissions requires write permissions
    authorization.expectWrite(userId, entry);
    ArrayList<AccessPermission> accessPermissions = new ArrayList<>();
    List<Permission> permissions = permissionDAO.getEntryPermissions(entry);
    GroupController groupController = new GroupController();
    Group publicGroup = groupController.createOrRetrievePublicGroup();
    for (Permission permission : permissions) {
        if (permission.getAccount() == null && permission.getGroup() == null)
            continue;
        if (permission.getGroup() != null && permission.getGroup() == publicGroup)
            continue;
        accessPermissions.add(permission.toDataTransferObject());
    }
    return accessPermissions;
}
Also used : Group(org.jbei.ice.storage.model.Group) GroupController(org.jbei.ice.lib.group.GroupController) ArrayList(java.util.ArrayList) AccessPermission(org.jbei.ice.lib.dto.access.AccessPermission) AccessPermission(org.jbei.ice.lib.dto.access.AccessPermission) Permission(org.jbei.ice.storage.model.Permission)

Example 8 with AccessPermission

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

the class EntryPermissions method enablePublicReadAccess.

public boolean enablePublicReadAccess() {
    AccessPermission permission = new AccessPermission();
    permission.setType(AccessPermission.Type.READ_ENTRY);
    permission.setTypeId(this.entry.getId());
    permission.setArticle(AccessPermission.Article.GROUP);
    permission.setArticleId(groupController.createOrRetrievePublicGroup().getId());
    authorization.expectWrite(userId, entry);
    return addPermission(permission, entry, null, null) != null;
}
Also used : AccessPermission(org.jbei.ice.lib.dto.access.AccessPermission)

Example 9 with AccessPermission

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

the class FolderPermissions method get.

/**
     * Retrieves list of available folder permissions (both local and remote)
     *
     * @return list available folders
     */
public ArrayList<AccessPermission> get() {
    authorization.expectWrite(userId, folder);
    ArrayList<AccessPermission> accessPermissions = new ArrayList<>();
    // get local permissions
    List<Permission> permissions = this.permissionDAO.getFolderPermissions(folder);
    for (Permission permission : permissions) {
        if (permission.getGroup() != null && permission.getGroup().getUuid().equals(GroupController.PUBLIC_GROUP_UUID))
            continue;
        AccessPermission accessPermission = permission.toDataTransferObject();
        if (permission.getRemoteShare() != null) {
            RemoteShareModel remoteShareModel = permission.getRemoteShare();
            accessPermission.setArticle(AccessPermission.Article.REMOTE);
            // for remote access permissions, the article id is the actual permission
            accessPermission.setArticleId(permission.getId());
            accessPermission.setId(remoteShareModel.getId());
            //                accessPermission.setType(this.permission.isCanWrite() ? AccessPermission.Type.WRITE_FOLDER : AccessPermission.Type.READ_FOLDER);
            AccountTransfer accountTransfer = new AccountTransfer();
            accountTransfer.setEmail(remoteShareModel.getClient().getEmail());
            accessPermission.setPartner(remoteShareModel.getClient().getRemotePartner().toDataTransferObject());
            accessPermission.setDisplay(accountTransfer.getEmail());
        }
        accessPermissions.add(accessPermission);
    }
    return accessPermissions;
}
Also used : ArrayList(java.util.ArrayList) AccessPermission(org.jbei.ice.lib.dto.access.AccessPermission) AccessPermission(org.jbei.ice.lib.dto.access.AccessPermission) AccountTransfer(org.jbei.ice.lib.account.AccountTransfer)

Example 10 with AccessPermission

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

the class BulkUploadController method addPermission.

/**
     * Adds specified access permission to the bulk upload.
     *
     * @param userId   unique identifier of user making the request. Must be an admin or owner of the upload
     * @param uploadId unique identifier for bulk upload
     * @param access   details about the permission to the added
     * @return added permission with identifier that can be used to remove/delete the permission
     * @throws java.lang.IllegalArgumentException if the upload cannot be located using its identifier
     */
public AccessPermission addPermission(String userId, long uploadId, AccessPermission access) {
    BulkUpload upload = dao.get(uploadId);
    if (upload == null)
        throw new IllegalArgumentException("Could not locate bulk upload with id " + uploadId);
    access.setTypeId(uploadId);
    Permission permission = new PermissionsController().addPermission(userId, access);
    upload.getPermissions().add(permission);
    dao.update(upload);
    return permission.toDataTransferObject();
}
Also used : AccessPermission(org.jbei.ice.lib.dto.access.AccessPermission) PermissionsController(org.jbei.ice.lib.access.PermissionsController)

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