10000 fix(api,ui): audit on pipeline with template is now correct (#4930) · ovh/cds@1141bd7 · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Commit 1141bd7

Browse files
authored
fix(api,ui): audit on pipeline with template is now correct (#4930)
Signed-off-by: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com>
1 parent 41c348e commit 1141bd7

File tree

5 files changed

+34
-10
lines changed

5 files changed

+34
-10
lines changed

engine/api/pipeline/audit.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ const (
4040
AuditUpdateStage = "updateStage"
4141
AuditDeleteStage = "deleteStage"
4242
AuditMoveStage = "moveStage"
43-
AuditUpdatePipeline = "updateStage"
43+
AuditUpdatePipeline = "updatePipeline"
4444
)
4545

4646
// CreateAudit insert current pipeline version on audit table

engine/api/pipeline/pipeline_parser.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,15 @@ func ParseAndImport(ctx context.Context, db gorp.SqlExecutor, cache cache.Store,
5050
}
5151
}(&msgList)
5252

53+
previousPip := pip
54+
if exist {
55+
prevPip, err := LoadPipeline(ctx, db, proj.Key, pip.Name, true)
56+
if err != nil {
57+
return pip, nil, sdk.WrapError(err, "cannot load previous pipeline")
58+
}
59+
previousPip = prevPip
60+
}
61+
5362
var globalError error
5463
if exist && !opts.Force {
5564
return pip, nil, sdk.ErrPipelineAlreadyExists
@@ -63,7 +72,7 @@ func ParseAndImport(ctx context.Context, db gorp.SqlExecutor, cache cache.Store,
6372
done.Wait()
6473

6574
if globalError == nil {
66-
if err := CreateAudit(db, pip, AuditUpdatePipeline, u); err != nil {
75+
if err := CreateAudit(db, previousPip, AuditUpdatePipeline, u); err != nil {
6776
log.Error(ctx, "%v", sdk.WrapError(err, "cannot create audit"))
6877
}
6978
}

ui/src/app/shared/diff/diff.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,10 @@ export function calculateWorkflowTemplateDiff(before: WorkflowTemplate, after: W
5353
})
5454
}
5555

56-
let applicationsLength = Math.max(before ? before.applications.length : 0, after ? after.applications.length : 0);
56+
let applicationsLength = Math.max(
57+
before ? before.applications && before.applications.length : 0,
58+
after ? after.applications && after.applications.length : 0
59+
);
5760
for (let i = 0; i < applicationsLength; i++) {
5861
diffItems.push(
5962
<Item>{
@@ -65,7 +68,10 @@ export function calculateWorkflowTemplateDiff(before: WorkflowTemplate, after: W
6568
})
6669
}
6770

68-
let environmentsLength = Math.max(before ? before.environments.length : 0, after ? after.environments.length : 0);
71+
let environmentsLength = Math.max(
72+
before ? before.environments && before.environments.length : 0,
73+
after ? after.environments && after.environments.length : 0
74+
);
6975
for (let i = 0; i < environmentsLength; i++) {
7076
diffItems.push(
7177
<Item>{

ui/src/app/shared/workflow-template/apply-form/workflow-template.apply-form.html

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@
33
<div class="wide column">
44
<div class="field">
55
<label>{{'workflow_name' | translate}}*</label>
6-
<input class="ui input" type="text" name="workflow_name" [(ngModel)]="parameterName" [disabled]="workflowTemplateInstance">
6+
<input class="ui input" type="text" name="workflow_name" [(ngModel)]="parameterName"
7+
[disabled]="workflowTemplateInstance">
78
</div>
89
<app-workflow-template-param-form [project]="project" [workflowTemplate]="workflowTemplate"
9-
[workflowTemplateInstance]="workflowTemplateInstance" (paramChange)="changeParam($event)"></app-workflow-template-param-form>
10+
[workflowTemplateInstance]="workflowTemplateInstance" (paramChange)="changeParam($event)">
11+
</app-workflow-template-param-form>
1012
<div class="wide field" *ngIf="result">
1113
<div class="ui message">
1214
<ul>
@@ -16,18 +18,22 @@
1618
</div>
1719
<div class="wide field">
1820
<div class="ui wide field">
19-
<app-delete-button *ngIf="workflowTemplateInstance && workflowTemplateInstance.id" class="left floated"
20-
(event)="clickDetach()" [loading]="loading" [title]="'workflow_template_detach'"></app-delete-button>
21+
<app-delete-button *ngIf="workflowTemplateInstance && workflowTemplateInstance.id"
22+
class="left floated" (event)="clickDetach()" [loading]="loading"
23+
[title]="'workflow_template_detach'"></app-delete-button>
2124
<div class="ui checked checkbox" *ngIf="!workflowTemplateInstance && !result">
2225
<input type="checkbox" [ngModel]="detached" [ngModelOptions]="{standalone: true}"
2326
(ngModelChange)="onSelectDetachChange($event)">
2427
<label>{{'workflow_template_apply_detach' | translate}}</label>
2528
</div>
2629
<button class="ui green button right floated" type="button" (click)="applyTemplate()"
30+
*ngIf="workflowTemplateInstance.workflow_template_version !== workflowTemplate.version"
2731
[class.loading]="loading">{{ 'btn_apply' | translate }}</button>
28-
<button class="ui primary button right floated" type="button" (click)="goToWorkflow()" *ngIf="result && !withClose">{{
32+
<button class="ui primary button right floated" type="button" (click)="goToWorkflow()"
33+
*ngIf="result && !withClose">{{
2934
'btn_goto_workflow' | translate}}</button>
30-
<button class="ui secondary button right floated" [disabled]="loading" (click)="clickClose()" *ngIf="withClose">{{
35+
<button class="ui secondary button right floated" [disabled]="loading" (click)="clickClose()"
36+
*ngIf="withClose">{{
3137
'btn_close' | translate }}</button>
3238
</div>
3339
</div>

ui/src/app/views/pipeline/show/audit/pipeline.audit.component.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,9 @@ export class PipelineAuditComponent implements OnInit {
123123
case 'updateStage':
124124
diff = this.getUpdateStageDiff(pathSplitted, pipTo, pipFrom);
125125
break;
126+
case 'updatePipeline':
127+
diff = this.getUpdateJobDiff(path, pathSplitted, pipTo, pipFrom);
128+
break;
126129
case 'deleteStage':
127130
diff = this.getDeleteStageDiff(pathSplitted, pipFrom);
128131
break;

0 commit comments

Comments
 (0)
0