summaryrefslogtreecommitdiffstats
path: root/apps/provisioning_api/lib/Controller
diff options
context:
space:
mode:
Diffstat (limited to 'apps/provisioning_api/lib/Controller')
-rw-r--r--apps/provisioning_api/lib/Controller/AUserData.php5
-rw-r--r--apps/provisioning_api/lib/Controller/UsersController.php191
2 files changed, 138 insertions, 58 deletions
diff --git a/apps/provisioning_api/lib/Controller/AUserData.php b/apps/provisioning_api/lib/Controller/AUserData.php
index 5bb62f2b7dc..f2fbea7b04f 100644
--- a/apps/provisioning_api/lib/Controller/AUserData.php
+++ b/apps/provisioning_api/lib/Controller/AUserData.php
@@ -181,6 +181,11 @@ abstract class AUserData extends OCSController {
IAccountManager::PROPERTY_ADDRESS,
IAccountManager::PROPERTY_WEBSITE,
IAccountManager::PROPERTY_TWITTER,
+ IAccountManager::PROPERTY_ORGANISATION,
+ IAccountManager::PROPERTY_ROLE,
+ IAccountManager::PROPERTY_HEADLINE,
+ IAccountManager::PROPERTY_BIOGRAPHY,
+ IAccountManager::PROPERTY_PROFILE_ENABLED,
] as $propertyName) {
$property = $userAccount->getProperty($propertyName);
$data[$propertyName] = $property->getValue();
diff --git a/apps/provisioning_api/lib/Controller/UsersController.php b/apps/provisioning_api/lib/Controller/UsersController.php
index dd8397a8a89..714759ccc0f 100644
--- a/apps/provisioning_api/lib/Controller/UsersController.php
+++ b/apps/provisioning_api/lib/Controller/UsersController.php
@@ -40,6 +40,7 @@ declare(strict_types=1);
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
*/
+
namespace OCA\Provisioning_API\Controller;
use InvalidArgumentException;
@@ -94,29 +95,33 @@ class UsersController extends AUserData {
/** @var IEventDispatcher */
private $eventDispatcher;
- public function __construct(string $appName,
- IRequest $request,
- IUserManager $userManager,
- IConfig $config,
- IGroupManager $groupManager,
- IUserSession $userSession,
- IAccountManager $accountManager,
- IURLGenerator $urlGenerator,
- LoggerInterface $logger,
- IFactory $l10nFactory,
- NewUserMailHelper $newUserMailHelper,
- ISecureRandom $secureRandom,
- RemoteWipe $remoteWipe,
- KnownUserService $knownUserService,
- IEventDispatcher $eventDispatcher) {
- parent::__construct($appName,
- $request,
- $userManager,
- $config,
- $groupManager,
- $userSession,
- $accountManager,
- $l10nFactory);
+ public function __construct(
+ string $appName,
+ IRequest $request,
+ IUserManager $userManager,
+ IConfig $config,
+ IGroupManager $groupManager,
+ IUserSession $userSession,
+ IAccountManager $accountManager,
+ IURLGenerator $urlGenerator,
+ LoggerInterface $logger,
+ IFactory $l10nFactory,
+ NewUserMailHelper $newUserMailHelper,
+ ISecureRandom $secureRandom,
+ RemoteWipe $remoteWipe,
+ KnownUserService $knownUserService,
+ IEventDispatcher $eventDispatcher
+ ) {
+ parent::__construct(
+ $appName,
+ $request,
+ $userManager,
+ $config,
+ $groupManager,
+ $userSession,
+ $accountManager,
+ $l10nFactory
+ );
$this->urlGenerator = $urlGenerator;
$this->logger = $logger;
@@ -325,14 +330,16 @@ class UsersController extends AUserData {
* @return DataResponse
* @throws OCSException
*/
- public function addUser(string $userid,
- string $password = '',
- string $displayName = '',
- string $email = '',
- array $groups = [],
- array $subadmin = [],
- string $quota = '',
- string $language = ''): DataResponse {
+ public function addUser(
+ string $userid,
+ string $password = '',
+ string $displayName = '',
+ string $email = '',
+ array $groups = [],
+ array $subadmin = [],
+ string $quota = '',
+ string $language = ''
+ ): DataResponse {
$user = $this->userSession->getUser();
$isAdmin = $this->groupManager->isAdmin($user->getUID());
$subAdminManager = $this->groupManager->getSubAdmin();
@@ -349,10 +356,10 @@ class UsersController extends AUserData {
if ($groups !== []) {
foreach ($groups as $group) {
if (!$this->groupManager->groupExists($group)) {
- throw new OCSException('group '.$group.' does not exist', 104);
+ throw new OCSException('group ' . $group . ' does not exist', 104);
}
if (!$isAdmin && !$subAdminManager->isSubAdminOfGroup($user, $this->groupManager->get($group))) {
- throw new OCSException('insufficient privileges for group '. $group, 105);
+ throw new OCSException('insufficient privileges for group ' . $group, 105);
}
}
} else {
@@ -440,7 +447,8 @@ class UsersController extends AUserData {
} catch (\Exception $e) {
// Mail could be failing hard or just be plain not configured
// Logging error as it is the hardest of the two
- $this->logger->error("Unable to send the invitation mail to $email",
+ $this->logger->error(
+ "Unable to send the invitation mail to $email",
[
'app' => 'ocs_api',
'exception' => $e,
@@ -452,7 +460,8 @@ class UsersController extends AUserData {
return new DataResponse(['id' => $userid]);
} catch (HintException $e) {
- $this->logger->warning('Failed addUser attempt with hint exception.',
+ $this->logger->warning(
+ 'Failed addUser attempt with hint exception.',
[
'app' => 'ocs_api',
'exception' => $e,
@@ -460,7 +469,8 @@ class UsersController extends AUserData {
);
throw new OCSException($e->getHint(), 107);
} catch (OCSException $e) {
- $this->logger->warning('Failed addUser attempt with ocs exeption.',
+ $this->logger->warning(
+ 'Failed addUser attempt with ocs exeption.',
[
'app' => 'ocs_api',
'exception' => $e,
@@ -468,7 +478,8 @@ class UsersController extends AUserData {
);
throw $e;
} catch (InvalidArgumentException $e) {
- $this->logger->error('Failed addUser attempt with invalid argument exeption.',
+ $this->logger->error(
+ 'Failed addUser attempt with invalid argument exeption.',
[
'app' => 'ocs_api',
'exception' => $e,
@@ -476,7 +487,8 @@ class UsersController extends AUserData {
);
throw new OCSException($e->getMessage(), 101);
} catch (\Exception $e) {
- $this->logger->error('Failed addUser attempt with exception.',
+ $this->logger->error(
+ 'Failed addUser attempt with exception.',
[
'app' => 'ocs_api',
'exception' => $e
@@ -573,8 +585,10 @@ class UsersController extends AUserData {
}
$subAdminManager = $this->groupManager->getSubAdmin();
- if (!$this->groupManager->isAdmin($currentLoggedInUser->getUID())
- && !$subAdminManager->isUserAccessible($currentLoggedInUser, $targetUser)) {
+ if (
+ !$this->groupManager->isAdmin($currentLoggedInUser->getUID())
+ && !$subAdminManager->isUserAccessible($currentLoggedInUser, $targetUser)
+ ) {
throw new OCSException('', OCSController::RESPOND_NOT_FOUND);
}
} else {
@@ -583,8 +597,10 @@ class UsersController extends AUserData {
// Editing self (display, email)
if ($this->config->getSystemValue('allow_user_to_change_display_name', true) !== false) {
- if ($targetUser->getBackend() instanceof ISetDisplayNameBackend
- || $targetUser->getBackend()->implementsActions(Backend::SET_DISPLAYNAME)) {
+ if (
+ $targetUser->getBackend() instanceof ISetDisplayNameBackend
+ || $targetUser->getBackend()->implementsActions(Backend::SET_DISPLAYNAME)
+ ) {
$permittedFields[] = IAccountManager::PROPERTY_DISPLAYNAME;
}
$permittedFields[] = IAccountManager::PROPERTY_EMAIL;
@@ -595,6 +611,11 @@ class UsersController extends AUserData {
$permittedFields[] = IAccountManager::PROPERTY_ADDRESS;
$permittedFields[] = IAccountManager::PROPERTY_WEBSITE;
$permittedFields[] = IAccountManager::PROPERTY_TWITTER;
+ $permittedFields[] = IAccountManager::PROPERTY_ORGANISATION;
+ $permittedFields[] = IAccountManager::PROPERTY_ROLE;
+ $permittedFields[] = IAccountManager::PROPERTY_HEADLINE;
+ $permittedFields[] = IAccountManager::PROPERTY_BIOGRAPHY;
+ $permittedFields[] = IAccountManager::PROPERTY_PROFILE_ENABLED;
return new DataResponse($permittedFields);
}
@@ -700,11 +721,11 @@ class UsersController extends AUserData {
*
* @param string $userId
* @param string $key
- * @param string $value
+ * @param string|bool $value
* @return DataResponse
* @throws OCSException
*/
- public function editUser(string $userId, string $key, string $value): DataResponse {
+ public function editUser(string $userId, string $key, $value): DataResponse {
$currentLoggedInUser = $this->userSession->getUser();
$targetUser = $this->userManager->get($userId);
@@ -716,8 +737,10 @@ class UsersController extends AUserData {
if ($targetUser->getUID() === $currentLoggedInUser->getUID()) {
// Editing self (display, email)
if ($this->config->getSystemValue('allow_user_to_change_display_name', true) !== false) {
- if ($targetUser->getBackend() instanceof ISetDisplayNameBackend
- || $targetUser->getBackend()->implementsActions(Backend::SET_DISPLAYNAME)) {
+ if (
+ $targetUser->getBackend() instanceof ISetDisplayNameBackend
+ || $targetUser->getBackend()->implementsActions(Backend::SET_DISPLAYNAME)
+ ) {
$permittedFields[] = self::USER_FIELD_DISPLAYNAME;
$permittedFields[] = IAccountManager::PROPERTY_DISPLAYNAME;
}
@@ -731,13 +754,17 @@ class UsersController extends AUserData {
$permittedFields[] = self::USER_FIELD_PASSWORD;
$permittedFields[] = self::USER_FIELD_NOTIFICATION_EMAIL;
- if ($this->config->getSystemValue('force_language', false) === false ||
- $this->groupManager->isAdmin($currentLoggedInUser->getUID())) {
+ if (
+ $this->config->getSystemValue('force_language', false) === false ||
+ $this->groupManager->isAdmin($currentLoggedInUser->getUID())
+ ) {
$permittedFields[] = self::USER_FIELD_LANGUAGE;
}
- if ($this->config->getSystemValue('force_locale', false) === false ||
- $this->groupManager->isAdmin($currentLoggedInUser->getUID())) {
+ if (
+ $this->config->getSystemValue('force_locale', false) === false ||
+ $this->groupManager->isAdmin($currentLoggedInUser->getUID())
+ ) {
$permittedFields[] = self::USER_FIELD_LOCALE;
}
@@ -745,10 +772,20 @@ class UsersController extends AUserData {
$permittedFields[] = IAccountManager::PROPERTY_ADDRESS;
$permittedFields[] = IAccountManager::PROPERTY_WEBSITE;
$permittedFields[] = IAccountManager::PROPERTY_TWITTER;
+ $permittedFields[] = IAccountManager::PROPERTY_ORGANISATION;
+ $permittedFields[] = IAccountManager::PROPERTY_ROLE;
+ $permittedFields[] = IAccountManager::PROPERTY_HEADLINE;
+ $permittedFields[] = IAccountManager::PROPERTY_BIOGRAPHY;
+ $permittedFields[] = IAccountManager::PROPERTY_PROFILE_ENABLED;
$permittedFields[] = IAccountManager::PROPERTY_PHONE . self::SCOPE_SUFFIX;
$permittedFields[] = IAccountManager::PROPERTY_ADDRESS . self::SCOPE_SUFFIX;
$permittedFields[] = IAccountManager::PROPERTY_WEBSITE . self::SCOPE_SUFFIX;
$permittedFields[] = IAccountManager::PROPERTY_TWITTER . self::SCOPE_SUFFIX;
+ $permittedFields[] = IAccountManager::PROPERTY_ORGANISATION . self::SCOPE_SUFFIX;
+ $permittedFields[] = IAccountManager::PROPERTY_ROLE . self::SCOPE_SUFFIX;
+ $permittedFields[] = IAccountManager::PROPERTY_HEADLINE . self::SCOPE_SUFFIX;
+ $permittedFields[] = IAccountManager::PROPERTY_BIOGRAPHY . self::SCOPE_SUFFIX;
+ $permittedFields[] = IAccountManager::PROPERTY_PROFILE_ENABLED . self::SCOPE_SUFFIX;
$permittedFields[] = IAccountManager::PROPERTY_AVATAR . self::SCOPE_SUFFIX;
@@ -759,11 +796,15 @@ class UsersController extends AUserData {
} else {
// Check if admin / subadmin
$subAdminManager = $this->groupManager->getSubAdmin();
- if ($this->groupManager->isAdmin($currentLoggedInUser->getUID())
- || $subAdminManager->isUserAccessible($currentLoggedInUser, $targetUser)) {
+ if (
+ $this->groupManager->isAdmin($currentLoggedInUser->getUID())
+ || $subAdminManager->isUserAccessible($currentLoggedInUser, $targetUser)
+ ) {
// They have permissions over the user
- if ($targetUser->getBackend() instanceof ISetDisplayNameBackend
- || $targetUser->getBackend()->implementsActions(Backend::SET_DISPLAYNAME)) {
+ if (
+ $targetUser->getBackend() instanceof ISetDisplayNameBackend
+ || $targetUser->getBackend()->implementsActions(Backend::SET_DISPLAYNAME)
+ ) {
$permittedFields[] = self::USER_FIELD_DISPLAYNAME;
$permittedFields[] = IAccountManager::PROPERTY_DISPLAYNAME;
}
@@ -776,6 +817,11 @@ class UsersController extends AUserData {
$permittedFields[] = IAccountManager::PROPERTY_ADDRESS;
$permittedFields[] = IAccountManager::PROPERTY_WEBSITE;
$permittedFields[] = IAccountManager::PROPERTY_TWITTER;
+ $permittedFields[] = IAccountManager::PROPERTY_ORGANISATION;
+ $permittedFields[] = IAccountManager::PROPERTY_ROLE;
+ $permittedFields[] = IAccountManager::PROPERTY_HEADLINE;
+ $permittedFields[] = IAccountManager::PROPERTY_BIOGRAPHY;
+ $permittedFields[] = IAccountManager::PROPERTY_PROFILE_ENABLED;
$permittedFields[] = self::USER_FIELD_QUOTA;
$permittedFields[] = self::USER_FIELD_NOTIFICATION_EMAIL;
} else {
@@ -802,7 +848,7 @@ class UsersController extends AUserData {
$quota = \OCP\Util::computerFileSize($quota);
}
if ($quota === false) {
- throw new OCSException('Invalid quota value '.$value, 102);
+ throw new OCSException('Invalid quota value ' . $value, 102);
}
if ($quota === -1) {
$quota = 'none';
@@ -892,6 +938,10 @@ class UsersController extends AUserData {
case IAccountManager::PROPERTY_ADDRESS:
case IAccountManager::PROPERTY_WEBSITE:
case IAccountManager::PROPERTY_TWITTER:
+ case IAccountManager::PROPERTY_ORGANISATION:
+ case IAccountManager::PROPERTY_ROLE:
+ case IAccountManager::PROPERTY_HEADLINE:
+ case IAccountManager::PROPERTY_BIOGRAPHY:
$userAccount = $this->accountManager->getAccount($targetUser);
try {
$userProperty = $userAccount->getProperty($key);
@@ -910,12 +960,34 @@ class UsersController extends AUserData {
}
$this->accountManager->updateAccount($userAccount);
break;
+ case IAccountManager::PROPERTY_PROFILE_ENABLED:
+ if (!is_bool($value)) {
+ throw new OCSException('Invalid value, value must be a boolean', 102);
+ }
+ $value = $value === true ? '1' : '0';
+
+ $userAccount = $this->accountManager->getAccount($targetUser);
+ try {
+ $userProperty = $userAccount->getProperty($key);
+ if ($userProperty->getValue() !== $value) {
+ $userProperty->setValue($value);
+ }
+ } catch (PropertyDoesNotExistException $e) {
+ $userAccount->setProperty($key, $value, IAccountManager::SCOPE_LOCAL, IAccountManager::NOT_VERIFIED);
+ }
+ $this->accountManager->updateAccount($userAccount);
+ break;
case IAccountManager::PROPERTY_DISPLAYNAME . self::SCOPE_SUFFIX:
case IAccountManager::PROPERTY_EMAIL . self::SCOPE_SUFFIX:
case IAccountManager::PROPERTY_PHONE . self::SCOPE_SUFFIX:
case IAccountManager::PROPERTY_ADDRESS . self::SCOPE_SUFFIX:
case IAccountManager::PROPERTY_WEBSITE . self::SCOPE_SUFFIX:
case IAccountManager::PROPERTY_TWITTER . self::SCOPE_SUFFIX:
+ case IAccountManager::PROPERTY_ORGANISATION . self::SCOPE_SUFFIX:
+ case IAccountManager::PROPERTY_ROLE . self::SCOPE_SUFFIX:
+ case IAccountManager::PROPERTY_HEADLINE . self::SCOPE_SUFFIX:
+ case IAccountManager::PROPERTY_BIOGRAPHY . self::SCOPE_SUFFIX:
+ case IAccountManager::PROPERTY_PROFILE_ENABLED . self::SCOPE_SUFFIX:
case IAccountManager::PROPERTY_AVATAR . self::SCOPE_SUFFIX:
$propertyName = substr($key, 0, strlen($key) - strlen(self::SCOPE_SUFFIX));
$userAccount = $this->accountManager->getAccount($targetUser);
@@ -1300,8 +1372,10 @@ class UsersController extends AUserData {
// Check if admin / subadmin
$subAdminManager = $this->groupManager->getSubAdmin();
- if (!$subAdminManager->isUserAccessible($currentLoggedInUser, $targetUser)
- && !$this->groupManager->isAdmin($currentLoggedInUser->getUID())) {
+ if (
+ !$subAdminManager->isUserAccessible($currentLoggedInUser, $targetUser)
+ && !$this->groupManager->isAdmin($currentLoggedInUser->getUID())
+ ) {
// No rights
throw new OCSException('', OCSController::RESPOND_NOT_FOUND);
}
@@ -1315,7 +1389,8 @@ class UsersController extends AUserData {
$emailTemplate = $this->newUserMailHelper->generateTemplate($targetUser, false);
$this->newUserMailHelper->sendMail($targetUser, $emailTemplate);
} catch (\Exception $e) {
- $this->logger->error("Can't send new user mail to $email",
+ $this->logger->error(
+ "Can't send new user mail to $email",
[
'app' => 'settings',
'exception' => $e,