chihab / ngx-access Goto Github PK
View Code? Open in Web Editor NEWAdd access control to your components using hierarchical configuration with logical expressions.
Add access control to your components using hierarchical configuration with logical expressions.
Add the ability to configure the access control outside Module definition
import access from "./src/assets/access.json";
import { APP_INITIALIZER } from "@angular/core";
export function loadServerConfiguration(
accessService: AccessService,
http: HttpClient
) {
this.http.get<AccessModuleConfiguration>("/configuration").pipe(
tap((configuration) => accessService.setConfiguration(configuration)), // <----
catchError((e) => accessService.setConfiguration({}))
);
}
@NgModule({
providers: [
{
provide: APP_INITIALIZER,
useFactory: loadServerConfiguration,
deps: [AccessService, HttpClient],
multi: true,
},
],
})
export class AppModule {}
Use logical expression on your access paths
<app-user *ngxAccess="'User:Update' | 'User:Read'"></app-user>
<form *ngxAccess>
<h1>Update User Form</h1>
<input *ngxAccess="'CanUpdateUserAvatar'" />
<input *ngxAccess="'CanUpdateUserName'" />
<input *ngxAccess="'CanUpdateUserAge'" />
<input *ngxAccess="'CanUpdateUserPassword'" />
</form>
The form
(including h1
) will be displayed only if the user has one of the accesses in the inputs beneath.
Trigger npm packaging and publishing on PR merge.
Right now only "AND" logical operator is accepted on access expression. OR operator and parenthesis are not yet supported.
it('should evaluate expression with AND, OR operator combination and parenthesis', (done: DoneFn) => {
setConfigurationAccess({
View: {
Resource1: {
Read: 'Read1 OR Read2'
},
Resource2: {
Read: 'ReadResource2 AND (Read3 OR Read4)'
}
}
});
hasAccessStrategy.and.callFake((access) => {
const userAccesses = ['ReadAccess', 'Read3'];
return of(
userAccesses.findIndex(a => a === access) !== -1
);
});
canExpression('View:Read')
.subscribe(value => {
expect(value).toBe(true);
expect(hasAccessStrategy).toHaveBeenCalledWith('Read1');
expect(hasAccessStrategy).toHaveBeenCalledWith('Read2');
expect(hasAccessStrategy).toHaveBeenCalledWith('ReadResource2');
expect(hasAccessStrategy).toHaveBeenCalledWith('Read3');
expect(hasAccessStrategy).toHaveBeenCalledWith('Read4');
done();
});
});
Test out https://github.com/ngworker/angular-versions-action
- name: Use Angular ${{ matrix.angular-version }}
uses: ngworker/angular-versions-action@v1
with:
angular-version: ${{ matrix.angular-version }}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.