Skip to content

Commit 2574944

Browse files
committed
refactor authorization
1 parent 36e6a2c commit 2574944

16 files changed

Lines changed: 64 additions & 192 deletions

.tours/ams-cap-nodejs-bookshop.tour

Lines changed: 0 additions & 104 deletions
This file was deleted.

ams-cap-nodejs-bookshop/.cdsrc.json

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,31 +4,29 @@
44
"[development]": {
55
"kind": "mocked",
66
"users": {
7-
"bob": {
7+
"content-manager": {
88
"policies": [
9-
"cap.admin",
10-
"cap.Reader"
9+
"cap.ContentManager"
1110
]
1211
},
13-
"carol": {
12+
"stock-manager": {
1413
"policies": [
15-
"local.Zealot"
14+
"cap.StockManager"
1615
]
1716
},
18-
"dave": {
17+
"reader": {
1918
"policies": [
20-
"local.JuniorReader"
19+
"cap.Reader"
2120
]
2221
},
23-
"erin": {
22+
"stock-manager-fiction": {
2423
"policies": [
25-
"local.BestsellerReader"
24+
"local.StockManagerFiction"
2625
]
2726
},
28-
"fred": {
27+
"juniorReader": {
2928
"policies": [
30-
"local.Zealot",
31-
"local.BestsellerReader"
29+
"local.JuniorReader"
3230
]
3331
},
3432
"technicalUser": {
@@ -49,7 +47,7 @@
4947
},
5048
"amsValueHelp": {
5149
"policies": [
52-
"cap.admin"
50+
"cap.ContentManager"
5351
],
5452
"ias_apis": [
5553
"AMS_ValueHelp"
Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
1-
POLICY "Reader" {
2-
ASSIGN ROLE "Reader" WHERE
3-
genre IS NOT RESTRICTED AND
4-
description IS NOT RESTRICTED AND
5-
stock IS NOT RESTRICTED;
1+
POLICY StockManager {
2+
ASSIGN ROLE ManageBooks WHERE Genre IS NOT RESTRICTED;
63
}
74

8-
POLICY Inquisitor {
9-
ASSIGN ROLE "Inquisitor" WHERE
10-
description IS NOT RESTRICTED;
5+
POLICY ContentManager {
6+
ASSIGN ROLE ManageAuthors;
7+
ASSIGN ROLE ManageBooks;
8+
ASSIGN ROLE ValueHelpUser;
119
}
1210

13-
POLICY "admin" {
14-
ASSIGN ROLE "admin";
11+
POLICY Reader {
12+
ASSIGN ROLE ReadBooks WHERE Genre IS NOT RESTRICTED;
1513
}
1614

15+
POLICY "ValueHelpUser" {
16+
ASSIGN ROLE "ValueHelpUser";
17+
}
Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
1-
INTERNAL Policy AMS_ValueHelp {
2-
USE cap.admin;
1+
INTERNAL POLICY AMS_ValueHelp {
2+
ASSIGN ROLE ValueHelpUser;
33
}
4-
5-
INTERNAL Policy ReadCatalog {
6-
USE cap.Reader RESTRICT
7-
genre IS NOT RESTRICTED,
8-
description IS NOT RESTRICTED,
9-
stock < 30;
4+
INTERNAL POLICY ReadCatalog {
5+
USE cap.Reader RESTRICT Genre NOT IN ('Mystery', 'Romance', 'Thriller', 'Dystopia');
106
}
Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,7 @@
1-
POLICY JuniorReader {
2-
USE cap.Reader RESTRICT
3-
genre IN ('Fantasy', 'Fairy Tale', 'Mystery'),
4-
description IS NOT RESTRICTED,
5-
stock IS NOT RESTRICTED;
6-
}
7-
8-
POLICY BestsellerReader {
9-
USE cap.Reader RESTRICT
10-
genre IS NOT RESTRICTED,
11-
description IS NOT RESTRICTED,
12-
stock < 20;
1+
POLICY StockManagerFiction {
2+
USE cap.StockManager RESTRICT Genre IN ('Mystery', 'Fantasy');
133
}
144

15-
POLICY Zealot {
16-
USE cap.Inquisitor RESTRICT
17-
description LIKE '%religious%references%';
5+
POLICY JuniorReader {
6+
USE cap.Reader RESTRICT Genre IN ('Fairy Tale', 'Fantasy', 'Mystery');
187
}
Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,8 @@
1-
// ---------------------------------HEADER_START-----------------------------------------------
2-
// Generated from a CAP model by the SAP AMS Plugin (@sap/ams) 3.3.0
3-
// hash of generated content: 760f88aa8521b7b516c368a517af58f0a55f37dfd0be60eb07c5d94cc2ea3efe
4-
// ----------------------------------HEADER_END------------------------------------------------
5-
61
SCHEMA {
72
@valueHelp: {
83
path: 'Genres',
94
valueField: 'name',
105
labelField: 'name'
116
}
12-
genre: String,
13-
description: String,
14-
stock: Number
7+
Genre: String
158
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
using { sap.capire.bookshop.Genres } from './schema';
2+
3+
aspect media {
4+
genre: Association to Genres;
5+
stock: Integer;
6+
}

ams-cap-nodejs-bookshop/db/schema.cds

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
using { Currency, managed, sap } from '@sap/cds/common';
2-
using { stocked, media } from '../srv/aspects';
2+
using { media } from './aspects';
33
namespace sap.capire.bookshop;
44

55

6-
entity Books : managed, media, stocked {
6+
entity Books : managed, media {
77
key ID : Integer;
88
@mandatory title : localized String(111);
99
@mandatory author : Association to Authors;
10+
descr: localized String(1111);
1011
price : Decimal;
1112
currency : Currency;
1213
image : LargeBinary @Core.MediaType : 'image/png';

ams-cap-nodejs-bookshop/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ams-cap-nodejs-bookshop",
3-
"version": "2.2.0",
3+
"version": "3.0.0",
44
"description": "A simple CAP project demonstrating the integration of AMS into CAP.",
55
"license": "UNLICENSED",
66
"private": true,
Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
1-
using { sap.capire.bookshop as my } from '../db/schema';
2-
service AdminService @(requires:'admin', path: '/admin') {
1+
using {sap.capire.bookshop as my} from '../db/schema';
2+
3+
service AdminService @(path: '/admin', requires: ['ManageAuthors', 'ManageBooks']) {
4+
5+
@(restrict: [
6+
{ grant: ['READ'], to: 'ManageAuthors' },
7+
{ grant: ['READ', 'WRITE'], to: 'ManageBooks' } ])
38
entity Books as projection on my.Books;
9+
10+
@(restrict: [
11+
{ grant: ['READ', 'WRITE'], to: 'ManageAuthors' },
12+
{ grant: ['READ'], to: 'ManageBooks' } ])
413
entity Authors as projection on my.Authors;
5-
}
14+
}

0 commit comments

Comments
 (0)