mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-26 00:32:42 +01:00
Allow pastes to be edited
Summary: Permits the name and langauge of a paste to be edited. This will eventually allow the visibility policy to be edited as well. Test Plan: Edited name/langauge of some pastes. Tried to edit a paste I didn't own, was harshly rebuffed. Reviewers: vrana, btrahan Reviewed By: btrahan CC: aran Maniphest Tasks: T1690 Differential Revision: https://secure.phabricator.com/D3376
This commit is contained in:
parent
fed30dfb4c
commit
36e71a0601
9 changed files with 144 additions and 49 deletions
|
@ -161,6 +161,7 @@ $action_template = id(new PhutilSprite())
|
||||||
$action_map = array(
|
$action_map = array(
|
||||||
'file' => 'icon/page_white_text.png',
|
'file' => 'icon/page_white_text.png',
|
||||||
'fork' => 'icon/arrow_branch.png',
|
'fork' => 'icon/arrow_branch.png',
|
||||||
|
'edit' => 'icon/page_white_edit.png',
|
||||||
);
|
);
|
||||||
|
|
||||||
foreach ($action_map as $icon => $source) {
|
foreach ($action_map as $icon => $source) {
|
||||||
|
|
|
@ -35,6 +35,7 @@ final class PhabricatorApplicationPaste extends PhabricatorApplication {
|
||||||
'/P(?P<id>\d+)' => 'PhabricatorPasteViewController',
|
'/P(?P<id>\d+)' => 'PhabricatorPasteViewController',
|
||||||
'/paste/' => array(
|
'/paste/' => array(
|
||||||
'' => 'PhabricatorPasteEditController',
|
'' => 'PhabricatorPasteEditController',
|
||||||
|
'edit/(?P<id>\d+)/' => 'PhabricatorPasteEditController',
|
||||||
'filter/(?P<filter>\w+)/' => 'PhabricatorPasteListController',
|
'filter/(?P<filter>\w+)/' => 'PhabricatorPasteListController',
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
|
@ -18,26 +18,54 @@
|
||||||
|
|
||||||
final class PhabricatorPasteEditController extends PhabricatorPasteController {
|
final class PhabricatorPasteEditController extends PhabricatorPasteController {
|
||||||
|
|
||||||
|
private $id;
|
||||||
|
|
||||||
|
public function willProcessRequest(array $data) {
|
||||||
|
$this->id = idx($data, 'id');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public function processRequest() {
|
public function processRequest() {
|
||||||
$request = $this->getRequest();
|
$request = $this->getRequest();
|
||||||
$user = $request->getUser();
|
$user = $request->getUser();
|
||||||
|
|
||||||
$paste = new PhabricatorPaste();
|
|
||||||
$title = 'Create Paste';
|
|
||||||
|
|
||||||
$parent_id = $request->getStr('parent');
|
|
||||||
$parent = null;
|
$parent = null;
|
||||||
if ($parent_id) {
|
$parent_id = null;
|
||||||
// NOTE: If the Paste is forked from a paste which the user no longer
|
if (!$this->id) {
|
||||||
// has permission to see, we still let them edit it.
|
$is_create = true;
|
||||||
$parent = id(new PhabricatorPasteQuery())
|
|
||||||
->setViewer($user)
|
|
||||||
->withIDs(array($parent_id))
|
|
||||||
->execute();
|
|
||||||
$parent = head($parent);
|
|
||||||
|
|
||||||
if ($parent) {
|
$paste = new PhabricatorPaste();
|
||||||
$paste->setParentPHID($parent->getPHID());
|
|
||||||
|
$parent_id = $request->getStr('parent');
|
||||||
|
if ($parent_id) {
|
||||||
|
// NOTE: If the Paste is forked from a paste which the user no longer
|
||||||
|
// has permission to see, we still let them edit it.
|
||||||
|
$parent = id(new PhabricatorPasteQuery())
|
||||||
|
->setViewer($user)
|
||||||
|
->withIDs(array($parent_id))
|
||||||
|
->execute();
|
||||||
|
$parent = head($parent);
|
||||||
|
|
||||||
|
if ($parent) {
|
||||||
|
$paste->setParentPHID($parent->getPHID());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$paste->setAuthorPHID($user->getPHID());
|
||||||
|
} else {
|
||||||
|
$is_create = false;
|
||||||
|
|
||||||
|
$paste = id(new PhabricatorPasteQuery())
|
||||||
|
->setViewer($user)
|
||||||
|
->requireCapabilities(
|
||||||
|
array(
|
||||||
|
PhabricatorPolicyCapability::CAN_VIEW,
|
||||||
|
PhabricatorPolicyCapability::CAN_EDIT,
|
||||||
|
))
|
||||||
|
->withIDs(array($this->id))
|
||||||
|
->executeOne();
|
||||||
|
if (!$paste) {
|
||||||
|
return new Aphront404Response();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -45,33 +73,36 @@ final class PhabricatorPasteEditController extends PhabricatorPasteController {
|
||||||
$e_text = true;
|
$e_text = true;
|
||||||
$errors = array();
|
$errors = array();
|
||||||
if ($request->isFormPost()) {
|
if ($request->isFormPost()) {
|
||||||
$text = $request->getStr('text');
|
|
||||||
if (!strlen($text)) {
|
if ($is_create) {
|
||||||
$e_text = 'Required';
|
$text = $request->getStr('text');
|
||||||
$errors[] = 'The paste may not be blank.';
|
if (!strlen($text)) {
|
||||||
} else {
|
$e_text = 'Required';
|
||||||
$e_text = null;
|
$errors[] = 'The paste may not be blank.';
|
||||||
|
} else {
|
||||||
|
$e_text = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$paste->setTitle($request->getStr('title'));
|
$paste->setTitle($request->getStr('title'));
|
||||||
$paste->setLanguage($request->getStr('language'));
|
$paste->setLanguage($request->getStr('language'));
|
||||||
|
|
||||||
if (!$errors) {
|
if (!$errors) {
|
||||||
$paste_file = PhabricatorFile::newFromFileData(
|
if ($is_create) {
|
||||||
$text,
|
$paste_file = PhabricatorFile::newFromFileData(
|
||||||
array(
|
$text,
|
||||||
'name' => $title,
|
array(
|
||||||
'mime-type' => 'text/plain; charset=utf-8',
|
'name' => $paste->getTitle(),
|
||||||
'authorPHID' => $user->getPHID(),
|
'mime-type' => 'text/plain; charset=utf-8',
|
||||||
));
|
'authorPHID' => $user->getPHID(),
|
||||||
$paste->setFilePHID($paste_file->getPHID());
|
));
|
||||||
$paste->setAuthorPHID($user->getPHID());
|
$paste->setFilePHID($paste_file->getPHID());
|
||||||
|
}
|
||||||
$paste->save();
|
$paste->save();
|
||||||
|
|
||||||
return id(new AphrontRedirectResponse())->setURI($paste->getURI());
|
return id(new AphrontRedirectResponse())->setURI($paste->getURI());
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if ($parent) {
|
if ($is_create && $parent) {
|
||||||
$paste->setTitle('Fork of '.$parent->getFullName());
|
$paste->setTitle('Fork of '.$parent->getFullName());
|
||||||
$paste->setLanguage($parent->getLanguage());
|
$paste->setLanguage($parent->getLanguage());
|
||||||
|
|
||||||
|
@ -96,9 +127,6 @@ final class PhabricatorPasteEditController extends PhabricatorPasteController {
|
||||||
'' => '(Detect With Wizardly Powers)',
|
'' => '(Detect With Wizardly Powers)',
|
||||||
) + PhabricatorEnv::getEnvConfig('pygments.dropdown-choices');
|
) + PhabricatorEnv::getEnvConfig('pygments.dropdown-choices');
|
||||||
|
|
||||||
$submit = id(new AphrontFormSubmitControl())
|
|
||||||
->setValue('Create Paste');
|
|
||||||
|
|
||||||
$form
|
$form
|
||||||
->setUser($user)
|
->setUser($user)
|
||||||
->addHiddenInput('parent', $parent_id)
|
->addHiddenInput('parent', $parent_id)
|
||||||
|
@ -112,15 +140,19 @@ final class PhabricatorPasteEditController extends PhabricatorPasteController {
|
||||||
->setLabel('Language')
|
->setLabel('Language')
|
||||||
->setName('language')
|
->setName('language')
|
||||||
->setValue($paste->getLanguage())
|
->setValue($paste->getLanguage())
|
||||||
->setOptions($langs))
|
->setOptions($langs));
|
||||||
->appendChild(
|
|
||||||
id(new AphrontFormTextAreaControl())
|
if ($is_create) {
|
||||||
->setLabel('Text')
|
$form
|
||||||
->setError($e_text)
|
->appendChild(
|
||||||
->setValue($text)
|
id(new AphrontFormTextAreaControl())
|
||||||
->setHeight(AphrontFormTextAreaControl::HEIGHT_VERY_TALL)
|
->setLabel('Text')
|
||||||
->setCustomClass('PhabricatorMonospaced')
|
->setError($e_text)
|
||||||
->setName('text'))
|
->setValue($text)
|
||||||
|
->setHeight(AphrontFormTextAreaControl::HEIGHT_VERY_TALL)
|
||||||
|
->setCustomClass('PhabricatorMonospaced')
|
||||||
|
->setName('text'));
|
||||||
|
}
|
||||||
|
|
||||||
/* TODO: Doesn't have any useful options yet.
|
/* TODO: Doesn't have any useful options yet.
|
||||||
->appendChild(
|
->appendChild(
|
||||||
|
@ -132,13 +164,25 @@ final class PhabricatorPasteEditController extends PhabricatorPasteController {
|
||||||
->setName('policy'))
|
->setName('policy'))
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
$submit = new AphrontFormSubmitControl();
|
||||||
|
|
||||||
|
if (!$is_create) {
|
||||||
|
$submit->addCancelButton($paste->getURI());
|
||||||
|
$submit->setValue('Save Paste');
|
||||||
|
$title = 'Edit '.$paste->getFullName();
|
||||||
|
} else {
|
||||||
|
$submit->setValue('Create Paste');
|
||||||
|
$title = 'Create Paste';
|
||||||
|
}
|
||||||
|
|
||||||
|
$form
|
||||||
->appendChild($submit);
|
->appendChild($submit);
|
||||||
|
|
||||||
$nav = $this->buildSideNavView();
|
$nav = $this->buildSideNavView();
|
||||||
$nav->selectFilter('edit');
|
$nav->selectFilter('edit');
|
||||||
$nav->appendChild(
|
$nav->appendChild(
|
||||||
array(
|
array(
|
||||||
id(new PhabricatorHeaderView())->setHeader('Create Paste'),
|
id(new PhabricatorHeaderView())->setHeader($title),
|
||||||
$error_view,
|
$error_view,
|
||||||
$form,
|
$form,
|
||||||
));
|
));
|
||||||
|
|
|
@ -59,7 +59,7 @@ final class PhabricatorPasteViewController extends PhabricatorPasteController {
|
||||||
$fork_phids));
|
$fork_phids));
|
||||||
|
|
||||||
$header = $this->buildHeaderView($paste);
|
$header = $this->buildHeaderView($paste);
|
||||||
$actions = $this->buildActionView($paste, $file);
|
$actions = $this->buildActionView($user, $paste, $file);
|
||||||
$properties = $this->buildPropertyView($paste, $fork_phids);
|
$properties = $this->buildPropertyView($paste, $fork_phids);
|
||||||
$source_code = $this->buildSourceCodeView($paste, $file);
|
$source_code = $this->buildSourceCodeView($paste, $file);
|
||||||
|
|
||||||
|
@ -89,9 +89,15 @@ final class PhabricatorPasteViewController extends PhabricatorPasteController {
|
||||||
}
|
}
|
||||||
|
|
||||||
private function buildActionView(
|
private function buildActionView(
|
||||||
|
PhabricatorUser $user,
|
||||||
PhabricatorPaste $paste,
|
PhabricatorPaste $paste,
|
||||||
PhabricatorFile $file) {
|
PhabricatorFile $file) {
|
||||||
|
|
||||||
|
$can_edit = PhabricatorPolicyFilter::hasCapability(
|
||||||
|
$user,
|
||||||
|
$paste,
|
||||||
|
PhabricatorPolicyCapability::CAN_EDIT);
|
||||||
|
|
||||||
return id(new PhabricatorActionListView())
|
return id(new PhabricatorActionListView())
|
||||||
->addAction(
|
->addAction(
|
||||||
id(new PhabricatorActionView())
|
id(new PhabricatorActionView())
|
||||||
|
@ -102,7 +108,14 @@ final class PhabricatorPasteViewController extends PhabricatorPasteController {
|
||||||
id(new PhabricatorActionView())
|
id(new PhabricatorActionView())
|
||||||
->setName(pht('View Raw File'))
|
->setName(pht('View Raw File'))
|
||||||
->setIcon('file')
|
->setIcon('file')
|
||||||
->setHref($file->getBestURI()));
|
->setHref($file->getBestURI()))
|
||||||
|
->addAction(
|
||||||
|
id(new PhabricatorActionView())
|
||||||
|
->setName(pht('Edit Paste'))
|
||||||
|
->setIcon('edit')
|
||||||
|
->setDisabled(!$can_edit)
|
||||||
|
->setWorkflow(!$can_edit)
|
||||||
|
->setHref($this->getApplicationURI('/edit/'.$paste->getID().'/')));
|
||||||
}
|
}
|
||||||
|
|
||||||
private function buildPropertyView(
|
private function buildPropertyView(
|
||||||
|
|
|
@ -44,11 +44,15 @@ final class PhabricatorPaste extends PhabricatorPasteDAO
|
||||||
public function getCapabilities() {
|
public function getCapabilities() {
|
||||||
return array(
|
return array(
|
||||||
PhabricatorPolicyCapability::CAN_VIEW,
|
PhabricatorPolicyCapability::CAN_VIEW,
|
||||||
|
PhabricatorPolicyCapability::CAN_EDIT,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getPolicy($capability) {
|
public function getPolicy($capability) {
|
||||||
return PhabricatorPolicies::POLICY_USER;
|
if ($capability == PhabricatorPolicyCapability::CAN_VIEW) {
|
||||||
|
return PhabricatorPolicies::POLICY_USER;
|
||||||
|
}
|
||||||
|
return PhabricatorPolicies::POLICY_NOONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function hasAutomaticCapability($capability, PhabricatorUser $user) {
|
public function hasAutomaticCapability($capability, PhabricatorUser $user) {
|
||||||
|
|
|
@ -21,6 +21,8 @@ final class PhabricatorActionView extends AphrontView {
|
||||||
private $name;
|
private $name;
|
||||||
private $icon;
|
private $icon;
|
||||||
private $href;
|
private $href;
|
||||||
|
private $disabled;
|
||||||
|
private $workflow;
|
||||||
|
|
||||||
public function setHref($href) {
|
public function setHref($href) {
|
||||||
$this->href = $href;
|
$this->href = $href;
|
||||||
|
@ -37,6 +39,16 @@ final class PhabricatorActionView extends AphrontView {
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function setDisabled($disabled) {
|
||||||
|
$this->disabled = $disabled;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setWorkflow($workflow) {
|
||||||
|
$this->workflow = $workflow;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
public function render() {
|
public function render() {
|
||||||
|
|
||||||
$icon = null;
|
$icon = null;
|
||||||
|
@ -51,11 +63,12 @@ final class PhabricatorActionView extends AphrontView {
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->href) {
|
if ($this->href) {
|
||||||
$item = phutil_render_tag(
|
$item = javelin_render_tag(
|
||||||
'a',
|
'a',
|
||||||
array(
|
array(
|
||||||
'href' => $this->href,
|
'href' => $this->href,
|
||||||
'class' => 'phabricator-action-view-item',
|
'class' => 'phabricator-action-view-item',
|
||||||
|
'sigil' => $this->workflow ? 'workflow' : null,
|
||||||
),
|
),
|
||||||
phutil_escape_html($this->name));
|
phutil_escape_html($this->name));
|
||||||
} else {
|
} else {
|
||||||
|
@ -67,10 +80,16 @@ final class PhabricatorActionView extends AphrontView {
|
||||||
phutil_escape_html($this->name));
|
phutil_escape_html($this->name));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$classes = array();
|
||||||
|
$classes[] = 'phabricator-action-view';
|
||||||
|
if ($this->disabled) {
|
||||||
|
$classes[] = 'phabricator-action-view-disabled';
|
||||||
|
}
|
||||||
|
|
||||||
return phutil_render_tag(
|
return phutil_render_tag(
|
||||||
'li',
|
'li',
|
||||||
array(
|
array(
|
||||||
'class' => 'phabricator-action-view',
|
'class' => implode(' ', $classes),
|
||||||
),
|
),
|
||||||
$icon.$item);
|
$icon.$item);
|
||||||
}
|
}
|
||||||
|
|
|
@ -258,3 +258,7 @@
|
||||||
.action-fork {
|
.action-fork {
|
||||||
background-position: 0px -2538px;
|
background-position: 0px -2538px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.action-edit {
|
||||||
|
background-position: 0px -2555px;
|
||||||
|
}
|
||||||
|
|
|
@ -52,3 +52,12 @@
|
||||||
color: #ffffff;
|
color: #ffffff;
|
||||||
text-decoration: none;
|
text-decoration: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.phabricator-action-view-disabled .phabricator-action-view-item {
|
||||||
|
color: #888888;
|
||||||
|
}
|
||||||
|
|
||||||
|
.phabricator-action-view-disabled .phabricator-action-view-item:hover {
|
||||||
|
background-color: #dfdfdf;
|
||||||
|
color: #888888;
|
||||||
|
}
|
||||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 82 KiB After Width: | Height: | Size: 83 KiB |
Loading…
Reference in a new issue