Skip to content

Commit

Permalink
enhancement: add theme capability
Browse files Browse the repository at this point in the history
  • Loading branch information
fschade committed May 28, 2024
1 parent 5687911 commit 0a0508f
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 45 deletions.
6 changes: 6 additions & 0 deletions changelog/unreleased/add-theme-capability.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Enhancement: Added theme capability

The ocs capabilities now contain a theme capability that exposes theme related configuration options to the clients.
As part of this change, the ocs capabilities are now exposed and can be used externally.

https://github.com/cs3org/reva/pull/4702
4 changes: 2 additions & 2 deletions internal/http/services/owncloud/ocdav/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ import (
"encoding/json"
"net/http"

"github.com/cs3org/reva/v2/internal/http/services/owncloud/ocs/data"
"github.com/cs3org/reva/v2/pkg/appctx"
"github.com/cs3org/reva/v2/pkg/owncloud/ocs"
)

func (s *svc) doStatus(w http.ResponseWriter, r *http.Request) {
log := appctx.GetLogger(r.Context())
status := &data.Status{
status := &ocs.Status{
Installed: true,
Maintenance: false,
NeedsDBUpgrade: false,
Expand Down
3 changes: 2 additions & 1 deletion internal/http/services/owncloud/ocs/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ package config

import (
"github.com/cs3org/reva/v2/internal/http/services/owncloud/ocs/data"
"github.com/cs3org/reva/v2/pkg/owncloud/ocs"
"github.com/cs3org/reva/v2/pkg/sharedconf"
"github.com/cs3org/reva/v2/pkg/storage/cache"
)
Expand All @@ -28,7 +29,7 @@ import (
type Config struct {
Prefix string `mapstructure:"prefix"`
Config data.ConfigData `mapstructure:"config"`
Capabilities data.CapabilitiesData `mapstructure:"capabilities"`
Capabilities ocs.CapabilitiesData `mapstructure:"capabilities"`
GatewaySvc string `mapstructure:"gatewaysvc"`
StorageregistrySvc string `mapstructure:"storage_registry_svc"`
DefaultUploadProtocol string `mapstructure:"default_upload_protocol"`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,17 @@ import (
collaboration "github.com/cs3org/go-cs3apis/cs3/sharing/collaboration/v1beta1"
link "github.com/cs3org/go-cs3apis/cs3/sharing/link/v1beta1"
provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1"
"github.com/go-chi/chi/v5"
"github.com/stretchr/testify/mock"

"github.com/cs3org/reva/v2/internal/http/services/owncloud/ocs/config"
cdata "github.com/cs3org/reva/v2/internal/http/services/owncloud/ocs/data"
"github.com/cs3org/reva/v2/internal/http/services/owncloud/ocs/handlers/apps/sharing/shares"
ctxpkg "github.com/cs3org/reva/v2/pkg/ctx"
"github.com/cs3org/reva/v2/pkg/owncloud/ocs"
"github.com/cs3org/reva/v2/pkg/rgrpc/status"
"github.com/cs3org/reva/v2/pkg/rgrpc/todo/pool"
helpers "github.com/cs3org/reva/v2/pkg/storage/utils/decomposedfs/testhelpers"
cs3mocks "github.com/cs3org/reva/v2/tests/cs3mocks/mocks"
"github.com/go-chi/chi/v5"
"github.com/stretchr/testify/mock"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
Expand Down Expand Up @@ -489,11 +490,11 @@ var _ = Describe("The ocs API", func() {
c := &config.Config{}
c.GatewaySvc = "gatewaysvc"
c.StatCacheConfig.Database = strconv.FormatInt(rand.Int63(), 10) // Use a fresh database for each test
// this is equivalent of the ocis OCIS_SHARING_PUBLIC_WRITEABLE_SHARE_MUST_HAVE_PASSWORD=true
c.Capabilities = cdata.CapabilitiesData{
Capabilities: &cdata.Capabilities{FilesSharing: &cdata.CapabilitiesFilesSharing{Public: &cdata.CapabilitiesFilesSharingPublic{
Password: &cdata.CapabilitiesFilesSharingPublicPassword{
EnforcedFor: &cdata.CapabilitiesFilesSharingPublicPasswordEnforcedFor{
// this is the equivalent of the ocis OCIS_SHARING_PUBLIC_WRITEABLE_SHARE_MUST_HAVE_PASSWORD=true
c.Capabilities = ocs.CapabilitiesData{
Capabilities: &ocs.Capabilities{FilesSharing: &ocs.CapabilitiesFilesSharing{Public: &ocs.CapabilitiesFilesSharingPublic{
Password: &ocs.CapabilitiesFilesSharingPublicPassword{
EnforcedFor: &ocs.CapabilitiesFilesSharingPublicPasswordEnforcedFor{
ReadOnly: false,
ReadWrite: true,
ReadWriteDelete: true,
Expand Down Expand Up @@ -630,11 +631,11 @@ var _ = Describe("The ocs API", func() {
c := &config.Config{}
c.GatewaySvc = "gatewaysvc"
c.StatCacheConfig.Database = strconv.FormatInt(rand.Int63(), 10) // Use a fresh database for each test
// this is equivalent of the ocis OCIS_SHARING_PUBLIC_WRITEABLE_SHARE_MUST_HAVE_PASSWORD=true
c.Capabilities = cdata.CapabilitiesData{
Capabilities: &cdata.Capabilities{FilesSharing: &cdata.CapabilitiesFilesSharing{Public: &cdata.CapabilitiesFilesSharingPublic{
Password: &cdata.CapabilitiesFilesSharingPublicPassword{
EnforcedFor: &cdata.CapabilitiesFilesSharingPublicPasswordEnforcedFor{
// this is the equivalent of the ocis OCIS_SHARING_PUBLIC_WRITEABLE_SHARE_MUST_HAVE_PASSWORD=true
c.Capabilities = ocs.CapabilitiesData{
Capabilities: &ocs.Capabilities{FilesSharing: &ocs.CapabilitiesFilesSharing{Public: &ocs.CapabilitiesFilesSharingPublic{
Password: &ocs.CapabilitiesFilesSharingPublicPassword{
EnforcedFor: &ocs.CapabilitiesFilesSharingPublicPasswordEnforcedFor{
ReadOnly: false,
ReadWrite: true,
ReadWriteDelete: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ import (
"net/http"

"github.com/cs3org/reva/v2/internal/http/services/owncloud/ocs/config"
"github.com/cs3org/reva/v2/internal/http/services/owncloud/ocs/data"
"github.com/cs3org/reva/v2/internal/http/services/owncloud/ocs/response"
"github.com/cs3org/reva/v2/pkg/owncloud/ocs"
)

// Handler renders the capability endpoint
type Handler struct {
c data.CapabilitiesData
c ocs.CapabilitiesData
defaultUploadProtocol string
userAgentChunkingMap map[string]string
}
Expand All @@ -41,13 +41,13 @@ func (h *Handler) Init(c *config.Config) {

// capabilities
if h.c.Capabilities == nil {
h.c.Capabilities = &data.Capabilities{}
h.c.Capabilities = &ocs.Capabilities{}
}

// core

if h.c.Capabilities.Core == nil {
h.c.Capabilities.Core = &data.CapabilitiesCore{}
h.c.Capabilities.Core = &ocs.CapabilitiesCore{}
}
if h.c.Capabilities.Core.PollInterval == 0 {
h.c.Capabilities.Core.PollInterval = 60
Expand All @@ -58,7 +58,7 @@ func (h *Handler) Init(c *config.Config) {
// h.c.Capabilities.Core.SupportURLSigning is boolean

if h.c.Capabilities.Core.Status == nil {
h.c.Capabilities.Core.Status = &data.Status{}
h.c.Capabilities.Core.Status = &ocs.Status{}
}
// h.c.Capabilities.Core.Status.Installed is boolean
// h.c.Capabilities.Core.Status.Maintenance is boolean
Expand All @@ -85,7 +85,7 @@ func (h *Handler) Init(c *config.Config) {
// checksums

if h.c.Capabilities.Checksums == nil {
h.c.Capabilities.Checksums = &data.CapabilitiesChecksums{}
h.c.Capabilities.Checksums = &ocs.CapabilitiesChecksums{}
}
if h.c.Capabilities.Checksums.SupportedTypes == nil {
h.c.Capabilities.Checksums.SupportedTypes = []string{"SHA256"}
Expand All @@ -97,7 +97,7 @@ func (h *Handler) Init(c *config.Config) {
// files

if h.c.Capabilities.Files == nil {
h.c.Capabilities.Files = &data.CapabilitiesFiles{}
h.c.Capabilities.Files = &ocs.CapabilitiesFiles{}
}

if h.c.Capabilities.Files.BlacklistedFiles == nil {
Expand All @@ -108,17 +108,17 @@ func (h *Handler) Init(c *config.Config) {
// h.c.Capabilities.Files.Favorites is boolean

if h.c.Capabilities.Files.Archivers == nil {
h.c.Capabilities.Files.Archivers = []*data.CapabilitiesArchiver{}
h.c.Capabilities.Files.Archivers = []*ocs.CapabilitiesArchiver{}
}

if h.c.Capabilities.Files.AppProviders == nil {
h.c.Capabilities.Files.AppProviders = []*data.CapabilitiesAppProvider{}
h.c.Capabilities.Files.AppProviders = []*ocs.CapabilitiesAppProvider{}
}

// dav

if h.c.Capabilities.Dav == nil {
h.c.Capabilities.Dav = &data.CapabilitiesDav{}
h.c.Capabilities.Dav = &ocs.CapabilitiesDav{}
}
if h.c.Capabilities.Dav.Trashbin == "" {
h.c.Capabilities.Dav.Trashbin = "1.0"
Expand All @@ -130,24 +130,24 @@ func (h *Handler) Init(c *config.Config) {
// sharing

if h.c.Capabilities.FilesSharing == nil {
h.c.Capabilities.FilesSharing = &data.CapabilitiesFilesSharing{}
h.c.Capabilities.FilesSharing = &ocs.CapabilitiesFilesSharing{}
}

// h.c.Capabilities.FilesSharing.APIEnabled is boolean

if h.c.Capabilities.FilesSharing.Public == nil {
h.c.Capabilities.FilesSharing.Public = &data.CapabilitiesFilesSharingPublic{}
h.c.Capabilities.FilesSharing.Public = &ocs.CapabilitiesFilesSharingPublic{}
}

// h.c.Capabilities.FilesSharing.IsPublic.Enabled is boolean
h.c.Capabilities.FilesSharing.Public.Enabled = true

if h.c.Capabilities.FilesSharing.Public.Password == nil {
h.c.Capabilities.FilesSharing.Public.Password = &data.CapabilitiesFilesSharingPublicPassword{}
h.c.Capabilities.FilesSharing.Public.Password = &ocs.CapabilitiesFilesSharingPublicPassword{}
}

if h.c.Capabilities.FilesSharing.Public.Password.EnforcedFor == nil {
h.c.Capabilities.FilesSharing.Public.Password.EnforcedFor = &data.CapabilitiesFilesSharingPublicPasswordEnforcedFor{}
h.c.Capabilities.FilesSharing.Public.Password.EnforcedFor = &ocs.CapabilitiesFilesSharingPublicPasswordEnforcedFor{}
}

// h.c.Capabilities.FilesSharing.IsPublic.Password.EnforcedFor.ReadOnly is boolean
Expand All @@ -158,7 +158,7 @@ func (h *Handler) Init(c *config.Config) {
// h.c.Capabilities.FilesSharing.IsPublic.Password.Enforced is boolean

if h.c.Capabilities.FilesSharing.Public.ExpireDate == nil {
h.c.Capabilities.FilesSharing.Public.ExpireDate = &data.CapabilitiesFilesSharingPublicExpireDate{}
h.c.Capabilities.FilesSharing.Public.ExpireDate = &ocs.CapabilitiesFilesSharingPublicExpireDate{}
}
// h.c.Capabilities.FilesSharing.IsPublic.ExpireDate.Enabled is boolean

Expand All @@ -169,7 +169,7 @@ func (h *Handler) Init(c *config.Config) {
// h.c.Capabilities.FilesSharing.IsPublic.SupportsUploadOnly is boolean

if h.c.Capabilities.FilesSharing.User == nil {
h.c.Capabilities.FilesSharing.User = &data.CapabilitiesFilesSharingUser{}
h.c.Capabilities.FilesSharing.User = &ocs.CapabilitiesFilesSharingUser{}
}

// h.c.Capabilities.FilesSharing.User.SendMail is boolean
Expand All @@ -182,7 +182,7 @@ func (h *Handler) Init(c *config.Config) {
// h.c.Capabilities.FilesSharing.ShareWithMembershipGroupsOnly is boolean

if h.c.Capabilities.FilesSharing.UserEnumeration == nil {
h.c.Capabilities.FilesSharing.UserEnumeration = &data.CapabilitiesFilesSharingUserEnumeration{}
h.c.Capabilities.FilesSharing.UserEnumeration = &ocs.CapabilitiesFilesSharingUserEnumeration{}
}

// h.c.Capabilities.FilesSharing.UserEnumeration.Enabled is boolean
Expand All @@ -192,7 +192,7 @@ func (h *Handler) Init(c *config.Config) {
h.c.Capabilities.FilesSharing.DefaultPermissions = 31
}
if h.c.Capabilities.FilesSharing.Federation == nil {
h.c.Capabilities.FilesSharing.Federation = &data.CapabilitiesFilesSharingFederation{}
h.c.Capabilities.FilesSharing.Federation = &ocs.CapabilitiesFilesSharingFederation{}
}

// h.c.Capabilities.FilesSharing.Federation.Outgoing is boolean
Expand All @@ -205,7 +205,7 @@ func (h *Handler) Init(c *config.Config) {
// notifications

// if h.c.Capabilities.Notifications == nil {
// h.c.Capabilities.Notifications = &data.CapabilitiesNotifications{}
// h.c.Capabilities.Notifications = &ocs.CapabilitiesNotifications{}
// }
// if h.c.Capabilities.Notifications.Endpoints == nil {
// h.c.Capabilities.Notifications.Endpoints = []string{"list", "get", "delete"}
Expand All @@ -214,7 +214,7 @@ func (h *Handler) Init(c *config.Config) {
// version

if h.c.Version == nil {
h.c.Version = &data.Version{
h.c.Version = &ocs.Version{
// TODO get from build env
Major: 10,
Minor: 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ import (
"encoding/xml"
"testing"

"github.com/cs3org/reva/v2/internal/http/services/owncloud/ocs/data"
"github.com/cs3org/reva/v2/pkg/owncloud/ocs"
)

func TestMarshal(t *testing.T) {
cd := data.CapabilitiesData{
Capabilities: &data.Capabilities{
FilesSharing: &data.CapabilitiesFilesSharing{
cd := ocs.CapabilitiesData{
Capabilities: &ocs.Capabilities{
FilesSharing: &ocs.CapabilitiesFilesSharing{
APIEnabled: true,
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ package capabilities
import (
"strings"

"github.com/cs3org/reva/v2/internal/http/services/owncloud/ocs/data"
"github.com/cs3org/reva/v2/pkg/owncloud/ocs"
)

type chunkProtocol string
Expand All @@ -32,7 +32,7 @@ var (
chunkTUS chunkProtocol = "tus"
)

func (h *Handler) getCapabilitiesForUserAgent(userAgent string) data.CapabilitiesData {
func (h *Handler) getCapabilitiesForUserAgent(userAgent string) ocs.CapabilitiesData {
if userAgent != "" {
for k, v := range h.userAgentChunkingMap {
// we could also use a regexp for pattern matching
Expand All @@ -47,7 +47,7 @@ func (h *Handler) getCapabilitiesForUserAgent(userAgent string) data.Capabilitie
return h.c
}

func setCapabilitiesForChunkProtocol(cp chunkProtocol, c *data.CapabilitiesData) {
func setCapabilitiesForChunkProtocol(cp chunkProtocol, c *ocs.CapabilitiesData) {
switch cp {
case chunkV1:
// 2.7+ will use Chunking V1 if "capabilities > files > bigfilechunking" is "true" AND "capabilities > dav > chunking" is not there
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
// granted to it by virtue of its status as an Intergovernmental Organization
// or submit itself to any jurisdiction.

package data
package ocs

import (
"encoding/xml"
Expand All @@ -42,7 +42,7 @@ func (c ocsBool) MarshalXML(e *xml.Encoder, start xml.StartElement) error {
return e.EncodeElement("0", start)
}

// CapabilitiesData TODO document
// CapabilitiesData holds the capabilities data
type CapabilitiesData struct {
Capabilities *Capabilities `json:"capabilities" xml:"capabilities"`
Version *Version `json:"version" xml:"version"`
Expand All @@ -59,6 +59,7 @@ type Capabilities struct {
Graph *CapabilitiesGraph `json:"graph,omitempty" xml:"graph,omitempty" mapstructure:"graph"`
PasswordPolicy *CapabilitiesPasswordPolicy `json:"password_policy,omitempty" xml:"password_policy,omitempty" mapstructure:"password_policy"`
Search *CapabilitiesSearch `json:"search,omitempty" xml:"search,omitempty" mapstructure:"search"`
Theme *CapabilitiesTheme `json:"theme,omitempty" xml:"theme,omitempty" mapstructure:"theme"`
Notifications *CapabilitiesNotifications `json:"notifications,omitempty" xml:"notifications,omitempty"`
}

Expand Down Expand Up @@ -290,6 +291,17 @@ type CapabilitiesNotifications struct {
Endpoints []string `json:"ocs-endpoints,omitempty" xml:"ocs-endpoints>element,omitempty" mapstructure:"endpoints"`
}

// CapabilitiesTheme holds theming capabilities
type CapabilitiesTheme struct {
Logo *CapabilitiesThemeLogo `json:"logo" xml:"logo" mapstructure:"logo"`
}

// CapabilitiesThemeLogo holds theming logo capabilities
type CapabilitiesThemeLogo struct {
// xml marshal, unmarshal does not support map[string]string, needs a custom type with MarshalXML and UnmarshalXML implementations
PermittedFileTypes map[string]string `json:"permitted_file_types" xml:"-" mapstructure:"permitted_file_types"`
}

// Version holds version information
type Version struct {
Major int `json:"major" xml:"major"`
Expand Down

0 comments on commit 0a0508f

Please sign in to comment.