Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[stable24] Fix reactions endpoints not accessible by guests #7217

Merged
merged 3 commits into from
Apr 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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