Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Dec 10, 2025

Allow administrators to switch between organizations in the dashboard

Test Fix - Regular User Access

Fixed: Test test_regular_user_cannot_access_dashboard now properly tests a user with no organizations

Problem: The test setup was creating org3 with regular_user as admin, giving them access to an organization. This caused the test to fail because the view returned 200 (showing the organization) instead of 302 (redirecting away).

Solution: Changed org3 to not have an admin user initially. The organization is only managed by manager_user, ensuring regular_user truly has no organizations to access.

Changes in website/tests/test_organization.py:

  • Removed admin=self.regular_user from org3 creation
  • Added comment clarifying that org3 has no admin initially
  • Now regular_user has no organizations and the test correctly expects a redirect

This fix ensures:

  • regular_user has no organizations (as intended by the test)
  • manager_user can still manage org3 via managers relationship
  • admin_user cannot access org3 (for other tests)
  • ✅ All test scenarios work as expected

Previous Updates

JavaScript Block Fix:

  • Moved JavaScript from non-existent extra_js block to content block
  • Organization switcher now works correctly

Performance Optimization:

  • Fixed N+1 query problem (reduced from 6+ queries to 1)
  • Credit to @sidd190 for identifying this issue

Security Fix:

  • Fixed CodeQL "DOM text reinterpreted as HTML" alert
  • Added protocol validation, URL encoding, and safer navigation

All PR Review Comments Addressed:

  • Performance optimization (organizations_count in context)
  • Input validation (integer validation for switch_to)
  • Accessibility (aria-hidden on SVG icons)
  • Code quality (GitHub spelling, removed unused variable)
  • Comprehensive edge case tests (17 total test cases)

Test Coverage

  • Original tests: 13
  • New edge case tests: 4
  • Total: 17 comprehensive test cases
Original prompt

This section details on the original issue you should resolve

<issue_title>allow for administrators to switch to different organizations if they manage more than one in the dashboard</issue_title>
<issue_description></issue_description>

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 10, 2025

Important

Review skipped

Bot user detected.

To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.


Note

Free review on us!

CodeRabbit is offering free reviews until Wed Dec 17 2025 to showcase some of the refinements we've made.

Comment @coderabbitai help to get the list of available commands and usage tips.

@DonnieBLT DonnieBLT marked this pull request as ready for review December 11, 2025 00:08
Copilot AI review requested due to automatic review settings December 11, 2025 00:08
@github-actions github-actions bot added the files-changed: 3 PR changes 3 files label Dec 11, 2025
@github-actions
Copy link
Contributor

❌ Pre-commit checks failed

The pre-commit hooks found issues that need to be fixed. Please run the following commands locally to fix them:

# Install pre-commit if you haven't already
pip install pre-commit

# Run pre-commit on all files
pre-commit run --all-files

# Or run pre-commit on staged files only
pre-commit run

After running these commands, the pre-commit hooks will automatically fix most issues.
Please review the changes, commit them, and push to your branch.

💡 Tip: You can set up pre-commit to run automatically on every commit by running:

pre-commit install
Pre-commit output
[INFO] Initializing environment for https://github.com/pre-commit/pre-commit-hooks.
[WARNING] repo `https://github.com/pre-commit/pre-commit-hooks` uses deprecated stage names (commit, push) which will be removed in a future version.  Hint: often `pre-commit autoupdate --repo https://github.com/pre-commit/pre-commit-hooks` will fix this.  if it does not -- consider reporting an issue to that repo.
[INFO] Initializing environment for https://github.com/pycqa/isort.
[WARNING] repo `https://github.com/pycqa/isort` uses deprecated stage names (commit, merge-commit, push) which will be removed in a future version.  Hint: often `pre-commit autoupdate --repo https://github.com/pycqa/isort` will fix this.  if it does not -- consider reporting an issue to that repo.
[INFO] Initializing environment for https://github.com/astral-sh/ruff-pre-commit.
[INFO] Initializing environment for https://github.com/djlint/djLint.
[INFO] Initializing environment for local.
[INFO] Installing environment for https://github.com/pre-commit/pre-commit-hooks.
[INFO] Once installed this environment will be reused.
[INFO] This may take a few minutes...
[INFO] Installing environment for https://github.com/pycqa/isort.
[INFO] Once installed this environment will be reused.
[INFO] This may take a few minutes...
[INFO] Installing environment for https://github.com/astral-sh/ruff-pre-commit.
[INFO] Once installed this environment will be reused.
[INFO] This may take a few minutes...
[INFO] Installing environment for https://github.com/djlint/djLint.
[INFO] Once installed this environment will be reused.
[INFO] This may take a few minutes...
[INFO] Installing environment for local.
[INFO] Once installed this environment will be reused.
[INFO] This may take a few minutes...
check python ast.........................................................Passed
check builtin type constructor use.......................................Passed
check yaml...............................................................Passed
fix python encoding pragma...............................................Passed
mixed line ending........................................................Passed
isort....................................................................Passed
ruff.....................................................................Passed
ruff-format..............................................................Failed
- hook id: ruff-format
- files were modified by this hook

