use of org.jbei.ice.lib.dto.folder.FolderAuthorization in project ice by JBEI.
the class PermissionsController method setFolderPermissions.
public FolderDetails setFolderPermissions(String userId, long folderId, List<AccessPermission> permissions) {
Folder folder = folderDAO.get(folderId);
FolderAuthorization folderAuthorization = new FolderAuthorization();
folderAuthorization.expectWrite(userId, folder);
dao.clearPermissions(folder);
if (permissions == null)
return null;
Account account = accountController.getByEmail(userId);
for (AccessPermission access : permissions) {
Permission permission = new Permission();
permission.setFolder(folder);
permission.setAccount(account);
permission.setCanRead(access.isCanRead());
permission.setCanWrite(access.isCanWrite());
dao.create(permission);
}
return folder.toDataTransferObject();
}
use of org.jbei.ice.lib.dto.folder.FolderAuthorization in project ice by JBEI.
the class PermissionsController method removePermission.
public void removePermission(String userId, AccessPermission access) {
if (access.isEntry()) {
Entry entry = DAOFactory.getEntryDAO().get(access.getTypeId());
if (entry == null)
return;
EntryAuthorization authorization = new EntryAuthorization();
authorization.expectWrite(userId, entry);
// remove permission from entry
removePermission(access, entry, null, null);
return;
}
if (access.isFolder()) {
Folder folder = folderDAO.get(access.getTypeId());
FolderAuthorization folderAuthorization = new FolderAuthorization();
folderAuthorization.expectWrite(userId, folder);
// if folder is to be propagated, add removing permission from contained entries
if (folder.isPropagatePermissions()) {
for (Entry folderContent : folder.getContents()) {
removePermission(access, folderContent, null, null);
}
}
// remove permission from folder
removePermission(access, null, folder, null);
return;
}
if (access.isUpload()) {
BulkUpload upload = DAOFactory.getBulkUploadDAO().get(access.getTypeId());
if (upload == null)
throw new IllegalArgumentException("Could not retrieve upload " + access.getTypeId());
BulkUploadAuthorization uploadAuthorization = new BulkUploadAuthorization();
uploadAuthorization.expectWrite(userId, upload);
removePermission(access, null, null, upload);
}
}
use of org.jbei.ice.lib.dto.folder.FolderAuthorization in project ice by JBEI.
the class UserFolder method getFolder.
public FolderDetails getFolder(long folderId) {
Folder folder = DAOFactory.getFolderDAO().get(folderId);
if (folder == null)
throw new IllegalArgumentException("Folder with id " + folderId + " does not exist");
FolderAuthorization folderAuthorization = new FolderAuthorization();
folderAuthorization.expectRead(this.userId, folder);
FolderDetails folderDetails = folder.toDataTransferObject();
Account owner = DAOFactory.getAccountDAO().getByEmail(folder.getOwnerEmail());
if (owner != null) {
folderDetails.setOwner(owner.toDataTransferObject());
}
return folderDetails;
}
use of org.jbei.ice.lib.dto.folder.FolderAuthorization in project ice by JBEI.
the class Entries method getFolderEntries.
// todo : folder controller
protected List<Long> getFolderEntries(long folderId, boolean all, EntryType type) {
Folder folder = DAOFactory.getFolderDAO().get(folderId);
FolderAuthorization folderAuthorization = new FolderAuthorization();
folderAuthorization.expectRead(userId, folder);
if (all)
type = null;
boolean visibleOnly = folder.getType() != FolderType.TRANSFERRED;
return DAOFactory.getFolderDAO().getFolderContentIds(folderId, type, visibleOnly);
}
Aggregations