Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/calendar/policyrule/PhabricatorCalendarEventInviteesPolicyRule.php
12256 views
1
<?php
2
3
final class PhabricatorCalendarEventInviteesPolicyRule
4
extends PhabricatorPolicyRule {
5
6
private $invited = array();
7
private $sourcePHIDs = array();
8
9
public function getObjectPolicyKey() {
10
return 'calendar.event.invitees';
11
}
12
13
public function getObjectPolicyName() {
14
return pht('Event Invitees');
15
}
16
17
public function getPolicyExplanation() {
18
return pht('Users invited to this event can take this action.');
19
}
20
21
public function getRuleDescription() {
22
return pht('event invitees');
23
}
24
25
public function canApplyToObject(PhabricatorPolicyInterface $object) {
26
return ($object instanceof PhabricatorCalendarEvent);
27
}
28
29
public function willApplyRules(
30
PhabricatorUser $viewer,
31
array $values,
32
array $objects) {
33
34
$viewer_phid = $viewer->getPHID();
35
if (!$viewer_phid) {
36
return;
37
}
38
39
if (empty($this->invited[$viewer_phid])) {
40
$this->invited[$viewer_phid] = array();
41
}
42
43
if (!isset($this->sourcePHIDs[$viewer_phid])) {
44
$source_phids = PhabricatorEdgeQuery::loadDestinationPHIDs(
45
$viewer_phid,
46
PhabricatorProjectMaterializedMemberEdgeType::EDGECONST);
47
$source_phids[] = $viewer_phid;
48
$this->sourcePHIDs[$viewer_phid] = $source_phids;
49
}
50
51
foreach ($objects as $key => $object) {
52
$cache = $this->getTransactionHint($object);
53
if ($cache === null) {
54
// We don't have a hint for this object, so we'll deal with it below.
55
continue;
56
}
57
58
// We have a hint, so use that as the source of truth.
59
unset($objects[$key]);
60
61
foreach ($this->sourcePHIDs[$viewer_phid] as $source_phid) {
62
if (isset($cache[$source_phid])) {
63
$this->invited[$viewer_phid][$object->getPHID()] = true;
64
break;
65
}
66
}
67
}
68
69
$phids = mpull($objects, 'getPHID');
70
if (!$phids) {
71
return;
72
}
73
74
$invited = id(new PhabricatorCalendarEventInvitee())->loadAllWhere(
75
'eventPHID IN (%Ls)
76
AND inviteePHID IN (%Ls)
77
AND status != %s',
78
$phids,
79
$this->sourcePHIDs[$viewer_phid],
80
PhabricatorCalendarEventInvitee::STATUS_UNINVITED);
81
$invited = mpull($invited, 'getEventPHID');
82
83
$this->invited[$viewer_phid] += array_fill_keys($invited, true);
84
}
85
86
public function applyRule(
87
PhabricatorUser $viewer,
88
$value,
89
PhabricatorPolicyInterface $object) {
90
91
$viewer_phid = $viewer->getPHID();
92
if (!$viewer_phid) {
93
return false;
94
}
95
96
$invited = idx($this->invited, $viewer_phid);
97
return isset($invited[$object->getPHID()]);
98
}
99
100
public function getValueControlType() {
101
return self::CONTROL_TYPE_NONE;
102
}
103
104
}
105
106