1 file reformatted, 462 files left unchanged


For more information, see the pre-commit documentation.

@github-actions github-actions bot added the pre-commit: failed Pre-commit checks failed label Dec 11, 2025
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds organization switching functionality to the administrator dashboard, allowing users who manage multiple organizations to switch between them and persist their selection across sessions. The changes enable non-superuser administrators and managers to access the organization dashboard with proper permission controls.

Key Changes:

  • Modified admin_organization_dashboard view to support organization switching with session-based persistence
  • Updated admin_organization_dashboard_detail view to allow access for organization admins and managers, not just superusers
  • Redesigned the admin dashboard template with a modern UI using Tailwind CSS, including a dropdown switcher for multiple organizations

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 9 comments.

File Description
website/views/organization.py Added organization filtering based on user role (admin/manager), implemented session-based organization switching with query parameter handling, and updated permission checks for detail view
website/tests/test_organization.py Added comprehensive test suite (OrganizationSwitchingTests) covering access permissions, switching functionality, session persistence, and edge cases
website/templates/admin_dashboard_organization.html Complete UI redesign with Tailwind CSS, added organization switcher dropdown, visual indicators for selected organization, and improved organization listing with logos and status badges

@DonnieBLT
Copy link
Collaborator

@copilot apply changes based on the comments in this thread

@github-actions github-actions bot added the tests: passed Django tests passed label Dec 11, 2025
@github-actions
Copy link
Contributor

❌ Pre-commit checks failed

The pre-commit hooks found issues that need to be fixed. Please run the following commands locally to fix them:

# Install pre-commit if you haven't already
pip install pre-commit

# Run pre-commit on all files
pre-commit run --all-files

# Or run pre-commit on staged files only
pre-commit run

After running these commands, the pre-commit hooks will automatically fix most issues.
Please review the changes, commit them, and push to your branch.

💡 Tip: You can set up pre-commit to run automatically on every commit by running:

pre-commit install
Pre-commit output
[INFO] Initializing environment for https://github.com/pre-commit/pre-commit-hooks.
[WARNING] repo `https://github.com/pre-commit/pre-commit-hooks` uses deprecated stage names (commit, push) which will be removed in a future version.  Hint: often `pre-commit autoupdate --repo https://github.com/pre-commit/pre-commit-hooks` will fix this.  if it does not -- consider reporting an issue to that repo.
[INFO] Initializing environment for https://github.com/pycqa/isort.
[WARNING] repo `https://github.com/pycqa/isort` uses deprecated stage names (commit, merge-commit, push) which will be removed in a future version.  Hint: often `pre-commit autoupdate --repo https://github.com/pycqa/isort` will fix this.  if it does not -- consider reporting an issue to that repo.
[INFO] Initializing environment for https://github.com/astral-sh/ruff-pre-commit.
[INFO] Initializing environment for https://github.com/djlint/djLint.
[INFO] Initializing environment for local.
[INFO] Installing environment for https://github.com/pre-commit/pre-commit-hooks.
[INFO] Once installed this environment will be reused.
[INFO] This may take a few minutes...
[INFO] Installing environment for https://github.com/pycqa/isort.
[INFO] Once installed this environment will be reused.
[INFO] This may take a few minutes...
[INFO] Installing environment for https://github.com/astral-sh/ruff-pre-commit.
[INFO] Once installed this environment will be reused.
[INFO] This may take a few minutes...
[INFO] Installing environment for https://github.com/djlint/djLint.
[INFO] Once installed this environment will be reused.
[INFO] This may take a few minutes...
[INFO] Installing environment for local.
[INFO] Once installed this environment will be reused.
[INFO] This may take a few minutes...
check python ast.........................................................Passed
check builtin type constructor use.......................................Passed
check yaml...............................................................Passed
fix python encoding pragma...............................................Passed
mixed line ending........................................................Passed
isort....................................................................Passed
ruff.....................................................................Passed
ruff-format..............................................................Failed
- hook id: ruff-format
- files were modified by this hook

1 file reformatted, 462 files left unchanged


For more information, see the pre-commit documentation.

