Allow to change account info via provisioning api
Signed-off-by: Joas Schilling <coding@schilljs.com>
This commit is contained in:
parent
98312a9a58
commit
3d628783d9
|
@ -290,12 +290,12 @@ class UsersController extends OCSController {
|
||||||
// Find the data
|
// Find the data
|
||||||
$data['id'] = $targetUserObject->getUID();
|
$data['id'] = $targetUserObject->getUID();
|
||||||
$data['quota'] = $this->fillStorageInfo($userId);
|
$data['quota'] = $this->fillStorageInfo($userId);
|
||||||
$data['email'] = $targetUserObject->getEMailAddress();
|
$data[AccountManager::PROPERTY_EMAIL] = $targetUserObject->getEMailAddress();
|
||||||
$data['displayname'] = $targetUserObject->getDisplayName();
|
$data[AccountManager::PROPERTY_DISPLAYNAME] = $targetUserObject->getDisplayName();
|
||||||
$data['phone'] = $userAccount[\OC\Accounts\AccountManager::PROPERTY_PHONE]['value'];
|
$data[AccountManager::PROPERTY_PHONE] = $userAccount[AccountManager::PROPERTY_PHONE]['value'];
|
||||||
$data['address'] = $userAccount[\OC\Accounts\AccountManager::PROPERTY_ADDRESS]['value'];
|
$data[AccountManager::PROPERTY_ADDRESS] = $userAccount[AccountManager::PROPERTY_ADDRESS]['value'];
|
||||||
$data['webpage'] = $userAccount[\OC\Accounts\AccountManager::PROPERTY_WEBSITE]['value'];
|
$data[AccountManager::PROPERTY_WEBSITE] = $userAccount[AccountManager::PROPERTY_WEBSITE]['value'];
|
||||||
$data['twitter'] = $userAccount[\OC\Accounts\AccountManager::PROPERTY_TWITTER]['value'];
|
$data[AccountManager::PROPERTY_TWITTER] = $userAccount[AccountManager::PROPERTY_TWITTER]['value'];
|
||||||
$data['groups'] = $gids;
|
$data['groups'] = $gids;
|
||||||
|
|
||||||
return $data;
|
return $data;
|
||||||
|
@ -327,8 +327,13 @@ class UsersController extends OCSController {
|
||||||
if($userId === $currentLoggedInUser->getUID()) {
|
if($userId === $currentLoggedInUser->getUID()) {
|
||||||
// Editing self (display, email)
|
// Editing self (display, email)
|
||||||
$permittedFields[] = 'display';
|
$permittedFields[] = 'display';
|
||||||
$permittedFields[] = 'email';
|
$permittedFields[] = AccountManager::PROPERTY_DISPLAYNAME;
|
||||||
|
$permittedFields[] = AccountManager::PROPERTY_EMAIL;
|
||||||
$permittedFields[] = 'password';
|
$permittedFields[] = 'password';
|
||||||
|
$permittedFields[] = AccountManager::PROPERTY_PHONE;
|
||||||
|
$permittedFields[] = AccountManager::PROPERTY_ADDRESS;
|
||||||
|
$permittedFields[] = AccountManager::PROPERTY_WEBSITE;
|
||||||
|
$permittedFields[] = AccountManager::PROPERTY_TWITTER;
|
||||||
// If admin they can edit their own quota
|
// If admin they can edit their own quota
|
||||||
if($this->groupManager->isAdmin($currentLoggedInUser->getUID())) {
|
if($this->groupManager->isAdmin($currentLoggedInUser->getUID())) {
|
||||||
$permittedFields[] = 'quota';
|
$permittedFields[] = 'quota';
|
||||||
|
@ -340,9 +345,14 @@ class UsersController extends OCSController {
|
||||||
|| $this->groupManager->isAdmin($currentLoggedInUser->getUID())) {
|
|| $this->groupManager->isAdmin($currentLoggedInUser->getUID())) {
|
||||||
// They have permissions over the user
|
// They have permissions over the user
|
||||||
$permittedFields[] = 'display';
|
$permittedFields[] = 'display';
|
||||||
$permittedFields[] = 'quota';
|
$permittedFields[] = AccountManager::PROPERTY_DISPLAYNAME;
|
||||||
|
$permittedFields[] = AccountManager::PROPERTY_EMAIL;
|
||||||
$permittedFields[] = 'password';
|
$permittedFields[] = 'password';
|
||||||
$permittedFields[] = 'email';
|
$permittedFields[] = AccountManager::PROPERTY_PHONE;
|
||||||
|
$permittedFields[] = AccountManager::PROPERTY_ADDRESS;
|
||||||
|
$permittedFields[] = AccountManager::PROPERTY_WEBSITE;
|
||||||
|
$permittedFields[] = AccountManager::PROPERTY_TWITTER;
|
||||||
|
$permittedFields[] = 'quota';
|
||||||
} else {
|
} else {
|
||||||
// No rights
|
// No rights
|
||||||
throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED);
|
throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED);
|
||||||
|
@ -355,6 +365,7 @@ class UsersController extends OCSController {
|
||||||
// Process the edit
|
// Process the edit
|
||||||
switch($key) {
|
switch($key) {
|
||||||
case 'display':
|
case 'display':
|
||||||
|
case AccountManager::PROPERTY_DISPLAYNAME:
|
||||||
$targetUser->setDisplayName($value);
|
$targetUser->setDisplayName($value);
|
||||||
break;
|
break;
|
||||||
case 'quota':
|
case 'quota':
|
||||||
|
@ -381,13 +392,23 @@ class UsersController extends OCSController {
|
||||||
case 'password':
|
case 'password':
|
||||||
$targetUser->setPassword($value);
|
$targetUser->setPassword($value);
|
||||||
break;
|
break;
|
||||||
case 'email':
|
case AccountManager::PROPERTY_EMAIL:
|
||||||
if(filter_var($value, FILTER_VALIDATE_EMAIL)) {
|
if(filter_var($value, FILTER_VALIDATE_EMAIL)) {
|
||||||
$targetUser->setEMailAddress($value);
|
$targetUser->setEMailAddress($value);
|
||||||
} else {
|
} else {
|
||||||
throw new OCSException('', 102);
|
throw new OCSException('', 102);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case AccountManager::PROPERTY_PHONE:
|
||||||
|
case AccountManager::PROPERTY_ADDRESS:
|
||||||
|
case AccountManager::PROPERTY_WEBSITE:
|
||||||
|
case AccountManager::PROPERTY_TWITTER:
|
||||||
|
$userAccount = $this->accountManager->getUser($targetUser);
|
||||||
|
if ($userAccount[$key]['value'] !== $value) {
|
||||||
|
$userAccount[$key]['value'] = $value;
|
||||||
|
$this->accountManager->updateUser($targetUser, $userAccount);
|
||||||
|
}
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
throw new OCSException('', 103);
|
throw new OCSException('', 103);
|
||||||
}
|
}
|
||||||
|
|
|
@ -734,7 +734,7 @@ class UsersControllerTest extends TestCase {
|
||||||
'displayname' => 'Demo User',
|
'displayname' => 'Demo User',
|
||||||
'phone' => 'phone',
|
'phone' => 'phone',
|
||||||
'address' => 'address',
|
'address' => 'address',
|
||||||
'webpage' => 'website',
|
'website' => 'website',
|
||||||
'twitter' => 'twitter',
|
'twitter' => 'twitter',
|
||||||
'groups' => ['group0', 'group1', 'group2']
|
'groups' => ['group0', 'group1', 'group2']
|
||||||
];
|
];
|
||||||
|
@ -823,7 +823,7 @@ class UsersControllerTest extends TestCase {
|
||||||
'displayname' => 'Demo User',
|
'displayname' => 'Demo User',
|
||||||
'phone' => 'phone',
|
'phone' => 'phone',
|
||||||
'address' => 'address',
|
'address' => 'address',
|
||||||
'webpage' => 'website',
|
'website' => 'website',
|
||||||
'twitter' => 'twitter',
|
'twitter' => 'twitter',
|
||||||
'groups' => []
|
'groups' => []
|
||||||
];
|
];
|
||||||
|
@ -952,7 +952,7 @@ class UsersControllerTest extends TestCase {
|
||||||
'displayname' => 'Subadmin User',
|
'displayname' => 'Subadmin User',
|
||||||
'phone' => 'phone',
|
'phone' => 'phone',
|
||||||
'address' => 'address',
|
'address' => 'address',
|
||||||
'webpage' => 'website',
|
'website' => 'website',
|
||||||
'twitter' => 'twitter',
|
'twitter' => 'twitter',
|
||||||
'groups' => []
|
'groups' => []
|
||||||
];
|
];
|
||||||
|
@ -2636,7 +2636,7 @@ class UsersControllerTest extends TestCase {
|
||||||
'displayname' => 'Demo User',
|
'displayname' => 'Demo User',
|
||||||
'phone' => 'phone',
|
'phone' => 'phone',
|
||||||
'address' => 'address',
|
'address' => 'address',
|
||||||
'webpage' => 'website',
|
'website' => 'website',
|
||||||
'twitter' => 'twitter'
|
'twitter' => 'twitter'
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
@ -2648,7 +2648,7 @@ class UsersControllerTest extends TestCase {
|
||||||
'email' => 'demo@owncloud.org',
|
'email' => 'demo@owncloud.org',
|
||||||
'phone' => 'phone',
|
'phone' => 'phone',
|
||||||
'address' => 'address',
|
'address' => 'address',
|
||||||
'webpage' => 'website',
|
'website' => 'website',
|
||||||
'twitter' => 'twitter',
|
'twitter' => 'twitter',
|
||||||
'display-name' => 'Demo User'
|
'display-name' => 'Demo User'
|
||||||
];
|
];
|
||||||
|
@ -2696,7 +2696,7 @@ class UsersControllerTest extends TestCase {
|
||||||
'email' => 'demo@owncloud.org',
|
'email' => 'demo@owncloud.org',
|
||||||
'phone' => 'phone',
|
'phone' => 'phone',
|
||||||
'address' => 'address',
|
'address' => 'address',
|
||||||
'webpage' => 'website',
|
'website' => 'website',
|
||||||
'twitter' => 'twitter',
|
'twitter' => 'twitter',
|
||||||
'displayname' => 'Demo User'
|
'displayname' => 'Demo User'
|
||||||
];
|
];
|
||||||
|
|
|
@ -121,6 +121,32 @@ trait Provisioning {
|
||||||
$client->send($client->createRequest('GET', $url, $options2));
|
$client->send($client->createRequest('GET', $url, $options2));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Then /^user "([^"]*)" has$/
|
||||||
|
*
|
||||||
|
* @param string $user
|
||||||
|
* @param \Behat\Gherkin\Node\TableNode|null $settings
|
||||||
|
*/
|
||||||
|
public function userHasSetting($user, $settings) {
|
||||||
|
$fullUrl = $this->baseUrl . "v{$this->apiVersion}.php/cloud/users/$user";
|
||||||
|
$client = new Client();
|
||||||
|
$options = [];
|
||||||
|
$options['auth'] = $this->adminUser;
|
||||||
|
$options['headers'] = [
|
||||||
|
'OCS-APIREQUEST' => 'true',
|
||||||
|
];
|
||||||
|
|
||||||
|
$response = $client->send($client->createRequest("GET", $fullUrl, $options));
|
||||||
|
foreach ($settings->getRows() as $setting) {
|
||||||
|
$value = json_decode(json_encode($response->xml()->data->{$setting[0]}), 1);
|
||||||
|
if (isset($value[0])) {
|
||||||
|
PHPUnit_Framework_Assert::assertEquals($setting[1], $value[0], "", 0.0, 10, true);
|
||||||
|
} else {
|
||||||
|
PHPUnit_Framework_Assert::assertEquals('', $setting[1]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public function createUser($user) {
|
public function createUser($user) {
|
||||||
$previous_user = $this->currentUser;
|
$previous_user = $this->currentUser;
|
||||||
$this->currentUser = "admin";
|
$this->currentUser = "admin";
|
||||||
|
|
|
@ -32,6 +32,14 @@ Feature: provisioning
|
||||||
| password | 123456 |
|
| password | 123456 |
|
||||||
Then the OCS status code should be "102"
|
Then the OCS status code should be "102"
|
||||||
And the HTTP status code should be "200"
|
And the HTTP status code should be "200"
|
||||||
|
And user "brand-new-user" has
|
||||||
|
| id | brand-new-user |
|
||||||
|
| displayname | brand-new-user |
|
||||||
|
| email | |
|
||||||
|
| phone | |
|
||||||
|
| address | |
|
||||||
|
| website | |
|
||||||
|
| twitter | |
|
||||||
|
|
||||||
Scenario: Get an existing user
|
Scenario: Get an existing user
|
||||||
Given As an "admin"
|
Given As an "admin"
|
||||||
|
@ -52,13 +60,48 @@ Feature: provisioning
|
||||||
Given As an "admin"
|
Given As an "admin"
|
||||||
And user "brand-new-user" exists
|
And user "brand-new-user" exists
|
||||||
When sending "PUT" to "/cloud/users/brand-new-user" with
|
When sending "PUT" to "/cloud/users/brand-new-user" with
|
||||||
|
| key | displayname |
|
||||||
|
| value | Brand New User |
|
||||||
|
And the OCS status code should be "100"
|
||||||
|
And the HTTP status code should be "200"
|
||||||
|
And sending "PUT" to "/cloud/users/brand-new-user" with
|
||||||
| key | quota |
|
| key | quota |
|
||||||
| value | 12MB |
|
| value | 12MB |
|
||||||
|
And the OCS status code should be "100"
|
||||||
|
And the HTTP status code should be "200"
|
||||||
|
And sending "PUT" to "/cloud/users/brand-new-user" with
|
||||||
| key | email |
|
| key | email |
|
||||||
| value | brand-new-user@gmail.com |
|
| value | brand-new-user@gmail.com |
|
||||||
Then the OCS status code should be "100"
|
And the OCS status code should be "100"
|
||||||
And the HTTP status code should be "200"
|
And the HTTP status code should be "200"
|
||||||
And user "brand-new-user" exists
|
And sending "PUT" to "/cloud/users/brand-new-user" with
|
||||||
|
| key | phone |
|
||||||
|
| value | 0123 456 789 |
|
||||||
|
And the OCS status code should be "100"
|
||||||
|
And the HTTP status code should be "200"
|
||||||
|
And sending "PUT" to "/cloud/users/brand-new-user" with
|
||||||
|
| key | address |
|
||||||
|
| value | Foo Bar Town |
|
||||||
|
And the OCS status code should be "100"
|
||||||
|
And the HTTP status code should be "200"
|
||||||
|
And sending "PUT" to "/cloud/users/brand-new-user" with
|
||||||
|
| key | website |
|
||||||
|
| value | https://nextcloud.com |
|
||||||
|
And the OCS status code should be "100"
|
||||||
|
And the HTTP status code should be "200"
|
||||||
|
And sending "PUT" to "/cloud/users/brand-new-user" with
|
||||||
|
| key | twitter |
|
||||||
|
| value | Nextcloud |
|
||||||
|
And the OCS status code should be "100"
|
||||||
|
And the HTTP status code should be "200"
|
||||||
|
Then user "brand-new-user" has
|
||||||
|
| id | brand-new-user |
|
||||||
|
| displayname | Brand New User |
|
||||||
|
| email | brand-new-user@gmail.com |
|
||||||
|
| phone | 0123 456 789 |
|
||||||
|
| address | Foo Bar Town |
|
||||||
|
| website | https://nextcloud.com |
|
||||||
|
| twitter | Nextcloud |
|
||||||
|
|
||||||
Scenario: Create a group
|
Scenario: Create a group
|
||||||
Given As an "admin"
|
Given As an "admin"
|
||||||
|
|
Loading…
Reference in New Issue