Skip to content

Commit

Permalink
fix: navigation when renaming workflow + user notifications (#5106)
Browse files Browse the repository at this point in the history
  • Loading branch information
sguiheux authored Apr 7, 2020
1 parent add4d15 commit 76a9939
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 15 deletions.
10 changes: 5 additions & 5 deletions engine/api/notification/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func Init(uiurl string) {
}

// GetUserWorkflowEvents return events to send for the given workflow run
func GetUserWorkflowEvents(ctx context.Context, db gorp.SqlExecutor, store cache.Store, w sdk.Workflow, previousWR *sdk.WorkflowNodeRun, nr sdk.WorkflowNodeRun) []sdk.EventNotif {
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 {
events := []sdk.EventNotif{}

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

for _, notif := range w.Notifications {
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, w.ProjectID, sdk.PermissionRead)
u, err := projectPermissionUserIDs(ctx, db, store, projectID, sdk.PermissionRead)
if err != nil {
log.Error(ctx, "notification[Jabber]. error while loading permission: %v", err)
break
Expand Down Expand Up @@ -85,7 +85,7 @@ func GetUserWorkflowEvents(ctx context.Context, db gorp.SqlExecutor, store cache
jn := &notif.Settings
//Get recipents from groups
if jn.SendToGroups != nil && *jn.SendToGroups {
u, err := projectPermissionUserIDs(ctx, db, store, w.ProjectID, sdk.PermissionRead)
u, err := projectPermissionUserIDs(ctx, db, store, projectID, sdk.PermissionRead)
if err != nil {
log.Error(ctx, "notification[Email].GetUserWorkflowEvents> error while loading permission: %v", err)
return nil
Expand Down
8 changes: 7 additions & 1 deletion engine/api/workflow_event.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,13 @@ func WorkflowSendEvent(ctx context.Context, db gorp.SqlExecutor, store cache.Sto
continue
}

event.PublishWorkflowNodeRun(ctx, *nr, wr.Workflow, notification.GetUserWorkflowEvents(ctx, db, store, wr.Workflow, &previousNodeRun, *nr))
workDB, err := workflow.LoadWorkflowFromWorkflowRunID(db, wr.ID)
if err != nil {
log.Warning(ctx, "WorkflowSendEvent> Unable to load workflow for event: %v", err)
continue
}
eventsNotif := notification.GetUserWorkflowEvents(ctx, db, store, wr.Workflow.ProjectID, wr.Workflow.ProjectKey, workDB.Name, wr.Workflow.Notifications, &previousNodeRun, *nr)
event.PublishWorkflowNodeRun(ctx, *nr, wr.Workflow, eventsNotif)
e := &workflow.VCSEventMessenger{}
if err := e.SendVCSEvent(ctx, db, store, proj, *wr, wnr); err != nil {
log.Warning(ctx, "WorkflowSendEvent> Cannot send vcs notification")
Expand Down
11 changes: 10 additions & 1 deletion engine/api/workflow_queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -692,8 +692,17 @@ func (api *API) postWorkflowJobStepStatusHandler() service.Handler {
log.Warning(ctx, "postWorkflowJobStepStatusHandler> Unable to load workflow for event: %v", err)
return nil
}

wr, err := workflow.LoadRunByID(api.mustDB(), nodeRun.WorkflowRunID, workflow.LoadRunOptions{
DisableDetailledNodeRun: true,
})
if err != nil {
log.Warning(ctx, "postWorkflowJobStepStatusHandler> Unable to load workflow run for event: %v", err)
return nil
}
nodeRun.Translate(r.Header.Get("Accept-Language"))
event.PublishWorkflowNodeRun(context.Background(), nodeRun, work, notification.GetUserWorkflowEvents(ctx, api.mustDB(), api.Cache, work, nil, nodeRun))
eventsNotifs := notification.GetUserWorkflowEvents(ctx, api.mustDB(), api.Cache, wr.Workflow.ProjectID, wr.Workflow.ProjectKey, work.Name, wr.Workflow.Notifications, nil, nodeRun)
event.PublishWorkflowNodeRun(context.Background(), nodeRun, wr.Workflow, eventsNotifs)
return nil
}
}
Expand Down
6 changes: 3 additions & 3 deletions engine/api/workflow_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const (
defaultLimit = 10
)

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

Expand Down Expand Up @@ -148,7 +148,7 @@ func (api *API) getWorkflowAllRunsHandler() service.Handler {
route := api.Router.GetRoute("GET", api.getWorkflowAllRunsHandler, map[string]string{
"permProjectKey": key,
})
return api.searchWorkflowRun(ctx, w, r, vars, route, key, name)
return api.searchWorkflowRun(w, r, route, key, name)
}
}

Expand All @@ -161,7 +161,7 @@ func (api *API) getWorkflowRunsHandler() service.Handler {
"key": key,
"workflowName": name,
})
return api.searchWorkflowRun(ctx, w, r, vars, route, key, name)
return api.searchWorkflowRun(w, r, route, key, name)
}
}

Expand Down
10 changes: 5 additions & 5 deletions ui/src/app/views/workflow/run/workflow.run.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export class WorkflowRunComponent implements OnInit {
private _cd: ChangeDetectorRef
) {
this.project = this._store.selectSnapshot(ProjectState.projectSnapshot);
this.workflowName = this._activatedRoute.snapshot.parent.params['workflowName'];
this.workflowName = this._store.selectSnapshot(WorkflowState.workflowSnapshot).name;
this._store.dispatch(new ChangeToRunView({}));

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

if (wr && this.workflowRunData && this.workflowRunData['id'] === wr.id && this.workflowRunData['status'] === wr.status) {
return;
return;
}

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

// If workflow run change, refresh workflow
if (wr && this.workflowRunData['id'] !== wr.id) {
this.workflowRunData['workflow'] = wr.workflow;
this.workflowName = wr.workflow.name;
this.workflowRunData['workflow'] = wr.workflow;
this.workflowName = this._store.selectSnapshot(WorkflowState.workflowSnapshot).name;
}

if (wr && this.workflowRunData['id'] && this.workflowRunData['id'] === wr.id
Expand All @@ -101,7 +101,7 @@ export class WorkflowRunComponent implements OnInit {
if (wr && wr.infos && wr.infos.length > 0 && (
(!this.workflowRunData['infos']) ||
(this.workflowRunData['infos'] && this.workflowRunData['infos'].length === wr.infos.length)
)) {
)) {
this.displayError = wr.infos.some((info) => info.type === 'Error');
this.warnings = wr.infos.filter(i => i.type === 'Warning');
}
Expand Down

0 comments on commit 76a9939

Please sign in to comment.