Skip to content
This repository was archived by the owner on Jun 3, 2024. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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 cap/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ default-*.json
gen/
node_modules/
target/
package-lock.json

# Web IDE, App Studio
.che/
Expand Down
3 changes: 2 additions & 1 deletion cap/db/data-model.cds
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ entity Books {
key ID : Integer;
title : String;
stock : Integer;
}
createdBy : String @cds.on.insert : $user;
}
44 changes: 42 additions & 2 deletions cap/package-lock.json

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

22 changes: 21 additions & 1 deletion cap/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@
"private": true,
"dependencies": {
"@sap/cds": "^5.5.4",
"cors": "^2.8.5",
"express": "^4",
"hdb": "^0.19"
"hdb": "^0.19",
"helmet": "^4.6.0",
"passport": "^0.5.0"
},
"devDependencies": {
"sqlite3": "^5.0.2"
Expand Down Expand Up @@ -49,6 +52,23 @@
},
"hana": {
"deploy-format": "hdbtable"
},
"auth": {
"kind": "basic-auth",
"users": {
"user_basic": {
"password": "28725",
"roles": [
"reader"
]
},
"user_admin": {
"password": "73546",
"roles": [
"admin"
]
}
}
}
}
}
22 changes: 20 additions & 2 deletions cap/srv/cat-service.cds
Original file line number Diff line number Diff line change
@@ -1,5 +1,23 @@
using my.bookshop as my from '../db/data-model';

service CatalogService {
@readonly entity Books as projection on my.Books;
}
@Capabilities: {
InsertRestrictions.Insertable: true,
UpdateRestrictions.Updatable: true,
DeleteRestrictions.Deletable: false
}
entity Books @(restrict : [
{
grant : ['READ'],
to : ['reader']
},
{
grant : ['READ', 'UPDATE', 'WRITE'],
to : ['admin']
}
]) as projection on my.Books;
}

annotate Books with @(restrict: [
{ grant: ['UPDATE', 'DELETE'], where: 'CreatedBy = $user' } ]);

19 changes: 16 additions & 3 deletions cap/srv/server.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
const cds = require ('@sap/cds')
const cds = require("@sap/cds");
const cors = require("cors");
const helmet = require("helmet");
cds.on('bootstrap', (app) => {


app.use(cors())
app.use(
helmet({
contentSecurityPolicy: {
directives: {
...helmet.contentSecurityPolicy.getDefaultDirectives(),
},
},
})
);

})

module.exports = cds.server
module.exports = cds.server