From 3d25ad7de4fdbb3eba2cde2a62422e6be5d79a0a Mon Sep 17 00:00:00 2001
From: Jake Vanderwerf <get@jakevanderwerf.ca>
Date: Tue, 25 Aug 2026 22:57:22 +0000
Subject: [PATCH] =It's been a minute. I went through the Routes and associated Managers and ensured they played together well. Reworked the Cache.php, and I think I caught all the references. Moving away from JVBase() root class, to individuall classes that are Instanced. Double checked for the ABSPATH check in every file, and added index.php to every directory that didn't already have it. Also still working on the MenuBlock to work with WooCommerce for now for Northeh

---
 inc/rest/routes/IntegrationsRoutes.php |   35 ++++++++++++++++++++++++++++-------
 1 files changed, 28 insertions(+), 7 deletions(-)

diff --git a/inc/rest/routes/IntegrationsRoutes.php b/inc/rest/routes/IntegrationsRoutes.php
index 4bfb20b..8df07a2 100644
--- a/inc/rest/routes/IntegrationsRoutes.php
+++ b/inc/rest/routes/IntegrationsRoutes.php
@@ -1,6 +1,8 @@
 <?php
 namespace JVBase\rest\routes;
 
+use JVBase\Instance;
+use JVBase\integrations\ServiceMap;
 use JVBase\rest\Rest;
 use JVBase\rest\Route;
 use WP_REST_Request;
@@ -13,7 +15,8 @@
 
 class IntegrationsRoutes extends Rest
 {
-
+	use Instance;
+	use ServiceMap;
 	/**
 	 * Register REST routes
 	 */
@@ -22,7 +25,7 @@
 		Route::for('integrations')
 			->post([$this, 'handleAction'])
 			->args([
-				'service'	=> 'string|required|enum:'.implode(',',JVB()->getAvailableServices()),
+				'service'	=> 'string|required|enum:'.implode(',',$this->getAvailableServices()),
 				'action'	=> 'string|required',
 				'user_id'	=> 'int',
 				'context'	=> 'string|enum:admin,user',
@@ -57,12 +60,17 @@
 		if ($theUserID === false) {
 			return $this->validationError(['message' => 'Not logged in']);
 		}
-		$integration = JVB()->connect($service, $theUserID);
+		$integration = $this->getService($service);
+		if (!method_exists($integration, 'switchUser')) {
+			return $this->validationError(['message' => 'Cannot get user integration']);
+		}
 
-		if (!$integration) {
+		if (!$integration || !method_exists($integration, 'processAction')) {
 			return $this->validationError(['message'=>'Invalid service']);
 		}
 
+		$integration->switchUser($theUserID);
+
 		$integration->getCredentials();
 
 		// Handle the action
@@ -88,13 +96,26 @@
 		$user_id = $request->get_param('user_id');
 		$return_url = $request->get_param('return_url');
 
-		$integration = JVB()->connect($service, $user_id);
+		$theUserID = current_user_can('manage_options') ? null : get_current_user_id();
+		if ($theUserID === false) {
+			return $this->validationError(['message' => 'Not logged in']);
+		}
+		$integration = $this->getService($service);
+		if (!method_exists($integration, 'switchUser')) {
+			return $this->validationError(['message' => 'Cannot get user integration']);
+		}
 
-		if (!$integration || !$integration->isOAuthService) {
+		if (!$integration || !method_exists($integration, 'processAction')) {
 			return $this->validationError(['message'=>'Invalid service']);
 		}
 
-		$auth_url = $integration->getOAuthUrl($return_url);
+		$integration->switchUser($theUserID);
+
+		if (!$integration || !method_exists($integration, 'getOAuthBaseURL') || is_null($integration->getOAuthBaseURL())) {
+			return $this->validationError(['message'=>'Invalid service']);
+		}
+
+		$auth_url = $integration->getOAuthBaseURL($return_url);
 
 		if ($auth_url) {
 			return $this->success($auth_url);

--
Gitblit v1.10.0