mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-10 08:52:39 +01:00
Ability to join or decline an event
Summary: Ref T7986, Ability to join or decline an event. Test Plan: Open Calendar event, join event, Invitee list should update. Decline event, invitee list should remove you. Reviewers: epriestley, #blessed_reviewers Reviewed By: epriestley, #blessed_reviewers Subscribers: Korvin, epriestley Maniphest Tasks: T7986 Differential Revision: https://secure.phabricator.com/D12618
This commit is contained in:
parent
8039e52ac2
commit
39e252caf5
6 changed files with 119 additions and 1 deletions
|
@ -1488,6 +1488,7 @@ phutil_register_library_map(array(
|
|||
'PhabricatorCalendarEventInvalidEpochException' => 'applications/calendar/exception/PhabricatorCalendarEventInvalidEpochException.php',
|
||||
'PhabricatorCalendarEventInvitee' => 'applications/calendar/storage/PhabricatorCalendarEventInvitee.php',
|
||||
'PhabricatorCalendarEventInviteeQuery' => 'applications/calendar/query/PhabricatorCalendarEventInviteeQuery.php',
|
||||
'PhabricatorCalendarEventJoinController' => 'applications/calendar/controller/PhabricatorCalendarEventJoinController.php',
|
||||
'PhabricatorCalendarEventListController' => 'applications/calendar/controller/PhabricatorCalendarEventListController.php',
|
||||
'PhabricatorCalendarEventPHIDType' => 'applications/calendar/phid/PhabricatorCalendarEventPHIDType.php',
|
||||
'PhabricatorCalendarEventQuery' => 'applications/calendar/query/PhabricatorCalendarEventQuery.php',
|
||||
|
@ -4824,6 +4825,7 @@ phutil_register_library_map(array(
|
|||
'PhabricatorPolicyInterface',
|
||||
),
|
||||
'PhabricatorCalendarEventInviteeQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
|
||||
'PhabricatorCalendarEventJoinController' => 'PhabricatorCalendarController',
|
||||
'PhabricatorCalendarEventListController' => 'PhabricatorCalendarController',
|
||||
'PhabricatorCalendarEventPHIDType' => 'PhabricatorPHIDType',
|
||||
'PhabricatorCalendarEventQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
|
||||
|
|
|
@ -53,6 +53,8 @@ final class PhabricatorCalendarApplication extends PhabricatorApplication {
|
|||
=> 'PhabricatorCalendarEventEditController',
|
||||
'cancel/(?P<id>[1-9]\d*)/'
|
||||
=> 'PhabricatorCalendarEventCancelController',
|
||||
'join/(?P<id>[1-9]\d*)/'
|
||||
=> 'PhabricatorCalendarEventJoinController',
|
||||
),
|
||||
),
|
||||
);
|
||||
|
|
|
@ -0,0 +1,74 @@
|
|||
<?php
|
||||
|
||||
final class PhabricatorCalendarEventJoinController
|
||||
extends PhabricatorCalendarController {
|
||||
|
||||
private $id;
|
||||
|
||||
public function handleRequest(AphrontRequest $request) {
|
||||
$this->id = $request->getURIData('id');
|
||||
$request = $this->getRequest();
|
||||
$viewer = $request->getViewer();
|
||||
$declined_status = PhabricatorCalendarEventInvitee::STATUS_DECLINED;
|
||||
$attending_status = PhabricatorCalendarEventInvitee::STATUS_ATTENDING;
|
||||
|
||||
$event = id(new PhabricatorCalendarEventQuery())
|
||||
->setViewer($viewer)
|
||||
->withIDs(array($this->id))
|
||||
->executeOne();
|
||||
|
||||
if (!$event) {
|
||||
return new Aphront404Response();
|
||||
}
|
||||
|
||||
$cancel_uri = '/E'.$event->getID();
|
||||
$validation_exception = null;
|
||||
|
||||
$is_attending = $event->getIsUserAttending($viewer->getPHID());
|
||||
|
||||
if ($request->isFormPost()) {
|
||||
$new_status = null;
|
||||
|
||||
if ($is_attending) {
|
||||
$new_status = array($viewer->getPHID() => $declined_status);
|
||||
} else {
|
||||
$new_status = array($viewer->getPHID() => $attending_status);
|
||||
}
|
||||
|
||||
$xaction = id(new PhabricatorCalendarEventTransaction())
|
||||
->setTransactionType(
|
||||
PhabricatorCalendarEventTransaction::TYPE_INVITE)
|
||||
->setNewValue($new_status);
|
||||
|
||||
$editor = id(new PhabricatorCalendarEventEditor())
|
||||
->setActor($viewer)
|
||||
->setContentSourceFromRequest($request)
|
||||
->setContinueOnNoEffect(true)
|
||||
->setContinueOnMissingFields(true);
|
||||
|
||||
try {
|
||||
$editor->applyTransactions($event, array($xaction));
|
||||
return id(new AphrontRedirectResponse())->setURI($cancel_uri);
|
||||
} catch (PhabricatorApplicationTransactionValidationException $ex) {
|
||||
$validation_exception = $ex;
|
||||
}
|
||||
}
|
||||
|
||||
if (!$is_attending) {
|
||||
$title = pht('Join Event');
|
||||
$paragraph = pht('Would you like to join this event?');
|
||||
$submit = pht('Join');
|
||||
} else {
|
||||
$title = pht('Decline Event');
|
||||
$paragraph = pht('Would you like to decline this event?');
|
||||
$submit = pht('Decline');
|
||||
}
|
||||
|
||||
return $this->newDialog()
|
||||
->setTitle($title)
|
||||
->setValidationException($validation_exception)
|
||||
->appendParagraph($paragraph)
|
||||
->addCancelButton($cancel_uri)
|
||||
->addSubmitButton($submit);
|
||||
}
|
||||
}
|
|
@ -72,6 +72,7 @@ final class PhabricatorCalendarEventViewController
|
|||
$viewer = $this->getRequest()->getUser();
|
||||
$id = $event->getID();
|
||||
$is_cancelled = $event->getIsCancelled();
|
||||
$is_attending = $event->getIsUserAttending($viewer->getPHID());
|
||||
|
||||
$actions = id(new PhabricatorActionListView())
|
||||
->setObjectURI($this->getApplicationURI('event/'.$id.'/'))
|
||||
|
@ -91,6 +92,22 @@ final class PhabricatorCalendarEventViewController
|
|||
->setDisabled(!$can_edit)
|
||||
->setWorkflow(!$can_edit));
|
||||
|
||||
if ($is_attending) {
|
||||
$actions->addAction(
|
||||
id(new PhabricatorActionView())
|
||||
->setName(pht('Decline Event'))
|
||||
->setIcon('fa-user-times')
|
||||
->setHref($this->getApplicationURI("event/join/{$id}/"))
|
||||
->setWorkflow(true));
|
||||
} else {
|
||||
$actions->addAction(
|
||||
id(new PhabricatorActionView())
|
||||
->setName(pht('Join Event'))
|
||||
->setIcon('fa-user-plus')
|
||||
->setHref($this->getApplicationURI("event/join/{$id}/"))
|
||||
->setWorkflow(true));
|
||||
}
|
||||
|
||||
if ($is_cancelled) {
|
||||
$actions->addAction(
|
||||
id(new PhabricatorActionView())
|
||||
|
|
|
@ -130,6 +130,27 @@ final class PhabricatorCalendarEvent extends PhabricatorCalendarDAO
|
|||
return $this;
|
||||
}
|
||||
|
||||
public function getUserInviteStatus($phid) {
|
||||
$invitees = $this->getInvitees();
|
||||
$invitees = mpull($invitees, null, 'getInviteePHID');
|
||||
|
||||
$invited = idx($invitees, $phid);
|
||||
if (!$invited) {
|
||||
return PhabricatorCalendarEventInvitee::STATUS_UNINVITED;
|
||||
}
|
||||
$invited = $invited->getStatus();
|
||||
return $invited;
|
||||
}
|
||||
|
||||
public function getIsUserAttending($phid) {
|
||||
$attending_status = PhabricatorCalendarEventInvitee::STATUS_ATTENDING;
|
||||
|
||||
$old_status = $this->getUserInviteStatus($phid);
|
||||
$is_attending = ($old_status == $attending_status);
|
||||
|
||||
return $is_attending;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates data and throws exceptions for non-sensical status
|
||||
* windows
|
||||
|
|
|
@ -66,9 +66,11 @@ final class PhabricatorCalendarEventTransaction
|
|||
case self::TYPE_STATUS:
|
||||
case self::TYPE_DESCRIPTION:
|
||||
case self::TYPE_CANCEL:
|
||||
case self::TYPE_INVITE:
|
||||
return 'fa-pencil';
|
||||
break;
|
||||
case self::TYPE_INVITE:
|
||||
return 'fa-user-plus';
|
||||
break;
|
||||
}
|
||||
return parent::getIcon();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue