Skip to content

Commit

Permalink
Merge pull request #39 from open-sausages/master
Browse files Browse the repository at this point in the history
Fixes and polish
  • Loading branch information
Damian Mooyman committed Aug 2, 2015
2 parents bb9560f + 0b11841 commit 4ae4b77
Show file tree
Hide file tree
Showing 12 changed files with 105 additions and 28 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ before_script:
- cd ~/builds/ss
- composer install

script:
- vendor/bin/phpunit sharedraftcontent/tests/
script:
- vendor/bin/phpunit sharedraftcontent/tests
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,27 @@

[![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

```
$ 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.
4 changes: 2 additions & 2 deletions _config/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ SiteTree:
CMSMain:
extensions:
- ShareDraftContentRequirementsExtension
CMSPageEditController:
Controller:
extensions:
- ShareDraftContentCMSPageEditControllerExtension
- ShareDraftContentControllerExtension
Director:
rules:
'preview': 'ShareDraftController'
Expand Down

This file was deleted.

32 changes: 32 additions & 0 deletions code/extensions/ShareDraftContentControllerExtension.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

class ShareDraftContentControllerExtension extends Extension {
/**
* @var array
*/
private static $allowed_actions = array(
'MakeShareDraftLink',
);

/**
* @return mixed
*/
public function MakeShareDraftLink() {
if ($member = Member::currentUser()) {
if($this->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');
}
}
3 changes: 3 additions & 0 deletions code/extensions/ShareDraftContentRequirementsExtension.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
<?php

class ShareDraftContentRequirementsExtension extends DataExtension {
/**
* @inheritdoc
*/
public function init() {
Requirements::css(SHAREDRAFTCONTENT_DIR . '/css/share-component.css');
Requirements::javascript(SHAREDRAFTCONTENT_DIR . '/javascript/main.js');
Expand Down
20 changes: 19 additions & 1 deletion code/extensions/ShareDraftContentSiteTreeExtension.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
<?php

/**
* @mixin SiteTree
*/
class ShareDraftContentSiteTreeExtension extends DataExtension {
/**
* The number of days a shared link should be valid for, before expiring.
Expand All @@ -24,13 +27,20 @@ class ShareDraftContentSiteTreeExtension extends DataExtension {
'ShareTokens' => '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);
}

/**
Expand Down Expand Up @@ -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');
}
}
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
2 changes: 1 addition & 1 deletion docs/developer.md → docs/developer-tools.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Front-end development
# Developer Tools

Get the dependencies by running `npm install`.

Expand Down
9 changes: 9 additions & 0 deletions docs/getting-started.md
Original file line number Diff line number Diff line change
@@ -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.
23 changes: 23 additions & 0 deletions docs/introduction.md
Original file line number Diff line number Diff line change
@@ -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).
6 changes: 5 additions & 1 deletion templates/Includes/LeftAndMain_ViewModeSelector.ss
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@

<div id="share-draft-content" class="ss-tabset ss-ui-action-tabset action-menus">
<ul>
<li><a class="popup-trigger" href="#share-draft-content-tab" data-makelink-action="$Controller.MakeLinkAction">Share draft</a></li>
<% if $CurrentPage.ShareDraftLinkAction %>
<li><a class="popup-trigger" href="#share-draft-content-tab" data-makelink-action="{$CurrentPage.ShareDraftLinkAction}">Share draft</a></li>
<% else %>
<li><a class="popup-trigger" href="#share-draft-content-tab" data-makelink-action="{$Controller.CurrentPage.ShareDraftLinkAction}">Share draft</a></li>
<% end_if %>
</ul>
<div id="share-draft-content-tab">
<div>
Expand Down

0 comments on commit 4ae4b77

Please sign in to comment.