From d3209668027849086b1ddf839666ee3e8a87f35f Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 19 Sep 2017 16:29:30 +0200 Subject: [PATCH 1/4] Fix displaying guest entries in the sidebar Signed-off-by: Joas Schilling --- js/views/participantview.js | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/js/views/participantview.js b/js/views/participantview.js index c96333b929c..0111d3e272e 100644 --- a/js/views/participantview.js +++ b/js/views/participantview.js @@ -32,7 +32,7 @@ var ITEM_TEMPLATE = '' + '' + '
' + - ' {{displayName}}' + + ' {{name}}' + '{{#if participantIsOwner}}(' + t('spreed', 'moderator') + '){{/if}}' + '{{#if participantIsModerator}}(' + t('spreed', 'moderator') + '){{/if}}' + '
'+ @@ -101,9 +101,6 @@ }); }, templateContext: function() { - console.log(this.model.get('userId')); - console.log(this.model.get('participantType') !== 1); - console.log(this.model.get('userId') !== oc_current_user); var canModerate = this.model.get('participantType') !== 1 && // can not moderate owners this.model.get('userId') !== oc_current_user && // can not moderate yourself (OCA.SpreedMe.app.activeRoom.get('participantType') === 1 || // current user must be owner @@ -111,6 +108,7 @@ return { canModerate: canModerate, + name: this.model.get('userId').length ? this.model.get('displayName') : t('spreed', 'Guest'), participantIsUser: this.model.get('participantType') === 3, participantIsModerator: this.model.get('participantType') === 2, participantIsOwner: this.model.get('participantType') === 1 @@ -119,10 +117,10 @@ onRender: function() { this.$el.find('.avatar').each(function() { var element = $(this); - if (element.data('displayname')) { + if (element.data('displayname').length) { element.avatar(element.data('user-id'), 32, undefined, false, undefined, element.data('displayname')); } else { - element.avatar(element.data('user-id'), 32); + element.avatar(null, 32); } }); From 960214ff3dd41bf7d440a3a3eaa6532639597541 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 19 Sep 2017 16:37:08 +0200 Subject: [PATCH 2/4] Use the variables Signed-off-by: Joas Schilling --- js/views/participantview.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/js/views/participantview.js b/js/views/participantview.js index 0111d3e272e..65e55d6c676 100644 --- a/js/views/participantview.js +++ b/js/views/participantview.js @@ -101,17 +101,17 @@ }); }, templateContext: function() { - var canModerate = this.model.get('participantType') !== 1 && // can not moderate owners + var canModerate = this.model.get('participantType') !== OCA.SpreedMe.app.OWNER && // can not moderate owners this.model.get('userId') !== oc_current_user && // can not moderate yourself - (OCA.SpreedMe.app.activeRoom.get('participantType') === 1 || // current user must be owner - OCA.SpreedMe.app.activeRoom.get('participantType') === 2); // or moderator. + (OCA.SpreedMe.app.activeRoom.get('participantType') === OCA.SpreedMe.app.OWNER || // current user must be owner + OCA.SpreedMe.app.activeRoom.get('participantType') === OCA.SpreedMe.app.MODERATOR); // or moderator. return { canModerate: canModerate, name: this.model.get('userId').length ? this.model.get('displayName') : t('spreed', 'Guest'), - participantIsUser: this.model.get('participantType') === 3, - participantIsModerator: this.model.get('participantType') === 2, - participantIsOwner: this.model.get('participantType') === 1 + participantIsUser: this.model.get('participantType') === OCA.SpreedMe.app.USER, + participantIsModerator: this.model.get('participantType') === OCA.SpreedMe.app.MODERATOR, + participantIsOwner: this.model.get('participantType') === OCA.SpreedMe.app.OWNER }; }, onRender: function() { @@ -155,7 +155,7 @@ this.ui.menu.toggleClass('open', this.menuShown); }, promoteToModerator: function() { - if (this.model.get('participantType') !== 3) { + if (this.model.get('participantType') !== OCA.SpreedMe.app.USER) { return; } @@ -177,7 +177,7 @@ }); }, demoteFromModerator: function() { - if (this.model.get('participantType') !== 2) { + if (this.model.get('participantType') !== OCA.SpreedMe.app.MODERATOR) { return; } @@ -199,7 +199,7 @@ }); }, removeParticipant: function() { - if (this.model.get('participantType') === 1) { + if (this.model.get('participantType') === OCA.SpreedMe.app.OWNER) { return; } From 18651b9d4f760ca540fa4bc1746f6b809f4bc20c Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 19 Sep 2017 16:46:54 +0200 Subject: [PATCH 3/4] Fix deleting of guests Signed-off-by: Joas Schilling --- appinfo/routes.php | 9 ++++++++ js/views/participantview.js | 15 +++++++------ lib/Controller/RoomController.php | 35 +++++++++++++++++++++++++++++ lib/Room.php | 37 +++++++++++++++++++++++++++++++ 4 files changed, 89 insertions(+), 7 deletions(-) diff --git a/appinfo/routes.php b/appinfo/routes.php index fe5fd350b93..3b586de6ee4 100644 --- a/appinfo/routes.php +++ b/appinfo/routes.php @@ -175,6 +175,15 @@ 'token' => '^[a-z0-9]{4,30}$', ], ], + [ + 'name' => 'Room#removeGuestFromRoom', + 'url' => '/api/{apiVersion}/room/{token}/participants/guests', + 'verb' => 'DELETE', + 'requirements' => [ + 'apiVersion' => 'v1', + 'token' => '^[a-z0-9]{4,30}$', + ], + ], [ 'name' => 'Room#promoteModerator', 'url' => '/api/{apiVersion}/room/{token}/moderators', diff --git a/js/views/participantview.js b/js/views/participantview.js index 65e55d6c676..a282be7317a 100644 --- a/js/views/participantview.js +++ b/js/views/participantview.js @@ -203,17 +203,18 @@ return; } - if (this.model.get('userId') === '') { - console.log('Guests can currently not be deleted'); - return; - } + var self = this, + participantId = this.model.get('userId'), + endpoint = '/participants'; - var participantId = this.model.get('userId'), - self = this; + if (this.model.get('participantType') === OCA.SpreedMe.app.GUEST) { + participantId = this.model.get('sessionId'); + endpoint += '/guests'; + } $.ajax({ type: 'DELETE', - url: OC.linkToOCS('apps/spreed/api/v1/room', 2) + OCA.SpreedMe.app.activeRoom.get('token') + '/participants', + url: OC.linkToOCS('apps/spreed/api/v1/room', 2) + OCA.SpreedMe.app.activeRoom.get('token') + endpoint, data: { participant: participantId }, diff --git a/lib/Controller/RoomController.php b/lib/Controller/RoomController.php index d1b69e554a3..2a74f7626bc 100644 --- a/lib/Controller/RoomController.php +++ b/lib/Controller/RoomController.php @@ -566,6 +566,41 @@ public function removeSelfFromRoom($token) { return new DataResponse([]); } + /** + * @NoAdminRequired + * + * @param string $token + * @param string $participant + * @return DataResponse + */ + public function removeGuestFromRoom($token, $participant) { + try { + $room = $this->manager->getRoomForParticipantByToken($token, $this->userId); + $currentParticipant = $room->getParticipant($this->userId); + } catch (RoomNotFoundException $e) { + return new DataResponse([], Http::STATUS_NOT_FOUND); + } catch (\RuntimeException $e) { + return new DataResponse([], Http::STATUS_NOT_FOUND); + } + + if (!in_array($currentParticipant->getParticipantType(), [Participant::OWNER, Participant::MODERATOR], true)) { + return new DataResponse([], Http::STATUS_FORBIDDEN); + } + + try { + $targetParticipant = $room->getParticipantBySession($participant); + } catch (\RuntimeException $e) { + return new DataResponse([], Http::STATUS_NOT_FOUND); + } + + if ($targetParticipant->getParticipantType() !== Participant::GUEST) { + return new DataResponse([], Http::STATUS_FORBIDDEN); + } + + $room->removeParticipantBySession($targetParticipant); + return new DataResponse([]); + } + /** * @NoAdminRequired * diff --git a/lib/Room.php b/lib/Room.php index 81768e111ca..7943ce97308 100644 --- a/lib/Room.php +++ b/lib/Room.php @@ -151,6 +151,32 @@ public function getParticipant($userId) { return new Participant($this->db, $this, $row['userId'], (int) $row['participantType'], (int) $row['lastPing'], $row['sessionId']); } + /** + * @param string $sessionId + * @return Participant + * @throws \RuntimeException When the user is not a participant + */ + public function getParticipantBySession($sessionId) { + if (!is_string($sessionId) || $sessionId === '') { + throw new \RuntimeException('Not a user'); + } + + $query = $this->db->getQueryBuilder(); + $query->select('*') + ->from('spreedme_room_participants') + ->where($query->expr()->eq('sessionId', $query->createNamedParameter($sessionId))) + ->andWhere($query->expr()->eq('roomId', $query->createNamedParameter($this->getId()))); + $result = $query->execute(); + $row = $result->fetch(); + $result->closeCursor(); + + if ($row === false) { + throw new \RuntimeException('User is not a participant'); + } + + return new Participant($this->db, $this, $row['userId'], (int) $row['participantType'], (int) $row['lastPing'], $row['sessionId']); + } + public function deleteRoom() { $query = $this->db->getQueryBuilder(); @@ -274,6 +300,17 @@ public function removeUser(IUser $user) { $query->execute(); } + /** + * @param Participant $participant + */ + public function removeParticipantBySession(Participant $participant) { + $query = $this->db->getQueryBuilder(); + $query->delete('spreedme_room_participants') + ->where($query->expr()->eq('roomId', $query->createNamedParameter($this->getId(), IQueryBuilder::PARAM_INT))) + ->andWhere($query->expr()->eq('sessionId', $query->createNamedParameter($participant->getSessionId()))); + $query->execute(); + } + /** * @param string $userId * @return string From bcbc315ce60255b219c4929044521d96f2d50c3a Mon Sep 17 00:00:00 2001 From: Ivan Sein Date: Tue, 19 Sep 2017 19:03:29 +0200 Subject: [PATCH 4/4] Fix guest avatar. Signed-off-by: Ivan Sein --- js/views/participantview.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/js/views/participantview.js b/js/views/participantview.js index a282be7317a..4d03304400a 100644 --- a/js/views/participantview.js +++ b/js/views/participantview.js @@ -120,7 +120,8 @@ if (element.data('displayname').length) { element.avatar(element.data('user-id'), 32, undefined, false, undefined, element.data('displayname')); } else { - element.avatar(null, 32); + element.imageplaceholder('?', undefined, 32); + element.css('background-color', '#b9b9b9'); } });