1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2025-01-10 23:01:04 +01:00

People - add application policy on user creation

Summary: Ref T6947.

Test Plan: made the setting say only admin user a and noted admin user b lost access

Reviewers: epriestley

Reviewed By: epriestley

Subscribers: Korvin, epriestley

Maniphest Tasks: T4137, T6947

Differential Revision: https://secure.phabricator.com/D11357
This commit is contained in:
Bob Trahan 2015-01-12 15:18:16 -08:00
parent f3db0891c7
commit e85dfcbeee
7 changed files with 40 additions and 22 deletions

View file

@ -1224,6 +1224,7 @@ phutil_register_library_map(array(
'PasteQueryConduitAPIMethod' => 'applications/paste/conduit/PasteQueryConduitAPIMethod.php',
'PasteReplyHandler' => 'applications/paste/mail/PasteReplyHandler.php',
'PeopleBrowseUserDirectoryCapability' => 'applications/people/capability/PeopleBrowseUserDirectoryCapability.php',
'PeopleCreateUsersCapability' => 'applications/people/capability/PeopleCreateUsersCapability.php',
'PeopleUserLogGarbageCollector' => 'applications/people/garbagecollector/PeopleUserLogGarbageCollector.php',
'Phabricator404Controller' => 'applications/base/controller/Phabricator404Controller.php',
'PhabricatorAPCSetupCheck' => 'applications/config/check/PhabricatorAPCSetupCheck.php',
@ -4382,6 +4383,7 @@ phutil_register_library_map(array(
'PasteQueryConduitAPIMethod' => 'PasteConduitAPIMethod',
'PasteReplyHandler' => 'PhabricatorMailReplyHandler',
'PeopleBrowseUserDirectoryCapability' => 'PhabricatorPolicyCapability',
'PeopleCreateUsersCapability' => 'PhabricatorPolicyCapability',
'PeopleUserLogGarbageCollector' => 'PhabricatorGarbageCollector',
'Phabricator404Controller' => 'PhabricatorController',
'PhabricatorAPCSetupCheck' => 'PhabricatorSetupCheck',

View file

@ -78,6 +78,9 @@ final class PhabricatorPeopleApplication extends PhabricatorApplication {
protected function getCustomCapabilities() {
return array(
PeopleCreateUsersCapability::CAPABILITY => array(
'default' => PhabricatorPolicies::POLICY_ADMIN,
),
PeopleBrowseUserDirectoryCapability::CAPABILITY => array(),
);
}

View file

@ -0,0 +1,16 @@
<?php
final class PeopleCreateUsersCapability
extends PhabricatorPolicyCapability {
const CAPABILITY = 'people.create.users';
public function getCapabilityName() {
return pht('Can Create Users');
}
public function describeCapabilityRejection() {
return pht('You do not have permission to create users.');
}
}

View file

@ -37,13 +37,14 @@ abstract class PhabricatorPeopleController extends PhabricatorController {
$viewer = $this->getRequest()->getUser();
if ($viewer->getIsAdmin()) {
$crumbs->addAction(
id(new PHUIListItemView())
->setName(pht('Create New User'))
->setHref($this->getApplicationURI('create/'))
->setIcon('fa-plus-square'));
}
$can_create = $this->hasApplicationCapability(
PeopleCreateUsersCapability::CAPABILITY);
$crumbs->addAction(
id(new PHUIListItemView())
->setName(pht('Create New User'))
->setHref($this->getApplicationURI('create/'))
->setDisabled(!$can_create)
->setIcon('fa-plus-square'));
return $crumbs;
}

View file

@ -3,8 +3,9 @@
final class PhabricatorPeopleCreateController
extends PhabricatorPeopleController {
public function processRequest() {
$request = $this->getRequest();
public function handleRequest(AphrontRequest $request) {
$this->requireApplicationCapability(
PeopleCreateUsersCapability::CAPABILITY);
$admin = $request->getUser();
id(new PhabricatorAuthSessionEngine())->requireHighSecuritySession(

View file

@ -3,9 +3,9 @@
final class PhabricatorPeopleLdapController
extends PhabricatorPeopleController {
public function processRequest() {
$request = $this->getRequest();
public function handleRequest(AphrontRequest $request) {
$this->requireApplicationCapability(
PeopleCreateUsersCapability::CAPABILITY);
$admin = $request->getUser();
$content = array();

View file

@ -3,17 +3,13 @@
final class PhabricatorPeopleNewController
extends PhabricatorPeopleController {
private $type;
public function willProcessRequest(array $data) {
$this->type = $data['type'];
}
public function processRequest() {
$request = $this->getRequest();
public function handleRequest(AphrontRequest $request) {
$this->requireApplicationCapability(
PeopleCreateUsersCapability::CAPABILITY);
$type = $request->getURIData('type');
$admin = $request->getUser();
switch ($this->type) {
switch ($type) {
case 'standard':
$is_bot = false;
break;
@ -36,7 +32,6 @@ final class PhabricatorPeopleNewController
$new_email = null;
$request = $this->getRequest();
if ($request->isFormPost()) {
$welcome_checked = $request->getInt('welcome');