class PermissionService (View source)

Service for managing user permissions

This service provides methods to check and retrieve user permissions using Domain-Driven Design principles.

Constants

TEMPLATE_ASSIGN_DENIED

TEMPLATE_SELF_ASSIGN_DENIED

TEMPLATE_SUPERUSER_DENIED

Methods

__construct(UserRepository $userRepository)

No description

bool
hasPermission(int $userId, string $permissionName)

Check if a user has a specific permission

array
getUserPermissions(int $userId)

Get all permissions for a specific user (direct template and group-based)

bool
canManageGroups(int $userId)

Check whether a user may create, edit or delete groups.

bool
isAdmin(int $userId)

Check if a user is an admin (has the "überuser" permission)

bool
userOwnsZone(int $userId, int $domainId)

Check if a user owns a zone directly or via group membership

bool
canPerformZoneAction(int $userId, int $domainId, string $permissionName)

Whether the user may perform an "_own" action on a zone: the grant comes from the user's template or any of their groups (union), and the zone is owned directly or through any group.

string
getViewPermissionLevel(int $userId)

Get view permission level for a user

string
getEditPermissionLevel(int $userId)

Get edit permission level for a user

string
getEditPermissionLevelForZone(int $userId, int $domainId)

The user's edit level narrowed to one zone: "own" levels apply only when the zone is owned directly or via any group.

string
getZoneMetaEditPermissionLevel(int $userId)

Get zone meta edit permission level for a user

string
getZoneMetadataViewPermissionLevel(int $userId)

Get zone metadata view permission level for a user

string
getZoneOwnershipViewPermissionLevel(int $userId)

Get zone ownership view permission level for a user

bool
canViewOthersContent(int $userId)

Check if user can view other users' content

bool
canCreateZone(int $userId, string $zoneType)

Whether the user may create (or convert a zone into) the given kind.

bool
canAddZoneTemplates(int $userId)

Check if user can add zone templates

bool
canManageUsers(int $userId)

Check if a user may access user management (any view/edit/add grant or admin).

bool
canManageDnssecForZone(int $userId, int $domainId)

DNSSEC key management on a zone: zone_dnssec_manage_own plus ownership (admins always).

bool
canViewZone(int $userId, int $domainId)

Whether the user may open a zone: view_others (or admin), or view_own on a zone owned directly or via any group.

bool
hasZoneContentEditPermission(int $userId, int $domainId)

Whether the user holds a content-edit grant that applies to the zone: edit_others (or admin), or edit_own on an owned zone. own_as_client is NOT included, so this is the gate for record types clients may not touch and never for zone metadata.

bool
canEditZoneContent(int $userId, int $domainId, string|null $zoneType = null)

Whether the user may edit records in the zone. Secondary and Consumer zones replicate from a primary and reject every content edit when the type is known.

bool
canEditZoneRecord(int $userId, int $domainId, string $recordType, string|null $zoneType = null, string|null $recordName = null, string|null $zoneName = null)

canEditZoneContent() plus the own_as_client record-type restriction: SOA/NS/LUA need edit_own or better, except subzone NS records for zone_content_edit_ns_subzone holders. Pass the record and zone names (FQDN) to enable that exemption.

bool
canEditZoneMeta(int $userId, int $domainId)

Zone metadata (name, type, primaries): meta_edit_others (or admin), or meta_edit_own on an owned zone.

bool
canViewZoneMetadata(int $userId, int $domainId)

No description

bool
canViewZoneOwnership(int $userId, int $domainId)

No description

bool
templateGrantsUberuser(int $permTemplId)

No description

string|null
checkPermissionTemplateAssignment(int $actorId, int|null $targetUserId, int $permTemplId)

Why the actor may not put the target on this permission template, or null when allowed. Echoing back an unchanged ordinary template is not a change.

string
getZoneLogPermissionLevel(int $userId)

Zone log access level: "all" (others or admin), "own", or "none".

