Skip to content

Commit

Permalink
fix(api,ui): audit on pipeline with template is now correct (#4930)
Browse files Browse the repository at this point in the history
Signed-off-by: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com>
  • Loading branch information
bnjjj committed Feb 4, 2020
1 parent 41c348e commit 1141bd7
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 10 deletions.
2 changes: 1 addition & 1 deletion engine/api/pipeline/audit.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const (
AuditUpdateStage = "updateStage"
AuditDeleteStage = "deleteStage"
AuditMoveStage = "moveStage"
AuditUpdatePipeline = "updateStage"
AuditUpdatePipeline = "updatePipeline"
)

// CreateAudit insert current pipeline version on audit table
Expand Down
11 changes: 10 additions & 1 deletion engine/api/pipeline/pipeline_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,15 @@ func ParseAndImport(ctx context.Context, db gorp.SqlExecutor, cache cache.Store,
}
}(&msgList)

previousPip := pip
if exist {
prevPip, err := LoadPipeline(ctx, db, proj.Key, pip.Name, true)
if err != nil {
return pip, nil, sdk.WrapError(err, "cannot load previous pipeline")
}
previousPip = prevPip
}

var globalError error
if exist && !opts.Force {
return pip, nil, sdk.ErrPipelineAlreadyExists
Expand All @@ -63,7 +72,7 @@ func ParseAndImport(ctx context.Context, db gorp.SqlExecutor, cache cache.Store,
done.Wait()

if globalError == nil {
if err := CreateAudit(db, pip, AuditUpdatePipeline, u); err != nil {
if err := CreateAudit(db, previousPip, AuditUpdatePipeline, u); err != nil {
log.Error(ctx, "%v", sdk.WrapError(err, "cannot create audit"))
}
}
Expand Down
10 changes: 8 additions & 2 deletions ui/src/app/shared/diff/diff.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,10 @@ export function calculateWorkflowTemplateDiff(before: WorkflowTemplate, after: W
})
}

let applicationsLength = Math.max(before ? before.applications.length : 0, after ? after.applications.length : 0);
let applicationsLength = Math.max(
before ? before.applications && before.applications.length : 0,
after ? after.applications && after.applications.length : 0
);
for (let i = 0; i < applicationsLength; i++) {
diffItems.push(
<Item>{
Expand All @@ -65,7 +68,10 @@ export function calculateWorkflowTemplateDiff(before: WorkflowTemplate, after: W
})
}

let environmentsLength = Math.max(before ? before.environments.length : 0, after ? after.environments.length : 0);
let environmentsLength = Math.max(
before ? before.environments && before.environments.length : 0,
after ? after.environments && after.environments.length : 0
);
for (let i = 0; i < environmentsLength; i++) {
diffItems.push(
<Item>{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
<div class="wide column">
<div class="field">
<label>{{'workflow_name' | translate}}*</label>
<input class="ui input" type="text" name="workflow_name" [(ngModel)]="parameterName" [disabled]="workflowTemplateInstance">
<input class="ui input" type="text" name="workflow_name" [(ngModel)]="parameterName"
[disabled]="workflowTemplateInstance">
</div>
<app-workflow-template-param-form [project]="project" [workflowTemplate]="workflowTemplate"
[workflowTemplateInstance]="workflowTemplateInstance" (paramChange)="changeParam($event)"></app-workflow-template-param-form>
[workflowTemplateInstance]="workflowTemplateInstance" (paramChange)="changeParam($event)">
</app-workflow-template-param-form>
<div class="wide field" *ngIf="result">
<div class="ui message">
<ul>
Expand All @@ -16,18 +18,22 @@
</div>
<div class="wide field">
<div class="ui wide field">
<app-delete-button *ngIf="workflowTemplateInstance && workflowTemplateInstance.id" class="left floated"
(event)="clickDetach()" [loading]="loading" [title]="'workflow_template_detach'"></app-delete-button>
<app-delete-button *ngIf="workflowTemplateInstance && workflowTemplateInstance.id"
class="left floated" (event)="clickDetach()" [loading]="loading"
[title]="'workflow_template_detach'"></app-delete-button>
<div class="ui checked checkbox" *ngIf="!workflowTemplateInstance && !result">
<input type="checkbox" [ngModel]="detached" [ngModelOptions]="{standalone: true}"
(ngModelChange)="onSelectDetachChange($event)">
<label>{{'workflow_template_apply_detach' | translate}}</label>
</div>
<button class="ui green button right floated" type="button" (click)="applyTemplate()"
*ngIf="workflowTemplateInstance.workflow_template_version !== workflowTemplate.version"
[class.loading]="loading">{{ 'btn_apply' | translate }}</button>
<button class="ui primary button right floated" type="button" (click)="goToWorkflow()" *ngIf="result && !withClose">{{
<button class="ui primary button right floated" type="button" (click)="goToWorkflow()"
*ngIf="result && !withClose">{{
'btn_goto_workflow' | translate}}</button>
<button class="ui secondary button right floated" [disabled]="loading" (click)="clickClose()" *ngIf="withClose">{{
<button class="ui secondary button right floated" [disabled]="loading" (click)="clickClose()"
*ngIf="withClose">{{
'btn_close' | translate }}</button>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@ export class PipelineAuditComponent implements OnInit {
case 'updateStage':
diff = this.getUpdateStageDiff(pathSplitted, pipTo, pipFrom);
break;
case 'updatePipeline':
diff = this.getUpdateJobDiff(path, pathSplitted, pipTo, pipFrom);
break;
case 'deleteStage':
diff = this.getDeleteStageDiff(pathSplitted, pipFrom);
break;
Expand Down

0 comments on commit 1141bd7

Please sign in to comment.