pub trait SpacePolicy: JmapBackend {
// Provided methods
fn may_set_custom_emoji(
&self,
_caller: &Self::CallerCtx,
_account_id: &Id,
_target_space_id: Option<&Id>,
_op: EmojiSetOp,
) -> impl Future<Output = Result<Result<(), SetError>, Self::Error>> + Send { ... }
fn may_set_space_ban(
&self,
_caller: &Self::CallerCtx,
_account_id: &Id,
_space_id: &Id,
) -> impl Future<Output = Result<Result<(), SetError>, Self::Error>> + Send { ... }
fn may_set_space_invite(
&self,
_caller: &Self::CallerCtx,
_account_id: &Id,
_space_id: &Id,
_created_by: Option<&Id>,
) -> impl Future<Output = Result<Result<(), SetError>, Self::Error>> + Send { ... }
fn may_get_space_invite(
&self,
_caller: &Self::CallerCtx,
_account_id: &Id,
_invite: &SpaceInvite,
) -> impl Future<Output = Result<bool, Self::Error>> + Send { ... }
fn may_get_space_ban(
&self,
_caller: &Self::CallerCtx,
_account_id: &Id,
_ban: &SpaceBan,
) -> impl Future<Output = Result<bool, Self::Error>> + Send { ... }
}Expand description
Space-scoped authorization gates: custom emoji, SpaceBan and SpaceInvite writes and reads.
Part of ChatBackend (docs/design/chat-backend-split.md).
Provided Methods§
Sourcefn may_set_custom_emoji(
&self,
_caller: &Self::CallerCtx,
_account_id: &Id,
_target_space_id: Option<&Id>,
_op: EmojiSetOp,
) -> impl Future<Output = Result<Result<(), SetError>, Self::Error>> + Send
fn may_set_custom_emoji( &self, _caller: &Self::CallerCtx, _account_id: &Id, _target_space_id: Option<&Id>, _op: EmojiSetOp, ) -> impl Future<Output = Result<Result<(), SetError>, Self::Error>> + Send
Authorization gate consulted by handle_emoji_set before every
CustomEmoji/set create, update, or destroy.
Per draft-atwood-jmap-chat-00 commit 9344aec (2026-05-11,
“refactor: implementation-defined emoji authorization”):
authorization for CustomEmoji/set is fully
implementation-defined, for both server-global and Space-scoped
emoji. When the caller is not authorized, the handler emits a
forbidden SetError (RFC 8620 §5.3).
§target_space_id semantics
target_space_id is the actual scope of the emoji this op
targets:
None— the emoji is server-global (itsspaceIdfield is absent / null).Some(id)— the emoji is scoped to that Space (itsspaceIdfield equalsid).
For Create, the handler reads the scope from the create
payload. For Update and Destroy, the handler pre-fetches
the existing emoji via get_objects and passes its current
spaceId. If the pre-fetch reports the id as not found, the
handler skips this gate entirely and lets update_object /
destroy_object surface a notFound SetError naturally — a
non-existent target consumes no authorization decision.
§When the handler calls this
Exactly once per create/update/destroy entry in the request,
AFTER wire-format validation has succeeded and BEFORE the
corresponding create_object / update_object /
destroy_object call. The handler skips the underlying mutation
when the outer Result is Ok(Err(_)) or when the outer is
Err(_). The wire mapping is:
Ok(Ok(()))— permit; the handler proceeds to the underlyingcreate_object/update_object/destroy_object.Ok(Err(set_err))— deny with reason; the handler serialisesset_errinto the appropriatenotCreated/notUpdated/notDestroyedmap verbatim. Backends construct theSetErrorwith the type, description, and anywith_extrafields the deployment wants the client to see.Err(e)— backend infrastructure failure; the handler maps to aserverFailSetError.
§Default implementation
The default returns Ok(Ok(())) — every op is permitted. This
matches the workspace’s “kit defines the hook; consumer
enforces the policy” posture (see the parallel design of
ChatAccessPolicy::slow_mode_check). Production backends SHOULD override
this method to apply the deployment’s permission model — e.g.
“only members of target_space_id may modify a Space-scoped
emoji” or “only manage_emoji permission-holders may modify
server-global emoji.”
§SetError shape recommendation
Production backends SHOULD return
Ok(Err(SetError::new(SetErrorType::Forbidden) .with_description("…"))) for authorization denials, mirroring
the workspace convention for /set responses. The description
should explain the deployment’s denial reason without leaking
internal policy details — e.g. “Space-scoped emoji on this
Space requires manage_channels permission” rather than
“principal abc123 is not in role admin on Space xyz789”.
§Foundation seam
Backends that wish to identify the caller call
jmap_server::JmapAccounts::principal_id on caller to learn
whether identity is wired, and compare account_id (the owner’s
member entry, draft §Terminology) against the Space’s members
list, or consult ACLs or whatever permission model the
deployment uses. Backends whose
principal_id returns None (the workspace default, see the
“Caller identity (foundation seam)” section of the workspace
AGENTS.md) cannot meaningfully implement identity-scoped
authorization — they should either override principal_id
first or return Ok(Ok(())) to match the reference posture.
Sourcefn may_set_space_ban(
&self,
_caller: &Self::CallerCtx,
_account_id: &Id,
_space_id: &Id,
) -> impl Future<Output = Result<Result<(), SetError>, Self::Error>> + Send
fn may_set_space_ban( &self, _caller: &Self::CallerCtx, _account_id: &Id, _space_id: &Id, ) -> impl Future<Output = Result<Result<(), SetError>, Self::Error>> + Send
Authorization gate consulted by handle_ban_set before each
SpaceBan create, update or destroy.
Per draft-atwood-jmap-chat-00 §SpaceBan/set: create, update and
destroy each “Requires "ban" permission in the Space.”
§When the handler calls this
Once per entry, AFTER wire-format validation and BEFORE
create_object / update_object / destroy_object. space_id
is the create body’s spaceId, or the stored ban’s spaceId for
update and destroy; an update or destroy whose ban does not
resolve skips the gate so the backend surfaces notFound. The
return mapping is the same as Self::may_set_custom_emoji.
§Default implementation
Returns Ok(Ok(())) — every op is permitted, matching the
parallel hooks above. Production backends SHOULD override this
method and deny with
Ok(Err(SetError::new(SetErrorType::Forbidden))).
Sourcefn may_set_space_invite(
&self,
_caller: &Self::CallerCtx,
_account_id: &Id,
_space_id: &Id,
_created_by: Option<&Id>,
) -> impl Future<Output = Result<Result<(), SetError>, Self::Error>> + Send
fn may_set_space_invite( &self, _caller: &Self::CallerCtx, _account_id: &Id, _space_id: &Id, _created_by: Option<&Id>, ) -> impl Future<Output = Result<Result<(), SetError>, Self::Error>> + Send
Authorization gate consulted by handle_invite_set before each
SpaceInvite create or destroy.
Per draft-atwood-jmap-chat-00 §SpaceInvite/set: create “Requires
"manage_members" permission”; destroy “Requires
"manage_members" permission or ownership of the invite.”
§When the handler calls this
Once per entry, AFTER wire-format validation and BEFORE
create_object / destroy_object. space_id is the create body’s
spaceId, or the stored invite’s spaceId for destroy.
created_by is None on create and the stored invite’s
createdBy on destroy. A destroy whose invite does not resolve
skips the gate so the backend surfaces notFound. The return
mapping is the same as Self::may_set_custom_emoji.
§Default implementation
Returns Ok(Ok(())) — every op is permitted, matching the
parallel hooks above. Production backends SHOULD override this
method and deny with
Ok(Err(SetError::new(SetErrorType::Forbidden))).
Sourcefn may_get_space_invite(
&self,
_caller: &Self::CallerCtx,
_account_id: &Id,
_invite: &SpaceInvite,
) -> impl Future<Output = Result<bool, Self::Error>> + Send
fn may_get_space_invite( &self, _caller: &Self::CallerCtx, _account_id: &Id, _invite: &SpaceInvite, ) -> impl Future<Output = Result<bool, Self::Error>> + Send
Visibility gate consulted by handle_invite_get and
handle_invite_changes for each stored SpaceInvite.
Per draft-atwood-jmap-chat-00 §SpaceInvite/get: “Only members of
the Space may retrieve its invites. Members with
"manage_members" permission see all invites; other members see
only invites they created.” §SpaceInvite/changes: “The same
visibility rules as SpaceInvite/get apply”.
§When the handler calls this
Once per invite returned by get_objects. Ok(false) hides the
invite: /get reports a requested id as notFound, and
/changes omits it from created and updated.
§Default implementation
Returns Ok(true), so every invite is visible, matching the
parallel hooks above. Production backends SHOULD override this
method; invite codes are join credentials.
Sourcefn may_get_space_ban(
&self,
_caller: &Self::CallerCtx,
_account_id: &Id,
_ban: &SpaceBan,
) -> impl Future<Output = Result<bool, Self::Error>> + Send
fn may_get_space_ban( &self, _caller: &Self::CallerCtx, _account_id: &Id, _ban: &SpaceBan, ) -> impl Future<Output = Result<bool, Self::Error>> + Send
Visibility gate consulted by handle_ban_get for each stored
SpaceBan.
Per draft-atwood-jmap-chat-00 §SpaceBan/get: “Members with
"ban" permission in the Space see all SpaceBan records for that
Space. A banned user fetching their own account sees only SpaceBan
records where userId is the accountId.”
§When the handler calls this
Once per ban returned by get_objects. Ok(false) hides the ban,
and a requested id is reported as notFound. SpaceBan/changes
does not consult this hook, because the spec defines it as plain
“Standard JMAP /changes”.
§Default implementation
Returns Ok(true), so every ban is visible, matching the parallel
hooks above. Production backends SHOULD override this method.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".
Implementors§
impl<C: MemoryCaller> SpacePolicy for MemoryBackend<C>
memory only.