本文整理汇总了PHP中PhabricatorPolicies类的典型用法代码示例。如果您正苦于以下问题:PHP PhabricatorPolicies类的具体用法?PHP PhabricatorPolicies怎么用?PHP PhabricatorPolicies使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了PhabricatorPolicies类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getPolicy
public function getPolicy($capability)
{
// These objects are low-level and only accessed through the storage
// engine, so policies are mostly just in place to let us use the common
// query infrastructure.
return PhabricatorPolicies::getMostOpenPolicy();
}
示例2: getPolicy
public function getPolicy($capability)
{
switch ($capability) {
case PhabricatorPolicyCapability::CAN_VIEW:
return PhabricatorPolicies::getMostOpenPolicy();
}
}
示例3: initializeNewDocument
public static function initializeNewDocument(PhabricatorUser $actor, $slug)
{
$document = new PhrictionDocument();
$document->setSlug($slug);
$content = new PhrictionContent();
$content->setSlug($slug);
$default_title = PhabricatorSlug::getDefaultTitle($slug);
$content->setTitle($default_title);
$document->attachContent($content);
$parent_doc = null;
$ancestral_slugs = PhabricatorSlug::getAncestry($slug);
if ($ancestral_slugs) {
$parent = end($ancestral_slugs);
$parent_doc = id(new PhrictionDocumentQuery())->setViewer($actor)->withSlugs(array($parent))->executeOne();
}
if ($parent_doc) {
$document->setViewPolicy($parent_doc->getViewPolicy());
$document->setEditPolicy($parent_doc->getEditPolicy());
} else {
$default_view_policy = PhabricatorPolicies::getMostOpenPolicy();
$document->setViewPolicy($default_view_policy);
$document->setEditPolicy(PhabricatorPolicies::POLICY_USER);
}
return $document;
}
示例4: testFileVisibility
public function testFileVisibility()
{
$engine = new PhabricatorTestStorageEngine();
$data = Filesystem::readRandomCharacters(64);
$author = $this->generateNewTestUser();
$viewer = $this->generateNewTestUser();
$users = array($author, $viewer);
$params = array('name' => 'test.dat', 'viewPolicy' => PhabricatorPolicies::POLICY_NOONE, 'authorPHID' => $author->getPHID(), 'storageEngines' => array($engine));
$file = PhabricatorFile::newFromFileData($data, $params);
$filter = new PhabricatorPolicyFilter();
// Test bare file policies.
$this->assertEqual(array(true, false), $this->canViewFile($users, $file), pht('File Visibility'));
// Create an object and test object policies.
$object = ManiphestTask::initializeNewTask($author);
$object->setViewPolicy(PhabricatorPolicies::getMostOpenPolicy());
$object->save();
$this->assertTrue($filter->hasCapability($author, $object, PhabricatorPolicyCapability::CAN_VIEW), pht('Object Visible to Author'));
$this->assertTrue($filter->hasCapability($viewer, $object, PhabricatorPolicyCapability::CAN_VIEW), pht('Object Visible to Others'));
// Attach the file to the object and test that the association opens a
// policy exception for the non-author viewer.
$file->attachToObject($object->getPHID());
// Test the attached file's visibility.
$this->assertEqual(array(true, true), $this->canViewFile($users, $file), pht('Attached File Visibility'));
// Create a "thumbnail" of the original file.
$params = array('name' => 'test.thumb.dat', 'viewPolicy' => PhabricatorPolicies::POLICY_NOONE, 'storageEngines' => array($engine));
$xform = PhabricatorFile::newFromFileData($data, $params);
id(new PhabricatorTransformedFile())->setOriginalPHID($file->getPHID())->setTransform('test-thumb')->setTransformedPHID($xform->getPHID())->save();
// Test the thumbnail's visibility.
$this->assertEqual(array(true, true), $this->canViewFile($users, $xform), pht('Attached Thumbnail Visibility'));
// Detach the object and make sure it affects the thumbnail.
$file->detachFromObject($object->getPHID());
// Test the detached thumbnail's visibility.
$this->assertEqual(array(true, false), $this->canViewFile($users, $xform), pht('Detached Thumbnail Visibility'));
}
示例5: getPolicy
public function getPolicy($capability)
{
switch ($capability) {
case PhabricatorPolicyCapability::CAN_VIEW:
return PhabricatorPolicies::getMostOpenPolicy();
case PhabricatorPolicyCapability::CAN_EDIT:
return $this->getUserPHID();
}
}
示例6: render
public function render()
{
$viewer = $this->getUser();
if (!$viewer->isLoggedIn()) {
return null;
}
$instructions_id = celerity_generate_unique_node_id();
require_celerity_resource('global-drag-and-drop-css');
Javelin::initBehavior('global-drag-and-drop', array('ifSupported' => $this->showIfSupportedID, 'instructions' => $instructions_id, 'uploadURI' => '/file/dropupload/', 'browseURI' => '/file/query/authored/', 'viewPolicy' => PhabricatorPolicies::getMostOpenPolicy()));
return phutil_tag('div', array('id' => $instructions_id, 'class' => 'phabricator-global-upload-instructions', 'style' => 'display: none;'), pht("⇪ Drop Files to Upload"));
}
示例7: getPolicy
public function getPolicy($capability)
{
$policy = PhabricatorPolicies::POLICY_NOONE;
switch ($capability) {
case PhabricatorPolicyCapability::CAN_VIEW:
// Since it's impossible to perform any meaningful computations with
// time if a user can't view some of it, visibility on tracked time is
// unrestricted. If we eventually lock it down, it should be per-user.
// (This doesn't mean that users can see tracked objects.)
return PhabricatorPolicies::getMostOpenPolicy();
}
return $policy;
}
示例8: initializeNewCalendarEvent
public static function initializeNewCalendarEvent(PhabricatorUser $actor, $mode)
{
$app = id(new PhabricatorApplicationQuery())->setViewer($actor)->withClasses(array('PhabricatorCalendarApplication'))->executeOne();
$view_policy = null;
$is_recurring = 0;
if ($mode == 'public') {
$view_policy = PhabricatorPolicies::getMostOpenPolicy();
}
if ($mode == 'recurring') {
$is_recurring = true;
}
return id(new PhabricatorCalendarEvent())->setUserPHID($actor->getPHID())->setIsCancelled(0)->setIsAllDay(0)->setIsRecurring($is_recurring)->setIcon(self::DEFAULT_ICON)->setViewPolicy($view_policy)->setEditPolicy($actor->getPHID())->setSpacePHID($actor->getDefaultSpacePHID())->attachInvitees(array())->applyViewerTimezone($actor);
}
示例9: execute
protected function execute(ConduitAPIRequest $request)
{
$data = $request->getValue('data_base64');
$name = $request->getValue('name');
$can_cdn = $request->getValue('canCDN');
$view_policy = $request->getValue('viewPolicy');
$user = $request->getUser();
$data = base64_decode($data, $strict = true);
if (!$view_policy) {
$view_policy = PhabricatorPolicies::getMostOpenPolicy();
}
$file = PhabricatorFile::newFromFileData($data, array('name' => $name, 'authorPHID' => $user->getPHID(), 'viewPolicy' => $view_policy, 'canCDN' => $can_cdn, 'isExplicitUpload' => true));
return $file->getPHID();
}
示例10: validateOption
public function validateOption(PhabricatorConfigOption $option, $value)
{
if (phid_get_type($value) != PhabricatorFileFilePHIDType::TYPECONST) {
throw new Exception(pht('%s is not a valid file PHID.', $value));
}
$file = id(new PhabricatorFileQuery())->setViewer(PhabricatorUser::getOmnipotentUser())->withPHIDs(array($value))->executeOne();
if (!$file) {
throw new Exception(pht('%s is not a valid file PHID.', $value));
}
$most_open_policy = PhabricatorPolicies::getMostOpenPolicy();
if ($file->getViewPolicy() != $most_open_policy) {
throw new Exception(pht('Specified file %s has policy "%s" but should have policy "%s".', $value, $file->getViewPolicy(), $most_open_policy));
}
if (!$file->isViewableImage()) {
throw new Exception(pht('Specified file %s is not a viewable image.', $value));
}
}
示例11: execute
public function execute(HarbormasterBuild $build, HarbormasterBuildTarget $build_target)
{
$settings = $this->getSettings();
$variables = $build_target->getVariables();
$path = $this->mergeVariables('vsprintf', $settings['path'], $variables);
$artifact = $build->loadArtifact($settings['artifact']);
$file = $artifact->loadPhabricatorFile();
$fragment = id(new PhragmentFragmentQuery())->setViewer(PhabricatorUser::getOmnipotentUser())->withPaths(array($path))->executeOne();
if ($fragment === null) {
PhragmentFragment::createFromFile(PhabricatorUser::getOmnipotentUser(), $file, $path, PhabricatorPolicies::getMostOpenPolicy(), PhabricatorPolicies::POLICY_USER);
} else {
if ($file->getMimeType() === 'application/zip') {
$fragment->updateFromZIP(PhabricatorUser::getOmnipotentUser(), $file);
} else {
$fragment->updateFromFile(PhabricatorUser::getOmnipotentUser(), $file);
}
}
}
示例12: getBook
protected function getBook()
{
if (!$this->book) {
$book_name = $this->getConfig('name');
$book = id(new DivinerLiveBook())->loadOneWhere('name = %s', $book_name);
if (!$book) {
$book = id(new DivinerLiveBook())->setName($book_name)->setViewPolicy(PhabricatorPolicies::getMostOpenPolicy())->setEditPolicy(PhabricatorPolicies::POLICY_ADMIN)->save();
}
$conn_w = $book->establishConnection('w');
$conn_w->openTransaction();
$book->setRepositoryPHID($this->getRepositoryPHID())->setConfigurationData($this->getConfigurationData())->save();
// TODO: This is gross. Without this, the repository won't be updated for
// atoms which have already been published.
queryfx($conn_w, 'UPDATE %T SET repositoryPHID = %s WHERE bookPHID = %s', id(new DivinerLiveSymbol())->getTableName(), $this->getRepositoryPHID(), $book->getPHID());
$conn_w->saveTransaction();
$this->book = $book;
id(new PhabricatorSearchIndexer())->queueDocumentForIndexing($book->getPHID());
}
return $this->book;
}
示例13: getPolicy
public function getPolicy($capability)
{
switch ($capability) {
case PhabricatorPolicyCapability::CAN_VIEW:
return PhabricatorPolicies::getMostOpenPolicy();
case PhabricatorPolicyCapability::CAN_EDIT:
// NOTE: In practice, this policy is always limited by the "Mangage
// Build Plans" policy.
if ($this->isAutoplan()) {
return PhabricatorPolicies::POLICY_NOONE;
}
return PhabricatorPolicies::getMostOpenPolicy();
}
}
示例14: initializeNewPhurlURL
public static function initializeNewPhurlURL(PhabricatorUser $actor)
{
$app = id(new PhabricatorApplicationQuery())->setViewer($actor)->withClasses(array('PhabricatorPhurlApplication'))->executeOne();
return id(new PhabricatorPhurlURL())->setAuthorPHID($actor->getPHID())->setViewPolicy(PhabricatorPolicies::getMostOpenPolicy())->setEditPolicy($actor->getPHID())->setSpacePHID($actor->getDefaultSpacePHID());
}
示例15: initializeNewBlog
public static function initializeNewBlog(PhabricatorUser $actor)
{
$blog = id(new PhameBlog())->setCreatorPHID($actor->getPHID())->setViewPolicy(PhabricatorPolicies::getMostOpenPolicy())->setEditPolicy(PhabricatorPolicies::POLICY_USER)->setJoinPolicy(PhabricatorPolicies::POLICY_USER);
return $blog;
}