mirror of
https://github.com/nextcloud/spreed.git
synced 2025-12-18 05:20:50 +01:00
fix(ban): Don't allow banning in one-to-one conversations
Signed-off-by: Joas Schilling <coding@schilljs.com>
This commit is contained in:
parent
d012784dde
commit
13bd181a9a
8 changed files with 27 additions and 13 deletions
|
|
@ -40,7 +40,7 @@ class BanController extends AEnvironmentAwareController {
|
|||
* @param 'users'|'guests'|'ip' $actorType Type of actor to ban, or `ip` when banning a clients remote address
|
||||
* @param string $actorId Actor ID or the IP address or range in case of type `ip`
|
||||
* @param string $internalNote Optional internal note (max. 4000 characters)
|
||||
* @return DataResponse<Http::STATUS_OK, TalkBan, array{}>|DataResponse<Http::STATUS_BAD_REQUEST, array{error: 'bannedActor'|'internalNote'|'moderator'|'self'}, array{}>
|
||||
* @return DataResponse<Http::STATUS_OK, TalkBan, array{}>|DataResponse<Http::STATUS_BAD_REQUEST, array{error: 'bannedActor'|'internalNote'|'moderator'|'self'|'room'}, array{}>
|
||||
*
|
||||
* 200: Ban successfully
|
||||
* 400: Actor information is invalid
|
||||
|
|
|
|||
|
|
@ -44,6 +44,10 @@ class BanService {
|
|||
* @throws \InvalidArgumentException
|
||||
*/
|
||||
public function createBan(Room $room, string $moderatorActorType, string $moderatorActorId, string $moderatorDisplayname, string $bannedActorType, string $bannedActorId, DateTime $bannedTime, string $internalNote): Ban {
|
||||
if (!in_array($room->getType(), [Room::TYPE_GROUP, Room::TYPE_PUBLIC], true)) {
|
||||
throw new \InvalidArgumentException('room');
|
||||
}
|
||||
|
||||
if (!in_array($bannedActorType, ['users', 'guests', 'ip'], true)) {
|
||||
throw new \InvalidArgumentException('bannedActor');
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2177,7 +2177,8 @@
|
|||
"bannedActor",
|
||||
"internalNote",
|
||||
"moderator",
|
||||
"self"
|
||||
"self",
|
||||
"room"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2064,7 +2064,8 @@
|
|||
"bannedActor",
|
||||
"internalNote",
|
||||
"moderator",
|
||||
"self"
|
||||
"self",
|
||||
"room"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2507,7 +2507,7 @@ export interface operations {
|
|||
meta: components["schemas"]["OCSMeta"];
|
||||
data: {
|
||||
/** @enum {string} */
|
||||
error: "bannedActor" | "internalNote" | "moderator" | "self";
|
||||
error: "bannedActor" | "internalNote" | "moderator" | "self" | "room";
|
||||
};
|
||||
};
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1988,7 +1988,7 @@ export interface operations {
|
|||
meta: components["schemas"]["OCSMeta"];
|
||||
data: {
|
||||
/** @enum {string} */
|
||||
error: "bannedActor" | "internalNote" | "moderator" | "self";
|
||||
error: "bannedActor" | "internalNote" | "moderator" | "self" | "room";
|
||||
};
|
||||
};
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1548,15 +1548,8 @@ class FeatureContext implements Context, SnippetAcceptingContext {
|
|||
|
||||
/**
|
||||
* @When /^user "([^"]*)" bans (user|group|email|remote|guest) "([^"]*)" from room "([^"]*)" with (\d+) \((v1)\)$/
|
||||
*
|
||||
* @param string $user
|
||||
* @param string $actorType
|
||||
* @param string $actorId
|
||||
* @param string $identifier
|
||||
* @param int $statusCode
|
||||
* @param string $apiVersion
|
||||
*/
|
||||
public function userBansUserFromRoom(string $user, string $actorType, string $actorId, string $identifier, int $statusCode, string $apiVersion = 'v1', TableNode $internalNote): void {
|
||||
public function userBansUserFromRoom(string $user, string $actorType, string $actorId, string $identifier, int $statusCode, string $apiVersion = 'v1', ?TableNode $internalNote = null): void {
|
||||
if ($actorType === 'guest') {
|
||||
$actorId = self::$sessionNameToActorId[$actorId];
|
||||
} elseif ($actorId === 'stranger') {
|
||||
|
|
@ -1595,6 +1588,12 @@ class FeatureContext implements Context, SnippetAcceptingContext {
|
|||
self::$userToBanId[self::$identifierToToken[$identifier]] ??= [];
|
||||
self::$userToBanId[self::$identifierToToken[$identifier]][$actorType] ??= [];
|
||||
self::$userToBanId[self::$identifierToToken[$identifier]][$actorType][$actorId] = $data['id'];
|
||||
} elseif ($internalNote !== null) {
|
||||
$internalNoteData = $internalNote->getRowsHash();
|
||||
if (isset($internalNoteData['error'])) {
|
||||
$data = $this->getDataFromResponse($this->response);
|
||||
Assert::assertSame($internalNoteData['error'], $data['error']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -72,6 +72,7 @@ Feature: conversation/ban
|
|||
And user "participant1" joins room "room" with 200 (v4)
|
||||
And user "participant1" bans user "participant1" from room "room" with 400 (v1)
|
||||
| internalNote | BannedP1 |
|
||||
| error | self |
|
||||
|
||||
Scenario: Moderator trying to ban moderator
|
||||
Given user "participant1" creates room "room" (v4)
|
||||
|
|
@ -83,6 +84,7 @@ Feature: conversation/ban
|
|||
And user "participant1" promotes "participant2" in room "room" with 200 (v4)
|
||||
And user "participant1" bans user "participant2" from room "room" with 400 (v1)
|
||||
| internalNote | BannedP2 |
|
||||
| error | moderator |
|
||||
And user "participant1" demotes "participant2" in room "room" with 200 (v4)
|
||||
And user "participant1" bans user "participant2" from room "room" with 200 (v1)
|
||||
| internalNote | BannedP2 |
|
||||
|
|
@ -179,3 +181,10 @@ Feature: conversation/ban
|
|||
| actorType | actorId |
|
||||
| users | participant1 |
|
||||
| groups | group1 |
|
||||
|
||||
Scenario: Can not ban in one-to-one conversations
|
||||
Given user "participant1" creates room "one-to-one room" (v4)
|
||||
| roomType | 1 |
|
||||
| invite | participant2 |
|
||||
And user "participant1" bans user "participant2" from room "one-to-one room" with 400 (v1)
|
||||
| error | room |
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue