PluginProbe
FluentBoards – Project Management, Task Management, Goal Tracking, Kanban Board, and, Team Collaboration / trunk
FluentBoards – Project Management, Task Management, Goal Tracking, Kanban Board, and, Team Collaboration vtrunk
2.0.15 2.0.12 2.0.10 2.0.4 2.0.1 2.0.0 1.95.3 1.95.2 1.95 1.91.6 trunk 1.11 1.12 1.13 1.20 1.21 1.22 1.23 1.30 1.31 1.32 1.35 1.40 1.41 1.45 All 41 releases
← All changes | app/Http/Controllers/NotificationController.php +36 -26 1.11trunk View file →
@@ -15,30 +15,29 @@
15 15 $this->notificationService = $notificationService;
16 16 }
17 17 public function getAllNotifications(Request $request)
18 18 {
19 - $data = $request->all();
20 19 try {
21 - $per_page = isset($data['per_page']) ? $data['per_page'] : 20;
22 - $page = isset($data['page']) ? $data['page'] : 1;
23 - $data = $this->notificationService->getAllNotifications($per_page, $page);
20 + $per_page = $request->getSafe('per_page', 'intval', 20);
21 + $page = $request->getSafe('page', 'intval', 1);
22 + $action = $request->getSafe('action', 'sanitize_text_field', 'all');
23 + $data = $this->notificationService->getAllNotifications($per_page, $page, $action);
24 24
25 25 return $this->sendSuccess($data, 200);
26 26 } catch (\Exception $e) {
27 - return $this->sendError($e->getMessage(), 404);
27 + return $this->sendError($e->getMessage(), 400);
28 28 }
29 29 }
30 30 public function getAllUnreadNotifications(Request $request)
31 31 {
32 - $data = $request->all();
33 32 try {
34 - $per_page = isset($data['per_page']) ? $data['per_page'] : 20;
35 - $page = isset($data['page']) ? $data['page'] : 1;
33 + $per_page = $request->getSafe('per_page', 'intval', 20);
34 + $page = $request->getSafe('page', 'intval', 1);
36 35 return $this->sendSuccess(
37 36 $this->notificationService->getAllUnreadNotifications($per_page, $page),
38 37 200);
39 38 } catch (\Exception $e) {
40 - return $this->sendError($e->getMessage(), 404);
39 + return $this->sendError($e->getMessage(), 400);
41 40 }
42 41 }
43 42
44 43 public function newNotificationNumber()
@@ -49,52 +48,63 @@
49 48 return $this->sendSuccess([
50 49 'total_unread' => $unread_notifications,
51 50 ], 200);
52 51 } catch (\Exception $e) {
53 - return $this->sendError($e->getMessage(), 404);
52 + return $this->sendError($e->getMessage(), 400);
54 53 }
55 54 }
56 55
56 + /**
57 + * Return the current user's board notification settings with safe defaults.
58 + */
57 59 public function getBoardNotificationSettings($board_id)
58 60 {
61 + $board_id = absint($board_id);
59 62 try {
60 63 $userId = get_current_user_id();
61 - $boardSettings = $this->notificationService->getBoardNotificationSettingsOfUser($board_id, $userId);
62 - if ($boardSettings->preferences)
63 - $currentSettings = maybe_unserialize($boardSettings->preferences);
64 + $currentSettings = $this->notificationService->getBoardNotificationSettingsWithDefaults($board_id, $userId);
64 65
65 66 return $this->sendSuccess([
66 67 'currentSettings' => $currentSettings,
67 68 ], 200);
68 69 } catch (\Exception $e) {
69 - return $this->sendError($e->getMessage(), 404);
70 + return $this->sendError($e->getMessage(), 400);
70 71 }
71 72 }
72 73
73 74 public function updateBoardNotificationSettings(Request $request, $board_id)
74 75 {
76 + $board_id = absint($board_id);
75 77 try {
76 - $newSettings = $request->getSafe('updatedSettings');
77 -
78 -
78 + // updatedSettings is an array, sanitize each element
79 + $rawSettings = $request->getSafe('updatedSettings');
80 + $newSettings = [];
81 + if (is_array($rawSettings)) {
82 + foreach ($rawSettings as $key => $value) {
83 + // Sanitize key and value
84 + $sanitizedKey = sanitize_text_field($key);
85 + $sanitizedValue = sanitize_text_field($value);
86 + $newSettings[$sanitizedKey] = $sanitizedValue;
87 + }
88 + }
79 89 $this->notificationService->updateBoardNotificationSettings($newSettings, $board_id);
80 90 return $this->sendSuccess([
81 - 'message' => __('Board notification settings has been updated', 'fluent-boards'),
91 + 'message' => __('Board notification settings have been updated', 'fluent-boards'),
82 92 ], 200);
83 93 } catch (\Exception $e) {
84 - return $this->sendError($e->getMessage(), 404);
94 + return $this->sendError($e->getMessage(), 400);
85 95 }
86 96 }
87 97
88 98 public function readNotification(Request $request)
89 99 {
90 - try{
91 - $notificationId = $request->getSafe('notification_id');
100 + try {
101 + $notificationId = $request->getSafe('notification_id', 'intval');
92 102
93 - if ( $notificationId ) {
94 - $notification = $this->notificationService->markNotificationRead( $notificationId );
103 + if ($notificationId) {
104 + $notification = $this->notificationService->markNotificationRead($notificationId);
95 105 } else {
96 - $notification = $this->notificationService->markAllRead();
106 + $notification = $this->notificationService->markAllRead();
97 107 }
98 108
99 109 return $this->sendSuccess([
100 110 'message' => __('Notification is updated', 'fluent-boards'),
@@ -101,8 +111,8 @@
101 111 'notification' => $notification
102 112 ], 200);
103 113
104 114 } catch (\Exception $e) {
105 - return $this->sendError($e->getMessage(), 404);
115 + return $this->sendError($e->getMessage(), 400);
106 116 }
107 117 }
108 -}
118 +}