From 8ae00d7657b0179e0fdfcede03cd8a97cd16d038 Mon Sep 17 00:00:00 2001 From: isUnknown Date: Fri, 22 Nov 2024 07:53:43 +0100 Subject: [PATCH] notifications working --- ...-bureaux-artistiquement-consideree.pdf.txt | 182 +----------------- public/site/models/project.php | 14 +- .../site/plugins/comments/routes/create.php | 4 +- .../site/plugins/comments/routes/delete.php | 2 +- public/site/plugins/notifications/index.php | 4 + .../notifications/user-methods/delete.php | 4 +- .../notifications/user-methods/read.php | 3 +- .../notifications/user-methods/send.php | 17 +- 8 files changed, 28 insertions(+), 202 deletions(-) diff --git a/public/content/projects/1_miss-dior-blooming-bouquet/1_client-brief/38969543_extrait-de-louis-sullivan-form-follow-function.-de-la-tour-de-bureaux-artistiquement-consideree.pdf.txt b/public/content/projects/1_miss-dior-blooming-bouquet/1_client-brief/38969543_extrait-de-louis-sullivan-form-follow-function.-de-la-tour-de-bureaux-artistiquement-consideree.pdf.txt index 654c483..66903d4 100644 --- a/public/content/projects/1_miss-dior-blooming-bouquet/1_client-brief/38969543_extrait-de-louis-sullivan-form-follow-function.-de-la-tour-de-bureaux-artistiquement-consideree.pdf.txt +++ b/public/content/projects/1_miss-dior-blooming-bouquet/1_client-brief/38969543_extrait-de-louis-sullivan-form-follow-function.-de-la-tour-de-bureaux-artistiquement-consideree.pdf.txt @@ -28,8 +28,8 @@ Comments: url: file://s0lNtRA0Z7ybTCWG position: pageIndex: 1 - x: "64.481176977282" - y: "14.478764478764" + x: '27.05459466102' + y: '35.135135135135' replies: [ ] text: test author: @@ -37,181 +37,7 @@ Comments: email: adrien.payet@outlook.com uuid: user://WWjXgPWk role: admin - date: 2024-11-21T19:18:40+01:00 - id: m3rmytqk - type: comment - isRead: false -- - location: - page: - uri: > - projects/miss-dior-blooming-bouquet/client-brief - title: Brief client - href: > - /projects/miss-dior-blooming-bouquet?dialog=client-brief - project: - title: Miss Dior Blooming Bouquet - uri: projects/miss-dior-blooming-bouquet - file: - uuid: file://s0lNtRA0Z7ybTCWG - url: file://s0lNtRA0Z7ybTCWG - position: - pageIndex: 1 - x: "64.481176977282" - y: "14.478764478764" - replies: [ ] - text: test - author: - name: Adrien Payet - email: adrien.payet@outlook.com - uuid: user://WWjXgPWk - role: admin - date: 2024-11-21T19:19:27+01:00 - id: m3rmzu2u - type: comment - isRead: false -- - location: - page: - uri: > - projects/miss-dior-blooming-bouquet/client-brief - title: Brief client - href: > - /projects/miss-dior-blooming-bouquet?dialog=client-brief - project: - title: Miss Dior Blooming Bouquet - uri: projects/miss-dior-blooming-bouquet - file: - uuid: file://s0lNtRA0Z7ybTCWG - url: file://s0lNtRA0Z7ybTCWG - position: - pageIndex: 1 - x: "64.481176977282" - y: "14.478764478764" - replies: [ ] - text: test - author: - name: Adrien Payet - email: adrien.payet@outlook.com - uuid: user://WWjXgPWk - role: admin - date: 2024-11-21T19:19:33+01:00 - id: m3rmzyl9 - type: comment - isRead: false -- - location: - page: - uri: > - projects/miss-dior-blooming-bouquet/client-brief - title: Brief client - href: > - /projects/miss-dior-blooming-bouquet?dialog=client-brief - project: - title: Miss Dior Blooming Bouquet - uri: projects/miss-dior-blooming-bouquet - file: - uuid: file://s0lNtRA0Z7ybTCWG - url: file://s0lNtRA0Z7ybTCWG - position: - pageIndex: 1 - x: "64.481176977282" - y: "14.478764478764" - replies: [ ] - text: test - author: - name: Adrien Payet - email: adrien.payet@outlook.com - uuid: user://WWjXgPWk - role: admin - date: 2024-11-21T19:19:44+01:00 - id: m3rn07nl - type: comment - isRead: false -- - location: - page: - uri: > - projects/miss-dior-blooming-bouquet/client-brief - title: Brief client - href: > - /projects/miss-dior-blooming-bouquet?dialog=client-brief - project: - title: Miss Dior Blooming Bouquet - uri: projects/miss-dior-blooming-bouquet - file: - uuid: file://s0lNtRA0Z7ybTCWG - url: file://s0lNtRA0Z7ybTCWG - position: - pageIndex: 1 - x: "64.481176977282" - y: "14.478764478764" - replies: [ ] - text: test - author: - name: Adrien Payet - email: adrien.payet@outlook.com - uuid: user://WWjXgPWk - role: admin - date: 2024-11-21T19:20:04+01:00 - id: m3rn0mf4 - type: comment - isRead: false -- - location: - page: - uri: > - projects/miss-dior-blooming-bouquet/client-brief - title: Brief client - href: > - /projects/miss-dior-blooming-bouquet?dialog=client-brief - project: - title: Miss Dior Blooming Bouquet - uri: projects/miss-dior-blooming-bouquet - file: - uuid: file://s0lNtRA0Z7ybTCWG - url: file://s0lNtRA0Z7ybTCWG - position: - pageIndex: 1 - x: "60.383375993749" - y: "31.660231660232" - replies: [ ] - text: test - author: - name: Adrien Payet - email: adrien.payet@outlook.com - uuid: user://WWjXgPWk - role: admin - date: 2024-11-21T19:35:48+01:00 - id: m3rnkvcn - type: comment - isRead: false -- - location: - page: - uri: > - projects/miss-dior-blooming-bouquet/client-brief - title: Brief client - href: > - /projects/miss-dior-blooming-bouquet?dialog=client-brief - project: - title: Miss Dior Blooming Bouquet - uri: projects/miss-dior-blooming-bouquet - file: - uuid: file://s0lNtRA0Z7ybTCWG - url: file://s0lNtRA0Z7ybTCWG - position: - pageIndex: 1 - x: '64.481176977282' - y: '50.772200772201' - replies: [ ] - text: test - author: - name: Adrien Payet - email: adrien.payet@outlook.com - uuid: user://WWjXgPWk - role: admin - date: 2024-11-21T19:36:11+01:00 - id: m3rnld52 + date: 2024-11-22T07:49:45+01:00 + id: m3sdsq23 type: comment isRead: false \ No newline at end of file diff --git a/public/site/models/project.php b/public/site/models/project.php index b199edc..4b3d93d 100644 --- a/public/site/models/project.php +++ b/public/site/models/project.php @@ -112,7 +112,17 @@ class ProjectPage extends Page { return $stepsLabel[$this->currentStep()->value()]; } - public function printManagers() { - return A::implode($this->managers()->toUsers()->pluck('name'), ', '); + // public function printManagers() { + // return A::implode($this->managers()->toUsers()->pluck('name'), ', '); + // } + + public function managers() { + return kirby()->users()->filter(function($user) { + if ($user->projects()->isEmpty()) { + return false; + } + + return $user->role() === 'admin' || $user->projects()->toPages()->has($this); + }); } } \ No newline at end of file diff --git a/public/site/plugins/comments/routes/create.php b/public/site/plugins/comments/routes/create.php index 9098823..b4f84b9 100644 --- a/public/site/plugins/comments/routes/create.php +++ b/public/site/plugins/comments/routes/create.php @@ -53,7 +53,9 @@ return [ try { $user->sendNotification($page->parent(), $newComment->toArray()); } catch (\Throwable $th) { - return $th->getMessage() . " in " . $th->getFile() . " line " . $th->getLine(); + echo json_encode([ + "error" => $th->getMessage() . " in " . $th->getFile() . " line " . $th->getLine(), + ]); } exit; diff --git a/public/site/plugins/comments/routes/delete.php b/public/site/plugins/comments/routes/delete.php index b03a5fa..4bf55c3 100644 --- a/public/site/plugins/comments/routes/delete.php +++ b/public/site/plugins/comments/routes/delete.php @@ -39,7 +39,7 @@ return [ echo json_encode(getFileData($newFile)); - kirby()->user()->deleteNotification($project->managers()->toUsers(), $data->id); + kirby()->user()->deleteNotification($project, $data->id); exit; } diff --git a/public/site/plugins/notifications/index.php b/public/site/plugins/notifications/index.php index 833d3fa..f0fa642 100644 --- a/public/site/plugins/notifications/index.php +++ b/public/site/plugins/notifications/index.php @@ -1,5 +1,9 @@ 'models/ProjectPage.php', +], __DIR__); + Kirby::plugin('adrienpayet/pdc-notifications', [ 'routes' => [ require(__DIR__ . '/routes/readAll.php'), diff --git a/public/site/plugins/notifications/user-methods/delete.php b/public/site/plugins/notifications/user-methods/delete.php index 54f2133..48dcb21 100644 --- a/public/site/plugins/notifications/user-methods/delete.php +++ b/public/site/plugins/notifications/user-methods/delete.php @@ -1,7 +1,7 @@ managers() as $projectManager) { try { $notifications = $projectManager->notifications()->isNotEmpty() ? Yaml::decode($projectManager->notifications()->value()) diff --git a/public/site/plugins/notifications/user-methods/read.php b/public/site/plugins/notifications/user-methods/read.php index 1bbc851..4de14df 100644 --- a/public/site/plugins/notifications/user-methods/read.php +++ b/public/site/plugins/notifications/user-methods/read.php @@ -1,7 +1,6 @@ notifications()->isNotEmpty() ? Yaml::decode($this->notifications()->value()) diff --git a/public/site/plugins/notifications/user-methods/send.php b/public/site/plugins/notifications/user-methods/send.php index b4c3950..b28389d 100644 --- a/public/site/plugins/notifications/user-methods/send.php +++ b/public/site/plugins/notifications/user-methods/send.php @@ -14,22 +14,7 @@ */ return function ($project, $notificationData) { - $recipients = kirby()->users()->filter(function($user) use ($project) { - if ($user === $this || $user->projects()->isEmpty()) { - return false; - } - throw new Exception(json_encode($user->name()), 1); - - $projects = $user->projects(); - if ($projects && ($user->role() == 'admin' || $projects->has($project))) { - return false; - } - - return false; - }); - - - // $recipients = page($projectUri)->managers()->toUsers()->not($this); + $recipients = $project->managers()->without($this); if (!$recipients) return;