Skip to content

Commit

Permalink
refactor(api,ui): rm jabb notifications (#6036)
Browse files Browse the repository at this point in the history
* refactor(api,ui): rm jabb notifications

kafka event have to be used to send msg on enterprise msg system

Signed-off-by: Yvonnick Esnault <[email protected]>
  • Loading branch information
yesnault authored Apr 22, 2022
1 parent 7a94305 commit 3016fac
Show file tree
Hide file tree
Showing 13 changed files with 26 additions and 88 deletions.
18 changes: 0 additions & 18 deletions docs/content/docs/concepts/files/workflow-syntax.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,24 +104,6 @@ Example of email notification.
- [email protected]
```

Example of jabber notification. Note that you can add `conditions` on every notifications

```yml
- type: jabber
pipelines:
- deploy
settings:
on_start: true
send_to_groups: true
recipients:
- [email protected]
conditions:
check:
- variable: cds.triggered_by.email
operator: eq
value: [email protected]
```

Example of vcs notification. Note that `pipelines` list is optional on every notifications. When it's not specified, notification will be triggered for each pipeline

```yml
Expand Down
2 changes: 1 addition & 1 deletion docs/content/docs/concepts/workflow/notifications.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ On a workflow you can have 2 kinds of notifications:

## User notifications

You can configure user notifications to send email or a message on jabber with different parameters. Inside the body of the notification you can customise the message thanks to the CDS variable templating with syntax like `{{.cds.myvar}}`. You can also use `HTML` to customise the message, then in order to let CDS interpret your message as an `HTML` one you just need to wrap all your message inside html tag like this `<html>MyContentHere</html>`.
You can configure user notifications to send email with different parameters. Inside the body of the notification you can customise the message thanks to the CDS variable templating with syntax like `{{.cds.myvar}}`. You can also use `HTML` to customise the message, then in order to let CDS interpret your message as an `HTML` one you just need to wrap all your message inside html tag like this `<html>MyContentHere</html>`.

## VCS Notifications

Expand Down
8 changes: 0 additions & 8 deletions engine/api/notification.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,6 @@ func (api *API) getUserNotificationTypeHandler() service.Handler {
SendToGroups: &sdk.False,
Template: &sdk.UserNotificationTemplateEmail,
},
sdk.JabberUserNotification: {
OnSuccess: sdk.UserNotificationChange,
OnFailure: sdk.UserNotificationAlways,
OnStart: &sdk.False,
SendToAuthor: &sdk.True,
SendToGroups: &sdk.False,
Template: &sdk.UserNotificationTemplateJabber,
},
sdk.VCSUserNotification: {
Template: &sdk.UserNotificationTemplate{
Body: sdk.DefaultWorkflowNodeRunReport,
Expand Down
36 changes: 2 additions & 34 deletions engine/api/notification/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,50 +57,18 @@ func GetUserWorkflowEvents(ctx context.Context, db gorp.SqlExecutor, store cache
for _, notif := range notifs {
if ShouldSendUserWorkflowNotification(ctx, notif, nr, previousWR) {
switch notif.Type {
case sdk.JabberUserNotification:
jn := &notif.Settings
//Get recipents from groups
if jn.SendToGroups != nil && *jn.SendToGroups {
u, err := projectPermissionUserIDs(ctx, db, store, projectID, sdk.PermissionRead)
if err != nil {
log.Error(ctx, "notification[Jabber]. error while loading permission: %v", err)
break
}
users, err := user.LoadAllByIDs(ctx, db, u)
if err != nil {
log.Error(ctx, "notification[Jabber]. error while loading users: %v", err)
break
}
for _, u := range users {
jn.Recipients = append(jn.Recipients, u.Username)
}
}
if jn.SendToAuthor == nil || *jn.SendToAuthor {
if author, ok := params[paramsAuthorEmail]; ok {
jn.Recipients = append(jn.Recipients, author)
}
}

//Finally deduplicate everyone
removeDuplicates(&jn.Recipients)
notif, err := getWorkflowEvent(jn, params)
if err != nil {
log.Error(ctx, "notification.GetUserWorkflowEvents> unable to handle event %+v: %v", jn, err)
}
events = append(events, notif)

case sdk.EmailUserNotification:
jn := &notif.Settings
//Get recipents from groups
if jn.SendToGroups != nil && *jn.SendToGroups {
u, err := projectPermissionUserIDs(ctx, db, store, projectID, sdk.PermissionRead)
if err != nil {
log.Error(ctx, "notification[Email].GetUserWorkflowEvents> error while loading permission: %v", err)
log.Error(ctx, "error while loading permission: %v", err)
return nil
}
contacts, err := user.LoadContactsByUserIDs(ctx, db, u)
if err != nil {
log.Error(ctx, "notification[Jabber]. error while loading users contacts: %v", err)
log.Error(ctx, "error while loading users contacts: %v", err)
break
}
for _, c := range contacts {
Expand Down
2 changes: 1 addition & 1 deletion engine/api/workflow/dao_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1158,7 +1158,7 @@ func TestInsertComplexeWorkflowWithComplexeJoins(t *testing.T) {
},
Notifications: []sdk.WorkflowNotification{
{
Type: "jabber",
Type: "email",
SourceNodeRefs: []string{"pip6", "pip5"},
Settings: sdk.UserNotificationSettings{
OnFailure: sdk.UserNotificationAlways,
Expand Down
6 changes: 3 additions & 3 deletions engine/api/workflow_ascode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -717,7 +717,7 @@ metadata:
default_tags: tag_version,git.branch,git.author
notifications:
- type: vcs
- type: jabber
- type: email
pipelines:
- playbook-game-stuff
- playbook-game-molecule
Expand All @@ -732,7 +732,7 @@ notifications:
{{.cds.status}}'
body: |
{{.cds.buildURL}}
- type: jabber
- type: email
pipelines:
- notify
settings:
Expand All @@ -748,7 +748,7 @@ notifications:
- variable: git.branch
operator: eq
value: master
- type: jabber
- type: email
pipelines:
- notify
settings:
Expand Down
5 changes: 5 additions & 0 deletions engine/sql/api/240_delete_notif_jabber.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
-- +migrate Up
delete from workflow_notification where type = 'jabber';

-- +migrate Down
SELECT 1;
5 changes: 3 additions & 2 deletions sdk/exportentities/v1/workflow_notif_test.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package v1_test

import (
v1 "github.com/ovh/cds/sdk/exportentities/v1"
"reflect"
"testing"

v1 "github.com/ovh/cds/sdk/exportentities/v1"

"github.com/ovh/cds/engine/api/test"
"github.com/ovh/cds/sdk"
yaml "gopkg.in/yaml.v2"
Expand Down Expand Up @@ -48,7 +49,7 @@ metadata:
default_tags: git.branch,git.author
notifications:
DDOS-me,DDOS-me_2:
- type: jabber
- type: email
settings:
on_success: always
on_failure: change
Expand Down
8 changes: 4 additions & 4 deletions sdk/exportentities/v2/workflow_notif_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ workflow:
metadata:
default_tags: git.branch,git.author
notifications:
- type: jabber
- type: email
pipelines:
- DDOS-me
- DDOS-me_2
Expand Down Expand Up @@ -158,7 +158,7 @@ workflow:
- success
pipeline: test
notifications:
- type: jabber
- type: email
pipelines:
- test
- test_2
Expand Down Expand Up @@ -198,7 +198,7 @@ notifications:
Details : {{.cds.buildURL}}
Triggered by : {{.cds.triggered_by.username}}
Branch : {{.git.branch}}
- type: jabber
- type: email
pipelines:
- test
- test_2
Expand Down Expand Up @@ -231,7 +231,7 @@ workflow:
- success
pipeline: test
notifications:
- type: jabber
- type: email
- type: event
integration: my-integration
`,
Expand Down
17 changes: 5 additions & 12 deletions sdk/notif.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,9 @@ import (

//const
const (
EmailUserNotification = "email"
JabberUserNotification = "jabber"
VCSUserNotification = "vcs"
EventsNotification = "event"
EmailUserNotification = "email"
VCSUserNotification = "vcs"
EventsNotification = "event"
)

//const
Expand All @@ -35,7 +34,7 @@ type UserNotification struct {
Notifications map[string]UserNotificationSettings `json:"notifications"`
}

// UserNotificationSettings are jabber or email settings
// UserNotificationSettings --> email settings
type UserNotificationSettings struct {
OnSuccess string `json:"on_success,omitempty" yaml:"on_success,omitempty"` // default is "onChange", empty means onChange
OnFailure string `json:"on_failure,omitempty" yaml:"on_failure,omitempty"` // default is "always", empty means always
Expand Down Expand Up @@ -96,14 +95,8 @@ Triggered by : {{.cds.triggered_by.username}}
Branch : {{.git.branch | default "n/a"}}`,
}

UserNotificationTemplateJabber = UserNotificationTemplate{
Subject: "{{.cds.project}}/{{.cds.workflow}}#{{.cds.version}} {{.cds.status}}",
Body: `{{.cds.buildURL}}`,
}

UserNotificationTemplateMap = map[string]UserNotificationTemplate{
EmailUserNotification: UserNotificationTemplateEmail,
JabberUserNotification: UserNotificationTemplateJabber,
EmailUserNotification: UserNotificationTemplateEmail,
VCSUserNotification: {
Body: DefaultWorkflowNodeRunReport,
},
Expand Down
2 changes: 1 addition & 1 deletion ui/src/app/model/workflow.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -687,7 +687,7 @@ export class WorkflowPull {
environments: Array<string>;
}

export const notificationTypes = ['jabber', 'email', 'vcs'];
export const notificationTypes = ['email', 'vcs'];
export const notificationOnSuccess = ['always', 'change', 'never'];
export const notificationOnFailure = ['always', 'change', 'never'];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
[readonly]="true">
</div>
</div>
<ng-container *ngIf="notification.type === 'jabber' || notification.type === 'email'">
<ng-container *ngIf="notification.type === 'email'">
<div class="three fields">
<div class="six wide field">
<label>{{ 'workflow_notification_on_success' | translate}}</label>
Expand Down Expand Up @@ -64,8 +64,6 @@
</div>
<div class="three fields">
<div class="eight wide field">
<label
*ngIf="notification.type === 'jabber'">{{ 'workflow_notification_jabber_user' | translate}}</label>
<label
*ngIf="notification.type === 'email'">{{ 'workflow_notification_email_user' | translate}}</label>
<input type="text" name="users" [(ngModel)]="selectedUsers" [readonly]="readOnly">
Expand Down
1 change: 0 additions & 1 deletion ui/src/assets/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -855,7 +855,6 @@
"workflow_notification_body": "Message",
"workflow_notification_to_group": "Send to group",
"workflow_notification_to_initiator": "Send to initiator",
"workflow_notification_jabber_user": "Jabber users",
"workflow_notification_email_user": "Mails",
"workflow_notification_form": "Add a notification",
"workflow_notification_copy": "Copy",
Expand Down

0 comments on commit 3016fac

Please sign in to comment.