Skip to content

Commit

Permalink
Correct file validation temporarily removing changes that enforce man…
Browse files Browse the repository at this point in the history
…datory file uploads

It seems that enforcing file uploads is not working properly and is impacting other validators.
For this reason we decide to reimplement this on a later stage.
  • Loading branch information
evilaliv3 committed Nov 26, 2024
1 parent 4e9ff08 commit ee4106b
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -281,9 +281,9 @@ export class SubmissionComponent implements OnInit {
});
}

const required_status = this.fieldUtilitiesService.onAnswersUpdate(this);
this.fieldUtilitiesService.onAnswersUpdate(this);

if (!this.runValidation() || required_status) {
if (!this.runValidation()) {
this.utilsService.scrollToTop();
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ export class WhistleblowerSubmissionService {
return;
}

scope.fieldUtilitiesService.onAnswersUpdate(scope);

if (!scope.runValidation()) {
scope.utilsService.scrollToTop();
return;
Expand Down
23 changes: 7 additions & 16 deletions client/app/src/shared/services/field-utilities.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,8 @@ export class FieldUtilitiesService {
}
}

updateAnswers(scope: any, parent: any, list: any, answers: any): boolean {
let ret=false, entry, option, i, j;
updateAnswers(scope: any, parent: any, list: any, answers: any) {
let entry, option, i, j;

list.forEach((field: any) => {
if (this.isFieldTriggered(parent, field, scope.answers, scope.score)) {
Expand All @@ -164,10 +164,10 @@ export class FieldUtilitiesService {

if (field.id in answers) {
for (i = 0; i < answers[field.id].length; i++) {
ret = ret || this.updateAnswers(scope, field, field.children, answers[field.id][i]);
this.updateAnswers(scope, field, field.children, answers[field.id][i]);
}
} else {
ret = ret || this.updateAnswers(scope, field, field.children, {});
this.updateAnswers(scope, field, field.children, {});
}

if (!field.enabled) {
Expand Down Expand Up @@ -205,8 +205,6 @@ export class FieldUtilitiesService {
entry.required_status = field.required && !entry["value"];
}

ret = ret || entry.required_status;

if (["checkbox", "selectbox", "multichoice"].indexOf(field.type) > -1) {
for (j = 0; j < field.options.length; j++) {
option = field.options[j];
Expand Down Expand Up @@ -234,38 +232,31 @@ export class FieldUtilitiesService {
}
}
});

return ret;
}

onAnswersUpdate(scope: any): boolean {
onAnswersUpdate(scope: any) {
scope.block_submission = false;
scope.score = 0;
scope.points_to_sum = 0;
scope.points_to_mul = 1;

if (!scope.questionnaire) {
return true;
return;
}

if (scope.submissionService) {
scope.submissionService.override_receivers = [];
}

let ret = false, recursive_ret = false;

scope.questionnaire.steps.forEach((step: any) => {
step.enabled = this.isFieldTriggered(null, step, scope.answers, scope.score);
recursive_ret = this.updateAnswers(scope, step, step.children, scope.answers);
ret = ret || recursive_ret;
this.updateAnswers(scope, step, step.children, scope.answers);
});

if (scope.context) {
scope.submissionService.submission.score = scope.score;
scope.submissionService.blocked = scope.block_submission;
}

return ret;
}


Expand Down

0 comments on commit ee4106b

Please sign in to comment.