Search in sources :

Example 1 with FolderAuthorization

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();
}
Also used : FolderAuthorization(org.jbei.ice.lib.dto.folder.FolderAuthorization) AccessPermission(org.jbei.ice.lib.dto.access.AccessPermission) AccessPermission(org.jbei.ice.lib.dto.access.AccessPermission)

Example 2 with FolderAuthorization

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);
    }
}
Also used : FolderAuthorization(org.jbei.ice.lib.dto.folder.FolderAuthorization) BulkUploadAuthorization(org.jbei.ice.lib.bulkupload.BulkUploadAuthorization) EntryAuthorization(org.jbei.ice.lib.entry.EntryAuthorization)

Example 3 with FolderAuthorization

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;
}
Also used : Account(org.jbei.ice.storage.model.Account) FolderAuthorization(org.jbei.ice.lib.dto.folder.FolderAuthorization) FolderDetails(org.jbei.ice.lib.dto.folder.FolderDetails) Folder(org.jbei.ice.storage.model.Folder)

Example 4 with FolderAuthorization

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);
}
Also used : FolderAuthorization(org.jbei.ice.lib.dto.folder.FolderAuthorization) Folder(org.jbei.ice.storage.model.Folder)

Aggregations

FolderAuthorization (org.jbei.ice.lib.dto.folder.FolderAuthorization)4 Folder (org.jbei.ice.storage.model.Folder)2 BulkUploadAuthorization (org.jbei.ice.lib.bulkupload.BulkUploadAuthorization)1 AccessPermission (org.jbei.ice.lib.dto.access.AccessPermission)1 FolderDetails (org.jbei.ice.lib.dto.folder.FolderDetails)1 EntryAuthorization (org.jbei.ice.lib.entry.EntryAuthorization)1 Account (org.jbei.ice.storage.model.Account)1