public final function execute() { if (!$this->viewer) { throw new Exception("Call setViewer() before execute()!"); } $results = array(); $filter = new PhabricatorPolicyFilter(); $filter->setViewer($this->viewer); $filter->setCapability(PhabricatorPolicyCapability::CAN_VIEW); $filter->raisePolicyExceptions($this->raisePolicyExceptions); do { $page = $this->loadPage(); $visible = $filter->apply($page); foreach ($visible as $key => $result) { $results[$key] = $result; if ($this->getLimit() && count($results) >= $this->getLimit()) { break 2; } } if (!$this->getLimit() || count($page) < $this->getLimit()) { break; } $this->nextPage($page); } while (true); return $results; }
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')); }
public static function hasCapability(PhabricatorUser $user, PhabricatorPolicyInterface $object, $capability) { $filter = new PhabricatorPolicyFilter(); $filter->setViewer($user); $filter->requireCapabilities(array($capability)); $result = $filter->apply(array($object)); return count($result) == 1; }
private function renderPreface() { $viewer = $this->getRequest()->getUser(); $branch = $this->getBranch(); $id = $branch->getID(); $header = id(new PHUIHeaderView())->setHeader($branch->getDisplayName())->setUser($viewer)->setPolicyObject($branch); if ($branch->getIsActive()) { $header->setStatus('fa-check', 'bluegrey', pht('Active')); } else { $header->setStatus('fa-ban', 'dark', pht('Closed')); } $actions = id(new PhabricatorActionListView())->setUser($viewer)->setObject($branch)->setObjectURI($this->getRequest()->getRequestURI()); $can_edit = PhabricatorPolicyFilter::hasCapability($viewer, $branch, PhabricatorPolicyCapability::CAN_EDIT); $edit_uri = $this->getApplicationURI("branch/edit/{$id}/"); $close_uri = $this->getApplicationURI("branch/close/{$id}/"); $reopen_uri = $this->getApplicationURI("branch/re-open/{$id}/"); $history_uri = $this->getApplicationURI("branch/{$id}/history/"); $actions->addAction(id(new PhabricatorActionView())->setName(pht('Edit Branch'))->setHref($edit_uri)->setIcon('fa-pencil')->setDisabled(!$can_edit)->setWorkflow(!$can_edit)); if ($branch->getIsActive()) { $actions->addAction(id(new PhabricatorActionView())->setName(pht('Close Branch'))->setHref($close_uri)->setIcon('fa-times')->setDisabled(!$can_edit)->setWorkflow(true)); } else { $actions->addAction(id(new PhabricatorActionView())->setName(pht('Reopen Branch'))->setHref($reopen_uri)->setIcon('fa-plus')->setUser($viewer)->setDisabled(!$can_edit)->setWorkflow(true)); } $actions->addAction(id(new PhabricatorActionView())->setName(pht('View History'))->setHref($history_uri)->setIcon('fa-list')); $properties = id(new PHUIPropertyListView())->setUser($viewer)->setObject($branch)->setActionList($actions); $properties->addProperty(pht('Branch'), $branch->getName()); return id(new PHUIObjectBoxView())->setHeader($header)->addPropertyList($properties); }
private function buildActionView(ManiphestTask $task) { $viewer = $this->getRequest()->getUser(); $id = $task->getID(); $phid = $task->getPHID(); $can_edit = PhabricatorPolicyFilter::hasCapability($viewer, $task, PhabricatorPolicyCapability::CAN_EDIT); $view = id(new PhabricatorActionListView())->setUser($viewer)->setObject($task); $view->addAction(id(new PhabricatorActionView())->setName(pht('Edit Task'))->setIcon('fa-pencil')->setHref($this->getApplicationURI("/task/edit/{$id}/"))->setDisabled(!$can_edit)->setWorkflow(!$can_edit)); $view->addAction(id(new PhabricatorActionView())->setName(pht('Merge Duplicates In'))->setHref("/search/attach/{$phid}/TASK/merge/")->setWorkflow(true)->setIcon('fa-compress')->setDisabled(!$can_edit)->setWorkflow(true)); $edit_config = id(new ManiphestEditEngine())->setViewer($viewer)->loadDefaultEditConfiguration(); $can_create = (bool) $edit_config; if ($can_create) { $form_key = $edit_config->getIdentifier(); $edit_uri = id(new PhutilURI("/task/edit/form/{$form_key}/"))->setQueryParam('parent', $id)->setQueryParam('template', $id)->setQueryParam('status', ManiphestTaskStatus::getDefaultStatus()); $edit_uri = $this->getApplicationURI($edit_uri); } else { // TODO: This will usually give us a somewhat-reasonable error page, but // could be a bit cleaner. $edit_uri = "/task/edit/{$id}/"; $edit_uri = $this->getApplicationURI($edit_uri); } $view->addAction(id(new PhabricatorActionView())->setName(pht('Create Subtask'))->setHref($edit_uri)->setIcon('fa-level-down')->setDisabled(!$can_create)->setWorkflow(!$can_create)); $view->addAction(id(new PhabricatorActionView())->setName(pht('Edit Blocking Tasks'))->setHref("/search/attach/{$phid}/TASK/blocks/")->setWorkflow(true)->setIcon('fa-link')->setDisabled(!$can_edit)->setWorkflow(true)); return $view; }
private function buildActionView(PhabricatorUser $viewer, PhabricatorPaste $paste, PhabricatorFile $file) { $can_edit = PhabricatorPolicyFilter::hasCapability($viewer, $paste, PhabricatorPolicyCapability::CAN_EDIT); $can_fork = $viewer->isLoggedIn(); $fork_uri = $this->getApplicationURI('/create/?parent=' . $paste->getID()); return id(new PhabricatorActionListView())->setUser($viewer)->setObject($paste)->setObjectURI($this->getRequest()->getRequestURI())->addAction(id(new PhabricatorActionView())->setName(pht('Edit Paste'))->setIcon('fa-pencil')->setDisabled(!$can_edit)->setWorkflow(!$can_edit)->setHref($this->getApplicationURI('/edit/' . $paste->getID() . '/')))->addAction(id(new PhabricatorActionView())->setName(pht('Fork This Paste'))->setIcon('fa-code-fork')->setDisabled(!$can_fork)->setWorkflow(!$can_fork)->setHref($fork_uri))->addAction(id(new PhabricatorActionView())->setName(pht('View Raw File'))->setIcon('fa-file-text-o')->setHref($file->getBestURI())); }
public function render() { require_celerity_resource('conpherence-menu-css'); require_celerity_resource('conpherence-message-pane-css'); require_celerity_resource('conpherence-participant-pane-css'); $layout_id = 'conpherence-main-layout'; $selected_id = null; $selected_thread_id = null; $selected_thread_phid = null; $can_edit_selected = null; $nux = null; if ($this->thread) { $selected_id = $this->thread->getPHID() . '-nav-item'; $selected_thread_id = $this->thread->getID(); $selected_thread_phid = $this->thread->getPHID(); $can_edit_selected = PhabricatorPolicyFilter::hasCapability($this->getUser(), $this->thread, PhabricatorPolicyCapability::CAN_EDIT); } else { $nux = $this->buildNUXView(); } $this->initBehavior('conpherence-menu', array('baseURI' => $this->baseURI, 'layoutID' => $layout_id, 'selectedID' => $selected_id, 'selectedThreadID' => $selected_thread_id, 'selectedThreadPHID' => $selected_thread_phid, 'canEditSelectedThread' => $can_edit_selected, 'latestTransactionID' => $this->latestTransactionID, 'role' => $this->role, 'hasThreadList' => (bool) $this->threadView, 'hasThread' => (bool) $this->messages, 'hasWidgets' => false)); $classes = array(); if (!$this->getUser()->isLoggedIn()) { $classes[] = 'conpherence-logged-out'; } if (!$this->getWidgetColumnVisible()) { $classes[] = 'hide-widgets'; } $this->initBehavior('conpherence-participant-pane'); return javelin_tag('div', array('id' => $layout_id, 'sigil' => 'conpherence-layout', 'class' => 'conpherence-layout ' . implode(' ', $classes) . ' conpherence-role-' . $this->role), array(javelin_tag('div', array('id' => 'conpherence-menu-pane', 'class' => 'conpherence-menu-pane phabricator-side-menu', 'sigil' => 'conpherence-menu-pane'), $this->threadView), javelin_tag('div', array('class' => 'conpherence-content-pane'), array(javelin_tag('div', array('class' => 'conpherence-header-pane', 'id' => 'conpherence-header-pane', 'sigil' => 'conpherence-header-pane'), nonempty($this->header, '')), javelin_tag('div', array('class' => 'conpherence-no-threads', 'sigil' => 'conpherence-no-threads', 'style' => 'display: none;'), $nux), javelin_tag('div', array('class' => 'conpherence-participant-pane', 'id' => 'conpherence-participant-pane', 'sigil' => 'conpherence-participant-pane'), array(phutil_tag('div', array('class' => 'widgets-loading-mask'), ''), javelin_tag('div', array('sigil' => 'conpherence-widgets-holder'), ''))), javelin_tag('div', array('class' => 'conpherence-message-pane', 'id' => 'conpherence-message-pane', 'sigil' => 'conpherence-message-pane'), array(javelin_tag('div', array('class' => 'conpherence-messages', 'id' => 'conpherence-messages', 'sigil' => 'conpherence-messages'), nonempty($this->messages, '')), phutil_tag('div', array('class' => 'messages-loading-mask'), ''), javelin_tag('div', array('id' => 'conpherence-form', 'sigil' => 'conpherence-form'), nonempty($this->replyForm, '')))))))); }
private function buildActionList(HarbormasterBuildable $buildable) { $request = $this->getRequest(); $viewer = $request->getUser(); $id = $buildable->getID(); $list = id(new PhabricatorActionListView())->setUser($viewer)->setObject($buildable)->setObjectURI($buildable->getMonogram()); $can_edit = PhabricatorPolicyFilter::hasCapability($viewer, $buildable, PhabricatorPolicyCapability::CAN_EDIT); $can_restart = false; $can_resume = false; $can_pause = false; $can_abort = false; foreach ($buildable->getBuilds() as $build) { if ($build->canRestartBuild()) { $can_restart = true; } if ($build->canResumeBuild()) { $can_resume = true; } if ($build->canPauseBuild()) { $can_pause = true; } if ($build->canAbortBuild()) { $can_abort = true; } } $restart_uri = "buildable/{$id}/restart/"; $pause_uri = "buildable/{$id}/pause/"; $resume_uri = "buildable/{$id}/resume/"; $abort_uri = "buildable/{$id}/abort/"; $list->addAction(id(new PhabricatorActionView())->setIcon('fa-repeat')->setName(pht('Restart All Builds'))->setHref($this->getApplicationURI($restart_uri))->setWorkflow(true)->setDisabled(!$can_restart || !$can_edit)); $list->addAction(id(new PhabricatorActionView())->setIcon('fa-pause')->setName(pht('Pause All Builds'))->setHref($this->getApplicationURI($pause_uri))->setWorkflow(true)->setDisabled(!$can_pause || !$can_edit)); $list->addAction(id(new PhabricatorActionView())->setIcon('fa-play')->setName(pht('Resume All Builds'))->setHref($this->getApplicationURI($resume_uri))->setWorkflow(true)->setDisabled(!$can_resume || !$can_edit)); $list->addAction(id(new PhabricatorActionView())->setIcon('fa-exclamation-triangle')->setName(pht('Abort All Builds'))->setHref($this->getApplicationURI($abort_uri))->setWorkflow(true)->setDisabled(!$can_abort || !$can_edit)); return $list; }
private function renderSettingsWidgetPaneContent() { $viewer = $this->getViewer(); $conpherence = $this->getConpherence(); $participant = $conpherence->getParticipantIfExists($viewer->getPHID()); if (!$participant) { $can_join = PhabricatorPolicyFilter::hasCapability($viewer, $conpherence, PhabricatorPolicyCapability::CAN_JOIN); if ($can_join) { $text = pht('Notification settings are available after joining the room.'); } else { if ($viewer->isLoggedIn()) { $text = pht('Notification settings not applicable to rooms you can not join.'); } else { $text = pht('Notification settings are available after logging in and joining ' . 'the room.'); } } return phutil_tag('div', array('class' => 'no-settings'), $text); } $default = ConpherenceSettings::EMAIL_ALWAYS; $preference = $this->getUserPreferences(); if ($preference) { $default = $preference->getPreference(PhabricatorUserPreferences::PREFERENCE_CONPH_NOTIFICATIONS, ConpherenceSettings::EMAIL_ALWAYS); } $settings = $participant->getSettings(); $notifications = idx($settings, 'notifications', $default); $options = id(new AphrontFormRadioButtonControl())->addButton(ConpherenceSettings::EMAIL_ALWAYS, ConpherenceSettings::getHumanString(ConpherenceSettings::EMAIL_ALWAYS), '')->addButton(ConpherenceSettings::NOTIFICATIONS_ONLY, ConpherenceSettings::getHumanString(ConpherenceSettings::NOTIFICATIONS_ONLY), '')->setName('notifications')->setValue($notifications); $layout = array($options, phutil_tag('input', array('type' => 'hidden', 'name' => 'action', 'value' => 'notifications')), phutil_tag('button', array('type' => 'submit', 'class' => 'notifications-update'), pht('Save'))); return phabricator_form($viewer, array('method' => 'POST', 'action' => $this->getWidgetURI(), 'sigil' => 'notifications-update'), $layout); }
public function handleRequest(AphrontRequest $request) { $viewer = $this->getViewer(); $username = $request->getURIData('username'); $user = id(new PhabricatorPeopleQuery())->setViewer($viewer)->withUsernames(array($username))->needBadges(true)->needProfileImage(true)->needAvailability(true)->executeOne(); if (!$user) { return new Aphront404Response(); } $this->setUser($user); $profile = $user->loadUserProfile(); $picture = $user->getProfileImageURI(); $profile_icon = PhabricatorPeopleIconSet::getIconIcon($profile->getIcon()); $profile_icon = id(new PHUIIconView())->setIcon($profile_icon); $profile_title = $profile->getDisplayTitle(); $header = id(new PHUIHeaderView())->setHeader($user->getFullName())->setSubheader(array($profile_icon, $profile_title))->setImage($picture)->setProfileHeader(true); $can_edit = PhabricatorPolicyFilter::hasCapability($viewer, $user, PhabricatorPolicyCapability::CAN_EDIT); if ($can_edit) { $id = $user->getID(); $header->setImageEditURL($this->getApplicationURI("picture/{$id}/")); } $properties = $this->buildPropertyView($user); $name = $user->getUsername(); $feed = $this->buildPeopleFeed($user, $viewer); $feed = phutil_tag_div('project-view-feed', $feed); $projects = $this->buildProjectsView($user); $badges = $this->buildBadgesView($user); $columns = id(new PHUITwoColumnView())->addClass('project-view-badges')->setMainColumn(array($properties, $feed))->setSideColumn(array($projects, $badges)); $nav = $this->getProfileMenu(); $nav->selectFilter(PhabricatorPeopleProfilePanelEngine::PANEL_PROFILE); $crumbs = $this->buildApplicationCrumbs(); $crumbs->setBorder(true); require_celerity_resource('project-view-css'); $home = phutil_tag('div', array('class' => 'project-view-home'), array($header, $columns)); return $this->newPage()->setTitle($user->getUsername())->setNavigation($nav)->setCrumbs($crumbs)->appendChild(array($home)); }
private function buildActionView(PhabricatorDashboard $dashboard) { $viewer = $this->getRequest()->getUser(); $id = $dashboard->getID(); $actions = id(new PhabricatorActionListView())->setObjectURI($this->getApplicationURI('view/' . $dashboard->getID() . '/'))->setObject($dashboard)->setUser($viewer); $can_edit = PhabricatorPolicyFilter::hasCapability($viewer, $dashboard, PhabricatorPolicyCapability::CAN_EDIT); $actions->addAction(id(new PhabricatorActionView())->setName(pht('View Dashboard'))->setIcon('fa-columns')->setHref($this->getApplicationURI("view/{$id}/"))); $actions->addAction(id(new PhabricatorActionView())->setName(pht('Edit Dashboard'))->setIcon('fa-pencil')->setHref($this->getApplicationURI("edit/{$id}/"))->setDisabled(!$can_edit)); if ($dashboard->isArchived()) { $actions->addAction(id(new PhabricatorActionView())->setName(pht('Activate Dashboard'))->setIcon('fa-check')->setHref($this->getApplicationURI("archive/{$id}/"))->setDisabled(!$can_edit)->setWorkflow($can_edit)); } else { $actions->addAction(id(new PhabricatorActionView())->setName(pht('Archive Dashboard'))->setIcon('fa-ban')->setHref($this->getApplicationURI("archive/{$id}/"))->setDisabled(!$can_edit)->setWorkflow($can_edit)); } $actions->addAction(id(new PhabricatorActionView())->setName(pht('Copy Dashboard'))->setIcon('fa-files-o')->setHref($this->getApplicationURI("copy/{$id}/"))->setWorkflow(true)); $installed_dashboard = id(new PhabricatorDashboardInstall())->loadOneWhere('objectPHID = %s AND applicationClass = %s', $viewer->getPHID(), 'PhabricatorHomeApplication'); if ($installed_dashboard && $installed_dashboard->getDashboardPHID() == $dashboard->getPHID()) { $title_install = pht('Uninstall Dashboard'); $href_install = "uninstall/{$id}/"; } else { $title_install = pht('Install Dashboard'); $href_install = "install/{$id}/"; } $actions->addAction(id(new PhabricatorActionView())->setName($title_install)->setIcon('fa-wrench')->setHref($this->getApplicationURI($href_install))->setWorkflow(true)); $actions->addAction(id(new PhabricatorActionView())->setName(pht('View History'))->setIcon('fa-history')->setHref($this->getApplicationURI("history/{$id}/"))); return $actions; }
private function buildCurtain(PhabricatorApplication $application) { $viewer = $this->getViewer(); $can_edit = PhabricatorPolicyFilter::hasCapability($viewer, $application, PhabricatorPolicyCapability::CAN_EDIT); $key = get_class($application); $edit_uri = $this->getApplicationURI("edit/{$key}/"); $install_uri = $this->getApplicationURI("{$key}/install/"); $uninstall_uri = $this->getApplicationURI("{$key}/uninstall/"); $curtain = $this->newCurtainView($application); $curtain->addAction(id(new PhabricatorActionView())->setName(pht('Edit Policies'))->setIcon('fa-pencil')->setDisabled(!$can_edit)->setWorkflow(!$can_edit)->setHref($edit_uri)); if ($application->canUninstall()) { if ($application->isInstalled()) { $curtain->addAction(id(new PhabricatorActionView())->setName(pht('Uninstall'))->setIcon('fa-times')->setDisabled(!$can_edit)->setWorkflow(true)->setHref($uninstall_uri)); } else { $action = id(new PhabricatorActionView())->setName(pht('Install'))->setIcon('fa-plus')->setDisabled(!$can_edit)->setWorkflow(true)->setHref($install_uri); $prototypes_enabled = PhabricatorEnv::getEnvConfig('phabricator.show-prototypes'); if ($application->isPrototype() && !$prototypes_enabled) { $action->setDisabled(true); } $curtain->addAction($action); } } else { $curtain->addAction(id(new PhabricatorActionView())->setName(pht('Uninstall'))->setIcon('fa-times')->setWorkflow(true)->setDisabled(true)->setHref($uninstall_uri)); } return $curtain; }
private function buildActionList(PhabricatorProject $project, array $milestones, array $subprojects) { $viewer = $this->getViewer(); $id = $project->getID(); $can_edit = PhabricatorPolicyFilter::hasCapability($viewer, $project, PhabricatorPolicyCapability::CAN_EDIT); $allows_milestones = $project->supportsMilestones(); $allows_subprojects = $project->supportsSubprojects(); $view = id(new PhabricatorActionListView())->setUser($viewer); if ($allows_milestones && $milestones) { $milestone_text = pht('Create Next Milestone'); } else { $milestone_text = pht('Create Milestone'); } $can_milestone = $can_edit && $allows_milestones; $milestone_href = "/project/edit/?milestone={$id}"; $view->addAction(id(new PhabricatorActionView())->setName($milestone_text)->setIcon('fa-plus')->setHref($milestone_href)->setDisabled(!$can_milestone)->setWorkflow(!$can_milestone)); $can_subproject = $can_edit && $allows_subprojects; // If we're offering to create the first subproject, we're going to warn // the user about the effects before moving forward. if ($can_subproject && !$subprojects) { $subproject_href = "/project/warning/{$id}/"; $subproject_disabled = false; $subproject_workflow = true; } else { $subproject_href = "/project/edit/?parent={$id}"; $subproject_disabled = !$can_subproject; $subproject_workflow = !$can_subproject; } $view->addAction(id(new PhabricatorActionView())->setName(pht('Create Subproject'))->setIcon('fa-plus')->setHref($subproject_href)->setDisabled($subproject_disabled)->setWorkflow($subproject_workflow)); return $view; }
public function render() { $conpherence = $this->conpherence; $viewer = $this->getViewer(); $participants = $conpherence->getParticipants(); $count = new PhutilNumber(count($participants)); $handles = $conpherence->getHandles(); $handles = array_intersect_key($handles, $participants); $head_handles = array_select_keys($handles, array($viewer->getPHID())); $handle_list = mpull($handles, 'getName'); natcasesort($handle_list); $handles = mpull($handles, null, 'getName'); $handles = array_select_keys($handles, $handle_list); $head_handles = mpull($head_handles, null, 'getName'); $handles = $head_handles + $handles; $can_edit = PhabricatorPolicyFilter::hasCapability($viewer, $conpherence, PhabricatorPolicyCapability::CAN_EDIT); $body = array(); foreach ($handles as $handle) { $user_phid = $handle->getPHID(); if ($user_phid == $viewer->getPHID() || $can_edit) { $icon = id(new PHUIIconView())->setIcon('fa-times')->addClass('lightbluetext'); $remove_html = javelin_tag('a', array('class' => 'remove', 'sigil' => 'remove-person', 'meta' => array('remove_person' => $user_phid, 'action' => 'remove_person')), $icon); } else { $remove_html = null; } $body[] = phutil_tag('div', array('class' => 'person-entry grouped'), array(phutil_tag('a', array('class' => 'pic', 'href' => $handle->getURI()), phutil_tag('img', array('src' => $handle->getImageURI()), '')), $handle->renderLink(), $remove_html)); } $new_icon = id(new PHUIIconView())->setIcon('fa-plus-square')->setHref($this->updateURI)->setMetadata(array('widget' => null))->addSigil('conpherence-widget-adder'); $header = id(new PHUIHeaderView())->setHeader(pht('Participants (%d)', $count))->addClass('widgets-header')->addActionItem($new_icon); $content = javelin_tag('div', array('class' => 'widgets-body', 'id' => 'widgets-people', 'sigil' => 'widgets-people'), array($header, $body)); return $content; }
private function buildActionView(PhabricatorUser $user, DivinerLiveBook $book) { $can_edit = PhabricatorPolicyFilter::hasCapability($user, $book, PhabricatorPolicyCapability::CAN_EDIT); $action_view = id(new PhabricatorActionListView())->setUser($user)->setObject($book)->setObjectURI($this->getRequest()->getRequestURI()); $action_view->addAction(id(new PhabricatorActionView())->setName(pht('Edit Book'))->setIcon('fa-pencil')->setHref('/book/' . $book->getName() . '/edit/')->setDisabled(!$can_edit)); return $action_view; }
private function renderActions(PhamePost $post, PhabricatorUser $viewer) { $actions = id(new PhabricatorActionListView())->setObject($post)->setObjectURI($this->getRequest()->getRequestURI())->setUser($viewer); $can_edit = PhabricatorPolicyFilter::hasCapability($viewer, $post, PhabricatorPolicyCapability::CAN_EDIT); $id = $post->getID(); $actions->addAction(id(new PhabricatorActionView())->setIcon('fa-pencil')->setHref($this->getApplicationURI('post/edit/' . $id . '/'))->setName(pht('Edit Post'))->setDisabled(!$can_edit)->setWorkflow(!$can_edit)); $actions->addAction(id(new PhabricatorActionView())->setIcon('fa-arrows')->setHref($this->getApplicationURI('post/move/' . $id . '/'))->setName(pht('Move Post'))->setDisabled(!$can_edit)->setWorkflow(!$can_edit)); $actions->addAction(id(new PhabricatorActionView())->setIcon('fa-history')->setHref($this->getApplicationURI('post/history/' . $id . '/'))->setName(pht('View History'))); if ($post->isDraft()) { $actions->addAction(id(new PhabricatorActionView())->setIcon('fa-eye')->setHref($this->getApplicationURI('post/publish/' . $id . '/'))->setDisabled(!$can_edit)->setName(pht('Publish'))->setWorkflow(true)); $actions->addAction(id(new PhabricatorActionView())->setIcon('fa-eye')->setHref($this->getApplicationURI('post/preview/' . $id . '/'))->setDisabled(!$can_edit)->setName(pht('Preview in Skin'))); } else { $actions->addAction(id(new PhabricatorActionView())->setIcon('fa-eye-slash')->setHref($this->getApplicationURI('post/unpublish/' . $id . '/'))->setName(pht('Unpublish'))->setDisabled(!$can_edit)->setWorkflow(true)); } $blog = $post->getBlog(); $can_view_live = $blog && !$post->isDraft(); if ($can_view_live) { $live_uri = $blog->getLiveURI($post); } else { $live_uri = 'post/notlive/' . $post->getID() . '/'; $live_uri = $this->getApplicationURI($live_uri); } $actions->addAction(id(new PhabricatorActionView())->setUser($viewer)->setIcon('fa-globe')->setHref($live_uri)->setName(pht('View Live'))->setDisabled(!$can_view_live)->setWorkflow(!$can_view_live)); return $actions; }
public function hasAutomaticCapability($capability, PhabricatorUser $viewer) { if ($this->isMilestone()) { return $this->getParentProject()->hasAutomaticCapability($capability, $viewer); } $can_edit = PhabricatorPolicyCapability::CAN_EDIT; switch ($capability) { case PhabricatorPolicyCapability::CAN_VIEW: if ($this->isUserMember($viewer->getPHID())) { // Project members can always view a project. return true; } break; case PhabricatorPolicyCapability::CAN_EDIT: $parent = $this->getParentProject(); if ($parent) { $can_edit_parent = PhabricatorPolicyFilter::hasCapability($viewer, $parent, $can_edit); if ($can_edit_parent) { return true; } } break; case PhabricatorPolicyCapability::CAN_JOIN: if (PhabricatorPolicyFilter::hasCapability($viewer, $this, $can_edit)) { // Project editors can always join a project. return true; } break; } return false; }
private function buildActionView(PhabricatorUser $user, PhabricatorApplication $selected) { $view = id(new PhabricatorActionListView())->setUser($user)->setObjectURI($this->getRequest()->getRequestURI()); if ($selected->getHelpURI()) { $view->addAction(id(new PhabricatorActionView())->setName(pht('Help / Documentation'))->setIcon('fa-life-ring')->setHref($selected->getHelpURI())); } $can_edit = PhabricatorPolicyFilter::hasCapability($user, $selected, PhabricatorPolicyCapability::CAN_EDIT); $edit_uri = $this->getApplicationURI('edit/' . get_class($selected) . '/'); $view->addAction(id(new PhabricatorActionView())->setName(pht('Edit Policies'))->setIcon('fa-pencil')->setDisabled(!$can_edit)->setWorkflow(!$can_edit)->setHref($edit_uri)); if ($selected->canUninstall()) { if ($selected->isInstalled()) { $view->addAction(id(new PhabricatorActionView())->setName(pht('Uninstall'))->setIcon('fa-times')->setDisabled(!$can_edit)->setWorkflow(true)->setHref($this->getApplicationURI(get_class($selected) . '/uninstall/'))); } else { $action = id(new PhabricatorActionView())->setName(pht('Install'))->setIcon('fa-plus')->setDisabled(!$can_edit)->setWorkflow(true)->setHref($this->getApplicationURI(get_class($selected) . '/install/')); $beta_enabled = PhabricatorEnv::getEnvConfig('phabricator.show-beta-applications'); if ($selected->isBeta() && !$beta_enabled) { $action->setDisabled(true); } $view->addAction($action); } } else { $view->addAction(id(new PhabricatorActionView())->setName(pht('Uninstall'))->setIcon('fa-times')->setWorkflow(true)->setDisabled(true)->setHref($this->getApplicationURI(get_class($selected) . '/uninstall/'))); } return $view; }
protected function buildManagementPanelActions() { $repository = $this->getRepository(); $viewer = $this->getViewer(); $can_edit = PhabricatorPolicyFilter::hasCapability($viewer, $repository, PhabricatorPolicyCapability::CAN_EDIT); $edit_uri = $this->getEditPageURI(); $activate_uri = $repository->getPathURI('edit/activate/'); $delete_uri = $repository->getPathURI('edit/delete/'); $encoding_uri = $this->getEditPageURI('encoding'); $dangerous_uri = $repository->getPathURI('edit/dangerous/'); if ($repository->isTracked()) { $activate_icon = 'fa-pause'; $activate_label = pht('Deactivate Repository'); } else { $activate_icon = 'fa-play'; $activate_label = pht('Activate Repository'); } $should_dangerous = $repository->shouldAllowDangerousChanges(); if ($should_dangerous) { $dangerous_icon = 'fa-shield'; $dangerous_name = pht('Prevent Dangerous Changes'); $can_dangerous = $can_edit; } else { $dangerous_icon = 'fa-bullseye'; $dangerous_name = pht('Allow Dangerous Changes'); $can_dangerous = $can_edit && $repository->canAllowDangerousChanges(); } return array(id(new PhabricatorActionView())->setIcon('fa-pencil')->setName(pht('Edit Basic Information'))->setHref($edit_uri)->setDisabled(!$can_edit)->setWorkflow(!$can_edit), id(new PhabricatorActionView())->setIcon('fa-text-width')->setName(pht('Edit Text Encoding'))->setHref($encoding_uri)->setDisabled(!$can_edit)->setWorkflow(!$can_edit), id(new PhabricatorActionView())->setIcon($dangerous_icon)->setName($dangerous_name)->setHref($dangerous_uri)->setDisabled(!$can_dangerous)->setWorkflow(true), id(new PhabricatorActionView())->setHref($activate_uri)->setIcon($activate_icon)->setName($activate_label)->setDisabled(!$can_edit)->setWorkflow(true), id(new PhabricatorActionView())->setName(pht('Delete Repository'))->setIcon('fa-times')->setHref($delete_uri)->setDisabled(true)->setWorkflow(true)); }
private function buildActionView(PassphraseCredential $credential, PassphraseCredentialType $type) { $viewer = $this->getRequest()->getUser(); $id = $credential->getID(); $is_locked = $credential->getIsLocked(); if ($is_locked) { $credential_lock_text = pht('Locked Permanently'); $credential_lock_icon = 'fa-lock'; } else { $credential_lock_text = pht('Lock Permanently'); $credential_lock_icon = 'fa-unlock'; } $allow_conduit = $credential->getAllowConduit(); if ($allow_conduit) { $credential_conduit_text = pht('Prevent Conduit Access'); $credential_conduit_icon = 'fa-ban'; } else { $credential_conduit_text = pht('Allow Conduit Access'); $credential_conduit_icon = 'fa-wrench'; } $actions = id(new PhabricatorActionListView())->setObjectURI('/K' . $id)->setObject($credential)->setUser($viewer); $can_edit = PhabricatorPolicyFilter::hasCapability($viewer, $credential, PhabricatorPolicyCapability::CAN_EDIT); $actions->addAction(id(new PhabricatorActionView())->setName(pht('Edit Credential'))->setIcon('fa-pencil')->setHref($this->getApplicationURI("edit/{$id}/"))->setDisabled(!$can_edit)->setWorkflow(!$can_edit)); if (!$credential->getIsDestroyed()) { $actions->addAction(id(new PhabricatorActionView())->setName(pht('Destroy Credential'))->setIcon('fa-times')->setHref($this->getApplicationURI("destroy/{$id}/"))->setDisabled(!$can_edit)->setWorkflow(true)); $actions->addAction(id(new PhabricatorActionView())->setName(pht('Show Secret'))->setIcon('fa-eye')->setHref($this->getApplicationURI("reveal/{$id}/"))->setDisabled(!$can_edit || $is_locked)->setWorkflow(true)); if ($type->hasPublicKey()) { $actions->addAction(id(new PhabricatorActionView())->setName(pht('Show Public Key'))->setIcon('fa-download')->setHref($this->getApplicationURI("public/{$id}/"))->setDisabled(!$can_edit)->setWorkflow(true)); } $actions->addAction(id(new PhabricatorActionView())->setName($credential_conduit_text)->setIcon($credential_conduit_icon)->setHref($this->getApplicationURI("conduit/{$id}/"))->setDisabled(!$can_edit)->setWorkflow(true)); $actions->addAction(id(new PhabricatorActionView())->setName($credential_lock_text)->setIcon($credential_lock_icon)->setHref($this->getApplicationURI("lock/{$id}/"))->setDisabled(!$can_edit || $is_locked)->setWorkflow(true)); } return $actions; }
public function buildQueryFromSavedQuery(PhabricatorSavedQuery $saved) { $query = id(new PhortuneSubscriptionQuery()); $viewer = $this->requireViewer(); $merchant = $this->getMerchant(); $account = $this->getAccount(); if ($merchant) { $can_edit = PhabricatorPolicyFilter::hasCapability($viewer, $merchant, PhabricatorPolicyCapability::CAN_EDIT); if (!$can_edit) { throw new Exception(pht('You can not query subscriptions for a merchant you do not ' . 'control.')); } $query->withMerchantPHIDs(array($merchant->getPHID())); } else { if ($account) { $can_edit = PhabricatorPolicyFilter::hasCapability($viewer, $account, PhabricatorPolicyCapability::CAN_EDIT); if (!$can_edit) { throw new Exception(pht('You can not query subscriptions for an account you are not ' . 'a member of.')); } $query->withAccountPHIDs(array($account->getPHID())); } else { $accounts = id(new PhortuneAccountQuery())->withMemberPHIDs(array($viewer->getPHID()))->execute(); if ($accounts) { $query->withAccountPHIDs(mpull($accounts, 'getPHID')); } else { throw new Exception(pht('You have no accounts!')); } } } return $query; }
/** * Load the namespace which prevents use of an Almanac name, if one exists. */ public static function loadRestrictedNamespace(PhabricatorUser $viewer, $name) { // For a name like "x.y.z", produce a list of controlling namespaces like // ("z", "y.x", "x.y.z"). $names = array(); $parts = explode('.', $name); for ($ii = 0; $ii < count($parts); $ii++) { $names[] = implode('.', array_slice($parts, -($ii + 1))); } // Load all the possible controlling namespaces. $namespaces = id(new AlmanacNamespaceQuery())->setViewer(PhabricatorUser::getOmnipotentUser())->withNames($names)->execute(); if (!$namespaces) { return null; } // Find the "nearest" (longest) namespace that exists. If both // "sub.domain.com" and "domain.com" exist, we only care about the policy // on the former. $namespaces = msort($namespaces, 'getNameLength'); $namespace = last($namespaces); $can_edit = PhabricatorPolicyFilter::hasCapability($viewer, $namespace, PhabricatorPolicyCapability::CAN_EDIT); if ($can_edit) { return null; } return $namespace; }
private function buildPaymentMethodsSection(PhortuneAccount $account) { $request = $this->getRequest(); $viewer = $request->getUser(); $can_edit = PhabricatorPolicyFilter::hasCapability($viewer, $account, PhabricatorPolicyCapability::CAN_EDIT); $id = $account->getID(); $header = id(new PHUIHeaderView())->setHeader(pht('Payment Methods')); $list = id(new PHUIObjectItemListView())->setUser($viewer)->setFlush(true)->setNoDataString(pht('No payment methods associated with this account.')); $methods = id(new PhortunePaymentMethodQuery())->setViewer($viewer)->withAccountPHIDs(array($account->getPHID()))->execute(); foreach ($methods as $method) { $id = $method->getID(); $item = new PHUIObjectItemView(); $item->setHeader($method->getFullDisplayName()); switch ($method->getStatus()) { case PhortunePaymentMethod::STATUS_ACTIVE: $item->setStatusIcon('fa-check green'); $disable_uri = $this->getApplicationURI('card/' . $id . '/disable/'); $item->addAction(id(new PHUIListItemView())->setIcon('fa-times')->setHref($disable_uri)->setDisabled(!$can_edit)->setWorkflow(true)); break; case PhortunePaymentMethod::STATUS_DISABLED: $item->setStatusIcon('fa-ban lightbluetext'); $item->setDisabled(true); break; } $provider = $method->buildPaymentProvider(); $item->addAttribute($provider->getPaymentMethodProviderDescription()); $edit_uri = $this->getApplicationURI('card/' . $id . '/edit/'); $item->addAction(id(new PHUIListItemView())->setIcon('fa-pencil')->setHref($edit_uri)->setDisabled(!$can_edit)->setWorkflow(!$can_edit)); $list->addItem($item); } return id(new PHUIObjectBoxView())->setHeader($header)->setObjectList($list); }
private function renderFormContent() { $conpherence = $this->getConpherence(); $user = $this->getRequest()->getUser(); $can_join = PhabricatorPolicyFilter::hasCapability($user, $conpherence, PhabricatorPolicyCapability::CAN_JOIN); $participating = $conpherence->getParticipantIfExists($user->getPHID()); if (!$can_join && !$participating && $user->isLoggedIn()) { return null; } $draft = PhabricatorDraft::newFromUserAndKey($user, $conpherence->getPHID()); if ($participating) { $action = ConpherenceUpdateActions::MESSAGE; $button_text = pht('Send'); } else { if ($user->isLoggedIn()) { $action = ConpherenceUpdateActions::JOIN_ROOM; $button_text = pht('Join Room'); } else { // user not logged in so give them a login button. $login_href = id(new PhutilURI('/auth/start/'))->setQueryParam('next', '/' . $conpherence->getMonogram()); return id(new PHUIFormLayoutView())->addClass('login-to-participate')->appendChild(id(new PHUIButtonView())->setTag('a')->setText(pht('Login to Participate'))->setHref((string) $login_href)); } } $update_uri = $this->getApplicationURI('update/' . $conpherence->getID() . '/'); $this->initBehavior('conpherence-pontificate'); $form = id(new AphrontFormView())->setUser($user)->setAction($update_uri)->addSigil('conpherence-pontificate')->setWorkflow(true)->addHiddenInput('action', $action)->appendChild(id(new PhabricatorRemarkupControl())->setUser($user)->setName('text')->setValue($draft->getDraft()))->appendChild(id(new AphrontFormSubmitControl())->setValue($button_text))->render(); return $form; }
private function buildActionList(PhabricatorUser $user) { $viewer = $this->getViewer(); $actions = id(new PhabricatorActionListView())->setUser($viewer); $can_edit = PhabricatorPolicyFilter::hasCapability($viewer, $user, PhabricatorPolicyCapability::CAN_EDIT); $actions->addAction(id(new PhabricatorActionView())->setIcon('fa-pencil')->setName(pht('Edit Profile'))->setHref($this->getApplicationURI('editprofile/' . $user->getID() . '/'))->setDisabled(!$can_edit)->setWorkflow(!$can_edit)); $actions->addAction(id(new PhabricatorActionView())->setIcon('fa-picture-o')->setName(pht('Edit Profile Picture'))->setHref($this->getApplicationURI('picture/' . $user->getID() . '/'))->setDisabled(!$can_edit)->setWorkflow(!$can_edit)); $actions->addAction(id(new PhabricatorActionView())->setIcon('fa-wrench')->setName(pht('Edit Settings'))->setDisabled(!$can_edit)->setWorkflow(!$can_edit)->setHref('/settings/' . $user->getID() . '/')); if ($user->getIsAdmin()) { $empower_icon = 'fa-arrow-circle-o-down'; $empower_name = pht('Remove Administrator'); } else { $empower_icon = 'fa-arrow-circle-o-up'; $empower_name = pht('Make Administrator'); } $is_admin = $viewer->getIsAdmin(); $is_self = $user->getPHID() === $viewer->getPHID(); $can_admin = $is_admin && !$is_self; $actions->addAction(id(new PhabricatorActionView())->setIcon($empower_icon)->setName($empower_name)->setDisabled(!$can_admin)->setWorkflow(true)->setHref($this->getApplicationURI('empower/' . $user->getID() . '/'))); $actions->addAction(id(new PhabricatorActionView())->setIcon('fa-tag')->setName(pht('Change Username'))->setDisabled(!$is_admin)->setWorkflow(true)->setHref($this->getApplicationURI('rename/' . $user->getID() . '/'))); if ($user->getIsDisabled()) { $disable_icon = 'fa-check-circle-o'; $disable_name = pht('Enable User'); } else { $disable_icon = 'fa-ban'; $disable_name = pht('Disable User'); } $actions->addAction(id(new PhabricatorActionView())->setIcon($disable_icon)->setName($disable_name)->setDisabled(!$can_admin)->setWorkflow(true)->setHref($this->getApplicationURI('disable/' . $user->getID() . '/'))); $actions->addAction(id(new PhabricatorActionView())->setIcon('fa-times')->setName(pht('Delete User'))->setDisabled(!$can_admin)->setWorkflow(true)->setHref($this->getApplicationURI('delete/' . $user->getID() . '/'))); $can_welcome = $is_admin && $user->canEstablishWebSessions(); $actions->addAction(id(new PhabricatorActionView())->setIcon('fa-envelope')->setName(pht('Send Welcome Email'))->setWorkflow(true)->setDisabled(!$can_welcome)->setHref($this->getApplicationURI('welcome/' . $user->getID() . '/'))); return $actions; }
private function buildPaymentMethodsSection(PhortuneAccount $account) { $request = $this->getRequest(); $viewer = $request->getUser(); $can_edit = PhabricatorPolicyFilter::hasCapability($viewer, $account, PhabricatorPolicyCapability::CAN_EDIT); $id = $account->getID(); $header = id(new PHUIHeaderView())->setHeader(pht('Payment Methods'))->addActionLink(id(new PHUIButtonView())->setTag('a')->setHref($this->getApplicationURI($id . '/card/new/'))->setText(pht('Add Payment Method'))->setIcon(id(new PHUIIconView())->setIconFont('fa-plus'))); $list = id(new PHUIObjectItemListView())->setUser($viewer)->setNoDataString(pht('No payment methods associated with this account.')); $methods = id(new PhortunePaymentMethodQuery())->setViewer($viewer)->withAccountPHIDs(array($account->getPHID()))->execute(); if ($methods) { $this->loadHandles(mpull($methods, 'getAuthorPHID')); } foreach ($methods as $method) { $id = $method->getID(); $item = new PHUIObjectItemView(); $item->setHeader($method->getFullDisplayName()); switch ($method->getStatus()) { case PhortunePaymentMethod::STATUS_ACTIVE: $item->setBarColor('green'); $disable_uri = $this->getApplicationURI('card/' . $id . '/disable/'); $item->addAction(id(new PHUIListItemView())->setIcon('fa-times')->setHref($disable_uri)->setDisabled(!$can_edit)->setWorkflow(true)); break; case PhortunePaymentMethod::STATUS_DISABLED: $item->setDisabled(true); break; } $provider = $method->buildPaymentProvider(); $item->addAttribute($provider->getPaymentMethodProviderDescription()); $item->setImageURI($provider->getPaymentMethodIcon()); $edit_uri = $this->getApplicationURI('card/' . $id . '/edit/'); $item->addAction(id(new PHUIListItemView())->setIcon('fa-pencil')->setHref($edit_uri)->setDisabled(!$can_edit)->setWorkflow(!$can_edit)); $list->addItem($item); } return id(new PHUIObjectBoxView())->setHeader($header)->appendChild($list); }
private function attemptLand($revision, $request) { $status = $revision->getStatus(); if ($status != ArcanistDifferentialRevisionStatus::ACCEPTED) { throw new Exception(pht('Only Accepted revisions can be landed.')); } $repository = $revision->getRepository(); if ($repository === null) { throw new Exception(pht('Revision is not attached to a repository.')); } $can_push = PhabricatorPolicyFilter::hasCapability($request->getUser(), $repository, DiffusionPushCapability::CAPABILITY); if (!$can_push) { throw new Exception(pht('You do not have permission to push to this repository.')); } $lock = $this->lockRepository($repository); try { $response = $this->pushStrategy->processLandRequest($request, $revision, $repository); } catch (Exception $e) { $lock->unlock(); throw $e; } $lock->unlock(); $looksoon = new ConduitCall('diffusion.looksoon', array('callsigns' => array($repository->getCallsign()))); $looksoon->setUser($request->getUser()); $looksoon->execute(); return $response; }
public function render() { $conpherence = $this->getConpherence(); $widget_data = $conpherence->getWidgetData(); $viewer = $this->getUser(); $participants = $conpherence->getParticipants(); $handles = $conpherence->getHandles(); $head_handles = array_select_keys($handles, array($viewer->getPHID())); $handle_list = mpull($handles, 'getName'); natcasesort($handle_list); $handles = mpull($handles, null, 'getName'); $handles = array_select_keys($handles, $handle_list); $head_handles = mpull($head_handles, null, 'getName'); $handles = $head_handles + $handles; $can_edit = PhabricatorPolicyFilter::hasCapability($viewer, $conpherence, PhabricatorPolicyCapability::CAN_EDIT); $body = array(); foreach ($handles as $handle) { $user_phid = $handle->getPHID(); if ($user_phid == $viewer->getPHID() || $can_edit) { $icon = id(new PHUIIconView())->setIcon('fa-times lightbluetext'); $remove_html = javelin_tag('a', array('class' => 'remove', 'sigil' => 'remove-person', 'meta' => array('remove_person' => $user_phid, 'action' => 'remove_person')), $icon); } else { $remove_html = null; } $body[] = phutil_tag('div', array('class' => 'person-entry grouped'), array(phutil_tag('a', array('class' => 'pic', 'href' => $handle->getURI()), phutil_tag('img', array('src' => $handle->getImageURI()), '')), $handle->renderLink(), $remove_html)); } return $body; }
private function buildActionListView(PhabricatorProject $project) { $request = $this->getRequest(); $viewer = $request->getUser(); $id = $project->getID(); $view = id(new PhabricatorActionListView())->setUser($viewer)->setObject($project)->setObjectURI($request->getRequestURI()); $can_edit = PhabricatorPolicyFilter::hasCapability($viewer, $project, PhabricatorPolicyCapability::CAN_EDIT); $view->addAction(id(new PhabricatorActionView())->setName(pht('Edit Details'))->setIcon('fa-pencil')->setHref($this->getApplicationURI("details/{$id}/"))->setDisabled(!$can_edit)); $view->addAction(id(new PhabricatorActionView())->setName(pht('Edit Picture'))->setIcon('fa-picture-o')->setHref($this->getApplicationURI("picture/{$id}/"))->setDisabled(!$can_edit)->setWorkflow(!$can_edit)); if ($project->isArchived()) { $view->addAction(id(new PhabricatorActionView())->setName(pht('Activate Project'))->setIcon('fa-check')->setHref($this->getApplicationURI("archive/{$id}/"))->setDisabled(!$can_edit)->setWorkflow(true)); } else { $view->addAction(id(new PhabricatorActionView())->setName(pht('Archive Project'))->setIcon('fa-ban')->setHref($this->getApplicationURI("archive/{$id}/"))->setDisabled(!$can_edit)->setWorkflow(true)); } $action = null; if (!$project->isUserMember($viewer->getPHID())) { $can_join = PhabricatorPolicyFilter::hasCapability($viewer, $project, PhabricatorPolicyCapability::CAN_JOIN); $action = id(new PhabricatorActionView())->setUser($viewer)->setRenderAsForm(true)->setHref('/project/update/' . $project->getID() . '/join/')->setIcon('fa-plus')->setDisabled(!$can_join)->setName(pht('Join Project')); $view->addAction($action); } else { $action = id(new PhabricatorActionView())->setWorkflow(true)->setHref('/project/update/' . $project->getID() . '/leave/')->setIcon('fa-times')->setName(pht('Leave Project...')); $view->addAction($action); if (!$project->isUserWatcher($viewer->getPHID())) { $action = id(new PhabricatorActionView())->setWorkflow(true)->setHref('/project/watch/' . $project->getID() . '/')->setIcon('fa-eye')->setName(pht('Watch Project')); $view->addAction($action); } else { $action = id(new PhabricatorActionView())->setWorkflow(true)->setHref('/project/unwatch/' . $project->getID() . '/')->setIcon('fa-eye-slash')->setName(pht('Unwatch Project')); $view->addAction($action); } } return $view; }
protected function buildLocalNavigation(PhabricatorProject $project) { $id = $project->getID(); $nav_view = new AphrontSideNavFilterView(); $uri = new PhutilURI('/project/view/' . $id . '/'); $nav_view->setBaseURI($uri); $external_arrow = "↗"; $tasks_uri = '/maniphest/view/all/?projects=' . $project->getPHID(); $slug = PhabricatorSlug::normalize($project->getName()); $phriction_uri = '/w/projects/' . $slug; $edit_uri = '/project/edit/' . $id . '/'; $members_uri = '/project/members/' . $id . '/'; $nav_view->addFilter('dashboard', 'Dashboard'); $nav_view->addSpacer(); $nav_view->addFilter('feed', 'Feed'); $nav_view->addFilter(null, 'Tasks ' . $external_arrow, $tasks_uri); $nav_view->addFilter(null, 'Wiki ' . $external_arrow, $phriction_uri); $nav_view->addFilter('people', 'People'); $nav_view->addFilter('about', 'About'); $user = $this->getRequest()->getUser(); $can_edit = PhabricatorPolicyCapability::CAN_EDIT; $nav_view->addSpacer(); if (PhabricatorPolicyFilter::hasCapability($user, $project, $can_edit)) { $nav_view->addFilter('edit', "Edit Project…", $edit_uri); $nav_view->addFilter('members', "Edit Members…", $members_uri); } else { $nav_view->addFilter('edit', "Edit Project…", $edit_uri, $relative = false, 'disabled'); $nav_view->addFilter('members', "Edit Members…", $members_uri, $relative = false, 'disabled'); } return $nav_view; }