Technology Blogs by Members
Explore a vibrant mix of technical expertise, industry insights, and tech buzz in member blogs covering SAP products, technology, and events. Get in the mix!
cancel
Showing results for 
Search instead for 
Did you mean: 
eamarce23
Participant
0 Kudos
Hello there,

In this blog we will have a quick review on how to create and assign custom roles in SAP Cloud Platform Portal and Fiori Launchpad Portal. We will also cover how to access this roles from a SAPUI5 / Fiori app.

Creating and assigning a user role


First, we should go to the service Portal overview page inside SAP Cloud Platform. In this page, we should make click on the Configure Portal option.



From the Roles section, we can go and create a new Custom role. In this case, it will be called Test_Role.





Once that we have created the role, we will assign a user to this role. We can do so by making click on the Assign option after selecting the new created role.



Now, we will have both the role and the user ready for the next step.



Next, we will need to enter our SAP Fiori Launchpad site, inside the portal service.



In the configuration cockpit, we should go to Roles, under the Content Management section. There, we should create the same role we created on the Portal configuration.

We must be careful of setting the Role ID with the same name as our previously created role.



We can now assign Catalogs and groups as required for this new role.



 

Accessing roles from a SAPUI5 app


To access the roles for a user we can include the following code inside our Component.js init method.


try{

jQuery.sap.require("sap.ushell.cpv2.services.cloudServices.SiteService");

}catch(oException){

}

This will help us ensure we have the SiteService component loaded.

Next, we can create a SiteService object where we need to access the roles. In this example, the object is created inside the CreateContent method of the view.


        try {
if (sap.ushell && sap.ushell.cpv2 && sap.ushell.cpv2.services && sap.ushell.cpv2.services.cloudServices && sap.ushell.cpv2.services.cloudServices.SiteService) {

var oLocalSiteService = sap.ushell.cpv2.services.cloudServices.SiteService();
var oRoles = oLocalSiteService.siteModel.getProperty("/roles");
var oProperty;


for (oProperty in oRoles) {

if (oRoles.hasOwnProperty(oProperty)) {
if (oProperty.toString() === "Test_Role"{
/// Some action based on the Test_Role
}
}
}


}
} catch (oException) {

}

As you can see, we are able to access the user configured roles from this object. Next we could specify some defined behavior based on the user role.

 

I hope this blog might be helpful.

 

Thank you!
14 Comments
Labels in this area