Copilot AI changed the title [WIP] Add functionality for administrators to switch organizations Add organization switching for administrators managing multiple organizations Dec 11, 2025
@github-actions
Copy link
Contributor

👋 Hi @Copilot!

This pull request needs a peer review before it can be merged. Please request a review from a team member who is not:

  • The PR author
  • DonnieBLT
  • coderabbitai
  • copilot

Once a valid peer review is submitted, this check will pass automatically. Thank you!

@github-actions
Copy link
Contributor

❌ Tests failed

The Django tests found issues that need to be fixed. Please review the test output below and fix the failing tests.

How to run tests locally

# Install dependencies
poetry install --with dev

# Run all tests
poetry run python manage.py test

# Run tests with verbose output
poetry run python manage.py test -v 3

# Run a specific test
poetry run python manage.py test app.tests.TestClass.test_method
Test output (last 100 lines)
DEBUG Skipping throttling for test mode
DEBUG Skipping throttling for GET /dashboard/admin/organization (exempt path or DRF view)
ok
test_invalid_organization_switch_shows_error (website.tests.test_organization.OrganizationSwitchingTests.test_invalid_organization_switch_shows_error)
Test that switching to invalid organization shows error ... WARNING OpenAI client not available (missing or invalid API key), using default BACON score
WARNING OpenAI client not available (missing or invalid API key), using default BACON score
WARNING OpenAI client not available (missing or invalid API key), using default BACON score
INFO ThrottlingMiddleware initialized with limits: {'GET': 100, 'POST': 50, 'OTHER': 30}
DEBUG Using REMOTE_ADDR for IP: 127.0.0.1
DEBUG Processing request: GET /dashboard/admin/organization from IP: 127.0.0.1
DEBUG Skipping throttling for test mode
DEBUG Skipping throttling for GET /dashboard/admin/organization (exempt path or DRF view)
ok
test_manager_can_access_managed_organizations (website.tests.test_organization.OrganizationSwitchingTests.test_manager_can_access_managed_organizations)
Test that manager can access organizations they manage ... WARNING OpenAI client not available (missing or invalid API key), using default BACON score
WARNING OpenAI client not available (missing or invalid API key), using default BACON score
WARNING OpenAI client not available (missing or invalid API key), using default BACON score
INFO ThrottlingMiddleware initialized with limits: {'GET': 100, 'POST': 50, 'OTHER': 30}
DEBUG Using REMOTE_ADDR for IP: 127.0.0.1
DEBUG Processing request: GET /dashboard/admin/organization from IP: 127.0.0.1
DEBUG Skipping throttling for test mode
DEBUG Skipping throttling for GET /dashboard/admin/organization (exempt path or DRF view)
ok
test_manager_can_view_managed_organization_detail (website.tests.test_organization.OrganizationSwitchingTests.test_manager_can_view_managed_organization_detail)
Test that manager can view details of organization they manage ... WARNING OpenAI client not available (missing or invalid API key), using default BACON score
WARNING OpenAI client not available (missing or invalid API key), using default BACON score
WARNING OpenAI client not available (missing or invalid API key), using default BACON score
INFO ThrottlingMiddleware initialized with limits: {'GET': 100, 'POST': 50, 'OTHER': 30}
DEBUG Using REMOTE_ADDR for IP: 127.0.0.1
DEBUG Processing request: GET /dashboard/admin/organization/3/ from IP: 127.0.0.1
DEBUG Skipping throttling for test mode
DEBUG Skipping throttling for GET /dashboard/admin/organization/3/ (exempt path or DRF view)
ok
test_non_integer_organization_id_shows_error (website.tests.test_organization.OrganizationSwitchingTests.test_non_integer_organization_id_shows_error)
Test that non-integer organization ID shows error ... WARNING OpenAI client not available (missing or invalid API key), using default BACON score
WARNING OpenAI client not available (missing or invalid API key), using default BACON score
WARNING OpenAI client not available (missing or invalid API key), using default BACON score
INFO ThrottlingMiddleware initialized with limits: {'GET': 100, 'POST': 50, 'OTHER': 30}
DEBUG Using REMOTE_ADDR for IP: 127.0.0.1
DEBUG Processing request: GET /dashboard/admin/organization from IP: 127.0.0.1
DEBUG Skipping throttling for test mode
DEBUG Skipping throttling for GET /dashboard/admin/organization (exempt path or DRF view)
ok
test_organization_switcher_not_shown_for_single_org (website.tests.test_organization.OrganizationSwitchingTests.test_organization_switcher_not_shown_for_single_org)
Test that organization switcher is not shown when user manages only one organization ... WARNING OpenAI client not available (missing or invalid API key), using default BACON score
WARNING OpenAI client not available (missing or invalid API key), using default BACON score
WARNING OpenAI client not available (missing or invalid API key), using default BACON score
INFO ThrottlingMiddleware initialized with limits: {'GET': 100, 'POST': 50, 'OTHER': 30}
DEBUG Using REMOTE_ADDR for IP: 127.0.0.1
DEBUG Processing request: GET /dashboard/admin/organization from IP: 127.0.0.1
DEBUG Skipping throttling for test mode
DEBUG Skipping throttling for GET /dashboard/admin/organization (exempt path or DRF view)
ok
test_organization_switcher_shown_for_multiple_orgs (website.tests.test_organization.OrganizationSwitchingTests.test_organization_switcher_shown_for_multiple_orgs)
Test that organization switcher is shown when user manages multiple organizations ... WARNING OpenAI client not available (missing or invalid API key), using default BACON score
WARNING OpenAI client not available (missing or invalid API key), using default BACON score
WARNING OpenAI client not available (missing or invalid API key), using default BACON score
INFO ThrottlingMiddleware initialized with limits: {'GET': 100, 'POST': 50, 'OTHER': 30}
DEBUG Using REMOTE_ADDR for IP: 127.0.0.1
DEBUG Processing request: GET /dashboard/admin/organization from IP: 127.0.0.1
DEBUG Skipping throttling for test mode
DEBUG Skipping throttling for GET /dashboard/admin/organization (exempt path or DRF view)
ok
test_organization_switching_updates_session (website.tests.test_organization.OrganizationSwitchingTests.test_organization_switching_updates_session)
Test that switching organizations updates the session ... WARNING OpenAI client not available (missing or invalid API key), using default BACON score
WARNING OpenAI client not available (missing or invalid API key), using default BACON score
WARNING OpenAI client not available (missing or invalid API key), using default BACON score
INFO ThrottlingMiddleware initialized with limits: {'GET': 100, 'POST': 50, 'OTHER': 30}
DEBUG Using REMOTE_ADDR for IP: 127.0.0.1
DEBUG Processing request: GET /dashboard/admin/organization from IP: 127.0.0.1
DEBUG Skipping throttling for test mode
DEBUG Skipping throttling for GET /dashboard/admin/organization (exempt path or DRF view)
ok
test_regular_user_cannot_access_dashboard (website.tests.test_organization.OrganizationSwitchingTests.test_regular_user_cannot_access_dashboard)
Test that regular user without organizations is redirected ... WARNING OpenAI client not available (missing or invalid API key), using default BACON score
WARNING OpenAI client not available (missing or invalid API key), using default BACON score
WARNING OpenAI client not available (missing or invalid API key), using default BACON score
INFO ThrottlingMiddleware initialized with limits: {'GET': 100, 'POST': 50, 'OTHER': 30}
DEBUG Using REMOTE_ADDR for IP: 127.0.0.1
DEBUG Processing request: GET /dashboard/admin/organization from IP: 127.0.0.1
DEBUG Skipping throttling for test mode
DEBUG Skipping throttling for GET /dashboard/admin/organization (exempt path or DRF view)
FAIL

