summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorJoas Schilling <coding@schilljs.com>2019-10-09 12:44:14 +0200
committerJoas Schilling <coding@schilljs.com>2019-10-10 11:19:22 +0200
commit1a3a6e85d0e36695774146d8779f144ee1cab4cb (patch)
tree92ddc5f61ec2974df15ba200b1c1265c9c85732c /lib
parent8aa2aa2efe53ca0f2cdcb1b7a05812cb9930e52e (diff)
Move GuestController to EnviromentAware
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/Controller/GuestController.php42
1 files changed, 10 insertions, 32 deletions
diff --git a/lib/Controller/GuestController.php b/lib/Controller/GuestController.php
index 53f033e61..c3e43cf38 100644
--- a/lib/Controller/GuestController.php
+++ b/lib/Controller/GuestController.php
@@ -24,66 +24,44 @@ declare(strict_types=1);
namespace OCA\Talk\Controller;
use Doctrine\DBAL\DBALException;
-use OCA\Talk\Exceptions\RoomNotFoundException;
use OCA\Talk\GuestManager;
-use OCA\Talk\Manager;
-use OCA\Talk\TalkSession;
+use OCA\Talk\Participant;
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\DataResponse;
-use OCP\AppFramework\OCSController;
use OCP\IRequest;
-class GuestController extends OCSController {
-
- /** @var string|null */
- private $userId;
-
- /** @var TalkSession */
- private $session;
-
- /** @var Manager */
- private $roomManager;
+class GuestController extends AEnvironmentAwareController {
/** @var GuestManager */
private $guestManager;
public function __construct(string $appName,
- ?string $UserId,
IRequest $request,
- TalkSession $session,
- Manager $roomManager,
GuestManager $guestManager) {
parent::__construct($appName, $request);
- $this->userId = $UserId;
- $this->session = $session;
- $this->roomManager = $roomManager;
$this->guestManager = $guestManager;
}
/**
* @PublicPage
+ * @RequireParticipant
*
- *
- * @param string $token
* @param string $displayName
* @return DataResponse
*/
- public function setDisplayName(string $token, string $displayName): DataResponse {
- if ($this->userId) {
- return new DataResponse([], Http::STATUS_FORBIDDEN);
+ public function setDisplayName(string $displayName): DataResponse {
+ $participant = $this->getParticipant();
+ if (!$participant instanceof Participant) {
+ return new DataResponse([], Http::STATUS_NOT_FOUND);
}
- $sessionId = $this->session->getSessionForRoom($token);
-
- try {
- $room = $this->roomManager->getRoomForSession($this->userId, $sessionId);
- } catch (RoomNotFoundException $exception) {
- return new DataResponse([], Http::STATUS_NOT_FOUND);
+ if (!$participant->isGuest()) {
+ return new DataResponse([], Http::STATUS_FORBIDDEN);
}
try {
- $this->guestManager->updateName($room, $sessionId, $displayName);
+ $this->guestManager->updateName($this->getRoom(), $participant->getSessionId(), $displayName);
} catch (DBALException $e) {
return new DataResponse([], Http::STATUS_INTERNAL_SERVER_ERROR);
}