diff --git a/docs/content-services/services/node-comments.service.md b/docs/content-services/services/node-comments.service.md index 1ee7e19ce0..fcedc64f40 100644 --- a/docs/content-services/services/node-comments.service.md +++ b/docs/content-services/services/node-comments.service.md @@ -20,7 +20,7 @@ Adds and retrieves comments for nodes in Content Services. Gets all comments that have been added to a task. - _id:_ `string` - ID of the target task - **Returns** [`Observable`](http://reactivex.io/documentation/observable.html)`<`[`CommentModel`](../../../lib/core/src/lib/models/comment.model.ts)`[]>` - Details for each comment -- **getUserImage**(avatarId: `string`): `string`
- Gets the URL for the user's profile image. - - _avatarId:_ `string` - ID of the user - - **Returns** `string` - URL for the user's profile image +- **getUserImage**(userId: `string`): `string`
+ Returns the avatar URL for the specified user. + - _userId:_ `string` - ID of the user + - **Returns** `string` - URL of the user's avatar image diff --git a/lib/content-services/src/lib/node-comments/services/node-comments.service.spec.ts b/lib/content-services/src/lib/node-comments/services/node-comments.service.spec.ts index cf22e702aa..a03eedfec6 100644 --- a/lib/content-services/src/lib/node-comments/services/node-comments.service.spec.ts +++ b/lib/content-services/src/lib/node-comments/services/node-comments.service.spec.ts @@ -38,7 +38,6 @@ describe('NodeCommentsService', () => { ] }); service = TestBed.inject(NodeCommentsService); - jasmine.Ajax.install(); }); @@ -81,5 +80,17 @@ describe('NodeCommentsService', () => { responseText: JSON.stringify(fakeContentComments) }); }); + + it('should return avatar image URL for given userId', () => { + const userId = 'fake-user-id'; + const expectedUrl = 'https://fake-avatar-url.com/avatar.png'; + + spyOn(service.peopleApi, 'getAvatarImageUrl').and.returnValue(expectedUrl); + + const result = service.getUserImage(userId); + + expect(service.peopleApi.getAvatarImageUrl).toHaveBeenCalledWith(userId); + expect(result).toBe(expectedUrl); + }); }); }); diff --git a/lib/content-services/src/lib/node-comments/services/node-comments.service.ts b/lib/content-services/src/lib/node-comments/services/node-comments.service.ts index 26e8f6131d..1a24590db2 100644 --- a/lib/content-services/src/lib/node-comments/services/node-comments.service.ts +++ b/lib/content-services/src/lib/node-comments/services/node-comments.service.ts @@ -16,11 +16,10 @@ */ import { CommentModel, CommentsService, User } from '@alfresco/adf-core'; -import { CommentEntry, CommentsApi, Comment } from '@alfresco/js-api'; +import { CommentEntry, CommentsApi, Comment, PeopleApi } from '@alfresco/js-api'; import { Injectable } from '@angular/core'; import { Observable, from } from 'rxjs'; import { map } from 'rxjs/operators'; -import { ContentService } from '../../common/services/content.service'; import { AlfrescoApiService } from '../../services/alfresco-api.service'; @Injectable({ @@ -33,7 +32,13 @@ export class NodeCommentsService implements CommentsService { return this._commentsApi; } - constructor(private apiService: AlfrescoApiService, private contentService: ContentService) {} + private _peopleApi: PeopleApi; + get peopleApi(): PeopleApi { + this._peopleApi = this._peopleApi ?? new PeopleApi(this.apiService.getInstance()); + return this._peopleApi; + } + + constructor(private readonly apiService: AlfrescoApiService) {} /** * Gets all comments that have been added to a task. @@ -81,7 +86,13 @@ export class NodeCommentsService implements CommentsService { }); } - getUserImage(avatarId: string): string { - return this.contentService.getContentUrl(avatarId); + /** + * Gets the avatar image URL for a given user ID. + * + * @param userId ID of the user + * @returns The URL of the user's avatar image + */ + getUserImage(userId: string): string { + return this.peopleApi.getAvatarImageUrl(userId); } } diff --git a/lib/js-api/src/api/content-rest-api/api/people.api.ts b/lib/js-api/src/api/content-rest-api/api/people.api.ts index 523fcd5f1c..bf48d7676d 100644 --- a/lib/js-api/src/api/content-rest-api/api/people.api.ts +++ b/lib/js-api/src/api/content-rest-api/api/people.api.ts @@ -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 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 * diff --git a/lib/js-api/src/api/content-rest-api/docs/PeopleApi.md b/lib/js-api/src/api/content-rest-api/docs/PeopleApi.md index 3532544900..989d15821f 100644 --- a/lib/js-api/src/api/content-rest-api/docs/PeopleApi.md +++ b/lib/js-api/src/api/content-rest-api/docs/PeopleApi.md @@ -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(``, 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 to specify the currently authenticated user. + +This method is useful for displaying profile images using direct 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(''); +console.log('Avatar URL:', avatarUrl); +``` + ## updatePerson Update the given person's details.