@Test @WithMockUser(username = ADMIN_USERNAME, roles = ROLE_ADMIN) void creatingOrganizationUserWillDelegate_WhenRequestingUserIsAdmin() throws Exception { User authUser = MockAuthenticationContextProvider.getAuthUser(); mockMvc.perform(post("/api/organizations/{organizationId}/users", ORGANIZATION_ID) .contentType(APPLICATION_JSON) .content(objectMapper.writeValueAsString(NEW_USER_REQUEST))) .andExpect(status().isCreated()) .andExpect(content().string(Matchers.any(String.class))); verify(usersService).createUser(authUser.getId(), ORGANIZATION_ID, NEW_USER_USERNAME, NEW_USER_DISPLAY_NAME, RAW_PASSWORD); }
@PostMapping("/{organizationId}/users") @ApiOperation(produces = APPLICATION_JSON_VALUE, value = "Create a new user for an organization") @ResponseStatus(CREATED) @AdminOrAdminOfTargetOrganization public UUID createUser(User requestingUser, @PathVariable UUID organizationId, @RequestBody @Valid NewUserRequest request) { return usersService.createUser(requestingUser.getId(), organizationId, request.getUsername(), request.getDisplayName(), request.getPassword()); }
OrganizationsController { @PostMapping("/{organizationId}/users") @ApiOperation(produces = APPLICATION_JSON_VALUE, value = "Create a new user for an organization") @ResponseStatus(CREATED) @AdminOrAdminOfTargetOrganization public UUID createUser(User requestingUser, @PathVariable UUID organizationId, @RequestBody @Valid NewUserRequest request) { return usersService.createUser(requestingUser.getId(), organizationId, request.getUsername(), request.getDisplayName(), request.getPassword()); } }
OrganizationsController { @PostMapping("/{organizationId}/users") @ApiOperation(produces = APPLICATION_JSON_VALUE, value = "Create a new user for an organization") @ResponseStatus(CREATED) @AdminOrAdminOfTargetOrganization public UUID createUser(User requestingUser, @PathVariable UUID organizationId, @RequestBody @Valid NewUserRequest request) { return usersService.createUser(requestingUser.getId(), organizationId, request.getUsername(), request.getDisplayName(), request.getPassword()); } @Autowired  OrganizationsController(DtoConverter dtoConverter,
                                   OrganizationsService organizationsService,
                                   OrganizationsReadService organizationsReadService,
                                   PendingRegistrationsService pendingRegistrationsService,
                                   UsersService usersService,
                                   UsersReadService usersReadService,
                                   RandomFieldsGenerator randomFieldsGenerator); }
OrganizationsController { @PostMapping("/{organizationId}/users") @ApiOperation(produces = APPLICATION_JSON_VALUE, value = "Create a new user for an organization") @ResponseStatus(CREATED) @AdminOrAdminOfTargetOrganization public UUID createUser(User requestingUser, @PathVariable UUID organizationId, @RequestBody @Valid NewUserRequest request) { return usersService.createUser(requestingUser.getId(), organizationId, request.getUsername(), request.getDisplayName(), request.getPassword()); } @Autowired  OrganizationsController(DtoConverter dtoConverter,
                                   OrganizationsService organizationsService,
                                   OrganizationsReadService organizationsReadService,
                                   PendingRegistrationsService pendingRegistrationsService,
                                   UsersService usersService,
                                   UsersReadService usersReadService,
                                   RandomFieldsGenerator randomFieldsGenerator); @GetMapping("/{organizationId}") @ResponseStatus(OK) @ApiOperation("Get information for an organization") @AdminOrUserOfTargetOrganization OrganizationResponse getOrganization(User requestingUser, @PathVariable UUID organizationId); @PostMapping("/register") @ResponseStatus(CREATED) @ApiOperation("Register a new organization") OrganizationRegistrationResponse registerOrganization(@RequestBody @Valid RegisterOrganizationRequest request); @GetMapping("/{organizationId}/register/{confirmationCode}") // Can't easily POST from an email link @ResponseStatus(OK) @ApiOperation("Confirm the email address used to register an organization") void confirmOrganizationContactEmail(@PathVariable UUID organizationId, @PathVariable UUID confirmationCode); @PutMapping("/{organizationId}") @ResponseStatus(OK) @ApiOperation("Update Organization") @AdminOrAdminOfTargetOrganization void updateOrganization(User requestingUser,
                                   @PathVariable UUID organizationId,
                                   @RequestBody @Valid UpdateOrganizationRequest request); @GetMapping("/{organizationId}/users") @ApiOperation(produces = APPLICATION_JSON_VALUE, value = "Retrieve a list of users for an organization") @AdminOrUserOfTargetOrganization List<UserResponse> listOrganizationUsers(User requestingUser, @PathVariable UUID organizationId); @PostMapping("/{organizationId}/users") @ApiOperation(produces = APPLICATION_JSON_VALUE, value = "Create a new user for an organization") @ResponseStatus(CREATED) @AdminOrAdminOfTargetOrganization UUID createUser(User requestingUser, @PathVariable UUID organizationId, @RequestBody @Valid NewUserRequest request); }
OrganizationsController { @PostMapping("/{organizationId}/users") @ApiOperation(produces = APPLICATION_JSON_VALUE, value = "Create a new user for an organization") @ResponseStatus(CREATED) @AdminOrAdminOfTargetOrganization public UUID createUser(User requestingUser, @PathVariable UUID organizationId, @RequestBody @Valid NewUserRequest request) { return usersService.createUser(requestingUser.getId(), organizationId, request.getUsername(), request.getDisplayName(), request.getPassword()); } @Autowired  OrganizationsController(DtoConverter dtoConverter,
                                   OrganizationsService organizationsService,
                                   OrganizationsReadService organizationsReadService,
                                   PendingRegistrationsService pendingRegistrationsService,
                                   UsersService usersService,
                                   UsersReadService usersReadService,
                                   RandomFieldsGenerator randomFieldsGenerator); @GetMapping("/{organizationId}") @ResponseStatus(OK) @ApiOperation("Get information for an organization") @AdminOrUserOfTargetOrganization OrganizationResponse getOrganization(User requestingUser, @PathVariable UUID organizationId); @PostMapping("/register") @ResponseStatus(CREATED) @ApiOperation("Register a new organization") OrganizationRegistrationResponse registerOrganization(@RequestBody @Valid RegisterOrganizationRequest request); @GetMapping("/{organizationId}/register/{confirmationCode}") // Can't easily POST from an email link @ResponseStatus(OK) @ApiOperation("Confirm the email address used to register an organization") void confirmOrganizationContactEmail(@PathVariable UUID organizationId, @PathVariable UUID confirmationCode); @PutMapping("/{organizationId}") @ResponseStatus(OK) @ApiOperation("Update Organization") @AdminOrAdminOfTargetOrganization void updateOrganization(User requestingUser,
                                   @PathVariable UUID organizationId,
                                   @RequestBody @Valid UpdateOrganizationRequest request); @GetMapping("/{organizationId}/users") @ApiOperation(produces = APPLICATION_JSON_VALUE, value = "Retrieve a list of users for an organization") @AdminOrUserOfTargetOrganization List<UserResponse> listOrganizationUsers(User requestingUser, @PathVariable UUID organizationId); @PostMapping("/{organizationId}/users") @ApiOperation(produces = APPLICATION_JSON_VALUE, value = "Create a new user for an organization") @ResponseStatus(CREATED) @AdminOrAdminOfTargetOrganization UUID createUser(User requestingUser, @PathVariable UUID organizationId, @RequestBody @Valid NewUserRequest request);  }