@Test public void remove_user_from_template() { newRequest(USER_LOGIN, permissionTemplate.getUuid(), DEFAULT_PERMISSION); assertThat(getLoginsInTemplateAndPermission(permissionTemplate.getId(), DEFAULT_PERMISSION)) .isEmpty(); }
private Long getTemplateId(String key) { PermissionTemplateDto permissionTemplateDto = dbClient.permissionTemplateDao().selectByUuid(key); if (permissionTemplateDto == null) { throw new BadRequestException("Unknown template: " + key); } return permissionTemplateDto.getId(); }
@Test public void keep_other_users_when_one_user_removed() { UserDto newUser = insertUser(newUserDto().setLogin("new-login")); addUserToTemplate(newUser, permissionTemplate, DEFAULT_PERMISSION); commit(); newRequest(USER_LOGIN, permissionTemplate.getUuid(), DEFAULT_PERMISSION); assertThat(getLoginsInTemplateAndPermission(permissionTemplate.getId(), DEFAULT_PERMISSION)) .containsExactly("new-login"); }
@Test public void keep_user_permission_not_removed() { addUserToTemplate(user, permissionTemplate, ISSUE_ADMIN); commit(); newRequest(USER_LOGIN, permissionTemplate.getUuid(), DEFAULT_PERMISSION); assertThat(getLoginsInTemplateAndPermission(permissionTemplate.getId(), DEFAULT_PERMISSION)) .isEmpty(); assertThat(getLoginsInTemplateAndPermission(permissionTemplate.getId(), ISSUE_ADMIN)) .containsExactly(user.getLogin()); }
@Test public void remove_user_from_template_by_name_case_insensitive() { ws.newRequest() .setParam(PARAM_USER_LOGIN, USER_LOGIN) .setParam(PARAM_PERMISSION, DEFAULT_PERMISSION) .setParam(PARAM_TEMPLATE_NAME, permissionTemplate.getName().toUpperCase()) .execute(); commit(); assertThat(getLoginsInTemplateAndPermission(permissionTemplate.getId(), DEFAULT_PERMISSION)) .isEmpty(); }
@Test public void fail_if_user_does_not_exist() { expectedException.expect(NotFoundException.class); expectedException.expectMessage("User with login 'unknown-login' is not found"); newRequest("unknown-login", permissionTemplate.getUuid(), DEFAULT_PERMISSION); }
@Test public void fail_if_not_logged_in() { expectedException.expect(UnauthorizedException.class); userSession.anonymous(); newRequest(USER_LOGIN, permissionTemplate.getUuid(), DEFAULT_PERMISSION); }
@Test public void fail_if_insufficient_privileges() { expectedException.expect(ForbiddenException.class); userSession.setGlobalPermissions(GlobalPermissions.QUALITY_PROFILE_ADMIN); newRequest(USER_LOGIN, permissionTemplate.getUuid(), DEFAULT_PERMISSION); }
private void doHandle(RemoveProjectCreatorFromTemplateWsRequest request) { DbSession dbSession = dbClient.openSession(false); try { PermissionTemplateDto template = dependenciesFinder.getTemplate( dbSession, WsTemplateRef.newTemplateRef(request.getTemplateId(), request.getTemplateName())); PermissionTemplateCharacteristicDao dao = dbClient.permissionTemplateCharacteristicDao(); Optional<PermissionTemplateCharacteristicDto> templatePermission = dao.selectByPermissionAndTemplateId(dbSession, request.getPermission(), template.getId()); if (templatePermission.isPresent()) { updateTemplateCharacteristic(dbSession, templatePermission.get()); } } finally { dbClient.closeSession(dbSession); } }
private void addUserToTemplate( UserDto user, PermissionTemplateDto permissionTemplate, String permission) { dbClient .permissionTemplateDao() .insertUserPermission(dbSession, permissionTemplate.getId(), user.getId(), permission); }
@Test public void fail_if_permission_missing() { expectedException.expect(IllegalArgumentException.class); newRequest(USER_LOGIN, permissionTemplate.getUuid(), null); }
@Test public void fail_if_user_missing() { expectedException.expect(IllegalArgumentException.class); newRequest(null, permissionTemplate.getUuid(), DEFAULT_PERMISSION); }
@Test public void fail_if_not_a_project_permission() { expectedException.expect(BadRequestException.class); newRequest(USER_LOGIN, permissionTemplate.getUuid(), GlobalPermissions.PREVIEW_EXECUTION); }