From ec86c409fdd096aa41a3f15539ea0d601c1d377f Mon Sep 17 00:00:00 2001 From: Jonathan Date: Wed, 26 Feb 2025 17:23:26 -0600 Subject: [PATCH] #31486 adding the locked by property (#31487) Adding the locked by property to content resource --- .../strategy/DefaultTransformStrategy.java | 7 ++ .../ContentResourceV1.postman_collection.json | 118 +++++++++++++++++- 2 files changed, 124 insertions(+), 1 deletion(-) diff --git a/dotCMS/src/main/java/com/dotmarketing/portlets/contentlet/transform/strategy/DefaultTransformStrategy.java b/dotCMS/src/main/java/com/dotmarketing/portlets/contentlet/transform/strategy/DefaultTransformStrategy.java index ccbae86f61cf..0aa532227355 100644 --- a/dotCMS/src/main/java/com/dotmarketing/portlets/contentlet/transform/strategy/DefaultTransformStrategy.java +++ b/dotCMS/src/main/java/com/dotmarketing/portlets/contentlet/transform/strategy/DefaultTransformStrategy.java @@ -403,6 +403,13 @@ private void addVersionProperties(final Contentlet contentlet, final Map lockedByOpt = Try.of(()->toolBox.versionableAPI.getLockedBy(contentlet)).getOrElse(Optional.empty()); + if (lockedByOpt.isPresent()) { + + final User user = toolBox.userAPI.loadUserById(lockedByOpt.get()); + map.put("lockedBy", Map.of("userId", user.getUserId(), + "firstName", user.getFirstName(), "lastName", user.getLastName())); + } final Optional versionInfo = APILocator.getVersionableAPI().getContentletVersionInfo( diff --git a/dotcms-postman/src/main/resources/postman/ContentResourceV1.postman_collection.json b/dotcms-postman/src/main/resources/postman/ContentResourceV1.postman_collection.json index e5bf5a4390f7..3a13d4742a1c 100644 --- a/dotcms-postman/src/main/resources/postman/ContentResourceV1.postman_collection.json +++ b/dotcms-postman/src/main/resources/postman/ContentResourceV1.postman_collection.json @@ -1,6 +1,6 @@ { "info": { - "_postman_id": "3a7f408a-7661-4715-8cf8-35f9305b3f73", + "_postman_id": "15e5191d-c7ec-4e91-aded-f855ce7d4f00", "name": "ContentResourceV1", "description": "This folder contains a comprehensive set of API requests related to the `ContentResourceV1` API endpoints. These requests cover various operations such as creating, retrieving and updating content. The folder is organized to help developers and testers efficiently validate and interact with the content resource endpoints in the system.\n\n#### Objectives:\n\n1. **Create Content**:\n \n - Test the creation of new content items with valid and invalid data.\n \n - Ensure that the response includes all necessary details for the created content.\n \n2. **Retrieve Content**:\n \n - Validate the retrieval of content items by ID.\n \n - Ensure the response contains accurate and complete content details.\n \n3. **Update Content**:\n \n - Test updating existing content items with valid and invalid data.\n \n - Verify that the response reflects the updated content accurately.\n \n - Ensure that only authorized users can update content.\n \n4. **Error Handling**:\n \n - Verify that the API returns appropriate error messages for invalid requests.\n \n - Ensure the correct HTTP status codes are used for different error scenarios.\n \n5. **Security**:\n \n - Validate that only authorized users can perform operations on the content.\n \n - Ensure that all security protocols are enforced during API interactions.", "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json", @@ -2881,6 +2881,60 @@ }, "response": [] }, + { + "name": "GetContentlet", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "let id = pm.collectionVariables.get('contentletIdentifier');", + "const responseJson = pm.response.json();", + "", + "pm.test(\"Valid response\", function () {", + " pm.response.to.have.status(200);", + " pm.expect(responseJson.entity.identifier).to.eql(id);", + " pm.expect(responseJson.entity.locked).to.eql(true);", + " pm.expect(responseJson.entity.lockedBy.firstName).to.eql(\"Admin\");", + " pm.expect(responseJson.entity.lockedBy.userId).to.eql(\"dotcms.org.1\");", + "});", + "", + "", + "" + ], + "type": "text/javascript", + "packages": {} + } + } + ], + "request": { + "auth": { + "type": "bearer", + "bearer": [ + { + "key": "token", + "value": "{{jwt}}", + "type": "string" + } + ] + }, + "method": "GET", + "header": [], + "url": { + "raw": "{{serverURL}}/api/v1/content/{{contentletIdentifier}}", + "host": [ + "{{serverURL}}" + ], + "path": [ + "api", + "v1", + "content", + "{{contentletIdentifier}}" + ] + } + }, + "response": [] + }, { "name": "Unlock", "event": [ @@ -2987,6 +3041,68 @@ }, "response": [] } + ], + "event": [ + { + "listen": "prerequest", + "script": { + "type": "text/javascript", + "packages": {}, + "exec": [ + "if (!pm.environment.get('jwt')) {", + " console.log(\"generating....\")", + " const serverURL = pm.environment.get('serverURL'); // Get the server URL from the environment variable", + " const apiUrl = `${serverURL}/api/v1/apitoken`; // Construct the full API URL", + "", + " if (!pm.environment.get('jwt')) {", + " const username = pm.environment.get(\"user\");", + " const password = pm.environment.get(\"password\");", + " const basicAuth = Buffer.from(`${username}:${password}`).toString('base64');", + "", + " const requestOptions = {", + " url: apiUrl,", + " method: \"POST\",", + " header: {", + " \"accept\": \"*/*\",", + " \"content-type\": \"application/json\",", + " \"Authorization\": `Basic ${basicAuth}`", + " },", + " body: {", + " mode: \"raw\",", + " raw: JSON.stringify({", + " \"expirationSeconds\": 7200,", + " \"userId\": \"dotcms.org.1\",", + " \"network\": \"0.0.0.0/0\",", + " \"claims\": {\"label\": \"postman-tests\"}", + " })", + " }", + " };", + "", + " pm.sendRequest(requestOptions, function (err, response) {", + " if (err) {", + " console.log(err);", + " } else {", + " const jwt = response.json().entity.jwt;", + " pm.environment.set('jwt', jwt);", + " console.log(jwt);", + " }", + " });", + " }", + "}", + "" + ] + } + }, + { + "listen": "test", + "script": { + "type": "text/javascript", + "packages": {}, + "exec": [ + "" + ] + } + } ] } ],