diff --git a/.travis.yml b/.travis.yml index 9f70ae7..51b8151 100644 --- a/.travis.yml +++ b/.travis.yml @@ -20,5 +20,5 @@ before_script: - cd ~/builds/ss - composer install -script: - - vendor/bin/phpunit sharedraftcontent/tests/ +script: + - vendor/bin/phpunit sharedraftcontent/tests diff --git a/README.md b/README.md index fd3c8a8..3d60cb6 100644 --- a/README.md +++ b/README.md @@ -2,16 +2,18 @@ [![Build Status](http://img.shields.io/travis/silverstripe-labs/silverstripe-sharedraftcontent.svg?style=flat-square)](https://travis-ci.org/silverstripe-labs/silverstripe-sharedraftcontent) [![Code Quality](http://img.shields.io/scrutinizer/g/silverstripe-labs/silverstripe-sharedraftcontent.svg?style=flat-square)](https://scrutinizer-ci.com/g/silverstripe-labs/silverstripe-sharedraftcontent) +[![Version](http://img.shields.io/packagist/v/silverstripe-labs/silverstripe-sharedraftcontent.svg?style=flat-square)](https://packagist.org/packages/silverstripe-labs/silverstripe-sharedraftcontent) +[![License](http://img.shields.io/packagist/l/silverstripe-labs/silverstripe-sharedraftcontent.svg?style=flat-square)](license.md) Share draft page content with non-CMS users. ## Overview -This module adds a 'Share draft' action menu to the CMS. This enables Content Authors to generate tokenised links to draft pages. Content Authors can share these links with anyone, allowing non-CMS user to view draft page content. Each preview link is valid for 30 days. +This module adds a 'Share draft' action menu to the CMS. This enables Content Authors to generate tokenised links to draft pages. Content authors can share these links with anyone, allowing non-CMS user to view draft page content. Each preview link is valid for 30 days. ## Requirements -- SilverStripe 3.1 +- SilverStripe ^3.1 ## Installation @@ -19,6 +21,8 @@ This module adds a 'Share draft' action menu to the CMS. This enables Content Au $ composer require silverstripe/sharedraftcontent ``` +You'll also need to run `dev/build`. + ## Documentation -See the [docs](docs/) folder. +See the [docs/en](docs/en/introduction.md) folder. diff --git a/_config/config.yml b/_config/config.yml index 4fe2307..734b906 100644 --- a/_config/config.yml +++ b/_config/config.yml @@ -8,9 +8,9 @@ SiteTree: CMSMain: extensions: - ShareDraftContentRequirementsExtension -CMSPageEditController: +Controller: extensions: - - ShareDraftContentCMSPageEditControllerExtension + - ShareDraftContentControllerExtension Director: rules: 'preview': 'ShareDraftController' diff --git a/code/extensions/ShareDraftContentCMSPageEditControllerExtension.php b/code/extensions/ShareDraftContentCMSPageEditControllerExtension.php deleted file mode 100644 index 6ce79fd..0000000 --- a/code/extensions/ShareDraftContentCMSPageEditControllerExtension.php +++ /dev/null @@ -1,16 +0,0 @@ -owner->Link('makelink'); - } - - public function makelink() { - return $this->owner->currentPage()->ShareTokenLink(); - } -} diff --git a/code/extensions/ShareDraftContentControllerExtension.php b/code/extensions/ShareDraftContentControllerExtension.php new file mode 100644 index 0000000..eb0f08f --- /dev/null +++ b/code/extensions/ShareDraftContentControllerExtension.php @@ -0,0 +1,32 @@ +owner->hasMethod('CurrentPage') && $this->owner->CurrentPage()->canEdit($member)) { + return $this->owner->CurrentPage()->ShareTokenLink(); + } elseif ($this->owner->hasMethod('canEdit') && $this->owner->canEdit($member)) { + return $this->owner->ShareTokenLink(); + } + } + + return Security::permissionFailure(); + } + + /** + * @return string + */ + public function getShareDraftLinkAction() { + return $this->owner->Link('MakeShareDraftLink'); + } +} diff --git a/code/extensions/ShareDraftContentRequirementsExtension.php b/code/extensions/ShareDraftContentRequirementsExtension.php index 0689efe..690fcf8 100644 --- a/code/extensions/ShareDraftContentRequirementsExtension.php +++ b/code/extensions/ShareDraftContentRequirementsExtension.php @@ -1,6 +1,9 @@ 'ShareToken', ); + /** + * @var array + */ + private static $allowed_actions = array( + 'MakeShareDraftLink' + ); + /** * @return string */ public function ShareTokenLink() { $shareToken = $this->getNewShareToken(); - return Controller::join_links($this->owner->AbsoluteLink(), 'preview', $this->generateKey($shareToken->Token), $shareToken->Token); + return Controller::join_links(Director::absoluteBaseURL(), 'preview', $this->generateKey($shareToken->Token), $shareToken->Token); } /** @@ -88,4 +98,12 @@ protected function getNewToken() { public function generateKey($salt) { return hash_pbkdf2('sha256', $salt, $this->owner->SharedTokenSalt, 1000, 16); } + + /** + * @return string + */ + public function getShareDraftLinkAction() + { + return $this->owner->Link('MakeShareDraftLink'); + } } diff --git a/composer.json b/composer.json index bfde920..13d265d 100644 --- a/composer.json +++ b/composer.json @@ -19,12 +19,12 @@ } ], "require": { - "php": ">=5.3.2", + "php": ">=5.3.3", "silverstripe/framework": "~3.1", "silverstripe/cms": "~3.1", "assertchris/hash-compat": "~1.0" }, "require-dev": { - "phpunit/phpunit": "~3.7" + "phpunit/phpunit": "~4.7" } } diff --git a/docs/developer.md b/docs/developer-tools.md similarity index 89% rename from docs/developer.md rename to docs/developer-tools.md index 30c45ab..3382ec8 100644 --- a/docs/developer.md +++ b/docs/developer-tools.md @@ -1,4 +1,4 @@ -# Front-end development +# Developer Tools Get the dependencies by running `npm install`. diff --git a/docs/getting-started.md b/docs/getting-started.md new file mode 100644 index 0000000..594674a --- /dev/null +++ b/docs/getting-started.md @@ -0,0 +1,9 @@ +# Getting Started + +The easiest way to install is by using [Composer](https://getcomposer.org): + +```sh +$ composer require silverstripe/sharedraftcontent +``` + +You'll also need to run `dev/build`. You should now see a link/button on the bottom-right of edit pages. Clicking the link will generate a new share link. diff --git a/docs/introduction.md b/docs/introduction.md new file mode 100644 index 0000000..03a9f35 --- /dev/null +++ b/docs/introduction.md @@ -0,0 +1,23 @@ +# Introduction + +[![Build Status](http://img.shields.io/travis/silverstripe-labs/silverstripe-sharedraftcontent.svg?style=flat-square)](https://travis-ci.org/silverstripe-labs/silverstripe-sharedraftcontent) +[![Code Quality](http://img.shields.io/scrutinizer/g/silverstripe-labs/silverstripe-sharedraftcontent.svg?style=flat-square)](https://scrutinizer-ci.com/g/silverstripe-labs/silverstripe-sharedraftcontent) +[![Version](http://img.shields.io/packagist/v/silverstripe-labs/silverstripe-sharedraftcontent.svg?style=flat-square)](https://packagist.org/packages/silverstripe-labs/silverstripe-sharedraftcontent) +[![License](http://img.shields.io/packagist/l/silverstripe-labs/silverstripe-sharedraftcontent.svg?style=flat-square)](license.md) + +Share draft page content with non-CMS users. + +## Share Links + +The generated share links have a public key and hash. There can be any number of share links per-page, but all share links are unique, and cannot be used to gain access to pages other than the one each link was created for. + +## Sections + +- [Getting Started](getting-started.md) +- [Developer Tools](developer-tools.md) + +## Questions + +This module was created by [SilverStripe](https://twitter.com/silverstripe). You can ask questions on Twitter. + +You can report bugs or request features on [GitHub](https://github.com/silverstripe-labs/silverstripe-sharedraftcontent/issues). diff --git a/templates/Includes/LeftAndMain_ViewModeSelector.ss b/templates/Includes/LeftAndMain_ViewModeSelector.ss index a836ee6..87b6319 100644 --- a/templates/Includes/LeftAndMain_ViewModeSelector.ss +++ b/templates/Includes/LeftAndMain_ViewModeSelector.ss @@ -12,7 +12,11 @@