コード例 #1
0
  @Test
  public void remove_user_from_template() {
    newRequest(USER_LOGIN, permissionTemplate.getUuid(), DEFAULT_PERMISSION);

    assertThat(getLoginsInTemplateAndPermission(permissionTemplate.getId(), DEFAULT_PERMISSION))
        .isEmpty();
  }
コード例 #2
0
 private Long getTemplateId(String key) {
   PermissionTemplateDto permissionTemplateDto =
       dbClient.permissionTemplateDao().selectByUuid(key);
   if (permissionTemplateDto == null) {
     throw new BadRequestException("Unknown template: " + key);
   }
   return permissionTemplateDto.getId();
 }
コード例 #3
0
  @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");
  }
コード例 #4
0
  @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());
  }
コード例 #5
0
  @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();
  }
コード例 #6
0
  @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);
  }
コード例 #7
0
  @Test
  public void fail_if_not_logged_in() {
    expectedException.expect(UnauthorizedException.class);
    userSession.anonymous();

    newRequest(USER_LOGIN, permissionTemplate.getUuid(), DEFAULT_PERMISSION);
  }
コード例 #8
0
  @Test
  public void fail_if_insufficient_privileges() {
    expectedException.expect(ForbiddenException.class);
    userSession.setGlobalPermissions(GlobalPermissions.QUALITY_PROFILE_ADMIN);

    newRequest(USER_LOGIN, permissionTemplate.getUuid(), DEFAULT_PERMISSION);
  }
コード例 #9
0
 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);
   }
 }
コード例 #10
0
 private void addUserToTemplate(
     UserDto user, PermissionTemplateDto permissionTemplate, String permission) {
   dbClient
       .permissionTemplateDao()
       .insertUserPermission(dbSession, permissionTemplate.getId(), user.getId(), permission);
 }
コード例 #11
0
  @Test
  public void fail_if_permission_missing() {
    expectedException.expect(IllegalArgumentException.class);

    newRequest(USER_LOGIN, permissionTemplate.getUuid(), null);
  }
コード例 #12
0
  @Test
  public void fail_if_user_missing() {
    expectedException.expect(IllegalArgumentException.class);

    newRequest(null, permissionTemplate.getUuid(), DEFAULT_PERMISSION);
  }
コード例 #13
0
  @Test
  public void fail_if_not_a_project_permission() {
    expectedException.expect(BadRequestException.class);

    newRequest(USER_LOGIN, permissionTemplate.getUuid(), GlobalPermissions.PREVIEW_EXECUTION);
  }