CheckRole against Inactive users

Hi there,

Wondering if anyone can assist or has encountered similar issues.

Within my user management screens I have the need for my System Administration Role to grant and revoke roles of active users and inactive users (those that have left the organisation).

I have an edit function for each user in the app and their roles, when you click on the user name link it reveals edit user roles and allows the System Admin to grant or revoke roles by selecting/unselecting the checkbox(s) and pressing save.

The issue is when the User.Is_Active = False, then the checkboxes are not displaying the roles for the Inactive users, it works fine for Active users. I am using the CheckRole(Role.Id, User.Id). On debug it is returning False against the roles even though they have them.

Guess my question is, can you use the CheckRole function if a user in Inactive?


Solution

No you can not. Since the user is inactive, they essentially don't have any roles.

Solution

Stacey's response is correct - the user has no roles granted if they are inactive.

But if you want to introspect what roles they would have if they were made active, then what you can do is to add a reference to the User_Effective_Role system entity. This entity relates UserId and RoleId, and already accounts for roles that are inherited due to a group membership. It will give you the same results as you can see in the Users application.

leonardo.fernandes wrote:

Stacey's response is correct - the user has no roles granted if they are inactive.

But if you want to introspect what roles they would have if they were made active, then what you can do is to add a reference to the User_Effective_Role system entity. This entity relates UserId and RoleId, and already accounts for roles that are inherited due to a group membership. It will give you the same results as you can see in the Users application.


Thanks Stacey/Leonardo...very helpful and thanks for the confirmation. That was my frustration that I can see the roles in the Users application but couldnt return the values in the front end. I will take a look at the User_Effective_Role although I have been using the User_Role entity.

I think my solution is to check if the user is inactive, to reactivate them, revoke the roles and then inactive them right away in the same action.