@universis/janitor 2.5.0 → 2.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -440,6 +440,26 @@ add `scopeAccess` section under `settings/universis/janitor` configuration and s
440
440
 
441
441
  The given files should contain an array of scope access configuration elements as described in the `ScopeAccessConfiguration` section.
442
442
 
443
+ ## EnableReadAccessScope
444
+
445
+ `EnableReadAccessScope` is an application service which enables read-only client scopes (`students:read`, `teachers:read` and `registrar:read`) alongside the default `students`, `teachers` and `registrar` scopes.
446
+
447
+ Register service under application services:
448
+
449
+ ```json
450
+ {
451
+ "services": [
452
+ {
453
+ "serviceType": "@universis/janitor#EnableReadAccessScope"
454
+ }
455
+ ]
456
+ }
457
+ ```
458
+
459
+ When the application container is ready, the service enumerates all model definitions and, for every scope-based privilege with read access (`mask: 1`) — at model or field level — which includes a client scope, it appends the corresponding `<scope>:read` scope. It also extends `ScopeAccessConfiguration` by inserting a read-only (`access: ["read"]`) element with the `<scope>:read` scope right after every element that grants read access to the original scope.
460
+
461
+ This allows OAuth2 clients to request e.g. `students:read` and get read access to the same resources as `students`, without being able to modify them.
462
+
443
463
 
444
464
  ## RemoteAddressValidator
445
465
 
package/dist/index.esm.js CHANGED
@@ -2014,6 +2014,30 @@ class EnableReadAccessScope extends ApplicationService {
2014
2014
  }
2015
2015
  }
2016
2016
  }
2017
+
2018
+ // get views with scope based privileges
2019
+ // noinspection JSUnresolvedReference
2020
+ if (Array.isArray(definition.views)) {
2021
+ // noinspection JSUnresolvedReference
2022
+ const views = definition.views.filter((item) => {
2023
+ return Array.isArray(item.privileges);
2024
+ });
2025
+ for (const view of views) {
2026
+ const privileges = view.privileges.filter((privilege) => {
2027
+ return privilege.mask === 1 && Array.isArray(privilege.scope) && privilege.scope.includes(searchScope);
2028
+ });
2029
+ if (privileges.length > 0) {
2030
+ shouldUpdate = true;
2031
+ for (const privilege of privileges) {
2032
+ if (!privilege.scope.includes(targetScope)) {
2033
+ privilege.scope.push(targetScope);
2034
+ }
2035
+ }
2036
+ }
2037
+ }
2038
+ }
2039
+
2040
+
2017
2041
  if (shouldUpdate) {
2018
2042
  updated++;
2019
2043
  // update model definition