Skip to content

Commit

Permalink
added the translation
Browse files Browse the repository at this point in the history
  • Loading branch information
2403905 committed Sep 23, 2024
1 parent b65355c commit 1a23ea5
Show file tree
Hide file tree
Showing 13 changed files with 146 additions and 63 deletions.
2 changes: 1 addition & 1 deletion changelog/unreleased/fix-acitivity-update-share.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
go Bugfix: Added ShareUpdate activity
Bugfix: Added ShareUpdate activity

Added the ShareUpdate activity in the space context.

Expand Down
4 changes: 1 addition & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ require (
github.com/cenkalti/backoff v2.2.1+incompatible
github.com/coreos/go-oidc/v3 v3.11.0
github.com/cs3org/go-cs3apis v0.0.0-20240724121416-062c4e3046cb
github.com/cs3org/reva/v2 v2.24.2-0.20240918135034-5a494dc2ebf7
github.com/cs3org/reva/v2 v2.24.2-0.20240919151635-556263192484
github.com/dhowden/tag v0.0.0-20230630033851-978a0926ee25
github.com/dutchcoders/go-clamd v0.0.0-20170520113014-b970184f4d9e
github.com/egirna/icap-client v0.1.1
Expand Down Expand Up @@ -368,5 +368,3 @@ replace github.com/go-micro/plugins/v4/store/nats-js-kv => github.com/kobergj/pl
// exclude the v2 line of go-sqlite3 which was released accidentally and prevents pulling in newer versions of go-sqlite3
// see https://github.com/mattn/go-sqlite3/issues/965 for more details
exclude github.com/mattn/go-sqlite3 v2.0.3+incompatible

replace github.com/cs3org/reva/v2 => github.com/2403905/reva/v2 v2.24.1-0.20240918144132-2e1d422f27f7
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ contrib.go.opencensus.io/exporter/prometheus v0.4.2/go.mod h1:dvEHbiKmgvbr5pjaF9
dario.cat/mergo v1.0.1 h1:Ra4+bf83h2ztPIQYNP99R6m+Y7KfnARDfID+a+vLl4s=
dario.cat/mergo v1.0.1/go.mod h1:uNxQE+84aUszobStD9th8a29P2fMDhsBdgRYvZOxGmk=
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
github.com/2403905/reva/v2 v2.24.1-0.20240918144132-2e1d422f27f7 h1:hGa5dN1E/WgehwO6XRwYlMZGvfw6LExMFlGCqBSyZ3U=
github.com/2403905/reva/v2 v2.24.1-0.20240918144132-2e1d422f27f7/go.mod h1:p7CHBXcg6sSqB+0JMNDfC1S7TSh9FghXkw1kTV3KcJI=
github.com/Acconut/go-httptest-recorder v1.0.0 h1:TAv2dfnqp/l+SUvIaMAUK4GeN4+wqb6KZsFFFTGhoJg=
github.com/Acconut/go-httptest-recorder v1.0.0/go.mod h1:CwQyhTH1kq/gLyWiRieo7c0uokpu3PXeyF/nZjUNtmM=
github.com/Azure/azure-sdk-for-go v32.4.0+incompatible/go.mod h1:9XXNKU+eRnpl9moKnB4QOLf1HestfXbmab5FXxiDBjc=
Expand Down Expand Up @@ -257,6 +255,8 @@ github.com/crewjam/saml v0.4.14 h1:g9FBNx62osKusnFzs3QTN5L9CVA/Egfgm+stJShzw/c=
github.com/crewjam/saml v0.4.14/go.mod h1:UVSZCf18jJkk6GpWNVqcyQJMD5HsRugBPf4I1nl2mME=
github.com/cs3org/go-cs3apis v0.0.0-20240724121416-062c4e3046cb h1:KmYZDReplv/yfwc1LNYpDcVhVujC3Pasv6WjXx1haSU=
github.com/cs3org/go-cs3apis v0.0.0-20240724121416-062c4e3046cb/go.mod h1:yyP8PRo0EZou3nSH7H4qjlzQwaydPeIRNgX50npQHpE=
github.com/cs3org/reva/v2 v2.24.2-0.20240919151635-556263192484 h1:MeHzCFCh5WttP2hz7UTCHgV6WQXrucQXSyQs5+aIrcY=
github.com/cs3org/reva/v2 v2.24.2-0.20240919151635-556263192484/go.mod h1:p7CHBXcg6sSqB+0JMNDfC1S7TSh9FghXkw1kTV3KcJI=
github.com/cyberdelia/templates v0.0.0-20141128023046-ca7fffd4298c/go.mod h1:GyV+0YP4qX0UQ7r2MoYZ+AvYDp12OF5yg4q8rGnyNh4=
github.com/cyphar/filepath-securejoin v0.2.4 h1:Ugdm7cg7i6ZK6x3xDF1oEu1nfkyfH53EtKeQYTC3kyg=
github.com/cyphar/filepath-securejoin v0.2.4/go.mod h1:aPGpWjXOXUn2NCNjFvBE6aRxGGx79pTxQpKOJNYHHl4=
Expand Down
11 changes: 6 additions & 5 deletions services/activitylog/pkg/service/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,9 @@ func (s *ActivitylogService) HandleGetItemActivities(w http.ResponseWriter, r *h
vars map[string]interface{}
)

loc := l10n.MustGetUserLocale(r.Context(), activeUser.GetId().GetOpaqueId(), r.Header.Get(l10n.HeaderAcceptLanguage), s.valService)
t := l10n.NewTranslatorFromCommonConfig(s.cfg.DefaultLanguage, _domain, s.cfg.TranslationPath, _localeFS, _localeSubPath)

switch ev := s.unwrapEvent(e).(type) {
case nil:
// error already logged in unwrapEvent
Expand Down Expand Up @@ -158,7 +161,7 @@ func (s *ActivitylogService) HandleGetItemActivities(w http.ResponseWriter, r *h
}
message = MessageShareUpdated
ts = utils.TSToTime(ev.MTime)
vars, err = s.GetVars(ctx, WithResource(toRef(ev.ItemID), false), WithUser(ev.Executant, ""), WithFieldMask(ev.UpdateMask))
vars, err = s.GetVars(ctx, WithResource(toRef(ev.ItemID), false), WithUser(ev.Executant, ""), WithTranslation(&t, loc, "field", ev.UpdateMask))
case events.ShareRemoved:
message = MessageShareDeleted
ts = ev.Timestamp
Expand All @@ -176,7 +179,8 @@ func (s *ActivitylogService) HandleGetItemActivities(w http.ResponseWriter, r *h
vars, err = s.GetVars(ctx,
WithResource(toRef(ev.ItemID), false),
WithUser(ev.Executant, ""),
WithLinkFieldUpdated(&ev))
WithTranslation(&t, loc, "field", []string{ev.FieldUpdated}),
WithVar("token", ev.ItemID.GetOpaqueId(), ev.Token))
case events.LinkRemoved:
message = MessageLinkDeleted
ts = utils.TSToTime(ev.Timestamp)
Expand All @@ -196,9 +200,6 @@ func (s *ActivitylogService) HandleGetItemActivities(w http.ResponseWriter, r *h
continue
}

loc := l10n.MustGetUserLocale(r.Context(), activeUser.GetId().GetOpaqueId(), r.Header.Get(l10n.HeaderAcceptLanguage), s.valService)
t := l10n.NewTranslatorFromCommonConfig(s.cfg.DefaultLanguage, _domain, s.cfg.TranslationPath, _localeFS, _localeSubPath)

resp.Activities = append(resp.Activities, NewActivity(t.Translate(message, loc), ts, e.GetId(), vars))
}

Expand Down
74 changes: 46 additions & 28 deletions services/activitylog/pkg/service/response.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package service
import (
"context"
"fmt"
"github.com/cs3org/reva/v2/pkg/events"
"path/filepath"
"strings"
"time"
Expand Down Expand Up @@ -35,6 +34,22 @@ var (
MessageLinkDeleted = l10n.Template("{user} removed link to {resource}")
MessageSpaceShared = l10n.Template("{user} added {sharee} as member of {space}")
MessageSpaceUnshared = l10n.Template("{user} removed {sharee} from {space}")

StrSomeField = l10n.Template(_someField)
StrPermission = l10n.Template(_permission)
StrPassword = l10n.Template(_password)
StrExpirationDate = l10n.Template(_expirationDate)
StrDisplayName = l10n.Template(_displayName)
StrDescription = l10n.Template(_description)
)

const (
_someField = "some field"
_permission = "permission"
_password = "password"
_expirationDate = "expiration date"
_displayName = "display name"
_description = "description"
)

// GetActivitiesResponse is the response on GET activities requests
Expand Down Expand Up @@ -230,42 +245,29 @@ func WithSpace(spaceid *provider.StorageSpaceId) ActivityOption {
}
}

// WithLinkFieldUpdated sets the field and token variables for an activity
func WithLinkFieldUpdated(e *events.LinkUpdated) ActivityOption {
// WithTranslation sets a variable that translation is needed for
func WithTranslation(t *l10n.Translator, locale string, key string, values []string) ActivityOption {
return func(_ context.Context, _ gateway.GatewayAPIClient, vars map[string]interface{}) error {
f := "some field"
switch e.FieldUpdated {
case "TYPE_PERMISSIONS":
f = "permission"
case "TYPE_PASSWORD":
f = "password"
case "TYPE_EXPIRATION":
f = "expiration date"
case "TYPE_DISPLAYNAME":
f = "display name"
case "TYPE_DESCRIPTION":
f = "description"
f := t.Translate(StrSomeField, locale)
if len(values) > 0 {
for i := range values {
values[i] = t.Translate(mapField(values[i]), locale)
}
f = strings.Join(values, ", ")
}
vars["field"] = Resource{
ID: e.ItemID.GetOpaqueId(),
vars[key] = Resource{
Name: f,
}
vars["token"] = Resource{
ID: e.ItemID.GetOpaqueId(),
Name: e.Token,
}
return nil
}
}

func WithFieldMask(mask []string) ActivityOption {
// WithVar sets a variable for an activity
func WithVar(key, id, name string) ActivityOption {
return func(_ context.Context, _ gateway.GatewayAPIClient, vars map[string]interface{}) error {
f := "some field"
if len(mask) > 0 {
f = strings.Join(mask, ", ")
}
vars["field"] = Resource{
Name: f,
vars[key] = Resource{
ID: id,
Name: name,
}
return nil
}
Expand Down Expand Up @@ -299,3 +301,19 @@ func (s *ActivitylogService) GetVars(ctx context.Context, opts ...ActivityOption

return vars, nil
}

func mapField(val string) string {
switch val {
case "TYPE_PERMISSIONS", "permission":
return _permission
case "TYPE_PASSWORD", "password":
return _password
case "TYPE_EXPIRATION", "expiration":
return _expirationDate
case "TYPE_DISPLAYNAME":
return _displayName
case "TYPE_DESCRIPTION":
return _description
}
return _someField
}
2 changes: 1 addition & 1 deletion services/audit/pkg/types/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func ShareUpdated(ev events.ShareUpdated) AuditEventShareUpdated {
func LinkUpdated(ev events.LinkUpdated) AuditEventShareUpdated {
uid := ev.Sharer.OpaqueId
with, typ := "", _linktype
base := BasicAuditEvent(uid, formatTime(ev.MTime), MessageLinkUpdated(uid, ev.ShareID.OpaqueId, ev.FieldUpdated), updateType(ev.FieldUpdated))
base := BasicAuditEvent(uid, formatTime(ev.MTime), MessageLinkUpdated(uid, ev.ShareID.GetOpaqueId(), ev.FieldUpdated), updateType(ev.FieldUpdated))
return AuditEventShareUpdated{
AuditEventSharing: SharingAuditEvent(ev.ShareID.GetOpaqueId(), ev.ItemID.OpaqueId, uid, base),
ShareOwner: uid,
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 1a23ea5

Please sign in to comment.