Hi Team,
In the application we have multiple components at UI level and respective API/app services (where the services can be restricted at the permission level). But we are looking for solution/approach where the permission/feature where it can be applied at the login time of the user and based on that it can be restrict to the specific components.
Thanks
1 Answer(s)
-
0
Hi,
If I understood correctly, you're looking for a way to check the user's permissions (or features), and based on that, control which UI components should be visible or accessible. Is that right?
If so, here's a common and recommended approach:
For menu items:
{ path: '/authors', name: '::Menu:Authors', parentName: '::Menu:BookStore', layout: eLayoutType.application, requiredPolicy: 'BookStore.Authors', }
For UI components:
<button *abpPermission="'BookStore.Authors.Create'" id="create" class="btn btn-primary" type="button" (click)="createAuthor()"> <i class="fa fa-plus me-1"></i> <span>{{ '::NewAuthor' | abpLocalization }}</span> </button>
If you want to check whether a specific feature is enabled or disabled and render something accordingly, you can check this document.
For AppService methods:
[Authorize(BookStorePermissions.Authors.Delete)] public async Task DeleteAsync(Guid id) { //continue to the normal flow... }
or
public async Task CreateAsync(CreateAuthorDto input) { var result = await AuthorizationService .AuthorizeAsync("Author_Management_Create_Books"); if (result.Succeeded == false) { //throw exception throw new AbpAuthorizationException("..."); } //continue to the normal flow... }
If I misunderstood your question or you're trying to do something else, feel free to give a bit more detail.