Skip to content
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
8 changes: 7 additions & 1 deletion lib/Listener/UserDeletedListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,19 @@
namespace OCA\Talk\Listener;

use OCA\Talk\Manager;
use OCA\Talk\Model\Attendee;
use OCA\Talk\Service\PollService;
use OCP\EventDispatcher\Event;
use OCP\EventDispatcher\IEventListener;
use OCP\User\Events\UserDeletedEvent;

class UserDeletedListener implements IEventListener {
private Manager $manager;
private PollService $pollService;

public function __construct(Manager $manager) {
public function __construct(Manager $manager, PollService $pollService) {
$this->manager = $manager;
$this->pollService = $pollService;
}

public function handle(Event $event): void {
Expand All @@ -43,5 +47,7 @@ public function handle(Event $event): void {

$user = $event->getUser();
$this->manager->removeUserFromAllRooms($user);

$this->pollService->neutralizeDeletedUser(Attendee::ACTOR_USERS, $user->getUID());
}
}
20 changes: 20 additions & 0 deletions lib/Service/PollService.php
Original file line number Diff line number Diff line change
Expand Up @@ -333,4 +333,24 @@ public function updateDisplayNameForActor(string $actorType, string $actorId, st
->andWhere($update->expr()->eq('actor_id', $update->createNamedParameter($actorId)));
$update->executeStatement();
}

public function neutralizeDeletedUser(string $actorType, string $actorId): void {
$update = $this->connection->getQueryBuilder();
$update->update('talk_polls')
->set('display_name', $update->createNamedParameter(''))
->set('actor_type', $update->createNamedParameter('deleted_users'))
->set('actor_id', $update->createNamedParameter('deleted_users'))
->where($update->expr()->eq('actor_type', $update->createNamedParameter($actorType)))
->andWhere($update->expr()->eq('actor_id', $update->createNamedParameter($actorId)));
$update->executeStatement();

$update = $this->connection->getQueryBuilder();
$update->update('talk_poll_votes')
->set('display_name', $update->createNamedParameter(''))
->set('actor_type', $update->createNamedParameter('deleted_users'))
->set('actor_id', $update->createNamedParameter('deleted_users'))
->where($update->expr()->eq('actor_type', $update->createNamedParameter($actorType)))
->andWhere($update->expr()->eq('actor_id', $update->createNamedParameter($actorId)));
$update->executeStatement();
}
}
10 changes: 9 additions & 1 deletion src/components/AvatarWrapper/AvatarWrapperSmall.vue
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@
<div v-if="iconClass"
class="icon"
:class="[`avatar-${sizeToString}px`, iconClass]" />
<div v-else-if="isDeletedUser"
class="guest"
:class="`avatar-${sizeToString}px`">
X
</div>
<NcAvatar v-else-if="!isGuest"
:user="id"
:display-name="name"
Expand Down Expand Up @@ -98,7 +103,7 @@ export default {
computed: {
// Determines which icon is displayed
iconClass() {
if (!this.source || this.source === 'users' || this.isGuest) {
if (!this.source || this.source === 'users' || this.isGuest || this.isDeletedUser) {
return ''
}
if (this.source === 'emails') {
Expand All @@ -110,6 +115,9 @@ export default {
isGuest() {
return this.source === 'guests'
},
isDeletedUser() {
return this.source === 'deleted_users'
},
firstLetterOfGuestName() {
const customName = this.name !== t('spreed', 'Guest') ? this.name : '?'
return customName.charAt(0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ export default {
return t('spreed', 'Guest')
}

if (item.actorType === 'deleted_users') {
return t('spreed', 'Deleted user')
}

return item.actorDisplayName
},
},
Expand Down
53 changes: 53 additions & 0 deletions tests/integration/features/chat/poll.feature
Original file line number Diff line number Diff line change
Expand Up @@ -589,3 +589,56 @@ Feature: chat/poll
| options | ["Empty question is not","allowed either"] |
| resultMode | public |
| maxVotes | unlimited |

Scenario: Deleting a user neutralizes their details
Given user "participant1" creates room "room" (v4)
| roomType | 2 |
| roomName | room |
And user "participant1" adds user "participant2" to room "room" with 200 (v4)
And user "participant2" creates a poll in room "room" with 201
| question | What is the question? |
| options | ["Where are you?","How much is the fish?"] |
| resultMode | public |
| maxVotes | unlimited |
And user "participant2" votes for options "[0]" on poll "What is the question?" in room "room" with 200
| id | POLL_ID(What is the question?) |
| question | What is the question? |
| options | ["Where are you?","How much is the fish?"] |
| votes | {"option-0":1} |
| numVoters | 1 |
| resultMode | public |
| maxVotes | unlimited |
| actorType | users |
| actorId | participant2 |
| actorDisplayName | participant2-displayname |
| status | open |
| votedSelf | [0] |
And user "participant2" closes poll "What is the question?" in room "room" with 200
| id | POLL_ID(What is the question?) |
| question | What is the question? |
| options | ["Where are you?","How much is the fish?"] |
| votes | {"option-0":1} |
| numVoters | 1 |
| resultMode | public |
| maxVotes | unlimited |
| actorType | users |
| actorId | participant2 |
| actorDisplayName | participant2-displayname |
| status | closed |
| votedSelf | [0] |
| details | [{"actorType":"users","actorId":"participant2","actorDisplayName":"participant2-displayname","optionId":0}] |
When user "participant2" is deleted
Then user "participant1" sees poll "What is the question?" in room "room" with 200
| id | POLL_ID(What is the question?) |
| question | What is the question? |
| options | ["Where are you?","How much is the fish?"] |
| votes | {"option-0":1} |
| numVoters | 1 |
| resultMode | public |
| maxVotes | unlimited |
| actorType | deleted_users |
| actorId | deleted_users |
| actorDisplayName | |
| status | closed |
| votedSelf | [] |
| details | [{"actorType":"deleted_users","actorId":"deleted_users","actorDisplayName":"","optionId":0}] |
22 changes: 22 additions & 0 deletions tests/integration/features/reaction/react.feature
Original file line number Diff line number Diff line change
Expand Up @@ -164,3 +164,25 @@ Feature: reaction/react
And user "participant1" sees the following messages in room "room" with 200
| room | actorType | actorId | actorDisplayName | message | messageParameters | reactions |
| room | users | participant1 | participant1-displayname | Message deleted by you | {"actor":{"type":"user","id":"participant1","name":"participant1-displayname"}} | [] |

Scenario: Deleting a user neutralizes their details
Given user "participant1" creates room "room" (v4)
| roomType | 3 |
| roomName | room |
And user "participant1" adds user "participant2" to room "room" with 200 (v4)
And user "participant1" sends message "Message 1" to room "room" with 201
And user "participant2" react with "👍" on message "Message 1" to room "room" with 201
| actorType | actorId | actorDisplayName | reaction |
| users | participant2 | participant2-displayname | 👍 |
And user "participant2" react with "👎" on message "Message 1" to room "room" with 201
| actorType | actorId | actorDisplayName | reaction |
| users | participant2 | participant2-displayname | 👎 |
| users | participant2 | participant2-displayname | 👍 |
When user "participant2" is deleted
And user "participant1" retrieve reactions "👎" of message "Message 1" in room "room" with 200
| actorType | actorId | actorDisplayName | reaction |
| deleted_users | deleted_users | | 👎 |
And user "participant1" retrieve reactions "all" of message "Message 1" in room "room" with 200
| actorType | actorId | actorDisplayName | reaction |
| deleted_users | deleted_users | | 👎 |
| deleted_users | deleted_users | | 👍 |