Search in sources :

Example 16 with User

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);
}
Also used : Project(ca.corefacility.bioinformatics.irida.model.project.Project) User(ca.corefacility.bioinformatics.irida.model.user.User) ProjectUserJoin(ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectUserJoin) DataTablesResponseModel(ca.corefacility.bioinformatics.irida.ria.web.components.datatables.models.DataTablesResponseModel) Join(ca.corefacility.bioinformatics.irida.model.joins.Join) ProjectUserJoin(ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectUserJoin) UserGroupProjectJoin(ca.corefacility.bioinformatics.irida.model.user.group.UserGroupProjectJoin) DataTablesResponse(ca.corefacility.bioinformatics.irida.ria.web.components.datatables.DataTablesResponse) DTProjectMember(ca.corefacility.bioinformatics.irida.ria.web.models.datatables.DTProjectMember)

Example 17 with User

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));
}
Also used : Project(ca.corefacility.bioinformatics.irida.model.project.Project) User(ca.corefacility.bioinformatics.irida.model.user.User) ProjectRole(ca.corefacility.bioinformatics.irida.model.enums.ProjectRole)

Example 18 with User

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";
}
Also used : Project(ca.corefacility.bioinformatics.irida.model.project.Project) User(ca.corefacility.bioinformatics.irida.model.user.User) HashMap(java.util.HashMap) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 19 with User

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;
}
Also used : Project(ca.corefacility.bioinformatics.irida.model.project.Project) User(ca.corefacility.bioinformatics.irida.model.user.User) HashMap(java.util.HashMap) RemoteStatus(ca.corefacility.bioinformatics.irida.model.remote.RemoteStatus) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 20 with User

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.");
    }
}
Also used : User(ca.corefacility.bioinformatics.irida.model.user.User) CredentialsExpiredException(org.springframework.security.authentication.CredentialsExpiredException) Calendar(java.util.Calendar) GregorianCalendar(java.util.GregorianCalendar) GregorianCalendar(java.util.GregorianCalendar) Date(java.util.Date)

Aggregations

User (ca.corefacility.bioinformatics.irida.model.user.User)252 Test (org.junit.Test)153 Project (ca.corefacility.bioinformatics.irida.model.project.Project)84 WithMockUser (org.springframework.security.test.context.support.WithMockUser)57 Authentication (org.springframework.security.core.Authentication)45 Join (ca.corefacility.bioinformatics.irida.model.joins.Join)34 UsernamePasswordAuthenticationToken (org.springframework.security.authentication.UsernamePasswordAuthenticationToken)27 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)27 PageRequest (org.springframework.data.domain.PageRequest)26 UserGroup (ca.corefacility.bioinformatics.irida.model.user.group.UserGroup)25 ProjectRole (ca.corefacility.bioinformatics.irida.model.enums.ProjectRole)24 ProjectUserJoin (ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectUserJoin)24 AnalysisSubmission (ca.corefacility.bioinformatics.irida.model.workflow.submission.AnalysisSubmission)19 Principal (java.security.Principal)19 ProjectSampleJoin (ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectSampleJoin)18 RelatedProjectJoin (ca.corefacility.bioinformatics.irida.model.joins.impl.RelatedProjectJoin)18 List (java.util.List)18 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)17 EntityNotFoundException (ca.corefacility.bioinformatics.irida.exceptions.EntityNotFoundException)16 ArrayList (java.util.ArrayList)16