Skip to content

Commit

Permalink
Make event detail view more user-friendly for imported events
Browse files Browse the repository at this point in the history
Summary:
Ref T10747. When viewing an imported event:

  - Make it more clear that it is imported and where it is from.
  - Add some explicit "this is imported" help.

Test Plan: Viewed imported and normal events.

Reviewers: chad

Reviewed By: chad

Maniphest Tasks: T10747

Differential Revision: https://secure.phabricator.com/D16727
  • Loading branch information
epriestley committed Oct 19, 2016
1 parent 5039b9c commit d860008
Show file tree
Hide file tree
Showing 7 changed files with 96 additions and 6 deletions.
Expand Up @@ -18,4 +18,23 @@ protected function newICSResponse(
->setContent($ics_data);
}

protected function newImportedEventResponse(PhabricatorCalendarEvent $event) {
if (!$event->isImportedEvent()) {
return null;
}

// Give the user a specific, detailed message if they try to edit an
// imported event via common web paths. Other edits (including those via
// the API) are blocked by the normal policy system, but this makes it more
// clear exactly why the event can't be edited.

return $this->newDialog()
->setTitle(pht('Can Not Edit Imported Event'))
->appendParagraph(
pht(
'This event has been imported from an external source and '.
'can not be edited.'))
->addCancelButton($event->getURI(), pht('Done'));
}

}
Expand Up @@ -7,19 +7,27 @@ public function handleRequest(AphrontRequest $request) {
$viewer = $request->getViewer();
$id = $request->getURIData('id');

// Just check CAN_VIEW first. Then we'll check if this is an import so
// we can raise a better error.
$event = id(new PhabricatorCalendarEventQuery())
->setViewer($viewer)
->withIDs(array($id))
->requireCapabilities(
array(
PhabricatorPolicyCapability::CAN_VIEW,
PhabricatorPolicyCapability::CAN_EDIT,
))
->executeOne();
if (!$event) {
return new Aphront404Response();
}

$response = $this->newImportedEventResponse($event);
if ($response) {
return $response;
}

// Now that we've done the import check, check for CAN_EDIT.
PhabricatorPolicyFilter::requireCapability(
$viewer,
$event,
PhabricatorPolicyCapability::CAN_EDIT);

$cancel_uri = $event->getURI();

$is_parent = $event->isParentEvent();
Expand Down
Expand Up @@ -4,6 +4,20 @@ final class PhabricatorCalendarEventEditController
extends PhabricatorCalendarController {

public function handleRequest(AphrontRequest $request) {
$viewer = $this->getViewer();

$id = $request->getURIData('id');
if ($id) {
$event = id(new PhabricatorCalendarEventQuery())
->setViewer($viewer)
->withIDs(array($id))
->executeOne();
$response = $this->newImportedEventResponse($event);
if ($response) {
return $response;
}
}

return id(new PhabricatorCalendarEventEditEngine())
->setController($this)
->buildResponse();
Expand Down
Expand Up @@ -15,6 +15,11 @@ public function handleRequest(AphrontRequest $request) {
return new Aphront404Response();
}

$response = $this->newImportedEventResponse($event);
if ($response) {
return $response;
}

$cancel_uri = $event->getURI();

$action = $request->getURIData('action');
Expand Down
Expand Up @@ -63,6 +63,19 @@ public function handleRequest(AphrontRequest $request) {
->setHeader(pht('Details'));
$recurring_header = $this->buildRecurringHeader($event);

// NOTE: This is a bit hacky: for imported events, we're just hiding the
// comment form without actually preventing comments. Users could still
// submit a request to add comments to these events. This isn't really a
// major problem since they can't do anything truly bad and there isn't an
// easy way to selectively disable this or some other similar behaviors
// today, but it would probably be nice to fully disable these
// "pseudo-edits" (like commenting and probably subscribing and awarding
// tokens) at some point.
if ($event->isImportedEvent()) {
$comment_view = null;
$timeline->setShouldTerminate(true);
}

$view = id(new PHUITwoColumnView())
->setHeader($header)
->setSubheader($subheader)
Expand Down Expand Up @@ -105,6 +118,16 @@ private function buildHeaderView(
->setPolicyObject($event)
->setHeaderIcon($event->getIcon());

if ($event->isImportedEvent()) {
$header->addTag(
id(new PHUITagView())
->setType(PHUITagView::TYPE_SHADE)
->setName(pht('Imported'))
->setIcon('fa-download')
->setHref($event->getImportSource()->getURI())
->setShade('orange'));
}

foreach ($this->buildRSVPActions($event) as $action) {
$header->addActionLink($action);
}
Expand Down Expand Up @@ -141,19 +164,23 @@ private function buildCurtain(PhabricatorCalendarEvent $event) {
->setWorkflow(!$can_edit));
}

$can_attend = !$event->isImportedEvent();

if ($is_attending) {
$curtain->addAction(
id(new PhabricatorActionView())
->setName(pht('Decline Event'))
->setIcon('fa-user-times')
->setHref($this->getApplicationURI("event/join/{$id}/"))
->setDisabled(!$can_attend)
->setWorkflow(true));
} else {
$curtain->addAction(
id(new PhabricatorActionView())
->setName(pht('Join Event'))
->setIcon('fa-user-plus')
->setHref($this->getApplicationURI("event/join/{$id}/"))
->setDisabled(!$can_attend)
->setWorkflow(true));
}

Expand Down Expand Up @@ -261,6 +288,15 @@ private function buildPropertySection(
pht('None'));
}

if ($event->isImportedEvent()) {
$properties->addProperty(
pht('Imported By'),
pht(
'%s from %s',
$viewer->renderHandle($event->getImportAuthorPHID()),
$viewer->renderHandle($event->getImportSourcePHID())));
}

$properties->addProperty(
pht('Invitees'),
$invitee_list);
Expand Down
Expand Up @@ -33,7 +33,7 @@ public function loadHandles(
$import = $objects[$phid];

$id = $import->getID();
$name = $import->getName();
$name = $import->getDisplayName();
$uri = $import->getURI();

$handle
Expand Down
Expand Up @@ -576,6 +576,10 @@ public function getDisplayIcon(PhabricatorUser $viewer) {
}
}

if ($this->isImportedEvent()) {
return 'fa-download';
}

return $this->getIcon();
}

Expand All @@ -584,6 +588,10 @@ public function getDisplayIconColor(PhabricatorUser $viewer) {
return 'red';
}

if ($this->isImportedEvent()) {
return 'orange';
}

if ($viewer->isLoggedIn()) {
$status = $this->getUserInviteStatus($viewer->getPHID());
switch ($status) {
Expand Down

0 comments on commit d860008

Please sign in to comment.