mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-18 19:40:55 +01:00
Make event hosts editable
Summary: Fixes T10909. I think this is a generally reasonable sort of capability to expose, although I've made it edit-only for now (when creating an event, you're always the host). Also clean up some minor leftovers in the code, and a couple of little bugs with recurrence frequencies. Test Plan: Created an event, edited the host of an event. Reviewers: chad Reviewed By: chad Maniphest Tasks: T10909 Differential Revision: https://secure.phabricator.com/D16292
This commit is contained in:
parent
b6daa049de
commit
439af11e70
6 changed files with 101 additions and 25 deletions
|
@ -2036,6 +2036,7 @@ phutil_register_library_map(array(
|
|||
'PhabricatorCalendarEventEndDateTransaction' => 'applications/calendar/xaction/PhabricatorCalendarEventEndDateTransaction.php',
|
||||
'PhabricatorCalendarEventFrequencyTransaction' => 'applications/calendar/xaction/PhabricatorCalendarEventFrequencyTransaction.php',
|
||||
'PhabricatorCalendarEventFulltextEngine' => 'applications/calendar/search/PhabricatorCalendarEventFulltextEngine.php',
|
||||
'PhabricatorCalendarEventHostTransaction' => 'applications/calendar/xaction/PhabricatorCalendarEventHostTransaction.php',
|
||||
'PhabricatorCalendarEventIconTransaction' => 'applications/calendar/xaction/PhabricatorCalendarEventIconTransaction.php',
|
||||
'PhabricatorCalendarEventInviteTransaction' => 'applications/calendar/xaction/PhabricatorCalendarEventInviteTransaction.php',
|
||||
'PhabricatorCalendarEventInvitee' => 'applications/calendar/storage/PhabricatorCalendarEventInvitee.php',
|
||||
|
@ -6663,6 +6664,7 @@ phutil_register_library_map(array(
|
|||
'PhabricatorCalendarEventEndDateTransaction' => 'PhabricatorCalendarEventDateTransaction',
|
||||
'PhabricatorCalendarEventFrequencyTransaction' => 'PhabricatorCalendarEventTransactionType',
|
||||
'PhabricatorCalendarEventFulltextEngine' => 'PhabricatorFulltextEngine',
|
||||
'PhabricatorCalendarEventHostTransaction' => 'PhabricatorCalendarEventTransactionType',
|
||||
'PhabricatorCalendarEventIconTransaction' => 'PhabricatorCalendarEventTransactionType',
|
||||
'PhabricatorCalendarEventInviteTransaction' => 'PhabricatorCalendarEventTransactionType',
|
||||
'PhabricatorCalendarEventInvitee' => array(
|
||||
|
|
|
@ -23,8 +23,7 @@ final class PhabricatorCalendarEventEditEngine
|
|||
|
||||
protected function newEditableObject() {
|
||||
return PhabricatorCalendarEvent::initializeNewCalendarEvent(
|
||||
$this->getViewer(),
|
||||
$mode = null);
|
||||
$this->getViewer());
|
||||
}
|
||||
|
||||
protected function newObjectQuery() {
|
||||
|
@ -106,6 +105,17 @@ final class PhabricatorCalendarEventEditEngine
|
|||
->setConduitDescription(pht('Cancel or restore the event.'))
|
||||
->setConduitTypeDescription(pht('True to cancel the event.'))
|
||||
->setValue($object->getIsCancelled()),
|
||||
id(new PhabricatorUsersEditField())
|
||||
->setKey('hostPHID')
|
||||
->setAliases(array('host'))
|
||||
->setLabel(pht('Host'))
|
||||
->setDescription(pht('Host of the event.'))
|
||||
->setTransactionType(
|
||||
PhabricatorCalendarEventHostTransaction::TRANSACTIONTYPE)
|
||||
->setIsConduitOnly($this->getIsCreate())
|
||||
->setConduitDescription(pht('Change the host of the event.'))
|
||||
->setConduitTypeDescription(pht('New event host.'))
|
||||
->setSingleValue($object->getHostPHID()),
|
||||
id(new PhabricatorDatasourceEditField())
|
||||
->setKey('inviteePHIDs')
|
||||
->setAliases(array('invite', 'invitee', 'invitees', 'inviteePHID'))
|
||||
|
@ -141,7 +151,7 @@ final class PhabricatorCalendarEventEditEngine
|
|||
->setDescription(pht('Recurring event frequency.'))
|
||||
->setConduitDescription(pht('Change the event frequency.'))
|
||||
->setConduitTypeDescription(pht('New event frequency.'))
|
||||
->setValue($object->getFrequencyUnit());
|
||||
->setValue($object->getFrequencyRule());
|
||||
}
|
||||
|
||||
if ($this->getIsCreate() || $object->getIsRecurring()) {
|
||||
|
|
|
@ -39,8 +39,6 @@ final class PhabricatorCalendarEvent extends PhabricatorCalendarDAO
|
|||
|
||||
protected $spacePHID;
|
||||
|
||||
const DEFAULT_ICON = 'fa-calendar';
|
||||
|
||||
private $parentEvent = self::ATTACHABLE;
|
||||
private $invitees = self::ATTACHABLE;
|
||||
|
||||
|
@ -53,24 +51,13 @@ final class PhabricatorCalendarEvent extends PhabricatorCalendarDAO
|
|||
const FREQUENCY_MONTHLY = 'monthly';
|
||||
const FREQUENCY_YEARLY = 'yearly';
|
||||
|
||||
public static function initializeNewCalendarEvent(
|
||||
PhabricatorUser $actor,
|
||||
$mode) {
|
||||
public static function initializeNewCalendarEvent(PhabricatorUser $actor) {
|
||||
$app = id(new PhabricatorApplicationQuery())
|
||||
->setViewer($actor)
|
||||
->withClasses(array('PhabricatorCalendarApplication'))
|
||||
->executeOne();
|
||||
|
||||
$view_policy = null;
|
||||
$is_recurring = 0;
|
||||
|
||||
if ($mode == 'public') {
|
||||
$view_policy = PhabricatorPolicies::getMostOpenPolicy();
|
||||
}
|
||||
|
||||
if ($mode == 'recurring') {
|
||||
$is_recurring = true;
|
||||
}
|
||||
$view_policy = PhabricatorPolicies::getMostOpenPolicy();
|
||||
|
||||
$start = new DateTime('@'.PhabricatorTime::getNow());
|
||||
$start->setTimeZone($actor->getTimeZone());
|
||||
|
@ -82,13 +69,19 @@ final class PhabricatorCalendarEvent extends PhabricatorCalendarDAO
|
|||
$epoch_min = $start->format('U');
|
||||
$epoch_max = $end->format('U');
|
||||
|
||||
$default_icon = 'fa-calendar';
|
||||
|
||||
return id(new PhabricatorCalendarEvent())
|
||||
->setHostPHID($actor->getPHID())
|
||||
->setIsCancelled(0)
|
||||
->setIsAllDay(0)
|
||||
->setIsStub(0)
|
||||
->setIsRecurring($is_recurring)
|
||||
->setIcon(self::DEFAULT_ICON)
|
||||
->setIsRecurring(0)
|
||||
->setRecurrenceFrequency(
|
||||
array(
|
||||
'rule' => self::FREQUENCY_WEEKLY,
|
||||
))
|
||||
->setIcon($default_icon)
|
||||
->setViewPolicy($view_policy)
|
||||
->setEditPolicy($actor->getPHID())
|
||||
->setSpacePHID($actor->getDefaultSpacePHID())
|
||||
|
@ -396,8 +389,12 @@ final class PhabricatorCalendarEvent extends PhabricatorCalendarDAO
|
|||
return $this;
|
||||
}
|
||||
|
||||
public function getFrequencyRule() {
|
||||
return idx($this->recurrenceFrequency, 'rule');
|
||||
}
|
||||
|
||||
public function getFrequencyUnit() {
|
||||
$frequency = idx($this->recurrenceFrequency, 'rule');
|
||||
$frequency = $this->getFrequencyRule();
|
||||
|
||||
switch ($frequency) {
|
||||
case 'daily':
|
||||
|
|
|
@ -6,7 +6,7 @@ final class PhabricatorCalendarEventFrequencyTransaction
|
|||
const TRANSACTIONTYPE = 'calendar.frequency';
|
||||
|
||||
public function generateOldValue($object) {
|
||||
return $object->getFrequencyUnit();
|
||||
return $object->getFrequencyRule();
|
||||
}
|
||||
|
||||
public function applyInternalEffects($object, $value) {
|
||||
|
@ -17,7 +17,7 @@ final class PhabricatorCalendarEventFrequencyTransaction
|
|||
}
|
||||
|
||||
public function getTitle() {
|
||||
$frequency = $this->getFrequencyUnit($this->getNewValue());
|
||||
$frequency = $this->getFrequencyRule($this->getNewValue());
|
||||
switch ($frequency) {
|
||||
case PhabricatorCalendarEvent::FREQUENCY_DAILY:
|
||||
return pht(
|
||||
|
@ -39,7 +39,7 @@ final class PhabricatorCalendarEventFrequencyTransaction
|
|||
}
|
||||
|
||||
public function getTitleForFeed() {
|
||||
$frequency = $this->getFrequencyUnit($this->getNewValue());
|
||||
$frequency = $this->getFrequencyRule($this->getNewValue());
|
||||
switch ($frequency) {
|
||||
case PhabricatorCalendarEvent::FREQUENCY_DAILY:
|
||||
return pht(
|
||||
|
@ -64,7 +64,7 @@ final class PhabricatorCalendarEventFrequencyTransaction
|
|||
}
|
||||
}
|
||||
|
||||
private function getFrequencyUnit($value) {
|
||||
private function getFrequencyRule($value) {
|
||||
if (is_array($value)) {
|
||||
$value = idx($value, 'rule');
|
||||
} else {
|
||||
|
|
|
@ -0,0 +1,59 @@
|
|||
<?php
|
||||
|
||||
final class PhabricatorCalendarEventHostTransaction
|
||||
extends PhabricatorCalendarEventTransactionType {
|
||||
|
||||
const TRANSACTIONTYPE = 'calendar.host';
|
||||
|
||||
public function generateOldValue($object) {
|
||||
return $object->getHostPHID();
|
||||
}
|
||||
|
||||
public function applyInternalEffects($object, $value) {
|
||||
$object->setHostPHID($value);
|
||||
}
|
||||
|
||||
public function getTitle() {
|
||||
return pht(
|
||||
'%s changed the host of this event from %s to %s.',
|
||||
$this->renderAuthor(),
|
||||
$this->renderOldHandle(),
|
||||
$this->renderNewHandle());
|
||||
}
|
||||
|
||||
public function getTitleForFeed() {
|
||||
return pht(
|
||||
'%s changed the host of %s from %s to %s.',
|
||||
$this->renderAuthor(),
|
||||
$this->renderObject(),
|
||||
$this->renderOldHandle(),
|
||||
$this->renderNewHandle());
|
||||
}
|
||||
|
||||
public function validateTransactions($object, array $xactions) {
|
||||
$errors = array();
|
||||
|
||||
foreach ($xactions as $xaction) {
|
||||
$host_phid = $xaction->getNewValue();
|
||||
if (!$host_phid) {
|
||||
$errors[] = $this->newRequiredError(
|
||||
pht('Event host is required.'));
|
||||
continue;
|
||||
}
|
||||
|
||||
$user = id(new PhabricatorPeopleQuery())
|
||||
->setViewer($this->getActor())
|
||||
->withPHIDs(array($host_phid))
|
||||
->executeOne();
|
||||
if (!$user) {
|
||||
$errors[] = $this->newInvalidError(
|
||||
pht(
|
||||
'Host PHID "%s" is not a valid user PHID.',
|
||||
$host_phid));
|
||||
}
|
||||
}
|
||||
|
||||
return $errors;
|
||||
}
|
||||
|
||||
}
|
|
@ -148,6 +148,14 @@ abstract class PhabricatorModularTransactionType
|
|||
return $display;
|
||||
}
|
||||
|
||||
final protected function renderOldHandle() {
|
||||
return $this->renderHandle($this->getOldValue());
|
||||
}
|
||||
|
||||
final protected function renderNewHandle() {
|
||||
return $this->renderHandle($this->getNewValue());
|
||||
}
|
||||
|
||||
final protected function renderHandleList(array $phids) {
|
||||
$viewer = $this->getViewer();
|
||||
$display = $viewer->renderHandleList($phids)
|
||||
|
|
Loading…
Reference in a new issue