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

fix(talk): Only invite guest accounts to open Talk conversations #5688

Merged
merged 1 commit into from
Jan 18, 2024
Merged
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
35 changes: 18 additions & 17 deletions src/services/talkService.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,43 +78,44 @@
return
}
try {
const { data: { ocs: { data: room } } } = await HTTPClient.get(generateOcsUrl('apps/spreed/api/' + apiVersion + '/', 2) + 'room/' + token)

Check warning on line 81 in src/services/talkService.js

View check run for this annotation

Codecov / codecov/patch

src/services/talkService.js#L81

Added line #L81 was not covered by tests
const participantsResponse = await HTTPClient.get(generateOcsUrl('apps/spreed/api/' + apiVersion + '/', 2) + 'room/' + token + '/participants')
// Ignore if the actor isn't owner of the conversation
if (!participantsResponse.data.ocs.data.some(participant => participant.actorId === getCurrentUser().uid && participant.participantType <= 2)) {
logger.debug('Current user is not a moderator or owner', { currentUser: getCurrentUser().uid, conversation: participantsResponse.data.ocs.data })
return
}
console.info('room', room)

Check warning on line 88 in src/services/talkService.js

View check run for this annotation

Codecov / codecov/patch

src/services/talkService.js#L88

Added line #L88 was not covered by tests

for (const attendee of eventComponent.getAttendeeIterator()) {
logger.debug('Processing attendee', { attendee })
if (['GROUP', 'RESOURCE', 'ROOM'].includes(attendee.userType)) {
continue
}

let participantId = removeMailtoPrefix(attendee.email)
let attendeeSource = 'emails'
const participantId = removeMailtoPrefix(attendee.email)

Check warning on line 96 in src/services/talkService.js

View check run for this annotation

Codecov / codecov/patch

src/services/talkService.js#L96

Added line #L96 was not covered by tests
try {
// Map attendee email to Nextcloud user uid
const searchResult = await HTTPClient.get(generateOcsUrl('core/autocomplete/', 2) + 'get?search=' + encodeURIComponent(participantId) + '&itemType=&itemId=%20&shareTypes[]=0&limit=2')
// Only map if there is exactly one result. Use email if there are none or more results.
if (searchResult.data.ocs.data.length === 1) {
participantId = searchResult.data.ocs.data[0].id
attendeeSource = 'users'
// Only map if there is exactly one result
if (searchResult.data.ocs.data.length === 1 && searchResult.data.ocs.data[0].id !== getCurrentUser().uid) {
await HTTPClient.post(generateOcsUrl('apps/spreed/api/' + apiVersion + '/', 2) + 'room/' + token + '/participants', {

Check warning on line 102 in src/services/talkService.js

View check run for this annotation

Codecov / codecov/patch

src/services/talkService.js#L101-L102

Added lines #L101 - L102 were not covered by tests
newParticipant: searchResult.data.ocs.data[0].id,
source: 'users',
})
} else if (searchResult.data.ocs.data[0]?.id === getCurrentUser().uid) {
logger.debug('Skipping organizer ' + searchResult.data.ocs.data[0].id)
} else if (room.type === 3) {
await HTTPClient.post(generateOcsUrl('apps/spreed/api/' + apiVersion + '/', 2) + 'room/' + token + '/participants', {

Check warning on line 109 in src/services/talkService.js

View check run for this annotation

Codecov / codecov/patch

src/services/talkService.js#L106-L109

Added lines #L106 - L109 were not covered by tests
newParticipant: participantId,
source: 'emails',
})
} else {
logger.debug('Attendee ' + participantId + ' is not a Nextcloud user')
logger.debug('Attendee ' + participantId + ' ignored as Talk participant')

Check warning on line 114 in src/services/talkService.js

View check run for this annotation

Codecov / codecov/patch

src/services/talkService.js#L114

Added line #L114 was not covered by tests
}
} catch (error) {
logger.info('Could not find user data for attendee ' + participantId, { error })
logger.info('Could not add attendee ' + participantId + ' as Talk participant', { error })

Check warning on line 117 in src/services/talkService.js

View check run for this annotation

Codecov / codecov/patch

src/services/talkService.js#L117

Added line #L117 was not covered by tests
}

if (attendeeSource === 'users' && participantId === getCurrentUser().uid) {
logger.debug('Skipping organizer')
continue
}
await HTTPClient.post(generateOcsUrl('apps/spreed/api/' + apiVersion + '/', 2) + 'room/' + token + '/participants', {
newParticipant: participantId,
source: attendeeSource,
})
}
} catch (error) {
logger.warn('Could not update Talk room attendees', { error })
Expand Down
Loading