コード例 #1
0
  @Test
  public void search_in_organization() throws Exception {
    OrganizationDto org = db.organizations().insert();
    PermissionTemplateDto templateInOrg = insertProjectTemplate(org);
    PermissionTemplateDto templateInDefaultOrg = insertProjectTemplateOnDefaultOrganization();
    db.commit();

    WsPermissions.SearchTemplatesWsResponse result =
        WsPermissions.SearchTemplatesWsResponse.parseFrom(
            newRequest()
                .setParam("organization", org.getKey())
                .setMediaType(MediaTypes.PROTOBUF)
                .execute()
                .getInputStream());

    assertThat(result.getPermissionTemplatesCount()).isEqualTo(1);
    assertThat(result.getPermissionTemplates(0).getId()).isEqualTo(templateInOrg.getUuid());
  }
コード例 #2
0
  private void doHandle(BulkApplyTemplateWsRequest request) {
    try (DbSession dbSession = dbClient.openSession(false)) {
      PermissionTemplateDto template =
          wsSupport.findTemplate(
              dbSession,
              newTemplateRef(
                  request.getTemplateId(), request.getOrganization(), request.getTemplateName()));
      ComponentQuery componentQuery =
          ComponentQuery.builder()
              .setNameOrKeyQuery(request.getQuery())
              .setQualifiers(qualifiers(request.getQualifier()))
              .build();
      List<ComponentDto> projects =
          dbClient.componentDao().selectByQuery(dbSession, componentQuery, 0, Integer.MAX_VALUE);

      for (ComponentDto project : projects) {
        ProjectId projectId = new ProjectId(project);
        checkProjectAdmin(userSession, template.getOrganizationUuid(), Optional.of(projectId));
      }
      permissionTemplateService.apply(dbSession, template, projects);
    }
  }
コード例 #3
0
  @Test
  public void search_project_permissions() {
    PermissionTemplateDto projectTemplate = insertProjectTemplateOnDefaultOrganization();
    PermissionTemplateDto viewsTemplate = insertViewsTemplate();
    PermissionTemplateDto developerTemplate = insertDeveloperTemplate();

    UserDto user1 = insertUser(newUserDto());
    UserDto user2 = insertUser(newUserDto());
    UserDto user3 = insertUser(newUserDto());

    GroupDto group1 = insertGroup(newGroupDto());
    GroupDto group2 = insertGroup(newGroupDto());
    GroupDto group3 = insertGroup(newGroupDto());

    addUserToTemplate(projectTemplate.getId(), user1.getId(), UserRole.ISSUE_ADMIN);
    addUserToTemplate(projectTemplate.getId(), user2.getId(), UserRole.ISSUE_ADMIN);
    addUserToTemplate(projectTemplate.getId(), user3.getId(), UserRole.ISSUE_ADMIN);
    addUserToTemplate(projectTemplate.getId(), user1.getId(), UserRole.CODEVIEWER);
    addGroupToTemplate(projectTemplate.getId(), group1.getId(), UserRole.ADMIN);
    addPermissionTemplateWithProjectCreator(projectTemplate.getId(), UserRole.ADMIN);

    addUserToTemplate(viewsTemplate.getId(), user1.getId(), UserRole.USER);
    addUserToTemplate(viewsTemplate.getId(), user2.getId(), UserRole.USER);
    addGroupToTemplate(viewsTemplate.getId(), group1.getId(), UserRole.ISSUE_ADMIN);
    addGroupToTemplate(viewsTemplate.getId(), group2.getId(), UserRole.ISSUE_ADMIN);
    addGroupToTemplate(viewsTemplate.getId(), group3.getId(), UserRole.ISSUE_ADMIN);

    addGroupToTemplate(developerTemplate.getId(), group1.getId(), UserRole.USER);

    db.commit();

    String result = newRequest().execute().getInput();

    assertJson(result)
        .withStrictArrayOrder()
        .isSimilarTo(getClass().getResource("search_templates-example.json"));
  }