Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/documentserver_community.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobin Appelman <robin@icewind.nl>2020-01-29 17:15:23 +0300
committerRobin Appelman <robin@icewind.nl>2020-01-29 17:15:23 +0300
commit3d18bc2967ba3125651c2950ccdaa11512cee6fd (patch)
treed18fe1908722d2550c822261b898e84cec37e918
parentc5994761331127d5fa27d615ce1bee2cee5a184a (diff)
use displayname instead of uid in ui
-rw-r--r--lib/Channel/Session.php11
-rw-r--r--lib/Channel/SessionManager.php11
-rw-r--r--lib/Migration/Version001400Date20200129140530.php28
-rw-r--r--lib/XHRCommand/AuthCommand.php2
-rw-r--r--tests/Channel/SessionManagerTest.php3
5 files changed, 47 insertions, 8 deletions
diff --git a/lib/Channel/Session.php b/lib/Channel/Session.php
index 0e47549..570f627 100644
--- a/lib/Channel/Session.php
+++ b/lib/Channel/Session.php
@@ -29,8 +29,9 @@ class Session {
private $lastSeen;
private $readOnly;
private $userId;
+ private $userName;
- public function __construct(string $sessionId, int $documentId, string $user, string $userOriginal, int $lastSeen, bool $readOnly, int $userId) {
+ public function __construct(string $sessionId, int $documentId, string $user, string $userOriginal, string $userName, int $lastSeen, bool $readOnly, int $userId) {
$this->documentId = $documentId;
$this->sessionId = $sessionId;
$this->user = $user;
@@ -38,6 +39,7 @@ class Session {
$this->lastSeen = $lastSeen;
$this->readOnly = $readOnly;
$this->userId = $userId;
+ $this->userName = $userName;
}
public function getDocumentId(): int {
@@ -52,6 +54,10 @@ class Session {
return $this->user;
}
+ public function getUserName(): string {
+ return $this->userName;
+ }
+
public function getUserOriginal(): string {
return $this->userOriginal;
}
@@ -76,7 +82,7 @@ class Session {
return [
"id" => $this->getUserId(),
"idOriginal" => $this->getUserOriginal(),
- "username" => $this->getUserOriginal(),
+ "username" => $this->getUserName(),
"indexUser" => $this->getUserIndex(),
"view" => $this->isReadOnly(),
"connectionId" => $this->getSessionId(),
@@ -90,6 +96,7 @@ class Session {
(int)$row['document_id'],
$row['user'],
$row['user_original'],
+ $row['username'] ?? $row['user'],
(int)$row['last_seen'],
(bool)$row['readonly'],
(int)$row['user_index']
diff --git a/lib/Channel/SessionManager.php b/lib/Channel/SessionManager.php
index c1cb68e..7fa0365 100644
--- a/lib/Channel/SessionManager.php
+++ b/lib/Channel/SessionManager.php
@@ -48,7 +48,7 @@ class SessionManager {
public function getSession(string $sessionId): ?Session {
$query = $this->connection->getQueryBuilder();
- $query->select('session_id', 'document_id', 'user', 'user_original', 'last_seen', 'readonly', 'user_index')
+ $query->select('session_id', 'document_id', 'user', 'user_original', 'last_seen', 'readonly', 'user_index', 'username')
->from('documentserver_sess')
->where($query->expr()->eq('session_id', $query->createNamedParameter($sessionId)));
@@ -83,13 +83,14 @@ class SessionManager {
'last_seen' => $query->createNamedParameter($now, \PDO::PARAM_INT),
'user' => $query->createNamedParameter(""),
'user_original' => $query->createNamedParameter(""),
+ 'username' => $query->createNamedParameter(""),
'readonly' => $query->createNamedParameter(1, \PDO::PARAM_INT),
'user_index' => $query->createNamedParameter($userId, \PDO::PARAM_INT),
]);
$query->execute();
}
- public function authenticate(Session $session, string $user, string $userOriginal, bool $readOnly): Session {
+ public function authenticate(Session $session, string $user, string $userOriginal, string $userName, bool $readOnly): Session {
$query = $this->connection->getQueryBuilder();
$now = $this->timeFactory->getTime();
@@ -97,6 +98,7 @@ class SessionManager {
->set('last_seen', $query->createNamedParameter($now, \PDO::PARAM_INT))
->set('user', $query->createNamedParameter($user))
->set('user_original', $query->createNamedParameter($userOriginal))
+ ->set('username', $query->createNamedParameter($userName))
->set('readonly', $query->createNamedParameter($readOnly, \PDO::PARAM_INT))
->where($query->expr()->eq('session_id', $query->createNamedParameter($session->getSessionId())));
$query->execute();
@@ -106,6 +108,7 @@ class SessionManager {
$session->getDocumentId(),
$user,
$userOriginal,
+ $userName,
$now,
$readOnly,
$session->getUserIndex()
@@ -157,7 +160,7 @@ class SessionManager {
public function getSessionsForDocument(int $documentId): array {
$query = $this->connection->getQueryBuilder();
- $query->select('session_id', 'document_id', 'user', 'user_original', 'last_seen', 'readonly', 'user_index')
+ $query->select('session_id', 'document_id', 'user', 'user_original', 'last_seen', 'readonly', 'user_index', 'username')
->from('documentserver_sess')
->where($query->expr()->eq('document_id', $query->createNamedParameter($documentId, \PDO::PARAM_INT)));
@@ -169,7 +172,7 @@ class SessionManager {
public function getSessionForUser(string $userId): ?Session {
$query = $this->connection->getQueryBuilder();
- $query->select('session_id', 'document_id', 'user', 'user_original', 'last_seen', 'readonly', 'user_index')
+ $query->select('session_id', 'document_id', 'user', 'user_original', 'last_seen', 'readonly', 'user_index', 'username')
->from('documentserver_sess')
->where($query->expr()->eq($query->func()->concat('user', 'user_index'), $query->createNamedParameter($userId)));
diff --git a/lib/Migration/Version001400Date20200129140530.php b/lib/Migration/Version001400Date20200129140530.php
new file mode 100644
index 0000000..3372176
--- /dev/null
+++ b/lib/Migration/Version001400Date20200129140530.php
@@ -0,0 +1,28 @@
+<?php
+
+declare(strict_types=1);
+
+namespace OCA\DocumentServer\Migration;
+
+use Closure;
+use Doctrine\DBAL\Schema\Schema;
+use OCP\DB\ISchemaWrapper;
+use OCP\Migration\IOutput;
+use OCP\Migration\SimpleMigrationStep;
+
+class Version001400Date20200129140530 extends SimpleMigrationStep {
+
+ public function changeSchema(IOutput $output, Closure $schemaClosure, array $options) {
+ /** @var Schema $schema */
+ $schema = $schemaClosure();
+
+ if ($schema->hasTable('documentserver_sess')) {
+ $table = $schema->getTable('documentserver_sess');
+ $table->addColumn('username', 'text', [
+ 'notnull' => false,
+ ]);
+ }
+
+ return $schema;
+ }
+}
diff --git a/lib/XHRCommand/AuthCommand.php b/lib/XHRCommand/AuthCommand.php
index d1ce97c..c149806 100644
--- a/lib/XHRCommand/AuthCommand.php
+++ b/lib/XHRCommand/AuthCommand.php
@@ -79,7 +79,7 @@ class AuthCommand implements ICommandHandler {
$user = $command['user'];
$readOnly = $command['view'];
- $session = $this->sessionManager->authenticate($session, $user['id'], $user['username'], $readOnly);
+ $session = $this->sessionManager->authenticate($session, $user['id'], $user['id'], $user['username'], $readOnly);
$participants = $this->sessionManager->getSessionsForDocument($session->getDocumentId());
diff --git a/tests/Channel/SessionManagerTest.php b/tests/Channel/SessionManagerTest.php
index 80c3140..ba08c9e 100644
--- a/tests/Channel/SessionManagerTest.php
+++ b/tests/Channel/SessionManagerTest.php
@@ -69,12 +69,13 @@ class SessionManagerTest extends TestCase {
$this->assertEquals('', $session->getUserOriginal());
$this->assertEquals(10, $session->getLastSeen());
- $this->manager->authenticate($session, 'user', 'original', false);
+ $this->manager->authenticate($session, 'user', 'original', 'name', false);
$session = $this->manager->getSession('foo');
$this->assertEquals('foo', $session->getSessionId());
$this->assertEquals(5, $session->getDocumentId());
$this->assertEquals('user', $session->getUser());
+ $this->assertEquals('name', $session->getUser());
$this->assertEquals('original', $session->getUserOriginal());
$this->assertEquals(10, $session->getLastSeen());
}