Skip to content

Commit

Permalink
fix: document and validate messages post/list
Browse files Browse the repository at this point in the history
  • Loading branch information
db0 committed Jan 29, 2025
1 parent 04be4e4 commit 6e17062
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
13 changes: 13 additions & 0 deletions horde/apis/models/v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,8 @@ def __init__(self, api):
"worker_id": fields.String(
title="Worker ID",
description="The UUID of the worker which generated this image.",
min_length=36,
max_length=36,
),
"worker_name": fields.String(
title="Worker Name",
Expand Down Expand Up @@ -781,6 +783,8 @@ def __init__(self, api):
description="The ID of the worker this message is intended for.",
example="00000000-0000-0000-0000-000000000000",
required=True,
min_length=36,
max_length=36,
),
"user_id": fields.String(
description="The ID of owning user",
Expand Down Expand Up @@ -1236,6 +1240,8 @@ def __init__(self, api):
fields.String(
description="Privileged or public when the user has explicitly allows it to be public.",
example="00000000-0000-0000-0000-000000000000",
min_length=36,
max_length=36,
),
),
"styles": fields.List(fields.Nested(self.response_model_styles_user)),
Expand Down Expand Up @@ -1851,6 +1857,13 @@ def __init__(self, api):
self.input_model_message = api.model(
"ResponseModelMessage",
{
"worker_id": fields.String(
description="The ID of the worker this message is intended for.",
example="00000000-0000-0000-0000-000000000000",
required=False,
min_length=36,
max_length=36,
),
"message": fields.String(
description="The message sent",
example="Hello Worker!",
Expand Down
10 changes: 7 additions & 3 deletions horde/apis/v2/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -3190,6 +3190,8 @@ class WorkerMessages(Resource):
required=False,
type=str,
location="args",
help="Filter messages based on whether they're expired or not. Possible values are 'active', 'expired' and 'all",
default="active",
)
get_parser.add_argument(
"page",
Expand All @@ -3201,7 +3203,7 @@ class WorkerMessages(Resource):
)

# @cache.cached(timeout=60)
@api.expect(get_parser)
@api.expect(get_parser, validate=True)
@api.marshal_with(
models.response_model_message_full,
code=200,
Expand All @@ -3222,11 +3224,13 @@ def get(self):
self.args.user_id = user.id
if not user.moderator and user.id != self.args.user_id:
raise e.Forbidden("You can only view your own messages.")
if self.args.validity and self.args.validity not in {"active", "expired", "all"}:
raise e.BadRequest("validity can only be one of 'active, 'expired', or 'all'")
return (
database.get_worker_messages(
user_id=self.args.user_id,
worker_id=self.args.worker_id,
validity=self.args.validity,
validity=self.args.validity if self.args.validity else "active",
page=self.args.page - 1,
),
200,
Expand Down Expand Up @@ -3273,7 +3277,7 @@ def get(self):
)

@cache.cached(timeout=60)
@api.expect(post_parser)
@api.expect(post_parser, models.input_model_message, validate=True)
@api.marshal_with(
models.response_model_message_full,
code=200,
Expand Down

0 comments on commit 6e17062

Please sign in to comment.