1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-23 14:00:56 +01:00

Fix file attach bug in Macro

Summary: This was mis-tested by only using one account, which could always see the image. External transaction moved file attachment to the modular transaction for file and audio instead.

Test Plan: Test adding audio and a macro on a pleb account, visit with normal account and see macro fine.

Reviewers: epriestley, amckinley

Reviewed By: amckinley

Subscribers: Korvin

Differential Revision: https://secure.phabricator.com/D17836
This commit is contained in:
Chad Little 2017-05-05 19:50:05 -07:00
parent c8c23af840
commit 0a87881e98
4 changed files with 57 additions and 39 deletions

View file

@ -6,7 +6,7 @@ final class PhabricatorMacroEditEngine
const ENGINECONST = 'macro.image'; const ENGINECONST = 'macro.image';
public function getEngineName() { public function getEngineName() {
return pht('Macro Imagea'); return pht('Macro Image');
} }
public function getSummaryHeader() { public function getSummaryHeader() {

View file

@ -19,44 +19,6 @@ final class PhabricatorMacroEditor
return pht('%s created %s.', $author, $object); return pht('%s created %s.', $author, $object);
} }
protected function applyCustomExternalTransaction(
PhabricatorLiskDAO $object,
PhabricatorApplicationTransaction $xaction) {
switch ($xaction->getTransactionType()) {
case PhabricatorMacroFileTransaction::TRANSACTIONTYPE:
case PhabricatorMacroAudioTransaction::TRANSACTIONTYPE:
// When changing a macro's image or audio, attach the underlying files
// to the macro (and detach the old files).
$old = $xaction->getOldValue();
$new = $xaction->getNewValue();
$all = array();
if ($old) {
$all[] = $old;
}
if ($new) {
$all[] = $new;
}
$files = id(new PhabricatorFileQuery())
->setViewer($this->requireActor())
->withPHIDs($all)
->execute();
$files = mpull($files, null, 'getPHID');
$old_file = idx($files, $old);
if ($old_file) {
$old_file->detachFromObject($object->getPHID());
}
$new_file = idx($files, $new);
if ($new_file) {
$new_file->attachToObject($object->getPHID());
}
break;
}
}
protected function shouldSendMail( protected function shouldSendMail(
PhabricatorLiskDAO $object, PhabricatorLiskDAO $object,
array $xactions) { array $xactions) {

View file

@ -13,6 +13,34 @@ final class PhabricatorMacroAudioTransaction
$object->setAudioPHID($value); $object->setAudioPHID($value);
} }
public function applyExternalEffects($object, $value) {
$old = $this->generateOldValue($object);
$new = $value;
$all = array();
if ($old) {
$all[] = $old;
}
if ($new) {
$all[] = $new;
}
$files = id(new PhabricatorFileQuery())
->setViewer($this->getActor())
->withPHIDs($all)
->execute();
$files = mpull($files, null, 'getPHID');
$old_file = idx($files, $old);
if ($old_file) {
$old_file->detachFromObject($object->getPHID());
}
$new_file = idx($files, $new);
if ($new_file) {
$new_file->attachToObject($object->getPHID());
}
}
public function getTitle() { public function getTitle() {
$new = $this->getNewValue(); $new = $this->getNewValue();
$old = $this->getOldValue(); $old = $this->getOldValue();

View file

@ -13,6 +13,34 @@ final class PhabricatorMacroFileTransaction
$object->setFilePHID($value); $object->setFilePHID($value);
} }
public function applyExternalEffects($object, $value) {
$old = $this->generateOldValue($object);
$new = $value;
$all = array();
if ($old) {
$all[] = $old;
}
if ($new) {
$all[] = $new;
}
$files = id(new PhabricatorFileQuery())
->setViewer($this->getActor())
->withPHIDs($all)
->execute();
$files = mpull($files, null, 'getPHID');
$old_file = idx($files, $old);
if ($old_file) {
$old_file->detachFromObject($object->getPHID());
}
$new_file = idx($files, $new);
if ($new_file) {
$new_file->attachToObject($object->getPHID());
}
}
public function getTitle() { public function getTitle() {
return pht( return pht(
'%s changed the image for this macro.', '%s changed the image for this macro.',