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

github.com/nextcloud/text.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorJulius Härtl <jus@bitgrid.net>2019-06-15 00:26:12 +0300
committerJulius Härtl <jus@bitgrid.net>2019-06-15 11:14:01 +0300
commitd392585407cfd5abfd6b9f1880c96feeacc5447a (patch)
tree2ea57b1a86aeac4e07d3a0630fdaa99db0432dc8 /lib
parent1428971a593764d829007b30ffe9d13d3ffec8ab (diff)
Implement guest name change
Signed-off-by: Julius Härtl <jus@bitgrid.net>
Diffstat (limited to 'lib')
-rw-r--r--lib/Controller/PublicSessionController.php8
-rw-r--r--lib/Db/SessionMapper.php4
-rw-r--r--lib/Service/ApiService.php20
-rw-r--r--lib/Service/SessionService.php22
4 files changed, 47 insertions, 7 deletions
diff --git a/lib/Controller/PublicSessionController.php b/lib/Controller/PublicSessionController.php
index c5e430eab..4aff8d83b 100644
--- a/lib/Controller/PublicSessionController.php
+++ b/lib/Controller/PublicSessionController.php
@@ -110,4 +110,12 @@ class PublicSessionController extends PublicShareController {
return $this->apiService->sync($documentId, $sessionId, $sessionToken, $version, $autosaveContent, $force, $manualSave, $token);
}
+ /**
+ * @NoAdminRequired
+ * @PublicPage
+ */
+ public function updateSession(int $documentId, int $sessionId, string $sessionToken, string $guestName) {
+ return $this->apiService->updateSession($documentId, $sessionId, $sessionToken, $guestName);
+ }
+
}
diff --git a/lib/Db/SessionMapper.php b/lib/Db/SessionMapper.php
index 87e305cff..c162d82ae 100644
--- a/lib/Db/SessionMapper.php
+++ b/lib/Db/SessionMapper.php
@@ -30,6 +30,10 @@ use OCP\AppFramework\Db\QBMapper;
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\IDBConnection;
+/**
+ * @method Session update(Session $session)
+ * @method Session insert(Session $session)
+ */
class SessionMapper extends QBMapper {
public function __construct(IDBConnection $db) {
diff --git a/lib/Service/ApiService.php b/lib/Service/ApiService.php
index a98d957ee..2b0280ece 100644
--- a/lib/Service/ApiService.php
+++ b/lib/Service/ApiService.php
@@ -61,7 +61,8 @@ class ApiService {
try {
$this->documentService->checkSharePermissions($token, Constants::PERMISSION_UPDATE);
$readOnly = false;
- } catch (NotFoundException $e) {}
+ } catch (NotFoundException $e) {
+ }
} else if ($fileId) {
$file = $this->documentService->getFileById($fileId);
$readOnly = !$file->isUpdateable();
@@ -77,7 +78,8 @@ class ApiService {
if (count($activeSessions) === 0 || $forceRecreate) {
try {
$this->documentService->resetDocument($file->getId(), $forceRecreate);
- } catch (DocumentHasUnsavedChangesException $e) {}
+ } catch (DocumentHasUnsavedChangesException $e) {
+ }
}
$document = $this->documentService->createDocument($file);
@@ -113,7 +115,8 @@ class ApiService {
if (count($activeSessions) === 0) {
try {
$this->documentService->resetDocument($documentId);
- } catch (DocumentHasUnsavedChangesException $e) {}
+ } catch (DocumentHasUnsavedChangesException $e) {
+ }
}
return new DataResponse([]);
}
@@ -167,4 +170,15 @@ class ApiService {
'document' => $document
]);
}
+
+ public function updateSession(int $documentId, int $sessionId, string $sessionToken, string $guestName) {
+ if (!$this->sessionService->isValidSession($documentId, $sessionId, $sessionToken)) {
+ return new DataResponse([], 500);
+ }
+
+ if ($guestName === '') {
+ return new DataResponse([ 'message' => 'A guest name needs to be provided'], 500);
+ }
+ return $this->sessionService->updateSession($documentId, $sessionId, $sessionToken, $guestName);
+ }
}
diff --git a/lib/Service/SessionService.php b/lib/Service/SessionService.php
index fe796955c..b4eb393dd 100644
--- a/lib/Service/SessionService.php
+++ b/lib/Service/SessionService.php
@@ -60,7 +60,9 @@ class SessionService {
$color = $avatarGenerator->getGuestAvatar($userName)->avatarBackgroundColor($userName);
$color = sprintf("#%02x%02x%02x", $color->r, $color->g, $color->b);
$session->setColor($color);
- $session->setGuestName($guestName);
+ if ($this->userId === null) {
+ $session->setGuestName($guestName);
+ }
$session->setLastContact($this->timeFactory->getTime());
return $this->sessionMapper->insert($session);
}
@@ -102,8 +104,20 @@ class SessionService {
return true;
}
- public function cleanupSession() {
- // find expired sessions
- // remove them
+ /**
+ * @param $documentId
+ * @param $sessionId
+ * @param $sessionToken
+ * @param $guestName
+ * @return Session
+ * @throws DoesNotExistException
+ */
+ public function updateSession(int $documentId, int $sessionId, string $sessionToken, string $guestName): Session {
+ if ($this->userId !== null) {
+ throw new \Exception('Logged in users cannot set a guest name');
+ }
+ $session = $this->sessionMapper->find($documentId, $sessionId, $sessionToken);
+ $session->setGuestName($guestName);
+ return $this->sessionMapper->update($session);
}
}