From 6d36577de465998a7485781dd6bc4fb43e846a4a Mon Sep 17 00:00:00 2001 From: Jonathan Foucher <jfoucher@gmail.com> Date: Tue, 20 Sep 2022 11:22:58 +0200 Subject: [PATCH] Prevent deleting or modifying previous completed evaluations. Fixes https://app.asana.com/0/1202404842967175/1202993772128376 --- database/seeders/OrganizationSeeder.php | 2 +- resources/js/components/Evaluations/List.vue | 24 +++++++++++--------- tests/Feature/EvaluationsControllerTest.php | 5 ++-- 3 files changed, 16 insertions(+), 15 deletions(-) diff --git a/database/seeders/OrganizationSeeder.php b/database/seeders/OrganizationSeeder.php index f7125f65..2746eab2 100644 --- a/database/seeders/OrganizationSeeder.php +++ b/database/seeders/OrganizationSeeder.php @@ -83,7 +83,7 @@ public function run() }); } - private function setEvaluationsData (Organization $org) + private function setEvaluationsData(Organization $org) { foreach ($org->evaluations as $eval) { if ($eval->current_step < Evaluation::STEP_RESULTS) { diff --git a/resources/js/components/Evaluations/List.vue b/resources/js/components/Evaluations/List.vue index be79e734..3e07e611 100644 --- a/resources/js/components/Evaluations/List.vue +++ b/resources/js/components/Evaluations/List.vue @@ -131,7 +131,7 @@ class="btn btn-light btn-xs" ><i class="fas fa-chart-bar" /> Résultats</router-link> <button - v-if="!isUser() && !previousCompletedEvaluation" + v-if="!isUser() && !nextCompletedEvaluation(props.row)" class="btn btn-light btn-xs" @click.prevent="editRow(props.row)" ><i class="fas fa-pen" /> Modifier</button> @@ -146,7 +146,7 @@ <i class="fas fa-clipboard-list" /> Rapport </a> <button - v-if="!isUser() && !previousCompletedEvaluation" + v-if="!isUser() && !nextCompletedEvaluation(props.row)" class="btn btn-light btn-xs" @click="deleteRow(props.row)" > @@ -297,15 +297,7 @@ export default { user () { return this.$store.state.user }, - previousCompletedEvaluation (evaluation) { - return this.$store.state.evaluations.all.find(e => { - return e.organization_id === evaluation.organization_id - && e.status === 2 - && e.updated_at < evaluation.updated_at - && e.reference === this.$reference - && evaluation.reference === this.$reference - }) - }, + evaluations () { return this.$store.state.evaluations.all .map(u => { @@ -357,6 +349,16 @@ export default { }, }, methods: { + nextCompletedEvaluation (evaluation) { + return this.$store.state.evaluations.all.find(e => { + return e.organization_id === evaluation.organization_id + && e.status === 2 + && new Date(e.updated_at) > new Date(evaluation.updated_at) + && e.reference === this.$reference + && evaluation.reference === this.$reference + && e.id !== evaluation.id + }) + }, resetFilters () { try { this.dateRange.startDate = null diff --git a/tests/Feature/EvaluationsControllerTest.php b/tests/Feature/EvaluationsControllerTest.php index 92522f79..a8924e21 100644 --- a/tests/Feature/EvaluationsControllerTest.php +++ b/tests/Feature/EvaluationsControllerTest.php @@ -525,8 +525,7 @@ public function testAdminCannotUpdateEvaluationIfDifferentReference() public function testExecutionMaturityLevelWithOneCompletedEvaluationInOrganizationShouldBeZero() { - $orgWithSingleEvaluation = Organization::whereHas('evaluations', function($q) { - + $orgWithSingleEvaluation = Organization::whereHas('evaluations', function ($q) { }, '=', 1)->first(); $evals = Evaluation::where('status', Evaluation::STATUS_DONE) @@ -544,7 +543,7 @@ public function testExecutionMaturityLevelWithOneCompletedEvaluationInOrganizati $eval = $evals->first(); $execLevel = $eval->maturityLevels->first(function (EvaluationMaturityAnswer $ml) { - return $ml->question->title === 'Exécution'; + return 'Exécution' === $ml->question->title; }); $this->assertEquals(0, $execLevel->answer->level); -- GitLab