X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/33e999909f177c195d7dab02a70245b7afc866d2..6be2d3f28c2d59987dba8b2b38714a7b9aae7c6b:/app/Auth/Permissions/PermissionService.php diff --git a/app/Auth/Permissions/PermissionService.php b/app/Auth/Permissions/PermissionService.php index af2a5e1fd..b28f59cc5 100644 --- a/app/Auth/Permissions/PermissionService.php +++ b/app/Auth/Permissions/PermissionService.php @@ -556,6 +556,33 @@ class PermissionService return $q; } + /** + * Checks if a user has a book or chapter available to create a page + * @param Ownable $ownable + * @param $permission + * @return bool + */ + public function checkAvailableCreatePageAccess() + { + $userRoleIds = $this->currentUser()->roles()->pluck('id')->toArray(); + $userId = $this->currentUser()->id; + + + $canCreatePage = $this->db->table('joint_permissions') + ->where('action', '=', 'page-create') + ->whereIn('role_id', $userRoleIds) + ->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.