Skip to content

Commit befa3a8

Browse files
committed
Permissions: Started addition of revision-view permission
1 parent 083fb1a commit befa3a8

7 files changed

Lines changed: 40 additions & 5 deletions

File tree

app/Entities/Controllers/PageRevisionController.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ public function __construct(
3434
*/
3535
public function index(Request $request, string $bookSlug, string $pageSlug)
3636
{
37+
$this->checkPermission(Permission::RevisionViewAll);
3738
$page = $this->pageQueries->findVisibleBySlugsOrFail($bookSlug, $pageSlug);
3839
$listOptions = SimpleListOptions::fromRequest($request, 'page_revisions', true)->withSortOptions([
3940
'id' => trans('entities.pages_revisions_sort_number')
@@ -65,6 +66,8 @@ public function index(Request $request, string $bookSlug, string $pageSlug)
6566
*/
6667
public function show(string $bookSlug, string $pageSlug, int $revisionId)
6768
{
69+
$this->checkPermission(Permission::RevisionViewAll);
70+
6871
$page = $this->pageQueries->findVisibleBySlugsOrFail($bookSlug, $pageSlug);
6972
/** @var ?PageRevision $revision */
7073
$revision = $page->revisions()->where('id', '=', $revisionId)->first();
@@ -94,6 +97,8 @@ public function show(string $bookSlug, string $pageSlug, int $revisionId)
9497
*/
9598
public function changes(string $bookSlug, string $pageSlug, int $revisionId)
9699
{
100+
$this->checkPermission(Permission::RevisionViewAll);
101+
97102
$page = $this->pageQueries->findVisibleBySlugsOrFail($bookSlug, $pageSlug);
98103
/** @var ?PageRevision $revision */
99104
$revision = $page->revisions()->where('id', '=', $revisionId)->first();
@@ -130,6 +135,7 @@ public function changes(string $bookSlug, string $pageSlug, int $revisionId)
130135
public function restore(string $bookSlug, string $pageSlug, int $revisionId)
131136
{
132137
$page = $this->pageQueries->findVisibleBySlugsOrFail($bookSlug, $pageSlug);
138+
$this->checkPermission(Permission::RevisionViewAll);
133139
$this->checkOwnablePermission(Permission::PageUpdate, $page);
134140

135141
$page = $this->pageRepo->restoreRevision($page, $revisionId);
@@ -145,6 +151,7 @@ public function restore(string $bookSlug, string $pageSlug, int $revisionId)
145151
public function destroy(string $bookSlug, string $pageSlug, int $revId)
146152
{
147153
$page = $this->pageQueries->findVisibleBySlugsOrFail($bookSlug, $pageSlug);
154+
$this->checkPermission(Permission::RevisionViewAll);
148155
$this->checkOwnablePermission(Permission::PageDelete, $page);
149156

150157
$revision = $page->revisions()->where('id', '=', $revId)->first();

app/Permissions/Permission.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,8 @@ enum Permission: string
118118
case PageViewAll = 'page-view-all';
119119
case PageViewOwn = 'page-view-own';
120120

121+
case RevisionViewAll = 'revision-view-all';
122+
121123
/**
122124
* Get the generic permissions which may be queried for entities.
123125
*/

lang/en/settings.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,7 @@
207207
'role_all' => 'All',
208208
'role_own' => 'Own',
209209
'role_controlled_by_asset' => 'Controlled by the asset they are uploaded to',
210+
'role_controlled_by_page_delete' => 'Controlled by page delete permissions',
210211
'role_save' => 'Save Role',
211212
'role_users' => 'Users in this role',
212213
'role_users_none' => 'No users are currently assigned to this role',

resources/views/entities/meta.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
</div>
1010
@endif
1111

12-
@if ($entity->isA('page'))
12+
@if ($entity->isA('page') && userCan(\BookStack\Permissions\Permission::RevisionViewAll))
1313
<a href="{{ $entity->getUrl('/revisions') }}" class="entity-meta-item">
1414
@icon('history'){{ trans('entities.meta_revision', ['revisionCount' => $entity->revision_count]) }}
1515
</a>

resources/views/pages/parts/show-sidebar-section-actions.blade.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,12 @@
2424
</a>
2525
@endif
2626
@endif
27-
<a href="{{ $page->getUrl('/revisions') }}" data-shortcut="revisions" class="icon-list-item">
28-
<span>@icon('history')</span>
29-
<span>{{ trans('entities.revisions') }}</span>
30-
</a>
27+
@if(userCan(\BookStack\Permissions\Permission::RevisionViewAll))
28+
<a href="{{ $page->getUrl('/revisions') }}" data-shortcut="revisions" class="icon-list-item">
29+
<span>@icon('history')</span>
30+
<span>{{ trans('entities.revisions') }}</span>
31+
</a>
32+
@endif
3133
@if(userCan(\BookStack\Permissions\Permission::RestrictionsManage, $page))
3234
<a href="{{ $page->getUrl('/permissions') }}" data-shortcut="permissions" class="icon-list-item">
3335
<span>@icon('lock')</span>

resources/views/settings/roles/parts/form.blade.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ class="item-list toggle-switch-list">
7979
@include('settings.roles.parts.asset-permissions-row', ['title' => trans('entities.books'), 'permissionPrefix' => 'book'])
8080
@include('settings.roles.parts.asset-permissions-row', ['title' => trans('entities.chapters'), 'permissionPrefix' => 'chapter'])
8181
@include('settings.roles.parts.asset-permissions-row', ['title' => trans('entities.pages'), 'permissionPrefix' => 'page'])
82+
@include('settings.roles.parts.revisions-permissions-row', ['title' => trans('entities.revisions'), 'permissionPrefix' => 'revision'])
8283
@include('settings.roles.parts.related-asset-permissions-row', ['title' => trans('entities.images'), 'permissionPrefix' => 'image'])
8384
@include('settings.roles.parts.related-asset-permissions-row', ['title' => trans('entities.attachments'), 'permissionPrefix' => 'attachment'])
8485
@include('settings.roles.parts.related-asset-permissions-row', ['title' => trans('entities.comments'), 'permissionPrefix' => 'comment'])
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<div class="item-list-row flex-container-row items-center wrap">
2+
<div class="flex py-s px-m min-width-s">
3+
<strong>{{ $title }}</strong> <br>
4+
<a href="#" refs="permissions-table@toggle-row" class="text-small text-link">{{ trans('common.toggle_all') }}</a>
5+
</div>
6+
<div class="flex py-s px-m min-width-xxs">
7+
<small class="hide-over-m bold">{{ trans('common.create') }}<br></small>
8+
<strong class="text-muted opacity-70 text-large">-</strong>
9+
</div>
10+
<div class="flex py-s px-m min-width-xxs">
11+
<small class="hide-over-m bold">{{ trans('common.view') }}<br></small>
12+
@include('settings.roles.parts.checkbox', ['permission' => $permissionPrefix . '-view-all', 'label' => trans('settings.role_all')])
13+
</div>
14+
<div class="flex py-s px-m min-width-xxs">
15+
<small class="hide-over-m bold">{{ trans('common.edit') }}<br></small>
16+
<strong class="text-muted opacity-70 text-large">-</strong>
17+
</div>
18+
<div class="flex py-s px-m min-width-xxs">
19+
<small class="hide-over-m bold">{{ trans('common.delete') }}<br></small>
20+
<small>{{ trans('settings.role_controlled_by_page_delete') }}</small>
21+
</div>
22+
</div>

0 commit comments

Comments
 (0)