1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-22 21:40:55 +01:00

Create separate "Accept" and "Decline" transactions for Calendar

Summary:
Ref T9275. Currently, there's a single "invite" transaction type for managing Calendar invites, and it takes a map of invitees to status.

This isn't great for EditEngine or API access, since it lets you set anyone else to any status and we can't reuse as much code as we can with a simpler API.

Make "Accept" and "Decline" separate actions which affect the actor's invite, so "invite" can be a simpler transaction which just invites or uninvites people.

Test Plan:
  - Joined/accepted/declined an event invitation.
  - Edited event invitees.

Reviewers: chad

Reviewed By: chad

Maniphest Tasks: T9275

Differential Revision: https://secure.phabricator.com/D16272
This commit is contained in:
epriestley 2016-07-11 15:08:53 -07:00
parent ffdb9f06f8
commit 3a09bb577e
3 changed files with 83 additions and 35 deletions

View file

@ -3,18 +3,9 @@
final class PhabricatorCalendarEventJoinController final class PhabricatorCalendarEventJoinController
extends PhabricatorCalendarController { extends PhabricatorCalendarController {
const ACTION_ACCEPT = 'accept';
const ACTION_DECLINE = 'decline';
const ACTION_JOIN = 'join';
public function handleRequest(AphrontRequest $request) { public function handleRequest(AphrontRequest $request) {
$viewer = $this->getViewer();
$id = $request->getURIData('id'); $id = $request->getURIData('id');
$action = $request->getURIData('action');
$request = $this->getRequest();
$viewer = $request->getViewer();
$declined_status = PhabricatorCalendarEventInvitee::STATUS_DECLINED;
$attending_status = PhabricatorCalendarEventInvitee::STATUS_ATTENDING;
$event = id(new PhabricatorCalendarEventQuery()) $event = id(new PhabricatorCalendarEventQuery())
->setViewer($viewer) ->setViewer($viewer)
@ -25,34 +16,31 @@ final class PhabricatorCalendarEventJoinController
} }
$cancel_uri = $event->getURI(); $cancel_uri = $event->getURI();
$action = $request->getURIData('action');
switch ($action) {
case 'accept':
$is_join = true;
break;
case 'decline':
$is_join = false;
break;
default:
$is_join = !$event->getIsUserAttending($viewer->getPHID());
break;
}
$validation_exception = null; $validation_exception = null;
$is_attending = $event->getIsUserAttending($viewer->getPHID());
if ($request->isFormPost()) { if ($request->isFormPost()) {
$new_status = null; if ($is_join) {
$xaction_type = PhabricatorCalendarEventTransaction::TYPE_ACCEPT;
switch ($action) { } else {
case self::ACTION_ACCEPT: $xaction_type = PhabricatorCalendarEventTransaction::TYPE_DECLINE;
$new_status = $attending_status;
break;
case self::ACTION_JOIN:
if ($is_attending) {
$new_status = $declined_status;
} else {
$new_status = $attending_status;
}
break;
case self::ACTION_DECLINE:
$new_status = $declined_status;
break;
} }
$new_status = array($viewer->getPHID() => $new_status);
$xaction = id(new PhabricatorCalendarEventTransaction()) $xaction = id(new PhabricatorCalendarEventTransaction())
->setTransactionType(PhabricatorCalendarEventTransaction::TYPE_INVITE) ->setTransactionType($xaction_type)
->setNewValue($new_status); ->setNewValue(true);
$editor = id(new PhabricatorCalendarEventEditor()) $editor = id(new PhabricatorCalendarEventEditor())
->setActor($viewer) ->setActor($viewer)
@ -68,8 +56,7 @@ final class PhabricatorCalendarEventJoinController
} }
} }
if (($action == self::ACTION_JOIN && !$is_attending) if ($is_join) {
|| $action == self::ACTION_ACCEPT) {
$title = pht('Join Event'); $title = pht('Join Event');
$paragraph = pht('Would you like to join this event?'); $paragraph = pht('Would you like to join this event?');
$submit = pht('Join'); $submit = pht('Join');

View file

@ -68,6 +68,8 @@ final class PhabricatorCalendarEventEditor
$types[] = PhabricatorCalendarEventTransaction::TYPE_INVITE; $types[] = PhabricatorCalendarEventTransaction::TYPE_INVITE;
$types[] = PhabricatorCalendarEventTransaction::TYPE_ALL_DAY; $types[] = PhabricatorCalendarEventTransaction::TYPE_ALL_DAY;
$types[] = PhabricatorCalendarEventTransaction::TYPE_ICON; $types[] = PhabricatorCalendarEventTransaction::TYPE_ICON;
$types[] = PhabricatorCalendarEventTransaction::TYPE_ACCEPT;
$types[] = PhabricatorCalendarEventTransaction::TYPE_DECLINE;
$types[] = PhabricatorCalendarEventTransaction::TYPE_RECURRING; $types[] = PhabricatorCalendarEventTransaction::TYPE_RECURRING;
$types[] = PhabricatorCalendarEventTransaction::TYPE_FREQUENCY; $types[] = PhabricatorCalendarEventTransaction::TYPE_FREQUENCY;
@ -104,6 +106,10 @@ final class PhabricatorCalendarEventEditor
return (int)$object->getIsAllDay(); return (int)$object->getIsAllDay();
case PhabricatorCalendarEventTransaction::TYPE_ICON: case PhabricatorCalendarEventTransaction::TYPE_ICON:
return $object->getIcon(); return $object->getIcon();
case PhabricatorCalendarEventTransaction::TYPE_ACCEPT:
case PhabricatorCalendarEventTransaction::TYPE_DECLINE:
$actor_phid = $this->getActingAsPHID();
return $object->getUserInviteStatus($actor_phid);
case PhabricatorCalendarEventTransaction::TYPE_INVITE: case PhabricatorCalendarEventTransaction::TYPE_INVITE:
$map = $xaction->getNewValue(); $map = $xaction->getNewValue();
$phids = array_keys($map); $phids = array_keys($map);
@ -136,6 +142,10 @@ final class PhabricatorCalendarEventEditor
case PhabricatorCalendarEventTransaction::TYPE_INVITE: case PhabricatorCalendarEventTransaction::TYPE_INVITE:
case PhabricatorCalendarEventTransaction::TYPE_ICON: case PhabricatorCalendarEventTransaction::TYPE_ICON:
return $xaction->getNewValue(); return $xaction->getNewValue();
case PhabricatorCalendarEventTransaction::TYPE_ACCEPT:
return PhabricatorCalendarEventInvitee::STATUS_ATTENDING;
case PhabricatorCalendarEventTransaction::TYPE_DECLINE:
return PhabricatorCalendarEventInvitee::STATUS_DECLINED;
case PhabricatorCalendarEventTransaction::TYPE_ALL_DAY: case PhabricatorCalendarEventTransaction::TYPE_ALL_DAY:
return (int)$xaction->getNewValue(); return (int)$xaction->getNewValue();
case PhabricatorCalendarEventTransaction::TYPE_RECURRENCE_END_DATE: case PhabricatorCalendarEventTransaction::TYPE_RECURRENCE_END_DATE:
@ -181,6 +191,8 @@ final class PhabricatorCalendarEventEditor
$object->setIcon($xaction->getNewValue()); $object->setIcon($xaction->getNewValue());
return; return;
case PhabricatorCalendarEventTransaction::TYPE_INVITE: case PhabricatorCalendarEventTransaction::TYPE_INVITE:
case PhabricatorCalendarEventTransaction::TYPE_ACCEPT:
case PhabricatorCalendarEventTransaction::TYPE_DECLINE:
return; return;
} }
@ -223,6 +235,28 @@ final class PhabricatorCalendarEventEditor
} }
$object->attachInvitees($invitees); $object->attachInvitees($invitees);
return; return;
case PhabricatorCalendarEventTransaction::TYPE_ACCEPT:
case PhabricatorCalendarEventTransaction::TYPE_DECLINE:
$acting_phid = $this->getActingAsPHID();
$invitees = $object->getInvitees();
$invitees = mpull($invitees, null, 'getInviteePHID');
$invitee = idx($invitees, $acting_phid);
if (!$invitee) {
$invitee = id(new PhabricatorCalendarEventInvitee())
->setEventPHID($object->getPHID())
->setInviteePHID($acting_phid)
->setInviterPHID($acting_phid);
$invitees[$acting_phid] = $invitee;
}
$invitee
->setStatus($xaction->getNewValue())
->save();
$object->attachInvitees($invitees);
return;
} }
return parent::applyCustomExternalTransaction($object, $xaction); return parent::applyCustomExternalTransaction($object, $xaction);
@ -252,6 +286,12 @@ final class PhabricatorCalendarEventEditor
// caches for all attendees. // caches for all attendees.
$invalidate_all = true; $invalidate_all = true;
break; break;
case PhabricatorCalendarEventTransaction::TYPE_ACCEPT:
case PhabricatorCalendarEventTransaction::TYPE_DECLINE:
$acting_phid = $this->getActingAsPHID();
$invalidate_phids[$acting_phid] = $acting_phid;
break;
case PhabricatorCalendarEventTransaction::TYPE_INVITE: case PhabricatorCalendarEventTransaction::TYPE_INVITE:
foreach ($xaction->getNewValue() as $phid => $ignored) { foreach ($xaction->getNewValue() as $phid => $ignored) {
$invalidate_phids[$phid] = $phid; $invalidate_phids[$phid] = $phid;

View file

@ -11,11 +11,14 @@ final class PhabricatorCalendarEventTransaction
const TYPE_ALL_DAY = 'calendar.allday'; const TYPE_ALL_DAY = 'calendar.allday';
const TYPE_ICON = 'calendar.icon'; const TYPE_ICON = 'calendar.icon';
const TYPE_INVITE = 'calendar.invite'; const TYPE_INVITE = 'calendar.invite';
const TYPE_ACCEPT = 'calendar.accept';
const TYPE_DECLINE = 'calendar.decline';
const TYPE_RECURRING = 'calendar.recurring'; const TYPE_RECURRING = 'calendar.recurring';
const TYPE_FREQUENCY = 'calendar.frequency'; const TYPE_FREQUENCY = 'calendar.frequency';
const TYPE_RECURRENCE_END_DATE = 'calendar.recurrenceenddate'; const TYPE_RECURRENCE_END_DATE = 'calendar.recurrenceenddate';
const MAILTAG_RESCHEDULE = 'calendar-reschedule'; const MAILTAG_RESCHEDULE = 'calendar-reschedule';
const MAILTAG_CONTENT = 'calendar-content'; const MAILTAG_CONTENT = 'calendar-content';
const MAILTAG_OTHER = 'calendar-other'; const MAILTAG_OTHER = 'calendar-other';
@ -163,6 +166,14 @@ final class PhabricatorCalendarEventTransaction
'%s reinstated this event.', '%s reinstated this event.',
$this->renderHandleLink($author_phid)); $this->renderHandleLink($author_phid));
} }
case self::TYPE_ACCEPT:
return pht(
'%s is attending this event.',
$this->renderHandleLink($author_phid));
case self::TYPE_DECLINE:
return pht(
'%s declined this event.',
$this->renderHandleLink($author_phid));
case self::TYPE_INVITE: case self::TYPE_INVITE:
$text = null; $text = null;
@ -363,6 +374,16 @@ final class PhabricatorCalendarEventTransaction
$this->renderHandleLink($author_phid), $this->renderHandleLink($author_phid),
$this->renderHandleLink($object_phid)); $this->renderHandleLink($object_phid));
} }
case self::TYPE_ACCEPT:
return pht(
'%s is attending %s.',
$this->renderHandleLink($author_phid),
$this->renderHandleLink($object_phid));
case self::TYPE_DECLINE:
return pht(
'%s declined %s.',
$this->renderHandleLink($author_phid),
$this->renderHandleLink($object_phid));
case self::TYPE_INVITE: case self::TYPE_INVITE:
$text = null; $text = null;