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 function getQuickCreateItems(PhabricatorUser $viewer)
 {
     $items = array();
     if ($viewer->getIsAdmin()) {
         $item = id(new PHUIListItemView())->setName(pht('User Account'))->setIcon('fa-users')->setHref($this->getBaseURI() . 'create/');
         $items[] = $item;
     }
     return $items;
 }
 public function processRequest()
 {
     $request = $this->getRequest();
     $viewer = $request->getUser();
     $is_admin = $viewer->getIsAdmin();
     $user = new PhabricatorUser();
     $count = queryfx_one($user->establishConnection('r'), 'SELECT COUNT(*) N FROM %T', $user->getTableName());
     $count = idx($count, 'N', 0);
     $pager = new AphrontPagerView();
     $pager->setOffset($request->getInt('page', 0));
     $pager->setCount($count);
     $pager->setURI($request->getRequestURI(), 'page');
     $users = id(new PhabricatorPeopleQuery())->needPrimaryEmail(true)->executeWithOffsetPager($pager);
     $rows = array();
     foreach ($users as $user) {
         $primary_email = $user->loadPrimaryEmail();
         if ($primary_email && $primary_email->getIsVerified()) {
             $email = 'Verified';
         } else {
             $email = 'Unverified';
         }
         $status = array();
         if ($user->getIsDisabled()) {
             $status[] = 'Disabled';
         }
         if ($user->getIsAdmin()) {
             $status[] = 'Admin';
         }
         if ($user->getIsSystemAgent()) {
             $status[] = 'System Agent';
         }
         $status = implode(', ', $status);
         $rows[] = array(phabricator_date($user->getDateCreated(), $viewer), phabricator_time($user->getDateCreated(), $viewer), phutil_render_tag('a', array('href' => '/p/' . $user->getUsername() . '/'), phutil_escape_html($user->getUserName())), phutil_escape_html($user->getRealName()), $status, $email, phutil_render_tag('a', array('class' => 'button grey small', 'href' => '/people/edit/' . $user->getID() . '/'), 'Administrate User'));
     }
     $table = new AphrontTableView($rows);
     $table->setHeaders(array('Join Date', 'Time', 'Username', 'Real Name', 'Roles', 'Email', ''));
     $table->setColumnClasses(array(null, 'right', 'pri', 'wide', null, null, 'action'));
     $table->setColumnVisibility(array(true, true, true, true, $is_admin, $is_admin, $is_admin));
     $panel = new AphrontPanelView();
     $panel->setHeader('People (' . number_format($count) . ')');
     $panel->appendChild($table);
     $panel->appendChild($pager);
     if ($is_admin) {
         $panel->addButton(phutil_render_tag('a', array('href' => '/people/edit/', 'class' => 'button green'), 'Create New Account'));
         if (PhabricatorEnv::getEnvConfig('ldap.auth-enabled')) {
             $panel->addButton(phutil_render_tag('a', array('href' => '/people/ldap/', 'class' => 'button green'), 'Import from LDAP'));
         }
     }
     $nav = $this->buildSideNavView();
     $nav->selectFilter('people');
     $nav->appendChild($panel);
     return $this->buildApplicationPage($nav, array('title' => 'People'));
 }
 public function loadStatus(PhabricatorUser $user)
 {
     if (!$user->getIsAdmin()) {
         return array();
     }
     $need_approval = id(new PhabricatorPeopleQuery())->setViewer($user)->withIsApproved(false)->withIsDisabled(false)->setLimit(self::MAX_STATUS_ITEMS)->execute();
     if (!$need_approval) {
         return array();
     }
     $status = array();
     $count = count($need_approval);
     $count_str = self::formatStatusCount($count, '%s Users Need Approval', '%d User(s) Need Approval');
     $type = PhabricatorApplicationStatusView::TYPE_NEEDS_ATTENTION;
     $status[] = id(new PhabricatorApplicationStatusView())->setType($type)->setText($count_str)->setCount($count);
     return $status;
 }
 protected function buildUserInformationDictionary(PhabricatorUser $user, $with_email = false, $with_availability = false)
 {
     $roles = array();
     if ($user->getIsDisabled()) {
         $roles[] = 'disabled';
     }
     if ($user->getIsSystemAgent()) {
         $roles[] = 'agent';
     }
     if ($user->getIsMailingList()) {
         $roles[] = 'list';
     }
     if ($user->getIsAdmin()) {
         $roles[] = 'admin';
     }
     $primary = $user->loadPrimaryEmail();
     if ($primary && $primary->getIsVerified()) {
         $email = $primary->getAddress();
         $roles[] = 'verified';
     } else {
         $email = null;
         $roles[] = 'unverified';
     }
     if ($user->getIsApproved()) {
         $roles[] = 'approved';
     }
     if ($user->isUserActivated()) {
         $roles[] = 'activated';
     }
     $return = array('phid' => $user->getPHID(), 'userName' => $user->getUserName(), 'realName' => $user->getRealName(), 'image' => $user->getProfileImageURI(), 'uri' => PhabricatorEnv::getURI('/p/' . $user->getUsername() . '/'), 'roles' => $roles);
     if ($with_email) {
         $return['primaryEmail'] = $email;
     }
     if ($with_availability) {
         // TODO: Modernize this once we have a more long-term view of what the
         // data looks like.
         $until = $user->getAwayUntil();
         if ($until) {
             $return['currentStatus'] = 'away';
             $return['currentStatusUntil'] = $until;
         }
     }
     return $return;
 }
 public function loadStatus(PhabricatorUser $user)
 {
     if (!$user->getIsAdmin()) {
         return array();
     }
     $limit = self::MAX_STATUS_ITEMS;
     $need_approval = id(new PhabricatorPeopleQuery())->setViewer($user)->withIsApproved(false)->withIsDisabled(false)->setLimit($limit)->execute();
     if (!$need_approval) {
         return array();
     }
     $status = array();
     $count = count($need_approval);
     if ($count >= $limit) {
         $count_str = pht('%s+ User(s) Need Approval', new PhutilNumber($limit - 1));
     } else {
         $count_str = pht('%s User(s) Need Approval', new PhutilNumber($count));
     }
     $type = PhabricatorApplicationStatusView::TYPE_NEEDS_ATTENTION;
     $status[] = id(new PhabricatorApplicationStatusView())->setType($type)->setText($count_str)->setCount($count);
     return $status;
 }
 public function processRequest()
 {
     $request = $this->getRequest();
     $viewer = $request->getUser();
     $is_admin = $viewer->getIsAdmin();
     $user = new PhabricatorUser();
     $count = queryfx_one($user->establishConnection('r'), 'SELECT COUNT(*) N FROM %T', $user->getTableName());
     $count = idx($count, 'N', 0);
     $pager = new AphrontPagerView();
     $pager->setOffset($request->getInt('page', 0));
     $pager->setCount($count);
     $pager->setURI($request->getRequestURI(), 'page');
     $users = id(new PhabricatorUser())->loadAllWhere('1 = 1 ORDER BY id DESC LIMIT %d, %d', $pager->getOffset(), $pager->getPageSize());
     $rows = array();
     foreach ($users as $user) {
         $status = '';
         if ($user->getIsDisabled()) {
             $status = 'Disabled';
         } else {
             if ($user->getIsAdmin()) {
                 $status = 'Admin';
             } else {
                 $status = '-';
             }
         }
         $rows[] = array(phabricator_date($user->getDateCreated(), $viewer), phabricator_time($user->getDateCreated(), $viewer), phutil_render_tag('a', array('href' => '/p/' . $user->getUsername() . '/'), phutil_escape_html($user->getUserName())), phutil_escape_html($user->getRealName()), $status, phutil_render_tag('a', array('class' => 'button grey small', 'href' => '/people/edit/' . $user->getID() . '/'), 'Administrate User'));
     }
     $table = new AphrontTableView($rows);
     $table->setHeaders(array('Join Date', 'Time', 'Username', 'Real Name', 'Status', ''));
     $table->setColumnClasses(array(null, 'right', 'pri', 'wide', null, 'action'));
     $table->setColumnVisibility(array(true, true, true, true, $is_admin, $is_admin));
     $panel = new AphrontPanelView();
     $panel->setHeader('People (' . number_format($count) . ')');
     $panel->appendChild($table);
     $panel->appendChild($pager);
     if ($is_admin) {
         $panel->addButton(phutil_render_tag('a', array('href' => '/people/edit/', 'class' => 'button green'), 'Create New Account'));
     }
     return $this->buildStandardPageResponse($panel, array('title' => 'People', 'tab' => 'directory'));
 }
 public function isPinnedByDefault(PhabricatorUser $viewer)
 {
     return $viewer->getIsAdmin();
 }
 /**
  * @task role
  */
 public function makeAdminUser(PhabricatorUser $user, $admin)
 {
     $actor = $this->requireActor();
     if (!$user->getID()) {
         throw new Exception("User has not been created yet!");
     }
     $user->openTransaction();
     $user->beginWriteLocking();
     $user->reload();
     if ($user->getIsAdmin() == $admin) {
         $user->endWriteLocking();
         $user->killTransaction();
         return $this;
     }
     $log = PhabricatorUserLog::newLog($actor, $user, PhabricatorUserLog::ACTION_ADMIN);
     $log->setOldValue($user->getIsAdmin());
     $log->setNewValue($admin);
     $user->setIsAdmin($admin);
     $user->save();
     $log->save();
     $user->endWriteLocking();
     $user->saveTransaction();
     return $this;
 }
