Search in sources :

Example 16 with Account

use of org.jbei.ice.storage.model.Account in project ice by JBEI.

the class Entries method updateVisibility.

public boolean updateVisibility(List<Long> entryIds, Visibility visibility) {
    Account account = accountDAO.getByEmail(userId);
    List<Group> accountGroups = new GroupController().getAllGroups(account);
    if (!new AccountController().isAdministrator(userId) && !permissionDAO.canWrite(account, accountGroups, entryIds))
        return false;
    for (long entryId : entryIds) {
        Entry entry = dao.get(entryId);
        if (entry.getVisibility() == visibility.getValue())
            continue;
        entry.setVisibility(visibility.getValue());
        dao.update(entry);
    }
    return true;
}
Also used : Account(org.jbei.ice.storage.model.Account) Group(org.jbei.ice.storage.model.Group) Entry(org.jbei.ice.storage.model.Entry) GroupController(org.jbei.ice.lib.group.GroupController) AccountController(org.jbei.ice.lib.account.AccountController)

Example 17 with Account

use of org.jbei.ice.storage.model.Account in project ice by JBEI.

the class FolderAuthorization method canWrite.

public boolean canWrite(String userId, Folder folder) {
    Account account = getAccount(userId);
    if (account == null)
        return false;
    if (super.canWrite(userId, folder))
        return true;
    // now check actual permissions
    Set<Folder> folders = new HashSet<>();
    folders.add(folder);
    return controller.groupHasWritePermission(new ArrayList<>(account.getGroups()), folders) || controller.accountHasWritePermission(account, folders);
}
Also used : Account(org.jbei.ice.storage.model.Account) ArrayList(java.util.ArrayList) Folder(org.jbei.ice.storage.model.Folder) HashSet(java.util.HashSet)

Example 18 with Account

use of org.jbei.ice.storage.model.Account in project ice by JBEI.

the class RequestRetriever method updateStatus.

public SampleRequest updateStatus(String userId, long requestId, SampleRequestStatus newStatus) {
    Request request = dao.get(requestId);
    if (request == null)
        return null;
    Account account = DAOFactory.getAccountDAO().getByEmail(userId);
    if (!request.getAccount().getEmail().equalsIgnoreCase(userId) && account.getType() != AccountType.ADMIN) {
        throw new PermissionException("No permissions for request");
    }
    if (request.getStatus() == newStatus)
        return request.toDataTransferObject();
    request.setStatus(newStatus);
    request.setUpdated(new Date());
    return dao.update(request).toDataTransferObject();
}
Also used : PermissionException(org.jbei.ice.lib.access.PermissionException) Account(org.jbei.ice.storage.model.Account) Request(org.jbei.ice.storage.model.Request)

Example 19 with Account

use of org.jbei.ice.storage.model.Account in project ice by JBEI.

the class Groups method getMatchingGroups.

public List<UserGroup> getMatchingGroups(String token, int limit) {
    Account account = accountDAO.getByEmail(this.userId);
    List<Group> groups = dao.getMatchingGroups(account, token, limit);
    List<UserGroup> results = new ArrayList<>(groups.size());
    for (Group group : groups) {
        results.add(group.toDataTransferObject());
    }
    return results;
}
Also used : Account(org.jbei.ice.storage.model.Account) Group(org.jbei.ice.storage.model.Group) UserGroup(org.jbei.ice.lib.dto.group.UserGroup) UserGroup(org.jbei.ice.lib.dto.group.UserGroup)

Example 20 with Account

use of org.jbei.ice.storage.model.Account in project ice by JBEI.

the class GroupController method deleteGroup.

public boolean deleteGroup(String userIdStr, long groupId) {
    Account account = DAOFactory.getAccountDAO().getByEmail(userIdStr);
    Group group = dao.get(groupId);
    if (group == null)
        return false;
    if (group.getType() == GroupType.PUBLIC && account.getType() != AccountType.ADMIN) {
        String errMsg = "Non admin " + account.getEmail() + " attempting to delete public group";
        Logger.error(errMsg);
        throw new PermissionException(errMsg);
    }
    if (group.getMembers() != null) {
        for (Account member : group.getMembers()) {
            accountController.removeMemberFromGroup(group.getId(), member.getEmail());
        }
    }
    DAOFactory.getPermissionDAO().clearPermissions(group);
    dao.delete(group);
    return true;
}
Also used : PermissionException(org.jbei.ice.lib.access.PermissionException) Account(org.jbei.ice.storage.model.Account) Group(org.jbei.ice.storage.model.Group) UserGroup(org.jbei.ice.lib.dto.group.UserGroup)

Aggregations

Account (org.jbei.ice.storage.model.Account)153 Test (org.junit.Test)71 Group (org.jbei.ice.storage.model.Group)24 Entry (org.jbei.ice.storage.model.Entry)21 Strain (org.jbei.ice.storage.model.Strain)20 PartData (org.jbei.ice.lib.dto.entry.PartData)18 Folder (org.jbei.ice.storage.model.Folder)18 ArrayList (java.util.ArrayList)16 UserGroup (org.jbei.ice.lib.dto.group.UserGroup)16 PermissionException (org.jbei.ice.lib.access.PermissionException)11 EntryCreator (org.jbei.ice.lib.entry.EntryCreator)10 Plasmid (org.jbei.ice.storage.model.Plasmid)10 AccountTransfer (org.jbei.ice.lib.account.AccountTransfer)8 AccessPermission (org.jbei.ice.lib.dto.access.AccessPermission)8 FolderDetails (org.jbei.ice.lib.dto.folder.FolderDetails)8 DAOException (org.jbei.ice.storage.DAOException)8 RemotePartner (org.jbei.ice.storage.model.RemotePartner)8 HibernateException (org.hibernate.HibernateException)7 HashSet (java.util.HashSet)6 Part (org.jbei.ice.storage.model.Part)6