[ADF-5582] Fix avatar rendering logic in adf-node-comments (#10995)

* [ADF-5582] Update NodeCommentsService to take userId as an argument in getUserImage

* [ADF-5582] Add unit tests for avatar caching and retrieval in NodeCommentsService

* Refactor NodeCommentsService unit tests to avoid accessing private members

* [ADF-5582] Remove picture Id from getUserImage

* [ADF-5582] Add comment to getAvatarCache and fix sonarcloud issues

* Update node-comments.service.spec.ts

* Trigger sonar

* [ADF-5582] Add method to return avatar url in people api

* [ADF-5582] Fix sonar cloud issue

* [ADF-5582] Add comment to getUserImage and fix request address for getAvatarImageUrl
This commit is contained in:
Shivangi Shree
2025-08-05 16:54:58 +05:30
committed by GitHub
parent 8ef0aee768
commit 9a0b75caa1
5 changed files with 88 additions and 21 deletions

View File

@@ -282,6 +282,21 @@ export class PeopleApi extends BaseApi {
});
}
/**
* Get avatar image URL
*
* Builds and returns the direct URL to fetch the avatar image for the person `personId`.
* This includes the current authentication ticket in the URL to allow secure access.
*
* You can use the `-me-` string in place of <personId> to specify the currently authenticated user.
* @param personId The identifier of a person.
* @returns A string URL to the user's avatar image.
*/
getAvatarImageUrl(personId: string): string {
const ticket = this.alfrescoApi.contentClient.getAlfTicket(undefined);
return `${this.apiClient.basePath}/people/${personId}/avatar?placeholder=true${ticket}`;
}
/**
* Update person
*

View File

@@ -2,17 +2,18 @@
All URIs are relative to *https://localhost/alfresco/api/-default-/public/alfresco/versions/1*
| Method | HTTP request | Description |
|-----------------------------------------------|----------------------------------------------------|------------------------|
| [createPerson](#createPerson) | **POST** /people | Create person |
| [deleteAvatarImage](#deleteAvatarImage) | **DELETE** /people/{personId}/avatar | Delete avatar image |
| [getAvatarImage](#getAvatarImage) | **GET** /people/{personId}/avatar | Get avatar image |
| [getPerson](#getPerson) | **GET** /people/{personId} | Get a person |
| [listPeople](#listPeople) | **GET** /people | List people |
| [requestPasswordReset](#requestPasswordReset) | **POST** /people/{personId}/request-password-reset | Request password reset |
| [resetPassword](#resetPassword) | **POST** /people/{personId}/reset-password | Reset password |
| [updateAvatarImage](#updateAvatarImage) | **PUT** /people/{personId}/avatar | Update avatar image |
| [updatePerson](#updatePerson) | **PUT** /people/{personId} | Update person |
| Method | HTTP request | Description |
|-----------------------------------------------|----------------------------------------------------|-------------------------|
| [createPerson](#createPerson) | **POST** /people | Create person |
| [deleteAvatarImage](#deleteAvatarImage) | **DELETE** /people/{personId}/avatar | Delete avatar image |
| [getAvatarImage](#getAvatarImage) | **GET** /people/{personId}/avatar | Get avatar image |
| [getPerson](#getPerson) | **GET** /people/{personId} | Get a person |
| [listPeople](#listPeople) | **GET** /people | List people |
| [requestPasswordReset](#requestPasswordReset) | **POST** /people/{personId}/request-password-reset | Request password reset |
| [resetPassword](#resetPassword) | **POST** /people/{personId}/reset-password | Reset password |
| [updateAvatarImage](#updateAvatarImage) | **PUT** /people/{personId}/avatar | Update avatar image |
| [getAvatarImageUrl](#getAvatarImageUrl) | **GET** /people/{personId}/avatar?placeholder=true | Returns avatar image url|
| [updatePerson](#updatePerson) | **PUT** /people/{personId} | Update person |
## createPerson
@@ -323,6 +324,35 @@ peopleApi.updateAvatarImage(`<personId>`, contentBodyUpdate).then(() => {
});
```
## getAvatarImageUrl
Returns the direct URL to the avatar image of the specified person.
> this is a local utility method that builds a direct URL to the avatar image, including the current authentication ticket to allow secure access.
> it does not make a network request — it only returns the constructed URL.
You can use the -me- string in place of <personId> to specify the currently authenticated user.
This method is useful for displaying profile images using direct <img> tags or background image URLs.
**Parameters**
| Name | Type | Description |
| ------------ | ------ | --------------------------- |
| **personId** | string | The identifier of a person. |
**Example**
```javascript
import { AlfrescoApi, PeopleApi } from '@alfresco/js-api';
const alfrescoApi = new AlfrescoApi(/*..*/);
const peopleApi = new PeopleApi(alfrescoApi);
const avatarUrl = peopleApi.getAvatarImageUrl('<personId>');
console.log('Avatar URL:', avatarUrl);
```
## updatePerson
Update the given person's details.