feat: allow editing of submission by the user#1690
feat: allow editing of submission by the user#1690tpokorra wants to merge 44 commits intonextcloud:mainfrom
Conversation
b8974c8 to
ebe6255
Compare
Chartman123
left a comment
There was a problem hiding this comment.
I just added some comments on the Changelog and the translations :)
I didn't have a closer look for now.
But one thing that I already saw: you seem to delete an existing submission instead of updating it. I'm not quite sure if that's the way to go here.
|
Thank you @Chartman123 The whole pull request is not fully functional yet. |
|
@tpokorra yes no problem :) you can have a look at the PR implementing the local storage how the components get their values there. And for getting the values from the database and pass them to the front-end can be seen in the results view... |
|
TODO list:
|
|
@tpokorra I've added your checklist to first post :) And btw thank you very much for your contribution to this project 👍🏻 I've also run the automated check workflows for this PR so that you can easily find problems with your commits. Please have a look at the failed checks. If you have questions about some of the checks feel free to ask 🙂 |
f5cc31d to
09db0ef
Compare
|
@tpokorra please don't merge the main branch into your branch. Use git rebase to update your branch to the latest commits to main :) You can also use git rebase to squash your commits into a single one so that the commit history on your main branch stays clean :) You can try |
76b1260 to
71f1622
Compare
3f1f5db to
b163c92
Compare
|
@Chartman123 I have a small question: why is there a reference to I get this error: If I change it from Am I missing something to install? I ran: phpunit in vendor/bin shows version |
|
@tpokorra didn't manage to run the unit tests locally... Regarding the |
|
@Chartman123 |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1690 +/- ##
============================================
+ Coverage 43.43% 44.12% +0.68%
- Complexity 882 919 +37
============================================
Files 77 78 +1
Lines 3361 3490 +129
============================================
+ Hits 1460 1540 +80
- Misses 1901 1950 +49 |
48e8988 to
6917908
Compare
9d148cd to
d60b3c4
Compare
|
Hello @tpokorra I thank you very much for your good work. I fully support this feature, which I believe is very important in many use cases. Do you need help, and if so, where? |
…User Signed-off-by: Timotheus Pokorra <timotheus.pokorra@solidcharity.com>
Signed-off-by: Timotheus Pokorra <timotheus.pokorra@solidcharity.com>
Signed-off-by: Timotheus Pokorra <timotheus.pokorra@solidcharity.com>
Signed-off-by: Timotheus Pokorra <timotheus.pokorra@solidcharity.com>
Signed-off-by: Timotheus Pokorra <timotheus.pokorra@solidcharity.com>
Signed-off-by: Timotheus Pokorra <timotheus.pokorra@solidcharity.com>
Signed-off-by: Timotheus Pokorra <timotheus.pokorra@solidcharity.com>
Signed-off-by: Timotheus Pokorra <timotheus.pokorra@solidcharity.com>
Signed-off-by: Timotheus Pokorra <timotheus.pokorra@solidcharity.com>
Signed-off-by: Timotheus Pokorra <timotheus.pokorra@solidcharity.com>
Signed-off-by: Timotheus Pokorra <timotheus.pokorra@solidcharity.com>
Signed-off-by: Timotheus Pokorra <timotheus.pokorra@solidcharity.com>
Signed-off-by: Timotheus Pokorra <timotheus.pokorra@solidcharity.com>
Signed-off-by: Timotheus Pokorra <timotheus.pokorra@solidcharity.com>
Signed-off-by: Timotheus Pokorra <timotheus.pokorra@solidcharity.com>
Signed-off-by: Timotheus Pokorra <timotheus.pokorra@solidcharity.com>
Signed-off-by: Timotheus Pokorra <timotheus.pokorra@solidcharity.com>
Signed-off-by: Timotheus Pokorra <timotheus.pokorra@solidcharity.com>
Signed-off-by: Timotheus Pokorra <timotheus.pokorra@solidcharity.com>
Signed-off-by: Timotheus Pokorra <timotheus.pokorra@solidcharity.com>
Signed-off-by: Timotheus Pokorra <timotheus.pokorra@solidcharity.com>
38cb8d6 to
31af1b3
Compare
AIlkiv
left a comment
There was a problem hiding this comment.
Thank you for your work. A few comments from me.
|
|
||
| // get existing submission of this user | ||
| try { | ||
| $submission = $this->submissionMapper->findByFormAndUser($form->getId(), $this->currentUser->getUID()); |
There was a problem hiding this comment.
- It makes sense to move the ownership check to submission before validateSubmission
- It is better to rewrite this check to $this->submissionMapper->findById($submissionId). This will cover situations with multiple submissions and is a faster method.
| $submission->setTimestamp(time()); | ||
| $this->submissionMapper->update($submission); | ||
|
|
||
| if (empty($answers)) { |
There was a problem hiding this comment.
In what cases can this be? When deleting a submission?
| // get stored answers for this question | ||
| $storedAnswers = []; | ||
| if ($update) { | ||
| $storedAnswers = $this->answerMapper->findBySubmissionAndQuestion($submissionId, $question['id']); |
There was a problem hiding this comment.
To generate fewer database queries, before foreach where the storeAnswersForQuestion method is called, get all the answers in one call through $this->answerMapper->findBySubmission and pass here
| $storedAnswers = []; | ||
| if ($update) { | ||
| $storedAnswers = $this->answerMapper->findBySubmissionAndQuestion($submissionId, $question['id']); | ||
| } |
There was a problem hiding this comment.
I will try to propose a simpler solution for this method
$deletingStoredAnswers = [];
foreach ($storedAnswers as $storedAnswer) {
$deletingStoredAnswers[$storedAnswer->getText() ] = $storedAnswer
}
| $storedAnswers = $this->answerMapper->findBySubmissionAndQuestion($submissionId, $question['id']); | ||
| } | ||
|
|
||
| $newAnswerTexts = []; |
| $answerText = $name; | ||
|
|
||
| $answerEntity->setText($answerText); | ||
| $this->answerMapper->insert($answerEntity); |
| $answerEntity->setQuestionId($question['id']); | ||
| $answerEntity->setText($answerText); | ||
| $this->answerMapper->insert($answerEntity); | ||
| } |
| } | ||
|
|
||
| $answerEntity->setText($answerText); | ||
| $this->answerMapper->insert($answerEntity); |
There was a problem hiding this comment.
if (array_key_exists($answerText, $deletingStoredAnswers)) {
unset($deletingStoredAnswers[$answerText])
continue; // answer already been stored
}
$answerEntity->setText($answerText);
$this->answerMapper->insert($answerEntity);
| $this->answerMapper->delete($storedAnswer); | ||
| } | ||
| } | ||
| } |
There was a problem hiding this comment.
if (!empty( $deletingStoredAnswers) {
foreach ( $deletingStoredAnswers as $storedAnswer) {
$this->answerMapper->delete($storedAnswer);
}
}
| $result['questions'] = $this->getQuestions($form->getId()); | ||
|
|
||
| // add previous submission if there is one by this user for this form | ||
| if ($this->currentUser->getUID() && $form->getAllowEdit()) { |
There was a problem hiding this comment.
if this only works for cases where only one submission is allowed. Add !$form->getSubmitMultiple() here
|
@tpokorra I'll try to get this branch back from the forked repo into a feature branch in our upstream repo if it's fine for you :) Then we can start working on your great contributions to get it in shape and being able to release it soon :) |
|
Closed in favor of #2715 |
related to #1110