Also refactored some role content, primarily updating the permission
controller to be RoleController since it only dealt with roles.
12 files changed:
const RECYCLE_BIN_RESTORE = 'recycle_bin_restore';
const RECYCLE_BIN_DESTROY = 'recycle_bin_destroy';
const RECYCLE_BIN_RESTORE = 'recycle_bin_restore';
const RECYCLE_BIN_DESTROY = 'recycle_bin_destroy';
- // TODO - Implement all below
const USER_CREATE = 'user_create';
const USER_UPDATE = 'user_update';
const USER_DELETE = 'user_delete';
const USER_CREATE = 'user_create';
const USER_UPDATE = 'user_update';
const USER_DELETE = 'user_delete';
const ROLE_UPDATE = 'role_update';
const ROLE_DELETE = 'role_delete';
const ROLE_UPDATE = 'role_update';
const ROLE_DELETE = 'role_delete';
+ // TODO - Implement all below
const ACCESS_PASSWORD_RESET = 'access_password_reset_request';
const ACCESS_PASSWORD_RESET_UPDATE = 'access_password_reset_update';
const ACCESS_LOGIN = 'access_login';
const ACCESS_PASSWORD_RESET = 'access_password_reset_request';
const ACCESS_PASSWORD_RESET_UPDATE = 'access_password_reset_update';
const ACCESS_LOGIN = 'access_login';
<?php namespace BookStack\Api;
use BookStack\Auth\User;
<?php namespace BookStack\Api;
use BookStack\Auth\User;
+use BookStack\Interfaces\Loggable;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Support\Carbon;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Support\Carbon;
-class ApiToken extends Model
+/**
+ * Class ApiToken
+ * @property int $id
+ * @property string $token_id
+ * @property string $secret
+ * @property string $name
+ * @property Carbon $expires_at
+ * @property User $user
+ * @package BookStack\Api
+ */
+class ApiToken extends Model implements Loggable
{
protected $fillable = ['name', 'expires_at'];
protected $casts = [
{
protected $fillable = ['name', 'expires_at'];
protected $casts = [
{
return Carbon::now()->addYears(100)->format('Y-m-d');
}
{
return Carbon::now()->addYears(100)->format('Y-m-d');
}
+
+ /**
+ * @inheritdoc
+ */
+ public function logDescriptor(): string
+ {
+ return "({$this->id}) {$this->name}; User: {$this->user->logDescriptor()}";
+ }
<?php namespace BookStack\Auth\Permissions;
<?php namespace BookStack\Auth\Permissions;
+use BookStack\Actions\ActivityType;
use BookStack\Auth\Role;
use BookStack\Exceptions\PermissionsException;
use BookStack\Auth\Role;
use BookStack\Exceptions\PermissionsException;
+use BookStack\Facades\Activity;
use Exception;
use Illuminate\Database\Eloquent\Collection;
use Exception;
use Illuminate\Database\Eloquent\Collection;
-use Illuminate\Support\Str;
$permissions = isset($roleData['permissions']) ? array_keys($roleData['permissions']) : [];
$this->assignRolePermissions($role, $permissions);
$this->permissionService->buildJointPermissionForRole($role);
$permissions = isset($roleData['permissions']) ? array_keys($roleData['permissions']) : [];
$this->assignRolePermissions($role, $permissions);
$this->permissionService->buildJointPermissionForRole($role);
+ Activity::add(ActivityType::ROLE_CREATE, $role);
$role->fill($roleData);
$role->save();
$this->permissionService->buildJointPermissionForRole($role);
$role->fill($roleData);
$role->save();
$this->permissionService->buildJointPermissionForRole($role);
+ Activity::add(ActivityType::ROLE_UPDATE, $role);
}
/**
* Assign an list of permission names to an role.
*/
}
/**
* Assign an list of permission names to an role.
*/
- public function assignRolePermissions(Role $role, array $permissionNameArray = [])
+ protected function assignRolePermissions(Role $role, array $permissionNameArray = [])
{
$permissions = [];
$permissionNameArray = array_values($permissionNameArray);
{
$permissions = [];
$permissionNameArray = array_values($permissionNameArray);
}
$this->permissionService->deleteJointPermissionsForRole($role);
}
$this->permissionService->deleteJointPermissionsForRole($role);
+ Activity::add(ActivityType::ROLE_DELETE, $role);
use BookStack\Auth\Permissions\JointPermission;
use BookStack\Auth\Permissions\RolePermission;
use BookStack\Auth\Permissions\JointPermission;
use BookStack\Auth\Permissions\RolePermission;
+use BookStack\Interfaces\Loggable;
use BookStack\Model;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Database\Eloquent\Relations\HasMany;
use BookStack\Model;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Database\Eloquent\Relations\HasMany;
* @property string $external_auth_id
* @property string $system_name
*/
* @property string $external_auth_id
* @property string $system_name
*/
-class Role extends Model
+class Role extends Model implements Loggable
{
protected $fillable = ['display_name', 'description', 'external_auth_id'];
{
protected $fillable = ['display_name', 'description', 'external_auth_id'];
{
return static::query()->where('system_name', '!=', 'admin')->get();
}
{
return static::query()->where('system_name', '!=', 'admin')->get();
}
+
+ /**
+ * @inheritdoc
+ */
+ public function logDescriptor(): string
+ {
+ return "({$this->id}) {$this->display_name}";
+ }
<?php namespace BookStack\Auth;
use BookStack\Api\ApiToken;
<?php namespace BookStack\Auth;
use BookStack\Api\ApiToken;
+use BookStack\Interfaces\Loggable;
use BookStack\Model;
use BookStack\Notifications\ResetPassword;
use BookStack\Uploads\Image;
use BookStack\Model;
use BookStack\Notifications\ResetPassword;
use BookStack\Uploads\Image;
* @property string $external_auth_id
* @property string $system_name
*/
* @property string $external_auth_id
* @property string $system_name
*/
-class User extends Model implements AuthenticatableContract, CanResetPasswordContract
+class User extends Model implements AuthenticatableContract, CanResetPasswordContract, Loggable
{
use Authenticatable, CanResetPassword, Notifiable;
{
use Authenticatable, CanResetPassword, Notifiable;
{
$this->notify(new ResetPassword($token));
}
{
$this->notify(new ResetPassword($token));
}
+
+ /**
+ * @inheritdoc
+ */
+ public function logDescriptor(): string
+ {
+ return "({$this->id}) {$this->name}";
+ }
{
/** @var Deletion $deletion */
$deletion = Deletion::query()->findOrFail($id);
{
/** @var Deletion $deletion */
$deletion = Deletion::query()->findOrFail($id);
+ $this->logActivity(ActivityType::RECYCLE_BIN_DESTROY, $deletion);
$deleteCount = (new TrashCan())->destroyFromDeletion($deletion);
$deleteCount = (new TrashCan())->destroyFromDeletion($deletion);
- $this->logActivity(ActivityType::RECYCLE_BIN_DESTROY, $deletion);
$this->showSuccessNotification(trans('settings.recycle_bin_destroy_notification', ['count' => $deleteCount]));
return redirect($this->recycleBinBaseUrl);
}
$this->showSuccessNotification(trans('settings.recycle_bin_destroy_notification', ['count' => $deleteCount]));
return redirect($this->recycleBinBaseUrl);
}
use Illuminate\Http\Request;
use Illuminate\Validation\ValidationException;
use Illuminate\Http\Request;
use Illuminate\Validation\ValidationException;
-class PermissionController extends Controller
+class RoleController extends Controller
{
protected $permissionsRepo;
{
protected $permissionsRepo;
/**
* Show a listing of the roles in the system.
*/
/**
* Show a listing of the roles in the system.
*/
- public function listRoles()
{
$this->checkPermission('user-roles-manage');
$roles = $this->permissionsRepo->getAllRoles();
{
$this->checkPermission('user-roles-manage');
$roles = $this->permissionsRepo->getAllRoles();
/**
* Show the form to create a new role
*/
/**
* Show the form to create a new role
*/
- public function createRole()
+ public function create()
{
$this->checkPermission('user-roles-manage');
return view('settings.roles.create');
{
$this->checkPermission('user-roles-manage');
return view('settings.roles.create');
/**
* Store a new role in the system.
*/
/**
* Store a new role in the system.
*/
- public function storeRole(Request $request)
+ public function store(Request $request)
{
$this->checkPermission('user-roles-manage');
$this->validate($request, [
{
$this->checkPermission('user-roles-manage');
$this->validate($request, [
* Show the form for editing a user role.
* @throws PermissionsException
*/
* Show the form for editing a user role.
* @throws PermissionsException
*/
- public function editRole(string $id)
+ public function edit(string $id)
{
$this->checkPermission('user-roles-manage');
$role = $this->permissionsRepo->getRoleById($id);
{
$this->checkPermission('user-roles-manage');
$role = $this->permissionsRepo->getRoleById($id);
* Updates a user role.
* @throws ValidationException
*/
* Updates a user role.
* @throws ValidationException
*/
- public function updateRole(Request $request, string $id)
+ public function update(Request $request, string $id)
{
$this->checkPermission('user-roles-manage');
$this->validate($request, [
{
$this->checkPermission('user-roles-manage');
$this->validate($request, [
* Show the view to delete a role.
* Offers the chance to migrate users.
*/
* Show the view to delete a role.
* Offers the chance to migrate users.
*/
- public function showDeleteRole(string $id)
+ public function showDelete(string $id)
{
$this->checkPermission('user-roles-manage');
$role = $this->permissionsRepo->getRoleById($id);
{
$this->checkPermission('user-roles-manage');
$role = $this->permissionsRepo->getRoleById($id);
* Migrate from a previous role if set.
* @throws Exception
*/
* Migrate from a previous role if set.
* @throws Exception
*/
- public function deleteRole(Request $request, string $id)
+ public function delete(Request $request, string $id)
{
$this->checkPermission('user-roles-manage');
{
$this->checkPermission('user-roles-manage');
<?php namespace BookStack\Http\Controllers;
<?php namespace BookStack\Http\Controllers;
+use BookStack\Actions\ActivityType;
use BookStack\Api\ApiToken;
use BookStack\Auth\User;
use Illuminate\Http\Request;
use BookStack\Api\ApiToken;
use BookStack\Auth\User;
use Illuminate\Http\Request;
-use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Str;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Str;
session()->flash('api-token-secret:' . $token->id, $secret);
$this->showSuccessNotification(trans('settings.user_api_token_create_success'));
session()->flash('api-token-secret:' . $token->id, $secret);
$this->showSuccessNotification(trans('settings.user_api_token_create_success'));
+ $this->logActivity(ActivityType::API_TOKEN_CREATE, $token);
+
return redirect($user->getEditUrl('/api-tokens/' . $token->id));
}
return redirect($user->getEditUrl('/api-tokens/' . $token->id));
}
])->save();
$this->showSuccessNotification(trans('settings.user_api_token_update_success'));
])->save();
$this->showSuccessNotification(trans('settings.user_api_token_update_success'));
+ $this->logActivity(ActivityType::API_TOKEN_UPDATE, $token);
return redirect($user->getEditUrl('/api-tokens/' . $token->id));
}
return redirect($user->getEditUrl('/api-tokens/' . $token->id));
}
$token->delete();
$this->showSuccessNotification(trans('settings.user_api_token_delete_success'));
$token->delete();
$this->showSuccessNotification(trans('settings.user_api_token_delete_success'));
+ $this->logActivity(ActivityType::API_TOKEN_DELETE, $token);
+
return redirect($user->getEditUrl('#api_tokens'));
}
return redirect($user->getEditUrl('#api_tokens'));
}
<?php namespace BookStack\Http\Controllers;
<?php namespace BookStack\Http\Controllers;
+use BookStack\Actions\ActivityType;
use BookStack\Auth\Access\SocialAuthService;
use BookStack\Auth\Access\UserInviteService;
use BookStack\Auth\User;
use BookStack\Auth\Access\SocialAuthService;
use BookStack\Auth\Access\UserInviteService;
use BookStack\Auth\User;
$this->userRepo->downloadAndAssignUserAvatar($user);
$this->userRepo->downloadAndAssignUserAvatar($user);
+ $this->logActivity(ActivityType::USER_CREATE, $user);
return redirect('/settings/users');
}
return redirect('/settings/users');
}
$user->save();
$this->showSuccessNotification(trans('settings.users_edit_success'));
$user->save();
$this->showSuccessNotification(trans('settings.users_edit_success'));
+ $this->logActivity(ActivityType::USER_UPDATE, $user);
$redirectUrl = userCan('users-manage') ? '/settings/users' : ('/settings/users/' . $user->id);
return redirect($redirectUrl);
$redirectUrl = userCan('users-manage') ? '/settings/users' : ('/settings/users/' . $user->id);
return redirect($redirectUrl);
$this->userRepo->destroy($user);
$this->showSuccessNotification(trans('settings.users_delete_success'));
$this->userRepo->destroy($user);
$this->showSuccessNotification(trans('settings.users_delete_success'));
+ $this->logActivity(ActivityType::USER_DELETE, $user);
return redirect('/settings/users');
}
return redirect('/settings/users');
}
Route::delete('/users/{userId}/api-tokens/{tokenId}', 'UserApiTokenController@destroy');
// Roles
Route::delete('/users/{userId}/api-tokens/{tokenId}', 'UserApiTokenController@destroy');
// Roles
- Route::get('/roles', 'PermissionController@listRoles');
- Route::get('/roles/new', 'PermissionController@createRole');
- Route::post('/roles/new', 'PermissionController@storeRole');
- Route::get('/roles/delete/{id}', 'PermissionController@showDeleteRole');
- Route::delete('/roles/delete/{id}', 'PermissionController@deleteRole');
- Route::get('/roles/{id}', 'PermissionController@editRole');
- Route::put('/roles/{id}', 'PermissionController@updateRole');
+ Route::get('/roles', 'RoleController@list');
+ Route::get('/roles/new', 'RoleController@create');
+ Route::post('/roles/new', 'RoleController@store');
+ Route::get('/roles/delete/{id}', 'RoleController@showDelete');
+ Route::delete('/roles/delete/{id}', 'RoleController@delete');
+ Route::get('/roles/{id}', 'RoleController@edit');
+ Route::put('/roles/{id}', 'RoleController@update');
<?php namespace Tests\Permissions;
<?php namespace Tests\Permissions;
+use BookStack\Actions\Comment;
+use BookStack\Auth\User;
+use BookStack\Entities\Book;
use BookStack\Entities\Bookshelf;
use BookStack\Entities\Bookshelf;
+use BookStack\Entities\Chapter;
use BookStack\Entities\Page;
use BookStack\Auth\Role;
use BookStack\Entities\Page;
use BookStack\Auth\Role;
+use BookStack\Uploads\Image;
use Laravel\BrowserKitTesting\HttpException;
use Tests\BrowserKitTest;
use Laravel\BrowserKitTesting\HttpException;
use Tests\BrowserKitTest;
public function test_cannot_delete_admin_role()
{
public function test_cannot_delete_admin_role()
{
- $adminRole = \BookStack\Auth\Role::getRole('admin');
+ $adminRole = Role::getRole('admin');
$deletePageUrl = '/settings/roles/delete/' . $adminRole->id;
$this->asAdmin()->visit($deletePageUrl)
->press('Confirm')
$deletePageUrl = '/settings/roles/delete/' . $adminRole->id;
$this->asAdmin()->visit($deletePageUrl)
->press('Confirm')
public function test_restrictions_manage_all_permission()
{
public function test_restrictions_manage_all_permission()
{
- $page = \BookStack\Entities\Page::take(1)->get()->first();
+ $page = Page::take(1)->get()->first();
$this->actingAs($this->user)->visit($page->getUrl())
->dontSee('Permissions')
->visit($page->getUrl() . '/permissions')
$this->actingAs($this->user)->visit($page->getUrl())
->dontSee('Permissions')
->visit($page->getUrl() . '/permissions')
public function test_restrictions_manage_own_permission()
{
public function test_restrictions_manage_own_permission()
{
- $otherUsersPage = \BookStack\Entities\Page::first();
+ $otherUsersPage = Page::first();
$content = $this->createEntityChainBelongingToUser($this->user);
// Check can't restrict other's content
$this->actingAs($this->user)->visit($otherUsersPage->getUrl())
$content = $this->createEntityChainBelongingToUser($this->user);
// Check can't restrict other's content
$this->actingAs($this->user)->visit($otherUsersPage->getUrl())
public function test_bookshelves_edit_all_permission()
{
public function test_bookshelves_edit_all_permission()
{
- $otherShelf = \BookStack\Entities\Bookshelf::first();
+ $otherShelf = Bookshelf::first();
$this->checkAccessPermission('bookshelf-update-all', [
$otherShelf->getUrl('/edit')
], [
$this->checkAccessPermission('bookshelf-update-all', [
$otherShelf->getUrl('/edit')
], [
public function test_bookshelves_delete_own_permission()
{
$this->giveUserPermissions($this->user, ['bookshelf-update-all']);
public function test_bookshelves_delete_own_permission()
{
$this->giveUserPermissions($this->user, ['bookshelf-update-all']);
- $otherShelf = \BookStack\Entities\Bookshelf::first();
+ $otherShelf = Bookshelf::first();
$ownShelf = $this->newShelf(['name' => 'test-shelf', 'slug' => 'test-shelf']);
$ownShelf->forceFill(['created_by' => $this->user->id, 'updated_by' => $this->user->id])->save();
$this->regenEntityPermissions($ownShelf);
$ownShelf = $this->newShelf(['name' => 'test-shelf', 'slug' => 'test-shelf']);
$ownShelf->forceFill(['created_by' => $this->user->id, 'updated_by' => $this->user->id])->save();
$this->regenEntityPermissions($ownShelf);
public function test_bookshelves_delete_all_permission()
{
$this->giveUserPermissions($this->user, ['bookshelf-update-all']);
public function test_bookshelves_delete_all_permission()
{
$this->giveUserPermissions($this->user, ['bookshelf-update-all']);
- $otherShelf = \BookStack\Entities\Bookshelf::first();
+ $otherShelf = Bookshelf::first();
$this->checkAccessPermission('bookshelf-delete-all', [
$otherShelf->getUrl('/delete')
], [
$this->checkAccessPermission('bookshelf-delete-all', [
$otherShelf->getUrl('/delete')
], [
public function test_books_edit_own_permission()
{
public function test_books_edit_own_permission()
{
- $otherBook = \BookStack\Entities\Book::take(1)->get()->first();
+ $otherBook = Book::take(1)->get()->first();
$ownBook = $this->createEntityChainBelongingToUser($this->user)['book'];
$this->checkAccessPermission('book-update-own', [
$ownBook->getUrl() . '/edit'
$ownBook = $this->createEntityChainBelongingToUser($this->user)['book'];
$this->checkAccessPermission('book-update-own', [
$ownBook->getUrl() . '/edit'
public function test_books_edit_all_permission()
{
public function test_books_edit_all_permission()
{
- $otherBook = \BookStack\Entities\Book::take(1)->get()->first();
+ $otherBook = Book::take(1)->get()->first();
$this->checkAccessPermission('book-update-all', [
$otherBook->getUrl() . '/edit'
], [
$this->checkAccessPermission('book-update-all', [
$otherBook->getUrl() . '/edit'
], [
public function test_books_delete_own_permission()
{
$this->giveUserPermissions($this->user, ['book-update-all']);
public function test_books_delete_own_permission()
{
$this->giveUserPermissions($this->user, ['book-update-all']);
- $otherBook = \BookStack\Entities\Book::take(1)->get()->first();
+ $otherBook = Book::take(1)->get()->first();
$ownBook = $this->createEntityChainBelongingToUser($this->user)['book'];
$this->checkAccessPermission('book-delete-own', [
$ownBook->getUrl() . '/delete'
$ownBook = $this->createEntityChainBelongingToUser($this->user)['book'];
$this->checkAccessPermission('book-delete-own', [
$ownBook->getUrl() . '/delete'
public function test_books_delete_all_permission()
{
$this->giveUserPermissions($this->user, ['book-update-all']);
public function test_books_delete_all_permission()
{
$this->giveUserPermissions($this->user, ['book-update-all']);
- $otherBook = \BookStack\Entities\Book::take(1)->get()->first();
+ $otherBook = Book::take(1)->get()->first();
$this->checkAccessPermission('book-delete-all', [
$otherBook->getUrl() . '/delete'
], [
$this->checkAccessPermission('book-delete-all', [
$otherBook->getUrl() . '/delete'
], [
public function test_chapter_create_own_permissions()
{
public function test_chapter_create_own_permissions()
{
- $book = \BookStack\Entities\Book::take(1)->get()->first();
+ $book = Book::take(1)->get()->first();
$ownBook = $this->createEntityChainBelongingToUser($this->user)['book'];
$this->checkAccessPermission('chapter-create-own', [
$ownBook->getUrl('/create-chapter')
$ownBook = $this->createEntityChainBelongingToUser($this->user)['book'];
$this->checkAccessPermission('chapter-create-own', [
$ownBook->getUrl('/create-chapter')
public function test_chapter_create_all_permissions()
{
public function test_chapter_create_all_permissions()
{
- $book = \BookStack\Entities\Book::take(1)->get()->first();
+ $book = Book::take(1)->get()->first();
$this->checkAccessPermission('chapter-create-all', [
$book->getUrl('/create-chapter')
], [
$this->checkAccessPermission('chapter-create-all', [
$book->getUrl('/create-chapter')
], [
public function test_chapter_edit_own_permission()
{
public function test_chapter_edit_own_permission()
{
- $otherChapter = \BookStack\Entities\Chapter::take(1)->get()->first();
+ $otherChapter = Chapter::take(1)->get()->first();
$ownChapter = $this->createEntityChainBelongingToUser($this->user)['chapter'];
$this->checkAccessPermission('chapter-update-own', [
$ownChapter->getUrl() . '/edit'
$ownChapter = $this->createEntityChainBelongingToUser($this->user)['chapter'];
$this->checkAccessPermission('chapter-update-own', [
$ownChapter->getUrl() . '/edit'
public function test_chapter_edit_all_permission()
{
public function test_chapter_edit_all_permission()
{
- $otherChapter = \BookStack\Entities\Chapter::take(1)->get()->first();
+ $otherChapter = Chapter::take(1)->get()->first();
$this->checkAccessPermission('chapter-update-all', [
$otherChapter->getUrl() . '/edit'
], [
$this->checkAccessPermission('chapter-update-all', [
$otherChapter->getUrl() . '/edit'
], [
public function test_chapter_delete_own_permission()
{
$this->giveUserPermissions($this->user, ['chapter-update-all']);
public function test_chapter_delete_own_permission()
{
$this->giveUserPermissions($this->user, ['chapter-update-all']);
- $otherChapter = \BookStack\Entities\Chapter::take(1)->get()->first();
+ $otherChapter = Chapter::take(1)->get()->first();
$ownChapter = $this->createEntityChainBelongingToUser($this->user)['chapter'];
$this->checkAccessPermission('chapter-delete-own', [
$ownChapter->getUrl() . '/delete'
$ownChapter = $this->createEntityChainBelongingToUser($this->user)['chapter'];
$this->checkAccessPermission('chapter-delete-own', [
$ownChapter->getUrl() . '/delete'
public function test_chapter_delete_all_permission()
{
$this->giveUserPermissions($this->user, ['chapter-update-all']);
public function test_chapter_delete_all_permission()
{
$this->giveUserPermissions($this->user, ['chapter-update-all']);
- $otherChapter = \BookStack\Entities\Chapter::take(1)->get()->first();
+ $otherChapter = Chapter::take(1)->get()->first();
$this->checkAccessPermission('chapter-delete-all', [
$otherChapter->getUrl() . '/delete'
], [
$this->checkAccessPermission('chapter-delete-all', [
$otherChapter->getUrl() . '/delete'
], [
public function test_page_create_own_permissions()
{
public function test_page_create_own_permissions()
{
- $book = \BookStack\Entities\Book::first();
- $chapter = \BookStack\Entities\Chapter::first();
+ $book = Book::first();
+ $chapter = Chapter::first();
$entities = $this->createEntityChainBelongingToUser($this->user);
$ownBook = $entities['book'];
$entities = $this->createEntityChainBelongingToUser($this->user);
$ownBook = $entities['book'];
foreach ($accessUrls as $index => $url) {
$this->actingAs($this->user)->visit($url);
foreach ($accessUrls as $index => $url) {
$this->actingAs($this->user)->visit($url);
- $expectedUrl = \BookStack\Entities\Page::where('draft', '=', true)->orderBy('id', 'desc')->first()->getUrl();
+ $expectedUrl = Page::where('draft', '=', true)->orderBy('id', 'desc')->first()->getUrl();
$this->seePageIs($expectedUrl);
}
$this->seePageIs($expectedUrl);
}
public function test_page_create_all_permissions()
{
public function test_page_create_all_permissions()
{
- $book = \BookStack\Entities\Book::take(1)->get()->first();
- $chapter = \BookStack\Entities\Chapter::take(1)->get()->first();
+ $book = Book::take(1)->get()->first();
+ $chapter = Chapter::take(1)->get()->first();
$baseUrl = $book->getUrl() . '/page';
$createUrl = $book->getUrl('/create-page');
$baseUrl = $book->getUrl() . '/page';
$createUrl = $book->getUrl('/create-page');
foreach ($accessUrls as $index => $url) {
$this->actingAs($this->user)->visit($url);
foreach ($accessUrls as $index => $url) {
$this->actingAs($this->user)->visit($url);
- $expectedUrl = \BookStack\Entities\Page::where('draft', '=', true)->orderBy('id', 'desc')->first()->getUrl();
+ $expectedUrl = Page::where('draft', '=', true)->orderBy('id', 'desc')->first()->getUrl();
$this->seePageIs($expectedUrl);
}
$this->seePageIs($expectedUrl);
}
public function test_page_edit_own_permission()
{
public function test_page_edit_own_permission()
{
- $otherPage = \BookStack\Entities\Page::take(1)->get()->first();
+ $otherPage = Page::take(1)->get()->first();
$ownPage = $this->createEntityChainBelongingToUser($this->user)['page'];
$this->checkAccessPermission('page-update-own', [
$ownPage->getUrl() . '/edit'
$ownPage = $this->createEntityChainBelongingToUser($this->user)['page'];
$this->checkAccessPermission('page-update-own', [
$ownPage->getUrl() . '/edit'
public function test_page_edit_all_permission()
{
public function test_page_edit_all_permission()
{
- $otherPage = \BookStack\Entities\Page::take(1)->get()->first();
+ $otherPage = Page::take(1)->get()->first();
$this->checkAccessPermission('page-update-all', [
$otherPage->getUrl() . '/edit'
], [
$this->checkAccessPermission('page-update-all', [
$otherPage->getUrl() . '/edit'
], [
public function test_page_delete_own_permission()
{
$this->giveUserPermissions($this->user, ['page-update-all']);
public function test_page_delete_own_permission()
{
$this->giveUserPermissions($this->user, ['page-update-all']);
- $otherPage = \BookStack\Entities\Page::take(1)->get()->first();
+ $otherPage = Page::take(1)->get()->first();
$ownPage = $this->createEntityChainBelongingToUser($this->user)['page'];
$this->checkAccessPermission('page-delete-own', [
$ownPage->getUrl() . '/delete'
$ownPage = $this->createEntityChainBelongingToUser($this->user)['page'];
$this->checkAccessPermission('page-delete-own', [
$ownPage->getUrl() . '/delete'
public function test_page_delete_all_permission()
{
$this->giveUserPermissions($this->user, ['page-update-all']);
public function test_page_delete_all_permission()
{
$this->giveUserPermissions($this->user, ['page-update-all']);
- $otherPage = \BookStack\Entities\Page::take(1)->get()->first();
+ $otherPage = Page::take(1)->get()->first();
$this->checkAccessPermission('page-delete-all', [
$otherPage->getUrl() . '/delete'
], [
$this->checkAccessPermission('page-delete-all', [
$otherPage->getUrl() . '/delete'
], [
public function test_public_role_visible_in_user_edit_screen()
{
public function test_public_role_visible_in_user_edit_screen()
{
- $user = \BookStack\Auth\User::first();
$adminRole = Role::getSystemRole('admin');
$publicRole = Role::getSystemRole('public');
$this->asAdmin()->visit('/settings/users/' . $user->id)
$adminRole = Role::getSystemRole('admin');
$publicRole = Role::getSystemRole('public');
$this->asAdmin()->visit('/settings/users/' . $user->id)
public function test_image_delete_own_permission()
{
$this->giveUserPermissions($this->user, ['image-update-all']);
public function test_image_delete_own_permission()
{
$this->giveUserPermissions($this->user, ['image-update-all']);
- $page = \BookStack\Entities\Page::first();
- $image = factory(\BookStack\Uploads\Image::class)->create(['uploaded_to' => $page->id, 'created_by' => $this->user->id, 'updated_by' => $this->user->id]);
+ $page = Page::first();
+ $image = factory(Image::class)->create(['uploaded_to' => $page->id, 'created_by' => $this->user->id, 'updated_by' => $this->user->id]);
$this->actingAs($this->user)->json('delete', '/images/' . $image->id)
->seeStatusCode(403);
$this->actingAs($this->user)->json('delete', '/images/' . $image->id)
->seeStatusCode(403);
{
$this->giveUserPermissions($this->user, ['image-update-all']);
$admin = $this->getAdmin();
{
$this->giveUserPermissions($this->user, ['image-update-all']);
$admin = $this->getAdmin();
- $page = \BookStack\Entities\Page::first();
- $image = factory(\BookStack\Uploads\Image::class)->create(['uploaded_to' => $page->id, 'created_by' => $admin->id, 'updated_by' => $admin->id]);
+ $page = Page::first();
+ $image = factory(Image::class)->create(['uploaded_to' => $page->id, 'created_by' => $admin->id, 'updated_by' => $admin->id]);
$this->actingAs($this->user)->json('delete', '/images/' . $image->id)
->seeStatusCode(403);
$this->actingAs($this->user)->json('delete', '/images/' . $image->id)
->seeStatusCode(403);
{
// To cover issue fixed in f99c8ff99aee9beb8c692f36d4b84dc6e651e50a.
$page = Page::first();
{
// To cover issue fixed in f99c8ff99aee9beb8c692f36d4b84dc6e651e50a.
$page = Page::first();
- $viewerRole = \BookStack\Auth\Role::getRole('viewer');
+ $viewerRole = Role::getRole('viewer');
$viewer = $this->getViewer();
$this->actingAs($viewer)->visit($page->getUrl())->assertResponseStatus(200);
$viewer = $this->getViewer();
$this->actingAs($viewer)->visit($page->getUrl())->assertResponseStatus(200);
{
$admin = $this->getAdmin();
// Book links
{
$admin = $this->getAdmin();
// Book links
- $book = factory(\BookStack\Entities\Book::class)->create(['created_by' => $admin->id, 'updated_by' => $admin->id]);
+ $book = factory(Book::class)->create(['created_by' => $admin->id, 'updated_by' => $admin->id]);
$this->updateEntityPermissions($book);
$this->actingAs($this->getViewer())->visit($book->getUrl())
->dontSee('Create a new page')
->dontSee('Add a chapter');
// Chapter links
$this->updateEntityPermissions($book);
$this->actingAs($this->getViewer())->visit($book->getUrl())
->dontSee('Create a new page')
->dontSee('Add a chapter');
// Chapter links
- $chapter = factory(\BookStack\Entities\Chapter::class)->create(['created_by' => $admin->id, 'updated_by' => $admin->id, 'book_id' => $book->id]);
+ $chapter = factory(Chapter::class)->create(['created_by' => $admin->id, 'updated_by' => $admin->id, 'book_id' => $book->id]);
$this->updateEntityPermissions($chapter);
$this->actingAs($this->getViewer())->visit($chapter->getUrl())
->dontSee('Create a new page')
$this->updateEntityPermissions($chapter);
$this->actingAs($this->getViewer())->visit($chapter->getUrl())
->dontSee('Create a new page')
}
private function addComment($page) {
}
private function addComment($page) {
- $comment = factory(\BookStack\Actions\Comment::class)->make();
+ $comment = factory(Comment::class)->make();
$url = "/comment/$page->id";
$request = [
'text' => $comment->text,
$url = "/comment/$page->id";
$request = [
'text' => $comment->text,
}
private function updateComment($commentId) {
}
private function updateComment($commentId) {
- $comment = factory(\BookStack\Actions\Comment::class)->make();
+ $comment = factory(Comment::class)->make();
$url = "/comment/$commentId";
$request = [
'text' => $comment->text,
$url = "/comment/$commentId";
$request = [
'text' => $comment->text,
<?php namespace Tests\User;
<?php namespace Tests\User;
+use BookStack\Actions\ActivityType;
use BookStack\Api\ApiToken;
use Carbon\Carbon;
use Tests\TestCase;
use BookStack\Api\ApiToken;
use Carbon\Carbon;
use Tests\TestCase;
$this->assertTrue(strlen($secret) === 32);
$this->assertSessionHas('success');
$this->assertTrue(strlen($secret) === 32);
$this->assertSessionHas('success');
+ $this->assertActivityExists(ActivityType::API_TOKEN_CREATE);
}
public function test_create_with_no_expiry_sets_expiry_hundred_years_away()
}
public function test_create_with_no_expiry_sets_expiry_hundred_years_away()
$this->assertDatabaseHas('api_tokens', array_merge($updateData, ['id' => $token->id]));
$this->assertSessionHas('success');
$this->assertDatabaseHas('api_tokens', array_merge($updateData, ['id' => $token->id]));
$this->assertSessionHas('success');
+ $this->assertActivityExists(ActivityType::API_TOKEN_UPDATE);
}
public function test_token_update_with_blank_expiry_sets_to_hundred_years_away()
}
public function test_token_update_with_blank_expiry_sets_to_hundred_years_away()
$resp = $this->delete($tokenUrl);
$resp->assertRedirect($editor->getEditUrl('#api_tokens'));
$this->assertDatabaseMissing('api_tokens', ['id' => $token->id]);
$resp = $this->delete($tokenUrl);
$resp->assertRedirect($editor->getEditUrl('#api_tokens'));
$this->assertDatabaseMissing('api_tokens', ['id' => $token->id]);
+ $this->assertActivityExists(ActivityType::API_TOKEN_DELETE);
}
public function test_user_manage_can_delete_token_without_api_permission_themselves()
}
public function test_user_manage_can_delete_token_without_api_permission_themselves()