Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,13 @@ export abstract class BaseDetailComponent<Entity extends { id: string; updatedAt
}
}

protected getCustomFieldConfig(key: Exclude<keyof CustomFields, '__typename'>): CustomFieldConfig[] {
protected getCustomFieldConfig(
key: Exclude<keyof CustomFields, '__typename'>,
isOwner = false,
): CustomFieldConfig[] {
Comment on lines +153 to +156
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function gets called for basically all detail components, so changing the function signature for one single case makes me think twice. I only looked at it briefly so I dont have a better solution right now and you might be totally right, but I think having a closer look at the root cause might be worth it.

In any way, thanks for making a PR!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right that this is just for one case but I couldn't find any other way the admin-ui knows what entities "belong" to the active user. I think this is the most straightforward solution without implementing that belonging logic in the admin-ui that I could think of.

return this.serverConfigService.getCustomFieldsFor(key).filter(f => {
if (f.requiresPermission?.length) {
return this.permissionsService.userHasPermissions(f.requiresPermission);
return this.permissionsService.userHasPermissions(f.requiresPermission, isOwner);
}
return true;
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ export class PermissionsService {
this._currentUserPermissions$.next(permissions);
}

userHasPermissions(requiredPermissions: Array<string | Permission>): boolean {
userHasPermissions(requiredPermissions: Array<string | Permission>, isOwner = false): boolean {
for (const perm of requiredPermissions) {
if (this.currentUserPermissions.includes(perm)) {
if (this.currentUserPermissions.includes(perm) || (perm === Permission.Owner && isOwner)) {
return true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@ export const GET_PROFILE_DETAIL = gql`
templateUrl: './profile.component.html',
styleUrls: ['./profile.component.scss'],
changeDetection: ChangeDetectionStrategy.OnPush,
standalone: false
standalone: false,
})
export class ProfileComponent
extends TypedBaseDetailComponent<typeof GetProfileDetailDocument, 'activeAdministrator'>
implements OnInit, OnDestroy
{
customFields = this.getCustomFieldConfig('Administrator');
customFields = this.getCustomFieldConfig('Administrator', true);
detailForm = this.formBuilder.group({
emailAddress: ['', Validators.required],
firstName: ['', Validators.required],
Expand Down
Loading