Search in sources :

Example 1 with User

use of ca.corefacility.bioinformatics.irida.model.user.User in project irida by phac-nml.

the class AnnouncementsController method submitCreateAnnouncement.

/**
 * Create a new announcement
 *
 * @param message
 *              The content of the message for the announcement
 * @param model
 *              The model for the view
 * @param principal
 *              The currently logged in user creating the announcement
 * @return A redirect to the announcement control centre page
 */
@RequestMapping(value = "/create", method = RequestMethod.POST)
@PreAuthorize("hasRole('ROLE_ADMIN')")
public String submitCreateAnnouncement(@RequestParam(required = true) String message, Model model, Principal principal) {
    User creator = userService.getUserByUsername(principal.getName());
    Announcement a = new Announcement(message, creator);
    try {
        announcementService.create(a);
    } catch (Exception e) {
        model.addAttribute("errors", "Announcement was not created successfully");
    }
    return "redirect:/announcements/admin";
}
Also used : DTAnnouncementUser(ca.corefacility.bioinformatics.irida.ria.web.models.datatables.DTAnnouncementUser) User(ca.corefacility.bioinformatics.irida.model.user.User) Announcement(ca.corefacility.bioinformatics.irida.model.announcements.Announcement) IOException(java.io.IOException) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with User

use of ca.corefacility.bioinformatics.irida.model.user.User in project irida by phac-nml.

the class AnnouncementsController method getUnreadAnnouncementsForUser.

/**
 * Gets a list of Announcements that the current user hasn't read yet
 *
 * @param model
 *              Model for the view
 * @param principal
 *              The current user
 * @return the fragment for viewing announcements in the dashboard
 */
@RequestMapping(value = "/user/unread")
public String getUnreadAnnouncementsForUser(final Model model, Principal principal) {
    User user = userService.getUserByUsername(principal.getName());
    List<Announcement> unreadAnnouncements = announcementService.getUnreadAnnouncementsForUser(user);
    Collections.sort(unreadAnnouncements, Collections.reverseOrder());
    model.addAttribute("announcements", unreadAnnouncements);
    return ANNOUNCEMENT_VIEW;
}
Also used : DTAnnouncementUser(ca.corefacility.bioinformatics.irida.ria.web.models.datatables.DTAnnouncementUser) User(ca.corefacility.bioinformatics.irida.model.user.User) Announcement(ca.corefacility.bioinformatics.irida.model.announcements.Announcement) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 3 with User

use of ca.corefacility.bioinformatics.irida.model.user.User in project irida by phac-nml.

the class GroupsController method updateUserRole.

/**
 * Update a user's role on a group
 *
 * @param groupId
 *            The ID of the group
 * @param userId
 *            The ID of the user
 * @param groupRole
 *            The role to set
 * @param locale
 *            Locale of the logged in user
 *
 * @return message indicating update result
 */
@RequestMapping(path = "/{groupId}/members/editrole/{userId}", method = RequestMethod.POST)
@ResponseBody
public Map<String, String> updateUserRole(@PathVariable final Long groupId, @PathVariable final Long userId, @RequestParam final String groupRole, final Locale locale) {
    final UserGroup group = userGroupService.read(groupId);
    final User user = userService.read(userId);
    final UserGroupRole userGroupRole = UserGroupRole.fromString(groupRole);
    final String roleName = messageSource.getMessage("group.users.role." + groupRole, new Object[] {}, locale);
    try {
        userGroupService.changeUserGroupRole(user, group, userGroupRole);
        return ImmutableMap.of("success", messageSource.getMessage("group.members.edit.role.success", new Object[] { user.getLabel(), roleName }, locale));
    } catch (final UserGroupWithoutOwnerException e) {
        return ImmutableMap.of("failure", messageSource.getMessage("group.members.edit.role.failure", new Object[] { user.getLabel(), roleName }, locale));
    }
}
Also used : UserGroupRole(ca.corefacility.bioinformatics.irida.model.user.group.UserGroupJoin.UserGroupRole) User(ca.corefacility.bioinformatics.irida.model.user.User) UserGroupWithoutOwnerException(ca.corefacility.bioinformatics.irida.exceptions.UserGroupWithoutOwnerException) DTUserGroup(ca.corefacility.bioinformatics.irida.ria.web.models.datatables.DTUserGroup) UserGroup(ca.corefacility.bioinformatics.irida.model.user.group.UserGroup)

Example 4 with User

use of ca.corefacility.bioinformatics.irida.model.user.User in project irida by phac-nml.

the class GroupsController method addUserToGroup.

/**
 * Add a new user to the group.
 *
 * @param userGroupId
 *            the group to add to.
 * @param userId
 *            the new member.
 * @param groupRole
 *            the role this user should have.
 * @param locale
 *            the locale of the browser.
 * @return a message indicating success.
 */
@RequestMapping(path = "/{userGroupId}/members", method = RequestMethod.POST)
@ResponseBody
public Map<String, String> addUserToGroup(@PathVariable final Long userGroupId, @RequestParam final Long userId, @RequestParam String groupRole, Locale locale) {
    final User user = userService.read(userId);
    final UserGroup group = userGroupService.read(userGroupId);
    final UserGroupRole role = UserGroupRole.valueOf(groupRole);
    userGroupService.addUserToGroup(user, group, role);
    return ImmutableMap.of("result", messageSource.getMessage("group.users.add.notification.success", new Object[] { user.getLabel() }, locale));
}
Also used : UserGroupRole(ca.corefacility.bioinformatics.irida.model.user.group.UserGroupJoin.UserGroupRole) User(ca.corefacility.bioinformatics.irida.model.user.User) DTUserGroup(ca.corefacility.bioinformatics.irida.ria.web.models.datatables.DTUserGroup) UserGroup(ca.corefacility.bioinformatics.irida.model.user.group.UserGroup)

Example 5 with User

use of ca.corefacility.bioinformatics.irida.model.user.User in project irida by phac-nml.

the class GroupsController method getRemoveUserModal.

/**
 * Get a string to tell the user which group they're going to delete.
 *
 * @param userId
 *            the user group that's about to be deleted.
 * @param model
 *            model for the view to render
 * @return a message indicating which group is going to be deleted.
 */
@RequestMapping(path = "/removeUserModal", method = RequestMethod.POST)
public String getRemoveUserModal(@RequestParam final Long userId, final Model model) {
    final User user = userService.read(userId);
    model.addAttribute("user", user);
    return GROUPS_USER_MODAL;
}
Also used : User(ca.corefacility.bioinformatics.irida.model.user.User)

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