Skip to content

Commit

Permalink
fixup! feat(polls): allow editing of draft polls
Browse files Browse the repository at this point in the history
  • Loading branch information
miaulalala committed Dec 16, 2024
1 parent 67161db commit d90570b
Show file tree
Hide file tree
Showing 6 changed files with 99 additions and 184 deletions.
10 changes: 5 additions & 5 deletions lib/Controller/PollController.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public function createPoll(string $question, array $options, int $resultMode, in
);
} catch (PollPropertyException $e) {
$this->logger->error('Error creating poll', ['exception' => $e]);
return new DataResponse(['error' => PollPropertyException::REASON_POLL], Http::STATUS_BAD_REQUEST);
return new DataResponse(['error' => $e->getReason()], Http::STATUS_BAD_REQUEST);
}

if ($draft) {
Expand Down Expand Up @@ -145,7 +145,7 @@ public function createPoll(string $question, array $options, int $resultMode, in
* @param 0|1 $resultMode Mode how the results will be shown
* @psalm-param Poll::MODE_* $resultMode Mode how the results will be shown
* @param int $maxVotes Number of maximum votes per voter
* @return DataResponse<Http::STATUS_OK, TalkPollDraft, array{}>|DataResponse<Http::STATUS_BAD_REQUEST|Http::STATUS_FORBIDDEN, array{error: 'draft'|'options'|'question'|'room'}, array{}>|DataResponse<Http::STATUS_NOT_FOUND, array{error: string}, array{}>
* @return DataResponse<Http::STATUS_OK, TalkPollDraft, array{}>|DataResponse<Http::STATUS_BAD_REQUEST|Http::STATUS_FORBIDDEN|Http::STATUS_NOT_FOUND, array{error: 'draft'|'options'|'poll'|'question'|'room'}, array{}>

Check failure on line 148 in lib/Controller/PollController.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis

MoreSpecificReturnType

lib/Controller/PollController.php:148:13: MoreSpecificReturnType: The declared return type 'OCP\AppFramework\Http\DataResponse<200|400|403|404, array{actorDisplayName?: string, actorId?: non-empty-string, actorType?: 'bots'|'bridged'|'circles'|'emails'|'federated_users'|'groups'|'guests'|'phones'|'users', error?: 'draft'|'options'|'poll'|'question'|'room', id?: int<1, max>, maxVotes?: int<0, max>, options?: list<string>, question?: non-empty-string, resultMode?: 0|1, status?: 0|1|2}, array<never, never>>' for OCA\Talk\Controller\PollController::updateDraftPoll is more specific than the inferred return type 'OCP\AppFramework\Http\DataResponse<200|400|403|404, array{actorDisplayName?: string, actorId?: non-empty-string, actorType?: 'bots'|'bridged'|'circles'|'emails'|'federated_users'|'groups'|'guests'|'phones'|'users', error?: string, id?: int<1, max>, maxVotes?: int<0, max>, options?: list<string>, question?: non-empty-string, resultMode?: 0|1, status?: 0|1|2}, array<never, never>>' (see https://psalm.dev/070)
*
* 200: Draft modified successfully
* 400: Modifying poll is not possible
Expand Down Expand Up @@ -173,7 +173,7 @@ public function updateDraftPoll(int $pollId, string $question, array $options, i
try {
$poll = $this->pollService->getPoll($this->room->getId(), $pollId);
} catch (DoesNotExistException $e) {
return new DataResponse(['error' => $e->getMessage()], Http::STATUS_NOT_FOUND);
return new DataResponse(['error' => PollPropertyException::REASON_POLL], Http::STATUS_NOT_FOUND);
}

if (!$poll->isDraft()) {
Expand All @@ -200,7 +200,7 @@ public function updateDraftPoll(int $pollId, string $question, array $options, i
$this->pollService->updatePoll($this->participant, $poll);
} catch (WrongPermissionsException $e) {
$this->logger->error('Error modifying poll', ['exception' => $e]);
return new DataResponse(['error' => 'poll'], Http::STATUS_FORBIDDEN);
return new DataResponse(['error' => PollPropertyException::REASON_POLL], Http::STATUS_FORBIDDEN);
}

return new DataResponse($poll->renderAsDraft());
Expand Down Expand Up @@ -346,7 +346,7 @@ public function votePoll(int $pollId, array $optionIds = []): DataResponse {
*
* @param int $pollId ID of the poll
* @psalm-param non-negative-int $pollId
* @return DataResponse<Http::STATUS_OK, TalkPoll, array{}>|DataResponse<Http::STATUS_ACCEPTED, null, array{}>|DataResponse<Http::STATUS_BAD_REQUEST|Http::STATUS_FORBIDDEN|Http::STATUS_NOT_FOUND, array{error: 'poll'}|array{error: string}, array{}>
* @return DataResponse<Http::STATUS_OK, TalkPoll, array{}>|DataResponse<Http::STATUS_ACCEPTED, null, array{}>|DataResponse<Http::STATUS_BAD_REQUEST|Http::STATUS_FORBIDDEN|Http::STATUS_NOT_FOUND, array{error: 'poll'}, array{}>

Check failure on line 349 in lib/Controller/PollController.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis

MoreSpecificReturnType

lib/Controller/PollController.php:349:13: MoreSpecificReturnType: The declared return type 'OCP\AppFramework\Http\DataResponse<200|400|403|404, array{actorDisplayName?: string, actorId?: non-empty-string, actorType?: 'bots'|'bridged'|'circles'|'emails'|'federated_users'|'groups'|'guests'|'phones'|'users', details?: list<array{actorDisplayName: string, actorId: string, actorType: string, optionId: int}>, error?: 'poll', id?: int<1, max>, maxVotes?: int<0, max>, numVoters?: int<0, max>, options?: list<string>, question?: non-empty-string, resultMode?: 0|1, status?: 0|1|2, votedSelf?: list<int>, votes?: array<string, int>}, array<never, never>>|OCP\AppFramework\Http\DataResponse<202, null, array<never, never>>' for OCA\Talk\Controller\PollController::closePoll is more specific than the inferred return type 'OCP\AppFramework\Http\DataResponse<200|400|403|404, array{actorDisplayName?: string, actorId?: non-empty-string, actorType?: 'bots'|'bridged'|'circles'|'emails'|'federated_users'|'groups'|'guests'|'phones'|'users', details?: list<array{actorDisplayName: string, actorId: string, actorType: string, optionId: int}>, error?: string, id?: int<1, max>, maxVotes?: int<0, max>, numVoters?: int<0, max>, options?: list<string>, question?: non-empty-string, resultMode?: 0|1, status?: 0|1|2, votedSelf?: list<int>, votes?: array<string, int>}, array<never, never>>|OCP\AppFramework\Http\DataResponse<202, null, array<never, never>>' (see https://psalm.dev/070)
*
* 200: Poll closed successfully
* 202: Poll draft was deleted successfully
Expand Down
3 changes: 0 additions & 3 deletions lib/Service/PollService.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,6 @@ public function updatePoll(Participant $participant, Poll $poll): void {
}

/**
* @param Participant $participant
* @param Poll $poll
* @return void
* @throws WrongPermissionsException
*/
public function closePoll(Participant $participant, Poll $poll): void {
Expand Down
122 changes: 43 additions & 79 deletions openapi-full.json
Original file line number Diff line number Diff line change
Expand Up @@ -9695,6 +9695,7 @@
"enum": [
"draft",
"options",
"poll",
"question",
"room"
]
Expand Down Expand Up @@ -9739,6 +9740,7 @@
"enum": [
"draft",
"options",
"poll",
"question",
"room"
]
Expand Down Expand Up @@ -9779,7 +9781,14 @@
],
"properties": {
"error": {
"type": "string"
"type": "string",
"enum": [
"draft",
"options",
"poll",
"question",
"room"
]
}
}
}
Expand Down Expand Up @@ -10397,33 +10406,18 @@
"$ref": "#/components/schemas/OCSMeta"
},
"data": {
"anyOf": [
{
"type": "object",
"required": [
"error"
],
"properties": {
"error": {
"type": "string",
"enum": [
"poll"
]
}
}
},
{
"type": "object",
"required": [
"error"
],
"properties": {
"error": {
"type": "string"
}
}
"type": "object",
"required": [
"error"
],
"properties": {
"error": {
"type": "string",
"enum": [
"poll"
]
}
]
}
}
}
}
Expand Down Expand Up @@ -10453,33 +10447,18 @@
"$ref": "#/components/schemas/OCSMeta"
},
"data": {
"anyOf": [
{
"type": "object",
"required": [
"error"
],
"properties": {
"error": {
"type": "string",
"enum": [
"poll"
]
}
}
},
{
"type": "object",
"required": [
"error"
],
"properties": {
"error": {
"type": "string"
}
}
"type": "object",
"required": [
"error"
],
"properties": {
"error": {
"type": "string",
"enum": [
"poll"
]
}
]
}
}
}
}
Expand Down Expand Up @@ -10509,33 +10488,18 @@
"$ref": "#/components/schemas/OCSMeta"
},
"data": {
"anyOf": [
{
"type": "object",
"required": [
"error"
],
"properties": {
"error": {
"type": "string",
"enum": [
"poll"
]
}
}
},
{
"type": "object",
"required": [
"error"
],
"properties": {
"error": {
"type": "string"
}
}
"type": "object",
"required": [
"error"
],
"properties": {
"error": {
"type": "string",
"enum": [
"poll"
]
}
]
}
}
}
}
Expand Down
Loading

0 comments on commit d90570b

Please sign in to comment.