1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-18 21:02:41 +01:00

Add default policy to Files application

Summary: **WIP** This adds default capability to the Files application

Test Plan: Set default to public, go to Files page, see public preset. Upload File. Doesn't work.

Reviewers: btrahan, epriestley

Reviewed By: epriestley

Subscribers: Korvin, epriestley

Maniphest Tasks: T6564

Differential Revision: https://secure.phabricator.com/D10888
This commit is contained in:
Chad Little 2014-11-21 11:17:20 -08:00
parent 31c09b7d6a
commit 1a8d87699c
5 changed files with 38 additions and 2 deletions

View file

@ -725,6 +725,7 @@ phutil_register_library_map(array(
'FileReplyHandler' => 'applications/files/mail/FileReplyHandler.php',
'FileUploadConduitAPIMethod' => 'applications/files/conduit/FileUploadConduitAPIMethod.php',
'FileUploadHashConduitAPIMethod' => 'applications/files/conduit/FileUploadHashConduitAPIMethod.php',
'FilesDefaultViewCapability' => 'applications/files/capability/FilesDefaultViewCapability.php',
'FlagConduitAPIMethod' => 'applications/flag/conduit/FlagConduitAPIMethod.php',
'FlagDeleteConduitAPIMethod' => 'applications/flag/conduit/FlagDeleteConduitAPIMethod.php',
'FlagEditConduitAPIMethod' => 'applications/flag/conduit/FlagEditConduitAPIMethod.php',
@ -3726,6 +3727,7 @@ phutil_register_library_map(array(
'FileReplyHandler' => 'PhabricatorMailReplyHandler',
'FileUploadConduitAPIMethod' => 'FileConduitAPIMethod',
'FileUploadHashConduitAPIMethod' => 'FileConduitAPIMethod',
'FilesDefaultViewCapability' => 'PhabricatorPolicyCapability',
'FlagConduitAPIMethod' => 'ConduitAPIMethod',
'FlagDeleteConduitAPIMethod' => 'FlagConduitAPIMethod',
'FlagEditConduitAPIMethod' => 'FlagConduitAPIMethod',

View file

@ -11,7 +11,7 @@ final class PhabricatorFilesApplication extends PhabricatorApplication {
}
public function getShortDescription() {
return 'Store and Share Files';
return pht('Store and Share Files');
}
public function getIconName() {
@ -40,6 +40,15 @@ final class PhabricatorFilesApplication extends PhabricatorApplication {
);
}
protected function getCustomCapabilities() {
return array(
FilesDefaultViewCapability::CAPABILITY => array(
'caption' => pht(
'Default view policy for newly created files.'),
),
);
}
public function getRoutes() {
return array(
'/F(?P<id>[1-9]\d*)' => 'PhabricatorFileInfoController',

View file

@ -0,0 +1,16 @@
<?php
final class FilesDefaultViewCapability
extends PhabricatorPolicyCapability {
const CAPABILITY = 'files.default.view';
public function getCapabilityName() {
return pht('Default View Policy');
}
public function shouldAllowPublicPolicySetting() {
return true;
}
}

View file

@ -6,7 +6,7 @@ final class PhabricatorFileUploadController extends PhabricatorFileController {
$request = $this->getRequest();
$viewer = $request->getUser();
$file = new PhabricatorFile();
$file = PhabricatorFile::initializeNewFile();
$e_file = true;
$errors = array();

View file

@ -53,7 +53,16 @@ final class PhabricatorFile extends PhabricatorFileDAO
private $originalFile = self::ATTACHABLE;
public static function initializeNewFile() {
$app = id(new PhabricatorApplicationQuery())
->setViewer(PhabricatorUser::getOmnipotentUser())
->withClasses(array('PhabricatorFilesApplication'))
->executeOne();
$view_policy = $app->getPolicy(
FilesDefaultViewCapability::CAPABILITY);
return id(new PhabricatorFile())
->setViewPolicy($view_policy)
->attachOriginalFile(null)
->attachObjects(array())
->attachObjectPHIDs(array());