array
getPermissionFlags(int $userId, array $permissionNames)

Several permissions at once, as name => granted, for templates that branch on them.

string
getDeletePermissionLevel(int $userId)

Get delete permission level for a user

bool
canDeleteZone(int $userId, bool $isOwner)

Check if user can delete a zone

bool
canDeleteZoneById(int $userId, int $domainId)

Whether the user may delete this zone; ownership is looked up only when their delete level depends on it.

Details

__construct(UserRepository $userRepository)

No description

Parameters

UserRepository $userRepository

bool hasPermission(int $userId, string $permissionName)

Check if a user has a specific permission

Parameters

int $userId

User ID to check

string $permissionName

Name of the permission to check

Return Value

bool

True if the user has the permission, false otherwise

array getUserPermissions(int $userId)

Get all permissions for a specific user (direct template and group-based)

Permissions do not change within a request, so they are cached per user to keep repeated checks at a single query.

Parameters

int $userId

User ID to get permissions for

Return Value

array

Array of permission names

bool canManageGroups(int $userId)

Check whether a user may create, edit or delete groups.

Group management is superuser-only, unlike user permission templates which user_edit_templ_perm delegates. Two reasons: that permission is defined as covering the template assigned to users, and a group's template lands in the same global permission union as a user's, so delegating it would hand out a second, unguarded route to superuser.

Parameters

int $userId

User ID to check

Return Value

bool

True if the user may manage groups

bool isAdmin(int $userId)

Check if a user is an admin (has the "überuser" permission)

Parameters

int $userId

User ID to check

Return Value

bool

True if the user is an admin, false otherwise

bool userOwnsZone(int $userId, int $domainId)

Check if a user owns a zone directly or via group membership

Parameters

int $userId

User ID to check

int $domainId

Domain/zone ID

Return Value

bool

True if the user owns the zone

bool canPerformZoneAction(int $userId, int $domainId, string $permissionName)

Whether the user may perform an "_own" action on a zone: the grant comes from the user's template or any of their groups (union), and the zone is owned directly or through any group.

Parameters

int $userId
int $domainId
string $permissionName

Permission name (e.g. 'zone_delete_own')

Return Value

bool

string getViewPermissionLevel(int $userId)

Get view permission level for a user

Parameters

int $userId

User ID to check

Return Value

string

"all", "own", or "none" depending on the user's view permission

string getEditPermissionLevel(int $userId)

Get edit permission level for a user

Parameters

int $userId

User ID to check

Return Value

string

"all", "own", "own_as_client", or "none" depending on the user's edit permission

string getEditPermissionLevelForZone(int $userId, int $domainId)

The user's edit level narrowed to one zone: "own" levels apply only when the zone is owned directly or via any group.

Parameters

int $userId
int $domainId

Return Value

string

"all", "own", "own_as_client", or "none"

string getZoneMetaEditPermissionLevel(int $userId)

Get zone meta edit permission level for a user

Parameters

int $userId

User ID to check

Return Value

string

"all", "own", or "none" depending on the user's meta edit permission

string getZoneMetadataViewPermissionLevel(int $userId)

Get zone metadata view permission level for a user

Holders of zone_metaedit* may always see what they are allowed to edit.

Parameters

int $userId

User ID to check

Return Value

string

"all", "own", or "none" depending on the user's metadata view permission

string getZoneOwnershipViewPermissionLevel(int $userId)

Get zone ownership view permission level for a user

Holders of zone_metaedit* may always see what they are allowed to edit.

Parameters

int $userId

User ID to check

Return Value

string

"all", "own", or "none" depending on the user's ownership view permission

bool canViewOthersContent(int $userId)

Check if user can view other users' content

Parameters

int $userId

User ID to check

Return Value

bool

True if user can view others' content

bool canCreateZone(int $userId, string $zoneType)

Whether the user may create (or convert a zone into) the given kind.

Kinds that replicate from a primary (SLAVE, CONSUMER) are governed by zone_slave_add, the rest by zone_master_add; the add forms use the same split.

