Skip to content

Commit

Permalink
feat: show functions on resourcetype
Browse files Browse the repository at this point in the history
  • Loading branch information
StephGit committed Dec 24, 2024
1 parent 2649d0d commit 8399710
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 45 deletions.
9 changes: 7 additions & 2 deletions AMW_angular/io/src/app/auth/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,16 @@ export class AuthService extends BaseService {
);
}

hasResourceTypePermission(permissionName: string, action: string, resourceType: string): boolean {
hasResourceTypePermission(permissionName: string, action: string, resourceTypeName: string): boolean {
return (
this.restrictions()
.filter((entry) => entry.permission.name === permissionName)
.filter((entry) => entry.resourceTypeName === resourceType || this.isDefaultType(entry, resourceType))
.filter(
(entry) =>
entry.resourceTypeName === resourceTypeName ||
this.isDefaultType(entry, resourceTypeName) ||
entry.resourceTypeName === null,
)
.map((entry) => entry.action)
.find((entry) => entry === Action.ALL || entry === action) !== undefined
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,6 @@ export class ResourceEditFunctionsComponent {
}
});

// then for editmodal it's read or edit

functionsData = computed(() => {
if (this.functions()?.length > 0) {
const [instance, resource] = this.splitFunctions(this.functions());
Expand All @@ -71,15 +69,15 @@ export class ResourceEditFunctionsComponent {
result.push({
title: 'Resource Instance Functions',
entries: instance,
canEdit: this.permissions().canEdit,
canEdit: this.permissions().canEdit || this.permissions().canShowInstanceFunctions, // fixme old gui used the `Edit`-link also for only viewing a function
canDelete: this.permissions().canDelete,
});
}
if (this.permissions().canShowSuperTypeFunctions) {
result.push({
title: 'Resource Type Functions',
entries: resource,
canOverwrite: this.permissions().canEdit,
canOverwrite: this.permissions().canEdit || this.permissions().canShowInstanceFunctions, // fixme old gui used the `Edit`-link also for only viewing a function
});
}
return result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,16 @@
Loaded resource:
{{ this.resource()?.name }}
</div>
<div>
<app-tile-component
[title]="'Templates'"
[actionName]="'New Template'"
[canAction]="true"
[isVisible]="false"
[lists]="templatesData()"
(tileAction)="add()"
(listAction)="doListAction($event)"
></app-tile-component>
<app-resources-edit-functions [resource]="resource()" [contextId]="contextId()"></app-resources-edit-functions>
</div>
<app-tile-component
[title]="'Templates'"
[actionName]="'New Template'"
[canAction]="true"
[isVisible]="false"
[lists]="templatesData()"
(tileAction)="add()"
(listAction)="doListAction($event)"
></app-tile-component>
<app-resources-edit-functions [resource]="resource()" [contextId]="contextId()"></app-resources-edit-functions>
}
</div>
</app-page>
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@ export class ResourceFunctionsService extends BaseService {
shareReplay(1),
);

private functionByTypeId$: Observable<ResourceFunction[]> = this.functions$.pipe(
private functionByTypeId$: Observable<ResourceFunction[]> = this.functionsForType$.pipe(
switchMap((id: number) => this.getResourceTypeFunctions(id)),
shareReplay(1),
);

functions = toSignal(this.functionById$, { initialValue: [] });
functionsForType = toSignal(this.functionByTypeId$, { initialValue: [] });

constructor(private http: HttpClient) {
super();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import { ResourceFunctionsService } from '../../resource-functions.service';
import { ResourceFunction } from '../../resource-function';
import { ResourceType } from '../../../resource/resource-type';

const RESOURCE_PERM = 'RESOURCE_AMWFUNCTION';
const RESOURCETYPE_PERM = 'RESOURCETYPE_AMWFUNCTION';

@Component({
Expand All @@ -26,7 +25,7 @@ export class ResourceTypeEditFunctionsComponent {

resourceType = input.required<ResourceType>();
contextId = input.required<number>();
functions = this.functionsService.functions;
functions = this.functionsService.functionsForType;

isLoading = computed(() => {
if (this.resourceType() != null) {
Expand All @@ -36,10 +35,9 @@ export class ResourceTypeEditFunctionsComponent {
});

permissions = computed(() => {
if (this.authService.restrictions().length > 0) {
if (this.authService.restrictions().length > 0 && this.resourceType()) {
return {
canShowInstanceFunctions: this.authService.hasPermission(RESOURCE_PERM, Action.READ),
canShowSuperTypeFunctions: this.authService.hasPermission(RESOURCETYPE_PERM, Action.READ),
canShowInstanceFunctions: this.authService.hasPermission(RESOURCETYPE_PERM, Action.READ),
canAdd:
(this.contextId() === 1 || this.contextId === null) &&
this.authService.hasResourceTypePermission(RESOURCETYPE_PERM, Action.CREATE, this.resourceType().name),
Expand All @@ -53,7 +51,6 @@ export class ResourceTypeEditFunctionsComponent {
} else {
return {
canShowInstanceFunctions: false,
canShowSuperTypeFunctions: false,
canAdd: false,
canEdit: false,
canDelete: false,
Expand All @@ -63,12 +60,16 @@ export class ResourceTypeEditFunctionsComponent {

functionsData = computed(() => {
if (this.functions()?.length > 0) {
if (this.permissions().canShowSuperTypeFunctions) {
return {
title: 'Type Functions',
entries: this.mapListEntries(this.functions()),
canOverwrite: this.permissions().canEdit,
};
if (this.permissions().canShowInstanceFunctions) {
const entries = this.mapListEntries(this.functions());
return [
{
title: 'Type Functions',
entries: entries,
canEdit: this.permissions().canEdit || this.permissions().canShowInstanceFunctions, // fixme old gui used the `Edit`-link also for only viewing a function
canDelete: this.permissions().canDelete,
},
];
} else return null;
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,19 @@
Loaded resourceType:
{{ this.resourceType()?.name }}
</div>
<div>
<app-tile-component
[title]="'Templates'"
[actionName]="'New Template'"
[canAction]="true"
[isVisible]="false"
[lists]="templatesData()"
(tileAction)="add()"
(listAction)="doListAction($event)"
></app-tile-component>
</div>
<app-tile-component
[title]="'Templates'"
[actionName]="'New Template'"
[canAction]="true"
[isVisible]="false"
[lists]="templatesData()"
(tileAction)="add()"
(listAction)="doListAction($event)"
></app-tile-component>
<app-resource-type-edit-functions
[resourceType]="resourceType()"
[contextId]="contextId()"
></app-resource-type-edit-functions>
}
</div>
</app-page>
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,25 @@ import { PageComponent } from '../../layout/page/page.component';
import { ActivatedRoute } from '@angular/router';
import { map } from 'rxjs/operators';
import { toSignal } from '@angular/core/rxjs-interop';
import { ResourceService } from '../../resource/resource.service';
import { Resource } from '../../resource/resource';
import { EntryAction, TileListEntry, TileListEntryOutput } from '../../shared/tile/tile-list/tile-list.component';
import { NgbModal } from '@ng-bootstrap/ng-bootstrap';
import { TileComponent } from '../../shared/tile/tile.component';
import { AuthService } from '../../auth/auth.service';
import { ResourceType } from '../../resource/resource-type';
import { ResourceTypesService } from '../../resource/resource-types.service';
import { ResourceEditFunctionsComponent } from '../resource-edit-page/resource-edit-functions/resource-edit-functions.component';
import { ResourceTypeEditFunctionsComponent } from './resource-type-edit-functions/resource-type-edit-functions.component';

@Component({
selector: 'app-resource-type-edit-page',
standalone: true,
imports: [LoadingIndicatorComponent, PageComponent, TileComponent],
imports: [
LoadingIndicatorComponent,
PageComponent,
TileComponent,
ResourceEditFunctionsComponent,
ResourceTypeEditFunctionsComponent,
],
templateUrl: './resource-type-edit-page.component.html',
})
export class ResourceTypeEditPageComponent {
Expand Down

0 comments on commit 8399710

Please sign in to comment.