1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-22 14:52:41 +01:00

Canceling calendar events should deactivate the event

Summary: Closes T7943, Canceling calendar event should deactivate the event instead of destroying data.

Test Plan: Create an event, cancel it, see changed status icon, query for active events, event should not appear, query for deactivated events, event should appear in results.

Reviewers: #blessed_reviewers, epriestley

Reviewed By: #blessed_reviewers, epriestley

Subscribers: Korvin, epriestley

Maniphest Tasks: T7943

Differential Revision: https://secure.phabricator.com/D12604
This commit is contained in:
lkassianik 2015-04-29 08:39:39 -07:00
parent 6575cc568d
commit 0f914afda9
13 changed files with 211 additions and 68 deletions

View file

@ -0,0 +1,2 @@
ALTER TABLE {$NAMESPACE}_calendar.calendar_event
ADD isCancelled BOOL NOT NULL;

View file

@ -1482,7 +1482,7 @@ phutil_register_library_map(array(
'PhabricatorCalendarController' => 'applications/calendar/controller/PhabricatorCalendarController.php',
'PhabricatorCalendarDAO' => 'applications/calendar/storage/PhabricatorCalendarDAO.php',
'PhabricatorCalendarEvent' => 'applications/calendar/storage/PhabricatorCalendarEvent.php',
'PhabricatorCalendarEventDeleteController' => 'applications/calendar/controller/PhabricatorCalendarEventDeleteController.php',
'PhabricatorCalendarEventCancelController' => 'applications/calendar/controller/PhabricatorCalendarEventCancelController.php',
'PhabricatorCalendarEventEditController' => 'applications/calendar/controller/PhabricatorCalendarEventEditController.php',
'PhabricatorCalendarEventEditor' => 'applications/calendar/editor/PhabricatorCalendarEventEditor.php',
'PhabricatorCalendarEventInvalidEpochException' => 'applications/calendar/exception/PhabricatorCalendarEventInvalidEpochException.php',
@ -4808,8 +4808,12 @@ phutil_register_library_map(array(
'PhabricatorMarkupInterface',
'PhabricatorApplicationTransactionInterface',
'PhabricatorSubscribableInterface',
'PhabricatorTokenReceiverInterface',
'PhabricatorDestructibleInterface',
'PhabricatorMentionableInterface',
'PhabricatorFlaggableInterface',
),
'PhabricatorCalendarEventDeleteController' => 'PhabricatorCalendarController',
'PhabricatorCalendarEventCancelController' => 'PhabricatorCalendarController',
'PhabricatorCalendarEventEditController' => 'PhabricatorCalendarController',
'PhabricatorCalendarEventEditor' => 'PhabricatorApplicationTransactionEditor',
'PhabricatorCalendarEventInvalidEpochException' => 'Exception',

View file

@ -51,8 +51,8 @@ final class PhabricatorCalendarApplication extends PhabricatorApplication {
=> 'PhabricatorCalendarEventEditController',
'edit/(?P<id>[1-9]\d*)/'
=> 'PhabricatorCalendarEventEditController',
'delete/(?P<id>[1-9]\d*)/'
=> 'PhabricatorCalendarEventDeleteController',
'cancel/(?P<id>[1-9]\d*)/'
=> 'PhabricatorCalendarEventCancelController',
),
),
);

View file

@ -0,0 +1,75 @@
<?php
final class PhabricatorCalendarEventCancelController
extends PhabricatorCalendarController {
private $id;
public function willProcessRequest(array $data) {
$this->id = idx($data, 'id');
}
public function processRequest() {
$request = $this->getRequest();
$user = $request->getUser();
$status = id(new PhabricatorCalendarEventQuery())
->setViewer($user)
->withIDs(array($this->id))
->requireCapabilities(
array(
PhabricatorPolicyCapability::CAN_VIEW,
PhabricatorPolicyCapability::CAN_EDIT,
))
->executeOne();
if (!$status) {
return new Aphront404Response();
}
$cancel_uri = '/E'.$status->getID();
$validation_exception = null;
$is_cancelled = $status->getIsCancelled();
if ($request->isFormPost()) {
$xactions = array();
$xaction = id(new PhabricatorCalendarEventTransaction())
->setTransactionType(
PhabricatorCalendarEventTransaction::TYPE_CANCEL)
->setNewValue(!$is_cancelled);
$editor = id(new PhabricatorCalendarEventEditor())
->setActor($user)
->setContentSourceFromRequest($request)
->setContinueOnNoEffect(true)
->setContinueOnMissingFields(true);
try {
$editor->applyTransactions($status, array($xaction));
return id(new AphrontRedirectResponse())->setURI($cancel_uri);
} catch (PhabricatorApplicationTransactionValidationException $ex) {
$validation_exception = $ex;
}
}
if ($is_cancelled) {
$title = pht('Reinstate Event');
$paragraph = pht('Reinstate this event?');
$cancel = pht('Don\'t Reinstate Event');
$submit = pht('Reinstate Event');
} else {
$title = pht('Cancel Event');
$paragraph = pht('You can always reinstate the event later.');
$cancel = pht('Don\'t Cancel Event');
$submit = pht('Cancel Event');
}
return $this->newDialog()
->setTitle($title)
->setValidationException($validation_exception)
->appendParagraph($paragraph)
->addCancelButton($cancel_uri, $cancel)
->addSubmitButton($submit);
}
}

View file

@ -1,54 +0,0 @@
<?php
final class PhabricatorCalendarEventDeleteController
extends PhabricatorCalendarController {
private $id;
public function willProcessRequest(array $data) {
$this->id = idx($data, 'id');
}
public function processRequest() {
$request = $this->getRequest();
$user = $request->getUser();
$status = id(new PhabricatorCalendarEventQuery())
->setViewer($user)
->withIDs(array($this->id))
->requireCapabilities(
array(
PhabricatorPolicyCapability::CAN_VIEW,
PhabricatorPolicyCapability::CAN_EDIT,
))
->executeOne();
if (!$status) {
return new Aphront404Response();
}
if ($request->isFormPost()) {
$status->delete();
$uri = new PhutilURI($this->getApplicationURI());
$uri->setQueryParams(
array(
'deleted' => true,
));
return id(new AphrontRedirectResponse())
->setURI($uri);
}
$dialog = new AphrontDialogView();
$dialog->setUser($user);
$dialog->setTitle(pht('Really delete status?'));
$dialog->appendChild(
pht('Permanently delete this status? This action can not be undone.'));
$dialog->addSubmitButton(pht('Delete'));
$dialog->addCancelButton(
$this->getApplicationURI('event/'));
return id(new AphrontDialogResponse())->setDialog($dialog);
}
}

View file

@ -19,7 +19,6 @@ final class PhabricatorCalendarEventEditController
$error_name = true;
$validation_exception = null;
$start_time = id(new AphrontFormDateControl())
->setUser($user)
->setName('start')

View file

@ -56,16 +56,22 @@ final class PhabricatorCalendarEventViewController
private function buildHeaderView(PhabricatorCalendarEvent $event) {
$viewer = $this->getRequest()->getUser();
$is_cancelled = $event->getIsCancelled();
$icon = $is_cancelled ? ('fa-times') : ('fa-calendar');
$color = $is_cancelled ? ('grey') : ('green');
$status = $is_cancelled ? ('Cancelled') : ('Active');
return id(new PHUIHeaderView())
->setUser($viewer)
->setHeader($event->getName())
->setStatus($icon, $color, $status)
->setPolicyObject($event);
}
private function buildActionView(PhabricatorCalendarEvent $event) {
$viewer = $this->getRequest()->getUser();
$id = $event->getID();
$is_cancelled = $event->getIsCancelled();
$actions = id(new PhabricatorActionListView())
->setObjectURI($this->getApplicationURI('event/'.$id.'/'))
@ -85,13 +91,23 @@ final class PhabricatorCalendarEventViewController
->setDisabled(!$can_edit)
->setWorkflow(!$can_edit));
if ($is_cancelled) {
$actions->addAction(
id(new PhabricatorActionView())
->setName(pht('Reinstate Event'))
->setIcon('fa-plus')
->setHref($this->getApplicationURI("event/cancel/{$id}/"))
->setDisabled(!$can_edit)
->setWorkflow(true));
} else {
$actions->addAction(
id(new PhabricatorActionView())
->setName(pht('Cancel Event'))
->setIcon('fa-times')
->setHref($this->getApplicationURI("event/delete/{$id}/"))
->setHref($this->getApplicationURI("event/cancel/{$id}/"))
->setDisabled(!$can_edit)
->setWorkflow(true));
}
return $actions;
}

