Introduction/use case
In your application, key users should be able to jump to another app via a button to view additional information. Normal users do not have access to this app, but the button is displayed. Each time normal users click the button, they get an error message. How can you show the button only for the corresponding key users?
In this blog post i will present you a possible solution via the CrossApplicationNavigation service.
Code Snippet
/** * @description get all semantic objects assigned to the user */ _readAssignedSemObjofUser: function () { return new Promise(function (resolve, reject) { if (!this._aSemObj) { sap.ushell.Container.getServiceAsync("CrossApplicationNavigation").then(function (oService) { oService.getLinks().done(function (aSemObj) { this._aSemObj = aSemObj; resolve(); }.bind(this)); }.bind(this)); } else { resolve(); } }.bind(this)); }, /** * @description check if the user has access to a specific semantic object/application */ _checkAuthorityBySemObj: function (sSemObj) { var bAuthorized = false; return new Promise(function (resolve, reject) { this._readAssignedSemObjofUser().then(function () { for (var i = 0; i < this._aSemObj.length; i++) { if (this._aSemObj[i].intent === sSemObj) { bAuthorized = true; } } resolve(bAuthorized); }.bind(this)); }.bind(this)); }
The method _readAssignedSemObjofUser
returns all semantic objects (incl. actions) that are assigned to the user via roles. To check if the user has access to an specific application just call the method checkAuthorityBySemObj
with the appropriate Semantic Object and action:
//check if the user has access to the application with the semantic object "Action" //and the action "toappnavsample" this._checkAuthorityBySemObj("#Action-toappnavsample").then(function (bAuthorized) { //TODO: Do something with bAuthorized });