summaryrefslogtreecommitdiffstats
path: root/settings/controller
diff options
context:
space:
mode:
authorRoeland Jago Douma <rullzer@owncloud.com>2015-11-08 22:08:19 +0100
committerRoeland Jago Douma <rullzer@owncloud.com>2015-11-20 16:05:43 +0100
commit0265bcfdae6eff2ea87eb0f6de66e2eacb590820 (patch)
tree45333175470f4a822c727ca065bf6e5cadfda424 /settings/controller
parent427d107b9f375f5667a3e8f40191edd46924fdb8 (diff)
downloadnextcloud-server-0265bcfdae6eff2ea87eb0f6de66e2eacb590820.tar.gz
nextcloud-server-0265bcfdae6eff2ea87eb0f6de66e2eacb590820.zip
Moved changedisplayname to usercontroller
Killed the old static route to change a users display name and moved it to a properly testable controller.
Diffstat (limited to 'settings/controller')
-rw-r--r--settings/controller/userscontroller.php54
1 files changed, 54 insertions, 0 deletions
diff --git a/settings/controller/userscontroller.php b/settings/controller/userscontroller.php
index 82483a76245..942319901f3 100644
--- a/settings/controller/userscontroller.php
+++ b/settings/controller/userscontroller.php
@@ -585,4 +585,58 @@ class UsersController extends Controller {
);
}
+
+ /**
+ * Set the displayName of a user
+ *
+ * @NoAdminRequired
+ * @NoSubadminRequired
+ *
+ * @param string $username
+ * @param string $displayName
+ * @return DataResponse
+ */
+ public function setDisplayName($username, $displayName) {
+ $currentUser = $this->userSession->getUser();
+
+ if ($username === null) {
+ $username = $currentUser->getUID();
+ }
+
+ $user = $this->userManager->get($username);
+
+ if ($user === null ||
+ !$user->canChangeDisplayName() ||
+ (
+ !$this->groupManager->isAdmin($currentUser->getUID()) &&
+ !$this->groupManager->getSubAdmin()->isUserAccessible($currentUser, $user) &&
+ $currentUser !== $user)
+ ) {
+ return new DataResponse([
+ 'status' => 'error',
+ 'data' => [
+ 'message' => $this->l10n->t('Authentication error'),
+ ],
+ ]);
+ }
+
+ if ($user->setDisplayName($displayName)) {
+ return new DataResponse([
+ 'status' => 'success',
+ 'data' => [
+ 'message' => $this->l10n->t('Your full name has been changed.'),
+ 'username' => $username,
+ 'displayName' => $displayName,
+ ],
+ ]);
+ } else {
+ return new DataResponse([
+ 'status' => 'error',
+ 'data' => [
+ 'message' => $this->l10n->t('Unable to change full name'),
+ 'displayName' => $user->getDisplayName(),
+ ],
+ ]);
+ }
+ }
}