1
0
Fork 0
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:
epriestley 2013-10-06 17:07:55 -07:00
parent c587b8a9c8
commit 515f9a36ab
9 changed files with 98 additions and 10 deletions

View file

@ -860,6 +860,25 @@ final class PhabricatorFile extends PhabricatorFileDAO
return idx($this->metadata, self::METADATA_IMAGE_WIDTH); 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 )-------------------------- */ /* -( PhabricatorPolicyInterface Implementation )-------------------------- */

View file

@ -77,6 +77,18 @@ final class PhabricatorMacroEditor
return; return;
} }
protected function extractFilePHIDsFromCustomTransaction(
PhabricatorLiskDAO $object,
PhabricatorApplicationTransaction $xaction) {
switch ($xaction->getTransactionType()) {
case PhabricatorMacroTransactionType::TYPE_FILE:
return array($xaction->getNewValue());
}
return array();
}
protected function mergeTransactions( protected function mergeTransactions(
PhabricatorApplicationTransaction $u, PhabricatorApplicationTransaction $u,
PhabricatorApplicationTransaction $v) { PhabricatorApplicationTransaction $v) {

View file

@ -49,6 +49,8 @@ final class ConduitAPI_paste_create_Method extends ConduitAPI_paste_Method {
'authorPHID' => $user->getPHID(), 'authorPHID' => $user->getPHID(),
)); ));
// TODO: This should use PhabricatorPasteEditor.
$paste = new PhabricatorPaste(); $paste = new PhabricatorPaste();
$paste->setTitle($title); $paste->setTitle($title);
$paste->setLanguage($language); $paste->setLanguage($language);
@ -57,6 +59,8 @@ final class ConduitAPI_paste_create_Method extends ConduitAPI_paste_Method {
$paste->setViewPolicy(PhabricatorPolicies::POLICY_USER); $paste->setViewPolicy(PhabricatorPolicies::POLICY_USER);
$paste->save(); $paste->save();
$paste_file->attachToObject($user, $paste->getPHID());
$paste->attachRawContent($content); $paste->attachRawContent($content);
return $this->buildPasteInfoDictionary($paste); return $this->buildPasteInfoDictionary($paste);

View file

@ -1,11 +1,10 @@
<?php <?php
/**
* @group paste
*/
final class PhabricatorPasteEditor final class PhabricatorPasteEditor
extends PhabricatorApplicationTransactionEditor { extends PhabricatorApplicationTransactionEditor {
private $pasteFile;
public function getTransactionTypes() { public function getTransactionTypes() {
$types = parent::getTransactionTypes(); $types = parent::getTransactionTypes();
@ -95,11 +94,28 @@ final class PhabricatorPasteEditor
'authorPHID' => $this->getActor()->getPHID(), 'authorPHID' => $this->getActor()->getPHID(),
)); ));
$object->setFilePHID($paste_file->getPHID()); $object->setFilePHID($paste_file->getPHID());
$this->pasteFile = $paste_file;
break; 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( protected function shouldSendMail(
PhabricatorLiskDAO $object, PhabricatorLiskDAO $object,
array $xactions) { array $xactions) {

View file

@ -1,8 +1,5 @@
<?php <?php
/**
* @group paste
*/
final class PhabricatorPasteTransaction final class PhabricatorPasteTransaction
extends PhabricatorApplicationTransaction { extends PhabricatorApplicationTransaction {

View file

@ -82,6 +82,7 @@ final class PhabricatorPeopleProfilePictureController
$user->setProfileImagePHID(null); $user->setProfileImagePHID(null);
} else { } else {
$user->setProfileImagePHID($xformed->getPHID()); $user->setProfileImagePHID($xformed->getPHID());
$xformed->attachToObject($viewer, $user->getPHID());
} }
$user->save(); $user->save();
return id(new AphrontRedirectResponse())->setURI($profile_uri); return id(new AphrontRedirectResponse())->setURI($profile_uri);

View file

@ -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( protected function transactionHasEffect(
PhabricatorLiskDAO $object, PhabricatorLiskDAO $object,
PhabricatorApplicationTransaction $xaction) { PhabricatorApplicationTransaction $xaction) {

View file

@ -107,7 +107,10 @@ final class PhabricatorProjectProfileEditController
$file, $file,
$x = 50, $x = 50,
$y = 50); $y = 50);
$profile->setProfileImagePHID($xformed->getPHID()); $profile->setProfileImagePHID($xformed->getPHID());
$xformed->attachToObject($user, $project->getPHID());
} else { } else {
$e_image = pht('Not Supported'); $e_image = pht('Not Supported');
$errors[] = $errors[] =

View file

@ -1575,13 +1575,20 @@ abstract class PhabricatorApplicationTransactionEditor
} }
$blocks = array_mergev($blocks); $blocks = array_mergev($blocks);
if (!$blocks) {
return array(); $phids = array();
if ($blocks) {
$phids[] = PhabricatorMarkupEngine::extractFilePHIDsFromEmbeddedFiles(
$blocks);
} }
$phids = PhabricatorMarkupEngine::extractFilePHIDsFromEmbeddedFiles( foreach ($xactions as $xaction) {
$blocks); $phids[] = $this->extractFilePHIDsFromCustomTransaction(
$object,
$xaction);
}
$phids = array_unique(array_filter(array_mergev($phids)));
if (!$phids) { if (!$phids) {
return array(); return array();
} }
@ -1598,6 +1605,15 @@ abstract class PhabricatorApplicationTransactionEditor
return mpull($files, 'getPHID'); return mpull($files, 'getPHID');
} }
/**
* @task files
*/
protected function extractFilePHIDsFromCustomTransaction(
PhabricatorLiskDAO $object,
PhabricatorApplicationTransaction $xaction) {
return array();
}
/** /**
* @task files * @task files