mirror of
https://we.phorge.it/source/phorge.git
synced 2025-02-01 09:28:22 +01:00
When editing objects which use files, attach the files to the objects
Summary: Ref T603. Fixes T3921. Tightens up policy controls for file/object relationships in existing applications. Test Plan: - Uploaded new project image, verified it got an edge to the project. - Uploaded new profile image, verified it got an edge to me. - Uploaded new macro image, verified it got an edge to the macro. - Uploaded new paste via web UI and conduit, verified it got attached. - Replaced, added images to a mock, verified they got edges. Reviewers: btrahan Reviewed By: btrahan CC: aran Maniphest Tasks: T3921, T603 Differential Revision: https://secure.phabricator.com/D7254
This commit is contained in:
parent
c587b8a9c8
commit
515f9a36ab
9 changed files with 98 additions and 10 deletions
|
@ -860,6 +860,25 @@ final class PhabricatorFile extends PhabricatorFileDAO
|
|||
return idx($this->metadata, self::METADATA_IMAGE_WIDTH);
|
||||
}
|
||||
|
||||
/**
|
||||
* Write the policy edge between this file and some object.
|
||||
*
|
||||
* @param PhabricatorUser Acting user.
|
||||
* @param phid Object PHID to attach to.
|
||||
* @return this
|
||||
*/
|
||||
public function attachToObject(PhabricatorUser $actor, $phid) {
|
||||
$edge_type = PhabricatorEdgeConfig::TYPE_OBJECT_HAS_FILE;
|
||||
|
||||
id(new PhabricatorEdgeEditor())
|
||||
->setActor($actor)
|
||||
->setSuppressEvents(true)
|
||||
->addEdge($phid, $edge_type, $this->getPHID())
|
||||
->save();
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/* -( PhabricatorPolicyInterface Implementation )-------------------------- */
|
||||
|
||||
|
|
|
@ -77,6 +77,18 @@ final class PhabricatorMacroEditor
|
|||
return;
|
||||
}
|
||||
|
||||
protected function extractFilePHIDsFromCustomTransaction(
|
||||
PhabricatorLiskDAO $object,
|
||||
PhabricatorApplicationTransaction $xaction) {
|
||||
|
||||
switch ($xaction->getTransactionType()) {
|
||||
case PhabricatorMacroTransactionType::TYPE_FILE:
|
||||
return array($xaction->getNewValue());
|
||||
}
|
||||
|
||||
return array();
|
||||
}
|
||||
|
||||
protected function mergeTransactions(
|
||||
PhabricatorApplicationTransaction $u,
|
||||
PhabricatorApplicationTransaction $v) {
|
||||
|
|
|
@ -49,6 +49,8 @@ final class ConduitAPI_paste_create_Method extends ConduitAPI_paste_Method {
|
|||
'authorPHID' => $user->getPHID(),
|
||||
));
|
||||
|
||||
// TODO: This should use PhabricatorPasteEditor.
|
||||
|
||||
$paste = new PhabricatorPaste();
|
||||
$paste->setTitle($title);
|
||||
$paste->setLanguage($language);
|
||||
|
@ -57,6 +59,8 @@ final class ConduitAPI_paste_create_Method extends ConduitAPI_paste_Method {
|
|||
$paste->setViewPolicy(PhabricatorPolicies::POLICY_USER);
|
||||
$paste->save();
|
||||
|
||||
$paste_file->attachToObject($user, $paste->getPHID());
|
||||
|
||||
$paste->attachRawContent($content);
|
||||
|
||||
return $this->buildPasteInfoDictionary($paste);
|
||||
|
|
|
@ -1,11 +1,10 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @group paste
|
||||
*/
|
||||
final class PhabricatorPasteEditor
|
||||
extends PhabricatorApplicationTransactionEditor {
|
||||
|
||||
private $pasteFile;
|
||||
|
||||
public function getTransactionTypes() {
|
||||
$types = parent::getTransactionTypes();
|
||||
|
||||
|
@ -95,11 +94,28 @@ final class PhabricatorPasteEditor
|
|||
'authorPHID' => $this->getActor()->getPHID(),
|
||||
));
|
||||
$object->setFilePHID($paste_file->getPHID());
|
||||
|
||||
$this->pasteFile = $paste_file;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected function applyFinalEffects(
|
||||
PhabricatorLiskDAO $object,
|
||||
array $xactions) {
|
||||
|
||||
// TODO: This should use extractFilePHIDs() instead, but the way
|
||||
// the transactions work right now makes pretty messy.
|
||||
|
||||
if ($this->pasteFile) {
|
||||
$this->pasteFile->attachToObject(
|
||||
$this->getActor(),
|
||||
$object->getPHID());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected function shouldSendMail(
|
||||
PhabricatorLiskDAO $object,
|
||||
array $xactions) {
|
||||
|
|
|
@ -1,8 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @group paste
|
||||
*/
|
||||
final class PhabricatorPasteTransaction
|
||||
extends PhabricatorApplicationTransaction {
|
||||
|
||||
|
|
|
@ -82,6 +82,7 @@ final class PhabricatorPeopleProfilePictureController
|
|||
$user->setProfileImagePHID(null);
|
||||
} else {
|
||||
$user->setProfileImagePHID($xformed->getPHID());
|
||||
$xformed->attachToObject($viewer, $user->getPHID());
|
||||
}
|
||||
$user->save();
|
||||
return id(new AphrontRedirectResponse())->setURI($profile_uri);
|
||||
|
|
|
@ -106,6 +106,26 @@ final class PholioMockEditor extends PhabricatorApplicationTransactionEditor {
|
|||
}
|
||||
}
|
||||
|
||||
protected function extractFilePHIDsFromCustomTransaction(
|
||||
PhabricatorLiskDAO $object,
|
||||
PhabricatorApplicationTransaction $xaction) {
|
||||
|
||||
switch ($xaction->getTransactionType()) {
|
||||
case PholioTransactionType::TYPE_IMAGE_FILE:
|
||||
$new = $xaction->getNewValue();
|
||||
$phids = array();
|
||||
foreach ($new as $key => $images) {
|
||||
$phids[] = mpull($images, 'getFilePHID');
|
||||
}
|
||||
return array_mergev($phids);
|
||||
case PholioTransactionType::TYPE_IMAGE_REPLACE:
|
||||
return array($xaction->getNewValue()->getFilePHID());
|
||||
}
|
||||
|
||||
return array();
|
||||
}
|
||||
|
||||
|
||||
protected function transactionHasEffect(
|
||||
PhabricatorLiskDAO $object,
|
||||
PhabricatorApplicationTransaction $xaction) {
|
||||
|
|
|
@ -107,7 +107,10 @@ final class PhabricatorProjectProfileEditController
|
|||
$file,
|
||||
$x = 50,
|
||||
$y = 50);
|
||||
|
||||
$profile->setProfileImagePHID($xformed->getPHID());
|
||||
$xformed->attachToObject($user, $project->getPHID());
|
||||
|
||||
} else {
|
||||
$e_image = pht('Not Supported');
|
||||
$errors[] =
|
||||
|
|
|
@ -1575,13 +1575,20 @@ abstract class PhabricatorApplicationTransactionEditor
|
|||
}
|
||||
$blocks = array_mergev($blocks);
|
||||
|
||||
if (!$blocks) {
|
||||
return array();
|
||||
|
||||
$phids = array();
|
||||
if ($blocks) {
|
||||
$phids[] = PhabricatorMarkupEngine::extractFilePHIDsFromEmbeddedFiles(
|
||||
$blocks);
|
||||
}
|
||||
|
||||
$phids = PhabricatorMarkupEngine::extractFilePHIDsFromEmbeddedFiles(
|
||||
$blocks);
|
||||
foreach ($xactions as $xaction) {
|
||||
$phids[] = $this->extractFilePHIDsFromCustomTransaction(
|
||||
$object,
|
||||
$xaction);
|
||||
}
|
||||
|
||||
$phids = array_unique(array_filter(array_mergev($phids)));
|
||||
if (!$phids) {
|
||||
return array();
|
||||
}
|
||||
|
@ -1598,6 +1605,15 @@ abstract class PhabricatorApplicationTransactionEditor
|
|||
return mpull($files, 'getPHID');
|
||||
}
|
||||
|
||||
/**
|
||||
* @task files
|
||||
*/
|
||||
protected function extractFilePHIDsFromCustomTransaction(
|
||||
PhabricatorLiskDAO $object,
|
||||
PhabricatorApplicationTransaction $xaction) {
|
||||
return array();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @task files
|
||||
|
|
Loading…
Add table
Reference in a new issue