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

feat(polls): allow editing of draft polls #13883

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
fixup! feat(polls): allow editing of draft polls
  • Loading branch information
miaulalala committed Dec 16, 2024
commit d90570b7fc48af7caa1fe0dc0f809198d0183c79
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 @@
);
} 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 @@
* @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 All @@ -162,7 +162,7 @@
if ($this->room->isFederatedConversation()) {
/** @var \OCA\Talk\Federation\Proxy\TalkV1\Controller\PollController $proxy */
$proxy = \OCP\Server::get(\OCA\Talk\Federation\Proxy\TalkV1\Controller\PollController::class);
return $proxy->updateDraftPoll($pollId, $this->room, $this->participant, $question, $options, $resultMode, $maxVotes);

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

View workflow job for this annotation

GitHub Actions / static-psalm-analysis

LessSpecificReturnStatement

lib/Controller/PollController.php:165:11: LessSpecificReturnStatement: The type 'OCP\AppFramework\Http\DataResponse<200|400|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>>' is more general than 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 (see https://psalm.dev/129)
}

if ($this->room->getType() !== Room::TYPE_GROUP
Expand All @@ -173,7 +173,7 @@
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 @@
$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 @@
*
* @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 All @@ -362,7 +362,7 @@
if ($this->room->isFederatedConversation()) {
/** @var \OCA\Talk\Federation\Proxy\TalkV1\Controller\PollController $proxy */
$proxy = \OCP\Server::get(\OCA\Talk\Federation\Proxy\TalkV1\Controller\PollController::class);
return $proxy->closePoll($this->room, $this->participant, $pollId);

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

View workflow job for this annotation

GitHub Actions / static-psalm-analysis

LessSpecificReturnStatement

lib/Controller/PollController.php:365:11: LessSpecificReturnStatement: The 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>>' is more general than 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 (see https://psalm.dev/129)
}

try {
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
Loading