View file

@ -19,6 +19,7 @@ final class PhabricatorCalendarEventEditor
$types[] = PhabricatorCalendarEventTransaction::TYPE_END_DATE;
$types[] = PhabricatorCalendarEventTransaction::TYPE_STATUS;
$types[] = PhabricatorCalendarEventTransaction::TYPE_DESCRIPTION;
$types[] = PhabricatorCalendarEventTransaction::TYPE_CANCEL;
$types[] = PhabricatorTransactions::TYPE_VIEW_POLICY;
$types[] = PhabricatorTransactions::TYPE_EDIT_POLICY;
@ -44,6 +45,8 @@ final class PhabricatorCalendarEventEditor
return (int)$status;
case PhabricatorCalendarEventTransaction::TYPE_DESCRIPTION:
return $object->getDescription();
case PhabricatorCalendarEventTransaction::TYPE_CANCEL:
return $object->getIsCancelled();
}
return parent::getCustomTransactionOldValue($object, $xaction);
@ -58,6 +61,7 @@ final class PhabricatorCalendarEventEditor
case PhabricatorCalendarEventTransaction::TYPE_START_DATE:
case PhabricatorCalendarEventTransaction::TYPE_END_DATE:
case PhabricatorCalendarEventTransaction::TYPE_DESCRIPTION:
case PhabricatorCalendarEventTransaction::TYPE_CANCEL:
return $xaction->getNewValue();
case PhabricatorCalendarEventTransaction::TYPE_STATUS:
return (int)$xaction->getNewValue();
@ -86,6 +90,9 @@ final class PhabricatorCalendarEventEditor
case PhabricatorCalendarEventTransaction::TYPE_DESCRIPTION:
$object->setDescription($xaction->getNewValue());
return;
case PhabricatorCalendarEventTransaction::TYPE_CANCEL:
$object->setIsCancelled((int)$xaction->getNewValue());
return;
case PhabricatorTransactions::TYPE_VIEW_POLICY:
case PhabricatorTransactions::TYPE_EDIT_POLICY:
case PhabricatorTransactions::TYPE_EDGE:
@ -106,6 +113,7 @@ final class PhabricatorCalendarEventEditor
case PhabricatorCalendarEventTransaction::TYPE_END_DATE:
case PhabricatorCalendarEventTransaction::TYPE_STATUS:
case PhabricatorCalendarEventTransaction::TYPE_DESCRIPTION:
case PhabricatorCalendarEventTransaction::TYPE_CANCEL:
case PhabricatorTransactions::TYPE_VIEW_POLICY:
case PhabricatorTransactions::TYPE_EDIT_POLICY:
case PhabricatorTransactions::TYPE_EDGE:

