Skip to content

Commit 3fb6bce

Browse files
committed
Permissions
1 parent 2565b6a commit 3fb6bce

File tree

4 files changed

+21
-3
lines changed

4 files changed

+21
-3
lines changed

src/Actions/ClearCache.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ public static function title()
2929

3030
public function visibleTo($item)
3131
{
32+
if (! auth()->user()->can('clear cache tracker tags')) {
33+
return false;
34+
}
35+
3236
if (! $item instanceof Entry) {
3337
return false;
3438
}

src/Actions/ViewCacheTags.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
use Statamic\Actions\Action;
66
use Statamic\Contracts\Entries\Entry;
77
use Statamic\Facades\Blink;
8-
use Thoughtco\StatamicCacheTracker\Facades\Tracker;
98

109
class ViewCacheTags extends Action
1110
{
@@ -30,6 +29,10 @@ public static function title()
3029

3130
public function visibleTo($item)
3231
{
32+
if (! auth()->user()->can('view cache tracker tags')) {
33+
return false;
34+
}
35+
3336
if (! $item instanceof Entry) {
3437
return false;
3538
}

src/ServiceProvider.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Thoughtco\StatamicCacheTracker;
44

5+
use Statamic\Facades\Permission;
56
use Statamic\Providers\AddonServiceProvider;
67

78
class ServiceProvider extends AddonServiceProvider
@@ -40,5 +41,15 @@ public function boot()
4041
$this->publishes([
4142
$config => config_path('statamic-cache-tracker.php'),
4243
], 'statamic-cache-tracker-config');
44+
45+
Permission::group('cache-tracker', 'Cache Tracker', function () {
46+
Permission::register('view cache tracker tags')
47+
->label(__('View Tags'))
48+
->description(__('Enables the action on listing views to view tags'));
49+
50+
Permission::register('clear cache tracker tags')
51+
->label(__('Clear Tags'))
52+
->description(__('Enables the action on listing views to clear tags'));
53+
});
4354
}
4455
}

tests/Unit/EventListenerTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public function it_tracks_tags_from_events()
2323
return response('');
2424
};
2525

26-
$middleware = new CacheTracker();
26+
$middleware = new CacheTracker;
2727
$middleware->handle($request, $next);
2828

2929
$this->assertSame(['test::tag'], collect(Tracker::all())->firstWhere('url', 'http://localhost/')['tags']);
@@ -40,7 +40,7 @@ public function dispatching_job_clears_tags()
4040
return response('');
4141
};
4242

43-
$middleware = new CacheTracker();
43+
$middleware = new CacheTracker;
4444
$middleware->handle($request, $next);
4545

4646
$this->assertSame(['test::tag'], collect(Tracker::all())->firstWhere('url', 'http://localhost/')['tags']);

0 commit comments

Comments
 (0)