Skip to content

Add/factor out validation of aliases#3863

Merged
johannaengland merged 4 commits intoUninett:masterfrom
johannaengland:feature/validate-aliases
Mar 18, 2026
Merged

Add/factor out validation of aliases#3863
johannaengland merged 4 commits intoUninett:masterfrom
johannaengland:feature/validate-aliases

Conversation

@johannaengland
Copy link
Copy Markdown
Contributor

Scope and purpose

Fixes #3852.

I was uncertain where to put the validation function, so I put it with the forms, but open for better suggestions!

I wish I could have just added a clean method to Room and Location, but DRF does not call that method anymore  when validating (https://www.django-rest-framework.org/community/3.0-announcement/#differences-between-modelserializer-validation-and-modelform), so the API would have anyway had to explicitly call the validation.

How to test:
Go to /seeddb/location/add///seeddb/room/add/ and try to create a room/location with an alias containing the pipe character.

Try to create a location/room with an alias containing the pipe character via the API:

curl -X POST -H "Content-type: application/json" -H "Authorization: Token  sometoken" http://localhost:8000/api/location/ -d '{"id":"Illegal", "aliases":["illegal|"]}'
curl -X POST -H "Content-type: application/json" -H "Authorization: Token  sometoken" http://localhost:8000/api/room/ -d '{"id":"Illegal","location":"locationid", "aliases":["illegal|"]}'

Contributor Checklist

Every pull request should have this checklist filled out, no matter how small it is.
More information about contributing to NAV can be found in the
Hacker's guide to NAV.

  • Added a changelog fragment for towncrier
  • Added/amended tests for new/changed code
  • Added/changed documentation
  • Linted/formatted the code with ruff, easiest by using pre-commit
  • Wrote the commit message so that the first line continues the sentence "If applied, this commit will ...", starts with a capital letter, does not end with punctuation and is 50 characters or less long. See https://cbea.ms/git-commit/
  • Based this pull request on the correct upstream branch: For a patch/bugfix affecting the latest stable version, it should be based on that version's branch (<major>.<minor>.x). For a new feature or other additions, it should be based on master.
  • If applicable: Created new issues if this PR does not fix the issue completely/there is further work to be done
  • If it's not obvious from a linked issue, described how to interact with NAV in order for a reviewer to observe the effects of this change first-hand (commands, URLs, UI interactions)
  • If this results in changes in the UI: Added screenshots of the before and after
  • If this adds a new Python source code file: Added the boilerplate header to that file

@johannaengland johannaengland requested review from a team and Simrayz March 17, 2026 12:44
@johannaengland johannaengland self-assigned this Mar 17, 2026
@codecov
Copy link
Copy Markdown

codecov bot commented Mar 17, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 63.70%. Comparing base (f169207) to head (01e05a3).
⚠️ Report is 5 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3863      +/-   ##
==========================================
+ Coverage   63.69%   63.70%   +0.01%     
==========================================
  Files         624      624              
  Lines       46106    46125      +19     
  Branches       43       43              
==========================================
+ Hits        29366    29383      +17     
- Misses      16730    16732       +2     
  Partials       10       10              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@johannaengland johannaengland force-pushed the feature/validate-aliases branch from 31e18af to 8322f26 Compare March 17, 2026 12:55
Copy link
Copy Markdown
Contributor

@Simrayz Simrayz left a comment

Choose a reason for hiding this comment

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

Overall this is pretty good work! I think it makes sense to put the validation function in the forms module. Tests seem to have solid coverage of edge cases, nice.

The only strictly required change imo is to add a test for the pipe character invalidation. The other nits/suggestions are just cleanup.

@johannaengland johannaengland requested review from a team and Simrayz March 18, 2026 11:04
Copy link
Copy Markdown
Contributor

@Simrayz Simrayz left a comment

Choose a reason for hiding this comment

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

Well Done Minions

@johannaengland johannaengland force-pushed the feature/validate-aliases branch from 8ddc753 to c2b05ef Compare March 18, 2026 13:30
@johannaengland johannaengland force-pushed the feature/validate-aliases branch from c2b05ef to 01e05a3 Compare March 18, 2026 13:39
@sonarqubecloud
Copy link
Copy Markdown

@johannaengland johannaengland merged commit b394078 into Uninett:master Mar 18, 2026
18 checks passed
@johannaengland johannaengland deleted the feature/validate-aliases branch March 18, 2026 13:53
johannaengland added a commit to johannaengland/nav that referenced this pull request Mar 18, 2026
The validation method was added in Uninett#3863
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 validation of location/room aliases

2 participants