Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,10 @@ go.work.sum
.DS_Store

# example deployments
**/opencloud-sandbox-*
**/opencloud-sandbox-*

# web apps
!./services/web/assets/
!./services/web/assets/apps/
!./services/web/assets/apps/collaboration-settings
!./services/web/assets/apps/collaboration-settings/**
39 changes: 39 additions & 0 deletions services/collaboration/pkg/collaboration/collaboration.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package collaboration

import (
"context"
"fmt"

gateway "github.com/cs3org/go-cs3apis/cs3/gateway/v1beta1"
userpb "github.com/cs3org/go-cs3apis/cs3/identity/user/v1beta1"
permissionsapi "github.com/cs3org/go-cs3apis/cs3/permissions/v1beta1"
rpc "github.com/cs3org/go-cs3apis/cs3/rpc/v1beta1"
revactx "github.com/opencloud-eu/reva/v2/pkg/ctx"
)

type Permission string

const (
PermissionCollaborationManageFonts Permission = "Collaboration.Fonts.Manage"
)

func CheckPermissions(gatewayClient gateway.GatewayAPIClient, ctx context.Context, permission Permission) (*userpb.User, bool, error) {
user, ok := revactx.ContextGetUser(ctx)
if !ok {
return nil, false, fmt.Errorf("could not get user from context")
}

rsp, err := gatewayClient.CheckPermission(ctx, &permissionsapi.CheckPermissionRequest{
Permission: string(permission),
SubjectRef: &permissionsapi.SubjectReference{
Spec: &permissionsapi.SubjectReference_UserId{
UserId: user.GetId(),
},
},
})
if err != nil {
return user, false, fmt.Errorf("could not check permissions: %w", err)
}

return user, rsp.GetStatus().GetCode() == rpc.Code_CODE_OK, nil
}
47 changes: 41 additions & 6 deletions services/collaboration/pkg/command/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,32 @@ import (
"context"
"fmt"
"net"
"net/url"
"os/signal"
"time"

"github.com/opencloud-eu/reva/v2/pkg/rgrpc/todo/pool"
"github.com/opencloud-eu/reva/v2/pkg/store"
"github.com/spf13/afero"

"github.com/spf13/cobra"
"go-micro.dev/v4/selector"
microstore "go-micro.dev/v4/store"

"github.com/opencloud-eu/opencloud/pkg/config/configlog"
"github.com/opencloud-eu/opencloud/pkg/log"
"github.com/opencloud-eu/opencloud/pkg/registry"
"github.com/opencloud-eu/opencloud/pkg/runner"
"github.com/opencloud-eu/opencloud/pkg/tracing"
"github.com/opencloud-eu/opencloud/pkg/x/io/fsx"
"github.com/opencloud-eu/opencloud/services/collaboration/pkg/config"
"github.com/opencloud-eu/opencloud/services/collaboration/pkg/config/parser"
"github.com/opencloud-eu/opencloud/services/collaboration/pkg/connector"
"github.com/opencloud-eu/opencloud/services/collaboration/pkg/font"
"github.com/opencloud-eu/opencloud/services/collaboration/pkg/helpers"
"github.com/opencloud-eu/opencloud/services/collaboration/pkg/server/debug"
"github.com/opencloud-eu/opencloud/services/collaboration/pkg/server/grpc"
"github.com/opencloud-eu/opencloud/services/collaboration/pkg/server/http"
"github.com/opencloud-eu/reva/v2/pkg/rgrpc/todo/pool"
"github.com/opencloud-eu/reva/v2/pkg/store"

"github.com/spf13/cobra"
"go-micro.dev/v4/selector"
microstore "go-micro.dev/v4/store"
)

// Server is the entrypoint for the server command.
Expand Down Expand Up @@ -137,6 +142,35 @@ func Server(cfg *config.Config) *cobra.Command {
}
gr.Add(runner.NewGolangHttpServerRunner(cfg.Service.Name+".debug", debugServer))

var fontService font.Service
{
fontFS := afero.NewBasePathFs(fsx.NewOsFs(), cfg.Font.AssetPath)
if err := fontFS.MkdirAll("/", 0o755); err != nil {
logger.Error().Err(err).Msg("Failed to initialize the fonts directory")
return err
}

fontServiceRootURI, err := url.JoinPath(cfg.Commons.OpenCloudURL, "/collaboration/fonts")
if err := fontFS.MkdirAll("/", 0o755); err != nil {
logger.Error().Err(err).Msg("Failed to build font service root uri")
return err
}

service, err := font.NewService(
font.ServiceOptions{}.
WithFontFS(fontFS).
WithRootURI(fontServiceRootURI).
WithGatewaySelector(gatewaySelector).
WithLogger(logger).
WithPreviewText(cfg.Font.PreviewText),
)
if err != nil {
return err
}

fontService = service
}

// start HTTP server
httpServer, err := http.Server(
http.Adapter(connector.NewHttpAdapter(gatewaySelector, cfg, st, selector.NewSelector(selector.Registry(registry.GetRegistry())))),
Expand All @@ -145,6 +179,7 @@ func Server(cfg *config.Config) *cobra.Command {
http.Context(ctx),
http.TracerProvider(traceProvider),
http.Store(st),
http.FontService(fontService),
)
if err != nil {
logger.Info().Err(err).Str("transport", "http").Msg("Failed to initialize server")
Expand Down
1 change: 1 addition & 0 deletions services/collaboration/pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ type Config struct {

Service Service `yaml:"-"`
App App `yaml:"app"`
Font Font `yaml:"font"`
Store Store `yaml:"store"`

TokenManager *TokenManager `yaml:"token_manager"`
Expand Down
6 changes: 6 additions & 0 deletions services/collaboration/pkg/config/defaults/defaultconfig.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package defaults

import (
"path/filepath"
"time"

"github.com/opencloud-eu/opencloud/pkg/config/defaults"
"github.com/opencloud-eu/opencloud/pkg/shared"
"github.com/opencloud-eu/opencloud/pkg/structs"
"github.com/opencloud-eu/opencloud/services/collaboration/pkg/config"
Expand Down Expand Up @@ -33,6 +35,10 @@ func DefaultConfig() *config.Config {
Duration: "12h",
},
},
Font: config.Font{
AssetPath: filepath.Join(defaults.BaseDataPath(), "collaboration/fonts"),
PreviewText: "OpenCloud",
},
Store: config.Store{
Store: "nats-js-kv",
Nodes: []string{"127.0.0.1:9233"},
Expand Down
6 changes: 6 additions & 0 deletions services/collaboration/pkg/config/font.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package config

type Font struct {
AssetPath string `yaml:"asset_path" env:"COLLABORATION_FONT_ASSET_PATH" desc:"Serve fonts from a path on the filesystem instead of the builtin assets. If not defined, the root directory derives from $OC_BASE_DATA_PATH/web/assets/fonts" introductionVersion:"%%NEXT%%"`
PreviewText string `yaml:"preview_text" env:"COLLABORATION_ASSET_APPS_PATH" desc:"The text that will be displayed in the font preview." introductionVersion:"%%NEXT%%"`
}
Loading