Skip to content

Commit 8097752

Browse files
committed
add permission (#1)
1 parent db3cabe commit 8097752

File tree

4 files changed

+22
-2
lines changed

4 files changed

+22
-2
lines changed

CHANGELOG.md

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

33
All notable changes to `statamic-forma` will be documented in this file.
44

5+
## 1.0 - 2021-08-12
6+
7+
* official release
8+
* add permission
9+
510
## 0.8 - 2020-12-19
611

712
* Allow addons to pre/post process the config

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ Once you do that, you get a menu item in the cp that your users can access and u
3333

3434
![menu item](https://raw.githubusercontent.com/edalzell/statamic-forma/main/images/mailchimp-menu.png)
3535

36+
### Permissions
37+
38+
There is a `Manage Addon Settings` permission that must be enabled to allow a user to update the settings of any Forma-enabled addons.
39+
3640
### Extending
3741

3842
If your addon needs to wangjangle the config before loading and after saving, create your own controller that `extends \Edalzell\Forma\ConfigController` and use the `preProcess` and `postProcess` methods.

src/FormaAddon.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ private function bootNav()
3636
NavAPI::extend(fn (Nav $nav) => $nav
3737
->content($addon->name())
3838
->section('Settings')
39-
->route($addon->slug().'.config.edit')
39+
->can('manage addon settings')
40+
->route($addon->slug() . '.config.edit')
4041
->icon('settings-horizontal'));
4142
}
4243

src/ServiceProvider.php

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

33
namespace Edalzell\Forma;
44

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

@@ -16,6 +17,15 @@ public function boot()
1617
{
1718
parent::boot();
1819

19-
Statamic::booted(fn () => Forma::all()->each->boot());
20+
Statamic::booted(function () {
21+
$this->bootPermissions();
22+
Forma::all()->each->boot();
23+
});
24+
}
25+
26+
private function bootPermissions()
27+
{
28+
Permission::register('manage addon settings')
29+
->label('Manage Addon Settings');
2030
}
2131
}

0 commit comments

Comments
 (0)