Files
bbs/bbs/api/queries/users.py
T
leanderandClaude Opus 5.5 7ab2a0f1f2 feat(inventory): add and edit products without the admin
The inventory page gets a "Ny vare" link and a "Rediger" link per product,
leading to a form for name, prices, volume, alcohol, description and whether
the product is for sale. Stock still changes only through inventory
transactions and sales, and the image through the admin.

Saving needs the same access as the Django admin: staff, plus the add or
change product permission (superusers have both). The server checks this on
every save and validates with the model's rules. Logged out visitors are
sent to log in and back to the form.

New in the API: createProduct and updateProduct mutations, a product query,
and a me query so the frontend knows who is logged in.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-05 03:44:12 +01:00

30 lines
952 B
Python

import strawberry
from django.contrib.auth.models import User as DjangoUser
from strawberry import ID, Info
from bbs.api.permissions import can_add_products, can_change_products
from bbs.api.types.users import User, Viewer
@strawberry.type
class UsersQueries:
@strawberry.field
def all_users(self) -> list[User]:
return DjangoUser.objects.filter(profile__isnull=False)
@strawberry.field
def user(self, user_id: ID) -> User:
return DjangoUser.objects.get(pk=user_id)
@strawberry.field(description="The logged in user, or null when nobody is logged in")
def me(self, info: Info) -> Viewer | None:
user = info.context.request.user
if not user.is_authenticated:
return None
return Viewer(
id=user.pk,
first_name=user.first_name,
can_add_products=can_add_products(user),
can_change_products=can_change_products(user),
)