use of org.jbei.ice.storage.model.Group in project ice by JBEI.
the class GroupDAOTest method testGetGroupsBy.
@Test
public void testGetGroupsBy() throws Exception {
String uid = UUID.randomUUID().toString();
Group group = createGroup(uid, GroupType.PUBLIC);
group.setAutoJoin(true);
dao.update(group);
createGroup(UUID.randomUUID().toString(), GroupType.PUBLIC);
createGroup(UUID.randomUUID().toString(), GroupType.PRIVATE);
List<Group> groups = dao.getGroupsBy(GroupType.PUBLIC, true);
Assert.assertEquals(1, groups.size());
Assert.assertEquals(uid, groups.get(0).getUuid());
}
use of org.jbei.ice.storage.model.Group in project ice by JBEI.
the class AccountController method authenticate.
/**
* Authenticate a user in the database.
* <p>
* Using the {@link org.jbei.ice.lib.account.authentication.IAuthentication} specified in the
* settings file, authenticate the user, and return the sessionData
*
* @param login
* @param password
* @param ip IP Address of the user.
* @return the account identifier (email) on a successful login, otherwise {@code null}
*/
protected Account authenticate(final String login, final String password, final String ip) {
final IAuthentication authentication = new LocalAuthentication();
String email;
try {
email = authentication.authenticates(login.trim(), password);
if (email == null) {
loginFailureCooldown();
return null;
}
} catch (final AuthenticationException e2) {
loginFailureCooldown();
return null;
}
Account account = dao.getByEmail(email);
if (account == null)
return null;
// add to public groups
List<Group> groups = groupDAO.getGroupsBy(GroupType.PUBLIC, true);
try {
if (groups != null) {
for (Group group : groups) {
account.getGroups().add(group);
}
dao.update(account);
}
} catch (Exception e) {
Logger.error(e);
}
account.setIp(ip);
account.setLastLoginTime(Calendar.getInstance().getTime());
account = save(account);
UserSessions.createNewSessionForUser(account.getEmail());
return account;
}
use of org.jbei.ice.storage.model.Group in project ice by JBEI.
the class FolderController method getPublicFolders.
/**
* Retrieves folders that are shared shared publicly. Note that this is different from
* featured folders that have a type of PUBLIC
*
* @return list of public folders on this site
*/
public ArrayList<FolderDetails> getPublicFolders() {
Group publicGroup = groupController.createOrRetrievePublicGroup();
List<Folder> folders = permissionDAO.getFolders(publicGroup);
ArrayList<FolderDetails> list = new ArrayList<>();
for (Folder folder : folders) {
FolderDetails details = folder.toDataTransferObject();
long folderSize = dao.getFolderSize(folder.getId(), null, true);
details.setCount(folderSize);
list.add(details);
}
Collections.sort(list);
return list;
}
use of org.jbei.ice.storage.model.Group in project ice by JBEI.
the class GroupController method createOrRetrievePublicGroup.
public Group createOrRetrievePublicGroup() {
Group publicGroup = dao.getByUUID(PUBLIC_GROUP_UUID);
if (publicGroup != null)
return publicGroup;
publicGroup = new Group();
publicGroup.setLabel(PUBLIC_GROUP_NAME);
publicGroup.setDescription(PUBLIC_GROUP_DESCRIPTION);
publicGroup.setType(GroupType.SYSTEM);
publicGroup.setUuid(PUBLIC_GROUP_UUID);
return save(publicGroup);
}
use of org.jbei.ice.storage.model.Group 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.setAutoJoin(userGroup.isAutoJoin());
group = dao.update(group);
setGroupMembers(group, userGroup.getMembers(), userGroup.getRemoteMembers());
return true;
}
Aggregations