Skip to content

Commit 992c199

Browse files
author
epriestley
committed
Add "Mailing List" users
Summary: Ref T8387. Adds new mailing list users. This doesn't migrate anything yet. I also need to update the "Email Addresses" panel to let administrators change the list address. Test Plan: - Created and edited a mailing list user. - Viewed profile. - Viewed People list. - Searched for lists / nonlists. - Grepped for all uses of `getIsDisabled()` / `getIsSystemAgent()` and added relevant corresponding behaviors. - Hit the web/api/ssh session blocks. Reviewers: btrahan Reviewed By: btrahan Subscribers: eadler, tycho.tatitscheff, epriestley Maniphest Tasks: T8387 Differential Revision: https://secure.phabricator.com/D13123
1 parent 13f0dac commit 992c199

22 files changed

+244
-43
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
ALTER TABLE {$NAMESPACE}_user.user
2+
ADD isMailingList BOOL NOT NULL;

scripts/ssh/ssh-exec.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -182,11 +182,11 @@
182182
'P' => $user->getPHID(),
183183
));
184184

185-
if (!$user->isUserActivated()) {
185+
if (!$user->canEstablishSSHSessions()) {
186186
throw new Exception(
187187
pht(
188-
'Your account ("%s") is not activated. Visit the web interface '.
189-
'for more information.',
188+
'Your account ("%s") does not have permission to establish SSH '.
189+
'sessions. Visit the web interface for more information.',
190190
$user->getUsername()));
191191
}
192192

scripts/user/account_admin.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@
125125

126126
$is_system_agent = $user->getIsSystemAgent();
127127
$set_system_agent = phutil_console_confirm(
128-
pht('Is this user a bot/script?'),
128+
pht('Is this user a bot?'),
129129
$default_no = !$is_system_agent);
130130

131131
$verify_email = null;
@@ -165,7 +165,7 @@
165165

166166
printf(
167167
$tpl,
168-
pht('Bot/Script'),
168+
pht('Bot'),
169169
$original->getIsSystemAgent() ? 'Y' : 'N',
170170
$set_system_agent ? 'Y' : 'N');
171171

src/applications/auth/engine/PhabricatorAuthSessionEngine.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,21 @@ public function loadUserForSession($session_type, $session_token) {
158158
$session_dict[substr($key, 2)] = $value;
159159
}
160160
}
161+
162+
$user = $user_table->loadFromArray($info);
163+
switch ($session_type) {
164+
case PhabricatorAuthSession::TYPE_WEB:
165+
// Explicitly prevent bots and mailing lists from establishing web
166+
// sessions. It's normally impossible to attach authentication to these
167+
// accounts, and likewise impossible to generate sessions, but it's
168+
// technically possible that a session could exist in the database. If
169+
// one does somehow, refuse to load it.
170+
if (!$user->canEstablishWebSessions()) {
171+
return null;
172+
}
173+
break;
174+
}
175+
161176
$session = id(new PhabricatorAuthSession())->loadFromArray($session_dict);
162177

163178
$ttl = PhabricatorAuthSession::getSessionTypeTTL($session_type);
@@ -181,7 +196,6 @@ public function loadUserForSession($session_type, $session_token) {
181196
unset($unguarded);
182197
}
183198

184-
$user = $user_table->loadFromArray($info);
185199
$user->attachSession($session);
186200
return $user;
187201
}

