feat: role-based access to the Messages page#194
Open
HardeepAsrani wants to merge 1 commit into
Open
Conversation
bc0e497 to
7f3ff04
Compare
Add two custom capabilities so support staff can review conversations without full dashboard access: - hyve_read_messages: view the Messages page and read conversations - hyve_manage_messages: delete conversations and export them Administrators receive both automatically; other roles can be granted either capability with a role-editor plugin or WP_Role::add_cap(). Also register every dashboard section as a WP submenu that deep-links into the app. Messages is gated on hyve_read_messages, the rest on manage_options, so a read-only user only sees Messages and the app opens in a messages-only view. The threads REST endpoints are gated per action (read for listing, manage for deleting).
7f3ff04 to
1a465a8
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this adds
Role-based access to the Messages page, so a support agent or team member can review chat conversations without being handed the whole Hyve dashboard.
Closes the access side of Codeinwp/hyve#232. Rather than a role picker in settings, this uses two WordPress capabilities (as suggested on the issue), which keeps it native and lets site owners grant access however they already manage roles.
Capabilities
hyve_read_messagesview the Messages page and read conversations.hyve_manage_messagesdelete conversations and export them (export lives in Pro).Administrators get both automatically. To give another role access, add the capability with a role-editor plugin or in code:
The grant for admins is done dynamically via
user_has_cap, so nothing is written to the roles table and there is nothing to clean up on uninstall.Submenus
Every top-level section of the dashboard is now a real WordPress submenu under Hyve (Dashboard, Knowledge Base, Messages, Integrations, Settings), each deep-linking into the app. Messages is gated on
hyve_read_messages; the rest stay onmanage_options.A user who only has
hyve_read_messagestherefore sees just the Hyve to Messages entry, and the app boots into a messages-only view (sidebar restricted to Messages, no settings request, so no 403 hang). The in-app sidebar is unchanged for admins.Enforcement
Access is enforced server-side, not just in the UI:
GET /threadsrequireshyve_read_messagesDELETE /threadsrequireshyve_manage_messagesThe delete and export buttons are hidden for users without
hyve_manage_messages, but the REST endpoints are the real gate.Manual QA
hyve_read_messages(wp user add-cap <user> hyve_read_messages). Log in: the Hyve menu shows only Messages, the app opens on Messages, the sidebar is limited to Messages, and there is no delete or export button.hyve_manage_messagesto that user. The delete button (and export, on Pro) appears and works.hyve_read_messages, aDELETEto/wp-json/hyve/v1/threadsreturns 403.