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

Added: Add server-side playlist validation to rules files #995

Merged
merged 9 commits into from
May 28, 2024

Conversation

drikusroor
Copy link
Contributor

@drikusroor drikusroor commented May 3, 2024

This pull request adds playlist validation to the rules files in order to ensure that the playlists used with each rule file meet the specific requirements. The validation is implemented by updating the rule base class with a validate method. This validation method is then used in the experiment form's (Django built-in clean_{property_name}) clean_playlists method and adds errors if one or more experiment playlists are invalid based on the experiment's rules.

No longer dynamic client-side

This pull request adds playlist validation to the rules files in order to ensure that the playlists used with each rule file meet the specific requirements. The validation is implemented by updating the rule base class with a validate function. Additionally, an API endpoint is added for validating the experiment playlist based on the rules. The experiment form in the admin interface is updated to use the validation endpoint and display warnings and errors for playlist incompatibility. The pull request also includes test cases for playlist validation.

It looks like this:

Screen.Recording.2024-05-03.at.15.06.27.mov

Resolves #978

@drikusroor drikusroor self-assigned this May 3, 2024
Copy link
Collaborator

@BeritJanssen BeritJanssen left a comment

Choose a reason for hiding this comment

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

Can we override the field's clean method to achieve this? Cf. Django documentation. This does seem like a situation where Django could handle the logic, but I'm not sure if it gets more involved because Playlist is a ManyToManyField.

@albertas-jn
Copy link
Contributor

Although I find it OK as it is, indeed, using built-in django form validation might be a simpler solution.

@drikusroor
Copy link
Contributor Author

Can we override the field's clean method to achieve this? Cf. Django documentation. This does seem like a situation where Django could handle the logic, but I'm not sure if it gets more involved because Playlist is a ManyToManyField.

Although I find it OK as it is, indeed, using built-in django form validation might be a simpler solution.

I explicitly did not use Django's built-in form validation because I wanted to add dynamic validation (which happens before you submit the form already). What you y'all think: Would it be better to rewrite it to use Django's built-in form validation and risking it not to be a dynamic validation, or should we keep it like this?

@drikusroor drikusroor force-pushed the feat/live-validate-experiment-rules-playlist branch from 49bfc8c to a8ffdd0 Compare May 17, 2024 09:35
@BeritJanssen
Copy link
Collaborator

My two cents would be that it's not too big a deal for the user if they clicked "save" and then get feedback about the playlist. It's a different story with things like uploading sections, where we'd have to repeat a rather involved process before fixing the problem, but here it's a checkmark that would need to be changed, so my preference would be Django built-in over custom Javascript, which is hard to unit test, and therefore hard to maintain.

@drikusroor
Copy link
Contributor Author

My two cents would be that it's not too big a deal for the user if they clicked "save" and then get feedback about the playlist. It's a different story with things like uploading sections, where we'd have to repeat a rather involved process before fixing the problem, but here it's a checkmark that would need to be changed, so my preference would be Django built-in over custom Javascript, which is hard to unit test, and therefore hard to maintain.

I've removed the client-side (server rules based) validation and moved it to server-side validation using Django's built-in clean_{property_name} method.

However, I've kept the API endpoint as it allows us to call it in E2E tests to validate the playlists. Do you think that it's a good idea or should I also remove the validate_playlist/{rules_id} endpoint?

@drikusroor drikusroor changed the title Added: Add (dynamic) playlist validation to rules files Added: Add server-side playlist validation to rules files May 28, 2024
@drikusroor drikusroor force-pushed the feat/live-validate-experiment-rules-playlist branch from 356fcbb to 7c99bcf Compare May 28, 2024 10:52
@BeritJanssen
Copy link
Collaborator

Nice! No, I think it's fine to keep the validate_playlist endpoint in place. If it turns out we don't use it (ideally, validation ensures that no faulty data is in the database, so we wouldn't need an e2e test / might use an e2e test only to catch and fix pre-existing problems), we can still remove it at a later stage.

@drikusroor
Copy link
Contributor Author

Nice! No, I think it's fine to keep the validate_playlist endpoint in place. If it turns out we don't use it (ideally, validation ensures that no faulty data is in the database, so we wouldn't need an e2e test / might use an e2e test only to catch and fix pre-existing problems), we can still remove it at a later stage.

Yes, for example, I think the production server has an experiment with the GoldSmith rules (which don't exist anymore). Such cases can be caught using this endpoint.

@drikusroor drikusroor merged commit 1488446 into develop May 28, 2024
10 checks passed
@drikusroor drikusroor deleted the feat/live-validate-experiment-rules-playlist branch May 28, 2024 11:30
drikusroor added a commit that referenced this pull request Jun 3, 2024
* chore: Remove unused import in congosamediff.py

* refactor: Generalize playlist validation

* feat: add API endpoint

* feat: Add experiment playlist validation JavaScript and CSS files

* test: Add playlist validation test cases

* chore: Add comment about deleting stylesheet after merging Add Playlist validation to rules files #978

* feat: Add playlist validation to ExperimentForm clean method

* refactor: Do not use generic clean method but clean_playlists method (which automatically gets called by Django as it's based on the model's properties)

* revert: Remove dynamic client-side (server rules based) validation
drikusroor added a commit that referenced this pull request Jun 5, 2024
* fix: return correct content for first_round

* Added: Add server-side playlist validation to rules files (#995)

* chore: Remove unused import in congosamediff.py

* refactor: Generalize playlist validation

* feat: add API endpoint

* feat: Add experiment playlist validation JavaScript and CSS files

* test: Add playlist validation test cases

* chore: Add comment about deleting stylesheet after merging Add Playlist validation to rules files #978

* feat: Add playlist validation to ExperimentForm clean method

* refactor: Do not use generic clean method but clean_playlists method (which automatically gets called by Django as it's based on the model's properties)

* revert: Remove dynamic client-side (server rules based) validation

* feat: Enable sourcemap generation in build configuration (#1041)

* fix: Do not call onNext in onResult when we should break the round (#1043)

* chore: Update package.json version to 2.1.3

* Fixed: Fix play again URL rendering (#1051)

* fix: return play again url as a relative url instead of an absolute url

* fix: Render a Link or an anchor tag (<a>), depending on whether the url received from the Final action is relative or absolute

* fix: Render non-linkoneous button when button.link is nullish or an empty string

* fix: Fix conditional rendering logic & open absolute url in new tab

* story: Update stories for specific button/link types for Final component

* fix: Refactor Final component to use FinalButton for rendering buttons

* docs: Add comments to FinalButton component

* fix: Fix internal Final button link, which wouldn't cause an experiment to reload as it was already on the same location, by introducing an InternalRedirect

* fix: Fix relative url button link test & add test for button without link

---------

Co-authored-by: Berit <berit.janssen@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add Playlist validation to rules files
3 participants