-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlugin.php
116 lines (100 loc) · 4.98 KB
/
Plugin.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
<?php
namespace Kanboard\Plugin\SensitiveItem;
use Kanboard\Core\Plugin\Base;
use Kanboard\Core\Translator;
use Kanboard\Model\TaskMetadataModel;
use Kanboard\Model\TaskModel;
use JsonRPC\Exception\AuthenticationFailureException;
use Kanboard\Core\Filter\QueryBuilder;
use Kanboard\Core\Controller\AccessForbiddenException;
use Kanboard\Plugin\SensitiveItem\Model\FilteredTaskFinderModel;
use Kanboard\Plugin\SensitiveItem\Model\FilteredTaskLinkModel;
class Plugin extends Base
{
public function initialize()
{
// Add helper for form
$this->helper->register('sensitiveItemHelper', '\Kanboard\Plugin\SensitiveItem\Helper\SensitiveItemHelper');
// Add checkbox to first column of task form
$this->template->hook->attach('template:task:form:first-column', 'SensitiveItem:task_creation/sensitive');
$sensitiveFlag = FALSE;
// Task Creation: Get sensitive flag value / unset for db
$this->hook->on('model:task:creation:prepare', function(&$values) use(&$sensitiveFlag) {
$sensitiveFlag = $values['sensitive_flag'];
unset($values['sensitive_flag']);
});
// Task Creation: We now have a task ID, set the sensitive flag.
$this->hook->on('model:task:creation:aftersave', function($taskId) use(&$sensitiveFlag) {
$this->taskMetadataModel->save($taskId, array('sensitive_flag' => $sensitiveFlag));
});
// Task Update: Set sensitive flag
$this->hook->on('model:task:modification:prepare', function(&$values) {
$task = $this->taskFinderModel->getDetails($this->request->getIntegerParam('task_id'));
$this->taskMetadataModel->save($task['id'], array('sensitive_flag' => $values['sensitive_flag'] == 1 ? true : false));
unset($values['sensitive_flag']);
});
// For public board view, exclude with sensitive flag
$this->hook->on('formatter:board:query', function (\PicoDb\Table &$query) {
if($this->router->getController() == "BoardViewController" && $this->router->getAction() == "readonly") {
$query->subquery("SELECT `value` FROM `task_has_metadata` WHERE `task_id` = " . TaskModel::TABLE . ".id AND `name` = 'sensitive_flag'", "sensitive");
$query->addCondition('(sensitive <> 1 OR sensitive IS NULL)');
}
});
$this->on('app.bootstrap', function($container) {
// Exclude sensitive tasks from project public feed
if($this->router->getController() == "FeedController" && $this->router->getAction() == "project") {
$container['projectActivityQuery'] = $container->factory(function ($c) {
$builder = new QueryBuilder();
$builder->withQuery($c['projectActivityModel']->getQuery());
$builder->getQuery()->subquery("SELECT `value` FROM `task_has_metadata` WHERE `task_id` = `project_activities`.task_id AND `name` = 'sensitive_flag'", "sensitive");
$builder->getQuery()->addCondition('(sensitive <> 1 OR sensitive IS NULL)');
//TODO: Better filtering here than just hiding link activities
$builder->getQuery()->addCondition("event_name <> 'task_internal_link.create_update'");
return $builder;
});
}
// Exclude sensitive tasks from iCal feed
if($this->router->getController() == "ICalendarController" && $this->router->getAction() == "project") {
$container['taskFinderModel'] = $container->factory(function($c) {
return new FilteredTaskFinderModel($c);
});
}
// Exclude sensitive tasks from being viewed by URL
if($this->router->getController() == "TaskViewController" && $this->router->getAction() == "readonly") {
$taskId = $this->request->getIntegerParam('task_id');
$value = $this->taskMetadataModel->get($taskId, 'sensitive_flag', FALSE);
if($value) {
throw AccessForbiddenException::getInstance()->withoutLayout();
}
// Stop internal links showing to sensitive tasks
$container['taskLinkModel'] = $container->factory(function($c) {
return new FilteredTaskLinkModel($c);
});
}
});
}
public function onStartup()
{
Translator::load($this->languageModel->getCurrentLanguage(), __DIR__.'/Locale');
}
public function getPluginName()
{
return 'Sensitive Item';
}
public function getPluginDescription()
{
return t('Allows hiding certain tasks from the public project feeds.');
}
public function getPluginAuthor()
{
return 'April MacDonald';
}
public function getPluginVersion()
{
return '1.0.0';
}
public function getPluginHomepage()
{
return 'https://github.com/stackrainbow/kanboard-plugin-sensitive';
}
}