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