Search in sources :

Example 16 with UserGroup

use of org.jbei.ice.lib.dto.group.UserGroup in project ice by JBEI.

the class Groups method getGroupMembers.

/**
     * Retrieves both local and remote members of the specified group if the user making the request
     * has the appropriate permissions
     *
     * @param groupId unique local identifier of group
     * @return information about specified group including remote and local members
     * @throws PermissionException if the user does not have read permissions
     */
public UserGroup getGroupMembers(long groupId) {
    Group group = dao.get(groupId);
    if (group == null)
        return null;
    if (group.getType() == GroupType.PUBLIC) {
        if (!accountController.isAdministrator(userId))
            throw new PermissionException("Administrative privileges required");
    } else if (!userId.equalsIgnoreCase(group.getOwner().getEmail())) {
        Account account = accountDAO.getByEmail(this.userId);
        if (account.getType() != AccountType.ADMIN)
            throw new PermissionException("Missing required permissions");
    }
    UserGroup userGroup = group.toDataTransferObject();
    for (Account account : group.getMembers()) {
        userGroup.getMembers().add(account.toDataTransferObject());
    }
    // get remote members
    List<RemoteClientModel> clients = remoteClientModelDAO.getClientsForGroup(group);
    for (RemoteClientModel clientModel : clients) {
        userGroup.getRemoteMembers().add(clientModel.toDataTransferObject());
    }
    return userGroup;
}
Also used : PermissionException(org.jbei.ice.lib.access.PermissionException) Group(org.jbei.ice.storage.model.Group) UserGroup(org.jbei.ice.lib.dto.group.UserGroup) Account(org.jbei.ice.storage.model.Account) RemoteClientModel(org.jbei.ice.storage.model.RemoteClientModel) UserGroup(org.jbei.ice.lib.dto.group.UserGroup)

Example 17 with UserGroup

use of org.jbei.ice.lib.dto.group.UserGroup in project ice by JBEI.

the class Groups method update.

public boolean update(long groupId, UserGroup userGroup) {
    Group group = dao.get(groupId);
    if (group == null) {
        return false;
    }
    if (group.getType() == GroupType.PUBLIC && !accountController.isAdministrator(userId)) {
        String errMsg = "Non admin " + userId + " attempting to update public group";
        Logger.error(errMsg);
        throw new PermissionException(errMsg);
    }
    group.setLabel(userGroup.getLabel());
    group.setDescription(userGroup.getDescription());
    group = dao.update(group);
    setGroupMembers(group, userGroup.getMembers(), userGroup.getRemoteMembers());
    return true;
}
Also used : PermissionException(org.jbei.ice.lib.access.PermissionException) Group(org.jbei.ice.storage.model.Group) UserGroup(org.jbei.ice.lib.dto.group.UserGroup)

Aggregations

UserGroup (org.jbei.ice.lib.dto.group.UserGroup)17 Account (org.jbei.ice.storage.model.Account)13 Group (org.jbei.ice.storage.model.Group)9 AccountTransfer (org.jbei.ice.lib.account.AccountTransfer)5 PermissionException (org.jbei.ice.lib.access.PermissionException)3 RemoteUser (org.jbei.ice.lib.dto.web.RemoteUser)3 RemotePartner (org.jbei.ice.storage.model.RemotePartner)3 Results (org.jbei.ice.lib.dto.common.Results)2 RemoteClientModel (org.jbei.ice.storage.model.RemoteClientModel)2 Test (org.junit.Test)2 Date (java.util.Date)1 AccountController (org.jbei.ice.lib.account.AccountController)1 RegistryPartner (org.jbei.ice.lib.dto.web.RegistryPartner)1 Message (org.jbei.ice.storage.model.Message)1