diff --git a/snikket_web/admin.py b/snikket_web/admin.py index bf895eb..e97a962 100644 --- a/snikket_web/admin.py +++ b/snikket_web/admin.py @@ -301,6 +301,10 @@ class InvitePost(BaseForm): default="prosody:registered", ) + note = wtforms.StringField( + _l("Comment (optional)"), + ) + action_create_invite = wtforms.SubmitField( _l("New invitation link") ) @@ -382,12 +386,14 @@ async def create_invite() -> typing.Union[str, werkzeug.Response]: group_ids=form.circles.data, role_names=[form.role.data], ttl=form.lifetime.data, + note=form.note.data, ) else: invite = await client.create_account_invite( group_ids=form.circles.data, role_names=[form.role.data], ttl=form.lifetime.data, + note=form.note.data, ) await flash( _("Invitation created"), diff --git a/snikket_web/prosodyclient.py b/snikket_web/prosodyclient.py index 2f9b6d1..f084cd2 100644 --- a/snikket_web/prosodyclient.py +++ b/snikket_web/prosodyclient.py @@ -162,6 +162,7 @@ class AdminInviteInfo: group_ids: typing.Collection[str] role_names: typing.Collection[str] is_reset: bool + note: typing.Optional[str] @classmethod def from_api_response( @@ -181,6 +182,7 @@ class AdminInviteInfo: role_names=data.get("roles", []), reusable=data["reusable"], is_reset=data.get("reset", False), + note=data.get("note"), ) @@ -1091,6 +1093,7 @@ class ProsodyClient: role_names: typing.Collection[str] = [], restrict_username: typing.Optional[str] = None, ttl: typing.Optional[int] = None, + note: typing.Optional[str] = None, session: aiohttp.ClientSession, ) -> AdminInviteInfo: payload: typing.Dict[str, typing.Any] = {} @@ -1100,6 +1103,8 @@ class ProsodyClient: payload["username"] = restrict_username if ttl is not None: payload["ttl"] = ttl + if note is not None: + payload["note"] = note async with session.post( self._admin_v1_endpoint("/invites/account"), @@ -1114,6 +1119,7 @@ class ProsodyClient: group_ids: typing.Collection[str] = [], role_names: typing.Collection[str] = [], ttl: typing.Optional[int] = None, + note: typing.Optional[str] = None, session: aiohttp.ClientSession, ) -> AdminInviteInfo: payload: typing.Dict[str, typing.Any] = { @@ -1122,6 +1128,8 @@ class ProsodyClient: } if ttl is not None: payload["ttl"] = ttl + if note is not None: + payload["note"] = note async with session.post( self._admin_v1_endpoint("/invites/group"), diff --git a/snikket_web/templates/admin_create_invite_form.html b/snikket_web/templates/admin_create_invite_form.html index f4c4144..1d0f68b 100644 --- a/snikket_web/templates/admin_create_invite_form.html +++ b/snikket_web/templates/admin_create_invite_form.html @@ -66,6 +66,12 @@ {%- call render_errors(invite_form.circles) -%}{%- endcall -%} + +
+ {{ invite_form.note.label }} + {{ invite_form.note }} +
+
{%- call form_button("create_link", invite_form.action_create_invite, class="primary") %}{% endcall -%}
diff --git a/snikket_web/templates/admin_invites.html b/snikket_web/templates/admin_invites.html index d4d2213..34d5eeb 100644 --- a/snikket_web/templates/admin_invites.html +++ b/snikket_web/templates/admin_invites.html @@ -21,6 +21,7 @@ {% trans %}Type{% endtrans %} {% trans %}Circle{% endtrans %} {% trans %}Expires{% endtrans %} + {% trans %}Comment{% endtrans %} {% trans %}Actions{% endtrans %} @@ -39,6 +40,7 @@ {#- -#} {{ (invite.expires - now) | format_timedelta(add_direction=True) }} + {% if invite.note is not none %}{{ invite.note }}{% endif %} {%- call action_button("more", url_for(".edit_invite", id_=invite.id_), class="secondary") -%} {% trans %}Show invite details{% endtrans %}