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

reset evaluation after it started #2136

Open
wants to merge 28 commits into
base: main
Choose a base branch
from

Conversation

fekoch
Copy link
Collaborator

@fekoch fekoch commented Mar 5, 2024

Closes #1991
Replaces the revert_to_new evaluation operation with reset_to_new. It now allows resetting from any State except NEW and PUBLISHED. It also allows deleting all previously received answers.

Also, it makes Evaluation.State an IntEnum.

  • Only show confirmation modal when deleting previous answers
  • Finish Unit-Tests
  • Cleanup leftover TODO's

@fekoch fekoch force-pushed the 1991/reset_evaluation_after_it_started branch 2 times, most recently from c353503 to 5ee1e27 Compare April 15, 2024 15:51
@fekoch fekoch force-pushed the 1991/reset_evaluation_after_it_started branch 3 times, most recently from cb79677 to 909c5a7 Compare April 22, 2024 19:28
@fekoch
Copy link
Collaborator Author

fekoch commented Apr 22, 2024

Two Unit Tests are missing. I do not have any idea on how to practically test for ui popups without selenium tests

@fekoch fekoch marked this pull request as ready for review April 22, 2024 19:34
Copy link
Member

@niklasmohrin niklasmohrin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I started reviewing your changes and I find it a bit tricky to separate the "revert -> reset" and "make State an IntEnum" changes. Do you think you could split these changes into two PRs? If not, we will have to see how we manage :D

The extra PR would also be a good place to discuss the motivation for the move to IntEnum - it sounds like a good idea, but it's hard to see the benefits when they are mixed in with the other changes here

evap/evaluation/migrations/0143_alter_evaluation_state.py Outdated Show resolved Hide resolved
@niklasmohrin
Copy link
Member

I do not have any idea on how to practically test for ui popups without selenium tests

I don't think it is possible with our current setup. However, since the javascript deciding whether or not to show the modal is pretty clear, I think we don't urgently need a test for that

@fekoch fekoch force-pushed the 1991/reset_evaluation_after_it_started branch from 909c5a7 to f3670fb Compare April 29, 2024 15:33
@fekoch fekoch marked this pull request as draft April 29, 2024 18:32
@fekoch fekoch force-pushed the 1991/reset_evaluation_after_it_started branch 3 times, most recently from 6c0cf01 to 8eabcbe Compare June 3, 2024 16:00
@fekoch
Copy link
Collaborator Author

fekoch commented Jun 10, 2024

@fekoch some TODO's:

  • type annotation in test helper function
  • remove empty newline

@fekoch fekoch force-pushed the 1991/reset_evaluation_after_it_started branch from 8eabcbe to 2e67d03 Compare June 24, 2024 17:55
@fekoch fekoch marked this pull request as ready for review June 24, 2024 17:57
evap/evaluation/models.py Outdated Show resolved Hide resolved
evap/evaluation/models.py Outdated Show resolved Hide resolved
evap/evaluation/models.py Outdated Show resolved Hide resolved
evap/staff/templates/staff_evaluation_operation.html Outdated Show resolved Hide resolved
evap/staff/templates/staff_evaluation_operation.html Outdated Show resolved Hide resolved
evap/staff/templates/staff_evaluation_operation.html Outdated Show resolved Hide resolved
evap/staff/templates/staff_evaluation_operation.html Outdated Show resolved Hide resolved
evap/staff/views.py Outdated Show resolved Hide resolved
Copy link
Member

@janno42 janno42 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Forgot to specify before: It should not be possible to reset single results. They should be removed from the selection and the operation should not be applicable_to them.
  • Submitting other operations (e.g., start evaluation, publish, unpublish) is not possible anymore. The submit button does not send a request in these cases (document.getElementById("delete-previous-answers") fails).

@fekoch fekoch force-pushed the 1991/reset_evaluation_after_it_started branch from cecbc89 to 5d9d71e Compare August 12, 2024 17:24
Copy link
Member

@richardebeling richardebeling left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks :)

Copy link
Member

@niklasmohrin niklasmohrin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice job, I have some final remarks below.

Since all reviews are green now, but you still may want to change something, just write a quick comment once you are okay with merging

Comment on lines +622 to +630
allowed_sources = [
Evaluation.State.PREPARED,
Evaluation.State.EDITOR_APPROVED,
Evaluation.State.APPROVED,
Evaluation.State.IN_EVALUATION,
Evaluation.State.EVALUATED,
Evaluation.State.REVIEWED,
]
return self.state in allowed_sources and not self.is_single_result
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason to prefer this over the following?

Suggested change
allowed_sources = [
Evaluation.State.PREPARED,
Evaluation.State.EDITOR_APPROVED,
Evaluation.State.APPROVED,
Evaluation.State.IN_EVALUATION,
Evaluation.State.EVALUATED,
Evaluation.State.REVIEWED,
]
return self.state in allowed_sources and not self.is_single_result
return Evaluation.State.NEW < self.state < Evaluation.State.PUBLISHED and not self.is_single_result

def reset_to_new(self, *, delete_previous_answers: bool):
if delete_previous_answers:
for answer_class in Answer.__subclasses__():
answer_class._default_manager.filter(contribution__evaluation_id=self.id).delete()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does the following also work?

Suggested change
answer_class._default_manager.filter(contribution__evaluation_id=self.id).delete()
answer_class._default_manager.filter(contribution__evaluation=self).delete()

Comment on lines +583 to +584
if request.POST.get("delete-previous-answers") == "on":
delete_previous_answers = True
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couldn't we do delete_previous_answers = request.POST.get("delete-previous-answers") == "on" from the start? I think this would also fix the bool | None "issue", although I don't care so much about that

Comment on lines +83 to +87
{% comment %}
The modal needs an element in the slot, otherwise it throws an error.
No button is needed, as the modal is conditionally shown via JS.
{% endcomment %}
<span slot="show-button"></span>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, we should change the modal so that this is not needed, you or me can fix it in a follow up :)

const data = new FormData(submitEvent.target);
if (data.get("delete-previous-answers") === "on" && !submitEvent.submitter?.hasAttribute("data-confirm-answer-deletion")) {
submitEvent.preventDefault()
submitEvent.target.querySelector("confirmation-modal[data-allow-answer-deletion]").dialog.showModal();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the following, we can get rid of the data-allow-answer-deletion on the modal:

Suggested change
submitEvent.target.querySelector("confirmation-modal[data-allow-answer-deletion]").dialog.showModal();
submitEvent.target.querySelector("confirmation-modal:has([data-confirm-answer-deletion])").dialog.showModal();

You can decide which version you prefer, I think both are fine

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Reset evaluation after it started
5 participants