diff --git a/_config/config.yml b/_config/config.yml index e2bb3b2..94030c2 100644 --- a/_config/config.yml +++ b/_config/config.yml @@ -7,4 +7,7 @@ LeftAndMain: - 'betternavigator/javascript/BN.LeftAndMain.Preview.js' ContentController: extensions: - - BetterNavigator \ No newline at end of file + - BetterNavigator +Permission: + extensions: + - BetterNavigator_Permissions \ No newline at end of file diff --git a/code/BetterNavigator.php b/code/BetterNavigator.php index 72e26a7..004ea32 100755 --- a/code/BetterNavigator.php +++ b/code/BetterNavigator.php @@ -25,7 +25,7 @@ class BetterNavigator extends DataExtension { public function BetterNavigator() { $isDev = Director::isDev(); - if($isDev || Permission::check('CMS_ACCESS_CMSMain') || Permission::check('VIEW_DRAFT_CONTENT')) { + if($isDev || Permission::check('CMS_ACCESS_CMSMain') || Permission::check('VIEW_DRAFT_CONTENT')) { if($this->owner && $this->owner->dataRecord && $this->owner->dataRecord instanceof SiteTree) { //Get SilverStripeNavigator links & stage info (CMS/Stage/Live/Archive) @@ -50,6 +50,7 @@ class BetterNavigator extends DataExtension { 'Stage' => Versioned::current_stage(), 'LoginLink' => Config::inst()->get('Security', 'login_url'), 'Mode' => Director::get_environment_type(), + 'CanEdit' => Permission::check('BETTERNAVIGATOR_CANEDIT'), 'IsDeveloper' => $isDeveloper )); @@ -62,3 +63,39 @@ class BetterNavigator extends DataExtension { return false; } } + +class BetterNavigator_Permissions extends Extension implements PermissionProvider +{ + /** + * Provide permissions for viewing better navigator on the front end + * + * @return array + */ + public function providePermissions() + { + return array( + "BETTERNAVIGATOR_CANEDIT" => array( + 'name' => 'Show Better Navigator `Edit in CMS` Option', + 'category' => 'Front End' + ) + ); + } + + public function requireDefaultRecords() + { + $contentGroup = Group::get()->filter('code', 'content-authors')->first(); + $previousPermissions = Permission::get()->filter('Code', 'BETTERNAVIGATOR_CANEDIT'); + + if ($contentGroup && $contentGroup->exists() && !$previousPermissions->count()) { + Permission::create( + array( + 'Code' => 'BETTERNAVIGATOR_CANEDIT', + 'Type' => 1, + 'GroupID' => $contentGroup->ID + ) + )->write(); + + DB::alteration_message('Default Better Navigator permissions created', 'created'); + } + } +} diff --git a/templates/BetterNavigator.ss b/templates/BetterNavigator.ss index a6c4d04..f41c130 100644 --- a/templates/BetterNavigator.ss +++ b/templates/BetterNavigator.ss @@ -31,8 +31,9 @@ Deleted from draft site <% end_if %> <% end_if %> - Edit in CMS - + <% if $CanEdit %> + Edit in CMS + <% end_if %> <% if $Member %> Log out<% if $Member.FirstName %> ($Member.FirstName)<% end_if %> <% else %>