Skip to content

Add self-approve ability #97

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion _test/publish.test.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function setUp(){
public function test_unaprroved_banner_exists() {
saveWikiText('foo', 'bar', 'foobar');
$request = new TestRequest();
$response = $request->get(array('id' => 'foo'), '/doku.php?id=foo');
$response = $request->get(array(), '/doku.php?id=foo');
$this->assertTrue(
strpos($response->getContent(), '<div class="approval approved_no">') !== false,
'The "not approved banner" is missing on a page which has not yet been aprroved with standard config.'
Expand All @@ -56,6 +56,8 @@ public function test_unaprroved_banner_exists() {
* @coversNothing
*/
public function test_aprroval_succesful() {
global $conf;
$conf['plugin']['publish']['auto_self_approve'] = 0;
saveWikiText('foo', 'bar', 'foobar');
$request = new TestRequest();
$response = $request->get(array(), '/doku.php?id=foo&publish_approve=1');
Expand All @@ -81,6 +83,21 @@ public function test_no_aprroved_banner() {
strpos($response->getContent(), '<div class="approval') === false,
'The approved banner is still showing even so it is supposed not to show.'
);
}

/**
* @coversNothing
*/
public function test_self_aprrove() {
global $conf;
$conf['plugin']['publish']['auto_self_approve'] = 1;
saveWikiText('foo', 'bar', 'foobar');
$request = new TestRequest();
$response = $request->get(array(), '/doku.php?id=foo');

$this->assertTrue(
strpos($response->getContent(), '<div class="approval approved_yes') === false,
'Approving a page automatically failed.'
);
}
}
49 changes: 44 additions & 5 deletions action/approve.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ function __construct() {
function register(Doku_Event_Handler $controller) {
$controller->register_hook('ACTION_ACT_PREPROCESS', 'BEFORE', $this, 'handle_io_write', array());
$controller->register_hook('AJAX_CALL_UNKNOWN', 'BEFORE', $this, 'approveNS', array());
$controller->register_hook('IO_WIKIPAGE_WRITE', 'AFTER', $this, 'self_approve', array(), -1000);
}

function approveNS(Doku_Event &$event, $param) {
Expand Down Expand Up @@ -70,17 +71,25 @@ function handle_io_write(Doku_Event &$event, $param) {
send_redirect(wl($ID, array('rev' => $this->helper->getRevision()), true, '&'));
}

function addApproval() {
function addApproval($approvalRevision = null) {
global $USERINFO;
global $ID;
global $INFO;
global $REV;

if (!$INFO['exists']) {
msg($this->getLang('cannot approve a non-existing revision'), -1);
return;
if($approvalRevision){
if ($approvalRevision !== $REV && !page_exists($ID, $approvalRevision)) {
msg($this->getLang('cannot approve a non-existing revision'), -1);
return;
}
}else{
$approvalRevision = $this->helper->getRevision();
if (!$INFO['exists']) {
msg($this->getLang('cannot approve a non-existing revision'), -1);
return;
}
}

$approvalRevision = $this->helper->getRevision();
$approvals = $this->helper->getApprovals();

if (!isset($approvals[$approvalRevision])) {
Expand Down Expand Up @@ -115,4 +124,34 @@ function addApproval() {

}

function self_approve(Doku_Event &$event, $param){
global $ID;
global $ACT;
global $INFO;
global $conf;
$data = pageinfo();

if ($ACT != 'save' || !$event->result) {
return true;
}

// IO_WIKIPAGE_WRITE is always called twice when saving a page. This makes sure to only send the mail once.
if (!$event->data[3]) {
return true;
}

// Does the publish plugin apply to this page?
if (!$this->helper->isActive($ID)) {
return true;
}

// are we supposed to auto approve?
if (!$this->getConf('auto_self_approve') || !$this->helper->canApprove()) {
return true;
}

$this->addApproval($event->data[3]);
return true;
}

}
2 changes: 1 addition & 1 deletion action/mail.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ function __construct() {

public function register(Doku_Event_Handler $controller) {

$controller->register_hook('IO_WIKIPAGE_WRITE', 'AFTER', $this, 'send_change_mail', array());
$controller->register_hook('IO_WIKIPAGE_WRITE', 'AFTER', $this, 'send_change_mail', array(), 1000);
}

/**
Expand Down
1 change: 1 addition & 0 deletions conf/default.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
$conf['hidereaderbanner'] = 0;
$conf['hide drafts'] = 0;
$conf['hide_approved_banner'] = 0;
$conf['auto_self_approve'] = 0;
$conf['author groups'] = '';
$conf['internal note'] = '';
$conf['delete attic on first approve'] = 0;
Expand Down
1 change: 1 addition & 0 deletions conf/metadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
$meta['hide drafts'] = array('onoff');
$meta['hidereaderbanner'] = array('onoff');
$meta['hide_approved_banner'] = array('onoff');
$meta['auto_self_approve'] = array('onoff');
$meta['author groups'] = array('string');
$meta['internal note'] = array('string');
$meta['delete attic on first approve'] = array('onoff');
Expand Down
1 change: 1 addition & 0 deletions lang/en/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
$lang['hidereaderbanner'] = 'Hide banner to read only users';
$lang['hide drafts'] = 'Hide drafts to read only users';
$lang['hide_approved_banner'] = 'Hide banner on approved pages';
$lang['auto_self_approve'] = 'Self approve if possible when submitting edit';
$lang['author groups'] = 'Groups that can see drafts (separate by blank)';
$lang['internal note'] = 'Note on unapproved pages';
$lang['delete attic on first approve'] = 'Delete attic on first approve';
Expand Down