View file

@ -30,11 +30,16 @@ final class PhabricatorCalendarEventPHIDType extends PhabricatorPHIDType {
$id = $event->getID();
$name = $event->getName();
$is_cancelled = $event->getIsCancelled();
$handle
->setName($name)
->setFullName(pht('E%d: %s', $id, $name))
->setURI('/E'.$id);
if ($is_cancelled) {
$handle->setStatus(PhabricatorObjectHandleStatus::STATUS_CLOSED);
}
}
}

View file

@ -9,6 +9,7 @@ final class PhabricatorCalendarEventQuery
private $rangeEnd;
private $invitedPHIDs;
private $creatorPHIDs;
private $isCancelled;
public function withIDs(array $ids) {
$this->ids = $ids;
@ -36,6 +37,11 @@ final class PhabricatorCalendarEventQuery
return $this;
}
public function withIsCancelled($is_cancelled) {
$this->isCancelled = $is_cancelled;
return $this;
}
protected function loadPage() {
$table = new PhabricatorCalendarEvent();
$conn_r = $table->establishConnection('r');
@ -99,6 +105,13 @@ final class PhabricatorCalendarEventQuery
$this->creatorPHIDs);
}
if ($this->isCancelled !== null) {
$where[] = qsprintf(
$conn_r,
'isCancelled = %d',
(int)$this->isCancelled);
}
$where[] = $this->buildPagingClause($conn_r);
return $this->formatWhereClause($where);

View file

