-
-
Notifications
You must be signed in to change notification settings - Fork 515
Fix: Prevent negative item quantities in edit and create modals #1463
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,13 +16,7 @@ | |
| import { Badge } from "@/components/ui/badge"; | ||
| import { Card } from "@/components/ui/card"; | ||
| import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "@/components/ui/tooltip"; | ||
| import { | ||
| Dialog, | ||
| DialogContent, | ||
| DialogFooter, | ||
| DialogHeader, | ||
| DialogTitle, | ||
| } from "@/components/ui/dialog"; | ||
| import { Dialog, DialogContent, DialogFooter, DialogHeader, DialogTitle } from "@/components/ui/dialog"; | ||
| import { useDialog } from "@/components/ui/dialog-provider"; | ||
| import { DialogID } from "~/components/ui/dialog-provider/utils"; | ||
| import FormTextField from "~/components/Form/TextField.vue"; | ||
|
|
@@ -98,7 +92,11 @@ | |
| updateForm.icon = et.icon; | ||
| updateForm.isLocation = et.isLocation; | ||
| updateTemplate.value = et.defaultTemplate | ||
| ? { id: et.defaultTemplate.id, name: et.defaultTemplate.name, description: et.defaultTemplate.description } as EntityTemplateSummary | ||
| ? ({ | ||
| id: et.defaultTemplate.id, | ||
| name: et.defaultTemplate.name, | ||
| description: et.defaultTemplate.description, | ||
| } as EntityTemplateSummary) | ||
| : null; | ||
| openDialog(DialogID.UpdateEntityType); | ||
| } | ||
|
|
@@ -154,13 +152,7 @@ | |
| <DialogTitle>Create Entity Type</DialogTitle> | ||
| </DialogHeader> | ||
| <form class="flex flex-col gap-3" @submit.prevent="create"> | ||
| <FormTextField | ||
| v-model="createForm.name" | ||
| :autofocus="true" | ||
| label="Name" | ||
| :max-length="255" | ||
| :min-length="1" | ||
| /> | ||
| <FormTextField v-model="createForm.name" :autofocus="true" label="Name" :max-length="255" :min-length="1" /> | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use translated labels instead of hardcoded Both changed Suggested change- <FormTextField v-model="createForm.name" :autofocus="true" label="Name" :max-length="255" :min-length="1" />
+ <FormTextField v-model="createForm.name" :autofocus="true" :label="t('common.name')" :max-length="255" :min-length="1" />
...
- <FormTextField v-model="updateForm.name" :autofocus="true" label="Name" :max-length="255" :min-length="1" />
+ <FormTextField v-model="updateForm.name" :autofocus="true" :label="t('common.name')" :max-length="255" :min-length="1" />Security recommendation: keep server-side validation/authorization as the source of truth for entity-type create/update/delete, since UI constraints can be bypassed. As per coding guidelines "Check for hardcoded strings in UI components that should be translatable." Also applies to: 173-173 🤖 Prompt for AI Agents |
||
| <FormCheckbox v-model="createForm.isLocation" label="Is a container / location type" /> | ||
| <TemplateSelector v-model="createTemplate" /> | ||
|
|
||
|
|
@@ -178,13 +170,7 @@ | |
| <DialogTitle>Update Entity Type</DialogTitle> | ||
| </DialogHeader> | ||
| <form class="flex flex-col gap-3" @submit.prevent="update"> | ||
| <FormTextField | ||
| v-model="updateForm.name" | ||
| :autofocus="true" | ||
| label="Name" | ||
| :max-length="255" | ||
| :min-length="1" | ||
| /> | ||
| <FormTextField v-model="updateForm.name" :autofocus="true" label="Name" :max-length="255" :min-length="1" /> | ||
| <FormCheckbox v-model="updateForm.isLocation" label="Is a container / location type" /> | ||
| <TemplateSelector v-model="updateTemplate" /> | ||
|
|
||
|
|
@@ -196,7 +182,7 @@ | |
| </Dialog> | ||
|
|
||
| <!-- Page Content --> | ||
| <div class="flex items-center justify-between mb-4"> | ||
| <div class="mb-4 flex items-center justify-between"> | ||
| <h3 class="text-lg font-medium">Entity Types</h3> | ||
| <Button size="sm" @click="openDialog(DialogID.CreateEntityType)"> | ||
| <MdiPlus class="mr-1 size-4" /> | ||
|
|
@@ -207,7 +193,9 @@ | |
| <div v-if="entityTypes && entityTypes.length > 0" class="space-y-2"> | ||
| <Card v-for="et in entityTypes" :key="et.id" class="p-4"> | ||
| <div class="flex items-center gap-3"> | ||
| <div class="flex size-10 shrink-0 items-center justify-center rounded-full bg-secondary text-secondary-foreground"> | ||
| <div | ||
| class="flex size-10 shrink-0 items-center justify-center rounded-full bg-secondary text-secondary-foreground" | ||
| > | ||
| <MdiMapMarkerOutline v-if="et.isLocation" class="size-5" /> | ||
| <MdiPackageVariantClosed v-else class="size-5" /> | ||
| </div> | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -94,6 +94,11 @@ | |
| return; | ||
| } | ||
|
|
||
| if (item.value.quantity < 0) { | ||
| toast.error(t("items.toast.quantity_cannot_negative")); | ||
| return; | ||
| } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same hop, slightly different burrow — and there's a side-door update path. 🐰🚪 Mirror of the CreateModal feedback, plus one extra:
🛠️ Proposed shared guard + sibling path coverage+ function hasInvalidQuantity(): boolean {
+ return !Number.isFinite(item.value.quantity) || item.value.quantity < 0;
+ }
+
async function saveItem(redirect: boolean) {
if (!item.value.parent?.id && !parent.value?.id) {
toast.error(t("items.toast.failed_save_no_location"));
return;
}
- if (item.value.quantity < 0) {
+ if (hasInvalidQuantity()) {
toast.error(t("items.toast.quantity_cannot_negative"));
return;
} async function syncChildEntityLocations() {
if (!item.value.parent?.id && !parent.value?.id) {
toast.error(t("items.toast.failed_save_no_location"));
return;
}
+
+ if (hasInvalidQuantity()) {
+ toast.error(t("items.toast.quantity_cannot_negative"));
+ return;
+ }🤖 Prompt for AI Agents |
||
|
|
||
| saving.value = true; | ||
|
|
||
| let purchasePrice = 0; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wrong i18n key — toast will display the raw key string instead of a translated message. 🐰🌍
The guard calls
t("components.item.create_modal.toast.quantity_cannot_negative"), but that path doesn't exist infrontend/locales/en.json. The actual key lives underitems.toast.quantity_cannot_negative(seeen.jsonline 620), and the siblingfrontend/pages/item/[id]/index/edit.vue(lines 97-100) and the PR description both use that path. With vue-i18n's default missing-handler the user will see the literal stringcomponents.item.create_modal.toast.quantity_cannot_negativein the toast — in every language. Switch to the existing key.🥕 Proposed fix
if (form.quantity < 0) { - toast.error(t("components.item.create_modal.toast.quantity_cannot_negative")); + toast.error(t("items.toast.quantity_cannot_negative")); return; }🔐 Security recommendation (carried over): this remains a client-side check only. Please confirm the backend handlers behind
api.items.createandapi.templates.createItemrejectquantity < 0(and ideally non-finite values) so a crafted request can't bypass the UI guard.🤖 Prompt for AI Agents