include authorization

This commit is contained in:
D065023
2019-12-06 11:32:50 +01:00
parent 68ee29598a
commit 140db39cd4
4 changed files with 33 additions and 2 deletions

View File

@@ -7,6 +7,7 @@
"@sap/cds": "latest",
"@sap/xb-msg-amqp-v100": "^0.9.31-SNAPSHOT",
"express": "*",
"passport": "^0.4.0",
"sqlite3": "^4.1.0"
},
"scripts": {
@@ -21,6 +22,12 @@
"messaging": {
"kind": "enterprise-messaging"
}
},
"auth": {
"passport": {
"strategy": "mock",
"users": { "alice": { "roles": [ "admin" ], "password": "secret", "ID": "ALICE" } }
}
}
}
}
}

View File

@@ -1,6 +1,6 @@
using { sap.capire.bookshop as my } from '../db/schema';
service AdminService @(_requires:'authenticated-user') {
service AdminService @(requires:'admin') {
entity Books as projection on my.Books;
entity Authors as projection on my.Authors;
entity Orders as select from my.Orders;

View File

@@ -59,6 +59,9 @@ module.exports = cds.service.impl(function () {
async function _readAddresses (req) {
const businessPartner = req.user.id
if (!businessPartner) {
return req.reject('You need to be authorized.')
}
const tx = bupaSrv.transaction(req)
const ql = SELECT.from('API_BUSINESS_PARTNER.A_BusinessPartnerAddress').where(
{ BusinessPartner: businessPartner.toUpperCase() }
@@ -80,6 +83,9 @@ async function _readAddresses (req) {
async function _fillAddress (req) {
if (req.data.shippingAddress_AddressID) {
const businessPartner = req.user.id
if (!businessPartner) {
return req.reject('You need to be authorized.')
}
const tx = bupaSrv.transaction(req)
const response = await tx.run(
SELECT.from('API_BUSINESS_PARTNER.A_BusinessPartnerAddress')

View File

@@ -23,6 +23,24 @@ module.exports = db => {
StreetName: 'SAP-Allee',
HouseNumber: '25'
},
{
BusinessPartner: 'ALICE',
AddressID: '62640',
CityName: 'Walldorf',
PostalCode: '69190',
Country: 'Germany',
StreetName: 'Dietmar-Hopp-Allee',
HouseNumber: '16'
},
{
BusinessPartner: 'ALICE',
AddressID: '22222',
CityName: 'St. Leon-Rot',
PostalCode: '68789',
Country: 'Germany',
StreetName: 'SAP-Allee',
HouseNumber: '25'
},
{
BusinessPartner: '1003765',
AddressID: '28241',