2014-08-02 23:45:50 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
final class PhabricatorFileEditController extends PhabricatorFileController {
|
|
|
|
|
2015-07-27 18:41:53 +02:00
|
|
|
public function handleRequest(AphrontRequest $request) {
|
|
|
|
$viewer = $request->getViewer();
|
|
|
|
$id = $request->getURIData('id');
|
2014-08-02 23:45:50 +02:00
|
|
|
|
|
|
|
$file = id(new PhabricatorFileQuery())
|
|
|
|
->setViewer($viewer)
|
2015-07-27 18:41:53 +02:00
|
|
|
->withIDs(array($id))
|
2014-08-02 23:45:50 +02:00
|
|
|
->requireCapabilities(
|
|
|
|
array(
|
|
|
|
PhabricatorPolicyCapability::CAN_VIEW,
|
|
|
|
PhabricatorPolicyCapability::CAN_EDIT,
|
|
|
|
))
|
|
|
|
->executeOne();
|
|
|
|
if (!$file) {
|
|
|
|
return new Aphront404Response();
|
|
|
|
}
|
|
|
|
|
2016-04-06 00:55:04 +02:00
|
|
|
$title = pht('Edit File: %s', $file->getName());
|
File names should be editable.
Summary: Fixes T7480, File names should be editable and the event should show up in feed.
Test Plan: Upload a file, view file details, edit file, change file name by adding a space and a word to the name, save changes, file name should retain space and not normalize the name, file details should show the edit event, install feed should correctly show an event for the action.
Reviewers: epriestley, #blessed_reviewers
Reviewed By: epriestley, #blessed_reviewers
Subscribers: Korvin, epriestley
Maniphest Tasks: T7480
Differential Revision: https://secure.phabricator.com/D12561
2015-04-27 00:24:29 +02:00
|
|
|
$file_name = $file->getName();
|
2016-04-06 00:55:04 +02:00
|
|
|
$header_icon = 'fa-pencil';
|
2014-08-02 23:45:50 +02:00
|
|
|
$view_uri = '/'.$file->getMonogram();
|
File names should be editable.
Summary: Fixes T7480, File names should be editable and the event should show up in feed.
Test Plan: Upload a file, view file details, edit file, change file name by adding a space and a word to the name, save changes, file name should retain space and not normalize the name, file details should show the edit event, install feed should correctly show an event for the action.
Reviewers: epriestley, #blessed_reviewers
Reviewed By: epriestley, #blessed_reviewers
Subscribers: Korvin, epriestley
Maniphest Tasks: T7480
Differential Revision: https://secure.phabricator.com/D12561
2015-04-27 00:24:29 +02:00
|
|
|
$error_name = true;
|
2014-08-02 23:45:50 +02:00
|
|
|
$validation_exception = null;
|
File names should be editable.
Summary: Fixes T7480, File names should be editable and the event should show up in feed.
Test Plan: Upload a file, view file details, edit file, change file name by adding a space and a word to the name, save changes, file name should retain space and not normalize the name, file details should show the edit event, install feed should correctly show an event for the action.
Reviewers: epriestley, #blessed_reviewers
Reviewed By: epriestley, #blessed_reviewers
Subscribers: Korvin, epriestley
Maniphest Tasks: T7480
Differential Revision: https://secure.phabricator.com/D12561
2015-04-27 00:24:29 +02:00
|
|
|
|
2014-08-02 23:45:50 +02:00
|
|
|
if ($request->isFormPost()) {
|
|
|
|
$can_view = $request->getStr('canView');
|
File names should be editable.
Summary: Fixes T7480, File names should be editable and the event should show up in feed.
Test Plan: Upload a file, view file details, edit file, change file name by adding a space and a word to the name, save changes, file name should retain space and not normalize the name, file details should show the edit event, install feed should correctly show an event for the action.
Reviewers: epriestley, #blessed_reviewers
Reviewed By: epriestley, #blessed_reviewers
Subscribers: Korvin, epriestley
Maniphest Tasks: T7480
Differential Revision: https://secure.phabricator.com/D12561
2015-04-27 00:24:29 +02:00
|
|
|
$file_name = $request->getStr('name');
|
|
|
|
$errors = array();
|
|
|
|
|
|
|
|
$type_name = PhabricatorFileTransaction::TYPE_NAME;
|
2014-08-02 23:45:50 +02:00
|
|
|
|
|
|
|
$xactions = array();
|
|
|
|
|
|
|
|
$xactions[] = id(new PhabricatorFileTransaction())
|
|
|
|
->setTransactionType(PhabricatorTransactions::TYPE_VIEW_POLICY)
|
|
|
|
->setNewValue($can_view);
|
|
|
|
|
File names should be editable.
Summary: Fixes T7480, File names should be editable and the event should show up in feed.
Test Plan: Upload a file, view file details, edit file, change file name by adding a space and a word to the name, save changes, file name should retain space and not normalize the name, file details should show the edit event, install feed should correctly show an event for the action.
Reviewers: epriestley, #blessed_reviewers
Reviewed By: epriestley, #blessed_reviewers
Subscribers: Korvin, epriestley
Maniphest Tasks: T7480
Differential Revision: https://secure.phabricator.com/D12561
2015-04-27 00:24:29 +02:00
|
|
|
$xactions[] = id(new PhabricatorFileTransaction())
|
|
|
|
->setTransactionType(PhabricatorFileTransaction::TYPE_NAME)
|
|
|
|
->setNewValue($file_name);
|
|
|
|
|
2014-08-02 23:45:50 +02:00
|
|
|
$editor = id(new PhabricatorFileEditor())
|
|
|
|
->setActor($viewer)
|
|
|
|
->setContentSourceFromRequest($request)
|
|
|
|
->setContinueOnNoEffect(true);
|
|
|
|
|
|
|
|
try {
|
|
|
|
$editor->applyTransactions($file, $xactions);
|
|
|
|
return id(new AphrontRedirectResponse())->setURI($view_uri);
|
|
|
|
} catch (PhabricatorApplicationTransactionValidationException $ex) {
|
|
|
|
$validation_exception = $ex;
|
File names should be editable.
Summary: Fixes T7480, File names should be editable and the event should show up in feed.
Test Plan: Upload a file, view file details, edit file, change file name by adding a space and a word to the name, save changes, file name should retain space and not normalize the name, file details should show the edit event, install feed should correctly show an event for the action.
Reviewers: epriestley, #blessed_reviewers
Reviewed By: epriestley, #blessed_reviewers
Subscribers: Korvin, epriestley
Maniphest Tasks: T7480
Differential Revision: https://secure.phabricator.com/D12561
2015-04-27 00:24:29 +02:00
|
|
|
$error_name = $ex->getShortMessage($type_name);
|
2014-08-02 23:45:50 +02:00
|
|
|
|
|
|
|
$file->setViewPolicy($can_view);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$policies = id(new PhabricatorPolicyQuery())
|
|
|
|
->setViewer($viewer)
|
|
|
|
->setObject($file)
|
|
|
|
->execute();
|
|
|
|
|
|
|
|
$form = id(new AphrontFormView())
|
|
|
|
->setUser($viewer)
|
File names should be editable.
Summary: Fixes T7480, File names should be editable and the event should show up in feed.
Test Plan: Upload a file, view file details, edit file, change file name by adding a space and a word to the name, save changes, file name should retain space and not normalize the name, file details should show the edit event, install feed should correctly show an event for the action.
Reviewers: epriestley, #blessed_reviewers
Reviewed By: epriestley, #blessed_reviewers
Subscribers: Korvin, epriestley
Maniphest Tasks: T7480
Differential Revision: https://secure.phabricator.com/D12561
2015-04-27 00:24:29 +02:00
|
|
|
->appendChild(
|
|
|
|
id(new AphrontFormTextControl())
|
|
|
|
->setName('name')
|
|
|
|
->setValue($file_name)
|
|
|
|
->setLabel(pht('Name'))
|
|
|
|
->setError($error_name))
|
2014-08-02 23:45:50 +02:00
|
|
|
->appendChild(
|
|
|
|
id(new AphrontFormPolicyControl())
|
|
|
|
->setUser($viewer)
|
|
|
|
->setCapability(PhabricatorPolicyCapability::CAN_VIEW)
|
|
|
|
->setPolicyObject($file)
|
|
|
|
->setPolicies($policies)
|
|
|
|
->setName('canView'))
|
|
|
|
->appendChild(
|
|
|
|
id(new AphrontFormSubmitControl())
|
|
|
|
->addCancelButton($view_uri)
|
|
|
|
->setValue(pht('Save Changes')));
|
|
|
|
|
|
|
|
$crumbs = $this->buildApplicationCrumbs()
|
|
|
|
->addTextCrumb($file->getMonogram(), $view_uri)
|
2016-04-06 00:55:04 +02:00
|
|
|
->addTextCrumb(pht('Edit'))
|
|
|
|
->setBorder(true);
|
2014-08-02 23:45:50 +02:00
|
|
|
|
2016-04-06 00:55:04 +02:00
|
|
|
$box = id(new PHUIObjectBoxView())
|
2014-08-02 23:45:50 +02:00
|
|
|
->setHeaderText($title)
|
|
|
|
->setValidationException($validation_exception)
|
2016-04-06 00:55:04 +02:00
|
|
|
->setBackground(PHUIObjectBoxView::BLUE_PROPERTY)
|
2014-08-02 23:45:50 +02:00
|
|
|
->appendChild($form);
|
|
|
|
|
2016-04-06 00:55:04 +02:00
|
|
|
$header = id(new PHUIHeaderView())
|
|
|
|
->setHeader($title)
|
|
|
|
->setHeaderIcon($header_icon);
|
|
|
|
|
|
|
|
$view = id(new PHUITwoColumnView())
|
|
|
|
->setHeader($header)
|
|
|
|
->setFooter($box);
|
|
|
|
|
|
|
|
return $this->newPage()
|
|
|
|
->setTitle($title)
|
|
|
|
->setCrumbs($crumbs)
|
|
|
|
->appendChild($view);
|
|
|
|
|
2014-08-02 23:45:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|