cleanup
This commit is contained in:
@@ -1,20 +0,0 @@
|
||||
{
|
||||
"auth": {
|
||||
"passport": {
|
||||
"strategy": "mock",
|
||||
"users": {
|
||||
"alice": {
|
||||
"password": "123",
|
||||
"ID": "alice",
|
||||
"roles": ["admin", "authenticated-user"],
|
||||
"xs.user.attributes": { "currency": [ "USD" ] }
|
||||
},
|
||||
"bob": {
|
||||
"password": "123",
|
||||
"ID": "bob",
|
||||
"roles": ["authenticated-user"]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
27
packages/bookshop/package-lock.json
generated
Normal file
27
packages/bookshop/package-lock.json
generated
Normal file
@@ -0,0 +1,27 @@
|
||||
{
|
||||
"name": "@sap/capire-bookshop",
|
||||
"version": "1.0.0",
|
||||
"lockfileVersion": 1,
|
||||
"requires": true,
|
||||
"dependencies": {
|
||||
"passport": {
|
||||
"version": "0.4.1",
|
||||
"resolved": "https://registry.npmjs.org/passport/-/passport-0.4.1.tgz",
|
||||
"integrity": "sha512-IxXgZZs8d7uFSt3eqNjM9NQ3g3uQCW5avD8mRNoXV99Yig50vjuaez6dQK2qC0kVWPRTujxY0dWgGfT09adjYg==",
|
||||
"requires": {
|
||||
"passport-strategy": "1.x.x",
|
||||
"pause": "0.0.1"
|
||||
}
|
||||
},
|
||||
"passport-strategy": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/passport-strategy/-/passport-strategy-1.0.0.tgz",
|
||||
"integrity": "sha1-tVOaqPwiWj0a0XlHbd8ja0QPUuQ="
|
||||
},
|
||||
"pause": {
|
||||
"version": "0.0.1",
|
||||
"resolved": "https://registry.npmjs.org/pause/-/pause-0.0.1.tgz",
|
||||
"integrity": "sha1-HUCLP9t2kjuVQ9lvtMnf1TXZy10="
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -8,35 +8,28 @@
|
||||
"express": "*",
|
||||
"passport": "^0.4.1"
|
||||
},
|
||||
"cds": {
|
||||
"auth": {
|
||||
"passport": {
|
||||
"strategy": "mock",
|
||||
"users": {
|
||||
"alice": {
|
||||
"password": "123",
|
||||
"ID": "alice",
|
||||
"roles": ["admin", "authenticated-user"],
|
||||
"xs.user.attributes": { "currency": [ "USD" ] }
|
||||
},
|
||||
"bob": {
|
||||
"password": "123",
|
||||
"ID": "bob",
|
||||
"roles": ["authenticated-user"]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"scripts": {
|
||||
"start": "cds run --in-memory?",
|
||||
"watch": "cds watch"
|
||||
},
|
||||
"auth": {
|
||||
"passport": {
|
||||
"strategy": "mock",
|
||||
"users": {
|
||||
"alice": {
|
||||
"password": "123",
|
||||
"ID": "alice",
|
||||
"roles": [
|
||||
"admin",
|
||||
"authenticated-user"
|
||||
],
|
||||
"xs.user.attributes": {
|
||||
"country": [
|
||||
"US"
|
||||
]
|
||||
}
|
||||
},
|
||||
"bob": {
|
||||
"password": "123",
|
||||
"ID": "bob",
|
||||
"roles": [
|
||||
"authenticated-user"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
10
packages/bookshop/srv/admin-service.js
Normal file
10
packages/bookshop/srv/admin-service.js
Normal file
@@ -0,0 +1,10 @@
|
||||
/** Service implementation for AdminService */
|
||||
module.exports = cds.service.impl(function() {
|
||||
this.before ('CREATE', 'Orders', _checkOrderCreateAuth)
|
||||
})
|
||||
|
||||
|
||||
/** Check authorization */
|
||||
function _checkOrderCreateAuth (req) {
|
||||
req.user.currency[0] === req.data.currency_code || req.reject(403)
|
||||
}
|
||||
@@ -4,7 +4,6 @@ const { Books } = cds.entities
|
||||
/** Service implementation for CatalogService */
|
||||
module.exports = cds.service.impl(function() {
|
||||
this.after ('READ', 'Books', each => each.stock > 111 && _addDiscount2(each,11))
|
||||
this.before ('CREATE', 'Orders', _checkOrderCreateAuth)
|
||||
this.before ('CREATE', 'Orders', _reduceStock)
|
||||
})
|
||||
|
||||
@@ -26,9 +25,5 @@ async function _reduceStock (req) {
|
||||
}))
|
||||
}
|
||||
|
||||
/** Check authorization */
|
||||
function _checkOrderCreateAuth (req) {
|
||||
req.user.country === req.data.country || req.reject(403)
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user