[MNT-25185] Display authority name instead of id if provided (#11809)

* [MNT-25185] Display authority name instead of id if provided

* [MNT-25185] CR fixes
This commit is contained in:
Michal Kinas
2026-04-15 10:12:04 +02:00
committed by GitHub
parent 8a6bcac29e
commit 32850a0ce8
3 changed files with 32 additions and 12 deletions
@@ -18,11 +18,12 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { UserNameColumnComponent } from './user-name-column.component';
import { NodeEntry } from '@alfresco/js-api';
import { UnitTestingUtils } from '@alfresco/adf-core';
describe('UserNameColumnComponent', () => {
let fixture: ComponentFixture<UserNameColumnComponent>;
let component: UserNameColumnComponent;
let element: HTMLElement;
let testingUtils: UnitTestingUtils;
const person = {
firstName: 'fake',
lastName: 'user',
@@ -34,13 +35,15 @@ describe('UserNameColumnComponent', () => {
displayName: 'fake authority'
};
const getUserName = (): string => testingUtils.getInnerTextByCSS('span.adf-user-name-column');
beforeEach(() => {
TestBed.configureTestingModule({
imports: [UserNameColumnComponent]
});
fixture = TestBed.createComponent(UserNameColumnComponent);
component = fixture.componentInstance;
element = fixture.nativeElement;
testingUtils = new UnitTestingUtils(fixture.debugElement);
fixture.detectChanges();
});
@@ -55,8 +58,8 @@ describe('UserNameColumnComponent', () => {
};
component.ngOnInit();
fixture.detectChanges();
expect(element.querySelector('[title="fake user"]').textContent).toContain('fake user');
expect(element.querySelector('[title="fake@test.com"]').textContent).toContain('fake@test.com');
expect(getUserName()).toBe('fake user');
expect(testingUtils.getInnerTextByCSS('.adf-user-email-column')).toBe('fake@test.com');
});
it('should render person value from node', (done) => {
@@ -95,7 +98,7 @@ describe('UserNameColumnComponent', () => {
};
component.ngOnInit();
fixture.detectChanges();
expect(element.querySelector('[title="fake authority"]').textContent.trim()).toBe('fake authority');
expect(getUserName()).toBe('fake authority');
});
it('should display group id when display name is not provided', () => {
@@ -110,20 +113,35 @@ describe('UserNameColumnComponent', () => {
};
component.ngOnInit();
fixture.detectChanges();
expect(element.querySelector('[title="fake_group_id"]').textContent.trim()).toBe('fake_group_id');
expect(getUserName()).toBe('fake_group_id');
});
it('should render group for authorityId', () => {
it('should render group for authorityId when authorityDisplayName is not provided', () => {
component.context = {
row: {
obj: {
authorityId: 'fake-id'
authorityId: 'fake-id',
authorityDisplayName: null
}
}
};
component.ngOnInit();
fixture.detectChanges();
expect(element.querySelector('[title=fake-id]').textContent.trim()).toBe('fake-id');
expect(getUserName()).toBe('fake-id');
});
it('should render authority display name when provided', () => {
component.context = {
row: {
obj: {
authorityId: 'fake-id',
authorityDisplayName: 'Fake authority'
}
}
};
component.ngOnInit();
fixture.detectChanges();
expect(getUserName()).toBe('Fake authority');
});
it('should render person value from node', () => {
@@ -137,7 +155,7 @@ describe('UserNameColumnComponent', () => {
} as NodeEntry;
component.ngOnInit();
fixture.detectChanges();
expect(element.querySelector('[title="Fake authority"]').textContent.trim()).toBe('Fake authority');
expect(getUserName()).toBe('Fake authority');
});
});
});
@@ -52,8 +52,8 @@ export class UserNameColumnComponent implements OnInit {
ngOnInit() {
if (this.context != null) {
const { person, group, authorityId } = this.context.row.obj?.entry ?? this.context.row.obj;
const permissionGroup = authorityId ? ({ displayName: authorityId } as Group) : null;
const { person, group, authorityId, authorityDisplayName } = this.context.row.obj?.entry ?? this.context.row.obj;
const permissionGroup: Group | null = authorityId ? { displayName: authorityDisplayName, id: authorityId } : null;
this.updatePerson(person);
this.updateGroup(group || permissionGroup);
}
@@ -19,6 +19,7 @@ import { PermissionElement } from '@alfresco/js-api';
export class PermissionDisplayModel implements PermissionElement {
authorityId?: string;
authorityDisplayName?: string;
name?: string;
accessStatus?: 'ALLOWED' | 'DENIED' | string;
isInherited: boolean = false;
@@ -28,6 +29,7 @@ export class PermissionDisplayModel implements PermissionElement {
constructor(obj?: any) {
if (obj) {
this.authorityId = obj.authorityId;
this.authorityDisplayName = obj.authorityDisplayName;
this.name = obj.name;
this.accessStatus = obj.accessStatus;
this.isInherited = obj.isInherited !== null && obj.isInherited !== undefined ? obj.isInherited : false;