Skip to content

Commit 4f5d61e

Browse files
committed
Allow to edit review
1 parent ae65e76 commit 4f5d61e

File tree

3 files changed

+24
-20
lines changed

3 files changed

+24
-20
lines changed

src/components/identificationTasks/IdentificationTaskGridItem.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
<figcaption v-if="task.result" class="absolute bottom-0 left-0 p-2">
2424
<IdentificationTaskResultTag class="bg-white/80!" :result="task.result" />
2525
</figcaption>
26-
<figcaption v-else-if="$can('add', 'Review') && !task.review"
26+
<figcaption v-else-if="$can('add', subject('Review', { 'identification_task': task }))"
2727
class="absolute bottom-0 left-0 p-2 flex gap-2 w-full bg-linear-to-t from-black to-transparent">
2828
<TaxonTreeSelect class="flex-1" placeholder="Select taxon"
2929
@on-change="(taxon) => taxon ? submitReview(taxon) : null" />
@@ -35,6 +35,7 @@
3535

3636
<script setup lang="ts">
3737
import { ref } from 'vue';
38+
import { subject } from '@casl/ability';
3839
import { useToast } from 'primevue/usetoast';
3940
4041
import type { IdentificationTask, Taxon, IdentificationTasksApiReviewCreateRequest } from 'mosquito-alert';

src/services/ability.ts

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -69,29 +69,27 @@ export default function defineAbilityFor(userPermission: UserPermission | null)
6969
}
7070

7171
function grantReviewPermissions(perms: ReviewPermission, countryId?: number) {
72+
const countryCondition = buildCountryCondition(countryId)
73+
const remappedCountryCondition = countryCondition
74+
? Object.fromEntries(
75+
Object.entries(countryCondition).map(([key, value]) => [
76+
`identification_task.${key}`,
77+
value,
78+
]),
79+
)
80+
: {}
7281
if (perms.add) {
73-
const countryCondition = buildCountryCondition(countryId)
74-
const remappedCountryCondition = countryCondition
75-
? Object.fromEntries(
76-
Object.entries(countryCondition).map(([key, value]) => [
77-
`identification_task.${key}`,
78-
value,
79-
]),
80-
)
81-
: {}
8282
can('add', 'Review', {
83-
'identification_task.status': {
84-
$in: [
85-
IdentificationTaskStatus.Conflict,
86-
IdentificationTaskStatus.Done,
87-
IdentificationTaskStatus.Review,
88-
],
89-
},
9083
'identification_task.review': null,
9184
...remappedCountryCondition,
9285
})
9386
}
94-
if (perms.change) can('change', 'Review', buildCountryCondition(countryId))
87+
if (perms.change) {
88+
can('change', 'Review', {
89+
'identification_task.review': { $ne: null },
90+
...remappedCountryCondition,
91+
})
92+
}
9593
if (perms.view) can('view', 'Review', buildCountryCondition(countryId))
9694
if (perms.delete) can('delete', 'Review', buildCountryCondition(countryId))
9795
}

src/views/identification_task/DetailView.vue

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,11 @@
1717
<span>Identification task: </span>
1818
<span class="text-surface-900 dark:text-surface-0">{{ identificationTask?.observation.uuid }}</span>
1919
</div>
20-
<div class="ml-auto">
20+
<div class="flex ml-auto gap-2 items-center">
21+
<Button
22+
v-if="$can(identificationTask?.review == null ? 'add' : 'change', subject('Review', { 'identification_task': identificationTask }))"
23+
icon="pi pi-pencil" size='small' severity="secondary" outlined @click="isReviewing = true"
24+
:disabled="isReviewing" v-tooltip.top="'Edit review'" />
2125
<IdentificationTaskStatusTag v-if="identificationTask" :status="identificationTask?.status" />
2226
</div>
2327
</div>
@@ -164,7 +168,8 @@
164168
</div>
165169
</div>
166170

167-
<ReviewDialog v-if="$can('add', subject('Review', { 'identification_task': identificationTask }))"
171+
<ReviewDialog
172+
v-if="$can('add', subject('Review', { 'identification_task': identificationTask })) && identificationTask?.result"
168173
:identification-task="identificationTask" :visible="!isReviewing" :loading="isSubmittingReview || loading"
169174
@agree="submitReview(CreateAgreeReviewRequestAction.Agree)" @disagree="isReviewing = true" />
170175

0 commit comments

Comments
 (0)