Refactored permission system components
Split joint permission creation into chunks Fixes #374
Showing
8 changed files
with
21 additions
and
18 deletions
| ... | @@ -95,17 +95,6 @@ class Entity extends Ownable | ... | @@ -95,17 +95,6 @@ class Entity extends Ownable |
| 95 | } | 95 | } |
| 96 | 96 | ||
| 97 | /** | 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 | - | ||
| 108 | - /** | ||
| 109 | * Get the entity jointPermissions this is connected to. | 98 | * Get the entity jointPermissions this is connected to. |
| 110 | * @return \Illuminate\Database\Eloquent\Relations\MorphMany | 99 | * @return \Illuminate\Database\Eloquent\Relations\MorphMany |
| 111 | */ | 100 | */ |
| ... | @@ -176,5 +165,11 @@ class Entity extends Ownable | ... | @@ -176,5 +165,11 @@ class Entity extends Ownable |
| 176 | */ | 165 | */ |
| 177 | public function entityRawQuery(){return '';} | 166 | public function entityRawQuery(){return '';} |
| 178 | 167 | ||
| 168 | + /** | ||
| 169 | + * Get the url of this entity | ||
| 170 | + * @param $path | ||
| 171 | + * @return string | ||
| 172 | + */ | ||
| 173 | + public function getUrl($path){return '/';} | ||
| 179 | 174 | ||
| 180 | } | 175 | } | ... | ... |
| 1 | <?php namespace BookStack\Http\Controllers; | 1 | <?php namespace BookStack\Http\Controllers; |
| 2 | 2 | ||
| 3 | use Activity; | 3 | use Activity; |
| 4 | +use BookStack\Book; | ||
| 4 | use BookStack\Repos\EntityRepo; | 5 | use BookStack\Repos\EntityRepo; |
| 5 | use BookStack\Repos\UserRepo; | 6 | use BookStack\Repos\UserRepo; |
| 6 | use BookStack\Services\ExportService; | 7 | use BookStack\Services\ExportService; |
| ... | @@ -207,13 +208,12 @@ class BookController extends Controller | ... | @@ -207,13 +208,12 @@ class BookController extends Controller |
| 207 | 208 | ||
| 208 | // Add activity for books | 209 | // Add activity for books |
| 209 | foreach ($sortedBooks as $bookId) { | 210 | foreach ($sortedBooks as $bookId) { |
| 211 | + /** @var Book $updatedBook */ | ||
| 210 | $updatedBook = $this->entityRepo->getById('book', $bookId); | 212 | $updatedBook = $this->entityRepo->getById('book', $bookId); |
| 213 | + $this->entityRepo->buildJointPermissionsForBook($updatedBook); | ||
| 211 | Activity::add($updatedBook, 'book_sort', $updatedBook->id); | 214 | Activity::add($updatedBook, 'book_sort', $updatedBook->id); |
| 212 | } | 215 | } |
| 213 | 216 | ||
| 214 | - // Update permissions on changed models | ||
| 215 | - if (count($updatedModels) === 0) $this->entityRepo->buildJointPermissions($updatedModels); | ||
| 216 | - | ||
| 217 | return redirect($book->getUrl()); | 217 | return redirect($book->getUrl()); |
| 218 | } | 218 | } |
| 219 | 219 | ... | ... |
| ... | @@ -533,11 +533,11 @@ class EntityRepo | ... | @@ -533,11 +533,11 @@ class EntityRepo |
| 533 | 533 | ||
| 534 | /** | 534 | /** |
| 535 | * Alias method to update the book jointPermissions in the PermissionService. | 535 | * Alias method to update the book jointPermissions in the PermissionService. |
| 536 | - * @param Collection $collection collection on entities | 536 | + * @param Book $book |
| 537 | */ | 537 | */ |
| 538 | - public function buildJointPermissions(Collection $collection) | 538 | + public function buildJointPermissionsForBook(Book $book) |
| 539 | { | 539 | { |
| 540 | - $this->permissionService->buildJointPermissionsForEntities($collection); | 540 | + $this->permissionService->buildJointPermissionsForEntity($book); |
| 541 | } | 541 | } |
| 542 | 542 | ||
| 543 | /** | 543 | /** | ... | ... |
This diff is collapsed.
Click to expand it.
| ... | @@ -28,6 +28,12 @@ class DummyContentSeeder extends Seeder | ... | @@ -28,6 +28,12 @@ class DummyContentSeeder extends Seeder |
| 28 | $book->pages()->saveMany($pages); | 28 | $book->pages()->saveMany($pages); |
| 29 | }); | 29 | }); |
| 30 | 30 | ||
| 31 | + $largeBook = factory(\BookStack\Book::class)->create(['name' => 'Large book' . str_random(10), 'created_by' => $user->id, 'updated_by' => $user->id]); | ||
| 32 | + $pages = factory(\BookStack\Page::class, 200)->make(['created_by' => $user->id, 'updated_by' => $user->id]); | ||
| 33 | + $chapters = factory(\BookStack\Chapter::class, 50)->make(['created_by' => $user->id, 'updated_by' => $user->id]); | ||
| 34 | + $largeBook->pages()->saveMany($pages); | ||
| 35 | + $largeBook->chapters()->saveMany($chapters); | ||
| 36 | + | ||
| 31 | app(\BookStack\Services\PermissionService::class)->buildJointPermissions(); | 37 | app(\BookStack\Services\PermissionService::class)->buildJointPermissions(); |
| 32 | app(\BookStack\Services\SearchService::class)->indexAllEntities(); | 38 | app(\BookStack\Services\SearchService::class)->indexAllEntities(); |
| 33 | } | 39 | } | ... | ... |
| ... | @@ -42,7 +42,7 @@ class EntitySearchTest extends TestCase | ... | @@ -42,7 +42,7 @@ class EntitySearchTest extends TestCase |
| 42 | 42 | ||
| 43 | public function test_book_search() | 43 | public function test_book_search() |
| 44 | { | 44 | { |
| 45 | - $book = \BookStack\Book::all()->first(); | 45 | + $book = \BookStack\Book::first(); |
| 46 | $page = $book->pages->last(); | 46 | $page = $book->pages->last(); |
| 47 | $chapter = $book->chapters->last(); | 47 | $chapter = $book->chapters->last(); |
| 48 | 48 | ... | ... |
| ... | @@ -226,6 +226,7 @@ class RestrictionsTest extends BrowserKitTest | ... | @@ -226,6 +226,7 @@ class RestrictionsTest extends BrowserKitTest |
| 226 | ->type('test content', 'html') | 226 | ->type('test content', 'html') |
| 227 | ->press('Save Page') | 227 | ->press('Save Page') |
| 228 | ->seePageIs($chapter->book->getUrl() . '/page/test-page'); | 228 | ->seePageIs($chapter->book->getUrl() . '/page/test-page'); |
| 229 | + | ||
| 229 | $this->visit($chapterUrl)->seeInElement('.action-buttons', 'New Page'); | 230 | $this->visit($chapterUrl)->seeInElement('.action-buttons', 'New Page'); |
| 230 | } | 231 | } |
| 231 | 232 | ... | ... |
-
Please register or sign in to post a comment