-
Notifications
You must be signed in to change notification settings - Fork 0
/
dkan_workflow.email_proxy.inc
74 lines (68 loc) · 1.99 KB
/
dkan_workflow.email_proxy.inc
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
<?php
/**
* @file
* Implements a transition email proxy for dkan_workflow.
*
* The business logic we wish to capture:
* Allow email send if the user is the origional author of the node.
*
* Only allow emails to "Worflow Moderator" that are in the same group as the
* node.
*
* If the node does not belong to a group, then only allow emails to users
* that belong to the "Workflow Supervisor" role.
*
* If the node belongs to a group do not email the "Workflow Supervisor".
*/
/**
* Implemenation of the a transition email proxy.
*/
class DkanWorkflowEmailProxy {
/**
* Constructor function.
*/
public function __construct($message) {
$this->roles = array_flip(user_roles());
$this->node = $message['params']['node'];
$this->user = user_load_by_mail($message['to']);
}
/**
* Decision process for sending messages.
*/
public function send() {
return $this->isCreator() || $this->isGroupModerator() || $this->isUngroupedSupervisor();
}
/**
* Allow emails to creator of the node.
*/
private function isCreator() {
return ($this->user->uid == $this->node->uid);
}
/**
* Allow emails to group Moderators that share same group as node.
*/
private function isGroupModerator() {
if (user_has_role($this->roles['Workflow Moderator'], $this->user)) {
$user_groups = og_get_entity_groups('user', $this->user);
$node_groups = og_get_entity_groups('node', $this->node);
if(isset($user_groups['node']) && isset($node_groups['node'])) {
$intersect = array_intersect($user_groups['node'], $node_groups['node']);
} else {
$intersect = array();
}
return !empty($intersect);
}
return FALSE;
}
/**
* Allow emails to Supervisors for groupless nodes.
*/
private function isUngroupedSupervisor() {
if (user_has_role($this->roles['Workflow Supervisor'], $this->user)) {
if (empty(og_get_entity_groups('node', $this->node))) {
return TRUE;
}
}
return FALSE;
}
}