testing progress

This commit is contained in:
2025-08-12 10:36:32 -07:00
parent 1633eb46df
commit f6429110e5
3 changed files with 22 additions and 14 deletions

View File

@@ -31,6 +31,14 @@ class TWP_Admin {
return; return;
} }
// Determine first available page for agents
$first_page = 'twilio-wp-browser-phone'; // Default to browser phone
if (current_user_can('twp_access_voicemails')) $first_page = 'twilio-wp-voicemails';
elseif (current_user_can('twp_access_call_log')) $first_page = 'twilio-wp-call-logs';
elseif (current_user_can('twp_access_agent_queue')) $first_page = 'twilio-wp-agent-queue';
elseif (current_user_can('twp_access_sms_inbox')) $first_page = 'twilio-wp-sms-inbox';
elseif (current_user_can('twp_access_browser_phone')) $first_page = 'twilio-wp-browser-phone';
// Main menu - show dashboard for admins, redirect to first available page for agents // Main menu - show dashboard for admins, redirect to first available page for agents
if (current_user_can('manage_options')) { if (current_user_can('manage_options')) {
add_menu_page( add_menu_page(
@@ -52,14 +60,6 @@ class TWP_Admin {
array($this, 'display_plugin_dashboard') array($this, 'display_plugin_dashboard')
); );
} else { } else {
// For agents, determine first available page
$first_page = 'twilio-wp-browser-phone'; // Default to browser phone
if (current_user_can('twp_access_voicemails')) $first_page = 'twilio-wp-voicemails';
elseif (current_user_can('twp_access_call_log')) $first_page = 'twilio-wp-call-logs';
elseif (current_user_can('twp_access_agent_queue')) $first_page = 'twilio-wp-agent-queue';
elseif (current_user_can('twp_access_sms_inbox')) $first_page = 'twilio-wp-sms-inbox';
elseif (current_user_can('twp_access_browser_phone')) $first_page = 'twilio-wp-browser-phone';
add_menu_page( add_menu_page(
'Twilio Phone', 'Twilio Phone',
'Twilio Phone', 'Twilio Phone',
@@ -129,7 +129,7 @@ class TWP_Admin {
} }
// Agent-accessible pages // Agent-accessible pages
$menu_parent = current_user_can('manage_options') ? 'twilio-wp-plugin' : null; $menu_parent = current_user_can('manage_options') ? 'twilio-wp-plugin' : $first_page;
if (current_user_can('manage_options') || current_user_can('twp_access_voicemails')) { if (current_user_can('manage_options') || current_user_can('twp_access_voicemails')) {
add_submenu_page( add_submenu_page(
@@ -2999,7 +2999,7 @@ class TWP_Admin {
public function ajax_get_phone_numbers() { public function ajax_get_phone_numbers() {
check_ajax_referer('twp_ajax_nonce', 'nonce'); check_ajax_referer('twp_ajax_nonce', 'nonce');
if (!current_user_can('manage_options')) { if (!current_user_can('manage_options') && !current_user_can('twp_access_phone_numbers')) {
wp_die('Unauthorized'); wp_die('Unauthorized');
} }
@@ -4026,7 +4026,7 @@ class TWP_Admin {
public function ajax_generate_capability_token() { public function ajax_generate_capability_token() {
check_ajax_referer('twp_ajax_nonce', 'nonce'); check_ajax_referer('twp_ajax_nonce', 'nonce');
if (!current_user_can('manage_options')) { if (!current_user_can('manage_options') && !current_user_can('twp_access_browser_phone')) {
wp_send_json_error('Insufficient permissions'); wp_send_json_error('Insufficient permissions');
} }
@@ -5246,7 +5246,7 @@ class TWP_Admin {
</div> </div>
</div> </div>
<?php if (!$smart_routing_configured): ?> <?php if (!$smart_routing_configured && current_user_can('manage_options')): ?>
<div class="setup-info"> <div class="setup-info">
<h4>📋 Setup Required</h4> <h4>📋 Setup Required</h4>
<p>To enable mode switching, update your phone number webhook to:</p> <p>To enable mode switching, update your phone number webhook to:</p>

View File

@@ -399,6 +399,7 @@ class TWP_Activator {
'twp_access_outbound_calls' => true, 'twp_access_outbound_calls' => true,
'twp_access_sms_inbox' => true, 'twp_access_sms_inbox' => true,
'twp_access_browser_phone' => true, 'twp_access_browser_phone' => true,
'twp_access_phone_numbers' => true,
)); ));
} }
} }

View File

@@ -67,8 +67,9 @@ class TWP_Core {
* Ensure custom user roles exist * Ensure custom user roles exist
*/ */
private function ensure_user_roles() { private function ensure_user_roles() {
// Check if the phone_agent role exists $role = get_role('phone_agent');
if (!get_role('phone_agent')) {
if (!$role) {
// Create the Phone Agent role with limited capabilities // Create the Phone Agent role with limited capabilities
add_role('phone_agent', 'Phone Agent', array( add_role('phone_agent', 'Phone Agent', array(
// Basic WordPress capabilities // Basic WordPress capabilities
@@ -84,7 +85,13 @@ class TWP_Core {
'twp_access_outbound_calls' => true, 'twp_access_outbound_calls' => true,
'twp_access_sms_inbox' => true, 'twp_access_sms_inbox' => true,
'twp_access_browser_phone' => true, 'twp_access_browser_phone' => true,
'twp_access_phone_numbers' => true,
)); ));
} else {
// Update existing role with any missing capabilities
if (!$role->has_cap('twp_access_phone_numbers')) {
$role->add_cap('twp_access_phone_numbers');
}
} }
} }