@Test public void hasComponentPermission_on_branch_checks_permissions_of_its_project() { UserDto user = db.users().insertUser(); ComponentDto privateProject = db.components().insertPrivateProject(); ComponentDto branch = db.components().insertProjectBranch(privateProject, b -> b.setKey("feature/foo")); ComponentDto fileInBranch = db.components().insertComponent(newChildComponent("fileUuid", branch, branch)); // permissions are defined on the project, not on the branch db.users().insertProjectPermissionOnUser(user, "p1", privateProject); UserSession underTest = newUserSession(user); assertThat(hasComponentPermissionByDtoOrUuid(underTest, "p1", privateProject)).isTrue(); assertThat(hasComponentPermissionByDtoOrUuid(underTest, "p1", branch)).isTrue(); assertThat(hasComponentPermissionByDtoOrUuid(underTest, "p1", fileInBranch)).isTrue(); }
public static ComponentDto newDirectory(ComponentDto module, String uuid, String path) { String key = !path.equals("/") ? module.getKey() + ":" + path : module.getKey() + ":/"; return newChildComponent(uuid, module, module) .setDbKey(generateKey(key, module)) .setName(path) .setLongName(path) .setPath(path) .setScope(Scopes.DIRECTORY) .setQualifier(Qualifiers.DIRECTORY); }
public static ComponentDto newFileDto(ComponentDto module, @Nullable ComponentDto directory, String fileUuid) { String filename = "NAME_" + fileUuid; String path = directory != null ? directory.path() + "/" + filename : module.path() + "/" + filename; return newChildComponent(fileUuid, module, directory == null ? module : directory) .setDbKey(generateKey("FILE_KEY_" + fileUuid, module)) .setName(filename) .setLongName(path) .setScope(Scopes.FILE) .setQualifier(Qualifiers.FILE) .setPath(path) .setCreatedAt(new Date()) .setLanguage("xoo"); }
private ComponentDto initJsonExampleComponents() throws IOException { OrganizationDto organizationDto = db.organizations().insertForKey("my-org-1"); ComponentDto project = newPrivateProjectDto(organizationDto, "MY_PROJECT_ID") .setDbKey("MY_PROJECT_KEY") .setName("Project Name"); db.components().insertProjectAndSnapshot(project); Date now = new Date(); JsonParser jsonParser = new JsonParser(); JsonElement jsonTree = jsonParser.parse(IOUtils.toString(getClass().getResource("tree-example.json"), UTF_8)); JsonArray components = jsonTree.getAsJsonObject().getAsJsonArray("components"); for (JsonElement componentAsJsonElement : components) { JsonObject componentAsJsonObject = componentAsJsonElement.getAsJsonObject(); String uuid = getJsonField(componentAsJsonObject, "id"); db.components().insertComponent(newChildComponent(uuid, project, project) .setDbKey(getJsonField(componentAsJsonObject, "key")) .setName(getJsonField(componentAsJsonObject, "name")) .setLanguage(getJsonField(componentAsJsonObject, "language")) .setPath(getJsonField(componentAsJsonObject, "path")) .setQualifier(getJsonField(componentAsJsonObject, "qualifier")) .setDescription(getJsonField(componentAsJsonObject, "description")) .setEnabled(true) .setCreatedAt(now)); } db.commit(); return project; }
public static ComponentDto newProjectCopy(String uuid, ComponentDto project, ComponentDto view) { checkNotNull(project.getId(), "The project need to be persisted before creating this technical project."); return newChildComponent(uuid, view, view) .setDbKey(view.getDbKey() + project.getDbKey()) .setName(project.name()) .setLongName(project.longName()) .setCopyComponentUuid(project.uuid()) .setScope(Scopes.FILE) .setQualifier(Qualifiers.PROJECT) .setPath(null) .setLanguage(null); }
public static ComponentDto newModuleDto(String uuid, ComponentDto parentModuleOrProject) { return newChildComponent(uuid, parentModuleOrProject, parentModuleOrProject) .setModuleUuidPath(parentModuleOrProject.moduleUuidPath() + uuid + UUID_PATH_SEPARATOR) .setDbKey(generateKey("MODULE_KEY_" + uuid, parentModuleOrProject)) .setName("NAME_" + uuid) .setLongName("LONG_NAME_" + uuid) .setPath("module") .setScope(Scopes.PROJECT) .setQualifier(Qualifiers.MODULE) .setLanguage(null); }