private function getPasswordHashInput(PhutilOpaqueEnvelope $password, PhabricatorUser $user) { if ($user->getPHID() != $this->getUserPHID()) { throw new Exception(pht('User does not match password user PHID!')); } $raw_input = PhabricatorHash::digestPassword($password, $user->getPHID()); return new PhutilOpaqueEnvelope($raw_input); }
private function generateTestFile(PhabricatorUser $actor) { $engine = new PhabricatorTestStorageEngine(); $data = Filesystem::readRandomCharacters(64); $params = array('name' => 'test.' . $actor->getPHID(), 'viewPolicy' => $actor->getPHID(), 'authorPHID' => $actor->getPHID(), 'storageEngines' => array($engine)); $file = PhabricatorFile::newFromFileData($data, $params); $file->save(); return $file; }
public static function loadDraftAndPublishedComments(PhabricatorUser $viewer, $commit_phid, $path_id = null) { if ($path_id === null) { $inlines = id(new PhabricatorAuditTransactionComment())->loadAllWhere('commitPHID = %s AND (transactionPHID IS NOT NULL OR authorPHID = %s) AND pathID IS NOT NULL', $commit_phid, $viewer->getPHID()); } else { $inlines = id(new PhabricatorAuditTransactionComment())->loadAllWhere('commitPHID = %s AND pathID = %d AND (authorPHID = %s OR transactionPHID IS NOT NULL)', $commit_phid, $path_id, $viewer->getPHID()); } return self::buildProxies($inlines); }
public function loadStatus(PhabricatorUser $user) { $revisions = id(new DifferentialRevisionQuery())->withResponsibleUsers(array($user->getPHID()))->withStatus(DifferentialRevisionQuery::STATUS_OPEN)->execute(); list($active, $waiting) = DifferentialRevisionQuery::splitResponsible($revisions, $user->getPHID()); $status = array(); $active = count($active); $type = $active ? PhabricatorApplicationStatusView::TYPE_NEEDS_ATTENTION : PhabricatorApplicationStatusView::TYPE_EMPTY; $status[] = id(new PhabricatorApplicationStatusView())->setType($type)->setText(pht('%d Review(s) Need Attention', $active))->setCount($active); $waiting = count($waiting); $type = $waiting ? PhabricatorApplicationStatusView::TYPE_INFO : PhabricatorApplicationStatusView::TYPE_EMPTY; $status[] = id(new PhabricatorApplicationStatusView())->setType($type)->setText(pht('%d Review(s) Waiting on Others', $waiting)); return $status; }
public static function newFromUserAndKey(PhabricatorUser $user, $key) { if ($user->getPHID() && strlen($key)) { $draft = id(new PhabricatorDraft())->loadOneWhere('authorPHID = %s AND draftKey = %s', $user->getPHID(), $key); if ($draft) { return $draft; } } $draft = new PhabricatorDraft(); if ($user->getPHID()) { $draft->setAuthorPHID($user->getPHID())->setDraftKey($key); } return $draft; }
protected function createUserAccount(PhabricatorUser $user) { $request = $this->getRequest(); $xactions = array(); $xactions[] = id(new PhortuneAccountTransaction())->setTransactionType(PhortuneAccountTransaction::TYPE_NAME)->setNewValue(pht('Account (%s)', $user->getUserName())); $xactions[] = id(new PhortuneAccountTransaction())->setTransactionType(PhabricatorTransactions::TYPE_EDGE)->setMetadataValue('edge:type', PhabricatorEdgeConfig::TYPE_ACCOUNT_HAS_MEMBER)->setNewValue(array('=' => array($user->getPHID() => $user->getPHID()))); $account = id(new PhortuneAccount())->attachMemberPHIDs(array()); $editor = id(new PhortuneAccountEditor())->setActor($user)->setContentSourceFromRequest($request); // We create an account for you the first time you visit Phortune. $unguarded = AphrontWriteGuard::beginScopedUnguardedWrites(); $editor->applyTransactions($account, $xactions); unset($unguarded); return $account; }
public static function indexUser(PhabricatorUser $user) { $doc = new PhabricatorSearchAbstractDocument(); $doc->setPHID($user->getPHID()); $doc->setDocumentType(PhabricatorPHIDConstants::PHID_TYPE_USER); $doc->setDocumentTitle($user->getUserName() . ' (' . $user->getRealName() . ')'); $doc->setDocumentCreated($user->getDateCreated()); $doc->setDocumentModified($user->getDateModified()); // TODO: Index the blurbs from their profile or something? Probably not // actually useful... if (!$user->getIsDisabled()) { $doc->addRelationship(PhabricatorSearchRelationship::RELATIONSHIP_OPEN, $user->getPHID(), PhabricatorPHIDConstants::PHID_TYPE_USER, time()); } self::reindexAbstractDocument($doc); }
public function hasAutomaticCapability($capability, PhabricatorUser $viewer) { if (!$viewer->getPHID()) { return false; } $object = $this->getIdentityObject(); if ($object instanceof PhabricatorUser) { return $object->getPHID() == $viewer->getPHID(); } else { if ($object instanceof PhabricatorExternalAccount) { return $object->getUserPHID() == $viewer->getPHID(); } } return false; }
public function hasAutomaticCapability($capability, PhabricatorUser $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; }
public static function createConpherence(PhabricatorUser $creator, array $participant_phids, $title, $message, PhabricatorContentSource $source) { $conpherence = id(new ConpherenceThread())->attachParticipants(array())->attachFilePHIDs(array())->setMessageCount(0); $files = array(); $errors = array(); if (empty($participant_phids)) { $errors[] = self::ERROR_EMPTY_PARTICIPANTS; } else { $participant_phids[] = $creator->getPHID(); $participant_phids = array_unique($participant_phids); $conpherence->setRecentParticipantPHIDs(array_slice($participant_phids, 0, 10)); } if (empty($message)) { $errors[] = self::ERROR_EMPTY_MESSAGE; } $file_phids = PhabricatorMarkupEngine::extractFilePHIDsFromEmbeddedFiles($creator, array($message)); if ($file_phids) { $files = id(new PhabricatorFileQuery())->setViewer($creator)->withPHIDs($file_phids)->execute(); } if (!$errors) { $xactions = array(); $xactions[] = id(new ConpherenceTransaction())->setTransactionType(ConpherenceTransactionType::TYPE_PARTICIPANTS)->setNewValue(array('+' => $participant_phids)); if ($files) { $xactions[] = id(new ConpherenceTransaction())->setTransactionType(ConpherenceTransactionType::TYPE_FILES)->setNewValue(array('+' => mpull($files, 'getPHID'))); } if ($title) { $xactions[] = id(new ConpherenceTransaction())->setTransactionType(ConpherenceTransactionType::TYPE_TITLE)->setNewValue($title); } $xactions[] = id(new ConpherenceTransaction())->setTransactionType(PhabricatorTransactions::TYPE_COMMENT)->attachComment(id(new ConpherenceTransactionComment())->setContent($message)->setConpherencePHID($conpherence->getPHID())); id(new ConpherenceEditor())->setContentSource($source)->setContinueOnNoEffect(true)->setActor($creator)->applyTransactions($conpherence, $xactions); } return array($errors, $conpherence); }
public static function applyLeaveProject(PhabricatorProject $project, PhabricatorUser $user) { $members = array_fill_keys($project->getMemberPHIDs(), true); unset($members[$user->getPHID()]); $members = array_keys($members); self::applyOneTransaction($project, $user, PhabricatorProjectTransactionType::TYPE_MEMBERS, $members); }
public function buildIconNavView(PhabricatorUser $user) { $viewer = $this->getViewer(); $picture = $user->getProfileImageURI(); $name = $user->getUsername(); $nav = new AphrontSideNavFilterView(); $nav->setIconNav(true); $nav->setBaseURI(new PhutilURI('/p/')); $nav->addIcon("{$name}/", $name, null, $picture); $class = 'PhabricatorCalendarApplication'; if (PhabricatorApplication::isClassInstalledForViewer($class, $viewer)) { $nav->addIcon("{$name}/calendar/", pht('Calendar'), 'fa-calendar'); } $class = 'PhabricatorManiphestApplication'; if (PhabricatorApplication::isClassInstalledForViewer($class, $viewer)) { $phid = $user->getPHID(); $view_uri = sprintf('/maniphest/?statuses=open()&assigned=%s#R', $phid); $nav->addIcon('maniphest', pht('Open Tasks'), 'fa-anchor', null, $view_uri); } $class = 'PhabricatorDifferentialApplication'; if (PhabricatorApplication::isClassInstalledForViewer($class, $viewer)) { $username = phutil_escape_uri($name); $view_uri = '/differential/?authors=' . $username; $nav->addIcon('differential', pht('Revisions'), 'fa-cog', null, $view_uri); } $class = 'PhabricatorAuditApplication'; if (PhabricatorApplication::isClassInstalledForViewer($class, $viewer)) { $username = phutil_escape_uri($name); $view_uri = '/audit/?authors=' . $username; $nav->addIcon('audit', pht('Commits'), 'fa-code', null, $view_uri); } return $nav; }
protected function buildUserInformationDictionary(PhabricatorUser $user, PhabricatorUserStatus $current_status = null) { $roles = array(); if ($user->getIsDisabled()) { $roles[] = 'disabled'; } if ($user->getIsSystemAgent()) { $roles[] = 'agent'; } if ($user->getIsAdmin()) { $roles[] = 'admin'; } $primary = $user->loadPrimaryEmail(); if ($primary && $primary->getIsVerified()) { $roles[] = 'verified'; } else { $roles[] = 'unverified'; } $return = array('phid' => $user->getPHID(), 'userName' => $user->getUserName(), 'realName' => $user->getRealName(), 'image' => $user->loadProfileImageURI(), 'uri' => PhabricatorEnv::getURI('/p/' . $user->getUsername() . '/'), 'roles' => $roles); if ($current_status) { $return['currentStatus'] = $current_status->getTextStatus(); $return['currentStatusUntil'] = $current_status->getDateTo(); } return $return; }
public static function loadNeedAttentionRevisions(PhabricatorUser $viewer) { if (!$viewer->isLoggedIn()) { return array(); } $viewer_phid = $viewer->getPHID(); $responsible_phids = id(new DifferentialResponsibleDatasource())->setViewer($viewer)->evaluateTokens(array($viewer_phid)); $revision_query = id(new DifferentialRevisionQuery())->setViewer($viewer)->withStatus(DifferentialRevisionQuery::STATUS_OPEN)->withResponsibleUsers($responsible_phids)->needReviewerStatus(true)->needRelationships(true)->needFlags(true)->needDrafts(true)->setLimit(self::MAX_STATUS_ITEMS); $revisions = $revision_query->execute(); $query = id(new PhabricatorSavedQuery())->attachParameterMap(array('responsiblePHIDs' => $responsible_phids)); $groups = id(new DifferentialRevisionRequiredActionResultBucket())->setViewer($viewer)->newResultGroups($query, $revisions); $include = array(); foreach ($groups as $group) { switch ($group->getKey()) { case DifferentialRevisionRequiredActionResultBucket::KEY_MUSTREVIEW: case DifferentialRevisionRequiredActionResultBucket::KEY_SHOULDREVIEW: foreach ($group->getObjects() as $object) { $include[] = $object; } break; default: break; } } return $include; }
public function hasAutomaticCapability($capability, PhabricatorUser $viewer) { if ($viewer->getPHID() == $this->userPHID) { return true; } return false; }
/** * Compute a chunked file hash for the viewer. * * We can not currently compute a real hash for chunked file uploads (because * no process sees all of the file data). * * We also can not trust the hash that the user claims to have computed. If * we trust the user, they can upload some `evil.exe` and claim it has the * same file hash as `good.exe`. When another user later uploads the real * `good.exe`, we'll just create a reference to the existing `evil.exe`. Users * who download `good.exe` will then receive `evil.exe`. * * Instead, we rehash the user's claimed hash with account secrets. This * allows users to resume file uploads, but not collide with other users. * * Ideally, we'd like to be able to verify hashes, but this is complicated * and time consuming and gives us a fairly small benefit. * * @param PhabricatorUser Viewing user. * @param string Claimed file hash. * @return string Rehashed file hash. */ public static function getChunkedHash(PhabricatorUser $viewer, $hash) { if (!$viewer->getPHID()) { throw new Exception(pht('Unable to compute chunked hash without real viewer!')); } $input = $viewer->getAccountSecret() . ':' . $hash . ':' . $viewer->getPHID(); return self::getChunkedHashForInput($input); }
public function hasAutomaticCapability($capability, PhabricatorUser $viewer) { if ($this->viewerHasVerificationCode) { return true; } if ($viewer->getPHID()) { if ($viewer->getPHID() == $this->getAuthorPHID()) { // You can see invites you sent. return true; } if ($viewer->getPHID() == $this->getAcceptedByPHID()) { // You can see invites you have accepted. return true; } } return false; }
public static function initializeNewMessage(PhabricatorUser $actor) { $actor_phid = $actor->getPHID(); if (!$actor_phid) { $actor_phid = id(new PhabricatorHarbormasterApplication())->getPHID(); } return id(new HarbormasterBuildMessage())->setAuthorPHID($actor_phid)->setIsConsumed(0); }
public function applyRule(PhabricatorUser $viewer, $value, PhabricatorPolicyInterface $object) { $viewer_phid = $viewer->getPHID(); if (!$viewer_phid) { return false; } return $object->getHostPHID() == $viewer_phid; }
public function applyRule(PhabricatorUser $viewer, $value, PhabricatorPolicyInterface $object) { $viewer_phid = $viewer->getPHID(); if (!$viewer_phid) { return false; } return (bool) $object->getParticipantIfExists($viewer_phid); }
public static function initializeNewProject(PhabricatorUser $actor) { $app = id(new PhabricatorApplicationQuery())->setViewer(PhabricatorUser::getOmnipotentUser())->withClasses(array('PhabricatorProjectApplication'))->executeOne(); $view_policy = $app->getPolicy(ProjectDefaultViewCapability::CAPABILITY); $edit_policy = $app->getPolicy(ProjectDefaultEditCapability::CAPABILITY); $join_policy = $app->getPolicy(ProjectDefaultJoinCapability::CAPABILITY); return id(new PhabricatorProject())->setAuthorPHID($actor->getPHID())->setIcon(self::DEFAULT_ICON)->setColor(self::DEFAULT_COLOR)->setViewPolicy($view_policy)->setEditPolicy($edit_policy)->setJoinPolicy($join_policy)->setIsMembershipLocked(0)->attachMemberPHIDs(array())->attachSlugs(array())->setHasWorkboard(0)->setHasMilestones(0)->setHasSubprojects(0)->attachParentProject(null); }
public function countUnread(PhabricatorUser $user) { $conn = $this->establishConnection('r'); $data = queryfx_one($conn, 'SELECT COUNT(*) as count FROM %T WHERE userPHID = %s AND hasViewed = 0', $this->getTableName(), $user->getPHID()); return $data['count']; }
public function hasAutomaticCapability($capability, PhabricatorUser $viewer) { $members = array_fuse($this->getMemberPHIDs()); if (isset($members[$viewer->getPHID()])) { return true; } return false; }
public function hasAutomaticCapability($capability, PhabricatorUser $viewer) { switch ($capability) { case PhabricatorPolicyCapability::CAN_EDIT: return $viewer->getPHID() == $this->getCreatorPHID(); } return false; }
public function applyRule(PhabricatorUser $viewer, $value, PhabricatorPolicyInterface $object) { foreach ($value as $phid) { if ($phid == $viewer->getPHID()) { return true; } } return false; }
public function applyRule(PhabricatorUser $viewer, $value, PhabricatorPolicyInterface $object) { foreach ($value as $project_phid) { if (isset($this->memberships[$viewer->getPHID()][$project_phid])) { return true; } } return false; }
public static function updateObjectNotificationViews(PhabricatorUser $user, $object_phid) { if (PhabricatorEnv::isReadOnly()) { return; } $unguarded = AphrontWriteGuard::beginScopedUnguardedWrites(); $notification_table = new PhabricatorFeedStoryNotification(); $conn = $notification_table->establishConnection('w'); queryfx($conn, 'UPDATE %T SET hasViewed = 1 WHERE userPHID = %s AND primaryObjectPHID = %s AND hasViewed = 0', $notification_table->getTableName(), $user->getPHID(), $object_phid); unset($unguarded); $count_key = PhabricatorUserNotificationCountCacheType::KEY_COUNT; PhabricatorUserCache::clearCache($count_key, $user->getPHID()); $user->clearCacheData($count_key); }
public function startTracking(PhabricatorUser $user, $phid, $timestamp) { $usertime = new PhrequentUserTime(); $usertime->setDateStarted($timestamp); $usertime->setUserPHID($user->getPHID()); $usertime->setObjectPHID($phid); $usertime->save(); return $phid; }
public function loadStatus(PhabricatorUser $user) { $status = array(); $flags = id(new PhabricatorFlagQuery())->withOwnerPHIDs(array($user->getPHID()))->execute(); $count = count($flags); $type = $count ? PhabricatorApplicationStatusView::TYPE_INFO : PhabricatorApplicationStatusView::TYPE_EMPTY; $status[] = id(new PhabricatorApplicationStatusView())->setType($type)->setText(pht('%d Flagged Object(s)', $count))->setCount($count); return $status; }
public function applyRule(PhabricatorUser $viewer, $value, PhabricatorPolicyInterface $object) { $viewer_phid = $viewer->getPHID(); if (!$viewer_phid) { return false; } $memberships = idx($this->memberships, $viewer_phid); return isset($memberships[$object->getPHID()]); }