77
88namespace OCA \Tables \Controller ;
99
10+ use InvalidArgumentException ;
1011use OCA \Tables \AppInfo \Application ;
12+ use OCA \Tables \Errors \NotFoundError ;
13+ use OCA \Tables \Service \ShareService ;
1114use OCA \Tables \Service \ValueObject \ShareToken ;
1215use OCA \Text \Event \LoadEditor ;
1316use OCA \Viewer \Event \LoadViewer ;
2023use OCP \AppFramework \Http \TemplateResponse ;
2124use OCP \AppFramework \Services \IInitialState ;
2225use OCP \EventDispatcher \IEventDispatcher ;
26+ use OCP \IL10N ;
2327use OCP \INavigationManager ;
2428use OCP \IRequest ;
2529use OCP \Util ;
@@ -31,6 +35,8 @@ public function __construct(
3135 protected IEventDispatcher $ eventDispatcher ,
3236 protected INavigationManager $ navigationManager ,
3337 protected IInitialState $ initialState ,
38+ protected ShareService $ shareService ,
39+ protected IL10N $ l ,
3440 ) {
3541 parent ::__construct (Application::APP_ID , $ request );
3642 }
@@ -78,13 +84,30 @@ public function context(int $contextId): TemplateResponse {
7884 #[OpenAPI(scope: OpenAPI::SCOPE_IGNORE )]
7985 #[FrontpageRoute(verb: 'GET ' , url: '/s/{token} ' )]
8086 public function linkShare (string $ token ): TemplateResponse {
87+ try {
88+ $ shareToken = new ShareToken ($ token );
89+ $ this ->shareService ->findByToken ($ shareToken );
90+ } catch (InvalidArgumentException |NotFoundError $ e ) {
91+
92+ return new TemplateResponse (
93+ Application::APP_ID ,
94+ 'error ' ,
95+ ['message ' => $ this ->l ->t ('This share does not exist or is no longer available ' )],
96+ TemplateResponse::RENDER_AS_PUBLIC
97+ );
98+ }
99+
81100 Util::addScript (Application::APP_ID , 'tables-main ' );
82101 $ this ->loadStyles ();
83102
84- $ shareToken = new ShareToken ($ token );
85103 $ this ->initialState ->provideInitialState ('shareToken ' , (string )$ shareToken );
86104
87- return new TemplateResponse (Application::APP_ID , 'main ' , [], TemplateResponse::RENDER_AS_GUEST );
105+
106+ if (class_exists (LoadEditor::class)) {
107+ $ this ->eventDispatcher ->dispatchTyped (new LoadEditor ());
108+ }
109+
110+ return new TemplateResponse (Application::APP_ID , 'main ' , [], TemplateResponse::RENDER_AS_PUBLIC );
88111 }
89112
90113 protected function loadStyles (): void {
0 commit comments