Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Frontend adaptions for user permissions #1036

Merged
merged 248 commits into from
Apr 14, 2022
Merged
Show file tree
Hide file tree
Changes from 229 commits
Commits
Show all changes
248 commits
Select commit Hold shift + click to select a range
359254a
changed proxy config to use local instance
TheSlimvReal Sep 9, 2021
16f0aa7
Merge remote-tracking branch 'origin/master' into backend-testing
TheSlimvReal Oct 5, 2021
ae56135
Refactor EntityMap
Schottkyc137 Oct 18, 2021
5f901a6
Dynamically add entity attributes
Schottkyc137 Oct 18, 2021
dc96a9a
remove unnecessary import
Schottkyc137 Oct 18, 2021
a56a492
remove unnecessary import
Schottkyc137 Oct 18, 2021
abedbf8
fix tests
Schottkyc137 Oct 18, 2021
15cba69
improve documentation
Schottkyc137 Oct 18, 2021
82bad28
refactor: dynamic registration of entity attributes works the other w…
Schottkyc137 Oct 21, 2021
be7eb06
refactor several things
Schottkyc137 Oct 21, 2021
00d8fb4
add aliases for Child and School
Schottkyc137 Oct 21, 2021
29ea441
Merge remote-tracking branch 'origin/master' into backend-testing
TheSlimvReal Oct 21, 2021
707bc6e
changed proxy config
TheSlimvReal Oct 22, 2021
fe4c207
added casl libraries
TheSlimvReal Oct 22, 2021
9806f97
added webpack patch for casl libraries
TheSlimvReal Oct 22, 2021
4ed7f27
added service that sets up the ability for the currently logged in user
TheSlimvReal Oct 22, 2021
90444e2
changed typing to EntityAbility
TheSlimvReal Oct 22, 2021
38c1e4a
using normal ability instead of mock
TheSlimvReal Oct 22, 2021
b5eca73
working on subject type detection
TheSlimvReal Oct 22, 2021
a45719d
Merge remote-tracking branch 'origin/entity-map' into backend-testing
TheSlimvReal Oct 22, 2021
ace44a4
finished subject type detection for rules and checks
TheSlimvReal Oct 22, 2021
b4de848
made initRules method async
TheSlimvReal Oct 22, 2021
b67b0eb
added route initialization after login
TheSlimvReal Oct 22, 2021
fc909f1
replaced "write" with more detailed actions
TheSlimvReal Oct 22, 2021
6339a0d
replaced permission service with ability in entity details
TheSlimvReal Oct 22, 2021
c99d987
replaced permission service with ability in disable entity operation …
TheSlimvReal Oct 22, 2021
ad64c8d
added fallback handling in case first request to rules does not succeed
TheSlimvReal Oct 25, 2021
4049d64
fixed test description
TheSlimvReal Oct 25, 2021
8ddadea
updating disabled directive whenever input values change
TheSlimvReal Oct 25, 2021
091f607
implementing function to get notified about all logins
TheSlimvReal Oct 25, 2021
4ee53b0
finished waitForChangeTo function
TheSlimvReal Oct 25, 2021
9154563
disabling buttons is re-evaluated whenever somebody logs in
TheSlimvReal Oct 25, 2021
fcc00fd
Merge remote-tracking branch 'origin/master' into backend-testing
TheSlimvReal Oct 26, 2021
f0c09e2
also copying casl path into dockerfile
TheSlimvReal Oct 26, 2021
8457f7f
cleaned up disable entity component directive test
TheSlimvReal Oct 26, 2021
a5f94fd
fix lint errors
TheSlimvReal Oct 26, 2021
c26c15b
trying to fix test error
TheSlimvReal Oct 27, 2021
19109bd
removed tests for wrapper component as this component is tested throu…
TheSlimvReal Oct 29, 2021
2f66eb2
some smaller changes
TheSlimvReal Oct 29, 2021
7288195
renamed action
TheSlimvReal Oct 30, 2021
c4d6a11
cleaned up code and added todos for next steps
TheSlimvReal Nov 16, 2021
a8d3940
Merge remote-tracking branch 'origin/master' into backend-testing
TheSlimvReal Nov 17, 2021
2b9683a
added test for invalid object
TheSlimvReal Nov 17, 2021
4baf3be
removed entity permission service
TheSlimvReal Nov 17, 2021
11a42a8
fixed failing test
TheSlimvReal Nov 18, 2021
5eacf10
made rules object optional
TheSlimvReal Nov 18, 2021
586b003
added documentation to the rules types
TheSlimvReal Nov 19, 2021
0f9d35f
moved setting up of rules into ability service and fixed when permiss…
TheSlimvReal Nov 19, 2021
af9d84c
moved rules object to database
TheSlimvReal Nov 22, 2021
b440858
added permission check to not details component through pipe
TheSlimvReal Nov 22, 2021
6818340
added a demo permission generator
TheSlimvReal Nov 22, 2021
bed078d
Merge remote-tracking branch 'origin/master' into backend-testing
TheSlimvReal Nov 22, 2021
83efa6b
fixed failing tests
TheSlimvReal Nov 22, 2021
23370f7
removed unused dependency to EntitySchemaService
TheSlimvReal Nov 23, 2021
df3f8ab
creating a database per user, after a user logged in
TheSlimvReal Nov 24, 2021
c70ba58
changing how demo data is generated to handle the new database-per-us…
TheSlimvReal Nov 24, 2021
2a7e0e8
refactored tests to work with real PouchDBs
TheSlimvReal Nov 26, 2021
be4ff60
removed log and added todo for progress-dashboard.component.ts
TheSlimvReal Nov 26, 2021
ed904ed
added sync state management to demo data generation and sync
TheSlimvReal Nov 27, 2021
c549459
loading progressdashboard after sync is done
TheSlimvReal Nov 27, 2021
cc188c7
removed todo
TheSlimvReal Nov 27, 2021
2dd76a4
renamed DemoMode to DemoSession and extend SessionService
TheSlimvReal Nov 29, 2021
779d8bf
implemented demo mode as a independent session
TheSlimvReal Nov 29, 2021
39247ab
integrated demo session into session service provider and made Databa…
TheSlimvReal Nov 29, 2021
61f2aaa
correctly resetting dialog ref so sync dialog can open multiple times…
TheSlimvReal Nov 29, 2021
5897bda
correctly resetting dialog ref so sync dialog can open multiple times…
TheSlimvReal Nov 29, 2021
4ccc30e
removed demo data progress popup
TheSlimvReal Nov 29, 2021
96c8909
demo session always syncs with the demo user db and cancels sync on l…
TheSlimvReal Nov 29, 2021
41b4125
fixed an error in logout process
TheSlimvReal Nov 29, 2021
ce01b3d
fixed errors in tests
TheSlimvReal Nov 29, 2021
64c3f94
fixed codeclimate problems
TheSlimvReal Nov 29, 2021
95dd37c
Merge remote-tracking branch 'origin/master' into backend-testing
TheSlimvReal Nov 29, 2021
6edb208
fixed lint error
TheSlimvReal Nov 29, 2021
26f6ebe
added script to move data from old pouchdb versions to new one
TheSlimvReal Nov 29, 2021
67b5152
added a test to ensure an already destroyed database does not sync
TheSlimvReal Nov 30, 2021
b7f012c
working on the migration
TheSlimvReal Nov 30, 2021
2896600
added migration to login process
TheSlimvReal Nov 30, 2021
b449958
added debug logs
TheSlimvReal Dec 1, 2021
92fe045
removing design docs before sync
TheSlimvReal Dec 1, 2021
4ef40db
removed sync state from local session
TheSlimvReal Dec 1, 2021
aa8cb9b
added test suite and first prototype implementation for a local purge…
TheSlimvReal Dec 2, 2021
f503444
moved di token to own file
TheSlimvReal Dec 3, 2021
fcbb226
implemented dumb permission enforcer
TheSlimvReal Dec 3, 2021
026d33c
removed debugging code
TheSlimvReal Dec 4, 2021
3420dea
finalized permission enforcer
TheSlimvReal Dec 4, 2021
a0b4fdb
added matomo event tracking for db migration
TheSlimvReal Dec 6, 2021
67ce706
added matomo tracking to permission enforcer
TheSlimvReal Dec 6, 2021
7486116
fixed tests and fixed cyclic dependency with analytics service
TheSlimvReal Dec 6, 2021
0703a22
added todo for translation
TheSlimvReal Dec 6, 2021
fb04e1f
fixed lint errors
TheSlimvReal Dec 7, 2021
7c24c7c
proxy conf also rewrites remote URL
TheSlimvReal Dec 7, 2021
f6198a8
Fixed creation of remote database
TheSlimvReal Dec 7, 2021
f9a70aa
Fixed race-condition in synced session
TheSlimvReal Dec 7, 2021
8751017
added permission check to entity subrecord
TheSlimvReal Dec 8, 2021
5963d9f
fixed tests
TheSlimvReal Dec 8, 2021
d3c15fb
Merge remote-tracking branch 'origin/master' into backend-testing
TheSlimvReal Dec 8, 2021
ef15b98
updated dependencies
TheSlimvReal Dec 8, 2021
9e6d7f1
some code refactoring
TheSlimvReal Dec 8, 2021
bf32608
Merge remote-tracking branch 'origin/master' into backend-testing
TheSlimvReal Dec 8, 2021
b65ce54
fixed lint error
TheSlimvReal Dec 8, 2021
33dfdca
fixed code smells
TheSlimvReal Dec 8, 2021
777481b
docs: Added guide for working with user roles and permissions
TheSlimvReal Dec 11, 2021
0a0146d
added todo item for users without rules
TheSlimvReal Dec 11, 2021
4dd7edf
Merge remote-tracking branch 'origin/master' into backend-testing
TheSlimvReal Jan 28, 2022
6382848
finished up master merge
TheSlimvReal Jan 28, 2022
ec22076
fixed lint errors
TheSlimvReal Jan 31, 2022
9ccf37f
fixed some code smells
TheSlimvReal Jan 31, 2022
0035f5d
added readonly view to note details
TheSlimvReal Feb 2, 2022
a191d97
Merge remote-tracking branch 'origin/master' into backend-testing
TheSlimvReal Feb 7, 2022
f6756f4
fixed broken tests
TheSlimvReal Feb 7, 2022
939cc56
improved algorithm to detect entities without permissions
TheSlimvReal Feb 7, 2022
ffe34a4
added variable interpolation for json rules
TheSlimvReal Feb 7, 2022
58250d7
added support rules with multiple subjects
TheSlimvReal Feb 9, 2022
69a3c16
fixed tests for permission enforcer
TheSlimvReal Feb 9, 2022
a520286
added permission check when saving an entity form
TheSlimvReal Feb 9, 2022
6010745
fixed failing test
TheSlimvReal Feb 9, 2022
05bc425
improved typing
TheSlimvReal Feb 9, 2022
9189900
transforming entities to database format before checking ability
TheSlimvReal Feb 9, 2022
57a99fd
refactored EntityAbility to inherit from Ability and correctly transf…
TheSlimvReal Feb 9, 2022
2ba7288
removed permission module from app module
TheSlimvReal Feb 10, 2022
0ef1ce0
refactoring entity subrecord and row detail component in order to bet…
TheSlimvReal Feb 10, 2022
b5346c2
refactored form dialog wrapper to work with the new entity subrecord …
TheSlimvReal Feb 10, 2022
426a7a3
added todo for reloading after undoing delete
TheSlimvReal Feb 10, 2022
30adaf3
refactored entity subrecord component to generally look for updates
TheSlimvReal Feb 10, 2022
3dd0a75
removed unneeded dialog data results from previous refactoring
TheSlimvReal Feb 10, 2022
174f99d
using entity remove service in row details
TheSlimvReal Feb 10, 2022
bfc3df1
fixed broken tests
TheSlimvReal Feb 10, 2022
ab0d96b
changed policy so create permissions are checked on the to-be-created…
TheSlimvReal Feb 10, 2022
dc49728
removed console logs
TheSlimvReal Feb 10, 2022
e2f0f0b
fixed lint errors
TheSlimvReal Feb 10, 2022
93009c3
Merge branch 'master' into backend-testing
TheSlimvReal Feb 11, 2022
3024714
fix: ignoring some subjects when checking for database reset
TheSlimvReal Feb 12, 2022
1412919
fix: preventing error messages when user object is not available yet
TheSlimvReal Feb 12, 2022
7773795
Merge remote-tracking branch 'origin/backend-testing' into backend-te…
TheSlimvReal Feb 12, 2022
0a64b7e
Merge remote-tracking branch 'origin/master' into backend-testing
TheSlimvReal Feb 15, 2022
c35a39d
Merge branch 'master' into backend-testing
TheSlimvReal Feb 15, 2022
410372a
removed deprecated permission properties from demo config
TheSlimvReal Feb 15, 2022
78ba30b
added Config entity to ignored subject when running permission enforcer
TheSlimvReal Feb 17, 2022
be4dfa9
Merge remote-tracking branch 'origin/backend-testing' into backend-te…
TheSlimvReal Feb 17, 2022
eb0ad84
fix lint error
TheSlimvReal Feb 17, 2022
e60389f
Merge branch 'master' into backend-testing
TheSlimvReal Feb 17, 2022
8c2eb42
Merge remote-tracking branch 'origin/master' into backend-testing
TheSlimvReal Feb 25, 2022
18e2229
Merge branch 'master' into backend-testing
TheSlimvReal Feb 28, 2022
224b08b
Merge branch 'master' into backend-testing
sleidig Mar 1, 2022
e0cba29
Merge remote-tracking branch 'origin/master' into backend-testing
TheSlimvReal Mar 1, 2022
c749bad
fixed permissions enforcer to correctly detect rules with conditions …
TheSlimvReal Mar 1, 2022
0206269
replaced permission entity with config object
TheSlimvReal Mar 1, 2022
4d26fb5
fixed e2e tests
TheSlimvReal Mar 1, 2022
5d23b05
fixed typo
TheSlimvReal Mar 1, 2022
3e3f3fb
docs: small documentation clarifications
sleidig Mar 1, 2022
fd7a070
fixed e2e tests
TheSlimvReal Mar 1, 2022
c9df026
Merge remote-tracking branch 'origin/backend-testing' into backend-te…
TheSlimvReal Mar 1, 2022
5d73aa4
Merge remote-tracking branch 'origin/master' into backend-testing
TheSlimvReal Mar 7, 2022
54cb1b4
refactor: rename static function
TheSlimvReal Mar 7, 2022
ecfbeb1
test: fix broken test
TheSlimvReal Mar 7, 2022
7b9d008
created demo data service for managing the demo data generation and l…
TheSlimvReal Mar 7, 2022
9acfcde
test: increased number of retries for karma
TheSlimvReal Mar 7, 2022
d2daf07
added error message for wrong session
TheSlimvReal Mar 7, 2022
ebe91ad
added synchronizatin to demo data initializer service
TheSlimvReal Mar 7, 2022
513958a
using new service for initializing demo data
TheSlimvReal Mar 7, 2022
fd9242d
deleted demo session
TheSlimvReal Mar 7, 2022
e5e5f46
undone changes to progress dashboard
TheSlimvReal Mar 7, 2022
3b0cb3b
doc: added comment about possible error messages
TheSlimvReal Mar 7, 2022
f7dcf0d
doc: updated some comments and test names
TheSlimvReal Mar 7, 2022
cbe7dc6
test: cleaned up test
TheSlimvReal Mar 7, 2022
f24e7d7
refactor: removed duplicate code fragment
TheSlimvReal Mar 7, 2022
24811f8
test: also checking for updated rules object
TheSlimvReal Mar 7, 2022
6d6e607
refactor: renamed rule update observable
TheSlimvReal Mar 7, 2022
b85ad6d
fix: logging warning if no rules could be found for the logged-in user
TheSlimvReal Mar 7, 2022
7c7061d
refactor: removed rules object copy
TheSlimvReal Mar 7, 2022
2cc5985
refactor: cleaned up changed rules check
TheSlimvReal Mar 9, 2022
e0cb914
refactor: cleaned up subject collection
TheSlimvReal Mar 9, 2022
2cbf092
test: created parameterized test
TheSlimvReal Mar 9, 2022
b1f8739
test: fixed broken tests
TheSlimvReal Mar 9, 2022
ef06722
doc: changed permission class to config object
TheSlimvReal Mar 9, 2022
8ad295c
refactor: changed default proxy endpoint
TheSlimvReal Mar 9, 2022
ad20072
refactor: removed default schema service
TheSlimvReal Mar 9, 2022
918a3b9
doc: added explanation for entity ability class
TheSlimvReal Mar 9, 2022
2ba4bfd
doc: added explanation for local storage key
TheSlimvReal Mar 9, 2022
7d54125
doc: added explanation for permission enforcer
TheSlimvReal Mar 9, 2022
7e14267
refactor: removed unnecessary app config setup
TheSlimvReal Mar 9, 2022
2278bd5
doc: added comment explaining database migration service
TheSlimvReal Mar 9, 2022
be93416
refactor: merged demo user and permission generator
TheSlimvReal Mar 9, 2022
5c592b9
refactor: re-addedd default app config for testing
TheSlimvReal Mar 9, 2022
fc0598b
refactor: fix broken demo data generator
TheSlimvReal Mar 9, 2022
4cc5c85
refactor: move migration out of local session and user context setup …
TheSlimvReal Mar 10, 2022
3cf41a3
refactor: inlined database provider
TheSlimvReal Mar 10, 2022
f26d50a
refactor: rmeoved default assignment of logging service
TheSlimvReal Mar 10, 2022
da10009
feat: added default rule option
TheSlimvReal Mar 10, 2022
3b6cd71
feat: added default rule option
TheSlimvReal Mar 10, 2022
353fa1e
fix: removed hardcoded default permissions
TheSlimvReal Mar 10, 2022
8840283
fix: undonde changes to demo data generation
TheSlimvReal Mar 10, 2022
90d16e8
small fixes to get it running
TheSlimvReal Mar 10, 2022
ece989a
fixed tests
TheSlimvReal Mar 11, 2022
bc4df45
fixed prettier issues
TheSlimvReal Mar 11, 2022
c972537
fixed e2e errors
TheSlimvReal Mar 11, 2022
b4fb536
fixed lint errors
TheSlimvReal Mar 11, 2022
8a91c96
removed design doc removal and location reload
TheSlimvReal Mar 15, 2022
40b7220
Merge remote-tracking branch 'origin/master' into backend-testing
TheSlimvReal Mar 15, 2022
7f7febd
fixed prettier
TheSlimvReal Mar 15, 2022
e13371e
added info dialog while migrating
TheSlimvReal Mar 17, 2022
1e907b0
Merge remote-tracking branch 'origin/master' into backend-testing
TheSlimvReal Mar 23, 2022
25f7bab
Merge remote-tracking branch 'origin/master' into backend-testing
TheSlimvReal Mar 25, 2022
8fe92eb
Merge branch 'master' into backend-testing
TheSlimvReal Mar 28, 2022
91846fe
cleaned up code and added documentation
TheSlimvReal Mar 28, 2022
3408a23
removed sync from session service interface
TheSlimvReal Mar 28, 2022
dba2470
added isEmpty function to database
TheSlimvReal Mar 28, 2022
f97a21d
added fallback handling of deprecated db format
TheSlimvReal Mar 28, 2022
74bc1fc
removed usage of database migration service
TheSlimvReal Mar 28, 2022
4d49ea6
added more logging
TheSlimvReal Mar 29, 2022
71656cb
fixed fallback database handling
TheSlimvReal Mar 29, 2022
bdbc054
added logging
TheSlimvReal Mar 29, 2022
c09a4bd
removed multiple execution of login button
TheSlimvReal Mar 29, 2022
715fe6e
fixed error in auto resolution service
TheSlimvReal Mar 29, 2022
afedb4b
removved logging
TheSlimvReal Mar 29, 2022
b0ea26e
indices are re-created whenever a user is logged in
TheSlimvReal Mar 29, 2022
24302b1
added DatabaseTestingModule that automatically sets up a fully workin…
TheSlimvReal Mar 29, 2022
025d3da
adapted MockedTestingModule and properly used it in all tests
TheSlimvReal Mar 29, 2022
eb5577e
fixed tests for database indices
TheSlimvReal Mar 29, 2022
054a2c5
undone starting point of sync
TheSlimvReal Mar 29, 2022
f639381
removed database migration service
TheSlimvReal Mar 29, 2022
f724673
added todo for search component
TheSlimvReal Mar 29, 2022
bec803c
fixed lint errors
TheSlimvReal Mar 29, 2022
d8727b9
fixed error when trying to remove entity from a table
TheSlimvReal Mar 30, 2022
df1cd2b
refactor usage of entityConstructor in entitySubrecord component
TheSlimvReal Mar 30, 2022
e9fabc0
Merge branch 'master' into backend-testing
TheSlimvReal Mar 30, 2022
80aa2d8
added some comments for the new testing modules
TheSlimvReal Mar 30, 2022
35b1cca
Merge remote-tracking branch 'origin/backend-testing' into backend-te…
TheSlimvReal Mar 30, 2022
a58995e
added comments to explain database fallback
TheSlimvReal Mar 30, 2022
ed39d63
restructured permission folder
TheSlimvReal Apr 5, 2022
4d69a87
fix typo
TheSlimvReal Apr 9, 2022
5b297d0
Merge remote-tracking branch 'origin/backend-testing' into backend-te…
TheSlimvReal Apr 9, 2022
7890ba4
Merge remote-tracking branch 'origin/master' into backend-testing
TheSlimvReal Apr 9, 2022
c3822bc
resolved some sonarcloud issues
TheSlimvReal Apr 9, 2022
83f9e40
removed database-migration-dialog.component.ts
TheSlimvReal Apr 9, 2022
36568fb
Merge branch 'master' into backend-testing
TheSlimvReal Apr 9, 2022
ab61771
fixed problems with initial creation of indices
TheSlimvReal Apr 11, 2022
6441bf0
fixed problem with re-login and reloading of the config
TheSlimvReal Apr 11, 2022
50dbdd9
refactored config service as it can now inject entity mapper directly
TheSlimvReal Apr 11, 2022
b3578ec
refactored workflows in app component and analytics service to work w…
TheSlimvReal Apr 12, 2022
57fc510
Merge remote-tracking branch 'origin/master' into backend-testing
TheSlimvReal Apr 12, 2022
6cd39a7
cleaned up pouchdb util function
TheSlimvReal Apr 12, 2022
5b8ad76
remote session does not throw errors when logging out without internet
TheSlimvReal Apr 12, 2022
2dfa99a
fixed initial config loading and initialization
TheSlimvReal Apr 12, 2022
be92b33
removed unnecessary navigate call in login component
TheSlimvReal Apr 12, 2022
27ab6a0
fixed test for analytics service
TheSlimvReal Apr 12, 2022
2f15718
correctly cleaning up database in app component test
TheSlimvReal Apr 13, 2022
16232f6
Merge branch 'master' into backend-testing
TheSlimvReal Apr 13, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions build/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ WORKDIR /app