src/applications/conduit/controller/PhabricatorConduitAPIController.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -475,10 +475,10 @@ private function validateAuthenticatedUser(
475475
ConduitAPIRequest $request,
476476
PhabricatorUser $user) {
477477

478-
if (!$user->isUserActivated()) {
478+
if (!$user->canEstablishAPISessions()) {
479479
return array(
480-
'ERR-USER-DISABLED',
481-
pht('User account is not activated.'),
480+
'ERR-INVALID-AUTH',
481+
pht('User account is not permitted to use the API.'),
482482
);
483483
}
484484

src/applications/conduit/settings/PhabricatorConduitTokensSettingsPanel.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ public function getPanelGroup() {
2020
}
2121

2222
public function isEnabled() {
23+
if ($this->getUser()->getIsMailingList()) {
24+
return false;
25+
}
26+
2327
return true;
2428
}
2529

src/applications/diffusion/panel/DiffusionSetPasswordSettingsPanel.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ public function getPanelGroup() {
1919
}
2020

2121
public function isEnabled() {
22+
if ($this->getUser()->getIsMailingList()) {
23+
return false;
24+
}
25+
2226
return PhabricatorEnv::getEnvConfig('diffusion.allow-http-auth');
2327
}
2428

src/applications/people/conduit/UserConduitAPIMethod.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ protected function buildUserInformationDictionary(
1818
if ($user->getIsSystemAgent()) {
1919
$roles[] = 'agent';
2020
}
21+
if ($user->getIsMailingList()) {
22+
$roles[] = 'list';
23+
}
2124
if ($user->getIsAdmin()) {
2225
$roles[] = 'admin';
2326
}

src/applications/people/controller/PhabricatorPeopleCreateController.php

Lines changed: 37 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ final class PhabricatorPeopleCreateController
44
extends PhabricatorPeopleController {
55

66
public function handleRequest(AphrontRequest $request) {
7-
$this->requireApplicationCapability(
8-
PeopleCreateUsersCapability::CAPABILITY);
97
$admin = $request->getUser();
108

119
id(new PhabricatorAuthSessionEngine())->requireHighSecuritySession(
@@ -17,7 +15,7 @@ public function handleRequest(AphrontRequest $request) {
1715
if ($request->isFormPost()) {
1816
$v_type = $request->getStr('type');
1917

20-
if ($v_type == 'standard' || $v_type == 'bot') {
18+
if ($v_type == 'standard' || $v_type == 'bot' || $v_type == 'list') {
2119
return id(new AphrontRedirectResponse())->setURI(
2220
$this->getApplicationURI('new/'.$v_type.'/'));
2321
}
@@ -41,6 +39,41 @@ public function handleRequest(AphrontRequest $request) {
4139
$bot_admin = pht(
4240
'Administrators have greater access to edit these accounts.');
4341

42+
$types = array();
43+
44+
$can_create = $this->hasApplicationCapability(
45+
PeopleCreateUsersCapability::CAPABILITY);
46+
if ($can_create) {
47+
$types[] = array(
48+
'type' => 'standard',
49+
'name' => pht('Create Standard User'),
50+
'help' => pht('Create a standard user account.'),
51+
);
52+
}
53+
54+
$types[] = array(
55+
'type' => 'bot',
56+
'name' => pht('Create Bot User'),
57+
'help' => pht('Create a new user for use with automated scripts.'),
58+
);
59+
60+
$types[] = array(
61+
'type' => 'list',
62+
'name' => pht('Create Mailing List User'),
63+
'help' => pht(
64+
'Create a mailing list user to represent an existing, external '.
65+
'mailing list like a Google Group or a Mailman list.'),
66+
);
67+
68+
$buttons = id(new AphrontFormRadioButtonControl())
69+
->setLabel(pht('Account Type'))
70+
->setName('type')
71+
->setValue($v_type);
72+
73+
foreach ($types as $type) {
74+
$buttons->addButton($type['type'], $type['name'], $type['help']);
75+
}
76+
4477
$form = id(new AphrontFormView())
4578
->setUser($admin)
4679
->appendRemarkupInstructions(
@@ -49,19 +82,7 @@ public function handleRequest(AphrontRequest $request) {
4982
'explanation of user account types, see [[ %s | User Guide: '.
5083
'Account Roles ]].',
5184
PhabricatorEnv::getDoclink('User Guide: Account Roles')))
52-
->appendChild(
53-
id(new AphrontFormRadioButtonControl())
54-
->setLabel(pht('Account Type'))
55-
->setName('type')
56-
->setValue($v_type)
57-
->addButton(
58-
'standard',
59-
pht('Create Standard User'),
60-
hsprintf('%s<br /><br />%s', $standard_caption, $standard_admin))
61-
->addButton(
62-
'bot',
63-
pht('Create Bot/Script User'),
64-
hsprintf('%s<br /><br />%s', $bot_caption, $bot_admin)))
85+
->appendChild($buttons)
6586
->appendChild(
6687
id(new AphrontFormSubmitControl())
6788
->addCancelButton($this->getApplicationURI())

src/applications/people/controller/PhabricatorPeopleListController.php

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,20 +33,12 @@ protected function buildApplicationCrumbs() {
3333
$crumbs = parent::buildApplicationCrumbs();
3434
$viewer = $this->getRequest()->getUser();
3535

36-
$can_create = $this->hasApplicationCapability(
37-
PeopleCreateUsersCapability::CAPABILITY);
38-
if ($can_create) {
36+
if ($viewer->getIsAdmin()) {
3937
$crumbs->addAction(
4038
id(new PHUIListItemView())
4139
->setName(pht('Create New User'))
4240
->setHref($this->getApplicationURI('create/'))
4341
->setIcon('fa-plus-square'));
44-
} else if ($viewer->getIsAdmin()) {
45-
$crumbs->addAction(
46-
id(new PHUIListItemView())
47-
->setName(pht('Create New Bot'))
48-
->setHref($this->getApplicationURI('new/bot/'))
49-
->setIcon('fa-plus-square'));
5042
}
5143

5244
return $crumbs;

0 commit comments

Comments
 (0)