1515use JustBetter \Detour \Actions \MatchDetour ;
1616use JustBetter \Detour \Actions \ResolveRepository ;
1717use JustBetter \Detour \Actions \StoreDetour ;
18+ use JustBetter \Detour \Http \Middleware \AuthorizeDetours ;
1819use JustBetter \Detour \Http \Middleware \RedirectIfNeeded ;
1920use JustBetter \Detour \Repositories \FileRepository ;
21+ use Statamic \Auth \Permission ;
2022use Statamic \Facades \CP \Nav ;
23+ use Statamic \Facades \Permission as PermissionFacade ;
2124use Statamic \Providers \AddonServiceProvider ;
2225
2326class ServiceProvider extends AddonServiceProvider
@@ -76,6 +79,9 @@ protected function registerMiddleware(): static
7679 {
7780 $ this ->app ->booted (function () {
7881 $ router = app (Router::class);
82+
83+ $ router ->aliasMiddleware ('detours.access ' , AuthorizeDetours::class);
84+
7985 if (config ('justbetter.statamic-detour.mode ' ) === 'performance ' ) {
8086 $ router ->pushMiddlewareToGroup ('web ' , RedirectIfNeeded::class);
8187 } else {
@@ -90,6 +96,7 @@ public function bootAddon(): void
9096 {
9197 $ this
9298 ->bootConfig ()
99+ ->bootPermissions ()
93100 ->bootNavigation ()
94101 ->bootMigrations ();
95102 }
@@ -110,17 +117,33 @@ function ($nav) {
110117 $ nav ->content ('Overview ' )
111118 ->section ('Detours ' )
112119 ->route ('justbetter.detours.index ' )
113- ->icon ('<svg class="svg-icon" style="width: 2em; height: 2em;vertical-align: middle;text-align:center;fill: currentColor;overflow: hidden;" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg"><path d="M653.328 125.024l-56.576 56.704L734.88 320H399.68C240.88 320 112 448.992 112 607.776c0 158.816 128 287.952 288 287.952v-80c-112 0-208-93.312-208-208.016 0-114.688 93.152-208 207.84-208h334.96l-137.888 137.856 56.528 56.56 234.48-234.496L653.344 125.024z" fill="#565D64" /></svg> ' );
120+ ->can (config ()->string ('justbetter.statamic-detour.permissions.access ' ))
121+ ->icon ('<svg class="svg-icon" style="width: 1.25em; height: 1.25em;vertical-align: middle;text-align:center;fill: currentColor;overflow: hidden;" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg"><path d="M653.328 125.024l-56.576 56.704L734.88 320H399.68C240.88 320 112 448.992 112 607.776c0 158.816 128 287.952 288 287.952v-80c-112 0-208-93.312-208-208.016 0-114.688 93.152-208 207.84-208h334.96l-137.888 137.856 56.528 56.56 234.48-234.496L653.344 125.024z" fill="#565D64" /></svg> ' );
114122
115123 $ nav ->content ('Import / Export ' )
116124 ->section ('Detours ' )
117125 ->route ('justbetter.detours.actions.index ' )
126+ ->can (config ()->string ('justbetter.statamic-detour.permissions.access ' ))
118127 ->icon ('<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M7 4v12"/><path d="M4 13l3 3 3-3"/><path d="M17 20V8"/><path d="M14 11l3-3 3 3"/></svg> ' );
119128 });
120129
121130 return $ this ;
122131 }
123132
133+ protected function bootPermissions (): static
134+ {
135+ PermissionFacade::group ('detours ' , 'Detours ' , function () {
136+ $ permission = config ()->string ('justbetter.statamic-detour.permissions.access ' );
137+ PermissionFacade::register ($ permission , function (Permission $ permission ) {
138+ $ permission
139+ ->label ('Access detours ' )
140+ ->description ('Gives the user access to managing detours (view, create, delete) ' );
141+ });
142+ });
143+
144+ return $ this ;
145+ }
146+
124147 protected function bootMigrations (): static
125148 {
126149 $ driver = config ('justbetter.statamic-detour.driver ' );
0 commit comments