======================================================================
FAIL: test_regular_user_cannot_access_dashboard (website.tests.test_organization.OrganizationSwitchingTests.test_regular_user_cannot_access_dashboard)
Test that regular user without organizations is redirected
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/runner/work/BLT/BLT/website/tests/test_organization.py", line 248, in test_regular_user_cannot_access_dashboard
    self.assertEqual(response.status_code, 302)  # Redirect
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: 200 != 302

----------------------------------------------------------------------
Ran 195 tests in 120.780s

FAILED (failures=1)
Destroying test database for alias 'default' ('file:memorydb_default?mode=memory&cache=shared')...

For more information, see the Django testing documentation.

@DonnieBLT
Copy link
Collaborator

@copilot fix Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.

Location: website/templates/admin_dashboard_organization.html#L220-L236

Potential issue: The admin_dashboard_organization.html template defines a {% block extra_js %} to include the JavaScript for the organization switcher. However, it
extends the base_dashboard.html parent template, which does not define this block. In
Django's template inheritance, if a child template defines a block that is absent from
its parent, the block's content is silently ignored. Consequently, the JavaScript
required for the organization switcher functionality is never rendered to the page,
which makes the feature completely non-functional. and fix tests and lints

Copy link
Contributor Author

Copilot AI commented Dec 11, 2025

@copilot fix Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
...

