mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-10 08:52:39 +01:00
Add basic Herald support to Calendar
Summary: Fixes T7939. This doesn't get too fancy, but allows you to write Herald rules against Calendar events. Test Plan: - Wrote an "add red flag to events with party in the name" rule. - Created a "mundane meeting", didn't get flagged. - Created a "cool party", got flagged. - Ran rules from the Herald test console. Reviewers: chad Reviewed By: chad Maniphest Tasks: T7939 Differential Revision: https://secure.phabricator.com/D16368
This commit is contained in:
parent
0cb9ca5500
commit
87f663ef77
7 changed files with 131 additions and 1 deletions
|
@ -2044,6 +2044,9 @@ phutil_register_library_map(array(
|
|||
'PhabricatorCalendarEventEndDateTransaction' => 'applications/calendar/xaction/PhabricatorCalendarEventEndDateTransaction.php',
|
||||
'PhabricatorCalendarEventFrequencyTransaction' => 'applications/calendar/xaction/PhabricatorCalendarEventFrequencyTransaction.php',
|
||||
'PhabricatorCalendarEventFulltextEngine' => 'applications/calendar/search/PhabricatorCalendarEventFulltextEngine.php',
|
||||
'PhabricatorCalendarEventHeraldAdapter' => 'applications/calendar/herald/PhabricatorCalendarEventHeraldAdapter.php',
|
||||
'PhabricatorCalendarEventHeraldField' => 'applications/calendar/herald/PhabricatorCalendarEventHeraldField.php',
|
||||
'PhabricatorCalendarEventHeraldFieldGroup' => 'applications/calendar/herald/PhabricatorCalendarEventHeraldFieldGroup.php',
|
||||
'PhabricatorCalendarEventHostPolicyRule' => 'applications/calendar/policyrule/PhabricatorCalendarEventHostPolicyRule.php',
|
||||
'PhabricatorCalendarEventHostTransaction' => 'applications/calendar/xaction/PhabricatorCalendarEventHostTransaction.php',
|
||||
'PhabricatorCalendarEventIconTransaction' => 'applications/calendar/xaction/PhabricatorCalendarEventIconTransaction.php',
|
||||
|
@ -2054,6 +2057,7 @@ phutil_register_library_map(array(
|
|||
'PhabricatorCalendarEventJoinController' => 'applications/calendar/controller/PhabricatorCalendarEventJoinController.php',
|
||||
'PhabricatorCalendarEventListController' => 'applications/calendar/controller/PhabricatorCalendarEventListController.php',
|
||||
'PhabricatorCalendarEventMailReceiver' => 'applications/calendar/mail/PhabricatorCalendarEventMailReceiver.php',
|
||||
'PhabricatorCalendarEventNameHeraldField' => 'applications/calendar/herald/PhabricatorCalendarEventNameHeraldField.php',
|
||||
'PhabricatorCalendarEventNameTransaction' => 'applications/calendar/xaction/PhabricatorCalendarEventNameTransaction.php',
|
||||
'PhabricatorCalendarEventPHIDType' => 'applications/calendar/phid/PhabricatorCalendarEventPHIDType.php',
|
||||
'PhabricatorCalendarEventQuery' => 'applications/calendar/query/PhabricatorCalendarEventQuery.php',
|
||||
|
@ -6757,6 +6761,9 @@ phutil_register_library_map(array(
|
|||
'PhabricatorCalendarEventEndDateTransaction' => 'PhabricatorCalendarEventDateTransaction',
|
||||
'PhabricatorCalendarEventFrequencyTransaction' => 'PhabricatorCalendarEventTransactionType',
|
||||
'PhabricatorCalendarEventFulltextEngine' => 'PhabricatorFulltextEngine',
|
||||
'PhabricatorCalendarEventHeraldAdapter' => 'HeraldAdapter',
|
||||
'PhabricatorCalendarEventHeraldField' => 'HeraldField',
|
||||
'PhabricatorCalendarEventHeraldFieldGroup' => 'HeraldFieldGroup',
|
||||
'PhabricatorCalendarEventHostPolicyRule' => 'PhabricatorPolicyRule',
|
||||
'PhabricatorCalendarEventHostTransaction' => 'PhabricatorCalendarEventTransactionType',
|
||||
'PhabricatorCalendarEventIconTransaction' => 'PhabricatorCalendarEventTransactionType',
|
||||
|
@ -6770,6 +6777,7 @@ phutil_register_library_map(array(
|
|||
'PhabricatorCalendarEventJoinController' => 'PhabricatorCalendarController',
|
||||
'PhabricatorCalendarEventListController' => 'PhabricatorCalendarController',
|
||||
'PhabricatorCalendarEventMailReceiver' => 'PhabricatorObjectMailReceiver',
|
||||
'PhabricatorCalendarEventNameHeraldField' => 'PhabricatorCalendarEventHeraldField',
|
||||
'PhabricatorCalendarEventNameTransaction' => 'PhabricatorCalendarEventTransactionType',
|
||||
'PhabricatorCalendarEventPHIDType' => 'PhabricatorPHIDType',
|
||||
'PhabricatorCalendarEventQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
|
||||
|
|
|
@ -289,5 +289,19 @@ final class PhabricatorCalendarEventEditor
|
|||
return $body;
|
||||
}
|
||||
|
||||
protected function shouldApplyHeraldRules(
|
||||
PhabricatorLiskDAO $object,
|
||||
array $xactions) {
|
||||
return true;
|
||||
}
|
||||
|
||||
protected function buildHeraldAdapter(
|
||||
PhabricatorLiskDAO $object,
|
||||
array $xactions) {
|
||||
|
||||
return id(new PhabricatorCalendarEventHeraldAdapter())
|
||||
->setObject($object);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,56 @@
|
|||
<?php
|
||||
|
||||
final class PhabricatorCalendarEventHeraldAdapter extends HeraldAdapter {
|
||||
|
||||
private $object;
|
||||
|
||||
public function getAdapterApplicationClass() {
|
||||
return 'PhabricatorCalendarApplication';
|
||||
}
|
||||
|
||||
public function getAdapterContentDescription() {
|
||||
return pht('React to events being created or updated.');
|
||||
}
|
||||
|
||||
protected function newObject() {
|
||||
return new PhabricatorCalendarEvent();
|
||||
}
|
||||
|
||||
public function isTestAdapterForObject($object) {
|
||||
return ($object instanceof PhabricatorCalendarEvent);
|
||||
}
|
||||
|
||||
public function getAdapterTestDescription() {
|
||||
return pht(
|
||||
'Test rules which run when an event is created or updated.');
|
||||
}
|
||||
|
||||
public function setObject($object) {
|
||||
$this->object = $object;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getObject() {
|
||||
return $this->object;
|
||||
}
|
||||
|
||||
public function getAdapterContentName() {
|
||||
return pht('Calendar Events');
|
||||
}
|
||||
|
||||
public function supportsRuleType($rule_type) {
|
||||
switch ($rule_type) {
|
||||
case HeraldRuleTypeConfig::RULE_TYPE_GLOBAL:
|
||||
case HeraldRuleTypeConfig::RULE_TYPE_PERSONAL:
|
||||
return true;
|
||||
case HeraldRuleTypeConfig::RULE_TYPE_OBJECT:
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public function getHeraldName() {
|
||||
return $this->getObject()->getMonogram();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
<?php
|
||||
|
||||
abstract class PhabricatorCalendarEventHeraldField extends HeraldField {
|
||||
|
||||
public function supportsObject($object) {
|
||||
return ($object instanceof PhabricatorCalendarEvent);
|
||||
}
|
||||
|
||||
public function getFieldGroupKey() {
|
||||
return PhabricatorCalendarEventHeraldFieldGroup::FIELDGROUPKEY;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
<?php
|
||||
|
||||
final class PhabricatorCalendarEventHeraldFieldGroup
|
||||
extends HeraldFieldGroup {
|
||||
|
||||
const FIELDGROUPKEY = 'calendar.event';
|
||||
|
||||
public function getGroupLabel() {
|
||||
return pht('Event Fields');
|
||||
}
|
||||
|
||||
protected function getGroupOrder() {
|
||||
return 1000;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
<?php
|
||||
|
||||
final class PhabricatorCalendarEventNameHeraldField
|
||||
extends PhabricatorCalendarEventHeraldField {
|
||||
|
||||
const FIELDCONST = 'calendar.event.name';
|
||||
|
||||
public function getHeraldFieldName() {
|
||||
return pht('Name');
|
||||
}
|
||||
|
||||
public function getHeraldFieldValue($object) {
|
||||
return $object->getName();
|
||||
}
|
||||
|
||||
protected function getHeraldFieldStandardType() {
|
||||
return self::STANDARD_TEXT;
|
||||
}
|
||||
|
||||
}
|
|
@ -768,7 +768,10 @@ abstract class HeraldAdapter extends Phobject {
|
|||
);
|
||||
}
|
||||
|
||||
abstract protected function initializeNewAdapter();
|
||||
protected function initializeNewAdapter() {
|
||||
$this->setObject($this->newObject());
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Does this adapter's event fire only once?
|
||||
|
|
Loading…
Reference in a new issue