Domains do not get assigned correctly if the user is assigned the role through a group assignment.
Steps to Reproduce
Activate the Domain Support - Domain Extensions Installer plugin.
Create a new group (GroupA) and add a role to it (RoleA).
Switch the domain to one of the subdomains (for example, TOP/ACME).
Go to sys_user table and go to user record who is in that domain (acme.itil).
From the Roles related list, click Edit and add RoleA to the user.
Personalize the related list and add the Domain and Domain Path fields.
Note that they show the domain and domain path of the user (User role record).
Switch to the Group related list, click Edit, and add GroupA.
Personalize the fields and add Domain and Domain path.
Note that they show the same domain as the user.
Go back to the Roles related list.
Note that the role that got added through the group (Role A, which has inherited true) is in the global domain. Therefore, if the user in one domain goes to the role record from here, that user is able to see the users in other domain with that role.
The role that got added through the group also should be in the correct domain as that of the user, but instead, the User role record shows the domain as global.
Write a script to iterate through all the sys_user records and fix the sys_user_has_role.sys_domain values.
- Loop through the sys_user records using a GlideRecord query.
- For each user, the script can get the sys_domain value from the sys_user table.
- Check that the sys_user_has_role.sys_domain field value for the current user in the loop.
- If it is not the same as sys_user.sys_domain field's value, update the sys_user_has_role.sys_domain field value to keep it in sync with sys_user.sys_domain value.
- If your instance is on V1 Role plugin(Contextual Security/com.glide.role_management), the issue should occur only when someone is editing the sys_user_role_contains records.
- If your instance is on V2 Role plugin(com.glide.role_management.inh_count), the sys_user and sys_user_has_role will be in sync only after this fix. Most likely all other operations on roles would cause this issue.
IMPORTANT: Do not remove/delete the sys_domain column from sys_user_has_role table as a fix to this issue. That is NOT the workaround for this issues.
Related Problem: PRB997761