User & Permissions
Current User
A current User is provided to the templating system for a data of currently logged in user at the time. A current User can be accessed by calling $CurrentUser in your nunjucks template.
{{ "✅" if $CurrentUser.Name == 'something' else "❌" }}
Permissions
Permissions are supported via a callback to the host application. A NJK helper is provided which can be accessed by calling _.host.hasPermission in your template
{{ "✅" if _.host.hasPermission("edit-this") else "❌" }}
or, from a platform component by importing the hasPermission function from platform core
import { hasPermission } from '@skedulo/horizon-core'
hasPermission('my-permission')
Extended Permission Examples
For more complex permission checking scenarios, you can use specific permission strings and check multiple permissions at once:
import { hasPermission, hasPermissions } from '@skedulo/horizon-core'
const hasSchedulePermission = hasPermission('schedule.tenant.schedule.view')
// For multiple permissions
const canModify = hasPermissions([
'skedulo.tenant.savedViews.viewStates.modify',
'skedulo.tenant.savedViews.viewStates.user.modify',
])
Roles
Roles are supported via a callback to the host application, similar to permissions. NJK helpers are provided which can be accessed by calling _.host.hasRole or _.host.hasRoles in your template.
{{ "✅" if _.host.hasRole("administrator") else "❌" }} {{ "✅" if
_.host.hasRoles(["scheduler", "dispatcher"]) else "❌" }}
You can also use these from a platform component by importing the hasRole and hasRoles functions from platform core:
import { hasRole, hasRoles } from '@skedulo/horizon-core'
const isAdmin = hasRole('administrator')
// For multiple roles
const canSchedule = hasRoles(['scheduler', 'dispatcher'])
Role Examples
Check for specific roles to control access to features:
import { hasRole, hasRoles } from '@skedulo/horizon-core'
// Check single role
const isAdministrator = hasRole('administrator')
const isScheduler = hasRole('scheduler')
// Check multiple roles (user must have all roles)
const canManageSchedule = hasRoles(['scheduler', 'resource'])