Skip to content

Commit

Permalink
wopi: introduced a usertype parameter on the open call
Browse files Browse the repository at this point in the history
  • Loading branch information
glpatcern committed Mar 5, 2023
1 parent 456aac4 commit f53089d
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions pkg/app/provider/wopi/wopi.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,16 @@ const publicLinkURLPrefix = "/files/link/public/"

const ocmLinkURLPrefix = "/files/spaces/sciencemesh/"

type userType string

const (
invalid userType = "invalid"
regular userType = "regular"
federated userType = "federated"
ocm userType = "ocm"
anonymous userType = "anonymous"
)

func init() {
registry.Register("wopi", New)
}
Expand Down Expand Up @@ -150,13 +160,15 @@ func (p *wopiProvider) GetAppURL(ctx context.Context, resource *provider.Resourc
q.Add("viewmode", viewMode.String())
q.Add("appname", p.conf.AppName)

var ut userType = invalid
u, ok := ctxpkg.ContextGetUser(ctx)
if !ok {
// we must have been authenticated
return nil, errors.New("wopi: ContextGetUser failed")
}
if u.Id.Type == userpb.UserType_USER_TYPE_LIGHTWEIGHT || u.Id.Type == userpb.UserType_USER_TYPE_FEDERATED {
q.Add("userid", resource.Owner.OpaqueId+"@"+resource.Owner.Idp)
ut = federated
} else {
q.Add("userid", u.Id.OpaqueId+"@"+u.Id.Idp)
}
Expand All @@ -176,12 +188,14 @@ func (p *wopiProvider) GetAppURL(ctx context.Context, resource *provider.Resourc
switch {
case ok:
// we are in a public link, username is not set so it will default to "Guest xyz"
ut = anonymous
rPath, pathErr = getPathForExternalLink(ctx, scopes, resource, publicLinkURLPrefix)
if pathErr != nil {
log.Warn().Err(pathErr).Msg("wopi: failed to extract relative path from public link scope")
}
case u.Username == "":
// OCM users have no username: use displayname@Idp
ut = ocm
idpURL, e := url.Parse(u.Id.Idp)
if e != nil {
q.Add("username", u.DisplayName+" @ "+u.Id.Idp)
Expand All @@ -193,8 +207,12 @@ func (p *wopiProvider) GetAppURL(ctx context.Context, resource *provider.Resourc
if pathErr != nil {
log.Warn().Err(pathErr).Msg("wopi: failed to extract relative path from ocm link scope")
}
q.Add("usertype", "ocm")
default:
// in all other cases use the resource's path
if ut == invalid {
ut = regular
}
rPath = "/files/spaces/" + path.Dir(resource.Path)
q.Add("username", u.DisplayName)
}
Expand All @@ -206,6 +224,7 @@ func (p *wopiProvider) GetAppURL(ctx context.Context, resource *provider.Resourc
q.Add("folderurl", fu)
}
}
q.Add("usertype", string(ut))

var viewAppURL string
if viewAppURLs, ok := p.appURLs["view"]; ok {
Expand Down

0 comments on commit f53089d

Please sign in to comment.