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();
}
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;
}
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;
}
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;
}
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();
}
Aggregations