From fff721dd185f5b97f7ae7a6e64189e55887ff590 Mon Sep 17 00:00:00 2001
From: Jake Vanderwerf <get@jakevanderwerf.ca>
Date: Sun, 05 Jul 2026 18:36:57 +0000
Subject: [PATCH] =Cleaning up the Square integration (still a bit more to do yet). Also majorly overhauled /rest/ files to ignore a rest request 'user' paramater, and rely on get_current_user_id() instead.

---
 inc/rest/routes/NotificationsRoutes.php |   54 +++++++++++++++++++++---------------------------------
 1 files changed, 21 insertions(+), 33 deletions(-)

diff --git a/inc/rest/routes/NotificationsRoutes.php b/inc/rest/routes/NotificationsRoutes.php
index ff84cdc..b3c2e05 100644
--- a/inc/rest/routes/NotificationsRoutes.php
+++ b/inc/rest/routes/NotificationsRoutes.php
@@ -146,7 +146,6 @@
 		Route::for('notifications')
 			->get([$this, 'getNotifications'])
 			->args([
-				'user' => 'integer|required',
 				'type' => 'string',
 				'status' => 'string|enum:unread,read,actioned,dismissed',
 				'limit' => 'integer|default:20|min:1|max:100',
@@ -160,7 +159,6 @@
 		Route::for('notifications/read')
 			->post([$this, 'markRead'])
 			->args([
-				'user' => 'integer|required',
 				'notification_id' => 'integer|required',
 			])
 			->auth('user')
@@ -171,7 +169,6 @@
 		Route::for('notifications/read-all')
 			->post([$this, 'markAllRead'])
 			->args([
-				'user' => 'integer|required',
 				'type' => 'string',
 			])
 			->auth('user')
@@ -182,7 +179,6 @@
 		Route::for('notifications/action')
 			->post([$this, 'markActioned'])
 			->args([
-				'user' => 'integer|required',
 				'notification_id' => 'integer|required',
 			])
 			->auth('user')
@@ -193,7 +189,6 @@
 		Route::for('notifications/dismiss')
 			->post([$this, 'markDismissed'])
 			->args([
-				'user' => 'integer|required',
 				'notification_id' => 'integer|required',
 			])
 			->auth('user')
@@ -204,7 +199,6 @@
 		Route::for('notifications/count')
 			->get([$this, 'getUnreadCount'])
 			->args([
-				'user' => 'integer|required',
 				'type' => 'string',
 			])
 			->auth('user')
@@ -221,16 +215,15 @@
 	 */
 	public function getNotifications(WP_REST_Request $request): WP_REST_Response
 	{
-		$user_id = absint($request->get_param('user'));
+		$user_id = get_current_user_id();
+		if (!$user_id) {
+			return $this->unauthorized();
+		}
 		$type = sanitize_text_field($request->get_param('type') ?? '');
 		$status = sanitize_text_field($request->get_param('status') ?? '');
 		$limit = absint($request->get_param('limit'));
 		$offset = absint($request->get_param('offset'));
 
-		if (!$this->checkUser($user_id)) {
-			return $this->unauthorized();
-		}
-
 		$cacheKey = compact('user_id', 'type', 'status', 'limit', 'offset');
 
 		$result = $this->cache->remember($cacheKey, function() use ($user_id, $type, $status, $limit, $offset) {
@@ -265,12 +258,11 @@
 	 */
 	public function getUnreadCount(WP_REST_Request $request): WP_REST_Response
 	{
-		$user_id = absint($request->get_param('user'));
-		$type = sanitize_text_field($request->get_param('type') ?? '');
-
-		if (!$this->checkUser($user_id)) {
+		$user_id = get_current_user_id();
+		if (!$user_id) {
 			return $this->unauthorized();
 		}
+		$type = sanitize_text_field($request->get_param('type') ?? '');
 
 		$cacheKey = compact('user_id', 'type');
 
@@ -555,7 +547,7 @@
 				$statusCondition = $wpdb->prepare("a.status = %s", $status);
 			}
 
-			$approvals = Registrar::getFeatured('approve_new');
+			$approvals = Registrar::withFeature('approve_new');
 			foreach ($approvals as $type => $config) {
 				$table = $wpdb->prefix . BASE . 'approval_' . $type . 'requests';
 				$votes = $wpdb->prefix . BASE . 'approval_' . $type . 'votes';
@@ -647,12 +639,11 @@
 	 */
 	public function markRead(WP_REST_Request $request): WP_REST_Response
 	{
-		$user_id = absint($request->get_param('user'));
-		$notification_id = absint($request->get_param('notification_id'));
-
-		if (!$this->checkUser($user_id)) {
+		$user_id = get_current_user_id();
+		if (!$user_id) {
 			return $this->unauthorized();
 		}
+		$notification_id = absint($request->get_param('notification_id'));
 
 		try {
 			$result = $this->notifications->transaction(function($table) use ($notification_id, $user_id) {
@@ -695,12 +686,11 @@
 	 */
 	public function markAllRead(WP_REST_Request $request): WP_REST_Response
 	{
-		$user_id = absint($request->get_param('user'));
-		$type = sanitize_text_field($request->get_param('type') ?? '');
-
-		if (!$this->checkUser($user_id)) {
+		$user_id = get_current_user_id();
+		if (!$user_id) {
 			return $this->unauthorized();
 		}
+		$type = sanitize_text_field($request->get_param('type') ?? '');
 
 		try {
 			$where = ['owner_id' => $user_id, 'status' => 'unread'];
@@ -730,12 +720,11 @@
 	 */
 	public function markActioned(WP_REST_Request $request): WP_REST_Response
 	{
-		$user_id = absint($request->get_param('user'));
-		$notification_id = absint($request->get_param('notification_id'));
-
-		if (!$this->checkUser($user_id)) {
+		$user_id = get_current_user_id();
+		if (!$user_id) {
 			return $this->unauthorized();
 		}
+		$notification_id = absint($request->get_param('notification_id'));
 
 		try {
 			$result = $this->notifications->transaction(function($table) use ($notification_id, $user_id) {
@@ -779,12 +768,11 @@
 	 */
 	public function markDismissed(WP_REST_Request $request): WP_REST_Response
 	{
-		$user_id = absint($request->get_param('user'));
-		$notification_id = absint($request->get_param('notification_id'));
-
-		if (!$this->checkUser($user_id)) {
+		$user_id = get_current_user_id();
+		if (!$user_id) {
 			return $this->unauthorized();
 		}
+		$notification_id = absint($request->get_param('notification_id'));
 
 		try {
 			$result = $this->notifications->transaction(function($table) use ($notification_id, $user_id) {
@@ -1318,7 +1306,7 @@
 			'status' => in_array($params['status'] ?? '', ['all', 'unread', 'expired'])
 				? $params['status']
 				: 'unread',
-			'user_id' => absint($params['user'] ?? get_current_user_id()),
+			'user_id' => get_current_user_id(),
 			'page' => absint($params['page'] ?? 1),
 			'type' => in_array($params['type'] ?? '', array_keys($this->manager->notification_types ?? []))
 				? $params['type']

--
Gitblit v1.10.0