@@ -309,7 +309,7 @@ public function validateExAppRequestToNC(IRequest $request, bool $isDav = false)
309309 $ this ->logger ->error (sprintf ('Error getting path info. Error: %s ' , $ e ->getMessage ()), ['exception ' => $ e ]);
310310 return false ;
311311 }
312- if (( $ this -> sanitizeOcsRoute ( $ path ) !== ' /apps/app_api/ex-app/state ' ) && !$ exApp -> getEnabled ( )) {
312+ if (! $ exApp -> getEnabled () && !$ this -> isExemptFromEnabledCheck ( $ path , $ exApp )) {
313313 $ this ->logger ->error (sprintf ('ExApp with appId %s is disabled (%s) ' , $ request ->getHeader ('EX-APP-ID ' ), $ request ->getRequestUri ()));
314314 return false ;
315315 }
@@ -368,6 +368,26 @@ private function sanitizeOcsRoute(string $route): string {
368368 return $ route ;
369369 }
370370
371+ /**
372+ * Check if the given path is exempt from the ExApp enabled check.
373+ * /ex-app/state is always exempt (query enabled state).
374+ * Init status endpoints are only exempt while the ExApp is actively being
375+ * installed or updated (status type set server-side by Register/Update commands),
376+ * preventing a disabled ExApp from re-enabling itself via set_init_status(100).
377+ */
378+ private function isExemptFromEnabledCheck (string $ path , ExApp $ exApp ): bool {
379+ $ sanitizedPath = $ this ->sanitizeOcsRoute ($ path );
380+ if ($ sanitizedPath === '/apps/app_api/ex-app/state ' ) {
381+ return true ;
382+ }
383+ $ status = $ exApp ->getStatus ();
384+ $ isInitializing = in_array ($ status ['type ' ] ?? '' , ['install ' , 'update ' ], true );
385+ if ($ isInitializing && $ sanitizedPath === '/apps/app_api/ex-app/status ' ) {
386+ return true ;
387+ }
388+ return false ;
389+ }
390+
371391 private function getCustomLogger (string $ name ): LoggerInterface {
372392 $ path = $ this ->config ->getSystemValue ('datadirectory ' , \OC ::$ SERVERROOT . '/data ' ) . '/ ' . $ name ;
373393 return $ this ->logFactory ->getCustomPsrLogger ($ path );
@@ -411,7 +431,11 @@ public function dispatchExAppInitInternal(ExApp $exApp): void {
411431 }
412432
413433 $ this ->setAppInitProgress ($ exApp , 0 );
414- $ this ->exAppService ->enableExAppInternal ($ exApp );
434+ if (!$ this ->exAppService ->enableExAppInternal ($ exApp )) {
435+ $ this ->logger ->error (sprintf ('Failed to enable ExApp %s before init dispatch ' , $ exApp ->getAppid ()));
436+ $ this ->setAppInitProgress ($ exApp , 0 , 'Failed to enable ExApp before init ' );
437+ return ;
438+ }
415439 try {
416440 $ this ->client ->post ($ initUrl , $ options );
417441 } catch (\Exception $ e ) {
0 commit comments