-
Notifications
You must be signed in to change notification settings - Fork 443
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
miaulalala
wants to merge
1
commit into
main
Choose a base branch
from
feat/edit-delete-poll-drafts
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,13 +10,15 @@ | |
namespace OCA\Talk\Federation\Proxy\TalkV1\Controller; | ||
|
||
use OCA\Talk\Exceptions\CannotReachRemoteException; | ||
use OCA\Talk\Exceptions\PollPropertyException; | ||
use OCA\Talk\Federation\Proxy\TalkV1\ProxyRequest; | ||
use OCA\Talk\Federation\Proxy\TalkV1\UserConverter; | ||
use OCA\Talk\Participant; | ||
use OCA\Talk\ResponseDefinitions; | ||
use OCA\Talk\Room; | ||
use OCP\AppFramework\Http; | ||
use OCP\AppFramework\Http\DataResponse; | ||
use Psr\Log\LoggerInterface; | ||
|
||
/** | ||
* @psalm-import-type TalkPoll from ResponseDefinitions | ||
|
@@ -26,6 +28,7 @@ class PollController { | |
public function __construct( | ||
protected ProxyRequest $proxy, | ||
protected UserConverter $userConverter, | ||
protected LoggerInterface $logger, | ||
) { | ||
} | ||
|
||
|
@@ -131,7 +134,7 @@ public function votePoll(Room $room, Participant $participant, int $pollId, arra | |
|
||
|
||
/** | ||
* @return DataResponse<Http::STATUS_OK, TalkPollDraft, array{}>|DataResponse<Http::STATUS_CREATED, TalkPoll, array{}>|DataResponse<Http::STATUS_BAD_REQUEST, array{error: 'draft'|'options'|'question'|'room'}, array{}> | ||
* @return DataResponse<Http::STATUS_OK, TalkPollDraft, array{}>|DataResponse<Http::STATUS_CREATED, TalkPoll, array{}>|DataResponse<Http::STATUS_BAD_REQUEST, array{error: 'draft'|'options'|'poll'|'question'|'room'}, array{}> | ||
* @throws CannotReachRemoteException | ||
* | ||
* 200: Draft created successfully | ||
|
@@ -171,7 +174,46 @@ public function createPoll(Room $room, Participant $participant, string $questio | |
} | ||
|
||
/** | ||
* @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: 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{}> | ||
* @throws CannotReachRemoteException | ||
* | ||
* 200: Draft created successfully | ||
* 201: Poll created successfully | ||
* 400: Creating poll is not possible | ||
* | ||
* @see \OCA\Talk\Controller\PollController::createPoll() | ||
*/ | ||
public function updateDraftPoll(int $pollId, Room $room, Participant $participant, string $question, array $options, int $resultMode, int $maxVotes): DataResponse { | ||
$proxy = $this->proxy->post( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. since this will not be part of 20.1 nor 19, |
||
$participant->getAttendee()->getInvitedCloudId(), | ||
$participant->getAttendee()->getAccessToken(), | ||
$room->getRemoteServer() . '/ocs/v2.php/apps/spreed/api/v1/poll/' . $room->getRemoteToken() . '/draft/' . $pollId, | ||
[ | ||
'question' => $question, | ||
'options' => $options, | ||
'resultMode' => $resultMode, | ||
'maxVotes' => $maxVotes | ||
], | ||
); | ||
|
||
$status = $proxy->getStatusCode(); | ||
if ($status === Http::STATUS_BAD_REQUEST) { | ||
$data = $this->proxy->getOCSData($proxy, [Http::STATUS_BAD_REQUEST]); | ||
return new DataResponse($data, Http::STATUS_BAD_REQUEST); | ||
} | ||
|
||
/** @var TalkPollDraft $data */ | ||
$data = $this->proxy->getOCSData($proxy, [Http::STATUS_OK, Http::STATUS_CREATED]); | ||
$data = $this->userConverter->convertPoll($room, $data); | ||
|
||
if ($status === Http::STATUS_OK) { | ||
return new DataResponse($data); | ||
} | ||
return new DataResponse($data); | ||
} | ||
|
||
/** | ||
* @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{}> | ||
* @throws CannotReachRemoteException | ||
* | ||
* 200: Poll closed successfully | ||
|
@@ -199,7 +241,12 @@ public function closePoll(Room $room, Participant $participant, int $pollId): Da | |
} | ||
/** @var array{error?: string} $data */ | ||
$data = $this->proxy->getOCSData($proxy); | ||
return new DataResponse(['error' => $data['error'] ?? 'poll'], $statusCode); | ||
|
||
if ($data['error'] !== PollPropertyException::REASON_POLL) { | ||
$this->logger->error('Unhandled error in ' . __METHOD__ . ': ' . $data['error']); | ||
} | ||
|
||
return new DataResponse(['error' => PollPropertyException::REASON_POLL], $statusCode); | ||
} | ||
|
||
/** @var TalkPoll $data */ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move to 21? Or are we backport this? Not sure
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we can backport if you like? It's up to you.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We never backport here (unless forced, and I see no one forcing here) 🙊
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should move to 21