Skip to content

Towards django auth#3619

Merged
hmpf merged 6 commits intomasterfrom
towards-django-auth
Oct 23, 2025
Merged

Towards django auth#3619
hmpf merged 6 commits intomasterfrom
towards-django-auth

Conversation

@hmpf
Copy link
Copy Markdown
Contributor

@hmpf hmpf commented Oct 22, 2025

Scope and purpose

Low hanging fruit that desn't break anything on the road towards full Django auth. Login/logout should work, sudo should work.

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

@hmpf hmpf added the nonews No news fragment is necessary for this PR (e.g. refactoring, cleanups, workflow/development changes) label Oct 22, 2025
hmpf and others added 4 commits October 22, 2025 09:36
The Django auth system uses the `is_active` property to decide whether a
user is allowed to log in. NAV's Account class already has the attribute
`locked` for this purpose. In order to edge towards compatibility with
Django Auth, this adds `is_active` as the negation of `locked`.
Django's auth system uses the generic concept of "natural keys" to fetch
user objects by their names (rather than their primary keys), as entered
in a login form.  In order for the Django auth system to be able to
look up NAV user accounts, the Account model and its manager need to
provide the necessary calls.
These are necessary for Django's auth system to work. However, since we
use our custom migration system, a custom migration script for these
apps needs to be created later.
@github-actions
Copy link
Copy Markdown

github-actions bot commented Oct 22, 2025

Test results

    27 files      27 suites   45m 53s ⏱️
 2 625 tests  2 625 ✅ 0 💤 0 ❌
19 390 runs  19 390 ✅ 0 💤 0 ❌

Results for commit 55c9d73.

♻️ This comment has been updated with latest results.

@codecov
Copy link
Copy Markdown

codecov bot commented Oct 22, 2025

Codecov Report

❌ Patch coverage is 81.81818% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 62.50%. Comparing base (f35cca2) to head (55c9d73).
⚠️ Report is 266 commits behind head on master.

Files with missing lines Patch % Lines
python/nav/models/profiles.py 77.77% 2 Missing ⚠️
python/nav/web/webfront/views.py 33.33% 2 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##           master    #3619   +/-   ##
=======================================
  Coverage   62.50%   62.50%           
=======================================
  Files         611      611           
  Lines       45093    45103   +10     
  Branches       43       43           
=======================================
+ Hits        28186    28193    +7     
- Misses      16897    16900    +3     
  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.

@hmpf hmpf force-pushed the towards-django-auth branch from cfc7686 to 12fddee Compare October 22, 2025 12:45
Copy link
Copy Markdown
Member

@lunkwill42 lunkwill42 left a comment

Choose a reason for hiding this comment

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

Low hanging fruit that desn't break anything on the road towards full Django auth. Login/logout should work, sudo should work.

I disagree with this assessment: This PR will break LDAP logins in NAV, since it replaces the NAV-specific authentication mechanism in do_login() with Django's authentication mechanism, before we have a working LDAP backend.

We can either:

  1. Merge the coming LdapBackend PR into this once it has been posted and approved, then move on with this,

or

  1. Rip out the parts of this that implements the actual authentication replacement in do_login(), and make a new PR for the whole login flow replacement once the LdapBackend is approved and merged (i.e one final PR to sew all the parts together to a working whole)

@hmpf
Copy link
Copy Markdown
Contributor Author

hmpf commented Oct 22, 2025

Let's go for option 2.

Copy link
Copy Markdown
Member

@lunkwill42 lunkwill42 left a comment

Choose a reason for hiding this comment

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

Just rename the SQL changescript to avoid conflicts with other in-flight PRs :)

@hmpf hmpf force-pushed the towards-django-auth branch from 720763d to 55c9d73 Compare October 23, 2025 07:51
@sonarqubecloud
Copy link
Copy Markdown

@hmpf
Copy link
Copy Markdown
Contributor Author

hmpf commented Oct 23, 2025

For the PR that merges the do_login change + new LDAP backend we also need to remove our own remote user support and support the default django auth backend (+ middleware). We really need a way to fix sudo for that one though I'm not sure sudo ever worked for our remote user.

@hmpf hmpf merged commit ac1e688 into master Oct 23, 2025
19 checks passed
@hmpf hmpf deleted the towards-django-auth branch October 23, 2025 08:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

auth authentication nonews No news fragment is necessary for this PR (e.g. refactoring, cleanups, workflow/development changes)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants