@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Show an "approval queue" item on the home page for admins, and sort out menu item visibility

Summary:
- If you're an administrator and there are users waiting for approval, show a count on the home page.
- Sort out the `isUserActivated()` access check.
- Hide all the menu widgets except "Logout" for disabled and unapproved users.
- Add a "Log In" item.
- Add a bunch of unit tests.

Test Plan: Ran unit tests, clicked around as unapproved/approved/logged-in/logged-out users.

Reviewers: btrahan

Reviewed By: btrahan

CC: aran, chad

Differential Revision: https://secure.phabricator.com/D7574

+76 -14
+14
src/applications/auth/application/PhabricatorApplicationAuth.php
··· 41 41 ->setHref('/logout/') 42 42 ->setSelected(($controller instanceof PhabricatorLogoutController)); 43 43 $items[] = $item; 44 + } else { 45 + if ($controller instanceof PhabricatorAuthController) { 46 + // Don't show the "Login" item on auth controllers, since they're 47 + // generally all related to logging in anyway. 48 + } else { 49 + $item = id(new PHUIListItemView()) 50 + ->addClass('core-menu-item') 51 + ->setName(pht('Log In')) 52 + // TODO: Login icon? 53 + ->setIcon('power') 54 + ->setWorkflow(true) 55 + ->setHref('/auth/login/'); 56 + $items[] = $item; 57 + } 44 58 } 45 59 46 60 return $items;
+9 -9
src/applications/base/controller/PhabricatorController.php
··· 74 74 } 75 75 } 76 76 77 - if ($user->getIsDisabled() && $this->shouldRequireEnabledUser()) { 78 - $disabled_user_controller = new PhabricatorDisabledUserController( 79 - $request); 80 - return $this->delegateToController($disabled_user_controller); 77 + if ($this->shouldRequireEnabledUser()) { 78 + if ($user->isLoggedIn() && !$user->getIsApproved()) { 79 + $controller = new PhabricatorAuthNeedsApprovalController($request); 80 + return $this->delegateToController($controller); 81 + } 82 + if ($user->getIsDisabled()) { 83 + $controller = new PhabricatorDisabledUserController($request); 84 + return $this->delegateToController($controller); 85 + } 81 86 } 82 87 83 88 $event = new PhabricatorEvent( ··· 119 124 $this->setCurrentApplication($auth_application); 120 125 return $this->delegateToController($controller); 121 126 } 122 - } 123 - if (!$user->getIsApproved()) { 124 - $controller = new PhabricatorAuthNeedsApprovalController($request); 125 - $this->setCurrentApplication($auth_application); 126 - return $this->delegateToController($controller); 127 127 } 128 128 } 129 129
+14
src/applications/base/controller/__tests__/PhabricatorAccessControlTestCase.php
··· 47 47 ->setUsername('admin') 48 48 ->save(); 49 49 50 + $u_notapproved = $this->generateNewTestUser() 51 + ->setIsApproved(0) 52 + ->setUsername('notapproved') 53 + ->save(); 54 + 50 55 $env = PhabricatorEnv::beginScopedEnv(); 51 56 $env->overrideEnvConfig('phabricator.base-uri', 'http://'.$host); 52 57 $env->overrideEnvConfig('policy.allow-public', false); ··· 68 73 array( 69 74 $u_public, 70 75 $u_disabled, 76 + $u_notapproved, 71 77 )); 72 78 73 79 ··· 86 92 $u_unverified, 87 93 $u_public, 88 94 $u_disabled, 95 + $u_notapproved, 89 96 )); 90 97 91 98 $this->checkAccess( ··· 100 107 array( 101 108 $u_public, 102 109 $u_disabled, 110 + $u_notapproved, 103 111 )); 104 112 $env->overrideEnvConfig('auth.require-email-verification', false); 105 113 ··· 118 126 $u_unverified, 119 127 $u_public, 120 128 $u_disabled, 129 + $u_notapproved, 121 130 )); 122 131 123 132 ··· 132 141 $u_unverified, 133 142 $u_admin, 134 143 $u_disabled, 144 + $u_notapproved, 135 145 ), 136 146 array( 137 147 $u_public, ··· 152 162 ), 153 163 array( 154 164 $u_disabled, 165 + $u_notapproved, 155 166 )); 156 167 157 168 ··· 184 195 ), 185 196 array( 186 197 $u_disabled, 198 + $u_notapproved, 187 199 )); 188 200 $env->overrideEnvConfig('policy.allow-public', false); 189 201 ··· 208 220 $u_admin, 209 221 $u_public, 210 222 $u_disabled, 223 + $u_notapproved, 211 224 )); 212 225 213 226 $this->checkAccess( ··· 222 235 ), 223 236 array( 224 237 $u_disabled, 238 + $u_notapproved, 225 239 )); 226 240 } 227 241
+27 -1
src/applications/people/application/PhabricatorApplicationPeople.php
··· 62 62 ); 63 63 } 64 64 65 + public function loadStatus(PhabricatorUser $user) { 66 + if (!$user->getIsAdmin()) { 67 + return array(); 68 + } 69 + 70 + $need_approval = id(new PhabricatorPeopleQuery()) 71 + ->setViewer($user) 72 + ->withIsApproved(false) 73 + ->execute(); 74 + 75 + if (!$need_approval) { 76 + return array(); 77 + } 78 + 79 + $status = array(); 80 + 81 + $count = count($need_approval); 82 + $type = PhabricatorApplicationStatusView::TYPE_NEEDS_ATTENTION; 83 + $status[] = id(new PhabricatorApplicationStatusView()) 84 + ->setType($type) 85 + ->setText(pht('%d User(s) Need Approval', $count)) 86 + ->setCount($count); 87 + 88 + return $status; 89 + } 90 + 65 91 public function buildMainMenuItems( 66 92 PhabricatorUser $user, 67 93 PhabricatorController $controller = null) { 68 94 69 95 $items = array(); 70 96 71 - if ($user->isLoggedIn()) { 97 + if ($user->isLoggedIn() && $user->isUserActivated()) { 72 98 $image = $user->loadProfileImageURI(); 73 99 74 100 $item = new PHUIListItemView();
+1 -1
src/applications/settings/application/PhabricatorApplicationSettings.php
··· 37 37 38 38 $items = array(); 39 39 40 - if ($user->isLoggedIn()) { 40 + if ($user->isLoggedIn() && $user->isUserActivated()) { 41 41 $selected = ($controller instanceof PhabricatorSettingsMainController); 42 42 $item = new PHUIListItemView(); 43 43 $item->setName(pht('Settings'));
+5
src/infrastructure/internationalization/PhabricatorBaseEnglishTranslation.php
··· 810 810 ), 811 811 ), 812 812 813 + '%d User(s) Need Approval' => array( 814 + '%d User Needs Approval', 815 + '%d Users Need Approval', 816 + ), 817 + 813 818 ); 814 819 } 815 820
+6 -3
src/view/page/menu/PhabricatorMainMenuView.php
··· 44 44 $search_button = ''; 45 45 $app_button = ''; 46 46 47 - if ($user->isLoggedIn()) { 47 + if ($user->isLoggedIn() && $user->isUserActivated()) { 48 48 list($menu, $dropdowns) = $this->renderNotificationMenu(); 49 49 $alerts[] = $menu; 50 50 $menus = array_merge($menus, $dropdowns); ··· 91 91 'helpURI' => '/help/keyboardshortcut/', 92 92 ); 93 93 94 - $show_search = ($user->isLoggedIn()) || 95 - (PhabricatorEnv::getEnvConfig('policy.allow-public')); 94 + if ($user->isLoggedIn()) { 95 + $show_search = $user->isUserActivated(); 96 + } else { 97 + $show_search = PhabricatorEnv::getEnvConfig('policy.allow-public'); 98 + } 96 99 97 100 if ($show_search) { 98 101 $search = new PhabricatorMainMenuSearchView();