mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-14 02:42:40 +01:00
Identify builtin files and give them open policies
Summary: Fixes T7379. Currently, builtin files generate with a "users" view policy even if an install is public. Because these files TTL after 7 days, there's no migration here. Installs won't see the fix actually happen for up to 7 days after updating, though. Test Plan: - Deleted a builtin. - Loaded projects page to regenerate it. - Saw new builtin had most open policy and was marked as a builtin. Reviewers: btrahan Reviewed By: btrahan Subscribers: epriestley Maniphest Tasks: T7379 Differential Revision: https://secure.phabricator.com/D11917
This commit is contained in:
parent
963025d374
commit
d1eda610fa
2 changed files with 34 additions and 0 deletions
|
@ -222,6 +222,15 @@ final class PhabricatorFileInfoController extends PhabricatorFileController {
|
||||||
$finfo->addProperty(pht('Viewable Image'), $image_string);
|
$finfo->addProperty(pht('Viewable Image'), $image_string);
|
||||||
$finfo->addProperty(pht('Cacheable'), $cache_string);
|
$finfo->addProperty(pht('Cacheable'), $cache_string);
|
||||||
|
|
||||||
|
$builtin = $file->getBuiltinName();
|
||||||
|
if ($builtin === null) {
|
||||||
|
$builtin_string = pht('No');
|
||||||
|
} else {
|
||||||
|
$builtin_string = $builtin;
|
||||||
|
}
|
||||||
|
|
||||||
|
$finfo->addProperty(pht('Builtin'), $builtin_string);
|
||||||
|
|
||||||
$storage_properties = new PHUIPropertyListView();
|
$storage_properties = new PHUIPropertyListView();
|
||||||
$box->addPropertyList($storage_properties, pht('Storage'));
|
$box->addPropertyList($storage_properties, pht('Storage'));
|
||||||
|
|
||||||
|
|
|
@ -14,6 +14,7 @@
|
||||||
* | isExplicitUpload | Used to show users files they explicitly uploaded.
|
* | isExplicitUpload | Used to show users files they explicitly uploaded.
|
||||||
* | canCDN | Allows the file to be cached and delivered over a CDN.
|
* | canCDN | Allows the file to be cached and delivered over a CDN.
|
||||||
* | mime-type | Optional, explicit file MIME type.
|
* | mime-type | Optional, explicit file MIME type.
|
||||||
|
* | builtin | Optional filename, identifies this as a builtin.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
final class PhabricatorFile extends PhabricatorFileDAO
|
final class PhabricatorFile extends PhabricatorFileDAO
|
||||||
|
@ -31,6 +32,7 @@ final class PhabricatorFile extends PhabricatorFileDAO
|
||||||
const METADATA_IMAGE_WIDTH = 'width';
|
const METADATA_IMAGE_WIDTH = 'width';
|
||||||
const METADATA_IMAGE_HEIGHT = 'height';
|
const METADATA_IMAGE_HEIGHT = 'height';
|
||||||
const METADATA_CAN_CDN = 'canCDN';
|
const METADATA_CAN_CDN = 'canCDN';
|
||||||
|
const METADATA_BUILTIN = 'builtin';
|
||||||
|
|
||||||
protected $name;
|
protected $name;
|
||||||
protected $mimeType;
|
protected $mimeType;
|
||||||
|
@ -895,6 +897,8 @@ final class PhabricatorFile extends PhabricatorFileDAO
|
||||||
$params = array(
|
$params = array(
|
||||||
'name' => $name,
|
'name' => $name,
|
||||||
'ttl' => time() + (60 * 60 * 24 * 7),
|
'ttl' => time() + (60 * 60 * 24 * 7),
|
||||||
|
'canCDN' => true,
|
||||||
|
'builtin' => $name,
|
||||||
);
|
);
|
||||||
|
|
||||||
$unguarded = AphrontWriteGuard::beginScopedUnguardedWrites();
|
$unguarded = AphrontWriteGuard::beginScopedUnguardedWrites();
|
||||||
|
@ -981,6 +985,19 @@ final class PhabricatorFile extends PhabricatorFileDAO
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function isBuiltin() {
|
||||||
|
return ($this->getBuiltinName() !== null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getBuiltinName() {
|
||||||
|
return idx($this->metadata, self::METADATA_BUILTIN);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setBuiltinName($name) {
|
||||||
|
$this->metadata[self::METADATA_BUILTIN] = $name;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
protected function generateOneTimeToken() {
|
protected function generateOneTimeToken() {
|
||||||
$key = Filesystem::readRandomCharacters(16);
|
$key = Filesystem::readRandomCharacters(16);
|
||||||
|
|
||||||
|
@ -1078,6 +1095,11 @@ final class PhabricatorFile extends PhabricatorFileDAO
|
||||||
$this->setCanCDN(true);
|
$this->setCanCDN(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$builtin = idx($params, 'builtin');
|
||||||
|
if ($builtin) {
|
||||||
|
$this->setBuiltinName($builtin);
|
||||||
|
}
|
||||||
|
|
||||||
$mime_type = idx($params, 'mime-type');
|
$mime_type = idx($params, 'mime-type');
|
||||||
if ($mime_type) {
|
if ($mime_type) {
|
||||||
$this->setMimeType($mime_type);
|
$this->setMimeType($mime_type);
|
||||||
|
@ -1142,6 +1164,9 @@ final class PhabricatorFile extends PhabricatorFileDAO
|
||||||
public function getPolicy($capability) {
|
public function getPolicy($capability) {
|
||||||
switch ($capability) {
|
switch ($capability) {
|
||||||
case PhabricatorPolicyCapability::CAN_VIEW:
|
case PhabricatorPolicyCapability::CAN_VIEW:
|
||||||
|
if ($this->isBuiltin()) {
|
||||||
|
return PhabricatorPolicies::getMostOpenPolicy();
|
||||||
|
}
|
||||||
return $this->getViewPolicy();
|
return $this->getViewPolicy();
|
||||||
case PhabricatorPolicyCapability::CAN_EDIT:
|
case PhabricatorPolicyCapability::CAN_EDIT:
|
||||||
return PhabricatorPolicies::POLICY_NOONE;
|
return PhabricatorPolicies::POLICY_NOONE;
|
||||||
|
|
Loading…
Reference in a new issue