3535use OCA \Dossiq \Kernel \AppIdentity ;
3636use OCA \Dossiq \Kernel \Contracts \CaseAccessGuardInterface ;
3737use OCA \Dossiq \Kernel \Contracts \MentionNotificationServiceInterface ;
38- use OCA \Dossiq \Kernel \Contracts \NotePushInterface ;
3938use OCA \Dossiq \Service \Notes \MentionedNote ;
4039use OCP \AppFramework \Controller ;
4140use OCP \AppFramework \Http ;
@@ -60,7 +59,6 @@ class NotesController extends Controller {
6059 * @param MentionNotificationServiceInterface $mentionSvc The mention notification service
6160 * @param IUserSession $userSession The user session
6261 * @param LoggerInterface $logger The logger
63- * @param NotePushInterface $notePush Hands a note to integriq for the neighbouring register, or says why it did not
6462 * @param CaseAccessGuardInterface $caseAccessGuard Decides whether the caller may write notes on this case
6563 * @param IUserManager $userManager Tells which mentioned user ids have an account
6664 */
@@ -69,110 +67,12 @@ public function __construct(
6967 private readonly MentionNotificationServiceInterface $ mentionSvc ,
7068 private readonly IUserSession $ userSession ,
7169 private readonly LoggerInterface $ logger ,
72- private readonly NotePushInterface $ notePush ,
7370 private readonly CaseAccessGuardInterface $ caseAccessGuard ,
7471 private readonly IUserManager $ userManager ,
7572 ) {
7673 parent ::__construct (appName: AppIdentity::APP_ID , request: $ request );
7774 }//end __construct()
7875
79- /**
80- * Send one case note to the neighbouring register, or say why it stayed.
81- *
82- * A DELIBERATE ACT RATHER THAN A HOOK ON SAVE, and that is measured rather
83- * than preferred. Note storage is OpenRegister's entirely (ADR-022): this
84- * app never reads or writes a note, and OpenRegister dispatches no
85- * note-saved event dossiq could listen for. `notes#mention` beside this
86- * method exists for the same reason and works the same way, as a call the
87- * frontend makes after the note is already stored. Pushing on save needs
88- * an event that does not exist yet, and that is an openregister row.
89- *
90- * The GUARD IS MUTATION, not read. Sending a note to another organisation
91- * is externally visible and not undoable, so it refuses what a change to
92- * the case would refuse rather than what reading it would.
93- *
94- * @param string $caseId The case the note is on.
95- *
96- * @return JSONResponse The outcome, or a refusal.
97- *
98- * @spec openspec/specs/zgw-api-mapping/spec.md
99- */
100- #[NoAdminRequired]
101- public function push (string $ caseId ): JSONResponse {
102- $ refusal = $ this ->pushRefusal (caseId: $ caseId );
103- if ($ refusal !== null ) {
104- return $ refusal ;
105- }
106-
107- $ data = $ this ->readJsonBody ();
108- $ note = $ data ['note ' ] ?? null ;
109- if (is_array ($ note ) === false || $ note === []) {
110- return new JSONResponse (['error ' => 'A note is required ' ], Http::STATUS_BAD_REQUEST );
111- }
112-
113- return $ this ->pushNote (caseId: $ caseId , note: $ note );
114- }//end push()
115-
116- /**
117- * Refuse a push without a session (401), without a case id (400) or by a
118- * caller who may not change the case (403).
119- *
120- * @param string $caseId The case the note is on.
121- *
122- * @return JSONResponse|null The refusal, or null when the push may go ahead.
123- *
124- * @spec openspec/specs/zgw-api-mapping/spec.md
125- */
126- private function pushRefusal (string $ caseId ): ?JSONResponse {
127- $ actor = $ this ->userSession ->getUser ();
128- if ($ actor === null ) {
129- return new JSONResponse (['error ' => 'Not authenticated ' ], Http::STATUS_UNAUTHORIZED );
130- }
131-
132- if (trim ($ caseId ) === '' ) {
133- return new JSONResponse (['error ' => 'A case id is required ' ], Http::STATUS_BAD_REQUEST );
134- }
135-
136- if ($ this ->caseAccessGuard ->hasCaseMutationAccess (caseId: $ caseId , user: $ actor ) === false ) {
137- return new JSONResponse (['error ' => 'Not authorized ' ], Http::STATUS_FORBIDDEN );
138- }
139-
140- return null ;
141- }//end pushRefusal()
142-
143- /**
144- * Push the note and answer with its outcome; a push that throws is a logged 500.
145- *
146- * @param string $caseId The case the note is on.
147- * @param array<string, mixed> $note The note.
148- *
149- * @return JSONResponse
150- *
151- * @spec openspec/specs/zgw-api-mapping/spec.md
152- */
153- private function pushNote (string $ caseId , array $ note ): JSONResponse {
154- try {
155- $ outcome = $ this ->notePush ->push (caseId: $ caseId , note: $ note );
156- } catch (\Throwable $ e ) {
157- $ this ->logger ->error (
158- 'NotesController: a note push failed ' ,
159- ['caseId ' => $ caseId , 'exception ' => $ e ->getMessage ()]
160- );
161-
162- return new JSONResponse (
163- ['error ' => 'The note could not be sent ' ],
164- Http::STATUS_INTERNAL_SERVER_ERROR
165- );
166- }
167-
168- // 200 for every outcome INCLUDING a failure, because the caller asked
169- // what happened and every answer here is a real answer. The outcome is
170- // in the body, where the notes panel reads it; a 500 for a refused
171- // push would be this app reporting its own success or failure rather
172- // than the note's.
173- return new JSONResponse ($ outcome );
174- }//end pushNote()
175-
17676 /**
17777 * Notify every user mentioned in a just-saved note.
17878 *
0 commit comments