@ -34,6 +34,10 @@ final class PhabricatorCalendarEventSearchEngine
'creatorPHIDs',
$this->readUsersFromRequest($request, 'creators'));
$saved->setParameter(
'isCancelled',
$request->getStr('isCancelled'));
return $saved;
}
@ -73,6 +77,16 @@ final class PhabricatorCalendarEventSearchEngine
$query->withCreatorPHIDs($creator_phids);
}
$is_cancelled = $saved->getParameter('isCancelled');
switch ($is_cancelled) {
case 'active':
$query->withIsCancelled(false);
break;
case 'cancelled':
$query->withIsCancelled(true);
break;
}
return $query;
}
@ -83,9 +97,15 @@ final class PhabricatorCalendarEventSearchEngine
$range_start = $saved->getParameter('rangeStart');
$range_end = $saved->getParameter('rangeEnd');
$upcoming = $saved->getParameter('upcoming');
$is_cancelled = $saved->getParameter('isCancelled', 'active');
$invited_phids = $saved->getParameter('invitedPHIDs', array());
$creator_phids = $saved->getParameter('creatorPHIDs', array());
$resolution_types = array(
'active' => pht('Active Events Only'),
'cancelled' => pht('Cancelled Events Only'),
'both' => pht('Both Cancelled and Active Events'),
);
$form
->appendControl(
@ -120,7 +140,13 @@ final class PhabricatorCalendarEventSearchEngine
'upcoming',
1,
pht('Show only upcoming events.'),
$upcoming));
$upcoming))
->appendChild(
id(new AphrontFormSelectControl())
->setLabel(pht('Cancelled Events'))
->setName('isCancelled')
->setValue($is_cancelled)
->setOptions($resolution_types));
}
protected function getURI($path) {

View file

@ -6,6 +6,7 @@ final class PhabricatorCalendarEvent extends PhabricatorCalendarDAO
PhabricatorApplicationTransactionInterface,
PhabricatorSubscribableInterface,
PhabricatorTokenReceiverInterface,
PhabricatorDestructibleInterface,
PhabricatorMentionableInterface,
PhabricatorFlaggableInterface {
@ -15,6 +16,7 @@ final class PhabricatorCalendarEvent extends PhabricatorCalendarDAO
protected $dateTo;
protected $status;
protected $description;
protected $isCancelled;
const STATUS_AWAY = 1;
const STATUS_SPORADIC = 2;
@ -26,7 +28,8 @@ final class PhabricatorCalendarEvent extends PhabricatorCalendarDAO
->executeOne();
return id(new PhabricatorCalendarEvent())
->setUserPHID($actor->getPHID());
->setUserPHID($actor->getPHID())
->setIsCancelled(0);
}
private static $statusTexts = array(
@ -64,6 +67,7 @@ final class PhabricatorCalendarEvent extends PhabricatorCalendarDAO
'dateTo' => 'epoch',
'status' => 'uint32',
'description' => 'text',
'isCancelled' => 'bool',
),
self::CONFIG_KEY_SCHEMA => array(
'userPHID_dateFrom' => array(
@ -244,4 +248,15 @@ final class PhabricatorCalendarEvent extends PhabricatorCalendarDAO
public function getUsersToNotifyOfTokenGiven() {
return array($this->getUserPHID());
}
/* -( PhabricatorDestructibleInterface )----------------------------------- */
public function destroyObjectPermanently(
PhabricatorDestructionEngine $engine) {
$this->openTransaction();
$this->delete();
$this->saveTransaction();
}
}

View file

@ -8,6 +8,7 @@ final class PhabricatorCalendarEventTransaction
const TYPE_END_DATE = 'calendar.enddate';
const TYPE_STATUS = 'calendar.status';
const TYPE_DESCRIPTION = 'calendar.description';
const TYPE_CANCEL = 'calendar.cancel';
const MAILTAG_CONTENT = 'calendar-content';
const MAILTAG_OTHER = 'calendar-other';
@ -33,6 +34,7 @@ final class PhabricatorCalendarEventTransaction
case self::TYPE_END_DATE:
case self::TYPE_STATUS:
case self::TYPE_DESCRIPTION:
case self::TYPE_CANCEL:
$phids[] = $this->getObjectPHID();
break;
}
@ -47,6 +49,7 @@ final class PhabricatorCalendarEventTransaction
case self::TYPE_END_DATE:
case self::TYPE_STATUS:
case self::TYPE_DESCRIPTION:
case self::TYPE_CANCEL:
return ($old === null);
}
return parent::shouldHide();
@ -59,6 +62,7 @@ final class PhabricatorCalendarEventTransaction
case self::TYPE_END_DATE:
case self::TYPE_STATUS:
case self::TYPE_DESCRIPTION:
case self::TYPE_CANCEL:
return 'fa-pencil';
break;
}
@ -115,6 +119,18 @@ final class PhabricatorCalendarEventTransaction
"%s updated the event's description.",
$this->renderHandleLink($author_phid));
break;
case self::TYPE_CANCEL:
if ($new) {
return pht(
'%s cancelled this event.',
$this->renderHandleLink($author_phid));
break;
} else {
return pht(
'%s reinstated this event.',
$this->renderHandleLink($author_phid));
break;
}
}
return parent::getTitle();
@ -186,6 +202,20 @@ final class PhabricatorCalendarEventTransaction
$this->renderHandleLink($author_phid),
$this->renderHandleLink($object_phid));
break;
case self::TYPE_CANCEL:
if ($new) {
return pht(
'%s cancelled %s.',
$this->renderHandleLink($author_phid),
$this->renderHandleLink($object_phid));
break;
} else {
return pht(
'%s reinstated %s.',
$this->renderHandleLink($author_phid),
$this->renderHandleLink($object_phid));
break;
}
}
return parent::getTitleForFeed();
@ -201,6 +231,7 @@ final class PhabricatorCalendarEventTransaction
case self::TYPE_END_DATE:
case self::TYPE_STATUS:
case self::TYPE_DESCRIPTION:
case self::TYPE_CANCEL:
return PhabricatorTransactions::COLOR_GREEN;
}
@ -250,6 +281,9 @@ final class PhabricatorCalendarEventTransaction
case self::TYPE_DESCRIPTION:
$tags[] = self::MAILTAG_CONTENT;
break;
case self::TYPE_CANCEL:
$tags[] = self::MAILTAG_CONTENT;
break;
}
return $tags;
}