Merge branch 'Copy-For-View-Only' of git://github.com/mark-james/BookStack into mark-james-Copy-For-View-Only

This commit is contained in:
Dan Brown
2019-03-09 16:12:12 +00:00
4 changed files with 47 additions and 7 deletions

View File

@ -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.