mirror of
https://github.com/BookStackApp/BookStack.git
synced 2024-12-02 05:43:40 +08:00
2332401854
Both caught in tests: Fixed loss of permissions for admin users when entity restrictions were active, since there are no entity-restrictions for the admin role but we'd force generate them in joint permissions, which would be queried. Fixed new role permission checks when permissions given with only the action (eg. 'view'), since the type prefix would be required for role permission checks. Was previously not needed as only the simpler form was used in the jointpermissions after merge & calculation.
46 lines
1.1 KiB
PHP
46 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace BookStack\Entities\Tools;
|
|
|
|
use BookStack\Entities\Models\Book;
|
|
use BookStack\Entities\Models\Bookshelf;
|
|
|
|
class ShelfContext
|
|
{
|
|
protected $KEY_SHELF_CONTEXT_ID = 'context_bookshelf_id';
|
|
|
|
/**
|
|
* Get the current bookshelf context for the given book.
|
|
*/
|
|
public function getContextualShelfForBook(Book $book): ?Bookshelf
|
|
{
|
|
$contextBookshelfId = session()->get($this->KEY_SHELF_CONTEXT_ID, null);
|
|
|
|
if (!is_int($contextBookshelfId)) {
|
|
return null;
|
|
}
|
|
|
|
/** @var Bookshelf $shelf */
|
|
$shelf = Bookshelf::visible()->find($contextBookshelfId);
|
|
$shelfContainsBook = $shelf && $shelf->contains($book);
|
|
|
|
return $shelfContainsBook ? $shelf : null;
|
|
}
|
|
|
|
/**
|
|
* Store the current contextual shelf ID.
|
|
*/
|
|
public function setShelfContext(int $shelfId)
|
|
{
|
|
session()->put($this->KEY_SHELF_CONTEXT_ID, $shelfId);
|
|
}
|
|
|
|
/**
|
|
* Clear the session stored shelf context id.
|
|
*/
|
|
public function clearShelfContext()
|
|
{
|
|
session()->forget($this->KEY_SHELF_CONTEXT_ID);
|
|
}
|
|
}
|