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

Make some views use URL query parameters instead of distinct paths #650

Merged
merged 15 commits into from
May 7, 2023

Conversation

ddabble
Copy link
Member

@ddabble ddabble commented May 5, 2023

Proposed changes

Changed multiple pages' URLs to use query parameters, instead of having multiple distinct paths for practically the same page.

Here's an exhaustive list of all affected URLs:

  • /reservation/quota/<int:pk>//reservation/quota/?user=<int:pk> (4fcb275)
  • POST form data with search_string field to /admin/news/events/participants/search/GET to /admin/news/events/participants/search/?search_string=<search_string> (cf2063d)
  • /reservation/me//reservation/reservations/?owner=me (c729089)
  • /reservation/admin//reservation/reservations/?owner=MAKE (c729089)
  • /reservation/<int:year>/<int:week>/<int:pk>//reservation/machines/<int:pk>/?calendar_year=<int:year>&calendar_week=<int:week> (0ca0e06)
  • /reservation/json/<int:pk>/<int:reservation_pk>//reservation/json/<int:pk>/?exclude_reservation=<int:reservation_pk> (ccded76)

Also refactored the following views to use the newly added QueryParameterFormMixin (bca8946):

  • DocumentationPageSearchView [/search/?query=<query>&page=<page>] (727aadc)
  • APIReservationListView [/reservation/calendar/<int:pk>/reservations/?start_date=<start_date>&end_date=<end_date>] (23d2acd)
    • Also renamed the startDate query param to start_date, and endDate to end_date

Also made all JsonResponses use UTF8 as encoding instead of ASCII (28f86df).

Areas to review closely

That all the changed views still work as intended, and that changing the encoding of JsonResponses to UTF8 doesn't cause any unforeseen bugs.

Checklist

(If any of the points are not relevant, mark them as checked)

  • Created tests that fail without the changes, if relevant/possible
  • Made sure that your code conforms to the code style guides and that any common code smells have been addressed
    • (It's not intended that you read through this whole document, but that you get yourself an overview over its contents, and that you keep it in mind while taking a second look at your code before opening a pull request)
  • Added sufficient documentation - e.g. as docstrings or in the README, if suitable
  • Added your changes to the "Unreleased" section of the changelog - mainly the changes that are of particular interest to users and/or developers, if any
  • Added a "Deployment notes" section above, if anything out of the ordinary should be done when deploying these changes to the server

@codecov
Copy link

codecov bot commented May 5, 2023

Codecov Report

Merging #650 (82631fa) into dev (82631fa) will not change coverage.
The diff coverage is n/a.

❗ Current head 82631fa differs from pull request most recent head f70538e. Consider uploading reports for the commit f70538e to get more accurate results

Impacted file tree graph

@@           Coverage Diff           @@
##              dev     #650   +/-   ##
=======================================
  Coverage   87.72%   87.72%           
=======================================
  Files         148      148           
  Lines        5937     5937           
=======================================
  Hits         5208     5208           
  Misses        729      729           

{{ ticket.timeplace.start_time.date }}
</a>
{% else %}
<a href="{% url 'admin_event_ticket_list' ticket.event.pk %}" target="_blank">

Check warning

Code scanning / CodeQL

Potentially unsafe external link

External links without noopener/noreferrer are a potential security risk.
{% for ticket in user.tickets %}
<li class="{% if not ticket.active %}canceled{% endif %}">
{% if ticket.timeplace %}
<a href="{% url 'admin_time_place_ticket_list' ticket.timeplace.event.pk ticket.timeplace.pk %}"

Check warning

Code scanning / CodeQL

Potentially unsafe external link

External links without noopener/noreferrer are a potential security risk.
@ddabble ddabble linked an issue May 5, 2023 that may be closed by this pull request
ddabble added a commit that referenced this pull request May 5, 2023
Also replaced the required `make_queue.add_printer3dcourse` permission with `users.view_user`,
which all active members currently have.
ddabble added a commit that referenced this pull request May 6, 2023
@ddabble ddabble force-pushed the cleanup/url-query-parameters-instead-of-distinct-paths branch from 9608bda to a9a1b1f Compare May 6, 2023 23:44
ddabble added a commit that referenced this pull request May 7, 2023
@ddabble ddabble force-pushed the cleanup/url-query-parameters-instead-of-distinct-paths branch from a9a1b1f to 1b80ab4 Compare May 7, 2023 17:21
ddabble added 14 commits May 7, 2023 19:28
This can make it easier for views to use forms for validating and cleaning URL query parameters.
...instead of a distinct path, for listing the quotas of a specific user.
This should make it easier to potentially extend the code in the future.
Also removed its inheritance of `CustomFieldsetFormMixin`, as that mixin class isn't suited for `GET` forms,
and because `AdminEventParticipantsSearchView` previously needed heavy customization of `CustomFieldsetFormMixin`'s
default fields anyway. Also, there wasn't much code needed to be added to `admin_event_participants_search.html`.
They both performed the same basic task (listing reservations using the same template), so this reduces code duplication
and makes it easier to potentially extend the code in the future.
...instead of having the year and week as part of the path.
This should make it easier to potentially extend the code in the future.
Also added the search query to the page title in the template.
...instead of having the excluded reservation PK as part of the path.
This should make it easier to potentially extend the code in the future.
The tests now use the more standard approach of comparing the context data of responses from test clients,
instead of using mock requests.
Also made the previously named `test_inherited_permissions()` properly test which inherited permissions are listed,
as the tests previously didn't add any permissions to any of the groups (i.e. `dev.inherited_permissions` was empty).

Also removed some comments from `test_models.py` that were accidentally added in 144e4ef
from another, unfinished commit.
@ddabble ddabble force-pushed the cleanup/url-query-parameters-instead-of-distinct-paths branch from 1b80ab4 to f70538e Compare May 7, 2023 17:28
@ddabble
Copy link
Member Author

ddabble commented May 7, 2023

Merging without explicit approval from another member, as the Dev committee previously agreed to merge these changes and assume they're relatively bug-free, simply to get things done quicker.

@ddabble ddabble merged commit f84561b into dev May 7, 2023
@ddabble ddabble deleted the cleanup/url-query-parameters-instead-of-distinct-paths branch May 7, 2023 17:56
@Gunvor4 Gunvor4 mentioned this pull request May 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

Make the event participants search form use query parameters
1 participant