@@ -125,7 +125,7 @@ func New(m map[string]interface{}) (app.Provider, error) {
125
125
}
126
126
127
127
wopiClient := rhttp .GetHTTPClient (
128
- rhttp .Timeout (time .Duration (5 * int64 (time .Second ))),
128
+ rhttp .Timeout (time .Duration (10 * int64 (time .Second ))),
129
129
rhttp .Insecure (c .InsecureConnections ),
130
130
)
131
131
wopiClient .CheckRedirect = func (req * http.Request , via []* http.Request ) error {
@@ -184,30 +184,25 @@ func (p *wopiProvider) GetAppURL(ctx context.Context, resource *provider.Resourc
184
184
// either append `/files/spaces/<full_path>` or the proper URL prefix + `/<relative_path>`
185
185
var rPath string
186
186
var pathErr error
187
- _ , ok = utils .HasPublicShareRole (u )
187
+ _ , pubrole := utils .HasPublicShareRole (u )
188
+ _ , ocmrole := utils .HasOCMShareRole (u )
188
189
switch {
189
- case ok :
190
+ case pubrole :
190
191
// we are in a public link, username is not set so it will default to "Guest xyz"
191
192
ut = anonymous
192
193
rPath , pathErr = getPathForExternalLink (ctx , scopes , resource , publicLinkURLPrefix )
193
194
if pathErr != nil {
194
195
log .Warn ().Err (pathErr ).Msg ("wopi: failed to extract relative path from public link scope" )
195
196
}
196
- case u . Username == "" :
197
+ case ocmrole :
197
198
// OCM users have no username: use displayname@Idp
198
199
ut = ocm
199
- idpURL , e := url .Parse (u .Id .Idp )
200
- if e != nil {
201
- q .Add ("username" , u .DisplayName + " @ " + u .Id .Idp )
202
- } else {
203
- q .Add ("username" , u .DisplayName + " @ " + idpURL .Hostname ())
204
- }
200
+ q .Add ("username" , u .DisplayName + " @ " + u .Id .Idp )
205
201
// and resolve the folder
206
202
rPath , pathErr = getPathForExternalLink (ctx , scopes , resource , ocmLinkURLPrefix )
207
203
if pathErr != nil {
208
204
log .Warn ().Err (pathErr ).Msg ("wopi: failed to extract relative path from ocm link scope" )
209
205
}
210
- q .Add ("usertype" , "ocm" )
211
206
default :
212
207
// in all other cases use the resource's path
213
208
if ut == invalid {
@@ -508,12 +503,25 @@ func parseWopiDiscovery(body io.Reader) (map[string]map[string]string, error) {
508
503
}
509
504
510
505
func getPathForExternalLink (ctx context.Context , scopes map [string ]* authpb.Scope , resource * provider.ResourceInfo , pathPrefix string ) (string , error ) {
511
- shares , err := scope .GetPublicOcmSharesFromScopes (scopes )
506
+ pubshares , err := scope .GetPublicSharesFromScopes (scopes )
507
+ if err != nil {
508
+ return "" , err
509
+ }
510
+ ocmshares , err := scope .GetOCMSharesFromScopes (scopes )
512
511
if err != nil {
513
512
return "" , err
514
513
}
515
- if len (shares ) > 1 {
516
- return "" , errors .New ("More than one public or OCM share found in the scope, lookup not implemented" )
514
+ var resId * provider.ResourceId
515
+ var token string
516
+ switch {
517
+ case len (pubshares ) == 1 :
518
+ resId = pubshares [0 ].ResourceId
519
+ token = pubshares [0 ].Token
520
+ case len (ocmshares ) == 1 :
521
+ resId = ocmshares [0 ].ResourceId
522
+ token = ocmshares [0 ].Token
523
+ default :
524
+ return "" , errors .New ("Either one public xor OCM share is supported, lookups not implemented" )
517
525
}
518
526
519
527
client , err := pool .GetGatewayServiceClient (pool .Endpoint (sharedconf .GetGatewaySVC ("" )))
@@ -522,7 +530,7 @@ func getPathForExternalLink(ctx context.Context, scopes map[string]*authpb.Scope
522
530
}
523
531
statRes , err := client .Stat (ctx , & provider.StatRequest {
524
532
Ref : & provider.Reference {
525
- ResourceId : shares [ 0 ]. ResourceId ,
533
+ ResourceId : resId ,
526
534
},
527
535
})
528
536
if err != nil {
@@ -531,7 +539,7 @@ func getPathForExternalLink(ctx context.Context, scopes map[string]*authpb.Scope
531
539
532
540
if statRes .Info .Path == resource .Path {
533
541
// this is a direct link to the resource
534
- return pathPrefix + shares [ 0 ]. Token , nil
542
+ return pathPrefix + token , nil
535
543
}
536
544
// otherwise we are in a subfolder of the public link
537
545
relPath , err := filepath .Rel (statRes .Info .Path , resource .Path )
@@ -541,5 +549,5 @@ func getPathForExternalLink(ctx context.Context, scopes map[string]*authpb.Scope
541
549
if strings .HasPrefix (relPath , "../" ) {
542
550
return "" , errors .New ("Scope path does not contain target resource" )
543
551
}
544
- return path .Join (pathPrefix + shares [ 0 ]. Token , path .Dir (relPath )), nil
552
+ return path .Join (pathPrefix + token , path .Dir (relPath )), nil
545
553
}
0 commit comments