use of com.enonic.xp.repository.RepositoryId in project xp by enonic.
the class ProjectServiceImplTest method create_with_root_content_permissions.
@Test
void create_with_root_content_permissions() {
final RepositoryId projectRepoId = RepositoryId.from("com.enonic.cms.test-project");
final ProjectName projectName = ProjectName.from(projectRepoId);
doCreateProjectAsAdmin(projectName);
List.of(ContextBuilder.from(adminContext()).branch(ContentConstants.BRANCH_DRAFT).repositoryId(projectRepoId).build(), ContextBuilder.from(adminContext()).branch(ContentConstants.BRANCH_MASTER).repositoryId(projectRepoId).build()).forEach(context -> context.runWith(() -> {
final Node rootContentNode = nodeService.getByPath(ContentConstants.CONTENT_ROOT_PATH);
final AccessControlList rootContentPermissions = rootContentNode.getPermissions();
assertTrue(rootContentPermissions.getEntry(RoleKeys.ADMIN).isAllowedAll());
assertTrue(rootContentPermissions.getEntry(RoleKeys.CONTENT_MANAGER_ADMIN).isAllowedAll());
assertTrue(rootContentPermissions.getEntry(PrincipalKey.ofRole("cms.project.test-project.owner")).isAllowedAll());
assertTrue(rootContentPermissions.getEntry(PrincipalKey.ofRole("cms.project.test-project.editor")).isAllowedAll());
assertTrue(rootContentPermissions.getEntry(PrincipalKey.ofRole("cms.project.test-project.author")).isAllowed(Permission.READ, Permission.CREATE, Permission.MODIFY, Permission.DELETE));
assertTrue(rootContentPermissions.getEntry(PrincipalKey.ofRole("cms.project.test-project.contributor")).isAllowed(Permission.READ));
assertTrue(rootContentPermissions.getEntry(PrincipalKey.ofRole("cms.project.test-project.viewer")).isAllowed(Permission.READ));
assertNull(rootContentPermissions.getEntry(RoleKeys.EVERYONE));
}));
}
use of com.enonic.xp.repository.RepositoryId in project xp by enonic.
the class ProjectServiceImplTest method create_with_custom_permissions.
@Test
void create_with_custom_permissions() {
final RepositoryId projectRepoId = RepositoryId.from("com.enonic.cms.test-project");
contentCustomManagerContext().runWith(() -> {
final RuntimeException ex = Assertions.assertThrows(RuntimeException.class, () -> doCreateProject(ProjectName.from(projectRepoId)));
assertEquals("Denied [user:system:custom-user] user access for [create] operation", ex.getMessage());
});
}
use of com.enonic.xp.repository.RepositoryId in project xp by enonic.
the class ProjectServiceImplTest method create_with_root_issues_permissions.
@Test
void create_with_root_issues_permissions() {
final RepositoryId projectRepoId = RepositoryId.from("com.enonic.cms.test-project");
final ProjectName projectName = ProjectName.from(projectRepoId);
doCreateProjectAsAdmin(projectName);
ContextBuilder.from(adminContext()).branch(ContentConstants.BRANCH_DRAFT).repositoryId(projectRepoId).build().runWith(() -> {
final Node rootIssuesNode = nodeService.getByPath(NodePath.create(NodePath.ROOT, "issues").build());
final AccessControlList rootContentPermissions = rootIssuesNode.getPermissions();
assertAll(() -> assertTrue(rootContentPermissions.getEntry(RoleKeys.ADMIN).isAllowedAll()), () -> assertTrue(rootContentPermissions.getEntry(RoleKeys.CONTENT_MANAGER_ADMIN).isAllowedAll()), () -> assertTrue(rootContentPermissions.isAllowedFor(PrincipalKey.ofRole("cms.project.test-project.viewer"), Permission.READ)));
PrincipalKeys.from(PrincipalKey.ofRole("cms.project.test-project.owner"), PrincipalKey.ofRole("cms.project.test-project.editor"), PrincipalKey.ofRole("cms.project.test-project.contributor"), PrincipalKey.ofRole("cms.project.test-project.author")).forEach(principalKey -> assertTrue(rootContentPermissions.isAllowedFor(principalKey, Permission.READ, Permission.CREATE, Permission.MODIFY, Permission.DELETE)));
});
}
use of com.enonic.xp.repository.RepositoryId in project xp by enonic.
the class ProjectServiceImplTest method modify_permissions.
@Test
void modify_permissions() {
final RepositoryId projectRepoId = RepositoryId.from("com.enonic.cms.test-project");
adminContext().runWith(() -> {
final User user1 = securityService.createUser(CreateUserParams.create().userKey(PrincipalKey.ofUser(IdProviderKey.system(), "user1")).displayName("user1").login("user1").build());
final User user2 = securityService.createUser(CreateUserParams.create().userKey(PrincipalKey.ofUser(IdProviderKey.system(), "user2")).displayName("user2").login("user2").build());
doCreateProjectAsAdmin(ProjectName.from(projectRepoId), ProjectPermissions.create().addOwner(user1.getKey()).build());
projectService.modifyPermissions(ProjectName.from("test-project"), ProjectPermissions.create().addOwner(user2.getKey()).build());
final PrincipalRelationships principalRelationships = securityService.getRelationships(PrincipalKey.ofRole("cms.project.test-project.owner"));
assertEquals(1, principalRelationships.getSize());
assertEquals(principalRelationships.get(0).getTo(), user2.getKey());
});
}
use of com.enonic.xp.repository.RepositoryId in project xp by enonic.
the class ProjectServiceImplTest method modify_with_deleted_role.
@Test
void modify_with_deleted_role() {
final RepositoryId projectRepoId = RepositoryId.from("com.enonic.cms.test-project");
doCreateProjectAsAdmin(ProjectName.from(projectRepoId));
adminContext().runWith(() -> {
securityService.deletePrincipal(PrincipalKey.ofRole("cms.project.test-project.owner"));
projectService.modify(ModifyProjectParams.create().name(ProjectName.from("test-project")).description("new description").displayName("new display name").build());
});
assertFalse(securityService.getRole(PrincipalKey.ofRole("cms.project.test-project.owner")).isPresent());
}
Aggregations