use of com.bakdata.conquery.models.auth.permissions.DatasetPermission in project conquery by bakdata.
the class RoleHandlingOnGroupTest method execute.
@Override
public void execute(StandaloneSupport conquery) throws Exception {
Dataset dataset1 = new Dataset();
dataset1.setLabel("dataset1");
MetaStorage storage = conquery.getMetaStorage();
Group group1 = new Group("company", "company", storage);
Role role = new Role("role1", "role1", storage);
TestUser user1 = new TestUser(storage);
try {
storage.addRole(role);
storage.addUser(user1);
storage.addGroup(group1);
role.addPermission(new DatasetPermission().instancePermission(Ability.READ, new DatasetId("testDataset")));
// // Add user to group
group1.addMember(user1);
assertThat(user1.isPermitted(new DatasetPermission().instancePermission(Ability.READ, new DatasetId("testDataset")))).isFalse();
// // Add role to group
group1.addRole(role);
assertThat(group1.getRoles()).containsExactlyInAnyOrder(role.getId());
assertThat(user1.isPermitted(new DatasetPermission().instancePermission(Ability.READ, new DatasetId("testDataset")))).isTrue();
// // Remove role from group
group1.removeRole(role);
assertThat(group1.getRoles()).isEmpty();
assertThat(user1.isPermitted(new DatasetPermission().instancePermission(Ability.READ, new DatasetId("testDataset")))).isFalse();
} finally {
storage.removeGroup(group1.getId());
storage.removeUser(user1.getId());
storage.removeRole(role.getId());
}
}
use of com.bakdata.conquery.models.auth.permissions.DatasetPermission in project conquery by bakdata.
the class PermissionCreationTest method createPermissionIllegalAbility.
@Test
public void createPermissionIllegalAbility() {
Permission perm = null;
try {
// This should fail because the ability is not allowed for a DatasetPermission
perm = DatasetPermission.onInstance(Ability.SHARE.asSet(), new DatasetId("test"));
} catch (Exception e) {
assertThat(e).isInstanceOf(IllegalArgumentException.class);
}
// Should not be reached
assertThat(perm).isNull();
}
Aggregations