108 Security: User management. Typescript classes. - chempkovsky/CS82ANGULAR GitHub Wiki

Two aspects

Security has two aspects: Authentication and Authorization

Notes

  • Before this article, we used to generate typescript classes with PhbkDbContext-Dbcontext as a Wizard's Repo.
  • In the article 012.1 we generated Auxiliary classes. All information about created object was persisted in a Wizard's Repo of PhbkDbContext
  • Now, aspnetchckdbcontext will be used to generate the Typescript code. But the aspnetchckdbcontext Repo does not contain information about the common classes that have already been created in the project.
  • Thus, our very first task is to import common classes info from PhbkDbContext-Repo in aspnetchckdbcontext-Repo.
    • There is a import common staff-button on one of the page of JavaScript Wizard. But we do not recommend to use this functionality (it's under the development).
    • Instead, we will show how to copy/paste json fragment from PhbkDbContext-Repo in aspnetchckdbcontext-Repo.

Common classes info

  • run Visual studio 2022
  • open the PhBkContext.PhBkContext.csproj.PhBkContext.Auth.aspnetchckdbcontext.json-file, which is a Repo for aspnetchckdbcontext
  • open the PhBkContext.PhBkContext.csproj.PhBkContext.PhBk.PhbkDbContext.json-file, which is a Repo for PhbkDbContext
  • Note: you will find both files in the Solution folder.
  • Format both files
    • right click editor window and select Format document-menu item
Click to show the picture

project structure

  • Select CommonStaffs-section of PhBkContext.PhBkContext.csproj.PhBkContext.PhBk.PhbkDbContext.json-file and copy into the clipboard.
Click to show the picture

project structure

  • Replace "CommonStaffs": null-line of PhBkContext.PhBkContext.csproj.PhBkContext.PhBk.PhbkDbContext.json-file with the clipboard selection.
Click to show the picture

project structure

  • save PhBkContext.PhBkContext.csproj.PhBkContext.Auth.aspnetchckdbcontext.json-file
  • close both files

Typescript classes

  • right click src/app-folder of the Angular project and select Javascript Wizard-menu item
  • on the first page click next-button
  • on the second page
    • select PhBkContext.csproj-project
    • select aspnetchckdbcontext-Dbcontext
    • click next-button
  • on the third page
    • select aspnetmodelView in the combo
    • click next-button
  • on the fourth page
    • click batch processing-button
      • Batch actions dialog will be shown
  • on Batch actions dialog run the scripts:
    • 02040-AspNetAllInterfacesBatch.json
    • 02041-AspNetAllWebApiServicesBatch.json
    • 02042-AspNetAllSFormsBatch.json
    • 02043-AspNetAllVformsBatch.json
    • 02044-AspNetAllAformsBatch.json
    • 02044-AspNetAllUformsBatch.json
    • 02044-AspNetAllDformsBatch.json
    • 02047-AspNetAllRvBatch.json
    • 02048-AspNetAllRaBatch.json
    • 02049-AspNetAllRuBatch.json
    • 02050-AspNetAllRdBatch.json
    • 02051-AspNetAllRlBatch.json
    • 02052-AspNetAllRdlBatch.json
  • After you finish
    • open the src\app\components\aspnetuser-view\aspnetuser-view-rdl.routing.module.ts-file
      • the children-array is empty!!!
      • here is a fragment
...
const routes: Routes = [
 {
    path: '',
    component: AspnetuserViewRdlistComponent,
    canActivate: [AppGlblSettingsServiceActivator],
    children: [

//
// Info: Root Master View  [aspnetuserView] 
// Info: Detail View  [aspnetuserrolesView] 
//
//
//warning: for the View   [aspnetuserrolesView] the component [02050-Rdl-lazy.routing.module.ts] has not been generated yet
//

//
// Info: Root Master View  [aspnetuserView] 
// Info: Detail View  [aspnetusermaskView] 
//
//
//warning: for the View   [aspnetusermaskView] the component [02050-Rdl-lazy.routing.module.ts] has not been generated yet
//

    ]
  }
];
...
  • to fix this issue, run the following batch-scripts second time:
    • 02042-AspNetAllSFormsBatch.json
    • 02043-AspNetAllVformsBatch.json
    • 02047-AspNetAllRvBatch.json
    • 02051-AspNetAllRlBatch.json
    • 02052-AspNetAllRdlBatch.json

Routes

Which Routes to generate

  • Navigation paths

    • in the article 106 we generated Webapi services.

      • Webapi service generated for aspnetroleView uses RoleManager<IdentityRole>-class functionality
        • RoleManager can not return users for the given Role.
      • Webapi service generated for aspnetuserView uses UserManager<IdentityUser>-class functionality
        • UserManager can return roles for the given user
    • in the article 107 we regenerated entities and Dbcontext for production.

      • The List of Entities consists of only two objects:
        • aspnetmodel to persist all Views in the project
        • aspnetrolemask to persist triples (View, Role, Permission Bitmask)
    • As a result

      • Webapi service generated for aspnetusermaskView returns read only data.
      • Webapi service generated for aspnetuserpermsView returns read only data.
      • The Rlform(Rflform) for aspnetuserrolesView can be used only as detail panel for aspnetuserView-master Rlform(Rflform)
    • Navigation paths which make sense

      • aspnetuserView-aspnetroleView-aspnetrolemask
      • aspnetuserView-aspnetusermaskView
      • aspnetroleView-aspnetrolemask
      • aspnetmodelView-aspnetrolemask
  • Rl and Rdl navigation forms:

    • For our demo app we will generate Routes for Rl and Rdl navigation forms
      • Real app require only one type of forms (Rdl or Rl)
      • Rdl forms implement Add/Update/Delete/View item as popup dialogs
      • Rl forms implement Add/Update/Delete/View item as a separate navigation forms.

Common steps

  • right click src/app-folder of the Angular project and select Javascript Wizard-menu item
  • on the first page click next-button
  • on the second page
    • select PhBkContext.csproj-project
    • select aspnetchckdbcontext-Dbcontext
    • click next-button

aspnetmodelView

  • on the third page
    • select aspnetmodelView in the combo
    • click next-button
  • on the fourth page
    • select 01980-R-lazy.routes.ts
    • click next-button
  • on the fifth page
    • select r-lazy.routes.ts.t4
    • click next-button
  • copy generated code in the app-routing.module.ts-file
  • copy the following html in the app.component.html-file
<a mat-list-item [routerLink]="['aspnetmodelView']" routerLinkActive="active">List of aspnetmodels</a>
  • on the fourth page
    • select 02060-Rdl-lazy.routes.ts
    • click next-button
  • on the fifth page
    • select rdl-lazy.routes.ts.t4
    • click next-button
  • copy generated code in the app-routing.module.ts-file
  • copy the following html in the app.component.html-file
<a mat-list-item [routerLink]="['RDLaspnetmodelView']" routerLinkActive="active">List of aspnetmodels (Dlg)</a>

aspnetroleView

repeat the steps similar to those described for aspnetmodelView

aspnetuserView

repeat the steps similar to those described for aspnetmodelView

Other Views

  • We do not need generate Routes and menu items for the rest of the Views.
    • aspnetrolemaskView is returned only for one selected role
    • aspnetusermaskView is returned only for one selected user
      • It is a dynamically generated data. It collects Roles assigned to the given User.
      • Having the Roles along with Role Permission Masks it defines permission Masks for the given user.
    • aspnetuserpermsView is returned only for one selected user.
      • It is a helper structure that is sent to the client after the user has logged in
    • aspnetuserrolesView is returned only for one selected user. It does not return for one selected Role.
⚠️ **GitHub.com Fallback** ⚠️