Beispiel #10
0
$set_system_agent = phutil_console_confirm(pht('Is this user a bot?'), $default_no = !$is_system_agent);
$verify_email = null;
$set_verified = false;
// Allow administrators to verify primary email addresses at this time in edit
// scenarios. (Create will work just fine from here as we auto-verify email
// on create.)
if (!$is_new) {
    $verify_email = $user->loadPrimaryEmail();
    if (!$verify_email->getIsVerified()) {
        $set_verified = phutil_console_confirm(pht('Should the primary email address be verified?'), $default_no = true);
    } else {
        // Already verified so let's not make a fuss.
        $verify_email = null;
    }
}
$is_admin = $user->getIsAdmin();
$set_admin = phutil_console_confirm(pht('Should this user be an administrator?'), $default_no = !$is_admin);
echo "\n\n" . pht('ACCOUNT SUMMARY') . "\n\n";
$tpl = "%12s   %-30s   %-30s\n";
printf($tpl, null, pht('OLD VALUE'), pht('NEW VALUE'));
printf($tpl, pht('Username'), $original->getUsername(), $user->getUsername());
printf($tpl, pht('Real Name'), $original->getRealName(), $user->getRealName());
if ($is_new) {
    printf($tpl, pht('Email'), '', $create_email);
}
printf($tpl, pht('Password'), null, $changed_pass !== false ? pht('Updated') : pht('Unchanged'));
printf($tpl, pht('Bot'), $original->getIsSystemAgent() ? 'Y' : 'N', $set_system_agent ? 'Y' : 'N');
if ($verify_email) {
    printf($tpl, pht('Verify Email'), $verify_email->getIsVerified() ? 'Y' : 'N', $set_verified ? 'Y' : 'N');
}
printf($tpl, pht('Admin'), $original->getIsAdmin() ? 'Y' : 'N', $set_admin ? 'Y' : 'N');
 public function applyRule(PhabricatorUser $viewer, $value, PhabricatorPolicyInterface $object)
 {
     return $viewer->getIsAdmin();
 }
 public function hasAutomaticCapability($capability, PhabricatorUser $viewer)
 {
     if ($this->hasManagedUser()) {
         if ($viewer->getIsAdmin()) {
             return true;
         }
     }
     return false;
 }
 public function applyRule(PhabricatorUser $viewer, $value)
 {
     return $viewer->getIsAdmin();
 }
 public function hasAutomaticCapability($capability, PhabricatorUser $viewer)
 {
     if ($viewer->getIsAdmin()) {
         return true;
     }
     $viewer_phid = $viewer->getPHID();
     if ($viewer_phid) {
         $user_phid = $this->getUserPHID();
         if ($viewer_phid == $user_phid) {
             return true;
         }
         $actor_phid = $this->getActorPHID();
         if ($viewer_phid == $actor_phid) {
             return true;
         }
     }
     return false;
 }
