Skip to content

Commit

Permalink
add language option for app provider (#3156)
Browse files Browse the repository at this point in the history
* add language option for app provider

* add changelog

* use opaque utils
  • Loading branch information
wkloucek authored Aug 17, 2022
1 parent 18c9e46 commit b0f72d7
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Enhancement: Added language option to the app provider

We've added an language option to the app provider which will in the
end be passed to the app a user opens so that the web ui is displayed in the users language.

https://github.com/cs3org/reva/pull/3156
https://github.com/owncloud/ocis/issues/4367
https://github.com/owncloud/ocis/pull/4399
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ require (
github.com/cs3org/go-cs3apis v0.0.0-20220719130120-361e9f987d64
github.com/cubewise-code/go-mime v0.0.0-20200519001935-8c5762b177d8
github.com/dgraph-io/ristretto v0.1.0
github.com/emvi/iso-639-1 v1.0.1
github.com/eventials/go-tus v0.0.0-20220610120217-05d0564bb571
github.com/gdexlab/go-render v1.0.1
github.com/go-chi/chi v4.1.2+incompatible
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,8 @@ github.com/dustin/go-humanize v1.0.0 h1:VSnTsYCnlFHaM2/igO1h6X3HA71jcobQuxemgkq4
github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
github.com/emirpasic/gods v1.12.0 h1:QAUIPSaCu4G+POclxeqb3F+WPpdKqFGlw36+yOzGlrg=
github.com/emirpasic/gods v1.12.0/go.mod h1:YfzfFFoVP/catgzJb4IKIqXjX78Ha8FMSDh3ymbK86o=
github.com/emvi/iso-639-1 v1.0.1 h1:4s6P8Uxc/RDkwCpxAr4NHOT/15a1swy9IQkB8PJCWVI=
github.com/emvi/iso-639-1 v1.0.1/go.mod h1:mghC4MDFyszxzH98ujf/K5whvB6B0nV4qCa5u94dP84=
github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98=
Expand Down
3 changes: 2 additions & 1 deletion internal/grpc/services/appprovider/appprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import (
"github.com/cs3org/reva/v2/pkg/rgrpc/status"
"github.com/cs3org/reva/v2/pkg/rgrpc/todo/pool"
"github.com/cs3org/reva/v2/pkg/sharedconf"
"github.com/cs3org/reva/v2/pkg/utils"
"github.com/juliangruber/go-intersect"
"github.com/mitchellh/mapstructure"
"google.golang.org/grpc"
Expand Down Expand Up @@ -169,7 +170,7 @@ func getProvider(c *config) (app.Provider, error) {
}

func (s *service) OpenInApp(ctx context.Context, req *providerpb.OpenInAppRequest) (*providerpb.OpenInAppResponse, error) {
appURL, err := s.provider.GetAppURL(ctx, req.ResourceInfo, req.ViewMode, req.AccessToken)
appURL, err := s.provider.GetAppURL(ctx, req.ResourceInfo, req.ViewMode, req.AccessToken, utils.ReadPlainFromOpaque(req.Opaque, "lang"))
if err != nil {
res := &providerpb.OpenInAppResponse{
Status: status.NewInternal(ctx, err.Error()),
Expand Down
5 changes: 3 additions & 2 deletions internal/grpc/services/gateway/appprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func (s *svc) OpenInApp(ctx context.Context, req *gateway.OpenInAppRequest) (*pr
}
fileInfo = res.Info
}
return s.openLocalResources(ctx, fileInfo, req.ViewMode, req.App)
return s.openLocalResources(ctx, fileInfo, req.ViewMode, req.App, req.Opaque)
}

func (s *svc) openFederatedShares(ctx context.Context, targetURL string, vm gateway.OpenInAppRequest_ViewMode, app string,
Expand Down Expand Up @@ -144,7 +144,7 @@ func (s *svc) openFederatedShares(ctx context.Context, targetURL string, vm gate
}

func (s *svc) openLocalResources(ctx context.Context, ri *storageprovider.ResourceInfo,
vm gateway.OpenInAppRequest_ViewMode, app string) (*providerpb.OpenInAppResponse, error) {
vm gateway.OpenInAppRequest_ViewMode, app string, opaque *typespb.Opaque) (*providerpb.OpenInAppResponse, error) {

accessToken, ok := ctxpkg.ContextGetToken(ctx)
if !ok || accessToken == "" {
Expand Down Expand Up @@ -173,6 +173,7 @@ func (s *svc) openLocalResources(ctx context.Context, ri *storageprovider.Resour
ResourceInfo: ri,
ViewMode: providerpb.OpenInAppRequest_ViewMode(vm),
AccessToken: accessToken,
Opaque: opaque,
}

res, err := appProviderClient.OpenInApp(ctx, appProviderReq)
Expand Down
8 changes: 8 additions & 0 deletions internal/http/services/appprovider/appprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import (
"github.com/cs3org/reva/v2/pkg/sharedconf"
"github.com/cs3org/reva/v2/pkg/storagespace"
"github.com/cs3org/reva/v2/pkg/utils"
iso6391 "github.com/emvi/iso-639-1"
"github.com/go-chi/chi"
ua "github.com/mileusna/useragent"
"github.com/mitchellh/mapstructure"
Expand Down Expand Up @@ -355,6 +356,12 @@ func (s *svc) handleOpen(openMode int) http.HandlerFunc {
writeError(w, r, appErrorInvalidParameter, "parameters could not be parsed", nil)
}

lang := r.Form.Get("lang")
if lang != "" && !iso6391.ValidCode(lang) {
writeError(w, r, appErrorInvalidParameter, "lang parameter does not contain a valid ISO 639-1 language code", nil)
return
}

fileID := r.Form.Get("file_id")

if fileID == "" {
Expand Down Expand Up @@ -402,6 +409,7 @@ func (s *svc) handleOpen(openMode int) http.HandlerFunc {
Ref: fileRef,
ViewMode: viewMode,
App: r.Form.Get("app_name"),
Opaque: utils.AppendPlainToOpaque(nil, "lang", lang),
}
openRes, err := client.OpenInApp(ctx, &openReq)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion pkg/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,6 @@ type Registry interface {
// Provider is the interface that application providers implement
// for interacting with external apps that serve the requested resource.
type Provider interface {
GetAppURL(ctx context.Context, resource *provider.ResourceInfo, viewMode appprovider.OpenInAppRequest_ViewMode, token string) (*appprovider.OpenInAppURL, error)
GetAppURL(ctx context.Context, resource *provider.ResourceInfo, viewMode appprovider.OpenInAppRequest_ViewMode, token, language string) (*appprovider.OpenInAppURL, error)
GetAppProviderInfo(ctx context.Context) (*registry.ProviderInfo, error)
}
2 changes: 1 addition & 1 deletion pkg/app/provider/demo/demo.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ type demoProvider struct {
iframeUIProvider string
}

func (p *demoProvider) GetAppURL(ctx context.Context, resource *provider.ResourceInfo, viewMode appprovider.OpenInAppRequest_ViewMode, token string) (*appprovider.OpenInAppURL, error) {
func (p *demoProvider) GetAppURL(ctx context.Context, resource *provider.ResourceInfo, viewMode appprovider.OpenInAppRequest_ViewMode, token, language string) (*appprovider.OpenInAppURL, error) {
url := fmt.Sprintf("<iframe src=%s/open/%s?view-mode=%s&access-token=%s />", p.iframeUIProvider, storagespace.FormatResourceID(*resource.Id), viewMode.String(), token)
return &appprovider.OpenInAppURL{
AppUrl: url,
Expand Down
16 changes: 15 additions & 1 deletion pkg/app/provider/wopi/wopi.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ func New(m map[string]interface{}) (app.Provider, error) {
}, nil
}

func (p *wopiProvider) GetAppURL(ctx context.Context, resource *provider.ResourceInfo, viewMode appprovider.OpenInAppRequest_ViewMode, token string) (*appprovider.OpenInAppURL, error) {
func (p *wopiProvider) GetAppURL(ctx context.Context, resource *provider.ResourceInfo, viewMode appprovider.OpenInAppRequest_ViewMode, token, language string) (*appprovider.OpenInAppURL, error) {
log := appctx.GetLogger(ctx)

ext := path.Ext(resource.Path)
Expand Down Expand Up @@ -236,6 +236,20 @@ func (p *wopiProvider) GetAppURL(ctx context.Context, resource *provider.Resourc

appFullURL := result["app-url"].(string)

if language != "" {
url, err := url.Parse(appFullURL)
if err != nil {
return nil, err
}
urlQuery := url.Query()
// we could improve this by using the UI_LLCC value from the wopi discovery url
// https://docs.microsoft.com/en-us/microsoft-365/cloud-storage-partner-program/online/discovery#ui_llcc
urlQuery.Set("ui", language) // OnlyOffice
urlQuery.Set("lang", language) // Collabora
url.RawQuery = urlQuery.Encode()
appFullURL = url.String()
}

// Depending on whether wopi server returned any form parameters or not,
// we decide whether the request method is POST or GET
var formParams map[string]string
Expand Down

0 comments on commit b0f72d7

Please sign in to comment.