Skip to content

PermissionUtility

App\Utilities\PermissionUtility

Get User rMain Role

php
PermissionUtility::getUserMainRole($userId, $langTag);
Parameter NameTypeRequiredDescription
userIdNumberrequiredusers->id
langTagStringoptionalWhat language is the role name in
  • If the main role has an expiration time and has expired, output the inherited role.
  • If there is no inherited role (or the inherited ID cannot find a role), use the role specified by the default_role key value in the configuration table.
  • If the configuration table key value is empty (or the role cannot be found), output null.

Get User All Roles

php
PermissionUtility::getUserRoles($userId, $langTag);
Parameter NameTypeRequiredDescription
userIdNumberrequiredusers->id
langTagStringoptionalWhat language is the role name in
  • Only output the list of roles within the valid period, including the main role.

Get Group IDs Not Displayed

php
PermissionUtility::getGroupFilterIds($userId);
Parameter NameTypeRequiredDescription
userIdNumberoptionalusers->id

Get Group IDs Excluding Posts

php
PermissionUtility::getPostFilterByGroupIds($userId);
Parameter NameTypeRequiredDescription
userIdNumberoptionalusers->id

Determine if User Belongs to Account

php
PermissionUtility::checkUserAffiliation($userId, $accountId);
Parameter NameTypeRequiredDescription
userIdNumberrequiredusers->id
accountIdNumberrequiredaccounts->id

Determine User Permissions

php
PermissionUtility::checkUserPerm($userId, $permUserIds);
Parameter NameTypeRequiredDescription
userIdNumberrequiredusers->id
permUserIdsArrayoptionalID array of authorised users ["1","2"]

Pass the user IDs with permissions and the user IDs to be confirmed as parameters. This function will check if the user IDs are included in the authorized IDs.

Determine User Role Permissions

php
PermissionUtility::checkUserRolePerm($userId, $permRoleIds);
Parameter NameTypeRequiredDescription
userIdNumberrequiredusers->id
permRoleIdsArrayrequiredID array of authorised roles ["1","2"]

Pass the role IDs with permissions and the user IDs to be confirmed as parameters. This function will check if all roles under the username have authorized roles.

Determine User Conversation Permissions

php
PermissionUtility::checkUserConversationPerm($receiveUserId, $authUserId, $langTag);
Parameter NameTypeRequiredDescription
receiveUserIdNumberrequiredRecipient users->id
authUserIdNumberrequiredSender users->id
langTagStringoptionalLanguage used for the prompt
View Result
  • If authorized, the output will be 0
  • If unauthorized, output the corresponding Error Code

Determine if User is Group Administrator

php
PermissionUtility::checkUserGroupAdmin($groupId, $userId);
Parameter NameTypeRequiredDescription
groupIdNumberrequiredgroups->id
userIdNumberrequiredusers->id

Determine if User Has Group Publish Permissions

php
PermissionUtility::checkUserGroupPublishPerm($groupId, $permissions, $userId);
Parameter NameTypeRequiredDescription
groupIdNumberrequiredgroups->id
permissionsArrayrequiredgroups->permissions
userIdNumberrequiredusers->id
View Result
json
{
    "allowPost": true, // Can post
    "reviewPost": false, // Post needs review
    "allowComment": true, // Can comment
    "reviewComment": false, // Comment needs review
}

Determine Post Reading Permissions

php
PermissionUtility::checkPostAuth($postId, $userId);
Parameter NameTypeRequiredDescription
postIdNumberrequiredposts->id
userIdNumberrequiredusers->id

For posts that require authorization, determine if the current user meets the authorization requirements

Determine if Post Can Be Commented On

php
PermissionUtility::checkPostCommentPerm($pidOrPostId, $userId);
Parameter NameTypeRequiredDescription
pidOrPostIdstringoptionalposts->id
userIdNumberoptionalusers->id

Determine Content Editing Status

php
PermissionUtility::checkContentEditPerm($createdDatetime, $editTimeConfig, $timezone, $langTag);
Parameter NameTypeRequiredDescription
createdDatetimeCarbonrequiredposts->created_at or comments->created_at
editTimeConfigNumberrequiredpost_edit_time_limit or comment_edit_time_limit
timezoneStringoptionalIf empty, the database time zone is used.
langTagStringoptionalIf empty, the default language is used.

Determine Extension Permissions

php
PermissionUtility::checkExtendPerm($fskey, $usageType, $groupId, $userId);
Parameter NameTypeRequiredDescription
fskeyStringrequiredPlugin Fskey
usageTypeNumberrequiredplugin_usages->usage_type
groupIdNumberoptionalGroup ID groups->id
userIdNumberoptionalUser ID users->id

Released under the Apache-2.0 License