PHP Class BookStack\Services\PermissionService

Mostrar archivo Open project: ssddanbrown/bookstack Class Usage Examples

Public Properties

Property Type Description
$book
$chapter
$page

Protected Properties

Property Type Description
$currentAction
$currentUserModel
$entityCache
$isAdminUser
$jointPermission
$role
$userRoles

Public Methods

Method Description
__construct ( JointPermission $jointPermission, Book $book, Chapter $chapter, Page $page, Role $role ) PermissionService constructor.
buildJointPermissionForRole ( Role $role ) Build the entity jointPermissions for a particular role.
buildJointPermissions ( ) Re-generate all entity permission from scratch.
buildJointPermissionsForEntities ( Collection $entities ) Rebuild the entity jointPermissions for a collection of entities.
buildJointPermissionsForEntity ( Entity $entity ) Rebuild the entity jointPermissions for a particular entity.
checkIfRestrictionsSet ( Entity $entity, $action ) : boolean | mixed Check if an entity has restrictions set on itself or its parent tree.
checkOwnableUserAccess ( Ownable $ownable, $permission ) : boolean Checks if an entity has a restriction set upon it.
deleteJointPermissionsForEntity ( Entity $entity ) Delete the entity jointPermissions for a particular entity.
deleteJointPermissionsForRole ( Role $role ) Delete the entity jointPermissions attached to a particular role.
enforceBookRestrictions ( $query, string $action = 'view' ) : mixed Add restrictions to a book query.
enforceChapterRestrictions ( $query, string $action = 'view' ) : mixed Add on permission restrictions to a chapter query.
enforceEntityRestrictions ( $query, string $action = 'view' ) : mixed Add restrictions for a generic entity
enforcePageRestrictions ( $query, string $action = 'view' ) : mixed Add restrictions for a page query
filterRelatedPages ( $query, $tableName, $entityIdColumn ) : mixed Filters pages that are a direct relation to another item.
filterRestrictedEntityRelations ( $query, string $tableName, string $entityIdColumn, string $entityTypeColumn ) : mixed Filter items that have entities set a a polymorphic relation.

Protected Methods

Method Description
createJointPermissionData ( Entity $entity, Role $role, $action ) : array Create entity permission data for an entity and role for a particular action.
createJointPermissionDataArray ( Entity $entity, Role $role, $action, $permissionAll, $permissionOwn ) : array Create an array of data with the information of an entity jointPermissions.
createManyJointPermissions ( Collection $entities, Collection $roles ) Create & Save entity jointPermissions for many entities and jointPermissions.
deleteManyJointPermissionsForEntities ( Entity[] $entities ) Delete all of the entity jointPermissions for a list of entities.
deleteManyJointPermissionsForRoles ( Role[] $roles ) Delete all of the entity jointPermissions for a list of entities.
entityRestrictionQuery ( $query ) : mixed The general query filter to remove all entities that the current user does not have access to.
getActions ( $entity ) : array Get the actions related to an entity.
getBook ( $bookId ) : Book Get a book via ID, Checks local cache
getChapter ( $chapterId ) : Book Get a chapter via ID, Checks local cache
getRoles ( ) : array | boolean Get the roles for the current user;
readyEntityCache ( ) Prepare the local entity cache and ensure it's empty

Private Methods

Method Description
clean ( ) Clean the cached user elements.
currentUser ( ) : User Get the current user
isAdmin ( ) : boolean Check if the current user is an admin.

Method Details

__construct() public method

PermissionService constructor.
public __construct ( JointPermission $jointPermission, Book $book, Chapter $chapter, Page $page, Role $role )
$jointPermission BookStack\JointPermission
$book BookStack\Book
$chapter BookStack\Chapter
$page BookStack\Page
$role BookStack\Role

buildJointPermissionForRole() public method

Build the entity jointPermissions for a particular role.
public buildJointPermissionForRole ( Role $role )
$role BookStack\Role

buildJointPermissions() public method

Re-generate all entity permission from scratch.

buildJointPermissionsForEntities() public method

Rebuild the entity jointPermissions for a collection of entities.
public buildJointPermissionsForEntities ( Collection $entities )
$entities Illuminate\Support\Collection

buildJointPermissionsForEntity() public method

Rebuild the entity jointPermissions for a particular entity.
public buildJointPermissionsForEntity ( Entity $entity )
$entity BookStack\Entity

checkIfRestrictionsSet() public method

