public static Role mockRole(String roleName, User creator) { Role role = mock(Role.class); when(role.getCreator()).thenReturn(creator); when(role.getCreationTimestamp()).thenReturn(TIMESTAMP_OLD); when(role.getEditor()).thenReturn(creator); when(role.getLastEditedTimestamp()).thenReturn(TIMESTAMP_NEW); when(role.getName()).thenReturn(roleName); when(role.getUuid()).thenReturn(ROLE_CLIENT_UUID); when(role.getRolesWithPerm(GraphPermission.READ_PERM)).thenReturn(createEmptyTraversal()); when(role.getElementVersion()).thenReturn(UUID_4); return role; }
@Override protected String composeDocumentIdFromEntry(UpdateDocumentEntry entry) { return Role.composeDocumentId(entry.getElementUuid()); }
@Override protected String composeIndexNameFromEntry(UpdateDocumentEntry entry) { return Role.composeIndexName(); }
/** * Transform the given object into a source JSON object which can be used to store the document in the search provider specific format. * * @param role * @return JSON document representing the role */ @Override public JsonObject toDocument(Role role) { JsonObject document = new JsonObject(); document.put(NAME_KEY, role.getName()); addBasicReferences(document, role); addPermissionInfo(document, role); document.put(VERSION_KEY, generateVersion(role)); return document; }
public GraphQLObjectType createType() { Builder roleType = newObject(); roleType.name(ROLE_TYPE_NAME); roleType.description("Role description"); interfaceTypeProvider.addCommonFields(roleType); // .name roleType.field(newFieldDefinition().name("name").description("The name of the role").type(GraphQLString).dataFetcher((env) -> { Role role = env.getSource(); return role.getName(); })); // .groups roleType.field(newPagingFieldWithFetcher("groups", "Groups which reference the role.", (env) -> { Role role = env.getSource(); GraphQLContext gc = env.getContext(); return role.getGroups(gc.getUser(), getPagingInfo(env)); }, GROUP_PAGE_TYPE_NAME)); return roleType.build(); }
/** * Adds the information which roles can read permission the given element to the document. This information will later be used by the permission script to * filter out document which should not be visible to the user which invokes the query. * * @param document * @param element */ protected void addPermissionInfo(JsonObject document, MeshCoreVertex<?, ?> element) { Iterable<? extends Role> roleIt = element.getRolesWithPerm(GraphPermission.READ_PERM); List<String> roleUuids = new ArrayList<>(); for (Role role : roleIt) { roleUuids.add(role.getUuid()); } document.put("_roleUuids", roleUuids); }
public String generateVersion(Role role) { // No need to add users since the creator/editor edge affects the role version return ETag.hash(role.getElementVersion()); }
public RoleResponseAssert matches(Role role) { assertGenericNode(role, actual); assertEquals(role.getName(), actual.getName()); assertNotNull(actual.getGroups()); return this; }
/** * Generate the node container specific permission info. Node containers need to store also the read publish perm roles for published containers. * * @param document * @param node * @param type */ private void addPermissionInfo(JsonObject document, Node node, ContainerType type) { List<String> roleUuids = new ArrayList<>(); for (Role role : node.getRolesWithPerm(READ_PERM)) { roleUuids.add(role.getUuid()); } // Also add the roles which would grant read on published nodes if the container is published. if (type == PUBLISHED) { for (Role role : node.getRolesWithPerm(READ_PUBLISHED_PERM)) { roleUuids.add(role.getUuid()); } } document.put("_roleUuids", roleUuids); }
try (Tx tx = db.tx()) { for (Role role : ac.getUser().getRoles()) { roleUuids.add(role.getUuid());
@Override public Set<String> getSelectedIndices(InternalActionContext ac) { return Collections.singleton(Role.composeIndexName()); }
@Override public Set<String> filterUnknownIndices(Set<String> indices) { return filterIndicesByType(indices, Role.composeIndexName()); }
@Override public Map<String, IndexInfo> getIndices() { String indexName = Role.composeIndexName(); IndexInfo info = new IndexInfo(indexName, null, getMappingProvider().getMapping(), "role"); return Collections.singletonMap(indexName, info); }
@Override public Completable syncIndices() { return Completable.defer(() -> { return diffAndSync(Role.composeIndexName(), null, new SyncMetric(getType())); }); }