Auto-mount defpages: eliminate Python route stubs across all 9 services
Some checks failed
Build and Deploy / build-and-deploy (push) Failing after 16s
Some checks failed
Build and Deploy / build-and-deploy (push) Failing after 16s
Defpages are now declared with absolute paths in .sx files and auto-mounted directly on the Quart app, removing ~850 lines of blueprint mount_pages calls, before_request hooks, and g.* wrapper boilerplate. A new page = one defpage declaration, nothing else. Infrastructure: - async_eval awaits coroutine results from callable dispatch - auto_mount_pages() mounts all registered defpages on the app - g._defpage_ctx pattern passes helper data to layout context Migrated: sx, account, orders, federation, cart, market, events, blog Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -311,6 +311,183 @@ def _markets_oob(ctx: dict, **kw: Any) -> str:
|
||||
return oobs
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Shared hydration helpers
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
def _add_to_defpage_ctx(**kwargs: Any) -> None:
|
||||
"""Add data to g._defpage_ctx for the app-level context_processor."""
|
||||
from quart import g
|
||||
if not hasattr(g, '_defpage_ctx'):
|
||||
g._defpage_ctx = {}
|
||||
g._defpage_ctx.update(kwargs)
|
||||
|
||||
|
||||
async def _ensure_calendar(calendar_slug: str | None) -> None:
|
||||
"""Load calendar into g.calendar if not already present."""
|
||||
from quart import g, abort
|
||||
if hasattr(g, 'calendar'):
|
||||
_add_to_defpage_ctx(calendar=g.calendar)
|
||||
return
|
||||
from bp.calendar.services.calendar_view import (
|
||||
get_calendar_by_post_and_slug, get_calendar_by_slug,
|
||||
)
|
||||
post_data = getattr(g, "post_data", None)
|
||||
if post_data:
|
||||
post_id = (post_data.get("post") or {}).get("id")
|
||||
cal = await get_calendar_by_post_and_slug(g.s, post_id, calendar_slug)
|
||||
else:
|
||||
cal = await get_calendar_by_slug(g.s, calendar_slug)
|
||||
if not cal:
|
||||
abort(404)
|
||||
g.calendar = cal
|
||||
g.calendar_slug = calendar_slug
|
||||
_add_to_defpage_ctx(calendar=cal)
|
||||
|
||||
|
||||
async def _ensure_entry(entry_id: int | None) -> None:
|
||||
"""Load calendar entry into g.entry if not already present."""
|
||||
from quart import g, abort
|
||||
if hasattr(g, 'entry'):
|
||||
_add_to_defpage_ctx(entry=g.entry)
|
||||
return
|
||||
from sqlalchemy import select
|
||||
from models.calendars import CalendarEntry
|
||||
result = await g.s.execute(
|
||||
select(CalendarEntry).where(
|
||||
CalendarEntry.id == entry_id,
|
||||
CalendarEntry.deleted_at.is_(None),
|
||||
)
|
||||
)
|
||||
entry = result.scalar_one_or_none()
|
||||
if entry is None:
|
||||
abort(404)
|
||||
g.entry = entry
|
||||
_add_to_defpage_ctx(entry=entry)
|
||||
|
||||
|
||||
async def _ensure_entry_context(entry_id: int | None) -> None:
|
||||
"""Load full entry context (ticket data, posts) into g.* and _defpage_ctx."""
|
||||
from quart import g
|
||||
from sqlalchemy import select
|
||||
from sqlalchemy.orm import selectinload
|
||||
from models.calendars import CalendarEntry
|
||||
from bp.tickets.services.tickets import (
|
||||
get_available_ticket_count,
|
||||
get_sold_ticket_count,
|
||||
get_user_reserved_count,
|
||||
)
|
||||
from shared.infrastructure.cart_identity import current_cart_identity
|
||||
from bp.calendar_entry.services.post_associations import get_entry_posts
|
||||
|
||||
await _ensure_entry(entry_id)
|
||||
|
||||
# Reload with ticket_types eagerly loaded
|
||||
stmt = (
|
||||
select(CalendarEntry)
|
||||
.where(CalendarEntry.id == entry_id, CalendarEntry.deleted_at.is_(None))
|
||||
.options(selectinload(CalendarEntry.ticket_types))
|
||||
)
|
||||
result = await g.s.execute(stmt)
|
||||
calendar_entry = result.scalar_one_or_none()
|
||||
|
||||
if calendar_entry and getattr(g, "calendar", None):
|
||||
if calendar_entry.calendar_id != g.calendar.id:
|
||||
calendar_entry = None
|
||||
|
||||
if calendar_entry:
|
||||
await g.s.refresh(calendar_entry, ['slot'])
|
||||
g.entry = calendar_entry
|
||||
entry_posts = await get_entry_posts(g.s, calendar_entry.id)
|
||||
ticket_remaining = await get_available_ticket_count(g.s, calendar_entry.id)
|
||||
ticket_sold_count = await get_sold_ticket_count(g.s, calendar_entry.id)
|
||||
ident = current_cart_identity()
|
||||
user_ticket_count = await get_user_reserved_count(
|
||||
g.s, calendar_entry.id,
|
||||
user_id=ident["user_id"],
|
||||
session_id=ident["session_id"],
|
||||
)
|
||||
user_ticket_counts_by_type = {}
|
||||
if calendar_entry.ticket_types:
|
||||
for tt in calendar_entry.ticket_types:
|
||||
if tt.deleted_at is None:
|
||||
user_ticket_counts_by_type[tt.id] = await get_user_reserved_count(
|
||||
g.s, calendar_entry.id,
|
||||
user_id=ident["user_id"],
|
||||
session_id=ident["session_id"],
|
||||
ticket_type_id=tt.id,
|
||||
)
|
||||
_add_to_defpage_ctx(
|
||||
entry=calendar_entry,
|
||||
entry_posts=entry_posts,
|
||||
ticket_remaining=ticket_remaining,
|
||||
ticket_sold_count=ticket_sold_count,
|
||||
user_ticket_count=user_ticket_count,
|
||||
user_ticket_counts_by_type=user_ticket_counts_by_type,
|
||||
)
|
||||
|
||||
|
||||
async def _ensure_day_data(year: int, month: int, day: int) -> None:
|
||||
"""Load day-specific data for layout header functions."""
|
||||
from quart import g, session as qsession
|
||||
if hasattr(g, 'day_date'):
|
||||
return
|
||||
from datetime import date as date_cls, datetime, timezone, timedelta
|
||||
from sqlalchemy import select
|
||||
from bp.calendar.services import get_visible_entries_for_period
|
||||
from models.calendars import CalendarSlot
|
||||
|
||||
calendar = getattr(g, "calendar", None)
|
||||
if not calendar:
|
||||
return
|
||||
|
||||
try:
|
||||
day_date = date_cls(year, month, day)
|
||||
except (ValueError, TypeError):
|
||||
return
|
||||
|
||||
period_start = datetime(year, month, day, tzinfo=timezone.utc)
|
||||
period_end = period_start + timedelta(days=1)
|
||||
|
||||
user = getattr(g, "user", None)
|
||||
session_id = qsession.get("calendar_sid")
|
||||
|
||||
visible = await get_visible_entries_for_period(
|
||||
sess=g.s,
|
||||
calendar_id=calendar.id,
|
||||
period_start=period_start,
|
||||
period_end=period_end,
|
||||
user=user,
|
||||
session_id=session_id,
|
||||
)
|
||||
|
||||
weekday_attr = ["mon", "tue", "wed", "thu", "fri", "sat", "sun"][day_date.weekday()]
|
||||
stmt = (
|
||||
select(CalendarSlot)
|
||||
.where(
|
||||
CalendarSlot.calendar_id == calendar.id,
|
||||
getattr(CalendarSlot, weekday_attr) == True, # noqa: E712
|
||||
CalendarSlot.deleted_at.is_(None),
|
||||
)
|
||||
.order_by(CalendarSlot.time_start.asc(), CalendarSlot.id.asc())
|
||||
)
|
||||
result = await g.s.execute(stmt)
|
||||
day_slots = list(result.scalars())
|
||||
|
||||
g.day_date = day_date
|
||||
_add_to_defpage_ctx(
|
||||
qsession=qsession,
|
||||
day_date=day_date,
|
||||
day=day,
|
||||
year=year,
|
||||
month=month,
|
||||
day_entries=visible.merged_entries,
|
||||
user_entries=visible.user_entries,
|
||||
confirmed_entries=visible.confirmed_entries,
|
||||
day_slots=day_slots,
|
||||
)
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Page helpers
|
||||
# ---------------------------------------------------------------------------
|
||||
@@ -336,39 +513,72 @@ def _register_events_helpers() -> None:
|
||||
})
|
||||
|
||||
|
||||
def _h_calendar_admin_content():
|
||||
async def _h_calendar_admin_content(calendar_slug=None, **kw):
|
||||
await _ensure_calendar(calendar_slug)
|
||||
from shared.sx.page import get_template_context
|
||||
from sx.sx_components import _calendar_admin_main_panel_html
|
||||
ctx = await get_template_context()
|
||||
return _calendar_admin_main_panel_html(ctx)
|
||||
|
||||
|
||||
async def _h_day_admin_content(calendar_slug=None, year=None, month=None, day=None, **kw):
|
||||
await _ensure_calendar(calendar_slug)
|
||||
if year is not None:
|
||||
await _ensure_day_data(int(year), int(month), int(day))
|
||||
from sx.sx_components import _day_admin_main_panel_html
|
||||
return _day_admin_main_panel_html({})
|
||||
|
||||
|
||||
async def _h_slots_content(calendar_slug=None, **kw):
|
||||
from quart import g
|
||||
return getattr(g, "calendar_admin_content", "")
|
||||
await _ensure_calendar(calendar_slug)
|
||||
calendar = getattr(g, "calendar", None)
|
||||
from bp.slots.services.slots import list_slots as svc_list_slots
|
||||
slots = await svc_list_slots(g.s, calendar.id) if calendar else []
|
||||
_add_to_defpage_ctx(slots=slots)
|
||||
from sx.sx_components import render_slots_table
|
||||
return render_slots_table(slots, calendar)
|
||||
|
||||
|
||||
def _h_day_admin_content():
|
||||
from quart import g
|
||||
return getattr(g, "day_admin_content", "")
|
||||
async def _h_slot_content(calendar_slug=None, slot_id=None, **kw):
|
||||
from quart import g, abort
|
||||
await _ensure_calendar(calendar_slug)
|
||||
from bp.slot.services.slot import get_slot as svc_get_slot
|
||||
slot = await svc_get_slot(g.s, slot_id) if slot_id else None
|
||||
if not slot:
|
||||
abort(404)
|
||||
g.slot = slot
|
||||
_add_to_defpage_ctx(slot=slot)
|
||||
calendar = getattr(g, "calendar", None)
|
||||
from sx.sx_components import render_slot_main_panel
|
||||
return render_slot_main_panel(slot, calendar)
|
||||
|
||||
|
||||
def _h_slots_content():
|
||||
from quart import g
|
||||
return getattr(g, "slots_content", "")
|
||||
async def _h_entry_content(calendar_slug=None, entry_id=None, **kw):
|
||||
await _ensure_calendar(calendar_slug)
|
||||
await _ensure_entry_context(entry_id)
|
||||
from shared.sx.page import get_template_context
|
||||
from sx.sx_components import _entry_main_panel_html
|
||||
ctx = await get_template_context()
|
||||
return _entry_main_panel_html(ctx)
|
||||
|
||||
|
||||
def _h_slot_content():
|
||||
from quart import g
|
||||
return getattr(g, "slot_content", "")
|
||||
async def _h_entry_menu(calendar_slug=None, entry_id=None, **kw):
|
||||
await _ensure_calendar(calendar_slug)
|
||||
await _ensure_entry_context(entry_id)
|
||||
from shared.sx.page import get_template_context
|
||||
from sx.sx_components import _entry_nav_html
|
||||
ctx = await get_template_context()
|
||||
return _entry_nav_html(ctx)
|
||||
|
||||
|
||||
def _h_entry_content():
|
||||
from quart import g
|
||||
return getattr(g, "entry_content", "")
|
||||
|
||||
|
||||
def _h_entry_menu():
|
||||
from quart import g
|
||||
return getattr(g, "entry_menu", "")
|
||||
|
||||
|
||||
def _h_entry_admin_content():
|
||||
from quart import g
|
||||
return getattr(g, "entry_admin_content", "")
|
||||
async def _h_entry_admin_content(calendar_slug=None, entry_id=None, **kw):
|
||||
await _ensure_calendar(calendar_slug)
|
||||
await _ensure_entry_context(entry_id)
|
||||
from shared.sx.page import get_template_context
|
||||
from sx.sx_components import _entry_admin_main_panel_html
|
||||
ctx = await get_template_context()
|
||||
return _entry_admin_main_panel_html(ctx)
|
||||
|
||||
|
||||
def _h_admin_menu():
|
||||
@@ -376,31 +586,118 @@ def _h_admin_menu():
|
||||
return sx_call("events-admin-placeholder-nav")
|
||||
|
||||
|
||||
def _h_ticket_types_content():
|
||||
async def _h_ticket_types_content(calendar_slug=None, entry_id=None,
|
||||
year=None, month=None, day=None, **kw):
|
||||
from quart import g
|
||||
return getattr(g, "ticket_types_content", "")
|
||||
await _ensure_calendar(calendar_slug)
|
||||
await _ensure_entry(entry_id)
|
||||
entry = getattr(g, "entry", None)
|
||||
calendar = getattr(g, "calendar", None)
|
||||
from bp.ticket_types.services.tickets import list_ticket_types as svc_list_ticket_types
|
||||
ticket_types = await svc_list_ticket_types(g.s, entry.id) if entry else []
|
||||
_add_to_defpage_ctx(ticket_types=ticket_types)
|
||||
from sx.sx_components import render_ticket_types_table
|
||||
return render_ticket_types_table(ticket_types, entry, calendar, day, month, year)
|
||||
|
||||
|
||||
def _h_ticket_type_content():
|
||||
async def _h_ticket_type_content(calendar_slug=None, entry_id=None,
|
||||
ticket_type_id=None, year=None, month=None, day=None, **kw):
|
||||
from quart import g, abort
|
||||
await _ensure_calendar(calendar_slug)
|
||||
await _ensure_entry(entry_id)
|
||||
from bp.ticket_type.services.ticket import get_ticket_type as svc_get_ticket_type
|
||||
ticket_type = await svc_get_ticket_type(g.s, ticket_type_id) if ticket_type_id else None
|
||||
if not ticket_type:
|
||||
abort(404)
|
||||
g.ticket_type = ticket_type
|
||||
_add_to_defpage_ctx(ticket_type=ticket_type)
|
||||
entry = getattr(g, "entry", None)
|
||||
calendar = getattr(g, "calendar", None)
|
||||
from sx.sx_components import render_ticket_type_main_panel
|
||||
return render_ticket_type_main_panel(ticket_type, entry, calendar, day, month, year)
|
||||
|
||||
|
||||
async def _h_tickets_content(**kw):
|
||||
from quart import g
|
||||
return getattr(g, "ticket_type_content", "")
|
||||
from shared.infrastructure.cart_identity import current_cart_identity
|
||||
from bp.tickets.services.tickets import get_user_tickets
|
||||
ident = current_cart_identity()
|
||||
tickets = await get_user_tickets(
|
||||
g.s,
|
||||
user_id=ident["user_id"],
|
||||
session_id=ident["session_id"],
|
||||
)
|
||||
from shared.sx.page import get_template_context
|
||||
from sx.sx_components import _tickets_main_panel_html
|
||||
ctx = await get_template_context()
|
||||
return _tickets_main_panel_html(ctx, tickets)
|
||||
|
||||
|
||||
def _h_tickets_content():
|
||||
async def _h_ticket_detail_content(code=None, **kw):
|
||||
from quart import g, abort
|
||||
from shared.infrastructure.cart_identity import current_cart_identity
|
||||
from bp.tickets.services.tickets import get_ticket_by_code
|
||||
ticket = await get_ticket_by_code(g.s, code) if code else None
|
||||
if not ticket:
|
||||
abort(404)
|
||||
# Verify ownership
|
||||
ident = current_cart_identity()
|
||||
if ident["user_id"] is not None:
|
||||
if ticket.user_id != ident["user_id"]:
|
||||
abort(404)
|
||||
elif ident["session_id"] is not None:
|
||||
if ticket.session_id != ident["session_id"]:
|
||||
abort(404)
|
||||
else:
|
||||
abort(404)
|
||||
from shared.sx.page import get_template_context
|
||||
from sx.sx_components import _ticket_detail_panel_html
|
||||
ctx = await get_template_context()
|
||||
return _ticket_detail_panel_html(ctx, ticket)
|
||||
|
||||
|
||||
async def _h_ticket_admin_content(**kw):
|
||||
from quart import g
|
||||
return getattr(g, "tickets_content", "")
|
||||
from sqlalchemy import select, func
|
||||
from sqlalchemy.orm import selectinload
|
||||
from models.calendars import CalendarEntry, Ticket
|
||||
|
||||
result = await g.s.execute(
|
||||
select(Ticket)
|
||||
.options(
|
||||
selectinload(Ticket.entry).selectinload(CalendarEntry.calendar),
|
||||
selectinload(Ticket.ticket_type),
|
||||
)
|
||||
.order_by(Ticket.created_at.desc())
|
||||
.limit(50)
|
||||
)
|
||||
tickets = result.scalars().all()
|
||||
|
||||
total = await g.s.scalar(select(func.count(Ticket.id)))
|
||||
confirmed = await g.s.scalar(
|
||||
select(func.count(Ticket.id)).where(Ticket.state == "confirmed")
|
||||
)
|
||||
checked_in = await g.s.scalar(
|
||||
select(func.count(Ticket.id)).where(Ticket.state == "checked_in")
|
||||
)
|
||||
reserved = await g.s.scalar(
|
||||
select(func.count(Ticket.id)).where(Ticket.state == "reserved")
|
||||
)
|
||||
stats = {
|
||||
"total": total or 0,
|
||||
"confirmed": confirmed or 0,
|
||||
"checked_in": checked_in or 0,
|
||||
"reserved": reserved or 0,
|
||||
}
|
||||
|
||||
from shared.sx.page import get_template_context
|
||||
from sx.sx_components import _ticket_admin_main_panel_html
|
||||
ctx = await get_template_context()
|
||||
return _ticket_admin_main_panel_html(ctx, tickets, stats)
|
||||
|
||||
|
||||
def _h_ticket_detail_content():
|
||||
from quart import g
|
||||
return getattr(g, "ticket_detail_content", "")
|
||||
|
||||
|
||||
def _h_ticket_admin_content():
|
||||
from quart import g
|
||||
return getattr(g, "ticket_admin_content", "")
|
||||
|
||||
|
||||
def _h_markets_content():
|
||||
from quart import g
|
||||
return getattr(g, "markets_content", "")
|
||||
async def _h_markets_content(**kw):
|
||||
from shared.sx.page import get_template_context
|
||||
from sx.sx_components import _markets_main_panel_html
|
||||
ctx = await get_template_context()
|
||||
return _markets_main_panel_html(ctx)
|
||||
|
||||
@@ -1,89 +1,89 @@
|
||||
;; Events pages — mounted on various nested blueprints
|
||||
;; Events pages — auto-mounted with absolute paths
|
||||
|
||||
;; Calendar admin (mounted on calendar.admin bp)
|
||||
;; Calendar admin
|
||||
(defpage calendar-admin
|
||||
:path "/"
|
||||
:path "/<slug>/<calendar_slug>/admin/"
|
||||
:auth :admin
|
||||
:layout :events-calendar-admin
|
||||
:content (calendar-admin-content))
|
||||
:content (calendar-admin-content calendar-slug))
|
||||
|
||||
;; Day admin (mounted on day.admin bp)
|
||||
;; Day admin
|
||||
(defpage day-admin
|
||||
:path "/"
|
||||
:path "/<slug>/<calendar_slug>/day/<int:year>/<int:month>/<int:day>/admin/"
|
||||
:auth :admin
|
||||
:layout :events-day-admin
|
||||
:content (day-admin-content))
|
||||
:content (day-admin-content calendar-slug year month day))
|
||||
|
||||
;; Slots listing (mounted on slots bp)
|
||||
;; Slots listing
|
||||
(defpage slots-listing
|
||||
:path "/"
|
||||
:path "/<slug>/<calendar_slug>/slots/"
|
||||
:auth :public
|
||||
:layout :events-slots
|
||||
:content (slots-content))
|
||||
:content (slots-content calendar-slug))
|
||||
|
||||
;; Slot detail (mounted on slot bp)
|
||||
;; Slot detail
|
||||
(defpage slot-detail
|
||||
:path "/"
|
||||
:path "/<slug>/<calendar_slug>/slots/<int:slot_id>/"
|
||||
:auth :admin
|
||||
:layout :events-slot
|
||||
:content (slot-content))
|
||||
:content (slot-content calendar-slug slot-id))
|
||||
|
||||
;; Entry detail (mounted on calendar_entry bp)
|
||||
;; Entry detail
|
||||
(defpage entry-detail
|
||||
:path "/"
|
||||
:path "/<slug>/<calendar_slug>/day/<int:year>/<int:month>/<int:day>/entries/<int:entry_id>/"
|
||||
:auth :admin
|
||||
:layout :events-entry
|
||||
:content (entry-content)
|
||||
:menu (entry-menu))
|
||||
:content (entry-content calendar-slug entry-id)
|
||||
:menu (entry-menu calendar-slug entry-id))
|
||||
|
||||
;; Entry admin (mounted on calendar_entry.admin bp)
|
||||
;; Entry admin
|
||||
(defpage entry-admin
|
||||
:path "/"
|
||||
:path "/<slug>/<calendar_slug>/day/<int:year>/<int:month>/<int:day>/entries/<int:entry_id>/admin/"
|
||||
:auth :admin
|
||||
:layout :events-entry-admin
|
||||
:content (entry-admin-content)
|
||||
:content (entry-admin-content calendar-slug entry-id)
|
||||
:menu (admin-menu))
|
||||
|
||||
;; Ticket types listing (mounted on ticket_types bp)
|
||||
;; Ticket types listing
|
||||
(defpage ticket-types-listing
|
||||
:path "/"
|
||||
:path "/<slug>/<calendar_slug>/day/<int:year>/<int:month>/<int:day>/entries/<int:entry_id>/ticket-types/"
|
||||
:auth :public
|
||||
:layout :events-ticket-types
|
||||
:content (ticket-types-content)
|
||||
:content (ticket-types-content calendar-slug entry-id year month day)
|
||||
:menu (admin-menu))
|
||||
|
||||
;; Ticket type detail (mounted on ticket_type bp)
|
||||
;; Ticket type detail
|
||||
(defpage ticket-type-detail
|
||||
:path "/"
|
||||
:path "/<slug>/<calendar_slug>/day/<int:year>/<int:month>/<int:day>/entries/<int:entry_id>/ticket-types/<int:ticket_type_id>/"
|
||||
:auth :admin
|
||||
:layout :events-ticket-type
|
||||
:content (ticket-type-content)
|
||||
:content (ticket-type-content calendar-slug entry-id ticket-type-id year month day)
|
||||
:menu (admin-menu))
|
||||
|
||||
;; My tickets (mounted on tickets bp)
|
||||
;; My tickets
|
||||
(defpage my-tickets
|
||||
:path "/"
|
||||
:path "/tickets/"
|
||||
:auth :public
|
||||
:layout :root
|
||||
:content (tickets-content))
|
||||
|
||||
;; Ticket detail (mounted on tickets bp)
|
||||
;; Ticket detail
|
||||
(defpage ticket-detail
|
||||
:path "/<code>/"
|
||||
:path "/tickets/<code>/"
|
||||
:auth :public
|
||||
:layout :root
|
||||
:content (ticket-detail-content))
|
||||
:content (ticket-detail-content code))
|
||||
|
||||
;; Ticket admin dashboard (mounted on ticket_admin bp)
|
||||
;; Ticket admin dashboard
|
||||
(defpage ticket-admin
|
||||
:path "/"
|
||||
:path "/admin/tickets/"
|
||||
:auth :admin
|
||||
:layout :root
|
||||
:content (ticket-admin-content))
|
||||
|
||||
;; Markets (mounted on markets bp)
|
||||
;; Markets
|
||||
(defpage events-markets
|
||||
:path "/"
|
||||
:path "/<slug>/markets/"
|
||||
:auth :public
|
||||
:layout :events-markets
|
||||
:content (markets-content))
|
||||
|
||||
Reference in New Issue
Block a user