Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F14316092
D16702.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
6 KB
Referenced Files
None
Subscribers
None
D16702.diff
View Options
diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php
--- a/src/__phutil_library_map__.php
+++ b/src/__phutil_library_map__.php
@@ -2102,6 +2102,7 @@
'PhabricatorCalendarICSWriter' => 'applications/calendar/util/PhabricatorCalendarICSWriter.php',
'PhabricatorCalendarIconSet' => 'applications/calendar/icon/PhabricatorCalendarIconSet.php',
'PhabricatorCalendarImport' => 'applications/calendar/storage/PhabricatorCalendarImport.php',
+ 'PhabricatorCalendarImportDisableController' => 'applications/calendar/controller/PhabricatorCalendarImportDisableController.php',
'PhabricatorCalendarImportDisableTransaction' => 'applications/calendar/xaction/PhabricatorCalendarImportDisableTransaction.php',
'PhabricatorCalendarImportEditController' => 'applications/calendar/controller/PhabricatorCalendarImportEditController.php',
'PhabricatorCalendarImportEditEngine' => 'applications/calendar/editor/PhabricatorCalendarImportEditEngine.php',
@@ -6905,6 +6906,7 @@
'PhabricatorApplicationTransactionInterface',
'PhabricatorDestructibleInterface',
),
+ 'PhabricatorCalendarImportDisableController' => 'PhabricatorCalendarController',
'PhabricatorCalendarImportDisableTransaction' => 'PhabricatorCalendarImportTransactionType',
'PhabricatorCalendarImportEditController' => 'PhabricatorCalendarController',
'PhabricatorCalendarImportEditEngine' => 'PhabricatorEditEngine',
diff --git a/src/applications/calendar/controller/PhabricatorCalendarImportDisableController.php b/src/applications/calendar/controller/PhabricatorCalendarImportDisableController.php
new file mode 100644
--- /dev/null
+++ b/src/applications/calendar/controller/PhabricatorCalendarImportDisableController.php
@@ -0,0 +1,71 @@
+<?php
+
+final class PhabricatorCalendarImportDisableController
+ extends PhabricatorCalendarController {
+
+ public function handleRequest(AphrontRequest $request) {
+ $viewer = $request->getViewer();
+
+ $import = id(new PhabricatorCalendarImportQuery())
+ ->setViewer($viewer)
+ ->withIDs(array($request->getURIData('id')))
+ ->requireCapabilities(
+ array(
+ PhabricatorPolicyCapability::CAN_VIEW,
+ PhabricatorPolicyCapability::CAN_EDIT,
+ ))
+ ->executeOne();
+ if (!$import) {
+ return new Aphront404Response();
+ }
+
+ $import_uri = $import->getURI();
+ $is_disable = !$import->getIsDisabled();
+
+ if (!$import->getEngine()->canDisable($viewer, $import)) {
+ $reason = $import->getEngine()->explainCanDisable($viewer, $import);
+ return $this->newDialog()
+ ->setTitle(pht('Unable to Disable'))
+ ->appendParagraph($reason)
+ ->addCancelButton($import_uri);
+ }
+
+ if ($request->isFormPost()) {
+ $xactions = array();
+ $xactions[] = id(new PhabricatorCalendarImportTransaction())
+ ->setTransactionType(
+ PhabricatorCalendarImportDisableTransaction::TRANSACTIONTYPE)
+ ->setNewValue($is_disable ? 1 : 0);
+
+ $editor = id(new PhabricatorCalendarImportEditor())
+ ->setActor($viewer)
+ ->setContinueOnNoEffect(true)
+ ->setContinueOnMissingFields(true)
+ ->setContentSourceFromRequest($request);
+
+ $editor->applyTransactions($import, $xactions);
+
+ return id(new AphrontRedirectResponse())->setURI($import_uri);
+ }
+
+ if ($is_disable) {
+ $title = pht('Disable Import');
+ $body = pht(
+ 'Disable this import? Events from this source will no longer be '.
+ 'updated.');
+ $button = pht('Disable Import');
+ } else {
+ $title = pht('Enable Import');
+ $body = pht(
+ 'Enable this import? Events from this source will be updated again.');
+ $button = pht('Enable Import');
+ }
+
+ return $this->newDialog()
+ ->setTitle($title)
+ ->appendParagraph($body)
+ ->addCancelButton($import_uri)
+ ->addSubmitButton($button);
+ }
+
+}
diff --git a/src/applications/calendar/controller/PhabricatorCalendarImportViewController.php b/src/applications/calendar/controller/PhabricatorCalendarImportViewController.php
--- a/src/applications/calendar/controller/PhabricatorCalendarImportViewController.php
+++ b/src/applications/calendar/controller/PhabricatorCalendarImportViewController.php
@@ -80,6 +80,7 @@
$id = $import->getID();
$curtain = $this->newCurtainView($import);
+ $engine = $import->getEngine();
$can_edit = PhabricatorPolicyFilter::hasCapability(
$viewer,
@@ -89,6 +90,8 @@
$edit_uri = "import/edit/{$id}/";
$edit_uri = $this->getApplicationURI($edit_uri);
+ $can_disable = ($can_edit && $engine->canDisable($viewer, $import));
+
$curtain->addAction(
id(new PhabricatorActionView())
->setName(pht('Edit Import'))
@@ -111,7 +114,7 @@
id(new PhabricatorActionView())
->setName($disable_name)
->setIcon($disable_icon)
- ->setDisabled(!$can_edit)
+ ->setDisabled(!$can_disable)
->setWorkflow(true)
->setHref($disable_uri));
diff --git a/src/applications/calendar/import/PhabricatorCalendarICSImportEngine.php b/src/applications/calendar/import/PhabricatorCalendarICSImportEngine.php
--- a/src/applications/calendar/import/PhabricatorCalendarICSImportEngine.php
+++ b/src/applications/calendar/import/PhabricatorCalendarICSImportEngine.php
@@ -70,5 +70,20 @@
}
+ public function canDisable(
+ PhabricatorUser $viewer,
+ PhabricatorCalendarImport $import) {
+ return false;
+ }
+
+ public function explainCanDisable(
+ PhabricatorUser $viewer,
+ PhabricatorCalendarImport $import) {
+ return pht(
+ 'You can not disable import of an ICS file because the entire import '.
+ 'occurs immediately when you upload the file. There is no further '.
+ 'activity to disable.');
+ }
+
}
diff --git a/src/applications/calendar/import/PhabricatorCalendarImportEngine.php b/src/applications/calendar/import/PhabricatorCalendarImportEngine.php
--- a/src/applications/calendar/import/PhabricatorCalendarImportEngine.php
+++ b/src/applications/calendar/import/PhabricatorCalendarImportEngine.php
@@ -21,6 +21,16 @@
PhabricatorUser $viewer,
PhabricatorCalendarImport $import);
+ abstract public function canDisable(
+ PhabricatorUser $viewer,
+ PhabricatorCalendarImport $import);
+
+ public function explainCanDisable(
+ PhabricatorUser $viewer,
+ PhabricatorCalendarImport $import) {
+ throw new PhutilMethodNotImplementedException();
+ }
+
final public static function getAllImportEngines() {
return id(new PhutilClassMapQuery())
->setAncestorClass(__CLASS__)
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Thu, Dec 19, 6:52 AM (21 h, 57 m)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
6903710
Default Alt Text
D16702.diff (6 KB)
Attached To
Mode
D16702: Support disabling calendar imports
Attached
Detach File
Event Timeline
Log In to Comment