Browse Source

fix(ban): Add display name to the database

Signed-off-by: Joas Schilling <coding@schilljs.com>
pull/12735/head
Joas Schilling 1 year ago
parent
commit
c2628bb02f
No known key found for this signature in database GPG Key ID: 74434EFE0D2E2205
  1. 7
      lib/Controller/BanController.php
  2. 16
      lib/Migration/Version20000Date20240621150335.php
  3. 10
      lib/Model/Ban.php
  4. 2
      lib/ResponseDefinitions.php
  5. 20
      lib/Service/BanService.php
  6. 8
      openapi-full.json
  7. 8
      openapi.json
  8. 2
      src/types/openapi/openapi-full.ts
  9. 2
      src/types/openapi/openapi.ts
  10. 18
      tests/integration/features/conversation-1/ban.feature

7
lib/Controller/BanController.php

@ -52,13 +52,12 @@ class BanController extends AEnvironmentAwareController {
public function banActor(string $actorType, string $actorId, string $internalNote = ''): DataResponse {
try {
$moderator = $this->participant->getAttendee();
$moderatorActorType = $moderator->getActorType();
$moderatorActorId = $moderator->getActorId();
$ban = $this->banService->createBan(
$this->room,
$moderatorActorType,
$moderatorActorId,
$moderator->getActorType(),
$moderator->getActorId(),
$moderator->getDisplayName(),
$actorType,
$actorId,
$this->timeFactory->getDateTime(),

16
lib/Migration/Version20000Date20240621150335.php

@ -34,19 +34,27 @@ class Version20000Date20240621150335 extends SimpleMigrationStep {
]);
$table->addColumn('moderator_actor_type', Types::STRING, [
'notnull' => true,
'length' => 64,
'length' => 32,
]);
$table->addColumn('moderator_actor_id', Types::STRING, [
'notnull' => true,
'length' => 64,
'length' => 255,
]);
$table->addColumn('moderator_displayname', Types::STRING, [
'notnull' => false,
'length' => 255,
]);
$table->addColumn('banned_actor_type', Types::STRING, [
'length' => 64,
'notnull' => true,
'length' => 32,
]);
$table->addColumn('banned_actor_id', Types::STRING, [
'length' => 64,
'notnull' => true,
'length' => 255,
]);
$table->addColumn('banned_displayname', Types::STRING, [
'notnull' => false,
'length' => 255,
]);
$table->addColumn('room_id', Types::BIGINT, [
'unsigned' => true,

10
lib/Model/Ban.php

@ -20,12 +20,16 @@ use OCP\AppFramework\Db\Entity;
* @method string getModeratorActorType()
* @method void setModeratorActorId(string $moderatorActorId)
* @method string getModeratorActorId()
* @method void setModeratorDisplayname(?string $moderatorDisplayname)
* @method null|string getModeratorDisplayname()
* @method void setRoomId(int $roomId)
* @method int getRoomId()
* @method void setBannedActorType(string $bannedActorType)
* @method string getBannedActorType()
* @method void setBannedActorId(string $bannedActorId)
* @method string getBannedActorId()
* @method void setBannedDisplayname(?string $bannedDisplayname)
* @method null|string getBannedDisplayname()
* @method void setBannedTime(\DateTime $bannedTime)
* @method \DateTime getBannedTime()
* @method void setInternalNote(null|string $internalNote)
@ -36,9 +40,11 @@ class Ban extends Entity implements \JsonSerializable {
protected string $moderatorActorType = '';
protected string $moderatorActorId = '';
protected ?string $moderatorDisplayname = null;
protected int $roomId = 0;
protected string $bannedActorType = '';
protected string $bannedActorId = '';
protected ?string $bannedDisplayname = null;
protected ?\DateTime $bannedTime = null;
protected ?string $internalNote = null;
@ -46,9 +52,11 @@ class Ban extends Entity implements \JsonSerializable {
$this->addType('id', 'int');
$this->addType('moderatorActorType', 'string');
$this->addType('moderatorActorId', 'string');
$this->addType('moderatorDisplayname', 'string');
$this->addType('roomId', 'int');
$this->addType('bannedActorType', 'string');
$this->addType('bannedActorId', 'string');
$this->addType('bannedDisplayname', 'string');
$this->addType('bannedTime', 'datetime');
$this->addType('internalNote', 'string');
}
@ -61,8 +69,10 @@ class Ban extends Entity implements \JsonSerializable {
'id' => $this->getId(),
'moderatorActorType' => $this->getModeratorActorType(),
'moderatorActorId' => $this->getModeratorActorId(),
'moderatorDisplayName' => $this->getModeratorDisplayname() ?? $this->getModeratorActorId(),
'bannedActorType' => $this->getBannedActorType(),
'bannedActorId' => $this->getBannedActorId(),
'bannedDisplayName' => $this->getBannedDisplayname() ?? $this->getBannedActorId(),
'bannedTime' => $this->getBannedTime()->getTimestamp(),
'internalNote' => $this->getInternalNote() ?? '',
];

2
lib/ResponseDefinitions.php

@ -14,8 +14,10 @@ namespace OCA\Talk;
* id: int,
* moderatorActorType: string,
* moderatorActorId: string,
* moderatorDisplayName: string,
* bannedActorType: string,
* bannedActorId: string,
* bannedDisplayName: string,
* bannedTime: int,
* internalNote: string,
* }

20
lib/Service/BanService.php

@ -16,6 +16,7 @@ use OCA\Talk\Model\Ban;
use OCA\Talk\Model\BanMapper;
use OCA\Talk\Room;
use OCP\AppFramework\Db\DoesNotExistException;
use OCP\IUserManager;
class BanService {
@ -23,6 +24,7 @@ class BanService {
protected BanMapper $banMapper,
protected Manager $manager,
protected ParticipantService $participantService,
protected IUserManager $userManager,
) {
}
@ -31,7 +33,7 @@ class BanService {
*
* @throws \InvalidArgumentException
*/
public function createBan(Room $room, string $moderatorActorType, string $moderatorActorId, string $bannedActorType, string $bannedActorId, DateTime $bannedTime, string $internalNote): Ban {
public function createBan(Room $room, string $moderatorActorType, string $moderatorActorId, string $moderatorDisplayname, string $bannedActorType, string $bannedActorId, DateTime $bannedTime, string $internalNote): Ban {
if (empty($bannedActorId) || empty($bannedActorType)) {
throw new \InvalidArgumentException('bannedActor');
}
@ -44,23 +46,35 @@ class BanService {
throw new \InvalidArgumentException('self');
}
/** @var ?string $displayname */
$displayname = null;
if (in_array($bannedActorType, [Attendee::ACTOR_GUESTS, Attendee::ACTOR_USERS, Attendee::ACTOR_FEDERATED_USERS], true)) {
try {
$bannedParticipant = $this->participantService->getParticipantByActor($room, $bannedActorType, $bannedActorId);
$displayname = $bannedParticipant->getAttendee()->getDisplayName();
if ($bannedParticipant->hasModeratorPermissions()) {
throw new \InvalidArgumentException('moderator');
}
} catch (ParticipantNotFoundException) {
// No failure if the banned actor is not in the room yet/anymore
if ($bannedActorType === Attendee::ACTOR_USERS) {
$displayname = $this->userManager->getDisplayName($bannedActorId);
}
}
}
if ($displayname === null || $displayname === '') {
$displayname = $bannedActorId;
}
$ban = new Ban();
$ban->setModeratorActorId($moderatorActorId);
$ban->setModeratorActorType($moderatorActorType);
$ban->setModeratorActorId($moderatorActorId);
$ban->setModeratorDisplayname($moderatorDisplayname);
$ban->setRoomId($room->getId());
$ban->setBannedActorId($bannedActorId);
$ban->setBannedActorType($bannedActorType);
$ban->setBannedActorId($bannedActorId);
$ban->setBannedDisplayname($displayname);
$ban->setBannedTime($bannedTime);
$ban->setInternalNote($internalNote);

8
openapi-full.json

@ -26,8 +26,10 @@
"id",
"moderatorActorType",
"moderatorActorId",
"moderatorDisplayName",
"bannedActorType",
"bannedActorId",
"bannedDisplayName",
"bannedTime",
"internalNote"
],
@ -42,12 +44,18 @@
"moderatorActorId": {
"type": "string"
},
"moderatorDisplayName": {
"type": "string"
},
"bannedActorType": {
"type": "string"
},
"bannedActorId": {
"type": "string"
},
"bannedDisplayName": {
"type": "string"
},
"bannedTime": {
"type": "integer",
"format": "int64"

8
openapi.json

@ -26,8 +26,10 @@
"id",
"moderatorActorType",
"moderatorActorId",
"moderatorDisplayName",
"bannedActorType",
"bannedActorId",
"bannedDisplayName",
"bannedTime",
"internalNote"
],
@ -42,12 +44,18 @@
"moderatorActorId": {
"type": "string"
},
"moderatorDisplayName": {
"type": "string"
},
"bannedActorType": {
"type": "string"
},
"bannedActorId": {
"type": "string"
},
"bannedDisplayName": {
"type": "string"
},
"bannedTime": {
"type": "integer",
"format": "int64"

2
src/types/openapi/openapi-full.ts

@ -1749,8 +1749,10 @@ export type components = {
id: number;
moderatorActorType: string;
moderatorActorId: string;
moderatorDisplayName: string;
bannedActorType: string;
bannedActorId: string;
bannedDisplayName: string;
/** Format: int64 */
bannedTime: number;
internalNote: string;

2
src/types/openapi/openapi.ts

@ -1264,8 +1264,10 @@ export type components = {
id: number;
moderatorActorType: string;
moderatorActorId: string;
moderatorDisplayName: string;
bannedActorType: string;
bannedActorId: string;
bannedDisplayName: string;
/** Format: int64 */
bannedTime: number;
internalNote: string;

18
tests/integration/features/conversation-1/ban.feature

@ -17,9 +17,9 @@ Feature: conversation/ban
And user "participant1" bans user "participant3" from room "room" with 200 (v1)
| internalNote | BannedP3 |
And user "participant1" sees the following bans in room "room" with 200 (v1)
| actorType | actorId | bannedActorType | bannedActorId | internalNote |
| users | participant1 | users | participant2 | BannedP2 |
| users | participant1 | users | participant3 | BannedP3 |
| moderatorActorType | moderatorActorId | moderatorDisplayName | bannedActorType | bannedActorId | bannedDisplayName | internalNote |
| users | participant1 | participant1-displayname | users | participant2 | participant2-displayname | BannedP2 |
| users | participant1 | participant1-displayname | users | participant3 | participant3-displayname | BannedP3 |
And user "participant2" joins room "room" with 403 (v4)
And user "participant3" joins room "room" with 403 (v4)
And user "participant1" unbans user "participant2" from room "room" with 200 (v1)
@ -88,13 +88,5 @@ Feature: conversation/ban
And user "participant1" bans user "participant2" from room "room" with 200 (v1)
| internalNote | BannedP2 |
And user "participant1" sees the following bans in room "room" with 200 (v1)
| actorType | actorId | bannedActorType | bannedActorId | internalNote |
| users | participant1 | users | participant2 | BannedP2 |
| moderatorActorType | moderatorActorId | moderatorDisplayName | bannedActorType | bannedActorId | bannedDisplayName | internalNote |
| users | participant1 | participant1-displayname | users | participant2 | participant2-displayname | BannedP2 |
Loading…
Cancel
Save