Fixed in commit de86518. The JavaScript has been moved from the non-existent {% block extra_js %} into the {% block content %} block. Since base_dashboard.html doesn't define an extra_js block, the JavaScript was being silently ignored. Now it's properly included at the end of the content block and the organization switcher functionality works correctly.

@github-actions github-actions bot added last-active: 1d PR last updated 1 day ago and removed last-active: 0d PR last updated 0 days ago labels Dec 13, 2025
@github-actions
Copy link
Contributor

❌ Pre-commit checks failed

The pre-commit hooks found issues that need to be fixed. Please run the following commands locally to fix them:

# Install pre-commit if you haven't already
pip install pre-commit

# Run pre-commit on all files
pre-commit run --all-files

# Or run pre-commit on staged files only
pre-commit run

After running these commands, the pre-commit hooks will automatically fix most issues.
Please review the changes, commit them, and push to your branch.

💡 Tip: You can set up pre-commit to run automatically on every commit by running:

pre-commit install
Pre-commit output
[INFO] Initializing environment for https://github.com/pre-commit/pre-commit-hooks.
[WARNING] repo `https://github.com/pre-commit/pre-commit-hooks` uses deprecated stage names (commit, push) which will be removed in a future version.  Hint: often `pre-commit autoupdate --repo https://github.com/pre-commit/pre-commit-hooks` will fix this.  if it does not -- consider reporting an issue to that repo.
[INFO] Initializing environment for https://github.com/pycqa/isort.
[WARNING] repo `https://github.com/pycqa/isort` uses deprecated stage names (commit, merge-commit, push) which will be removed in a future version.  Hint: often `pre-commit autoupdate --repo https://github.com/pycqa/isort` will fix this.  if it does not -- consider reporting an issue to that repo.
[INFO] Initializing environment for https://github.com/astral-sh/ruff-pre-commit.
[INFO] Initializing environment for https://github.com/djlint/djLint.
[INFO] Initializing environment for local.
[INFO] Installing environment for https://github.com/pre-commit/pre-commit-hooks.
[INFO] Once installed this environment will be reused.
[INFO] This may take a few minutes...
[INFO] Installing environment for https://github.com/pycqa/isort.
[INFO] Once installed this environment will be reused.
[INFO] This may take a few minutes...
[INFO] Installing environment for https://github.com/astral-sh/ruff-pre-commit.
[INFO] Once installed this environment will be reused.
[INFO] This may take a few minutes...
[INFO] Installing environment for https://github.com/djlint/djLint.
[INFO] Once installed this environment will be reused.
[INFO] This may take a few minutes...
[INFO] Installing environment for local.
[INFO] Once installed this environment will be reused.
[INFO] This may take a few minutes...
check python ast.........................................................Passed
check builtin type constructor use.......................................Passed
check yaml...............................................................Passed
fix python encoding pragma...............................................Passed
mixed line ending........................................................Passed
isort....................................................................Passed
ruff.....................................................................Passed
ruff-format..............................................................Failed
- hook id: ruff-format
- files were modified by this hook

2 files reformatted, 470 files left unchanged


For more information, see the pre-commit documentation.

@github-actions
Copy link
Contributor

❌ Tests failed

The Django tests found issues that need to be fixed. Please review the test output below and fix the failing tests.

How to run tests locally

# Install dependencies
poetry install --with dev

# Run all tests
poetry run python manage.py test

# Run tests with verbose output
poetry run python manage.py test -v 3

