-
-
Notifications
You must be signed in to change notification settings - Fork 306
Add organization switching for administrators managing multiple organizations #5257
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
base: main
Are you sure you want to change the base?
Conversation
|
Important Review skippedBot user detected. To trigger a single review, invoke the You can disable this status message by setting the Note Other AI code review bot(s) detectedCodeRabbit 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. Comment |
Co-authored-by: DonnieBLT <128622481+DonnieBLT@users.noreply.github.com>
Co-authored-by: DonnieBLT <128622481+DonnieBLT@users.noreply.github.com>
❌ Pre-commit checks failedThe 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 runAfter running these commands, the pre-commit hooks will automatically fix most issues. 💡 Tip: You can set up pre-commit to run automatically on every commit by running: pre-commit installPre-commit outputFor more information, see the pre-commit documentation. |
Co-authored-by: DonnieBLT <128622481+DonnieBLT@users.noreply.github.com>
There was a problem hiding this 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_dashboardview to support organization switching with session-based persistence - Updated
admin_organization_dashboard_detailview 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 |
|
@copilot apply changes based on the comments in this thread |
Co-authored-by: DonnieBLT <128622481+DonnieBLT@users.noreply.github.com>
❌ Pre-commit checks failedThe 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 runAfter running these commands, the pre-commit hooks will automatically fix most issues. 💡 Tip: You can set up pre-commit to run automatically on every commit by running: pre-commit installPre-commit outputFor more information, see the pre-commit documentation. |
|
👋 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:
Once a valid peer review is submitted, this check will pass automatically. Thank you! |
❌ Pre-commit checks failedThe 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 runAfter running these commands, the pre-commit hooks will automatically fix most issues. 💡 Tip: You can set up pre-commit to run automatically on every commit by running: pre-commit installPre-commit outputFor more information, see the pre-commit documentation. |
|
@copilot address the most recent comments - fix this Review the code at the location below. A potential bug has been identified by an AI Location: website/views/organization.py#L168-L211 Potential issue: The |
Co-authored-by: DonnieBLT <128622481+DonnieBLT@users.noreply.github.com>
Fixed in commit ab9513b. The N+1 query problem has been resolved by evaluating the queryset once into a list at the beginning of the function. Before: 6+ database queries (exists, get, first, count, template iteration) All subsequent operations now use the in-memory list instead of hitting the database. This significantly improves performance for users managing multiple organizations. Thanks to @sidd190 for the excellent code review! |
❌ Tests failedThe 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_methodTest output (last 100 lines)For more information, see the Django testing documentation. |
❌ Pre-commit checks failedThe 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 runAfter running these commands, the pre-commit hooks will automatically fix most issues. 💡 Tip: You can set up pre-commit to run automatically on every commit by running: pre-commit installPre-commit outputFor more information, see the pre-commit documentation. |
@copilot fix ======================================================================
|
…direct Co-authored-by: DonnieBLT <128622481+DonnieBLT@users.noreply.github.com>
Fixed in commit 727d93a. The test now correctly expects inactive users to be redirected to the login page by the |
❌ Tests failedThe 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_methodTest output (last 100 lines)For more information, see the Django testing documentation. |
❌ Pre-commit checks failedThe 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 runAfter running these commands, the pre-commit hooks will automatically fix most issues. 💡 Tip: You can set up pre-commit to run automatically on every commit by running: pre-commit installPre-commit outputFor more information, see the pre-commit documentation. |
| // Safely encode the organization ID in the query parameter | ||
| url.searchParams.set('switch_to', encodeURIComponent(selectedOrg)); | ||
| // Use location.assign for safer navigation | ||
| window.location.assign(url.toString()); | ||
| } else { | ||
| console.error("Invalid URL: must be same-origin http/https"); | ||
| } | ||
| } catch (e) { | ||
| console.error("Invalid URL format:", e); | ||
| } | ||
| } |
This comment was marked as outdated.
This comment was marked as outdated.
Sorry, something went wrong.
❌ Tests failedThe 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_methodTest output (last 100 lines)For more information, see the Django testing documentation. |
|
@copilot fix Review the code at the location below. A potential bug has been identified by an AI Location: website/templates/admin_dashboard_organization.html#L220-L236 Potential issue: The |
Co-authored-by: DonnieBLT <128622481+DonnieBLT@users.noreply.github.com>
Fixed in commit de86518. The JavaScript has been moved from the non-existent |
❌ Pre-commit checks failedThe 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 runAfter running these commands, the pre-commit hooks will automatically fix most issues. 💡 Tip: You can set up pre-commit to run automatically on every commit by running: pre-commit installPre-commit outputFor more information, see the pre-commit documentation. |
❌ Tests failedThe 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_methodTest output (last 100 lines)For more information, see the Django testing documentation. |
Allow administrators to switch between organizations in the dashboard
JavaScript Block Fix
Fixed: Organization switcher JavaScript now properly renders on the page
Problem: The template was using
{% block extra_js %}which doesn't exist in the parentbase_dashboard.htmltemplate. In Django's template inheritance, blocks defined in child templates that don't exist in parent templates are silently ignored, causing the JavaScript to never render.Solution: Moved the JavaScript from the non-existent
extra_jsblock into thecontentblock at the end, ensuring it's properly included in the rendered page.Changes in
website/templates/admin_dashboard_organization.html:{% block extra_js %}...{% endblock extra_js %}contentblockPerformance Optimization - N+1 Query Fix
Fixed: N+1 query problem in
admin_organization_dashboardviewPrevious Updates
Test Fixes:
Security Fix:
All PR Review Comments Addressed:
Test Coverage
Original prompt
💡 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.