Skip to content

Commit 76a9939

Browse files
authored
fix: navigation when renaming workflow + user notifications (#5106)
1 parent add4d15 commit 76a9939

File tree

5 files changed

+30
-15
lines changed

5 files changed

+30
-15
lines changed

engine/api/notification/user.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ func Init(uiurl string) {
2424
}
2525

2626
// GetUserWorkflowEvents return events to send for the given workflow run
27-
func GetUserWorkflowEvents(ctx context.Context, db gorp.SqlExecutor, store cache.Store, w sdk.Workflow, previousWR *sdk.WorkflowNodeRun, nr sdk.WorkflowNodeRun) []sdk.EventNotif {
27+
func GetUserWorkflowEvents(ctx context.Context, db gorp.SqlExecutor, store cache.Store, projectID int64, projectKey, workflowName string, notifs []sdk.WorkflowNotification, previousWR *sdk.WorkflowNodeRun, nr sdk.WorkflowNodeRun) []sdk.EventNotif {
2828
events := []sdk.EventNotif{}
2929

3030
//Compute notification
@@ -33,7 +33,7 @@ func GetUserWorkflowEvents(ctx context.Context, db gorp.SqlExecutor, store cache
3333
params[p.Name] = p.Value
3434
}
3535
//Set PipelineBuild UI URL
36-
params["cds.buildURL"] = fmt.Sprintf("%s/project/%s/workflow/%s/run/%d", uiURL, w.ProjectKey, w.Name, nr.Number)
36+
params["cds.buildURL"] = fmt.Sprintf("%s/project/%s/workflow/%s/run/%d", uiURL, projectKey, workflowName, nr.Number)
3737
if p, ok := params["cds.triggered_by.email"]; ok {
3838
params["cds.author.email"] = p
3939
} else if p, ok := params["git.author.email"]; ok {
@@ -46,14 +46,14 @@ func GetUserWorkflowEvents(ctx context.Context, db gorp.SqlExecutor, store cache
4646
}
4747
params["cds.status"] = nr.Status
4848

49-
for _, notif := range w.Notifications {
49+
for _, notif := range notifs {
5050
if ShouldSendUserWorkflowNotification(ctx, notif, nr, previousWR) {
5151
switch notif.Type {
5252
case sdk.JabberUserNotification:
5353
jn := &notif.Settings
5454
//Get recipents from groups
5555
if jn.SendToGroups != nil && *jn.SendToGroups {
56-
u, err := projectPermissionUserIDs(ctx, db, store, w.ProjectID, sdk.PermissionRead)
56+
u, err := projectPermissionUserIDs(ctx, db, store, projectID, sdk.PermissionRead)
5757
if err != nil {
5858
log.Error(ctx, "notification[Jabber]. error while loading permission: %v", err)
5959
break
@@ -85,7 +85,7 @@ func GetUserWorkflowEvents(ctx context.Context, db gorp.SqlExecutor, store cache
8585
jn := &notif.Settings
8686
//Get recipents from groups
8787
if jn.SendToGroups != nil && *jn.SendToGroups {
88-
u, err := projectPermissionUserIDs(ctx, db, store, w.ProjectID, sdk.PermissionRead)
88+
u, err := projectPermissionUserIDs(ctx, db, store, projectID, sdk.PermissionRead)
8989
if err != nil {
9090
log.Error(ctx, "notification[Email].GetUserWorkflowEvents> error while loading permission: %v", err)
9191
return nil

engine/api/workflow_event.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,13 @@ func WorkflowSendEvent(ctx context.Context, db gorp.SqlExecutor, store cache.Sto
5050
continue
5151
}
5252

53-
event.PublishWorkflowNodeRun(ctx, *nr, wr.Workflow, notification.GetUserWorkflowEvents(ctx, db, store, wr.Workflow, &previousNodeRun, *nr))
53+
workDB, err := workflow.LoadWorkflowFromWorkflowRunID(db, wr.ID)
54+
if err != nil {
55+
log.Warning(ctx, "WorkflowSendEvent> Unable to load workflow for event: %v", err)
56+
continue
57+
}
58+
eventsNotif := notification.GetUserWorkflowEvents(ctx, db, store, wr.Workflow.ProjectID, wr.Workflow.ProjectKey, workDB.Name, wr.Workflow.Notifications, &previousNodeRun, *nr)
59+
event.PublishWorkflowNodeRun(ctx, *nr, wr.Workflow, eventsNotif)
5460
e := &workflow.VCSEventMessenger{}
5561
if err := e.SendVCSEvent(ctx, db, store, proj, *wr, wnr); err != nil {
5662
log.Warning(ctx, "WorkflowSendEvent> Cannot send vcs notification")

engine/api/workflow_queue.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -692,8 +692,17 @@ func (api *API) postWorkflowJobStepStatusHandler() service.Handler {
692692
log.Warning(ctx, "postWorkflowJobStepStatusHandler> Unable to load workflow for event: %v", err)
693693
return nil
694694
}
695+
696+
wr, err := workflow.LoadRunByID(api.mustDB(), nodeRun.WorkflowRunID, workflow.LoadRunOptions{
697+
DisableDetailledNodeRun: true,
698+
})
699+
if err != nil {
700+
log.Warning(ctx, "postWorkflowJobStepStatusHandler> Unable to load workflow run for event: %v", err)
701+
return nil
702+
}
695703
nodeRun.Translate(r.Header.Get("Accept-Language"))
696-
event.PublishWorkflowNodeRun(context.Background(), nodeRun, work, notification.GetUserWorkflowEvents(ctx, api.mustDB(), api.Cache, work, nil, nodeRun))
704+
eventsNotifs := notification.GetUserWorkflowEvents(ctx, api.mustDB(), api.Cache, wr.Workflow.ProjectID, wr.Workflow.ProjectKey, work.Name, wr.Workflow.Notifications, nil, nodeRun)
705+
event.PublishWorkflowNodeRun(context.Background(), nodeRun, wr.Workflow, eventsNotifs)
697706
return nil
698707
}
699708
}

engine/api/workflow_run.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ const (
3434
defaultLimit = 10
3535
)
3636

37-
func (api *API) searchWorkflowRun(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string, route, key, name string) error {
37+
func (api *API) searchWorkflowRun(w http.ResponseWriter, r *http.Request, route, key, name string) error {
3838
// About pagination: [FR] http://blog.octo.com/designer-une-api-rest/#pagination
3939
var limit, offset int
4040

@@ -148,7 +148,7 @@ func (api *API) getWorkflowAllRunsHandler() service.Handler {
148148
route := api.Router.GetRoute("GET", api.getWorkflowAllRunsHandler, map[string]string{
149149
"permProjectKey": key,
150150
})
151-
return api.searchWorkflowRun(ctx, w, r, vars, route, key, name)
151+
return api.searchWorkflowRun(w, r, route, key, name)
152152
}
153153
}
154154

@@ -161,7 +161,7 @@ func (api *API) getWorkflowRunsHandler() service.Handler {
161161
"key": key,
162162
"workflowName": name,
163163
})
164-
return api.searchWorkflowRun(ctx, w, r, vars, route, key, name)
164+
return api.searchWorkflowRun(w, r, route, key, name)
165165
}
166166
}
167167

ui/src/app/views/workflow/run/workflow.run.component.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ export class WorkflowRunComponent implements OnInit {
5858
private _cd: ChangeDetectorRef
5959
) {
6060
this.project = this._store.selectSnapshot(ProjectState.projectSnapshot);
61-
this.workflowName = this._activatedRoute.snapshot.parent.params['workflowName'];
61+
this.workflowName = this._store.selectSnapshot(WorkflowState.workflowSnapshot).name;
6262
this._store.dispatch(new ChangeToRunView({}));
6363

6464
this.paramsSub = this._activatedRoute.params.subscribe(p => {
@@ -80,7 +80,7 @@ export class WorkflowRunComponent implements OnInit {
8080
}
8181

8282
if (wr && this.workflowRunData && this.workflowRunData['id'] === wr.id && this.workflowRunData['status'] === wr.status) {
83-
return;
83+
return;
8484
}
8585

8686
if (!this.workflowRunData) {
@@ -89,8 +89,8 @@ export class WorkflowRunComponent implements OnInit {
8989

9090
// If workflow run change, refresh workflow
9191
if (wr && this.workflowRunData['id'] !== wr.id) {
92-
this.workflowRunData['workflow'] = wr.workflow;
93-
this.workflowName = wr.workflow.name;
92+
this.workflowRunData['workflow'] = wr.workflow;
93+
this.workflowName = this._store.selectSnapshot(WorkflowState.workflowSnapshot).name;
9494
}
9595

9696
if (wr && this.workflowRunData['id'] && this.workflowRunData['id'] === wr.id
@@ -101,7 +101,7 @@ export class WorkflowRunComponent implements OnInit {
101101
if (wr && wr.infos && wr.infos.length > 0 && (
102102
(!this.workflowRunData['infos']) ||
103103
(this.workflowRunData['infos'] && this.workflowRunData['infos'].length === wr.infos.length)
104-
)) {
104+
)) {
105105
this.displayError = wr.infos.some((info) => info.type === 'Error');
106106
this.warnings = wr.infos.filter(i => i.type === 'Warning');
107107
}

0 commit comments

Comments
 (0)