feat: connection-aware toolbar with state display and token refresh#2
feat: connection-aware toolbar with state display and token refresh#2
Conversation
Replace the plain Connect QAction with a QToolButton dropdown that shows connection state (server hostname when connected, "Connect to OpenSPP" when disconnected). Action buttons (Stats, Proximity, Geofence, Export) are now disabled when not connected. Key changes: - QToolButton with MenuButtonClick dropdown (connect/disconnect/change) - _set_actions_enabled() grays out data actions when disconnected - _update_connection_state() central method for all UI state updates - _disconnect() clears session without deleting saved credentials - OAPIF token refresh timer keeps Browser panel authenticated - Extracted APIHeader auth logic into shared openspp_qgis/auth.py - Added token_expires_in property to OpenSppClient - Renamed "Settings" to "Connection Settings..." (menu-only) - Fixed pre-existing test failures in test_batch_query.py
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly enhances the user experience and stability of the OpenSPP QGIS plugin by revamping its connection management. It introduces a more intuitive toolbar for connecting and disconnecting, provides clear visual feedback on the connection status, and ensures continuous authentication for OAPIF services by automatically refreshing access tokens. These changes streamline interaction with the OpenSPP server and prevent common issues related to expired sessions. Highlights
Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request significantly improves the plugin's user experience by introducing a connection-aware toolbar, a token refresh mechanism, and a disconnect flow. No new security vulnerabilities were identified in the added or modified code. The implementation correctly utilizes the QGIS authentication manager for secure credential storage and follows standard Qt/QGIS patterns. The code is well-structured, with authentication logic refactored into a dedicated module and accompanied by a comprehensive suite of new tests. One opportunity exists to simplify the token refresh logic by removing some duplicated code.
| self._token_refresh_timer = QTimer() | ||
| self._token_refresh_timer.setSingleShot(True) | ||
| self._token_refresh_timer.timeout.connect( | ||
| self._on_token_refresh | ||
| ) | ||
| self._token_refresh_timer.start( | ||
| self._TOKEN_REFRESH_RETRY_MS | ||
| ) |
There was a problem hiding this comment.
The logic to create and start a retry timer in this except block is a duplication of what _start_token_refresh_timer() already does. When a token refresh fails, self.client.token_expires_in will return 0, causing _start_token_refresh_timer() to correctly schedule a retry with _TOKEN_REFRESH_RETRY_MS. You can simplify this by just calling self._start_token_refresh_timer() here.
| self._token_refresh_timer = QTimer() | |
| self._token_refresh_timer.setSingleShot(True) | |
| self._token_refresh_timer.timeout.connect( | |
| self._on_token_refresh | |
| ) | |
| self._token_refresh_timer.start( | |
| self._TOKEN_REFRESH_RETRY_MS | |
| ) | |
| self._start_token_refresh_timer() |
Summary
update_oapif_auth_token()intoauth.py(used by both connection dialog and refresh timer)token_expires_inproperty toOpenSppClientfor accurate timer schedulingCloses #1
Files changed
openspp_plugin.py_set_actions_enabled(),_update_connection_state(),_disconnect(), token refresh timer, cleanup inunload()auth.pyconnection_dialog.pyauth.pyinstead of inline auth config logicclient.pytoken_expires_inpropertytest_plugin_ux.pytest_connection_settings.pyauth.pytest_batch_query.pyTest plan
python -m pytest tests/ -v)QToolButton.MenuButtonPopupis the correct enum (notMenuButtonClick)