# Run a specific test
poetry run python manage.py test app.tests.TestClass.test_method
Test output (last 100 lines)
DEBUG Skipping throttling for test mode
DEBUG Skipping throttling for GET /dashboard/admin/organization (exempt path or DRF view)
ok
test_invalid_organization_switch_shows_error (website.tests.test_organization.OrganizationSwitchingTests.test_invalid_organization_switch_shows_error)
Test that switching to invalid organization shows error ... WARNING OpenAI client not available (missing or invalid API key), using default BACON score
WARNING OpenAI client not available (missing or invalid API key), using default BACON score
WARNING OpenAI client not available (missing or invalid API key), using default BACON score
INFO ThrottlingMiddleware initialized with limits: {'GET': 100, 'POST': 50, 'OTHER': 30}
DEBUG Using REMOTE_ADDR for IP: 127.0.0.1
DEBUG Processing request: GET /dashboard/admin/organization from IP: 127.0.0.1
DEBUG Skipping throttling for test mode
DEBUG Skipping throttling for GET /dashboard/admin/organization (exempt path or DRF view)
ok
test_manager_can_access_managed_organizations (website.tests.test_organization.OrganizationSwitchingTests.test_manager_can_access_managed_organizations)
Test that manager can access organizations they manage ... WARNING OpenAI client not available (missing or invalid API key), using default BACON score
WARNING OpenAI client not available (missing or invalid API key), using default BACON score
WARNING OpenAI client not available (missing or invalid API key), using default BACON score
INFO ThrottlingMiddleware initialized with limits: {'GET': 100, 'POST': 50, 'OTHER': 30}
DEBUG Using REMOTE_ADDR for IP: 127.0.0.1
DEBUG Processing request: GET /dashboard/admin/organization from IP: 127.0.0.1
DEBUG Skipping throttling for test mode
DEBUG Skipping throttling for GET /dashboard/admin/organization (exempt path or DRF view)
ok
test_manager_can_view_managed_organization_detail (website.tests.test_organization.OrganizationSwitchingTests.test_manager_can_view_managed_organization_detail)
Test that manager can view details of organization they manage ... WARNING OpenAI client not available (missing or invalid API key), using default BACON score
WARNING OpenAI client not available (missing or invalid API key), using default BACON score
WARNING OpenAI client not available (missing or invalid API key), using default BACON score
INFO ThrottlingMiddleware initialized with limits: {'GET': 100, 'POST': 50, 'OTHER': 30}
DEBUG Using REMOTE_ADDR for IP: 127.0.0.1
DEBUG Processing request: GET /dashboard/admin/organization/3/ from IP: 127.0.0.1
DEBUG Skipping throttling for test mode
DEBUG Skipping throttling for GET /dashboard/admin/organization/3/ (exempt path or DRF view)
ok
test_non_integer_organization_id_shows_error (website.tests.test_organization.OrganizationSwitchingTests.test_non_integer_organization_id_shows_error)
Test that non-integer organization ID shows error ... WARNING OpenAI client not available (missing or invalid API key), using default BACON score
WARNING OpenAI client not available (missing or invalid API key), using default BACON score
WARNING OpenAI client not available (missing or invalid API key), using default BACON score
INFO ThrottlingMiddleware initialized with limits: {'GET': 100, 'POST': 50, 'OTHER': 30}
DEBUG Using REMOTE_ADDR for IP: 127.0.0.1
DEBUG Processing request: GET /dashboard/admin/organization from IP: 127.0.0.1
DEBUG Skipping throttling for test mode
DEBUG Skipping throttling for GET /dashboard/admin/organization (exempt path or DRF view)
ok
test_organization_switcher_not_shown_for_single_org (website.tests.test_organization.OrganizationSwitchingTests.test_organization_switcher_not_shown_for_single_org)
Test that organization switcher is not shown when user manages only one organization ... WARNING OpenAI client not available (missing or invalid API key), using default BACON score
WARNING OpenAI client not available (missing or invalid API key), using default BACON score
WARNING OpenAI client not available (missing or invalid API key), using default BACON score
INFO ThrottlingMiddleware initialized with limits: {'GET': 100, 'POST': 50, 'OTHER': 30}
DEBUG Using REMOTE_ADDR for IP: 127.0.0.1
DEBUG Processing request: GET /dashboard/admin/organization from IP: 127.0.0.1
DEBUG Skipping throttling for test mode
DEBUG Skipping throttling for GET /dashboard/admin/organization (exempt path or DRF view)
ok
test_organization_switcher_shown_for_multiple_orgs (website.tests.test_organization.OrganizationSwitchingTests.test_organization_switcher_shown_for_multiple_orgs)
Test that organization switcher is shown when user manages multiple organizations ... WARNING OpenAI client not available (missing or invalid API key), using default BACON score
WARNING OpenAI client not available (missing or invalid API key), using default BACON score
WARNING OpenAI client not available (missing or invalid API key), using default BACON score
INFO ThrottlingMiddleware initialized with limits: {'GET': 100, 'POST': 50, 'OTHER': 30}
DEBUG Using REMOTE_ADDR for IP: 127.0.0.1
DEBUG Processing request: GET /dashboard/admin/organization from IP: 127.0.0.1
DEBUG Skipping throttling for test mode
DEBUG Skipping throttling for GET /dashboard/admin/organization (exempt path or DRF view)
ok
test_organization_switching_updates_session (website.tests.test_organization.OrganizationSwitchingTests.test_organization_switching_updates_session)
Test that switching organizations updates the session ... WARNING OpenAI client not available (missing or invalid API key), using default BACON score
WARNING OpenAI client not available (missing or invalid API key), using default BACON score
WARNING OpenAI client not available (missing or invalid API key), using default BACON score
INFO ThrottlingMiddleware initialized with limits: {'GET': 100, 'POST': 50, 'OTHER': 30}
DEBUG Using REMOTE_ADDR for IP: 127.0.0.1
DEBUG Processing request: GET /dashboard/admin/organization from IP: 127.0.0.1
DEBUG Skipping throttling for test mode
DEBUG Skipping throttling for GET /dashboard/admin/organization (exempt path or DRF view)
ok
test_regular_user_cannot_access_dashboard (website.tests.test_organization.OrganizationSwitchingTests.test_regular_user_cannot_access_dashboard)
Test that regular user without organizations is redirected ... WARNING OpenAI client not available (missing or invalid API key), using default BACON score
WARNING OpenAI client not available (missing or invalid API key), using default BACON score
WARNING OpenAI client not available (missing or invalid API key), using default BACON score
INFO ThrottlingMiddleware initialized with limits: {'GET': 100, 'POST': 50, 'OTHER': 30}
DEBUG Using REMOTE_ADDR for IP: 127.0.0.1
DEBUG Processing request: GET /dashboard/admin/organization from IP: 127.0.0.1
DEBUG Skipping throttling for test mode
DEBUG Skipping throttling for GET /dashboard/admin/organization (exempt path or DRF view)
FAIL

