mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-01-06 12:19:37 -06:00
Merge pull request #8723 from kobergj/SpaceTemplatesII
Server-Side Space Templates
This commit is contained in:
@@ -44,7 +44,7 @@ l10n-push:
|
||||
|
||||
.PHONY: l10n-read
|
||||
l10n-read: $(GO_XGETTEXT)
|
||||
go-xgettext -o $(OUTPUT_DIR)/userlog.pot --keyword=Template -s pkg/service/templates.go
|
||||
go-xgettext -o $(OUTPUT_DIR)/userlog.pot --keyword=l10n.Template -s pkg/service/templates.go
|
||||
|
||||
.PHONY: l10n-write
|
||||
l10n-write:
|
||||
|
||||
@@ -6,7 +6,6 @@ import (
|
||||
"embed"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/fs"
|
||||
"strings"
|
||||
"text/template"
|
||||
"time"
|
||||
@@ -18,7 +17,7 @@ import (
|
||||
"github.com/cs3org/reva/v2/pkg/events"
|
||||
"github.com/cs3org/reva/v2/pkg/storagespace"
|
||||
"github.com/cs3org/reva/v2/pkg/utils"
|
||||
"github.com/leonelquinteros/gotext"
|
||||
"github.com/owncloud/ocis/v2/ocis-pkg/l10n"
|
||||
)
|
||||
|
||||
//go:embed l10n/locale
|
||||
@@ -338,7 +337,7 @@ func (c *Converter) getResource(ctx context.Context, resourceID *storageprovider
|
||||
return resource, err
|
||||
}
|
||||
|
||||
func (c *Converter) getUser(ctx context.Context, userID *user.UserId) (*user.User, error) {
|
||||
func (c *Converter) getUser(_ context.Context, userID *user.UserId) (*user.User, error) {
|
||||
if u, ok := c.users[userID.GetOpaqueId()]; ok {
|
||||
return u, nil
|
||||
}
|
||||
@@ -361,25 +360,9 @@ func composeMessage(nt NotificationTemplate, locale, defaultLocale, path string,
|
||||
return subject, subjectraw, message, messageraw, err
|
||||
}
|
||||
|
||||
func newLocate(locale string, path string) *gotext.Locale {
|
||||
// Create Locale with library path and language code and load default domain
|
||||
var l *gotext.Locale
|
||||
if path == "" {
|
||||
filesystem, _ := fs.Sub(_translationFS, "l10n/locale")
|
||||
l = gotext.NewLocaleFS(locale, filesystem)
|
||||
} else { // use custom path instead
|
||||
l = gotext.NewLocale(path, locale)
|
||||
}
|
||||
l.AddDomain(_domain) // make domain configurable only if needed
|
||||
return l
|
||||
}
|
||||
|
||||
func loadTemplates(nt NotificationTemplate, locale, defaultLocale, path string) (string, string) {
|
||||
l := newLocate(locale, path)
|
||||
if locale != "en" && len(l.GetTranslations()) == 0 {
|
||||
l = newLocate(defaultLocale, path)
|
||||
}
|
||||
return l.Get(nt.Subject), l.Get(nt.Message)
|
||||
t := l10n.NewTranslatorFromCommonConfig(defaultLocale, _domain, path, _translationFS, "l10n/locale").Locale(locale)
|
||||
return t.Get(nt.Subject), t.Get(nt.Message)
|
||||
}
|
||||
|
||||
func executeTemplate(raw string, vars map[string]interface{}) (string, error) {
|
||||
|
||||
@@ -11,20 +11,18 @@ import (
|
||||
gateway "github.com/cs3org/go-cs3apis/cs3/gateway/v1beta1"
|
||||
user "github.com/cs3org/go-cs3apis/cs3/identity/user/v1beta1"
|
||||
"github.com/go-chi/chi/v5"
|
||||
micrometadata "go-micro.dev/v4/metadata"
|
||||
"go-micro.dev/v4/store"
|
||||
"go.opentelemetry.io/otel/trace"
|
||||
|
||||
"github.com/cs3org/reva/v2/pkg/events"
|
||||
"github.com/cs3org/reva/v2/pkg/rgrpc/todo/pool"
|
||||
"github.com/cs3org/reva/v2/pkg/utils"
|
||||
"github.com/owncloud/ocis/v2/ocis-pkg/l10n"
|
||||
"github.com/owncloud/ocis/v2/ocis-pkg/log"
|
||||
"github.com/owncloud/ocis/v2/ocis-pkg/middleware"
|
||||
"github.com/owncloud/ocis/v2/ocis-pkg/roles"
|
||||
ehmsg "github.com/owncloud/ocis/v2/protogen/gen/ocis/messages/eventhistory/v0"
|
||||
ehsvc "github.com/owncloud/ocis/v2/protogen/gen/ocis/services/eventhistory/v0"
|
||||
settingssvc "github.com/owncloud/ocis/v2/protogen/gen/ocis/services/settings/v0"
|
||||
"github.com/owncloud/ocis/v2/services/settings/pkg/store/defaults"
|
||||
"github.com/owncloud/ocis/v2/services/userlog/pkg/config"
|
||||
)
|
||||
|
||||
@@ -343,7 +341,7 @@ func (ul *UserlogService) sendSSE(ctx context.Context, userIDs []string, event e
|
||||
m := make(map[string]events.SendSSE)
|
||||
|
||||
for _, userid := range userIDs {
|
||||
loc := ul.getUserLocale(userid)
|
||||
loc := l10n.MustGetUserLocale(ctx, userid, "", ul.valueClient)
|
||||
if ev, ok := m[loc]; ok {
|
||||
ev.UserIDs = append(m[loc].UserIDs, userid)
|
||||
m[loc] = ev
|
||||
@@ -455,25 +453,6 @@ func (ul *UserlogService) alterGlobalEvents(ctx context.Context, alter func(map[
|
||||
})
|
||||
}
|
||||
|
||||
func (ul *UserlogService) getUserLocale(userid string) string {
|
||||
resp, err := ul.valueClient.GetValueByUniqueIdentifiers(
|
||||
micrometadata.Set(context.Background(), middleware.AccountID, userid),
|
||||
&settingssvc.GetValueByUniqueIdentifiersRequest{
|
||||
AccountUuid: userid,
|
||||
SettingId: defaults.SettingUUIDProfileLanguage,
|
||||
},
|
||||
)
|
||||
if err != nil {
|
||||
ul.log.Error().Err(err).Str("userid", userid).Msg("cannot get users locale")
|
||||
return ""
|
||||
}
|
||||
val := resp.GetValue().GetValue().GetListValue().GetValues()
|
||||
if len(val) == 0 {
|
||||
return ""
|
||||
}
|
||||
return val[0].GetStringValue()
|
||||
}
|
||||
|
||||
func removeExecutant(users []string, executant *user.UserId) []string {
|
||||
var usrs []string
|
||||
for _, u := range users {
|
||||
|
||||
@@ -1,63 +1,62 @@
|
||||
package service
|
||||
|
||||
// Template marks the string as a translatable template
|
||||
func Template(s string) string { return s }
|
||||
import "github.com/owncloud/ocis/v2/ocis-pkg/l10n"
|
||||
|
||||
// the available templates
|
||||
var (
|
||||
VirusFound = NotificationTemplate{
|
||||
Subject: Template("Virus found"),
|
||||
Message: Template("Virus found in {resource}. Upload not possible. Virus: {virus}"),
|
||||
Subject: l10n.Template("Virus found"),
|
||||
Message: l10n.Template("Virus found in {resource}. Upload not possible. Virus: {virus}"),
|
||||
}
|
||||
|
||||
PoliciesEnforced = NotificationTemplate{
|
||||
Subject: Template("Policies enforced"),
|
||||
Message: Template("File {resource} was deleted because it violates the policies"),
|
||||
Subject: l10n.Template("Policies enforced"),
|
||||
Message: l10n.Template("File {resource} was deleted because it violates the policies"),
|
||||
}
|
||||
|
||||
SpaceShared = NotificationTemplate{
|
||||
Subject: Template("Space shared"),
|
||||
Message: Template("{user} added you to Space {space}"),
|
||||
Subject: l10n.Template("Space shared"),
|
||||
Message: l10n.Template("{user} added you to Space {space}"),
|
||||
}
|
||||
|
||||
SpaceUnshared = NotificationTemplate{
|
||||
Subject: Template("Removed from Space"),
|
||||
Message: Template("{user} removed you from Space {space}"),
|
||||
Subject: l10n.Template("Removed from Space"),
|
||||
Message: l10n.Template("{user} removed you from Space {space}"),
|
||||
}
|
||||
|
||||
SpaceDisabled = NotificationTemplate{
|
||||
Subject: Template("Space disabled"),
|
||||
Message: Template("{user} disabled Space {space}"),
|
||||
Subject: l10n.Template("Space disabled"),
|
||||
Message: l10n.Template("{user} disabled Space {space}"),
|
||||
}
|
||||
|
||||
SpaceDeleted = NotificationTemplate{
|
||||
Subject: Template("Space deleted"),
|
||||
Message: Template("{user} deleted Space {space}"),
|
||||
Subject: l10n.Template("Space deleted"),
|
||||
Message: l10n.Template("{user} deleted Space {space}"),
|
||||
}
|
||||
|
||||
SpaceMembershipExpired = NotificationTemplate{
|
||||
Subject: Template("Membership expired"),
|
||||
Message: Template("Access to Space {space} lost"),
|
||||
Subject: l10n.Template("Membership expired"),
|
||||
Message: l10n.Template("Access to Space {space} lost"),
|
||||
}
|
||||
|
||||
ShareCreated = NotificationTemplate{
|
||||
Subject: Template("Resource shared"),
|
||||
Message: Template("{user} shared {resource} with you"),
|
||||
Subject: l10n.Template("Resource shared"),
|
||||
Message: l10n.Template("{user} shared {resource} with you"),
|
||||
}
|
||||
|
||||
ShareRemoved = NotificationTemplate{
|
||||
Subject: Template("Resource unshared"),
|
||||
Message: Template("{user} unshared {resource} with you"),
|
||||
Subject: l10n.Template("Resource unshared"),
|
||||
Message: l10n.Template("{user} unshared {resource} with you"),
|
||||
}
|
||||
|
||||
ShareExpired = NotificationTemplate{
|
||||
Subject: Template("Share expired"),
|
||||
Message: Template("Access to {resource} expired"),
|
||||
Subject: l10n.Template("Share expired"),
|
||||
Message: l10n.Template("Access to {resource} expired"),
|
||||
}
|
||||
|
||||
PlatformDeprovision = NotificationTemplate{
|
||||
Subject: Template("Instance will be shut down and deprovisioned"),
|
||||
Message: Template("Attention! The instance will be shut down and deprovisioned on {date}. Download all your data before that date as no access past that date is possible."),
|
||||
Subject: l10n.Template("Instance will be shut down and deprovisioned"),
|
||||
Message: l10n.Template("Attention! The instance will be shut down and deprovisioned on {date}. Download all your data before that date as no access past that date is possible."),
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user