Get Role of User who Opens an Entity

Hi,

I have two entities Reports & Failures that extend an Incidents Entity. From the Incidents Browse Screen, I have two create buttons - one that opens the Reports Edit Screen and the other the Failures Edit Screen and they will all be listed under Incidents Browser. If you select one of them to open,the Incidents Browser Edit Button opens the Incidents Edit Screen but all fields are uneditable. This works fine so far.

The Incidents Entity has a Status Enumeration with New, Viewed, Pending Assignment & Assigned as the options. When I create an Incident (either Report or Failure), they automatically get the New Status.

I would like to automatically change the status to Viewed if a user with the Supervisor Role opens the incident. Regardless of whether they’ll assign it or not. This way, they can always be notified of the incidences that they have opened and those that they haven’t. How can I achieve this?

I am only able to get the createdByTs on the system properties but I don’t know how I can get to the roles.

Regards,
Kenince

Hi Kenince,

You can get the list of all role names from UserSession and use it in your check:

@Inject
private UserSession userSession;

if (userSession.getRoles().contains("Supervisor ")) {
    showNotification("Status changed to Viewed");
}

But the more elegant solution would be using Specific permissions: you define a named permission, set it for the Supervisor role, and in your controller code programmatically change the status to Viewed if isSpecificPermitted() returns true.

Thanks @shiryaeva, using Specific Permissions did the trick. Thanks for pointing it out.

1 Like