Skip to content

Commit

Permalink
Merge pull request #7217 from nextcloud/backport/7205/stable24
Browse files Browse the repository at this point in the history
[stable24] Fix reactions endpoints not accessible by guests
  • Loading branch information
vitormattos authored Apr 25, 2022
2 parents b5f2b76 + 1c99458 commit 7751d00
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 7 deletions.
6 changes: 3 additions & 3 deletions lib/Controller/ReactionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function __construct(string $appName,
}

/**
* @NoAdminRequired
* @PublicPage
* @RequireParticipant
* @RequireReadWriteConversation
* @RequireModeratorOrNoLobby
Expand Down Expand Up @@ -75,7 +75,7 @@ public function react(int $messageId, string $reaction): DataResponse {
}

/**
* @NoAdminRequired
* @PublicPage
* @RequireParticipant
* @RequireReadWriteConversation
* @RequireModeratorOrNoLobby
Expand Down Expand Up @@ -103,7 +103,7 @@ public function delete(int $messageId, string $reaction): DataResponse {
}

/**
* @NoAdminRequired
* @PublicPage
* @RequireParticipant
* @RequireReadWriteConversation
* @RequireModeratorOrNoLobby
Expand Down
17 changes: 16 additions & 1 deletion src/components/MessagesList/MessagesGroup/Message/Message.vue
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ import EmojiPicker from '@nextcloud/vue/dist/Components/EmojiPicker'
import EmoticonOutline from 'vue-material-design-icons/EmoticonOutline.vue'
import Popover from '@nextcloud/vue/dist/Components/Popover'
import { showError, showSuccess, showWarning, TOAST_DEFAULT_TIMEOUT } from '@nextcloud/dialogs'
import { ATTENDEE } from '../../../../constants'

export default {
name: 'Message',
Expand Down Expand Up @@ -738,12 +739,26 @@ export default {
&& list[item].actorId === this.$store.getters.getActorId()) {
summary.unshift(t('spreed', 'You'))
} else {
summary.push(list[item].actorDisplayName)
summary.push(this.getDisplayNameForReaction(list[item]))
}
}

return summary.join(', ')
},

getDisplayNameForReaction(reaction) {
const displayName = reaction.actorDisplayName.trim()

if (reaction.actorType === ATTENDEE.ACTOR_TYPE.GUESTS) {
return this.$store.getters.getGuestNameWithGuestSuffix(this.token, reaction.actorId)
}

if (displayName === '') {
return t('spreed', 'Deleted user')
}

return displayName
},
},
}
</script>
Expand Down
8 changes: 8 additions & 0 deletions src/store/guestNameStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@ const getters = {
}
return t('spreed', 'Guest')
},

getGuestNameWithGuestSuffix: (state, getters) => (token, actorId) => {
const displayName = getters.getGuestName(token, actorId)
if (displayName === t('spreed', 'Guest')) {
return displayName
}
return t('spreed', '{guest} (guest)', { guest: displayName })
},
}

const mutations = {
Expand Down
1 change: 1 addition & 0 deletions tests/integration/features/bootstrap/FeatureContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -2300,6 +2300,7 @@ private function assertReactionList(?TableNode $formData): void {
$result = array_map(static function ($reaction, $list) use ($expected): array {
$list = array_map(function ($reaction) {
unset($reaction['timestamp']);
$reaction['actorId'] = ($reaction['actorType'] === 'guests') ? self::$sessionIdToUser[$reaction['actorId']] : (string) $reaction['actorId'];
return $reaction;
}, $list);
Assert::assertArrayHasKey($reaction, $expected, 'Not expected reaction: ' . $reaction);
Expand Down
16 changes: 13 additions & 3 deletions tests/integration/features/reaction/react.feature
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,14 @@ Feature: reaction/react
| users | participant1 | participant1-displayname | πŸ‘ |
| users | participant2 | participant2-displayname | πŸ‘ |
And user "participant1" react with "πŸš€" on message "Message 1" to room "room" with 201
Then user "guest" joins room "room" with 200 (v4)
And user "guest" react with "πŸ‘€" on message "Message 1" to room "room" with 201
Then user "participant1" sees the following messages in room "room" with 200
| room | actorType | actorId | actorDisplayName | message | messageParameters | reactions | reactionsSelf |
| room | users | participant1 | participant1-displayname | Message 1 | [] | {"πŸ‘":2,"πŸš€":1} | ["πŸ‘","πŸš€"] |
| room | actorType | actorId | actorDisplayName | message | messageParameters | reactions | reactionsSelf |
| room | users | participant1 | participant1-displayname | Message 1 | [] | {"πŸ‘":2,"πŸ‘€":1,"πŸš€":1} | ["πŸ‘","πŸš€"] |
Then user "participant1" sees the following system messages in room "room" with 200
| room | actorType | actorId | actorDisplayName | systemMessage |
| room | guests | guest | | reaction |
| room | users | participant1 | participant1-displayname | reaction |
| room | users | participant1 | participant1-displayname | reaction |
| room | users | participant2 | participant2-displayname | reaction |
Expand Down Expand Up @@ -66,17 +69,24 @@ Feature: reaction/react
And user "participant2" react with "πŸ‘" on message "Message 1" to room "room" with 201
| actorType | actorId | actorDisplayName | reaction |
| users | participant2 | participant2-displayname | πŸ‘ |
Then user "guest" joins room "room" with 200 (v4)
And user "guest" react with "πŸ‘€" on message "Message 1" to room "room" with 201
Then user "participant1" sees the following messages in room "room" with 200
| room | actorType | actorId | actorDisplayName | message | messageParameters | reactions |
| room | users | participant1 | participant1-displayname | Message 1 | [] | {"πŸ‘":1} |
| room | users | participant1 | participant1-displayname | Message 1 | [] | {"πŸ‘€":1,"πŸ‘":1} |
And user "participant2" delete react with "πŸ‘" on message "Message 1" to room "room" with 200
| actorType | actorId | actorDisplayName | reaction |
| guests | guest | | πŸ‘€ |
And user "guest" delete react with "πŸ‘€" on message "Message 1" to room "room" with 200
| actorType | actorId | actorDisplayName | reaction |
Then user "participant1" sees the following messages in room "room" with 200
| room | actorType | actorId | actorDisplayName | message | messageParameters | reactions |
| room | users | participant1 | participant1-displayname | Message 1 | [] | [] |
Then user "participant1" sees the following system messages in room "room" with 200
| room | actorType | actorId | actorDisplayName | systemMessage |
| room | guests | guest | | reaction_revoked |
| room | users | participant2 | participant2-displayname | reaction_revoked |
| room | guests | guest | | reaction_deleted |
| room | users | participant2 | participant2-displayname | reaction_deleted |
| room | users | participant1 | participant1-displayname | user_added |
| room | users | participant1 | participant1-displayname | conversation_created |
Expand Down

0 comments on commit 7751d00

Please sign in to comment.