- ->where(function ($query) use ($userId) {
- $query->where('has_permission', '=', 1)
- ->orWhere(function ($query2) use ($userId) {
- $query2->where('has_permission_own', '=', 1)
- ->where('created_by', '=', $userId);
- });
- })
- ->get()->count() > 0;
-
- return $canCreatePage;
- }
-
- /**
- * Check if an entity has restrictions set on itself or its
- * parent tree.
- * @param \BookStack\Entities\Entity $entity
- * @param $action
- * @return bool|mixed
- */
- public function checkIfRestrictionsSet(Entity $entity, $action)
- {
- $this->currentAction = $action;
- if ($entity->isA('page')) {
- return $entity->restricted || ($entity->chapter && $entity->chapter->restricted) || $entity->book->restricted;
- } elseif ($entity->isA('chapter')) {
- return $entity->restricted || $entity->book->restricted;
- } elseif ($entity->isA('book')) {
- return $entity->restricted;
+ ->where(function (Builder $query) use ($userId) {
+ $this->addJointHasPermissionCheck($query, $userId);
+ });
+
+ if (!is_null($entityClass)) {
+ $entityInstance = app($entityClass);
+ $permissionQuery = $permissionQuery->where('entity_type', '=', $entityInstance->getMorphClass());