Beispiel #15
0
        echo "ERROR: There is already a user with that email address " . "({$duplicate_username}). Each user must have a unique email " . "address.\n";
    } else {
        break;
    }
} while (true);
$user->setEmail($email);
$changed_pass = false;
// This disables local echo, so the user's password is not shown as they type
// it.
phutil_passthru('stty -echo');
$password = phutil_console_prompt("Enter a password for this user [blank to leave unchanged]:");
phutil_passthru('stty echo');
if (strlen($password)) {
    $changed_pass = $password;
}
$is_admin = $user->getIsAdmin();
$set_admin = phutil_console_confirm('Should this user be an administrator?', $default_no = !$is_admin);
$user->setIsAdmin($set_admin);
echo "\n\nACCOUNT SUMMARY\n\n";
$tpl = "%12s   %-30s   %-30s\n";
printf($tpl, null, 'OLD VALUE', 'NEW VALUE');
printf($tpl, 'Username', $original->getUsername(), $user->getUsername());
printf($tpl, 'Real Name', $original->getRealName(), $user->getRealName());
printf($tpl, 'Email', $original->getEmail(), $user->getEmail());
printf($tpl, 'Password', null, $changed_pass !== false ? 'Updated' : 'Unchanged');
printf($tpl, 'Admin', $original->getIsAdmin() ? 'Y' : 'N', $user->getIsAdmin() ? 'Y' : 'N');
echo "\n";
if (!phutil_console_confirm("Save these changes?", $default_no = false)) {
    echo "Cancelled.\n";
    exit(1);
}