diff --git a/changelog/unreleased/enhancement-app-provider-language-selection.md b/changelog/unreleased/enhancement-app-provider-language-selection.md new file mode 100644 index 0000000000..82ba2ed631 --- /dev/null +++ b/changelog/unreleased/enhancement-app-provider-language-selection.md @@ -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 diff --git a/go.mod b/go.mod index a0dfde8290..8d6638dabd 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/go.sum b/go.sum index 679c376970..4e5a200695 100644 --- a/go.sum +++ b/go.sum @@ -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= diff --git a/internal/grpc/services/appprovider/appprovider.go b/internal/grpc/services/appprovider/appprovider.go index aa5d0a1df4..e745f368b7 100644 --- a/internal/grpc/services/appprovider/appprovider.go +++ b/internal/grpc/services/appprovider/appprovider.go @@ -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" @@ -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()), diff --git a/internal/grpc/services/gateway/appprovider.go b/internal/grpc/services/gateway/appprovider.go index 4ed90aba98..e53a3c6fc1 100644 --- a/internal/grpc/services/gateway/appprovider.go +++ b/internal/grpc/services/gateway/appprovider.go @@ -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, @@ -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 == "" { @@ -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) diff --git a/internal/http/services/appprovider/appprovider.go b/internal/http/services/appprovider/appprovider.go index a428b7382f..5ffa2f91bd 100644 --- a/internal/http/services/appprovider/appprovider.go +++ b/internal/http/services/appprovider/appprovider.go @@ -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" @@ -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 == "" { @@ -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 { diff --git a/pkg/app/app.go b/pkg/app/app.go index a6edad2a02..50e6ce28d8 100644 --- a/pkg/app/app.go +++ b/pkg/app/app.go @@ -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) } diff --git a/pkg/app/provider/demo/demo.go b/pkg/app/provider/demo/demo.go index a2552364d2..0b00fa419a 100644 --- a/pkg/app/provider/demo/demo.go +++ b/pkg/app/provider/demo/demo.go @@ -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("