1
0
mirror of https://github.com/BookStackApp/BookStack.git synced 2025-07-31 15:24:31 +03:00

Added ability to copy a page

In 'More' menu alongside move.
Allows you to move if you have permission to create within the new
target parent.
Closes #673
This commit is contained in:
Dan Brown
2018-04-14 18:00:16 +01:00
parent d34b91f2c9
commit 0f7b0ad45a
17 changed files with 243 additions and 57 deletions

View File

@ -67,7 +67,7 @@ class SearchService
* @param int $count - Count of each entity to search, Total returned could can be larger and not guaranteed.
* @return array[int, Collection];
*/
public function searchEntities($searchString, $entityType = 'all', $page = 1, $count = 20)
public function searchEntities($searchString, $entityType = 'all', $page = 1, $count = 20, $action = 'view')
{
$terms = $this->parseSearchString($searchString);
$entityTypes = array_keys($this->entities);
@ -87,8 +87,8 @@ class SearchService
if (!in_array($entityType, $entityTypes)) {
continue;
}
$search = $this->searchEntityTable($terms, $entityType, $page, $count);
$entityTotal = $this->searchEntityTable($terms, $entityType, $page, $count, true);
$search = $this->searchEntityTable($terms, $entityType, $page, $count, $action);
$entityTotal = $this->searchEntityTable($terms, $entityType, $page, $count, $action, true);
if ($entityTotal > $page * $count) {
$hasMore = true;
}
@ -147,12 +147,13 @@ class SearchService
* @param string $entityType
* @param int $page
* @param int $count
* @param string $action
* @param bool $getCount Return the total count of the search
* @return \Illuminate\Database\Eloquent\Collection|int|static[]
*/
public function searchEntityTable($terms, $entityType = 'page', $page = 1, $count = 20, $getCount = false)
public function searchEntityTable($terms, $entityType = 'page', $page = 1, $count = 20, $action = 'view', $getCount = false)
{
$query = $this->buildEntitySearchQuery($terms, $entityType);
$query = $this->buildEntitySearchQuery($terms, $entityType, $action);
if ($getCount) {
return $query->count();
}
@ -165,9 +166,10 @@ class SearchService
* Create a search query for an entity
* @param array $terms
* @param string $entityType
* @param string $action
* @return \Illuminate\Database\Eloquent\Builder
*/
protected function buildEntitySearchQuery($terms, $entityType = 'page')
protected function buildEntitySearchQuery($terms, $entityType = 'page', $action = 'view')
{
$entity = $this->getEntity($entityType);
$entitySelect = $entity->newQuery();
@ -212,7 +214,7 @@ class SearchService
}
}
return $this->permissionService->enforceEntityRestrictions($entityType, $entitySelect, 'view');
return $this->permissionService->enforceEntityRestrictions($entityType, $entitySelect, $action);
}