The @rhapsody/permissions package is now available and replaces both calling the Devise.hasPermission/Devise.hasAnyPermission methods and directly accessing devise.current_account.permission_names. The service exposes the hasPermission and hasAnyPermission functions to check a user's assigned permissions.
Example
import { hasAnyPermission, hasPermission } from '@rhapsody/permissions'
function AdminLink() {
if (hasPermission('permission_a')) {
return <a href="/settings/team">Team Settings</a>
} else if (hasAnyPermission(['permission_b', 'permission_c'])) {
return <a href="/settings/superadmin">Superadmin Settings</a>
} else {
return null
}
}
The permissions service is written in Typescript and can be used in JavaScript and Typescript code. New code should use this service and any existing non-Angular code should be refactored to use this service as well. Existing Angular code referencing Devise.hasPermission/Devise.hasAnyPermission or devise.current_account.permission_names can be left as-is since all of these permission checking mechanisms use the permissions service under the hood.