======================================================================
FAIL: test_regular_user_cannot_access_dashboard (website.tests.test_organization.OrganizationSwitchingTests.test_regular_user_cannot_access_dashboard)
Test that regular user without organizations is redirected
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/runner/work/BLT/BLT/website/tests/test_organization.py", line 248, in test_regular_user_cannot_access_dashboard
    self.assertEqual(response.status_code, 302)  # Redirect
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: 200 != 302

----------------------------------------------------------------------
Ran 195 tests in 123.042s

FAILED (failures=1)
Destroying test database for alias 'default' ('file:memorydb_default?mode=memory&cache=shared')...

For more information, see the Django testing documentation.

@DonnieBLT
Copy link
Collaborator

@copilot please fix this

FAIL: test_regular_user_cannot_access_dashboard (website.tests.test_organization.OrganizationSwitchingTests.test_regular_user_cannot_access_dashboard)
Test that regular user without organizations is redirected

Traceback (most recent call last):
File "/home/runner/work/BLT/BLT/website/tests/test_organization.py", line 248, in test_regular_user_cannot_access_dashboard
self.assertEqual(response.status_code, 302) # Redirect
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: 200 != 302

… users without organizations

Co-authored-by: DonnieBLT <[email protected]>
Copy link
Contributor Author

Copilot AI commented Dec 14, 2025

@copilot please fix this