Parameters

int $userId
string $zoneType

Return Value

bool

bool canAddZoneTemplates(int $userId)

Check if user can add zone templates

Parameters

int $userId

User ID to check

Return Value

bool

True if user can add zone templates

bool canManageUsers(int $userId)

Check if a user may access user management (any view/edit/add grant or admin).

Parameters

int $userId

User ID to check

Return Value

bool

True if the user may manage other users

bool canManageDnssecForZone(int $userId, int $domainId)

DNSSEC key management on a zone: zone_dnssec_manage_own plus ownership (admins always).

Parameters

int $userId
int $domainId

Return Value

bool

bool canViewZone(int $userId, int $domainId)

Whether the user may open a zone: view_others (or admin), or view_own on a zone owned directly or via any group.

Parameters

int $userId
int $domainId

Return Value

bool

bool hasZoneContentEditPermission(int $userId, int $domainId)

Whether the user holds a content-edit grant that applies to the zone: edit_others (or admin), or edit_own on an owned zone. own_as_client is NOT included, so this is the gate for record types clients may not touch and never for zone metadata.

Parameters

int $userId
int $domainId

Return Value

bool

bool canEditZoneContent(int $userId, int $domainId, string|null $zoneType = null)

Whether the user may edit records in the zone. Secondary and Consumer zones replicate from a primary and reject every content edit when the type is known.

Parameters

int $userId
int $domainId
string|null $zoneType

Return Value

bool

bool canEditZoneRecord(int $userId, int $domainId, string $recordType, string|null $zoneType = null, string|null $recordName = null, string|null $zoneName = null)

canEditZoneContent() plus the own_as_client record-type restriction: SOA/NS/LUA need edit_own or better, except subzone NS records for zone_content_edit_ns_subzone holders. Pass the record and zone names (FQDN) to enable that exemption.

Parameters

int $userId
int $domainId
string $recordType
string|null $zoneType
string|null $recordName
string|null $zoneName

Return Value

bool

bool canEditZoneMeta(int $userId, int $domainId)

Zone metadata (name, type, primaries): meta_edit_others (or admin), or meta_edit_own on an owned zone.

Parameters

int $userId
int $domainId

Return Value

bool

bool canViewZoneMetadata(int $userId, int $domainId)

No description

Parameters

int $userId
int $domainId

Return Value

bool

bool canViewZoneOwnership(int $userId, int $domainId)

No description

Parameters

int $userId
int $domainId

Return Value

bool

bool templateGrantsUberuser(int $permTemplId)

No description

Parameters

int $permTemplId

Return Value

bool

string|null checkPermissionTemplateAssignment(int $actorId, int|null $targetUserId, int $permTemplId)

Why the actor may not put the target on this permission template, or null when allowed. Echoing back an unchanged ordinary template is not a change.

The strings are API contract.

Parameters

int $actorId
int|null $targetUserId
int $permTemplId

Return Value

string|null

string getZoneLogPermissionLevel(int $userId)

Zone log access level: "all" (others or admin), "own", or "none".

Parameters

int $userId

Return Value

string

array getPermissionFlags(int $userId, array $permissionNames)

Several permissions at once, as name => granted, for templates that branch on them.

Parameters

int $userId
array $permissionNames

Return Value

array

string getDeletePermissionLevel(int $userId)

Get delete permission level for a user

Parameters

int $userId

User ID to check

Return Value

string

"all", "own", or "none" depending on the user's delete permission

bool canDeleteZone(int $userId, bool $isOwner)

Check if user can delete a zone

Parameters

int $userId

User ID to check

bool $isOwner

Whether the user owns the zone

Return Value

bool

True if user can delete the zone

bool canDeleteZoneById(int $userId, int $domainId)

Whether the user may delete this zone; ownership is looked up only when their delete level depends on it.

Parameters

int $userId
int $domainId

Return Value

bool