From 919660678bec2b94eaa84ac60d0313f5ef07dfb7 Mon Sep 17 00:00:00 2001
From: Dan Brown
Date: Tue, 25 Sep 2018 12:30:50 +0100
Subject: [PATCH] Re-structured the app code to be feature based rather than
code type based
---
app/{ => Actions}/Activity.php | 5 +-
app/{Services => Actions}/ActivityService.php | 9 +-
app/{ => Actions}/Comment.php | 4 +-
app/{Repos => Actions}/CommentRepo.php | 22 ++--
app/{ => Actions}/Tag.php | 4 +-
app/{Repos => Actions}/TagRepo.php | 17 ++-
app/{ => Actions}/View.php | 4 +-
app/{Services => Actions}/ViewService.php | 17 +--
.../Access}/EmailConfirmationService.php | 12 +-
app/{Services => Auth/Access}/Ldap.php | 2 +-
app/{Services => Auth/Access}/LdapService.php | 18 +--
.../Access}/SocialAuthService.php | 8 +-
.../Permissions}/EntityPermission.php | 4 +-
.../Permissions}/JointPermission.php | 6 +-
.../Permissions}/PermissionService.php | 54 +++++----
.../Permissions}/PermissionsRepo.php | 13 +-
app/{ => Auth/Permissions}/RolePermission.php | 5 +-
app/{ => Auth}/Role.php | 16 ++-
app/{ => Auth}/SocialAccount.php | 5 +-
app/{ => Auth}/User.php | 6 +-
app/{Repos => Auth}/UserRepo.php | 23 ++--
app/Console/Commands/CleanupImages.php | 4 +-
app/Console/Commands/ClearActivity.php | 2 +-
app/Console/Commands/ClearRevisions.php | 2 +-
app/Console/Commands/CreateAdmin.php | 2 +-
app/Console/Commands/DeleteUsers.php | 4 +-
.../Commands/RegeneratePermissions.php | 4 +-
app/Console/Commands/RegenerateSearch.php | 4 +-
app/{ => Entities}/Book.php | 14 ++-
app/{ => Entities}/Bookshelf.php | 13 +-
app/{ => Entities}/Chapter.php | 15 ++-
app/{ => Entities}/Entity.php | 22 +++-
app/Entities/EntityProvider.php | 7 ++
app/{Repos => Entities}/EntityRepo.php | 111 +++++++++---------
app/{Services => Entities}/ExportService.php | 21 ++--
app/{ => Entities}/Page.php | 19 ++-
app/{ => Entities}/PageRevision.php | 6 +-
app/{Services => Entities}/SearchService.php | 21 ++--
app/{ => Entities}/SearchTerm.php | 4 +-
app/{Services => }/Facades/Activity.php | 2 +-
app/{Services => }/Facades/Images.php | 2 +-
app/{Services => }/Facades/Setting.php | 2 +-
app/{Services => }/Facades/Views.php | 2 +-
app/Http/Controllers/AttachmentController.php | 8 +-
app/Http/Controllers/Auth/LoginController.php | 10 +-
.../Controllers/Auth/RegisterController.php | 20 ++--
app/Http/Controllers/BookController.php | 12 +-
app/Http/Controllers/BookshelfController.php | 14 +--
app/Http/Controllers/ChapterController.php | 8 +-
app/Http/Controllers/CommentController.php | 8 +-
app/Http/Controllers/Controller.php | 2 +-
app/Http/Controllers/HomeController.php | 2 +-
app/Http/Controllers/ImageController.php | 6 +-
app/Http/Controllers/PageController.php | 10 +-
app/Http/Controllers/PermissionController.php | 4 +-
app/Http/Controllers/SearchController.php | 8 +-
app/Http/Controllers/SettingController.php | 2 +-
app/Http/Controllers/TagController.php | 2 +-
app/Http/Controllers/UserController.php | 10 +-
app/Ownable.php | 2 +
app/Providers/AppServiceProvider.php | 24 +++-
app/Providers/AuthServiceProvider.php | 2 +-
app/Providers/CustomFacadeProvider.php | 18 +--
app/Providers/LdapUserProvider.php | 10 +-
app/{ => Settings}/Setting.php | 4 +-
app/{Services => Settings}/SettingService.php | 10 +-
app/{ => Uploads}/Attachment.php | 5 +-
.../AttachmentService.php | 5 +-
app/{ => Uploads}/Image.php | 3 +-
app/{Repos => Uploads}/ImageRepo.php | 14 +--
app/{Services => Uploads}/ImageService.php | 9 +-
app/{Services => Uploads}/UploadService.php | 4 +-
app/helpers.php | 10 +-
config/app.php | 8 +-
config/auth.php | 2 +-
config/services.php | 2 +-
database/factories/ModelFactory.php | 18 +--
...15_12_07_195238_add_image_upload_types.php | 2 +-
..._08_04_115700_create_bookshelves_table.php | 12 +-
database/seeds/DummyContentSeeder.php | 28 ++---
database/seeds/LargeContentSeeder.php | 14 +--
.../views/components/page-picker.blade.php | 2 +-
resources/views/errors/404.blade.php | 6 +-
resources/views/settings/index.blade.php | 4 +-
tests/ActivityTrackingTest.php | 6 +-
tests/AttachmentTest.php | 14 +--
tests/Auth/AuthTest.php | 7 +-
tests/Auth/LdapTest.php | 6 +-
tests/Auth/SocialAuthTest.php | 6 +-
tests/BrowserKitTest.php | 19 +--
tests/CommandsTest.php | 8 +-
tests/Entity/BookShelfTest.php | 4 +-
tests/Entity/CommentSettingTest.php | 2 +-
tests/Entity/CommentTest.php | 6 +-
tests/Entity/EntitySearchTest.php | 16 +--
tests/Entity/EntityTest.php | 10 +-
tests/Entity/ExportTest.php | 4 +-
tests/Entity/MarkdownTest.php | 2 +-
tests/Entity/PageContentTest.php | 4 +-
tests/Entity/PageDraftTest.php | 10 +-
tests/Entity/PageRevisionTest.php | 2 +-
tests/Entity/SortTest.php | 8 +-
tests/Entity/TagTest.php | 12 +-
tests/ImageTest.php | 8 +-
tests/Permissions/RestrictionsTest.php | 46 ++++----
tests/Permissions/RolesTest.php | 80 ++++++-------
tests/PublicActionTest.php | 20 ++--
tests/SharedTestHelpers.php | 30 ++---
tests/UserProfileTest.php | 4 +-
109 files changed, 684 insertions(+), 531 deletions(-)
rename app/{ => Actions}/Activity.php (93%)
rename app/{Services => Actions}/ActivityService.php (96%)
rename app/{ => Actions}/Comment.php (94%)
rename app/{Repos => Actions}/CommentRepo.php (76%)
rename app/{ => Actions}/Tag.php (85%)
rename app/{Repos => Actions}/TagRepo.php (91%)
rename app/{ => Actions}/View.php (82%)
rename app/{Services => Actions}/ViewService.php (85%)
rename app/{Services => Auth/Access}/EmailConfirmationService.php (93%)
rename app/{Services => Auth/Access}/Ldap.php (98%)
rename app/{Services => Auth/Access}/LdapService.php (96%)
rename app/{Services => Auth/Access}/SocialAuthService.php (98%)
rename app/{ => Auth/Permissions}/EntityPermission.php (84%)
rename app/{ => Auth/Permissions}/JointPermission.php (80%)
rename app/{Services => Auth/Permissions}/PermissionService.php (95%)
rename app/{Repos => Auth/Permissions}/PermissionsRepo.php (93%)
rename app/{ => Auth/Permissions}/RolePermission.php (83%)
rename app/{ => Auth}/Role.php (77%)
rename app/{ => Auth}/SocialAccount.php (71%)
rename app/{ => Auth}/User.php (97%)
rename app/{Repos => Auth}/UserRepo.php (94%)
rename app/{ => Entities}/Book.php (91%)
rename app/{ => Entities}/Bookshelf.php (91%)
rename app/{ => Entities}/Chapter.php (86%)
rename app/{ => Entities}/Entity.php (88%)
create mode 100644 app/Entities/EntityProvider.php
rename app/{Repos => Entities}/EntityRepo.php (94%)
rename app/{Services => Entities}/ExportService.php (94%)
rename app/{ => Entities}/Page.php (89%)
rename app/{ => Entities}/PageRevision.php (93%)
rename app/{Services => Entities}/SearchService.php (97%)
rename app/{ => Entities}/SearchTerm.php (85%)
rename app/{Services => }/Facades/Activity.php (85%)
rename app/{Services => }/Facades/Images.php (85%)
rename app/{Services => }/Facades/Setting.php (85%)
rename app/{Services => }/Facades/Views.php (85%)
rename app/{ => Settings}/Setting.php (68%)
rename app/{Services => Settings}/SettingService.php (97%)
rename app/{ => Uploads}/Attachment.php (90%)
rename app/{Services => Uploads}/AttachmentService.php (98%)
rename app/{ => Uploads}/Image.php (88%)
rename app/{Repos => Uploads}/ImageRepo.php (95%)
rename app/{Services => Uploads}/ImageService.php (98%)
rename app/{Services => Uploads}/UploadService.php (93%)
diff --git a/app/Activity.php b/app/Actions/Activity.php
similarity index 93%
rename from app/Activity.php
rename to app/Actions/Activity.php
index c01da1f6c..1ae1811e1 100644
--- a/app/Activity.php
+++ b/app/Actions/Activity.php
@@ -1,6 +1,9 @@
permissionService->filterRestrictedEntityRelations($this->view, 'views', 'viewable_id', 'viewable_type', $action)
->select('*', 'viewable_id', 'viewable_type', \DB::raw('SUM(views) as view_count'))
@@ -65,7 +66,7 @@ class ViewService
if ($filterModel && is_array($filterModel)) {
$query->whereIn('viewable_type', $filterModel);
} else if ($filterModel) {
- $query->where('viewable_type', '=', get_class($filterModel));
+ $query->where('viewable_type', '=', $filterModel->getMorphClass());
}
return $query->with('viewable')->skip($skipCount)->take($count)->get()->pluck('viewable');
@@ -89,7 +90,7 @@ class ViewService
->filterRestrictedEntityRelations($this->view, 'views', 'viewable_id', 'viewable_type');
if ($filterModel) {
- $query = $query->where('viewable_type', '=', get_class($filterModel));
+ $query = $query->where('viewable_type', '=', $filterModel->getMorphClass());
}
$query = $query->where('user_id', '=', $user->id);
diff --git a/app/Services/EmailConfirmationService.php b/app/Auth/Access/EmailConfirmationService.php
similarity index 93%
rename from app/Services/EmailConfirmationService.php
rename to app/Auth/Access/EmailConfirmationService.php
index 9ee69ef1a..b14eb8c3f 100644
--- a/app/Services/EmailConfirmationService.php
+++ b/app/Auth/Access/EmailConfirmationService.php
@@ -1,11 +1,11 @@
-ldap = $ldap;
$this->config = config('services.ldap');
@@ -298,7 +300,7 @@ class LdapService
/**
* Sync the LDAP groups to the user roles for the current user
- * @param \BookStack\User $user
+ * @param \BookStack\Auth\User $user
* @param string $username
* @throws LdapException
*/
@@ -347,7 +349,7 @@ class LdapService
/**
* Check a role against an array of group names to see if it matches.
* Checked against role 'external_auth_id' if set otherwise the name of the role.
- * @param Role $role
+ * @param \BookStack\Auth\Role $role
* @param array $groupNames
* @return bool
*/
diff --git a/app/Services/SocialAuthService.php b/app/Auth/Access/SocialAuthService.php
similarity index 98%
rename from app/Services/SocialAuthService.php
rename to app/Auth/Access/SocialAuthService.php
index 9017dfebe..005380f5b 100644
--- a/app/Services/SocialAuthService.php
+++ b/app/Auth/Access/SocialAuthService.php
@@ -1,11 +1,11 @@
-currentAction = 'view';
$tableDetails = ['tableName' => $tableName, 'entityIdColumn' => $entityIdColumn];
- $q = $query->where(function ($query) use ($tableDetails) {
- $query->where(function ($query) use (&$tableDetails) {
- $query->whereExists(function ($permissionQuery) use (&$tableDetails) {
+ $pageMorphClass = $this->page->getMorphClass();
+ $q = $query->where(function ($query) use ($tableDetails, $pageMorphClass) {
+ $query->where(function ($query) use (&$tableDetails, $pageMorphClass) {
+ $query->whereExists(function ($permissionQuery) use (&$tableDetails, $pageMorphClass) {
$permissionQuery->select('id')->from('joint_permissions')
->whereRaw('joint_permissions.entity_id=' . $tableDetails['tableName'] . '.' . $tableDetails['entityIdColumn'])
- ->where('entity_type', '=', 'Bookstack\\Page')
+ ->where('entity_type', '=', $pageMorphClass)
->where('action', '=', $this->currentAction)
->whereIn('role_id', $this->getRoles())
->where(function ($query) {
@@ -726,7 +728,7 @@ class PermissionService
/**
* Get the current user
- * @return User
+ * @return \BookStack\Auth\User
*/
private function currentUser()
{
diff --git a/app/Repos/PermissionsRepo.php b/app/Auth/Permissions/PermissionsRepo.php
similarity index 93%
rename from app/Repos/PermissionsRepo.php
rename to app/Auth/Permissions/PermissionsRepo.php
index 68c9270be..98a8a9f14 100644
--- a/app/Repos/PermissionsRepo.php
+++ b/app/Auth/Permissions/PermissionsRepo.php
@@ -1,9 +1,10 @@
-permission = $permission;
$this->role = $role;
diff --git a/app/RolePermission.php b/app/Auth/Permissions/RolePermission.php
similarity index 83%
rename from app/RolePermission.php
rename to app/Auth/Permissions/RolePermission.php
index 366c16749..8b07b3073 100644
--- a/app/RolePermission.php
+++ b/app/Auth/Permissions/RolePermission.php
@@ -1,4 +1,7 @@
-belongsToMany(RolePermission::class, 'permission_role', 'role_id', 'permission_id');
+ return $this->belongsToMany(Permissions\RolePermission::class, 'permission_role', 'role_id', 'permission_id');
}
/**
@@ -48,18 +52,18 @@ class Role extends Model
/**
* Add a permission to this role.
- * @param RolePermission $permission
+ * @param \BookStack\Auth\Permissions\RolePermission $permission
*/
- public function attachPermission(RolePermission $permission)
+ public function attachPermission(Permissions\RolePermission $permission)
{
$this->permissions()->attach($permission->id);
}
/**
* Detach a single permission from this role.
- * @param RolePermission $permission
+ * @param \BookStack\Auth\Permissions\RolePermission $permission
*/
- public function detachPermission(RolePermission $permission)
+ public function detachPermission(Permissions\RolePermission $permission)
{
$this->permissions()->detach($permission->id);
}
diff --git a/app/SocialAccount.php b/app/Auth/SocialAccount.php
similarity index 71%
rename from app/SocialAccount.php
rename to app/Auth/SocialAccount.php
index fdba6a04f..7d0dbaafc 100644
--- a/app/SocialAccount.php
+++ b/app/Auth/SocialAccount.php
@@ -1,4 +1,7 @@
- $rawEntity) {
- if ($rawEntity->entity_type === 'BookStack\\Page') {
+ if ($rawEntity->entity_type === $this->page->getMorphClass()) {
$entities[$index] = $this->page->newFromBuilder($rawEntity);
if ($renderPages) {
$entities[$index]->html = $rawEntity->html;
$entities[$index]->html = $this->renderPage($entities[$index]);
};
- } else if ($rawEntity->entity_type === 'BookStack\\Chapter') {
+ } else if ($rawEntity->entity_type === $this->chapter->getMorphClass()) {
$entities[$index] = $this->chapter->newFromBuilder($rawEntity);
$key = $entities[$index]->entity_type . ':' . $entities[$index]->id;
$parents[$key] = $entities[$index];
@@ -390,7 +391,7 @@ class EntityRepo
if ($entity->chapter_id === 0 || $entity->chapter_id === '0') {
continue;
}
- $parentKey = 'BookStack\\Chapter:' . $entity->chapter_id;
+ $parentKey = $this->chapter->getMorphClass() . ':' . $entity->chapter_id;
if (!isset($parents[$parentKey])) {
$tree[] = $entity;
continue;
@@ -405,7 +406,7 @@ class EntityRepo
/**
* Get the child items for a chapter sorted by priority but
* with draft items floated to the top.
- * @param Chapter $chapter
+ * @param \BookStack\Entities\Chapter $chapter
* @return \Illuminate\Database\Eloquent\Collection|static[]
*/
public function getChapterChildren(Chapter $chapter)
@@ -417,7 +418,7 @@ class EntityRepo
/**
* Get the next sequential priority for a new child element in the given book.
- * @param Book $book
+ * @param \BookStack\Entities\Book $book
* @return int
*/
public function getNewBookPriority(Book $book)
@@ -428,7 +429,7 @@ class EntityRepo
/**
* Get a new priority for a new page to be added to the given chapter.
- * @param Chapter $chapter
+ * @param \BookStack\Entities\Chapter $chapter
* @return int
*/
public function getNewChapterPriority(Chapter $chapter)
@@ -477,7 +478,7 @@ class EntityRepo
/**
* Updates entity restrictions from a request
* @param $request
- * @param Entity $entity
+ * @param \BookStack\Entities\Entity $entity
*/
public function updateEntityPermissionsFromRequest($request, Entity $entity)
{
@@ -507,7 +508,7 @@ class EntityRepo
* @param string $type
* @param array $input
* @param bool|Book $book
- * @return Entity
+ * @return \BookStack\Entities\Entity
*/
public function createFromInput($type, $input = [], $book = false)
{
@@ -531,9 +532,9 @@ class EntityRepo
* Update entity details from request input.
* Used for books and chapters
* @param string $type
- * @param Entity $entityModel
+ * @param \BookStack\Entities\Entity $entityModel
* @param array $input
- * @return Entity
+ * @return \BookStack\Entities\Entity
*/
public function updateFromInput($type, Entity $entityModel, $input = [])
{
@@ -556,7 +557,7 @@ class EntityRepo
/**
* Sync the books assigned to a shelf from a comma-separated list
* of book IDs.
- * @param Bookshelf $shelf
+ * @param \BookStack\Entities\Bookshelf $shelf
* @param string $books
*/
public function updateShelfBooks(Bookshelf $shelf, string $books)
@@ -581,7 +582,7 @@ class EntityRepo
* @param integer $newBookId
* @param Entity $entity
* @param bool $rebuildPermissions
- * @return Entity
+ * @return \BookStack\Entities\Entity
*/
public function changeBook($type, $newBookId, Entity $entity, $rebuildPermissions = false)
{
@@ -639,7 +640,7 @@ class EntityRepo
* Get a new draft page instance.
* @param Book $book
* @param Chapter|bool $chapter
- * @return Page
+ * @return \BookStack\Entities\Page
*/
public function getDraftPage(Book $book, $chapter = false)
{
@@ -689,10 +690,10 @@ class EntityRepo
/**
* Create a copy of a page in a new location with a new name.
- * @param Page $page
- * @param Entity $newParent
+ * @param \BookStack\Entities\Page $page
+ * @param \BookStack\Entities\Entity $newParent
* @param string $newName
- * @return Page
+ * @return \BookStack\Entities\Page
*/
public function copyPage(Page $page, Entity $newParent, $newName = '')
{
@@ -728,7 +729,7 @@ class EntityRepo
* Saves a page revision into the system.
* @param Page $page
* @param null|string $summary
- * @return PageRevision
+ * @return \BookStack\Entities\PageRevision
*/
public function savePageRevision(Page $page, $summary = null)
{
@@ -902,7 +903,7 @@ class EntityRepo
/**
* Get the plain text version of a page's content.
- * @param Page $page
+ * @param \BookStack\Entities\Page $page
* @return string
*/
public function pageToPlainText(Page $page)
@@ -971,10 +972,10 @@ class EntityRepo
/**
* Updates a page with any fillable data and saves it into the database.
- * @param Page $page
+ * @param \BookStack\Entities\Page $page
* @param int $book_id
* @param array $input
- * @return Page
+ * @return \BookStack\Entities\Page
*/
public function updatePage(Page $page, $book_id, $input)
{
@@ -1019,7 +1020,7 @@ class EntityRepo
/**
* The base query for getting user update drafts.
- * @param Page $page
+ * @param \BookStack\Entities\Page $page
* @param $userId
* @return mixed
*/
@@ -1033,7 +1034,7 @@ class EntityRepo
/**
* Checks whether a user has a draft version of a particular page or not.
- * @param Page $page
+ * @param \BookStack\Entities\Page $page
* @param $userId
* @return bool
*/
@@ -1072,7 +1073,7 @@ class EntityRepo
* Checks for edits since last page updated.
* Passing in a minuted range will check for edits
* within the last x minutes.
- * @param Page $page
+ * @param \BookStack\Entities\Page $page
* @param null $minRange
* @return bool
*/
@@ -1108,7 +1109,7 @@ class EntityRepo
* @param Page $page
* @param Book $book
* @param int $revisionId
- * @return Page
+ * @return \BookStack\Entities\Page
*/
public function restorePageRevision(Page $page, Book $book, $revisionId)
{
@@ -1184,8 +1185,8 @@ class EntityRepo
/**
* Change the page's parent to the given entity.
- * @param Page $page
- * @param Entity $parent
+ * @param \BookStack\Entities\Page $page
+ * @param \BookStack\Entities\Entity $parent
*/
public function changePageParent(Page $page, Entity $parent)
{
@@ -1201,7 +1202,7 @@ class EntityRepo
/**
* Destroy a bookshelf instance
- * @param Bookshelf $shelf
+ * @param \BookStack\Entities\Bookshelf $shelf
* @throws \Throwable
*/
public function destroyBookshelf(Bookshelf $shelf)
@@ -1212,7 +1213,7 @@ class EntityRepo
/**
* Destroy the provided book and all its child entities.
- * @param Book $book
+ * @param \BookStack\Entities\Book $book
* @throws NotifyException
* @throws \Throwable
*/
@@ -1230,7 +1231,7 @@ class EntityRepo
/**
* Destroy a chapter and its relations.
- * @param Chapter $chapter
+ * @param \BookStack\Entities\Chapter $chapter
* @throws \Throwable
*/
public function destroyChapter(Chapter $chapter)
@@ -1272,7 +1273,7 @@ class EntityRepo
/**
* Destroy or handle the common relations connected to an entity.
- * @param Entity $entity
+ * @param \BookStack\Entities\Entity $entity
* @throws \Throwable
*/
protected function destroyEntityCommonRelations(Entity $entity)
@@ -1289,7 +1290,7 @@ class EntityRepo
/**
* Copy the permissions of a bookshelf to all child books.
* Returns the number of books that had permissions updated.
- * @param Bookshelf $bookshelf
+ * @param \BookStack\Entities\Bookshelf $bookshelf
* @return int
* @throws \Throwable
*/
diff --git a/app/Services/ExportService.php b/app/Entities/ExportService.php
similarity index 94%
rename from app/Services/ExportService.php
rename to app/Entities/ExportService.php
index 01e87f167..fc0e4d114 100644
--- a/app/Services/ExportService.php
+++ b/app/Entities/ExportService.php
@@ -1,9 +1,10 @@
-middleware('guest')->only(['getRegister', 'postRegister', 'socialRegister']);
$this->socialAuthService = $socialAuthService;
@@ -119,7 +119,7 @@ class RegisterController extends Controller
/**
* Create a new user instance after a valid registration.
* @param array $data
- * @return User
+ * @return \BookStack\Auth\User
*/
protected function create(array $data)
{
diff --git a/app/Http/Controllers/BookController.php b/app/Http/Controllers/BookController.php
index ea39a771e..045bcd344 100644
--- a/app/Http/Controllers/BookController.php
+++ b/app/Http/Controllers/BookController.php
@@ -1,10 +1,10 @@
searchService->searchEntities($searchTerm, 'all', 1, 20, $permission)['results'];
} else {
$entityNames = $entityTypes->map(function ($type) {
- return 'BookStack\\' . ucfirst($type);
+ return 'BookStack\\' . ucfirst($type); // TODO - Extract this elsewhere, too specific and stringy
})->toArray();
$entities = $this->viewService->getPopular(20, 0, $entityNames, $permission);
}
diff --git a/app/Http/Controllers/SettingController.php b/app/Http/Controllers/SettingController.php
index d9d66042e..01fb68fe0 100644
--- a/app/Http/Controllers/SettingController.php
+++ b/app/Http/Controllers/SettingController.php
@@ -1,6 +1,6 @@
getMimeType(), $imageMimes);
});
- \Blade::directive('icon', function ($expression) {
+ // Custom blade view directives
+ Blade::directive('icon', function ($expression) {
return "";
});
// Allow longer string lengths after upgrade to utf8mb4
- \Schema::defaultStringLength(191);
+ Schema::defaultStringLength(191);
+
+ // Set morph-map due to namespace changes
+ Relation::morphMap([
+ 'BookStack\\Bookshelf' => Bookshelf::class,
+ 'BookStack\\Book' => Book::class,
+ 'BookStack\\Chapter' => Chapter::class,
+ 'BookStack\\Page' => Page::class,
+ ]);
}
/**
diff --git a/app/Providers/AuthServiceProvider.php b/app/Providers/AuthServiceProvider.php
index d1fac56e6..6e5b6ffde 100644
--- a/app/Providers/AuthServiceProvider.php
+++ b/app/Providers/AuthServiceProvider.php
@@ -3,7 +3,7 @@
namespace BookStack\Providers;
use Auth;
-use BookStack\Services\LdapService;
+use BookStack\Auth\Access\LdapService;
use Illuminate\Support\ServiceProvider;
class AuthServiceProvider extends ServiceProvider
diff --git a/app/Providers/CustomFacadeProvider.php b/app/Providers/CustomFacadeProvider.php
index c81a5529d..2a5b101db 100644
--- a/app/Providers/CustomFacadeProvider.php
+++ b/app/Providers/CustomFacadeProvider.php
@@ -2,18 +2,18 @@
namespace BookStack\Providers;
-use BookStack\Activity;
-use BookStack\Image;
-use BookStack\Services\ImageService;
-use BookStack\Services\PermissionService;
-use BookStack\Services\ViewService;
-use BookStack\Setting;
-use BookStack\View;
+use BookStack\Actions\Activity;
+use BookStack\Uploads\Image;
+use BookStack\Uploads\ImageService;
+use BookStack\Auth\Permissions\PermissionService;
+use BookStack\Actions\ViewService;
+use BookStack\Settings\Setting;
+use BookStack\Actions\View;
use Illuminate\Contracts\Cache\Repository;
use Illuminate\Contracts\Filesystem\Factory;
use Illuminate\Support\ServiceProvider;
-use BookStack\Services\ActivityService;
-use BookStack\Services\SettingService;
+use BookStack\Actions\ActivityService;
+use BookStack\Settings\SettingService;
use Intervention\Image\ImageManager;
class CustomFacadeProvider extends ServiceProvider
diff --git a/app/Providers/LdapUserProvider.php b/app/Providers/LdapUserProvider.php
index 1dc789c3b..7f676eace 100644
--- a/app/Providers/LdapUserProvider.php
+++ b/app/Providers/LdapUserProvider.php
@@ -2,9 +2,9 @@
namespace BookStack\Providers;
-use BookStack\Role;
-use BookStack\Services\LdapService;
-use BookStack\User;
+use BookStack\Auth\Role;
+use BookStack\Auth\Access\LdapService;
+use BookStack\Auth\User;
use Illuminate\Contracts\Auth\Authenticatable;
use Illuminate\Contracts\Auth\UserProvider;
@@ -19,7 +19,7 @@ class LdapUserProvider implements UserProvider
protected $model;
/**
- * @var LdapService
+ * @var \BookStack\Auth\LdapService
*/
protected $ldapService;
@@ -27,7 +27,7 @@ class LdapUserProvider implements UserProvider
/**
* LdapUserProvider constructor.
* @param $model
- * @param LdapService $ldapService
+ * @param \BookStack\Auth\LdapService $ldapService
*/
public function __construct($model, LdapService $ldapService)
{
diff --git a/app/Setting.php b/app/Settings/Setting.php
similarity index 68%
rename from app/Setting.php
rename to app/Settings/Setting.php
index 0af3652db..1a52920ee 100644
--- a/app/Setting.php
+++ b/app/Settings/Setting.php
@@ -1,4 +1,6 @@
-user() ?: \BookStack\User::getDefault();
+ return auth()->user() ?: \BookStack\Auth\User::getDefault();
}
/**
@@ -61,7 +61,7 @@ function userCan($permission, Ownable $ownable = null)
}
// Check permission on ownable item
- $permissionService = app(\BookStack\Services\PermissionService::class);
+ $permissionService = app(\BookStack\Auth\Permissions\PermissionService::class);
return $permissionService->checkOwnableUserAccess($ownable, $permission);
}
@@ -69,11 +69,11 @@ function userCan($permission, Ownable $ownable = null)
* Helper to access system settings.
* @param $key
* @param bool $default
- * @return bool|string|\BookStack\Services\SettingService
+ * @return bool|string|\BookStack\Settings\SettingService
*/
function setting($key = null, $default = false)
{
- $settingService = resolve(\BookStack\Services\SettingService::class);
+ $settingService = resolve(\BookStack\Settings\SettingService::class);
if (is_null($key)) {
return $settingService;
}
diff --git a/config/app.php b/config/app.php
index 9b5ac2f8c..7529697fa 100755
--- a/config/app.php
+++ b/config/app.php
@@ -274,10 +274,10 @@ return [
* Custom
*/
- 'Activity' => BookStack\Services\Facades\Activity::class,
- 'Setting' => BookStack\Services\Facades\Setting::class,
- 'Views' => BookStack\Services\Facades\Views::class,
- 'Images' => BookStack\Services\Facades\Images::class,
+ 'Activity' => BookStack\Facades\Activity::class,
+ 'Setting' => BookStack\Facades\Setting::class,
+ 'Views' => BookStack\Facades\Views::class,
+ 'Images' => BookStack\Facades\Images::class,
],
diff --git a/config/auth.php b/config/auth.php
index ceeab5c71..f0e699809 100644
--- a/config/auth.php
+++ b/config/auth.php
@@ -70,7 +70,7 @@ return [
'providers' => [
'users' => [
'driver' => env('AUTH_METHOD', 'standard') === 'standard' ? 'eloquent' : env('AUTH_METHOD'),
- 'model' => BookStack\User::class,
+ 'model' => \BookStack\Auth\User::class,
],
// 'users' => [
diff --git a/config/services.php b/config/services.php
index 2b0f260cd..711040386 100644
--- a/config/services.php
+++ b/config/services.php
@@ -38,7 +38,7 @@ return [
],
'stripe' => [
- 'model' => BookStack\User::class,
+ 'model' => \BookStack\Auth\User::class,
'key' => '',
'secret' => '',
],
diff --git a/database/factories/ModelFactory.php b/database/factories/ModelFactory.php
index 3d6ed1d63..de6b0b276 100644
--- a/database/factories/ModelFactory.php
+++ b/database/factories/ModelFactory.php
@@ -11,7 +11,7 @@
|
*/
-$factory->define(BookStack\User::class, function ($faker) {
+$factory->define(\BookStack\Auth\User::class, function ($faker) {
return [
'name' => $faker->name,
'email' => $faker->email,
@@ -21,7 +21,7 @@ $factory->define(BookStack\User::class, function ($faker) {
];
});
-$factory->define(BookStack\Bookshelf::class, function ($faker) {
+$factory->define(\BookStack\Entities\Bookshelf::class, function ($faker) {
return [
'name' => $faker->sentence,
'slug' => str_random(10),
@@ -29,7 +29,7 @@ $factory->define(BookStack\Bookshelf::class, function ($faker) {
];
});
-$factory->define(BookStack\Book::class, function ($faker) {
+$factory->define(\BookStack\Entities\Book::class, function ($faker) {
return [
'name' => $faker->sentence,
'slug' => str_random(10),
@@ -37,7 +37,7 @@ $factory->define(BookStack\Book::class, function ($faker) {
];
});
-$factory->define(BookStack\Chapter::class, function ($faker) {
+$factory->define(\BookStack\Entities\Chapter::class, function ($faker) {
return [
'name' => $faker->sentence,
'slug' => str_random(10),
@@ -45,7 +45,7 @@ $factory->define(BookStack\Chapter::class, function ($faker) {
];
});
-$factory->define(BookStack\Page::class, function ($faker) {
+$factory->define(\BookStack\Entities\Page::class, function ($faker) {
$html = '' . implode('
', $faker->paragraphs(5)) . '
';
return [
'name' => $faker->sentence,
@@ -56,21 +56,21 @@ $factory->define(BookStack\Page::class, function ($faker) {
];
});
-$factory->define(BookStack\Role::class, function ($faker) {
+$factory->define(\BookStack\Auth\Role::class, function ($faker) {
return [
'display_name' => $faker->sentence(3),
'description' => $faker->sentence(10)
];
});
-$factory->define(BookStack\Tag::class, function ($faker) {
+$factory->define(\BookStack\Actions\Tag::class, function ($faker) {
return [
'name' => $faker->city,
'value' => $faker->sentence(3)
];
});
-$factory->define(BookStack\Image::class, function ($faker) {
+$factory->define(\BookStack\Uploads\Image::class, function ($faker) {
return [
'name' => $faker->slug . '.jpg',
'url' => $faker->url,
@@ -80,7 +80,7 @@ $factory->define(BookStack\Image::class, function ($faker) {
];
});
-$factory->define(BookStack\Comment::class, function($faker) {
+$factory->define(\BookStack\Actions\Comment::class, function($faker) {
$text = $faker->paragraph(1);
$html = '' . $text. '
';
return [
diff --git a/database/migrations/2015_12_07_195238_add_image_upload_types.php b/database/migrations/2015_12_07_195238_add_image_upload_types.php
index eed937611..515bc9d8d 100644
--- a/database/migrations/2015_12_07_195238_add_image_upload_types.php
+++ b/database/migrations/2015_12_07_195238_add_image_upload_types.php
@@ -1,6 +1,6 @@
where('entity_type', '=', 'BookStack\Bookshelf')->delete();
- DB::table('views')->where('viewable_type', '=', 'BookStack\Bookshelf')->delete();
- DB::table('entity_permissions')->where('restrictable_type', '=', 'BookStack\Bookshelf')->delete();
- DB::table('tags')->where('entity_type', '=', 'BookStack\Bookshelf')->delete();
- DB::table('search_terms')->where('entity_type', '=', 'BookStack\Bookshelf')->delete();
- DB::table('comments')->where('entity_type', '=', 'BookStack\Bookshelf')->delete();
+ DB::table('activities')->where('entity_type', '=', 'BookStack\Entities\Bookshelf')->delete();
+ DB::table('views')->where('viewable_type', '=', 'BookStack\Entities\Bookshelf')->delete();
+ DB::table('entity_permissions')->where('restrictable_type', '=', 'BookStack\Entities\Bookshelf')->delete();
+ DB::table('tags')->where('entity_type', '=', 'BookStack\Entities\Bookshelf')->delete();
+ DB::table('search_terms')->where('entity_type', '=', 'BookStack\Entities\Bookshelf')->delete();
+ DB::table('comments')->where('entity_type', '=', 'BookStack\Entities\Bookshelf')->delete();
}
}
diff --git a/database/seeds/DummyContentSeeder.php b/database/seeds/DummyContentSeeder.php
index dcf589352..ce3cd1307 100644
--- a/database/seeds/DummyContentSeeder.php
+++ b/database/seeds/DummyContentSeeder.php
@@ -12,39 +12,39 @@ class DummyContentSeeder extends Seeder
public function run()
{
// Create an editor user
- $editorUser = factory(\BookStack\User::class)->create();
- $editorRole = \BookStack\Role::getRole('editor');
+ $editorUser = factory(\BookStack\Auth\User::class)->create();
+ $editorRole = \BookStack\Auth\Role::getRole('editor');
$editorUser->attachRole($editorRole);
// Create a viewer user
- $viewerUser = factory(\BookStack\User::class)->create();
- $role = \BookStack\Role::getRole('viewer');
+ $viewerUser = factory(\BookStack\Auth\User::class)->create();
+ $role = \BookStack\Auth\Role::getRole('viewer');
$viewerUser->attachRole($role);
$byData = ['created_by' => $editorUser->id, 'updated_by' => $editorUser->id];
- factory(\BookStack\Book::class, 5)->create($byData)
+ factory(\BookStack\Entities\Book::class, 5)->create($byData)
->each(function($book) use ($editorUser, $byData) {
- $chapters = factory(\BookStack\Chapter::class, 3)->create($byData)
+ $chapters = factory(\BookStack\Entities\Chapter::class, 3)->create($byData)
->each(function($chapter) use ($editorUser, $book, $byData){
- $pages = factory(\BookStack\Page::class, 3)->make(array_merge($byData, ['book_id' => $book->id]));
+ $pages = factory(\BookStack\Entities\Page::class, 3)->make(array_merge($byData, ['book_id' => $book->id]));
$chapter->pages()->saveMany($pages);
});
- $pages = factory(\BookStack\Page::class, 3)->make($byData);
+ $pages = factory(\BookStack\Entities\Page::class, 3)->make($byData);
$book->chapters()->saveMany($chapters);
$book->pages()->saveMany($pages);
});
- $largeBook = factory(\BookStack\Book::class)->create(array_merge($byData, ['name' => 'Large book' . str_random(10)]));
- $pages = factory(\BookStack\Page::class, 200)->make($byData);
- $chapters = factory(\BookStack\Chapter::class, 50)->make($byData);
+ $largeBook = factory(\BookStack\Entities\Book::class)->create(array_merge($byData, ['name' => 'Large book' . str_random(10)]));
+ $pages = factory(\BookStack\Entities\Page::class, 200)->make($byData);
+ $chapters = factory(\BookStack\Entities\Chapter::class, 50)->make($byData);
$largeBook->pages()->saveMany($pages);
$largeBook->chapters()->saveMany($chapters);
- $shelves = factory(\BookStack\Bookshelf::class, 10)->create($byData);
+ $shelves = factory(\BookStack\Entities\Bookshelf::class, 10)->create($byData);
$largeBook->shelves()->attach($shelves->pluck('id'));
- app(\BookStack\Services\PermissionService::class)->buildJointPermissions();
- app(\BookStack\Services\SearchService::class)->indexAllEntities();
+ app(\BookStack\Auth\Permissions\PermissionService::class)->buildJointPermissions();
+ app(\BookStack\Entities\SearchService::class)->indexAllEntities();
}
}
diff --git a/database/seeds/LargeContentSeeder.php b/database/seeds/LargeContentSeeder.php
index 129ede997..136b6cb6a 100644
--- a/database/seeds/LargeContentSeeder.php
+++ b/database/seeds/LargeContentSeeder.php
@@ -12,16 +12,16 @@ class LargeContentSeeder extends Seeder
public function run()
{
// Create an editor user
- $editorUser = factory(\BookStack\User::class)->create();
- $editorRole = \BookStack\Role::getRole('editor');
+ $editorUser = factory(\BookStack\Auth\User::class)->create();
+ $editorRole = \BookStack\Auth\Role::getRole('editor');
$editorUser->attachRole($editorRole);
- $largeBook = factory(\BookStack\Book::class)->create(['name' => 'Large book' . str_random(10), 'created_by' => $editorUser->id, 'updated_by' => $editorUser->id]);
- $pages = factory(\BookStack\Page::class, 200)->make(['created_by' => $editorUser->id, 'updated_by' => $editorUser->id]);
- $chapters = factory(\BookStack\Chapter::class, 50)->make(['created_by' => $editorUser->id, 'updated_by' => $editorUser->id]);
+ $largeBook = factory(\BookStack\Entities\Book::class)->create(['name' => 'Large book' . str_random(10), 'created_by' => $editorUser->id, 'updated_by' => $editorUser->id]);
+ $pages = factory(\BookStack\Entities\Page::class, 200)->make(['created_by' => $editorUser->id, 'updated_by' => $editorUser->id]);
+ $chapters = factory(\BookStack\Entities\Chapter::class, 50)->make(['created_by' => $editorUser->id, 'updated_by' => $editorUser->id]);
$largeBook->pages()->saveMany($pages);
$largeBook->chapters()->saveMany($chapters);
- app(\BookStack\Services\PermissionService::class)->buildJointPermissions();
- app(\BookStack\Services\SearchService::class)->indexAllEntities();
+ app(\BookStack\Auth\Permissions\PermissionService::class)->buildJointPermissions();
+ app(\BookStack\Entities\SearchService::class)->indexAllEntities();
}
}
diff --git a/resources/views/components/page-picker.blade.php b/resources/views/components/page-picker.blade.php
index 91d8eb646..7a3285fa7 100644
--- a/resources/views/components/page-picker.blade.php
+++ b/resources/views/components/page-picker.blade.php
@@ -3,7 +3,7 @@
diff --git a/resources/views/errors/404.blade.php b/resources/views/errors/404.blade.php
index d614edca8..9c431828a 100644
--- a/resources/views/errors/404.blade.php
+++ b/resources/views/errors/404.blade.php
@@ -18,19 +18,19 @@
@icon('page') {{ trans('entities.pages_popular') }}
- @include('partials.entity-list', ['entities' => Views::getPopular(10, 0, [\BookStack\Page::class]), 'style' => 'compact'])
+ @include('partials.entity-list', ['entities' => Views::getPopular(10, 0, [\BookStack\Entities\Page::class]), 'style' => 'compact'])
@icon('book') {{ trans('entities.books_popular') }}
- @include('partials.entity-list', ['entities' => Views::getPopular(10, 0, [\BookStack\Book::class]), 'style' => 'compact'])
+ @include('partials.entity-list', ['entities' => Views::getPopular(10, 0, [\BookStack\Entities\Book::class]), 'style' => 'compact'])
@icon('chapter') {{ trans('entities.chapters_popular') }}
- @include('partials.entity-list', ['entities' => Views::getPopular(10, 0, [\BookStack\Chapter::class]), 'style' => 'compact'])
+ @include('partials.entity-list', ['entities' => Views::getPopular(10, 0, [\BookStack\Entities\Chapter::class]), 'style' => 'compact'])
diff --git a/resources/views/settings/index.blade.php b/resources/views/settings/index.blade.php
index 3c563a61c..26b81899e 100644
--- a/resources/views/settings/index.blade.php
+++ b/resources/views/settings/index.blade.php
@@ -127,9 +127,9 @@