Open Closed

Override the Permissions grant for super User/Admin (Angular) #1936


User avatar
0
alper created
Support Team Director

We looking forward the sample code on Angular UI to override the Permissions grant for super User/Admin. We did on API side, looking for angular Sample UI.


1 Answer(s)
  • User Avatar
    0
    alper created
    Support Team Director

    On the angular side, we have a service, a guard and a directive responsible for permission management. All you need to do is to replace the service with your own. Here is how you can do it

    First, create a service of your own. Let's call it CustomPermissionService and extend PermissionService from @abp/ng.core as follows:

    import { ConfigStateService, PermissionService } from '@abp/ng.core';
    import { Injectable } from '@angular/core';
    
    @Injectable({
      providedIn: 'root',
    })
    export class CustomPermissionService extends PermissionService {
      constructor(configStateService: ConfigStateService) {
        super(configStateService);
      }
    
      getGrantedPolicy$(key: string) {
        return super.getGrantedPolicy$(key);
      }
    }
    

    And in app.module.ts, provide this service as follows:

    @NgModule({
      // ...
      providers: [
        // ...
        {
          provide: PermissionService,
          useExisting: CustomPermissionService,
        },
      ],
      // ...
    })
    export class AppModule {}
    

    That's it. Now, when a directive/guard asks for PermissionService from angular, it will inject your service.

    For more information about the PermissionService, you can examine it here. https://github.com/abpframework/abp/blob/dev/npm/ng-packs/packages/core/src/lib/services/permission.service.ts

Made with ❤️ on ABP v9.0.0-preview Updated on September 19, 2024, 10:13