public boolean getNewProjectPrivate(OrganizationDto organization) { return dbTester.getDbClient().organizationDao().getNewProjectPrivate(dbTester.getSession(), organization); } }
@Test public void change_project_visibility_to_private() { userSession.logIn().setSystemAdministrator(); wsTester.newRequest() .setParam(PARAM_PROJECT_VISIBILITY, "private") .execute(); assertThat(dbTester.getDbClient().organizationDao().getNewProjectPrivate(dbTester.getSession(), dbTester.getDefaultOrganization())).isTrue(); }
private ComponentDto createProject(DbSession dbSession, OrganizationDto organization, BranchSupport.ComponentKey componentKey, @Nullable String projectName) { userSession.checkPermission(OrganizationPermission.PROVISION_PROJECTS, organization); Integer userId = userSession.getUserId(); boolean wouldCurrentUserHaveScanPermission = permissionTemplateService.wouldUserHaveScanPermissionWithDefaultTemplate( dbSession, organization.getUuid(), userId, componentKey.getDbKey(), Qualifiers.PROJECT); if (!wouldCurrentUserHaveScanPermission) { throw insufficientPrivilegesException(); } boolean newProjectPrivate = dbClient.organizationDao().getNewProjectPrivate(dbSession, organization); NewComponent newProject = newComponentBuilder() .setOrganizationUuid(organization.getUuid()) .setKey(componentKey.getKey()) .setName(defaultIfBlank(projectName, componentKey.getKey())) .setDeprecatedBranch(componentKey.getDeprecatedBranchName().orElse(null)) .setQualifier(Qualifiers.PROJECT) .setPrivate(newProjectPrivate) .build(); return componentUpdater.createWithoutCommit(dbSession, newProject, userId); }
private CreateWsResponse doHandle(CreateRequest request) { try (DbSession dbSession = dbClient.openSession(false)) { OrganizationDto organization = support.getOrganization(dbSession, request.getOrganization()); userSession.checkPermission(PROVISION_PROJECTS, organization); String visibility = request.getVisibility(); boolean changeToPrivate = visibility == null ? dbClient.organizationDao().getNewProjectPrivate(dbSession, organization) : "private".equals(visibility); support.checkCanUpdateProjectsVisibility(organization, changeToPrivate); ComponentDto componentDto = componentUpdater.create(dbSession, newComponentBuilder() .setOrganizationUuid(organization.getUuid()) .setKey(request.getKey()) .setName(request.getName()) .setDeprecatedBranch(request.getBranch()) .setPrivate(changeToPrivate) .setQualifier(PROJECT) .build(), userSession.isLoggedIn() ? userSession.getUserId() : null); return toCreateResponse(componentDto); } }
@Override public void handle(Request request, Response response) throws Exception { String organizationKey = request.mandatoryParam(PARAM_ORGANIZATION); try (DbSession dbSession = dbClient.openSession(false)) { OrganizationDto organization = checkFoundWithOptional( dbClient.organizationDao().selectByKey(dbSession, organizationKey), "No organization with key '%s'", organizationKey); if (organization.getSubscription() == PAID) { // If the organization is PAID without any public project then // the organization is only visible to members ComponentQuery query = ComponentQuery.builder() .setQualifiers(Qualifiers.PROJECT) .setPrivate(false) .build(); if (dbClient.componentDao().countByQuery(dbSession, organization.getUuid(), query) == 0) { userSession.checkMembership(organization); } } boolean newProjectPrivate = dbClient.organizationDao().getNewProjectPrivate(dbSession, organization); JsonWriter json = response.newJsonWriter(); json.beginObject(); writeOrganization(json, organization, dbClient.organizationAlmBindingDao().selectByOrganization(dbSession, organization), newProjectPrivate); json.endObject() .close(); } }
private ComponentDto createProject(DbSession dbSession, OrganizationDto organization, String projectKey, @Nullable String deprecatedBranch, @Nullable String projectName) { userSession.checkPermission(OrganizationPermission.PROVISION_PROJECTS, organization); Integer userId = userSession.getUserId(); String effectiveProjectKey = ComponentKeys.createEffectiveKey(projectKey, deprecatedBranch); boolean wouldCurrentUserHaveScanPermission = permissionTemplateService.wouldUserHaveScanPermissionWithDefaultTemplate( dbSession, organization.getUuid(), userId, effectiveProjectKey, Qualifiers.PROJECT); if (!wouldCurrentUserHaveScanPermission) { throw insufficientPrivilegesException(); } boolean newProjectPrivate = dbClient.organizationDao().getNewProjectPrivate(dbSession, organization); NewComponent newProject = newComponentBuilder() .setOrganizationUuid(organization.getUuid()) .setKey(projectKey) .setName(defaultIfBlank(projectName, projectKey)) .setBranch(deprecatedBranch) .setQualifier(Qualifiers.PROJECT) .setPrivate(newProjectPrivate) .build(); return componentUpdater.create(dbSession, newProject, userId); }
@Override public void handle(Request request, Response response) throws Exception { String organizationKey = request.mandatoryParam(PARAM_ORGANIZATION); try (DbSession dbSession = dbClient.openSession(false)) { OrganizationDto organization = checkFoundWithOptional( dbClient.organizationDao().selectByKey(dbSession, organizationKey), "No organization with key '%s'", organizationKey); boolean newProjectPrivate = dbClient.organizationDao().getNewProjectPrivate(dbSession, organization); JsonWriter json = response.newJsonWriter(); json.beginObject(); writeOrganization(json, organization, newProjectPrivate); json.endObject() .close(); } }
private CreateWsResponse doHandle(CreateRequest request) { try (DbSession dbSession = dbClient.openSession(false)) { OrganizationDto organization = support.getOrganization(dbSession, request.getOrganization()); userSession.checkPermission(PROVISION_PROJECTS, organization); String visibility = request.getVisibility(); Boolean changeToPrivate = visibility == null ? dbClient.organizationDao().getNewProjectPrivate(dbSession, organization) : "private".equals(visibility); support.checkCanUpdateProjectsVisibility(organization, changeToPrivate); ComponentDto componentDto = componentUpdater.create(dbSession, newComponentBuilder() .setOrganizationUuid(organization.getUuid()) .setKey(request.getKey()) .setName(request.getName()) .setBranch(request.getBranch()) .setPrivate(changeToPrivate) .setQualifier(PROJECT) .build(), userSession.isLoggedIn() ? userSession.getUserId() : null); return toCreateResponse(componentDto); } }