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