use of org.jbei.ice.storage.model.Group 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.Group in project ice by JBEI.
the class VisibleEntries method getEntries.
public List<PartData> getEntries(ColumnField field, boolean asc, int start, int limit, String filter) {
List<Entry> results;
if (isAdmin) {
// no filters
results = dao.retrieveAllEntries(field, asc, start, limit, filter);
} else {
// retrieve groups for account and filter by permission
Set<Group> accountGroups = new HashSet<>(account.getGroups());
accountGroups.add(everybodyGroup);
results = dao.retrieveVisibleEntries(account, accountGroups, field, asc, start, limit, filter);
}
ArrayList<PartData> data = new ArrayList<>();
for (Entry entry : results) {
PartData info = ModelToInfoFactory.createTableViewData(account.getEmail(), entry, false);
data.add(info);
}
return data;
}
use of org.jbei.ice.storage.model.Group in project ice by JBEI.
the class OwnerEntries method retrieveOwnerEntries.
public List<PartData> retrieveOwnerEntries(ColumnField sort, boolean asc, int start, int limit, String filter) {
List<Entry> entries;
if (this.isAdmin || this.isSelf) {
entries = entryDAO.retrieveOwnerEntries(this.ownerAccount.getEmail(), sort, asc, start, limit, filter);
} else {
Set<Group> accountGroups = new HashSet<>(account.getGroups());
GroupController controller = new GroupController();
Group everybodyGroup = controller.createOrRetrievePublicGroup();
accountGroups.add(everybodyGroup);
// retrieve entries for user that can be read by others
entries = entryDAO.retrieveUserEntries(account, this.ownerAccount.getEmail(), accountGroups, sort, asc, start, limit, filter);
}
ArrayList<PartData> data = new ArrayList<>();
for (Entry entry : entries) {
PartData info = ModelToInfoFactory.createTableViewData(account.getEmail(), entry, false);
data.add(info);
}
return data;
}
use of org.jbei.ice.storage.model.Group in project ice by JBEI.
the class SharedEntries method getEntries.
public List<PartData> getEntries(ColumnField field, boolean asc, int start, int limit, String filter) {
GroupController groupController = new GroupController();
Group publicGroup = groupController.createOrRetrievePublicGroup();
Set<Group> accountGroups = account.getGroups();
accountGroups.remove(publicGroup);
List<Entry> entries = this.entryDAO.sharedWithUserEntries(account, accountGroups, field, asc, start, limit, filter);
ArrayList<PartData> data = new ArrayList<>();
for (Entry entry : entries) {
PartData info = ModelToInfoFactory.createTableViewData(account.getEmail(), entry, false);
data.add(info);
}
return data;
}
use of org.jbei.ice.storage.model.Group in project ice by JBEI.
the class GroupController method getAllAccountGroups.
/**
* Retrieve all parent {@link Group}s of a given {@link Account}.
*
* @param account Account to query on.
* @return Set of Group ids.
*/
protected Set<Long> getAllAccountGroups(Account account) {
HashSet<Long> accountGroups = new HashSet<>();
for (Group group : account.getGroups()) {
accountGroups = getParentGroups(group, accountGroups);
}
// Everyone belongs to the everyone group
Group everybodyGroup = createOrRetrievePublicGroup();
accountGroups.add(everybodyGroup.getId());
return accountGroups;
}
Aggregations