Skip to content

Commit

Permalink
README.md updated.
Browse files Browse the repository at this point in the history
returned value swapped
  • Loading branch information
2403905 committed Apr 17, 2023
1 parent cd59424 commit a8a926b
Show file tree
Hide file tree
Showing 5 changed files with 104 additions and 24 deletions.
31 changes: 29 additions & 2 deletions services/notifications/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,41 @@

The notification service is responsible for sending emails to users informing them about events that happened. To do this it hooks into the event system and listens for certain events that the users need to be informed about.

## Email notification

The `notifications` service has embedded email body templates.
The email templates contain placeholders `{{ .Greeting }}`, `{{ .MessageBody }}`, `{{ .CallToAction }}` that are
replaced with translations (See [Translations](#translations) in this readme).
These embedded templates are available for all deployment scenarios. In addition, the service supports custom
templates.
The custom email template takes precedence over the embedded one. If a custom email template exists, the embedded ones
are not used. To configure custom email templates,
the `NOTIFICATIONS_EMAIL_TEMPLATE_PATH` environment variable needs to point to a base folder that will contain the email
templates. The source template files provided by ocis are situated
in [https://github.com/owncloud/ocis/tree/master/services/notifications/pkg/email/templates](https://github.com/owncloud/ocis/tree/master/services/notifications/pkg/email/templates) in the `shares`
and `spaces` subfolders.
The custom email templates must be situated in the same subfolder and have the same names as the embedded templates.
```
templates
└───shares
│ │ shareCreated.email.body.tmpl
│ │ shareExpired.email.body.tmpl
└───spaces
│ membershipExpired.email.body.tmpl
│ sharedSpace.email.body.tmpl
│ unsharedSpace.email.body.tmpl
```

## Translations

The `translations` service has embedded translations sourced via transifex to provide a basic set of translated languages.
The `notifications` service has embedded translations sourced via transifex to provide a basic set of translated languages.
These embedded translations are available for all deployment scenarios. In addition, the service supports custom
translations, though it is currently not possible to just add custom translations to embedded ones. If custom
translations are configured, the embedded ones are not used. To configure custom translations,
the `NOTIFICATIONS_TRANSLATION_PATH` environment variable needs to point to a base folder that will contain the translation
files. This path must be available from all instances of the translations service, a shared storage is recommended.
files. This path must be available from all instances of the notifications service, a shared storage is recommended.
Translation files must be of type [.po](https://www.gnu.org/software/gettext/manual/html_node/PO-Files.html#PO-Files)
or [.mo](https://www.gnu.org/software/gettext/manual/html_node/Binaries.html). For each language, the filename needs to
be `translations.po` (or `translations.mo`) and stored in a folder structure defining the language code. In general the path/name
Expand Down
6 changes: 1 addition & 5 deletions services/notifications/pkg/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,7 @@ func (s eventsNotifier) Run() error {

func (s eventsNotifier) render(template email.MessageTemplate, values map[string]interface{}) (string, string, error) {
// The locate have to come from the user setting
sub, msg, err := email.RenderEmailTemplate(template, "en", s.emailTemplatePath, s.translationPath, values)
if err != nil {
return "", "", err
}
return msg, sub, nil
return email.RenderEmailTemplate(template, "en", s.emailTemplatePath, s.translationPath, values)
}

func (s eventsNotifier) send(ctx context.Context, u *user.UserId, g *group.GroupId, msg, subj, sender string) error {
Expand Down
81 changes: 69 additions & 12 deletions services/notifications/pkg/service/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,19 @@ var _ = Describe("Notifications", func() {
Entry("Share Created", testChannel{
expectedReceipients: map[string]bool{sharee.GetId().GetOpaqueId(): true},
expectedSubject: "Dr. S. Harer shared 'secrets of the board' with you",
expectedSender: sharer.GetDisplayName(),
done: make(chan struct{}),
expectedMessage: `Hello Dr. S. Harer
Dr. S. Harer has shared "secrets of the board" with you.
Click here to view it: files/shares/with-me
---
ownCloud - Store. Share. Work.
https://owncloud.com
`,
expectedSender: sharer.GetDisplayName(),
done: make(chan struct{}),
}, events.Event{
Event: events.ShareCreated{
Sharer: sharer.GetId(),
Expand All @@ -80,8 +91,19 @@ var _ = Describe("Notifications", func() {
Entry("Share Expired", testChannel{
expectedReceipients: map[string]bool{sharee.GetId().GetOpaqueId(): true},
expectedSubject: "Share to 'secrets of the board' expired at 2023-04-17 16:42:00",
expectedSender: sharer.GetDisplayName(),
done: make(chan struct{}),
expectedMessage: `Hello Dr. S. Harer,
Your share to secrets of the board has expired at 2023-04-17 16:42:00
Even though this share has been revoked you still might have access through other shares and/or space memberships.
---
ownCloud - Store. Share. Work.
https://owncloud.com
`,
expectedSender: sharer.GetDisplayName(),
done: make(chan struct{}),
}, events.Event{
Event: events.ShareExpired{
ShareOwner: sharer.GetId(),
Expand All @@ -94,8 +116,19 @@ var _ = Describe("Notifications", func() {
Entry("Added to Space", testChannel{
expectedReceipients: map[string]bool{sharee.GetId().GetOpaqueId(): true},
expectedSubject: "Dr. S. Harer invited you to join secret space",
expectedSender: sharer.GetDisplayName(),
done: make(chan struct{}),
expectedMessage: `Hello Dr. S. Harer,
Dr. S. Harer has invited you to join "secret space".
Click here to view it: f/spaceid
---
ownCloud - Store. Share. Work.
https://owncloud.com
`,
expectedSender: sharer.GetDisplayName(),
done: make(chan struct{}),
}, events.Event{
Event: events.SpaceShared{
Executant: sharer.GetId(),
Expand All @@ -108,8 +141,21 @@ var _ = Describe("Notifications", func() {
Entry("Removed from Space", testChannel{
expectedReceipients: map[string]bool{sharee.GetId().GetOpaqueId(): true},
expectedSubject: "Dr. S. Harer removed you from secret space",
expectedSender: sharer.GetDisplayName(),
done: make(chan struct{}),
expectedMessage: `Hello Dr. S. Harer,
Dr. S. Harer has removed you from "secret space".
You might still have access through your other groups or direct membership.
Click here to check it: f/spaceid
---
ownCloud - Store. Share. Work.
https://owncloud.com
`,
expectedSender: sharer.GetDisplayName(),
done: make(chan struct{}),
}, events.Event{
Event: events.SpaceUnshared{
Executant: sharer.GetId(),
Expand All @@ -121,8 +167,19 @@ var _ = Describe("Notifications", func() {
Entry("Space Expired", testChannel{
expectedReceipients: map[string]bool{sharee.GetId().GetOpaqueId(): true},
expectedSubject: "Membership of 'secret space' expired at 2023-04-17 16:42:00",
expectedSender: sharer.GetDisplayName(),
done: make(chan struct{}),
expectedMessage: `Hello Dr. S. Harer,
Your membership of space secret space has expired at 2023-04-17 16:42:00
Even though this membership has expired you still might have access through other shares and/or space memberships
---
ownCloud - Store. Share. Work.
https://owncloud.com
`,
expectedSender: sharer.GetDisplayName(),
done: make(chan struct{}),
}, events.Event{
Event: events.SpaceMembershipExpired{
SpaceOwner: sharer.GetId(),
Expand All @@ -139,6 +196,7 @@ var _ = Describe("Notifications", func() {
type testChannel struct {
expectedReceipients map[string]bool
expectedSubject string
expectedMessage string
expectedSender string
done chan struct{}
}
Expand All @@ -150,8 +208,7 @@ func (tc testChannel) SendMessage(ctx context.Context, userIDs []string, msg, su
Expect(tc.expectedReceipients[u]).To(Equal(true))
}

// TODO: test the message?
//Expect(msg).To(Equal(tc.expectedMessage))
Expect(msg).To(Equal(tc.expectedMessage))
Expect(subject).To(Equal(tc.expectedSubject))
Expect(senderDisplayName).To(Equal(tc.expectedSender))
tc.done <- struct{}{}
Expand Down
4 changes: 2 additions & 2 deletions services/notifications/pkg/service/shares.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func (s eventsNotifier) handleShareCreated(e events.ShareCreated) {
}

sharerDisplayName := owner.GetDisplayName()
msg, subj, err := s.render(email.ShareCreated, map[string]interface{}{
subj, msg, err := s.render(email.ShareCreated, map[string]interface{}{
"ShareGrantee": shareGrantee,
"ShareSharer": sharerDisplayName,
"ShareFolder": resourceInfo.Name,
Expand Down Expand Up @@ -85,7 +85,7 @@ func (s eventsNotifier) handleShareExpired(e events.ShareExpired) {
return
}

msg, subj, err := s.render(email.ShareExpired, map[string]interface{}{
subj, msg, err := s.render(email.ShareExpired, map[string]interface{}{
"ShareGrantee": shareGrantee,
"ShareFolder": resourceInfo.GetName(),
"ExpiredAt": e.ExpiredAt.Format("2006-01-02 15:04:05"),
Expand Down
6 changes: 3 additions & 3 deletions services/notifications/pkg/service/spaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func (s eventsNotifier) handleSpaceShared(e events.SpaceShared) {
}

sharerDisplayName := owner.GetDisplayName()
msg, subj, err := s.render(email.SharedSpace, map[string]interface{}{
subj, msg, err := s.render(email.SharedSpace, map[string]interface{}{
"SpaceGrantee": spaceGrantee,
"SpaceSharer": sharerDisplayName,
"SpaceName": resourceInfo.GetSpace().GetName(),
Expand Down Expand Up @@ -117,7 +117,7 @@ func (s eventsNotifier) handleSpaceUnshared(e events.SpaceUnshared) {
}

sharerDisplayName := owner.GetDisplayName()
msg, subj, err := s.render(email.UnsharedSpace, map[string]interface{}{
subj, msg, err := s.render(email.UnsharedSpace, map[string]interface{}{
"SpaceGrantee": spaceGrantee,
"SpaceSharer": sharerDisplayName,
"SpaceName": resourceInfo.GetSpace().Name,
Expand Down Expand Up @@ -152,7 +152,7 @@ func (s eventsNotifier) handleSpaceMembershipExpired(e events.SpaceMembershipExp
return
}

msg, subj, err := s.render(email.MembershipExpired, map[string]interface{}{
subj, msg, err := s.render(email.MembershipExpired, map[string]interface{}{
"SpaceGrantee": shareGrantee,
"SpaceName": e.SpaceName,
"ExpiredAt": e.ExpiredAt.Format("2006-01-02 15:04:05"),
Expand Down

0 comments on commit a8a926b

Please sign in to comment.