This commit is contained in:
j3d1 2026-08-26 20:40:23 +02:00
parent 35be834799
commit 8de6ae8d8b
11 changed files with 168 additions and 150 deletions

View file

@ -46,7 +46,7 @@
Edit
</button>
<button type="submit" class="btn btn-danger"
@click="deleteInventoryItem(item).then(() => $router.push('/inventory'))">
@click="deleteInventoryItem(item).then(() => $router.push(ownerOverviewRoute(item)))">
<b-icon-trash></b-icon-trash>
Delete
</button>
@ -68,7 +68,7 @@ import * as BIcons from "bootstrap-icons-vue";
import BaseLayout from "@/components/BaseLayout.vue";
import {mapActions, mapGetters, mapState} from "vuex";
import AuthenticatedImage from "@/components/AuthenticatedImage.vue";
import {decodeHandleFromUrl} from "@/router";
import {decodeHandleFromUrl, ownerOverviewRoute} from "@/router";
export default {
name: "InventoryDetail",
@ -94,23 +94,30 @@ export default {
},
computed: {
...mapGetters(["getNameFromHandle", "groupIdByHandle"]),
...mapState(["user"]),
...mapState(["user", "groupMemberships"]),
decodedHandle() {
return decodeHandleFromUrl(this.handle)
},
// Am I a member of this group, hosted here (groupIdByHandle, from idmap) or elsewhere
// (groupMemberships - see GroupMembership/docs/design-in-progress/groups-mvp.md)? Either
// way the backend actually hosting the group is what authorizes the write - this is just
// enough of a client-side hint to show/hide the buttons for it.
isGroupMember() {
return this.decodedHandle in this.groupIdByHandle
|| this.groupMemberships.some(m => m.handle === this.decodedHandle)
},
// Edit/Delete require actual authorization (own item or member group), not just view
// access - get_shared_item's friends_or_self() lets a friend view but never act.
canEdit() {
return this.decodedHandle === this.user || this.decodedHandle in this.groupIdByHandle
return this.decodedHandle === this.user || this.isGroupMember
},
// Printed labels only support a personal owner handle so far (see label.js's
// splitUserHandle); group items get no print link until that's supported too.
canPrint() {
return this.decodedHandle === this.user
return this.decodedHandle === this.user || this.isGroupMember
}
},
methods: {
...mapActions(["fetchItemByHandle", "deleteInventoryItem"]),
ownerOverviewRoute,
...mapActions(["fetchItemByHandle", "deleteInventoryItem", "fetchGroupMemberships"]),
async loadItem() {
this.item = await this.fetchItemByHandle({handle: this.decodedHandle, id: this.id}) || {}
}
@ -121,6 +128,9 @@ export default {
},
mounted() {
this.loadItem()
if (this.decodedHandle.startsWith('#')) {
this.fetchGroupMemberships()
}
}
}
</script>