mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-09-17 14:21:29 +00:00
[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:
@@ -20,7 +20,7 @@ Adds and retrieves comments for nodes in Content Services.
|
|||||||
Gets all comments that have been added to a task.
|
Gets all comments that have been added to a task.
|
||||||
- _id:_ `string` - ID of the target 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
|
- **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`<br/>
|
- **getUserImage**(userId: `string`): `string`<br/>
|
||||||
Gets the URL for the user's profile image.
|
Returns the avatar URL for the specified user.
|
||||||
- _avatarId:_ `string` - ID of the user
|
- _userId:_ `string` - ID of the user
|
||||||
- **Returns** `string` - URL for the user's profile image
|
- **Returns** `string` - URL of the user's avatar image
|
||||||
|
@@ -38,7 +38,6 @@ describe('NodeCommentsService', () => {
|
|||||||
]
|
]
|
||||||
});
|
});
|
||||||
service = TestBed.inject(NodeCommentsService);
|
service = TestBed.inject(NodeCommentsService);
|
||||||
|
|
||||||
jasmine.Ajax.install();
|
jasmine.Ajax.install();
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -81,5 +80,17 @@ describe('NodeCommentsService', () => {
|
|||||||
responseText: JSON.stringify(fakeContentComments)
|
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);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@@ -16,11 +16,10 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { CommentModel, CommentsService, User } from '@alfresco/adf-core';
|
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 { Injectable } from '@angular/core';
|
||||||
import { Observable, from } from 'rxjs';
|
import { Observable, from } from 'rxjs';
|
||||||
import { map } from 'rxjs/operators';
|
import { map } from 'rxjs/operators';
|
||||||
import { ContentService } from '../../common/services/content.service';
|
|
||||||
import { AlfrescoApiService } from '../../services/alfresco-api.service';
|
import { AlfrescoApiService } from '../../services/alfresco-api.service';
|
||||||
|
|
||||||
@Injectable({
|
@Injectable({
|
||||||
@@ -33,7 +32,13 @@ export class NodeCommentsService implements CommentsService {
|
|||||||
return this._commentsApi;
|
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.
|
* 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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -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
|
* Update person
|
||||||
*
|
*
|
||||||
|
@@ -2,17 +2,18 @@
|
|||||||
|
|
||||||
All URIs are relative to *https://localhost/alfresco/api/-default-/public/alfresco/versions/1*
|
All URIs are relative to *https://localhost/alfresco/api/-default-/public/alfresco/versions/1*
|
||||||
|
|
||||||
| Method | HTTP request | Description |
|
| Method | HTTP request | Description |
|
||||||
|-----------------------------------------------|----------------------------------------------------|------------------------|
|
|-----------------------------------------------|----------------------------------------------------|-------------------------|
|
||||||
| [createPerson](#createPerson) | **POST** /people | Create person |
|
| [createPerson](#createPerson) | **POST** /people | Create person |
|
||||||
| [deleteAvatarImage](#deleteAvatarImage) | **DELETE** /people/{personId}/avatar | Delete avatar image |
|
| [deleteAvatarImage](#deleteAvatarImage) | **DELETE** /people/{personId}/avatar | Delete avatar image |
|
||||||
| [getAvatarImage](#getAvatarImage) | **GET** /people/{personId}/avatar | Get avatar image |
|
| [getAvatarImage](#getAvatarImage) | **GET** /people/{personId}/avatar | Get avatar image |
|
||||||
| [getPerson](#getPerson) | **GET** /people/{personId} | Get a person |
|
| [getPerson](#getPerson) | **GET** /people/{personId} | Get a person |
|
||||||
| [listPeople](#listPeople) | **GET** /people | List people |
|
| [listPeople](#listPeople) | **GET** /people | List people |
|
||||||
| [requestPasswordReset](#requestPasswordReset) | **POST** /people/{personId}/request-password-reset | Request password reset |
|
| [requestPasswordReset](#requestPasswordReset) | **POST** /people/{personId}/request-password-reset | Request password reset |
|
||||||
| [resetPassword](#resetPassword) | **POST** /people/{personId}/reset-password | Reset password |
|
| [resetPassword](#resetPassword) | **POST** /people/{personId}/reset-password | Reset password |
|
||||||
| [updateAvatarImage](#updateAvatarImage) | **PUT** /people/{personId}/avatar | Update avatar image |
|
| [updateAvatarImage](#updateAvatarImage) | **PUT** /people/{personId}/avatar | Update avatar image |
|
||||||
| [updatePerson](#updatePerson) | **PUT** /people/{personId} | Update person |
|
| [getAvatarImageUrl](#getAvatarImageUrl) | **GET** /people/{personId}/avatar?placeholder=true | Returns avatar image url|
|
||||||
|
| [updatePerson](#updatePerson) | **PUT** /people/{personId} | Update person |
|
||||||
|
|
||||||
## createPerson
|
## 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
|
## updatePerson
|
||||||
|
|
||||||
Update the given person's details.
|
Update the given person's details.
|
||||||
|
Reference in New Issue
Block a user