23
23
24
24
namespace OCA \Richdocuments \DirectEditing ;
25
25
26
+ use OCA \Richdocuments \AppConfig ;
26
27
use OCA \Richdocuments \AppInfo \Application ;
27
28
use OCA \Richdocuments \Capabilities ;
29
+ use OCA \Richdocuments \Controller \DocumentTrait ;
30
+ use OCA \Richdocuments \Service \InitialStateService ;
31
+ use OCA \Richdocuments \TokenManager ;
28
32
use OCP \AppFramework \Http \NotFoundResponse ;
29
33
use OCP \AppFramework \Http \Response ;
30
34
use OCP \AppFramework \Http \TemplateResponse ;
31
35
use OCP \DirectEditing \IEditor ;
32
36
use OCP \DirectEditing \IToken ;
33
37
use OCP \Files \InvalidPathException ;
38
+ use OCP \Files \IRootFolder ;
34
39
use OCP \Files \NotFoundException ;
35
40
use OCP \Files \NotPermittedException ;
41
+ use OCP \IConfig ;
36
42
use OCP \IInitialStateService ;
37
43
use OCP \IL10N ;
44
+ use Psr \Log \LoggerInterface ;
38
45
39
46
class DirectEditor implements IEditor {
47
+ use DocumentTrait;
40
48
41
49
/** @var IL10N */
42
50
private $ l10n ;
@@ -47,11 +55,40 @@ class DirectEditor implements IEditor {
47
55
/** @var string[] */
48
56
private $ mimetypes ;
49
57
58
+ /** @var TokenManager */
59
+ private $ tokenManager ;
50
60
51
- public function __construct (IL10N $ l10n , IInitialStateService $ initialStateService , Capabilities $ capabilities ) {
61
+ /** @var IRootFolder */
62
+ private $ rootFolder ;
63
+
64
+ /** @var IConfig */
65
+ private $ config ;
66
+
67
+ /** @var AppConfig */
68
+ private $ appConfig ;
69
+
70
+ /** @var LoggerInterface */
71
+ private $ logger ;
72
+
73
+
74
+ public function __construct (
75
+ IL10N $ l10n ,
76
+ InitialStateService $ initialStateService ,
77
+ Capabilities $ capabilities ,
78
+ TokenManager $ tokenManager ,
79
+ IConfig $ config ,
80
+ AppConfig $ appConfig ,
81
+ IRootFolder $ rootFolder ,
82
+ LoggerInterface $ logger
83
+ ) {
52
84
$ this ->l10n = $ l10n ;
53
85
$ this ->initialStateService = $ initialStateService ;
54
86
$ this ->mimetypes = $ capabilities ->getCapabilities ()[Application::APPNAME ]['mimetypes ' ];
87
+ $ this ->tokenManager = $ tokenManager ;
88
+ $ this ->config = $ config ;
89
+ $ this ->appConfig = $ appConfig ;
90
+ $ this ->rootFolder = $ rootFolder ;
91
+ $ this ->logger = $ logger ;
55
92
}
56
93
57
94
/**
@@ -131,18 +168,30 @@ public function isSecure(): bool {
131
168
public function open (IToken $ token ): Response {
132
169
$ token ->useTokenScope ();
133
170
try {
134
- $ session = $ this ->apiService ->create ($ token ->getFile ()->getId ());
135
- $ this ->initialStateService ->provideInitialState ('text ' , 'file ' , [
136
- 'fileId ' => $ token ->getFile ()->getId (),
137
- 'mimetype ' => $ token ->getFile ()->getMimeType (),
138
- 'content ' => $ token ->getFile ()->getContent (),
139
- 'session ' => \json_encode ($ session ->getData ())
140
- ]);
141
- $ this ->initialStateService ->provideInitialState ('text ' , 'directEditingToken ' , $ token ->getToken ());
142
- return new TemplateResponse (Application::APPNAME , 'main ' , [], 'base ' );
143
- } catch (InvalidPathException $ e ) {
144
- } catch (NotFoundException $ e ) {
145
- } catch (NotPermittedException $ e ) {
171
+ $ folder = $ this ->rootFolder ->getUserFolder ($ token ->getUser ());
172
+ $ item = $ token ->getFile ();
173
+
174
+ [$ urlSrc , $ token , $ wopi ] = $ this ->tokenManager ->getToken ($ item ->getId (), null , $ token ->getUser (), true );
175
+
176
+ $ params = [
177
+ 'permissions ' => $ item ->getPermissions (),
178
+ 'title ' => $ item ->getName (),
179
+ 'fileId ' => $ wopi ->getFileid () . '_ ' . $ this ->config ->getSystemValue ('instanceid ' ),
180
+ 'token ' => $ wopi ->getToken (),
181
+ 'token_ttl ' => $ wopi ->getExpiry (),
182
+ 'urlsrc ' => $ urlSrc ,
183
+ 'path ' => $ folder ->getRelativePath ($ item ->getPath ()),
184
+ 'instanceId ' => $ this ->config ->getSystemValue ('instanceid ' ),
185
+ 'canonical_webroot ' => $ this ->appConfig ->getAppValue ('canonical_webroot ' ),
186
+ 'direct ' => true ,
187
+ ];
188
+
189
+ $ this ->initialStateService ->provideDocument ($ wopi );
190
+ $ response = new TemplateResponse ('richdocuments ' , 'documents ' , $ params , 'base ' );
191
+ $ this ->applyPolicies ($ response );
192
+ return $ response ;
193
+ } catch (InvalidPathException |NotFoundException |NotPermittedException $ e ) {
194
+ $ this ->logger ->error ($ e ->getMessage ());
146
195
}
147
196
return new NotFoundResponse ();
148
197
}
0 commit comments