-
Notifications
You must be signed in to change notification settings - Fork 1
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
Added: Add server-side playlist validation to rules files #995
Conversation
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.
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? |
49bfc8c
to
a8ffdd0
Compare
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. |
6987ec8
to
e9d967e
Compare
I've removed the client-side (server rules based) validation and moved it to server-side validation using Django's built-in 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 |
…st validation to rules files #978
…(which automatically gets called by Django as it's based on the model's properties)
356fcbb
to
7c99bcf
Compare
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. |
* 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
* 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>
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