private Map<String, String> loadVersionsFromGraph() { Map<String, String> versions = new HashMap<>(); for (T element : getRootVertex().findAll()) { String v = generateVersion(element); versions.put(element.getUuid(), v); } return versions; }
/** * 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); }
@Override public <T extends MeshCoreVertex<?, ?>> T requiresPerm(T vertex, GraphPermission... permission) { for (GraphPermission perm : permission) { if (getUser().hasPermission(vertex, perm)) { return vertex; } } throw missingPerm(vertex.getTypeInfo().getType(), vertex.getUuid()); }
Tuple<Boolean, SearchQueueBatch> tuple = database.tx(() -> { SearchQueueBatch batch = searchQueue.create(); boolean updated = updateElement.update(ac, batch); return Tuple.tuple(updated, batch); }); RM model = updateElement.transformToRestSync(ac, 0); info = new ResultInfo(model, b); if (isUpdated) { updateElement.onUpdated(); RM model = createdElement.transformToRestSync(ac, 0); String path = createdElement.getAPIPath(ac); info = new ResultInfo(model, b); info.setProperty("path", path); createdElement.onCreated(); ac.setLocation(path);
/** * Read the element with the given element by loading it from the specified root vertex. * * @param ac * @param uuid * Uuid of the element which should be loaded * @param handler * Handler which provides the root vertex which should be used when loading the element * @param perm * Permission to check against when loading the element */ public <T extends MeshCoreVertex<RM, T>, RM extends RestModel> void readElement(InternalActionContext ac, String uuid, TxAction1<RootVertex<T>> handler, GraphPermission perm) { asyncTx(ac, (tx) -> { RootVertex<T> root = handler.handle(); T element = root.loadObjectByUuid(ac, uuid, perm); // Handle etag if (ac.getGenericParameters().getETag()) { String etag = element.getETag(ac); ac.setEtag(etag, true); if (ac.matches(etag, true)) { throw new NotModifiedException(); } } return element.transformToRestSync(ac, 0); }, (model) -> ac.send(model, OK)); }
return db.tx(() -> Single.just(element.v1().transformToRestSync(ac, 0, element.v2()))); }).collect(() -> listResponse.getData(), (x, y) -> { x.add(y);
/** * Add basic references (creator, editor, created, edited) to the map for the given vertex. * * @param document * JSON document to which basic references will be added * @param vertex * Vertex which will be used to load the basic references */ protected void addBasicReferences(JsonObject document, MeshCoreVertex<?, ?> vertex) { document.put("uuid", vertex.getUuid()); if (vertex instanceof CreatorTrackingVertex) { CreatorTrackingVertex createdVertex = (CreatorTrackingVertex) vertex; addUser(document, "creator", createdVertex.getCreator()); document.put("created", createdVertex.getCreationDate()); } if (vertex instanceof EditorTrackingVertex) { EditorTrackingVertex editedVertex = (EditorTrackingVertex) vertex; addUser(document, "editor", editedVertex.getEditor()); document.put("edited", editedVertex.getLastEditedDate()); } }
/** * Load the object by name and check the given permission. * * @param ac * Context to be used in order to check user permissions * @param name * Name of the object that should be loaded * @param perm * Permission that must be granted in order to load the object * @return */ default T findByName(InternalActionContext ac, String name, GraphPermission perm) { T element = findByName(name); if (element == null) { throw error(NOT_FOUND, "object_not_found_for_name", name); } MeshAuthUser requestUser = ac.getUser(); String elementUuid = element.getUuid(); if (requestUser.hasPermission(element, perm)) { return element; } else { throw error(FORBIDDEN, "error_missing_perm", elementUuid, perm.getRestPerm().getName()); } }
String elementUuid = element.getUuid(); if (requestUser.hasPermission(element, perm)) { return element;
public void assertGenericNode(MeshCoreVertex<?, ?> node, AbstractGenericRestResponse model) { assertNotNull(node); assertNotNull(model); assertNotNull("UUID field was not set in the rest response.", model.getUuid()); assertEquals("The uuids should not be different", node.getUuid(), model.getUuid()); assertNotNull("Permissions field was not set in the rest response.", model.getPermissions()); if (node instanceof EditorTrackingVertex) { assertNotNull("Editor field was not set in the rest response.", model.getEditor()); EditorTrackingVertex editedNode = (EditorTrackingVertex) node; assertNotNull("The editor of the graph node was not set.", editedNode.getEditor()); assertEquals(editedNode.getEditor().getFirstname(), model.getEditor()); assertEquals(editedNode.getEditor().getLastname(), model.getEditor().getLastName()); assertEquals(editedNode.getEditor().getUuid(), model.getEditor().getUuid()); } if (node instanceof CreatorTrackingVertex && ((CreatorTrackingVertex) node).getCreator() != null) { assertNotNull("Creator field was not set in the rest response.", model.getCreator()); CreatorTrackingVertex createdNode = (CreatorTrackingVertex) node; assertEquals(createdNode.getCreator().getFirstname(), model.getCreator().getFirstName()); assertEquals(createdNode.getCreator().getLastname(), model.getCreator().getLastName()); assertEquals(createdNode.getCreator().getUuid(), model.getCreator().getUuid()); } } }
public void assertGenericNode(MeshCoreVertex<?, ?> node, AbstractGenericRestResponse model) { assertNotNull(node); assertNotNull(model); assertNotNull("UUID field was not set in the rest response.", model.getUuid()); assertEquals("The uuids should not be different", node.getUuid(), model.getUuid()); assertNotNull("Permissions field was not set in the rest response.", model.getPermissions()); assertNotNull("Creator field was not set in the rest response.", model.getCreator()); assertNotNull("Editor field was not set in the rest response.", model.getEditor()); if (node instanceof EditorTrackingVertex) { EditorTrackingVertex editedNode = (EditorTrackingVertex) node; assertNotNull("The editor of the graph node was not set.", editedNode.getEditor()); assertEquals(editedNode.getEditor().getFirstname(), model.getEditor().getFirstName()); assertEquals(editedNode.getEditor().getLastname(), model.getEditor().getLastName()); assertEquals(editedNode.getEditor().getUuid(), model.getEditor().getUuid()); } if (node instanceof CreatorTrackingVertex) { CreatorTrackingVertex createdNode = (CreatorTrackingVertex) node; assertEquals(createdNode.getCreator().getFirstname(), model.getCreator().getFirstName()); assertEquals(createdNode.getCreator().getLastname(), model.getCreator().getLastName()); assertEquals(createdNode.getCreator().getUuid(), model.getCreator().getUuid()); } } }