FAIL: test_regular_user_cannot_access_dashboard (website.tests.test_organization.OrganizationSwitchin...

Fixed in commit 4c23037. The issue was in the test setup - org3 was being created with regular_user as admin, giving them access to an organization when the test expected them to have none. Removed the admin assignment from org3 so regular_user now truly has no organizations and the test correctly expects a 302 redirect.

@github-actions github-actions bot added last-active: 0d PR last updated 0 days ago and removed last-active: 1d PR last updated 1 day ago labels Dec 15, 2025
@github-actions github-actions bot removed the last-active: 0d PR last updated 0 days ago label Dec 15, 2025
@github-actions
Copy link
Contributor

❌ Pre-commit checks failed

The pre-commit hooks found issues that need to be fixed. Please run the following commands locally to fix them:

# Install pre-commit if you haven't already
pip install pre-commit

# Run pre-commit on all files
pre-commit run --all-files

# Or run pre-commit on staged files only
pre-commit run

After running these commands, the pre-commit hooks will automatically fix most issues.
Please review the changes, commit them, and push to your branch.

💡 Tip: You can set up pre-commit to run automatically on every commit by running:

pre-commit install
Pre-commit output
[INFO] Initializing environment for https://github.com/pre-commit/pre-commit-hooks.
[WARNING] repo `https://github.com/pre-commit/pre-commit-hooks` uses deprecated stage names (commit, push) which will be removed in a future version.  Hint: often `pre-commit autoupdate --repo https://github.com/pre-commit/pre-commit-hooks` will fix this.  if it does not -- consider reporting an issue to that repo.
[INFO] Initializing environment for https://github.com/pycqa/isort.
[WARNING] repo `https://github.com/pycqa/isort` uses deprecated stage names (commit, merge-commit, push) which will be removed in a future version.  Hint: often `pre-commit autoupdate --repo https://github.com/pycqa/isort` will fix this.  if it does not -- consider reporting an issue to that repo.
[INFO] Initializing environment for https://github.com/astral-sh/ruff-pre-commit.
[INFO] Initializing environment for https://github.com/djlint/djLint.
[INFO] Initializing environment for local.
[INFO] Installing environment for https://github.com/pre-commit/pre-commit-hooks.
[INFO] Once installed this environment will be reused.
[INFO] This may take a few minutes...
[INFO] Installing environment for https://github.com/pycqa/isort.
[INFO] Once installed this environment will be reused.
[INFO] This may take a few minutes...
[INFO] Installing environment for https://github.com/astral-sh/ruff-pre-commit.
[INFO] Once installed this environment will be reused.
[INFO] This may take a few minutes...
[INFO] Installing environment for https://github.com/djlint/djLint.
[INFO] Once installed this environment will be reused.
[INFO] This may take a few minutes...
[INFO] Installing environment for local.
[INFO] Once installed this environment will be reused.
[INFO] This may take a few minutes...
check python ast.........................................................Passed
check builtin type constructor use.......................................Passed
check yaml...............................................................Passed
fix python encoding pragma...............................................Passed
mixed line ending........................................................Passed
isort....................................................................Passed
ruff.....................................................................Passed
ruff-format..............................................................Failed
- hook id: ruff-format
- files were modified by this hook

1 file reformatted, 471 files left unchanged


For more information, see the pre-commit documentation.

@github-actions github-actions bot added tests: passed Django tests passed and removed fix-pre-commit tests: failed Django tests failed labels Dec 15, 2025
@github-actions
Copy link
Contributor

❌ Pre-commit checks failed

The pre-commit hooks found issues that need to be fixed. Please run the following commands locally to fix them:

# Install pre-commit if you haven't already
pip install pre-commit

# Run pre-commit on all files
pre-commit run --all-files

# Or run pre-commit on staged files only
pre-commit run

After running these commands, the pre-commit hooks will automatically fix most issues.
Please review the changes, commit them, and push to your branch.

💡 Tip: You can set up pre-commit to run automatically on every commit by running:

pre-commit install
Pre-commit output
[INFO] Initializing environment for https://github.com/pre-commit/pre-commit-hooks.
[WARNING] repo `https://github.com/pre-commit/pre-commit-hooks` uses deprecated stage names (commit, push) which will be removed in a future version.  Hint: often `pre-commit autoupdate --repo https://github.com/pre-commit/pre-commit-hooks` will fix this.  if it does not -- consider reporting an issue to that repo.
[INFO] Initializing environment for https://github.com/pycqa/isort.
[WARNING] repo `https://github.com/pycqa/isort` uses deprecated stage names (commit, merge-commit, push) which will be removed in a future version.  Hint: often `pre-commit autoupdate --repo https://github.com/pycqa/isort` will fix this.  if it does not -- consider reporting an issue to that repo.
[INFO] Initializing environment for https://github.com/astral-sh/ruff-pre-commit.
[INFO] Initializing environment for https://github.com/djlint/djLint.
[INFO] Initializing environment for local.
[INFO] Installing environment for https://github.com/pre-commit/pre-commit-hooks.
[INFO] Once installed this environment will be reused.
[INFO] This may take a few minutes...
[INFO] Installing environment for https://github.com/pycqa/isort.
[INFO] Once installed this environment will be reused.
[INFO] This may take a few minutes...
[INFO] Installing environment for https://github.com/astral-sh/ruff-pre-commit.
[INFO] Once installed this environment will be reused.
[INFO] This may take a few minutes...
[INFO] Installing environment for https://github.com/djlint/djLint.
[INFO] Once installed this environment will be reused.
[INFO] This may take a few minutes...
[INFO] Installing environment for local.
[INFO] Once installed this environment will be reused.
[INFO] This may take a few minutes...
check python ast.........................................................Passed
check builtin type constructor use.......................................Passed
check yaml...............................................................Passed
fix python encoding pragma...............................................Passed
mixed line ending........................................................Passed
isort....................................................................Passed
ruff.....................................................................Passed
ruff-format..............................................................Failed
- hook id: ruff-format
- files were modified by this hook

1 file reformatted, 471 files left unchanged


For more information, see the pre-commit documentation.

@github-actions github-actions bot added last-active: 0d PR last updated 0 days ago last-active: 1d PR last updated 1 day ago and removed last-active: 0d PR last updated 0 days ago labels Dec 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

changes-requested PR has requested changes from a reviewer files-changed: 3 PR changes 3 files last-active: 1d PR last updated 1 day ago needs-peer-review PR needs peer review pre-commit: failed Pre-commit checks failed tests: passed Django tests passed

Projects

Status: Ready

Development

Successfully merging this pull request may close these issues.

allow for administrators to switch to different organizations if they manage more than one in the dashboard

3 participants