Skip to content

Do not flush session on sudo to default account#3575

Merged
johannaengland merged 1 commit intoUninett:5.14.xfrom
johannaengland:bugfix/sudo-default-user
Oct 15, 2025
Merged

Do not flush session on sudo to default account#3575
johannaengland merged 1 commit intoUninett:5.14.xfrom
johannaengland:bugfix/sudo-default-user

Conversation

@johannaengland
Copy link
Copy Markdown
Contributor

Scope and purpose

Fixes #3571.

The function ensure_account checks if the account is locked and if so flushes the session and changes to the default account. #2828 added the session flushing. The problem is that the default account is usually marked as locked since it has no password.

So before this function introduced the session flushing when sudoing to the default user this function always set the the current user (default account) to default account, so in essence no difference, but a silly thing that was introduced much earlier in 2019 in #2007.

But after the session flushing was added this leads to the information about the sudoing user that is saved in the session under session[SUDOER_ID_VAR] to be deleted, which means that the sudoing user is essentially logged out.

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, hmpf, lunkwill42 and stveit October 5, 2025 19:04
@johannaengland johannaengland self-assigned this Oct 5, 2025
@codecov
Copy link
Copy Markdown

codecov bot commented Oct 5, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 61.44%. Comparing base (091d214) to head (d8a79e9).

Additional details and impacted files
@@           Coverage Diff           @@
##           5.14.x    #3575   +/-   ##
=======================================
  Coverage   61.44%   61.44%           
=======================================
  Files         610      610           
  Lines       44726    44726           
  Branches       43       43           
=======================================
  Hits        27480    27480           
  Misses      17236    17236           
  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.

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.

Nice 😄

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.

🎉

The default account is usually marked as locked since it has no password
@johannaengland johannaengland force-pushed the bugfix/sudo-default-user branch from 972f6d2 to d8a79e9 Compare October 15, 2025 12:29
@sonarqubecloud
Copy link
Copy Markdown

@johannaengland johannaengland merged commit cee63e7 into Uninett:5.14.x Oct 15, 2025
25 checks passed
@johannaengland johannaengland deleted the bugfix/sudo-default-user branch October 15, 2025 12:53
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.

[BUG] The default dashboard can no longer be modified by an admin

3 participants