Skip to content

Commit 2b25bf6

Browse files
committed
Merge branch 'master' into release
2 parents f932806 + f8ae4c3 commit 2b25bf6

File tree

20 files changed

+264
-156
lines changed

20 files changed

+264
-156
lines changed

app/Console/Commands/RegeneratePermissions.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ public function handle()
4949
$connection = \DB::getDefaultConnection();
5050
if ($this->option('database') !== null) {
5151
\DB::setDefaultConnection($this->option('database'));
52+
$this->permissionService->setConnection(\DB::connection($this->option('database')));
5253
}
5354

5455
$this->permissionService->buildJointPermissions();

app/Console/Commands/RegenerateSearch.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ public function handle()
4444
$connection = \DB::getDefaultConnection();
4545
if ($this->option('database') !== null) {
4646
\DB::setDefaultConnection($this->option('database'));
47+
$this->searchService->setConnection(\DB::connection($this->option('database')));
4748
}
4849

4950
$this->searchService->indexAllEntities();

app/Entity.php

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -94,17 +94,6 @@ public function hasRestriction($role_id, $action)
9494
->where('action', '=', $action)->count() > 0;
9595
}
9696

97-
/**
98-
* Check if this entity has live (active) restrictions in place.
99-
* @param $role_id
100-
* @param $action
101-
* @return bool
102-
*/
103-
public function hasActiveRestriction($role_id, $action)
104-
{
105-
return $this->getRawAttribute('restricted') && $this->hasRestriction($role_id, $action);
106-
}
107-
10897
/**
10998
* Get the entity jointPermissions this is connected to.
11099
* @return \Illuminate\Database\Eloquent\Relations\MorphMany
@@ -176,5 +165,11 @@ public function getText()
176165
*/
177166
public function entityRawQuery(){return '';}
178167

168+
/**
169+
* Get the url of this entity
170+
* @param $path
171+
* @return string
172+
*/
173+
public function getUrl($path){return '/';}
179174

180175
}

app/Http/Controllers/BookController.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php namespace BookStack\Http\Controllers;
22

33
use Activity;
4+
use BookStack\Book;
45
use BookStack\Repos\EntityRepo;
56
use BookStack\Repos\UserRepo;
67
use BookStack\Services\ExportService;
@@ -207,13 +208,12 @@ public function saveSort($bookSlug, Request $request)
207208

208209
// Add activity for books
209210
foreach ($sortedBooks as $bookId) {
211+
/** @var Book $updatedBook */
210212
$updatedBook = $this->entityRepo->getById('book', $bookId);
213+
$this->entityRepo->buildJointPermissionsForBook($updatedBook);
211214
Activity::add($updatedBook, 'book_sort', $updatedBook->id);
212215
}
213216

214-
// Update permissions on changed models
215-
if (count($updatedModels) === 0) $this->entityRepo->buildJointPermissions($updatedModels);
216-
217217
return redirect($book->getUrl());
218218
}
219219

app/Http/Controllers/HomeController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public function index()
4646
* @return \Illuminate\Contracts\Routing\ResponseFactory|\Symfony\Component\HttpFoundation\Response
4747
*/
4848
public function getTranslations() {
49-
$locale = trans()->getLocale();
49+
$locale = app()->getLocale();
5050
$cacheKey = 'GLOBAL_TRANSLATIONS_' . $locale;
5151
if (cache()->has($cacheKey) && config('app.env') !== 'development') {
5252
$resp = cache($cacheKey);

app/Http/Middleware/Localization.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,17 @@ class Localization
1515
public function handle($request, Closure $next)
1616
{
1717
$defaultLang = config('app.locale');
18-
$locale = setting()->getUser(user(), 'language', $defaultLang);
18+
if (user()->isDefault()) {
19+
$locale = $defaultLang;
20+
$availableLocales = config('app.locales');
21+
foreach ($request->getLanguages() as $lang) {
22+
if (!in_array($lang, $availableLocales)) continue;
23+
$locale = $lang;
24+
break;
25+
}
26+
} else {
27+
$locale = setting()->getUser(user(), 'language', $defaultLang);
28+
}
1929
app()->setLocale($locale);
2030
Carbon::setLocale($locale);
2131
return $next($request);

app/Repos/EntityRepo.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -533,11 +533,11 @@ public function changeBook($type, $newBookId, Entity $entity, $rebuildPermission
533533

534534
/**
535535
* Alias method to update the book jointPermissions in the PermissionService.
536-
* @param Collection $collection collection on entities
536+
* @param Book $book
537537
*/
538-
public function buildJointPermissions(Collection $collection)
538+
public function buildJointPermissionsForBook(Book $book)
539539
{
540-
$this->permissionService->buildJointPermissionsForEntities($collection);
540+
$this->permissionService->buildJointPermissionsForEntity($book);
541541
}
542542

543543
/**
@@ -730,6 +730,7 @@ public function getDraftPage(Book $book, $chapter = false)
730730
if ($chapter) $page->chapter_id = $chapter->id;
731731

732732
$book->pages()->save($page);
733+
$page = $this->page->find($page->id);
733734
$this->permissionService->buildJointPermissionsForEntity($page);
734735
return $page;
735736
}

0 commit comments

Comments
 (0)