Code Monkey home page Code Monkey logo

ngx-access's Issues

feat: set access configuration using AccessService

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 {}

feat: add implicit parent control access

<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.

Evaluate expression with AND/OR operators and parenthesis

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();
      });
  });

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.