From 23dc19fbefce4a921bad12899bca151f398ef743 Mon Sep 17 00:00:00 2001 From: phy25 Date: Wed, 25 Jan 2017 14:18:39 +0800 Subject: [PATCH 1/3] Add automatic self-approve support --- action/approve.php | 38 ++++++++++++++++++++++++++++++++++---- action/mail.php | 2 +- conf/default.php | 1 + conf/metadata.php | 1 + lang/en/settings.php | 1 + 5 files changed, 38 insertions(+), 5 deletions(-) diff --git a/action/approve.php b/action/approve.php index 08f7c8e..27ef3b6 100644 --- a/action/approve.php +++ b/action/approve.php @@ -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) { @@ -70,17 +71,16 @@ 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; - if (!$INFO['exists']) { + $approvalRevision = $approvalRevision ? $approvalRevision : $this->helper->getRevision(); + if (!file_exists(fullpath(wikiFN($ID, $approvalRevision)))) { msg($this->getLang('cannot approve a non-existing revision'), -1); return; } - - $approvalRevision = $this->helper->getRevision(); $approvals = $this->helper->getApprovals(); if (!isset($approvals[$approvalRevision])) { @@ -115,4 +115,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(); + return true; + } + } diff --git a/action/mail.php b/action/mail.php index 63fb90a..8acc9c2 100644 --- a/action/mail.php +++ b/action/mail.php @@ -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); } /** diff --git a/conf/default.php b/conf/default.php index 8d52fae..695a7ee 100644 --- a/conf/default.php +++ b/conf/default.php @@ -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; diff --git a/conf/metadata.php b/conf/metadata.php index cb9ea4b..15349f9 100644 --- a/conf/metadata.php +++ b/conf/metadata.php @@ -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'); diff --git a/lang/en/settings.php b/lang/en/settings.php index 9f25083..c3f00a4 100644 --- a/lang/en/settings.php +++ b/lang/en/settings.php @@ -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'; From 59dd21561255eaa0f8097f2362f4da55a864c003 Mon Sep 17 00:00:00 2001 From: phy25 Date: Wed, 25 Jan 2017 14:29:39 +0800 Subject: [PATCH 2/3] Add test for self approve --- _test/publish.test.php | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/_test/publish.test.php b/_test/publish.test.php index f96a0b8..2bcdc0f 100644 --- a/_test/publish.test.php +++ b/_test/publish.test.php @@ -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(), '
') !== false, 'The "not approved banner" is missing on a page which has not yet been aprroved with standard config.' @@ -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'); @@ -81,6 +83,21 @@ public function test_no_aprroved_banner() { strpos($response->getContent(), '