Check if an entity has restrictions set on itself or its parent tree.
public checkIfRestrictionsSet ( Entity $entity, $action ) : boolean | mixed
$entity BookStack\Entity
$action
return boolean | mixed

checkOwnableUserAccess() public method

Checks if an entity has a restriction set upon it.
public checkOwnableUserAccess ( Ownable $ownable, $permission ) : boolean
$ownable BookStack\Ownable
$permission
return boolean

createJointPermissionData() protected method

Create entity permission data for an entity and role for a particular action.
protected createJointPermissionData ( Entity $entity, Role $role, $action ) : array
$entity BookStack\Entity
$role BookStack\Role
$action
return array

createJointPermissionDataArray() protected method

Used to build data for bulk insertion.
protected createJointPermissionDataArray ( Entity $entity, Role $role, $action, $permissionAll, $permissionOwn ) : array
$entity BookStack\Entity
$role BookStack\Role
$action
$permissionAll
$permissionOwn
return array

createManyJointPermissions() protected method

Create & Save entity jointPermissions for many entities and jointPermissions.
protected createManyJointPermissions ( Collection $entities, Collection $roles )
$entities Illuminate\Support\Collection
$roles Illuminate\Support\Collection

deleteJointPermissionsForEntity() public method

Delete the entity jointPermissions for a particular entity.
public deleteJointPermissionsForEntity ( Entity $entity )
$entity BookStack\Entity

deleteJointPermissionsForRole() public method

Delete the entity jointPermissions attached to a particular role.
public deleteJointPermissionsForRole ( Role $role )
$role BookStack\Role

deleteManyJointPermissionsForEntities() protected method

Delete all of the entity jointPermissions for a list of entities.
protected deleteManyJointPermissionsForEntities ( Entity[] $entities )
$entities BookStack\Entity[]

deleteManyJointPermissionsForRoles() protected method

Delete all of the entity jointPermissions for a list of entities.
protected deleteManyJointPermissionsForRoles ( Role[] $roles )
$roles BookStack\Role[]

enforceBookRestrictions() public method

Add restrictions to a book query.
public enforceBookRestrictions ( $query, string $action = 'view' ) : mixed
$query
$action string
return mixed

enforceChapterRestrictions() public method

Add on permission restrictions to a chapter query.
public enforceChapterRestrictions ( $query, string $action = 'view' ) : mixed
$query
$action string
return mixed

enforceEntityRestrictions() public method

Add restrictions for a generic entity
public enforceEntityRestrictions ( $query, string $action = 'view' ) : mixed
$query
$action string
return mixed

enforcePageRestrictions() public method

Add restrictions for a page query
public enforcePageRestrictions ( $query, string $action = 'view' ) : mixed
$query
$action string
return mixed

entityRestrictionQuery() protected method

The general query filter to remove all entities that the current user does not have access to.
protected entityRestrictionQuery ( $query ) : mixed
$query
return mixed

filterRelatedPages() public method

Filters pages that are a direct relation to another item.
public filterRelatedPages ( $query, $tableName, $entityIdColumn ) : mixed
$query
$tableName
$entityIdColumn
return mixed

filterRestrictedEntityRelations() public method

Filter items that have entities set a a polymorphic relation.
public filterRestrictedEntityRelations ( $query, string $tableName, string $entityIdColumn, string $entityTypeColumn ) : mixed
$query
$tableName string
$entityIdColumn string
$entityTypeColumn string
return mixed

getActions() protected method

Get the actions related to an entity.
protected getActions ( $entity ) : array
$entity
return array

getBook() protected method

Get a book via ID, Checks local cache
protected getBook ( $bookId ) : Book
$bookId
return BookStack\Book

getChapter() protected method

Get a chapter via ID, Checks local cache
protected getChapter ( $chapterId ) : Book
$chapterId
return BookStack\Book

getRoles() protected method

Get the roles for the current user;
protected getRoles ( ) : array | boolean
return array | boolean

readyEntityCache() protected method

Prepare the local entity cache and ensure it's empty
protected readyEntityCache ( )

Property Details

$book public_oe property

public $book

$chapter public_oe property

public $chapter

$currentAction protected_oe property

protected $currentAction

$currentUserModel protected_oe property

protected $currentUserModel

$entityCache protected_oe property

protected $entityCache

$isAdminUser protected_oe property

protected $isAdminUser

$jointPermission protected_oe property

protected $jointPermission

$page public_oe property

public $page

$role protected_oe property

protected $role

$userRoles protected_oe property

protected $userRoles