COPY package*.json ./
COPY patch-webpack.js .
COPY patch-casl.js .
RUN npm ci --no-progress

RUN $(npm bin)/ng version
Expand Down
8 changes: 6 additions & 2 deletions doc/compodoc_sources/concepts/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@ On the top level of the config file, there are four different kinds of entries:
1. The main navigation menu (`navigationMenu`)
1. Views defining the UI of each page (`view:<path>`)
1. Lists of select options for dropdown fields (`enum:<category-id>`, including available Note categories, etc.)
1. Entity configuration to define [schemas](entity-schema-system.md) or permissions (`entity:<entity-id>`)
1. Entity configuration to define [schemas](./entity-schema.html (`entity:<entity-id>`)

_also see [User Roles & Permissions](user-roles-and-permissions.html)_


### Navigation Menu
Expand Down Expand Up @@ -110,7 +112,9 @@ The only mandatory field for each view is `"component":` telling the app which c
The component part has to refer to an existing angular component within the app. Components that are valid and may
be used for the view have the `@DynamicComponent` decorator present

The two optional fields of each view are `"config":` and `"requiresAdmin":`. The latter is a boolean telling the app whether the user has to be logged in as an administrator in order to be able the see the component.
The two optional fields of each view are `"config":` and `"permittedUserRoles":`.
`"permittedUserRoles"` expects an array of user role strings.
If one or more roles are specified, only users with these roles are able to see this menu item and visit this page in the app.

What comes within the `"config":` object depends on the component being used.
The Dashboard-Component for example takes as `"widgets:"` an array of subcomponents, where every entry has to have a `"component:"` and may have an own `"config:"` object.
Expand Down
148 changes: 148 additions & 0 deletions doc/compodoc_sources/concepts/permissions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
# Permissions
Aam Digital allows to specify permissions to restrict access of certain user roles to the various entity types.
Permissions are defined using the [CASL JSON syntax](https://casl.js.org/v5/en/guide/define-rules#the-shape-of-raw-rule).
The permissions are stored in a [config object](../../classes/Config.html) which is persisted together with other entities in the database.

## Permission structure
As an example, we will define a permission object which allows users with the role `user_app` *not* to *create*, *read*, *update* and *delete* `HealthCheck` entities and *not* *create* and *delete* `School` and `Child` entities.
Besides that, the role is allowed to do everything.
A second role `admin_app` is allowed to do everything.
Additionally, we add a `default` rule which allows each user (independent of role) to read the `Config` entities.
Default rules are prepended to the rules of any user and allow to configure user-agnostic permissions.
The default rules can be overwritten in the role-specific rules.

```JSON
{
"_id": "Config:Permissions",
"data": {
"default": [
{
"subject": "Config",
"action": "read"
}
],
"user_app": [
{
"subject": "all",
"action": "manage"
},
{
"subject": "HealthCheck",
"action": "manage",
"inverted": true
},
{
"subject": [
"School",
"Child"
],
"action": [
"create",
"delete"
],
"inverted": true
}
],
"admin_app": [
{
"subject": "all",
"action": "manage"
}
]
}
}
```
The `_id` property needs to be exactly as displayed here, as there is only one permission object allowed in a single database.
In `data`, the permissions for each of the user role are defined.
In this example we have permissions defined for two roles: `user_app` and `admin_app`.
The permissions for a given role consist of an array of rules.

In case of the `user_app`, we first define that the user is allowed to do everything.
`subject` refers to the type of entity and `all` is a wildcard, that matches any entity.
`action` refers to the operation that is allowed or permitted on the given `subject`.
In this case `manage` is also a wildcard which means *any operation is allowed*.
So the first rule states *any operation is allowed on any entity*.

The second and third rule for `user_app` restrict this through the `"inverted": true` keyword.
While the first rule defined what this role is **allowed** to do, when `"inverted": true` is specified, this rule defines what the role is **not allowed** to do.
This allows us to easily take permissions away from a certain role.
In this case we don't allow users with this role to perform *any* operation on the `HealhCheck` entity and no *create* and *update* on `Child` and `School` entities.
Other possible actions are `read` and `update` following the *CRUD* concept.

The `admin_app` role simpy allows user with this role to do everything, without restrictions.

To learn more about how to define rules, have a look at the [CASL documentation](https://casl.js.org/v5/en/guide/define-rules#rules).

## Implementing components with permissions
This section is about code using permissions to read and edit **entities**.
If you want to change the menu items which are shown in the navigation bar have a look at the *views* section in the [Configuration Guide](./configuration.html).

The permission object is automatically fetched whenever a user logs in.
The permissions disable certain buttons based on the users overall permissions.
This is done in the app through the [DisableEntityOperationDirective](../../directives/DisableEntityOperationDirective.html), which connects certain buttons with their operation.

As an example lets say we have a class variable called `note` which holds an object of the `Note` entity.
We want to create a button which allows to *edit* this note.
In the HTML template we could write the following in order to automatically connect it to the permission system:

```HTML
<button
*appDisabledEntityOperation="{
entity: note,
operation: 'update'
}"
>
Edit Note
</button>
```
This will automatically disable the button if the user is not allowed to *update* this specific note.

To check permissions inside a `*.ts` file, you can inject the `EntityAbility`:

```typescript
import { Note } from "./note";
import { Injectable } from "@angular/core";
import { EntityAbility } from "./permission-types";

@Injectable()
export class SomeService {
constructor(private ability: EntityAbility) {
if (this.ability.can('create', Note)) {
// I have permissions to create notes
const note = new Note();
} else {
// I don't have permissions to create notes
throw Error("Missing permissions");
}
}
}
```
In this example the `EntityAbility` service is used to check whether the currently logged in user is allowed to _create_ new objects of the `Note` entity.
In this case a constructor is provided to check for the permissions,
in other cases it might make more sense to use an instance of an object like `this.ability.can('read', new Note())`.

## Permissions in production
As permissions cannot directly be created and edited from within the app at the moment, you can use the following steps to define permissions for a deployed system:

1. using CouchDB Fauxton GUI to edit database documents directly:
Look for or create the document with `"_id": "Config:Permissions"` and define the permissions as described above.
2. After saving the new permissions document, update the replication backend about the updated permissions:
Visit `https://<your-system-domain>/db/api/` to use the OpenAPI interface for this.
3. There in `Servers` select `/db deployed`
4. Use your CouchDB admin credentials in the `POST /_session` endpoint to get a valid access token.
5. Make a request to the `POST /rules/reload` endpoint. If successful, the response will show the newly fetched rules.
6. In case some users might have **gained** access to documents to which they did not have access before,
also trigger the `POST /clear_local` endpoint.
The `/clear_local` endpoint will ensure that each client re-checks whether new objects are available for synchronization.
This should also be used in case an existing user has gotten a new, more powerful role.
In case a user lost permissions for objects that were already synced, this users local DB will automatically be destroyed and the user has to synchronize all data again.

The roles assigned to users are specified in the user documents in the `_users` database of CouchDB.

## Permissions in development
When trying to test out things with the permissions, the [DemoPermissionGeneratorService](../../Injectable/DemoPermissionGeneratorService.html) can be modified to change the permission object which is created in the demo data.
These changes should not be committed however, as this demo data is also used in the publicly available demo.

The demo data comes with two user: `demo` and `demo-admin`.
The `demo` user has the role `user_app`, the `demo-admin` has the roles `user_app` and `admin_app`.
The permissions of the latter overwrite the permissions of the former.
4 changes: 4 additions & 0 deletions doc/compodoc_sources/summary.json
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,10 @@
"title": "Configuration",
"file": "concepts/configuration.md"
},
{
"title": "User Roles and Permissions",
"file": "concepts/permissions.md"
},
{
"title": "UX Guidelines",
"file": "concepts/ux-guidelines.md"
Expand Down
2 changes: 1 addition & 1 deletion e2e/integration/LinkingChildToSchool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ describe("Scenario: Linking a child to a school - E2E test", () => {

// get the Add School button and click on it
cy.get(
"app-previous-schools.ng-star-inserted > app-entity-subrecord > .mat-elevation-z1 > .mat-table > thead > .mat-header-row > .cdk-column-actions > .mat-focus-indicator"
"app-previous-schools.ng-star-inserted > app-entity-subrecord > .mat-elevation-z1 > .mat-table > thead > .mat-header-row > .cdk-column-actions > app-disabled-wrapper.ng-star-inserted > .mat-tooltip-trigger > .mat-focus-indicator"
)
.should("be.visible")
.click();
Expand Down
4 changes: 3 additions & 1 deletion e2e/support/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@ Cypress.Commands.add("create", create);
// Overwriting default visit function to wait for index creation
Cypress.Commands.overwrite("visit", (originalFun, url, options) => {
originalFun(url, options);
cy.get("app-search").should("be.visible");
cy.get("app-search", { timeout: 4000 }).should("be.visible");
// wait for demo data generation
cy.wait(4000);
// wait for indexing
cy.contains("button", "Continue in background", { timeout: 10000 }).should(
"not.exist"
);
Expand Down
1 change: 1 addition & 0 deletions karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,6 @@ module.exports = function (config) {
autoWatch: true,
browsers: ["Chrome"],
singleRun: false,
retryLimit: 10,
});
};
100 changes: 100 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"e2e": "ng e2e",
"e2e-open": "ng run ndb-core-e2e:cypress-open",
"compodoc": "npx compodoc -c doc/compodoc_sources/.compodocrc.json",
"postinstall": "ngcc && node patch-webpack.js",
"postinstall": "ngcc && node patch-webpack.js && node patch-casl.js",
"docs:json": "compodoc -p ./tsconfig.json -e json -d .",
"storybook": "npm run docs:json && start-storybook -p 6006",
"build-storybook": "npm run docs:json && build-storybook",
Expand All @@ -37,6 +37,8 @@
"@angular/platform-browser-dynamic": "^11.2.12",
"@angular/router": "^11.2.12",
"@angular/service-worker": "^11.2.12",
"@casl/ability": "^5.4.3",
"@casl/angular": "^5.1.1",
"@fortawesome/angular-fontawesome": "^0.8.2",
"@fortawesome/fontawesome-svg-core": "^1.2.36",
"@fortawesome/free-regular-svg-icons": "^5.15.2",
Expand Down
Loading