mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-10 17:02:41 +01:00
DRAFT - Make cancel/reinstate child/ghost/recurring events work
Summary: Ref T2896, Make cancel/reinstate child/ghost/recurring events work Test Plan: Cancel/reinstate child/ghost/recurring events. Reviewers: epriestley, #blessed_reviewers Reviewed By: epriestley, #blessed_reviewers Subscribers: Korvin, epriestley Maniphest Tasks: T2896 Differential Revision: https://secure.phabricator.com/D13145
This commit is contained in:
parent
b4de79741c
commit
e4c38bb993
6 changed files with 184 additions and 67 deletions
|
@ -57,7 +57,7 @@ final class PhabricatorCalendarApplication extends PhabricatorApplication {
|
||||||
=> 'PhabricatorCalendarEventEditController',
|
=> 'PhabricatorCalendarEventEditController',
|
||||||
'drag/(?P<id>[1-9]\d*)/'
|
'drag/(?P<id>[1-9]\d*)/'
|
||||||
=> 'PhabricatorCalendarEventDragController',
|
=> 'PhabricatorCalendarEventDragController',
|
||||||
'cancel/(?P<id>[1-9]\d*)/'
|
'cancel/(?P<id>[1-9]\d*)/(?:(?P<sequence>\d+)/)?'
|
||||||
=> 'PhabricatorCalendarEventCancelController',
|
=> 'PhabricatorCalendarEventCancelController',
|
||||||
'(?P<action>join|decline|accept)/(?P<id>[1-9]\d*)/'
|
'(?P<action>join|decline|accept)/(?P<id>[1-9]\d*)/'
|
||||||
=> 'PhabricatorCalendarEventJoinController',
|
=> 'PhabricatorCalendarEventJoinController',
|
||||||
|
|
|
@ -26,4 +26,47 @@ abstract class PhabricatorCalendarController extends PhabricatorController {
|
||||||
return $crumbs;
|
return $crumbs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function getEventAtIndexForGhostPHID($viewer, $phid, $index) {
|
||||||
|
$result = id(new PhabricatorCalendarEventQuery())
|
||||||
|
->setViewer($viewer)
|
||||||
|
->withInstanceSequencePairs(
|
||||||
|
array(
|
||||||
|
array(
|
||||||
|
$phid,
|
||||||
|
$index,
|
||||||
|
),
|
||||||
|
))
|
||||||
|
->requireCapabilities(
|
||||||
|
array(
|
||||||
|
PhabricatorPolicyCapability::CAN_VIEW,
|
||||||
|
PhabricatorPolicyCapability::CAN_EDIT,
|
||||||
|
))
|
||||||
|
->executeOne();
|
||||||
|
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function createEventFromGhost($viewer, $event, $index) {
|
||||||
|
$invitees = $event->getInvitees();
|
||||||
|
|
||||||
|
$new_ghost = $event->generateNthGhost($index, $viewer);
|
||||||
|
$new_ghost->attachParentEvent($event);
|
||||||
|
|
||||||
|
$unguarded = AphrontWriteGuard::beginScopedUnguardedWrites();
|
||||||
|
$new_ghost
|
||||||
|
->setID(null)
|
||||||
|
->setPHID(null)
|
||||||
|
->removeViewerTimezone($viewer)
|
||||||
|
->save();
|
||||||
|
$ghost_invitees = array();
|
||||||
|
foreach ($invitees as $invitee) {
|
||||||
|
$ghost_invitee = clone $invitee;
|
||||||
|
$ghost_invitee
|
||||||
|
->setID(null)
|
||||||
|
->setEventPHID($new_ghost->getPHID())
|
||||||
|
->save();
|
||||||
|
}
|
||||||
|
unset($unguarded);
|
||||||
|
return $new_ghost;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,8 +12,9 @@ final class PhabricatorCalendarEventCancelController
|
||||||
public function processRequest() {
|
public function processRequest() {
|
||||||
$request = $this->getRequest();
|
$request = $this->getRequest();
|
||||||
$user = $request->getUser();
|
$user = $request->getUser();
|
||||||
|
$sequence = $request->getURIData('sequence');
|
||||||
|
|
||||||
$status = id(new PhabricatorCalendarEventQuery())
|
$event = id(new PhabricatorCalendarEventQuery())
|
||||||
->setViewer($user)
|
->setViewer($user)
|
||||||
->withIDs(array($this->id))
|
->withIDs(array($this->id))
|
||||||
->requireCapabilities(
|
->requireCapabilities(
|
||||||
|
@ -23,15 +24,40 @@ final class PhabricatorCalendarEventCancelController
|
||||||
))
|
))
|
||||||
->executeOne();
|
->executeOne();
|
||||||
|
|
||||||
if (!$status) {
|
if ($sequence) {
|
||||||
|
$parent_event = $event;
|
||||||
|
$event = $parent_event->generateNthGhost($sequence, $user);
|
||||||
|
$event->attachParentEvent($parent_event);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$event) {
|
||||||
return new Aphront404Response();
|
return new Aphront404Response();
|
||||||
}
|
}
|
||||||
|
|
||||||
$cancel_uri = '/E'.$status->getID();
|
if (!$sequence) {
|
||||||
|
$cancel_uri = '/E'.$event->getID();
|
||||||
|
} else {
|
||||||
|
$cancel_uri = '/E'.$event->getID().'/'.$sequence;
|
||||||
|
}
|
||||||
|
|
||||||
|
$is_cancelled = $event->getIsCancelled();
|
||||||
|
$is_parent_cancelled = $event->getIsParentCancelled();
|
||||||
|
$is_recurring = $event->getIsRecurring();
|
||||||
|
$instance_of = $event->getInstanceOfEventPHID();
|
||||||
|
|
||||||
$validation_exception = null;
|
$validation_exception = null;
|
||||||
$is_cancelled = $status->getIsCancelled();
|
|
||||||
|
|
||||||
if ($request->isFormPost()) {
|
if ($request->isFormPost()) {
|
||||||
|
if ($is_cancelled && $sequence) {
|
||||||
|
return id(new AphrontRedirectResponse())->setURI($cancel_uri);
|
||||||
|
} else if ($sequence) {
|
||||||
|
$event = $this->createEventFromGhost(
|
||||||
|
$user,
|
||||||
|
$event,
|
||||||
|
$sequence);
|
||||||
|
$event->applyViewerTimezone($user);
|
||||||
|
}
|
||||||
|
|
||||||
$xactions = array();
|
$xactions = array();
|
||||||
|
|
||||||
$xaction = id(new PhabricatorCalendarEventTransaction())
|
$xaction = id(new PhabricatorCalendarEventTransaction())
|
||||||
|
@ -46,7 +72,7 @@ final class PhabricatorCalendarEventCancelController
|
||||||
->setContinueOnMissingFields(true);
|
->setContinueOnMissingFields(true);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$editor->applyTransactions($status, array($xaction));
|
$editor->applyTransactions($event, array($xaction));
|
||||||
return id(new AphrontRedirectResponse())->setURI($cancel_uri);
|
return id(new AphrontRedirectResponse())->setURI($cancel_uri);
|
||||||
} catch (PhabricatorApplicationTransactionValidationException $ex) {
|
} catch (PhabricatorApplicationTransactionValidationException $ex) {
|
||||||
$validation_exception = $ex;
|
$validation_exception = $ex;
|
||||||
|
@ -54,15 +80,44 @@ final class PhabricatorCalendarEventCancelController
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($is_cancelled) {
|
if ($is_cancelled) {
|
||||||
$title = pht('Reinstate Event');
|
if ($sequence || $is_parent_cancelled) {
|
||||||
$paragraph = pht('Reinstate this event?');
|
$title = pht('Cannot Reinstate Instance');
|
||||||
$cancel = pht('Don\'t Reinstate Event');
|
$paragraph = pht('Cannot reinstate an instance of a
|
||||||
$submit = pht('Reinstate Event');
|
cancelled recurring event.');
|
||||||
|
$cancel = pht('Cancel');
|
||||||
|
$submit = null;
|
||||||
|
} else if ($is_recurring && !$instance_of) {
|
||||||
|
$title = pht('Reinstate Recurrence');
|
||||||
|
$paragraph = pht('Reinstate the entire series
|
||||||
|
of recurring events?');
|
||||||
|
$cancel = pht('Don\'t Reinstate Recurrence');
|
||||||
|
$submit = pht('Reinstate Recurrence');
|
||||||
|
} else {
|
||||||
|
$title = pht('Reinstate Event');
|
||||||
|
$paragraph = pht('Reinstate this event?');
|
||||||
|
$cancel = pht('Don\'t Reinstate Event');
|
||||||
|
$submit = pht('Reinstate Event');
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
$title = pht('Cancel Event');
|
if ($sequence) {
|
||||||
$paragraph = pht('You can always reinstate the event later.');
|
$title = pht('Cancel Instance');
|
||||||
$cancel = pht('Don\'t Cancel Event');
|
$paragraph = pht('Cancel just this instance
|
||||||
$submit = pht('Cancel Event');
|
of a recurring event.');
|
||||||
|
$cancel = pht('Don\'t Cancel Instance');
|
||||||
|
$submit = pht('Cancel Instance');
|
||||||
|
} else if ($is_recurring && !$instance_of) {
|
||||||
|
$title = pht('Cancel Recurrence');
|
||||||
|
$paragraph = pht('Cancel the entire series
|
||||||
|
of recurring events?');
|
||||||
|
$cancel = pht('Don\'t Cancel Recurrence');
|
||||||
|
$submit = pht('Cancel Recurrence');
|
||||||
|
} 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()
|
return $this->newDialog()
|
||||||
|
|
|
@ -78,14 +78,15 @@ final class PhabricatorCalendarEventEditController
|
||||||
$cancel_uri = $this->getApplicationURI();
|
$cancel_uri = $this->getApplicationURI();
|
||||||
} else {
|
} else {
|
||||||
$event = id(new PhabricatorCalendarEventQuery())
|
$event = id(new PhabricatorCalendarEventQuery())
|
||||||
->setViewer($viewer)
|
->setViewer($viewer)
|
||||||
->withIDs(array($this->id))
|
->withIDs(array($this->id))
|
||||||
->requireCapabilities(
|
->requireCapabilities(
|
||||||
array(
|
array(
|
||||||
PhabricatorPolicyCapability::CAN_VIEW,
|
PhabricatorPolicyCapability::CAN_VIEW,
|
||||||
PhabricatorPolicyCapability::CAN_EDIT,
|
PhabricatorPolicyCapability::CAN_EDIT,
|
||||||
))
|
))
|
||||||
->executeOne();
|
->executeOne();
|
||||||
|
|
||||||
if (!$event) {
|
if (!$event) {
|
||||||
return new Aphront404Response();
|
return new Aphront404Response();
|
||||||
}
|
}
|
||||||
|
@ -93,47 +94,23 @@ final class PhabricatorCalendarEventEditController
|
||||||
if ($request->getURIData('sequence')) {
|
if ($request->getURIData('sequence')) {
|
||||||
$index = $request->getURIData('sequence');
|
$index = $request->getURIData('sequence');
|
||||||
|
|
||||||
$result = id(new PhabricatorCalendarEventQuery())
|
$result = $this->getEventAtIndexForGhostPHID(
|
||||||
->setViewer($viewer)
|
$viewer,
|
||||||
->withInstanceSequencePairs(
|
$event->getPHID(),
|
||||||
array(
|
$index);
|
||||||
array(
|
|
||||||
$event->getPHID(),
|
|
||||||
$index,
|
|
||||||
),
|
|
||||||
))
|
|
||||||
->requireCapabilities(
|
|
||||||
array(
|
|
||||||
PhabricatorPolicyCapability::CAN_VIEW,
|
|
||||||
PhabricatorPolicyCapability::CAN_EDIT,
|
|
||||||
))
|
|
||||||
->executeOne();
|
|
||||||
|
|
||||||
if ($result) {
|
if ($result) {
|
||||||
return id(new AphrontRedirectResponse())
|
return id(new AphrontRedirectResponse())
|
||||||
->setURI('/calendar/event/edit/'.$result->getID().'/');
|
->setURI('/calendar/event/edit/'.$result->getID().'/');
|
||||||
}
|
}
|
||||||
|
|
||||||
$invitees = $event->getInvitees();
|
$event = $this->createEventFromGhost(
|
||||||
|
$viewer,
|
||||||
|
$event,
|
||||||
|
$index);
|
||||||
|
|
||||||
$new_ghost = $event->generateNthGhost($index, $viewer);
|
|
||||||
$unguarded = AphrontWriteGuard::beginScopedUnguardedWrites();
|
|
||||||
$new_ghost
|
|
||||||
->setID(null)
|
|
||||||
->setPHID(null)
|
|
||||||
->removeViewerTimezone($viewer)
|
|
||||||
->save();
|
|
||||||
$ghost_invitees = array();
|
|
||||||
foreach ($invitees as $invitee) {
|
|
||||||
$ghost_invitee = clone $invitee;
|
|
||||||
$ghost_invitee
|
|
||||||
->setID(null)
|
|
||||||
->setEventPHID($new_ghost->getPHID())
|
|
||||||
->save();
|
|
||||||
}
|
|
||||||
unset($unguarded);
|
|
||||||
return id(new AphrontRedirectResponse())
|
return id(new AphrontRedirectResponse())
|
||||||
->setURI('/calendar/event/edit/'.$new_ghost->getID().'/');
|
->setURI('/calendar/event/edit/'.$event->getID().'/');
|
||||||
}
|
}
|
||||||
|
|
||||||
$end_value = AphrontFormDateControlValue::newFromEpoch(
|
$end_value = AphrontFormDateControlValue::newFromEpoch(
|
||||||
|
|
|
@ -27,12 +27,25 @@ final class PhabricatorCalendarEventViewController
|
||||||
return new Aphront404Response();
|
return new Aphront404Response();
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($sequence && $event->getIsRecurring()) {
|
if ($sequence) {
|
||||||
$parent_event = $event;
|
$result = $this->getEventAtIndexForGhostPHID(
|
||||||
$event = $event->generateNthGhost($sequence, $viewer);
|
$viewer,
|
||||||
$event->attachParentEvent($parent_event);
|
$event->getPHID(),
|
||||||
} else if ($sequence) {
|
$sequence);
|
||||||
return new Aphront404Response();
|
|
||||||
|
if ($result) {
|
||||||
|
$parent_event = $event;
|
||||||
|
$event = $result;
|
||||||
|
$event->attachParentEvent($parent_event);
|
||||||
|
return id(new AphrontRedirectResponse())
|
||||||
|
->setURI('/E'.$result->getID());
|
||||||
|
} else if ($sequence && $event->getIsRecurring()) {
|
||||||
|
$parent_event = $event;
|
||||||
|
$event = $event->generateNthGhost($sequence, $viewer);
|
||||||
|
$event->attachParentEvent($parent_event);
|
||||||
|
} else if ($sequence) {
|
||||||
|
return new Aphront404Response();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$title = 'E'.$event->getID();
|
$title = 'E'.$event->getID();
|
||||||
|
@ -178,21 +191,46 @@ final class PhabricatorCalendarEventViewController
|
||||||
->setWorkflow(true));
|
->setWorkflow(true));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$cancel_uri = $this->getApplicationURI("event/cancel/{$id}/");
|
||||||
|
|
||||||
|
if ($event->getIsGhostEvent()) {
|
||||||
|
$index = $event->getSequenceIndex();
|
||||||
|
$can_reinstate = $event->getIsParentCancelled();
|
||||||
|
|
||||||
|
$cancel_label = pht('Cancel This Instance');
|
||||||
|
$reinstate_label = pht('Reinstate This Instance');
|
||||||
|
$cancel_disabled = (!$can_edit || $can_reinstate);
|
||||||
|
$cancel_uri = $this->getApplicationURI("event/cancel/{$id}/{$index}/");
|
||||||
|
} else if ($event->getInstanceOfEventPHID()) {
|
||||||
|
$can_reinstate = $event->getIsParentCancelled();
|
||||||
|
$cancel_label = pht('Cancel This Instance');
|
||||||
|
$reinstate_label = pht('Reinstate This Instance');
|
||||||
|
$cancel_disabled = (!$can_edit || $can_reinstate);
|
||||||
|
} else if ($event->getIsRecurring()) {
|
||||||
|
$cancel_label = pht('Cancel Recurrence');
|
||||||
|
$reinstate_label = pht('Reinstate Recurrence');
|
||||||
|
$cancel_disabled = !$can_edit;
|
||||||
|
} else {
|
||||||
|
$cancel_label = pht('Cancel Event');
|
||||||
|
$reinstate_label = pht('Reinstate Event');
|
||||||
|
$cancel_disabled = !$can_edit;
|
||||||
|
}
|
||||||
|
|
||||||
if ($is_cancelled) {
|
if ($is_cancelled) {
|
||||||
$actions->addAction(
|
$actions->addAction(
|
||||||
id(new PhabricatorActionView())
|
id(new PhabricatorActionView())
|
||||||
->setName(pht('Reinstate Event'))
|
->setName($reinstate_label)
|
||||||
->setIcon('fa-plus')
|
->setIcon('fa-plus')
|
||||||
->setHref($this->getApplicationURI("event/cancel/{$id}/"))
|
->setHref($cancel_uri)
|
||||||
->setDisabled(!$can_edit)
|
->setDisabled($cancel_disabled)
|
||||||
->setWorkflow(true));
|
->setWorkflow(true));
|
||||||
} else {
|
} else {
|
||||||
$actions->addAction(
|
$actions->addAction(
|
||||||
id(new PhabricatorActionView())
|
id(new PhabricatorActionView())
|
||||||
->setName(pht('Cancel Event'))
|
->setName($cancel_label)
|
||||||
->setIcon('fa-times')
|
->setIcon('fa-times')
|
||||||
->setHref($this->getApplicationURI("event/cancel/{$id}/"))
|
->setHref($cancel_uri)
|
||||||
->setDisabled(!$can_edit)
|
->setDisabled($cancel_disabled)
|
||||||
->setWorkflow(true));
|
->setWorkflow(true));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -348,6 +348,10 @@ final class PhabricatorCalendarEvent extends PhabricatorCalendarDAO
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getIsParentCancelled() {
|
public function getIsParentCancelled() {
|
||||||
|
if ($this->instanceOfEventPHID == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
$recurring_event = $this->getParentEvent();
|
$recurring_event = $this->getParentEvent();
|
||||||
if ($recurring_event->getIsCancelled()) {
|
if ($recurring_event->getIsCancelled()) {
|
||||||
return true;
|
return true;
|
||||||
|
|
Loading…
Reference in a new issue