Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
send notifications also to @group approvers
- Loading branch information
1 parent
9b6ad60
commit b664e7d
Showing
4 changed files
with
72 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<?php | ||
|
||
namespace dokuwiki\plugin\approve\meta; | ||
|
||
use dokuwiki\plugin\sqlite\SQLiteDB; | ||
use dokuwiki\Extension\AuthPlugin; | ||
|
||
class ApproveMetadata | ||
{ | ||
|
||
protected $db; | ||
|
||
public function __construct() | ||
{ | ||
$this->db = new SQLiteDB('approve', DOKU_PLUGIN . 'sqlite/db/'); | ||
} | ||
|
||
public function getPages($user=null, $states=['approved', 'draft', 'ready_for_approval'], $namespace='', $filter=''): array | ||
{ | ||
/* @var AuthPlugin $auth */ | ||
global $auth; | ||
|
||
$sql = 'SELECT page.page, page.approver, revision.rev, revision.approved, revision.approved_by, | ||
revision.ready_for_approval, revision.ready_for_approval_by, | ||
LENGTH(page.page) - LENGTH(REPLACE(page.page, \':\', \'\')) AS colons | ||
FROM page INNER JOIN revision ON page.page = revision.page | ||
WHERE page.hidden = 0 AND revision.current=1 AND page.page GLOB ? AND page.page REGEXP ? | ||
ORDER BY colons, page.page'; | ||
$pages = $this->db->queryAll($sql, $namespace.'*', $filter); | ||
|
||
if ($user) { | ||
$user_data = $auth->getUserData($user); | ||
$user_groups = $user_data['grps']; | ||
$pages = array_filter($pages, function ($page) use ($user, $user_groups) { | ||
return $page['approver'][0] == '@' && in_array(substr($page['approver'], 1), $user_groups) || | ||
$page['approver'] == $user; | ||
}); | ||
} | ||
|
||
// add status to the page | ||
$pages = array_map(function ($page) { | ||
if ($page['approved'] !== null) { | ||
$page['status'] = 'approved'; | ||
} elseif ($page['ready_for_approval'] !== null) { | ||
$page['status'] = 'ready_for_approval'; | ||
} else { | ||
$page['status'] = 'draft'; | ||
} | ||
return $page; | ||
}, $pages); | ||
|
||
// filter by status | ||
$pages = array_filter($pages, function ($page) use ($states) { | ||
return in_array($page['status'], $states); | ||
}); | ||
|
||
return $pages; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
base approve | ||
author Szymon Olewniczak | ||
email it@rid.pl | ||
date 2022-03-29 | ||
date 2023-11-17 | ||
name approve | ||
desc Page approval mechanism for dokuwiki. | ||
url https://www.dokuwiki.org/plugin:approve |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters