use of ca.corefacility.bioinformatics.irida.model.user.User in project irida by phac-nml.
the class ProjectMembersController method getProjectUserMembers.
/**
* Get a page of users on the project for display in a DataTable.
*
* @param params
* the datatables parameters for this DataTable
* @param projectId
* the id of the project we're looking at
* @return a {@link DataTablesResponseModel} of users on the project
*/
@RequestMapping(value = "/{projectId}/settings/ajax/members")
@ResponseBody
public DataTablesResponse getProjectUserMembers(@DataTablesRequest DataTablesParams params, @PathVariable final Long projectId) {
final Project project = projectService.read(projectId);
final Page<Join<Project, User>> usersForProject = userService.searchUsersForProject(project, params.getSearchValue(), params.getCurrentPage(), params.getLength(), params.getSort());
List<DataTablesResponseModel> modelList = new ArrayList<>();
for (Join<Project, User> join : usersForProject) {
modelList.add(new DTProjectMember((ProjectUserJoin) join));
}
return new DataTablesResponse(params, usersForProject, modelList);
}
use of ca.corefacility.bioinformatics.irida.model.user.User in project irida by phac-nml.
the class ProjectMembersController method addProjectMember.
/**
* Add a member to a project
*
* @param projectId
* The ID of the project
* @param memberId
* The ID of the user
* @param projectRole
* The role for the user on the project
* @param locale
* the reported locale of the browser
* @return map for showing success message.
*/
@RequestMapping(value = "/{projectId}/settings/members", method = RequestMethod.POST)
@ResponseBody
public Map<String, String> addProjectMember(@PathVariable Long projectId, @RequestParam Long memberId, @RequestParam String projectRole, Locale locale) {
logger.trace("Adding user " + memberId + " to project " + projectId);
Project project = projectService.read(projectId);
User user = userService.read(memberId);
ProjectRole role = ProjectRole.fromString(projectRole);
projectService.addUserToProject(project, user, role);
return ImmutableMap.of("result", messageSource.getMessage("project.members.add.success", new Object[] { user.getLabel(), project.getLabel() }, locale));
}
use of ca.corefacility.bioinformatics.irida.model.user.User in project irida by phac-nml.
the class ProjectSettingsAssociatedProjectsController method getAssociatedProjectsPage.
/**
* Get the associated projects for the given project
*
* @param projectId
* The ID of the project to get associated projects
* @param model
* A model for the view
* @param principal
* a reference to the logged in user.
*
* @return The view name of the assocated projects view
*/
@RequestMapping(value = "", method = RequestMethod.GET)
public String getAssociatedProjectsPage(@PathVariable Long projectId, Model model, Principal principal) {
Project project = projectService.read(projectId);
model.addAttribute("project", project);
User loggedInUser = userService.getUserByUsername(principal.getName());
// Determine if the user is an owner or admin.
boolean isAdmin = loggedInUser.getSystemRole().equals(Role.ROLE_ADMIN);
model.addAttribute("isAdmin", isAdmin);
// Add any associated projects
User currentUser = userService.getUserByUsername(principal.getName());
List<Map<String, String>> associatedProjects = getAssociatedProjectsForProject(project, currentUser, isAdmin);
model.addAttribute("associatedProjects", associatedProjects);
model.addAttribute("noAssociated", associatedProjects.isEmpty());
model.addAttribute(ProjectsController.ACTIVE_NAV, ProjectSettingsController.ACTIVE_NAV_SETTINGS);
model.addAttribute("page", "associated");
projectControllerUtils.getProjectTemplateDetails(model, principal, project);
return "projects/settings/pages/associated";
}
use of ca.corefacility.bioinformatics.irida.model.user.User in project irida by phac-nml.
the class ProjectSettingsController method updateProjectSyncSettings.
/**
* Update the project sync settings
*
* @param projectId
* the project id to update
* @param frequency
* the sync frequency to set
* @param forceSync
* Set the project's sync status to MARKED
* @param changeUser
* update the user on a remote project to the current logged in
* user
* @param principal
* The current logged in user
* @param locale
* user's locale
*
* @return result message if successful
*/
@RequestMapping(value = "/sync", method = RequestMethod.POST)
@ResponseBody
public Map<String, String> updateProjectSyncSettings(@PathVariable Long projectId, @RequestParam(required = false) ProjectSyncFrequency frequency, @RequestParam(required = false, defaultValue = "false") boolean forceSync, @RequestParam(required = false, defaultValue = "false") boolean changeUser, Principal principal, Locale locale) {
Project read = projectService.read(projectId);
RemoteStatus remoteStatus = read.getRemoteStatus();
Map<String, Object> updates = new HashMap<>();
String message = null;
String error = null;
if (frequency != null) {
updates.put("syncFrequency", frequency);
message = messageSource.getMessage("project.settings.notifications.sync", new Object[] {}, locale);
}
if (forceSync) {
remoteStatus.setSyncStatus(SyncStatus.MARKED);
updates.put("remoteStatus", remoteStatus);
message = messageSource.getMessage("project.settings.notifications.sync", new Object[] {}, locale);
}
if (changeUser) {
// ensure the user can read the project
try {
projectRemoteService.read(remoteStatus.getURL());
User user = userService.getUserByUsername(principal.getName());
remoteStatus.setReadBy(user);
updates.put("remoteStatus", remoteStatus);
message = messageSource.getMessage("project.settings.notifications.sync.userchange", new Object[] {}, locale);
} catch (Exception ex) {
error = messageSource.getMessage("project.settings.notifications.sync.userchange.error", new Object[] {}, locale);
}
}
projectService.updateProjectSettings(read, updates);
Map<String, String> response;
if (error == null) {
response = ImmutableMap.of("result", message);
} else {
response = ImmutableMap.of("error", error);
}
return response;
}
use of ca.corefacility.bioinformatics.irida.model.user.User in project irida by phac-nml.
the class PasswordExpiryChecker method check.
/**
* Checks if the given {@link UserDetails} password has expired.
*/
@Override
public void check(UserDetails toCheck) {
User user = userRepository.loadUserByUsername(toCheck.getUsername());
Revisions<Integer, User> revisions = userRepository.findRevisions(user.getId());
Date today = new Date();
Calendar cal = new GregorianCalendar();
cal.setTime(today);
cal.add(Calendar.DAY_OF_MONTH, -passwordExpiryInDays);
Date expiryDate = cal.getTime();
User oldUser = null;
for (Revision<Integer, User> rev : revisions) {
logger.trace("Checking old user with date of " + rev.getRevisionDate());
// if revision date is older than the expiry date we can stop looking
if (rev.getRevisionDate().toDate().before(expiryDate)) {
oldUser = rev.getEntity();
break;
}
}
/*
If oldUser is null, the user isn't old enough to reset. If the passwords are equal, they haven't been changed in the expiry time.
*/
if (oldUser != null && oldUser.getPassword().equals(user.getPassword())) {
logger.warn("Credentials for user " + user.getUsername() + " have expired.");
throw new CredentialsExpiredException("Credentials have expired.");
}
}
Aggregations