z_controller_helper (zotonic_core v1.0.0-rc.12)

Helper functions commonly used in controllers.

Link to this section Summary

Functions

Decode the request data
Decode the request data - remove zotonic arguments that are part of the query string and/or post.
Encode the response data
Fetch the id from the dispatch configuration.
Fetch the id from the request or the dispatch configuration.
Check if the current user is allowed to access the controller.

Link to this section Functions

Link to this function

decode_request(CT, Context)

-spec decode_request(undefined | cow_http_hd:media_type(), z:context()) ->
                  {map() | binary(), z:context()}.
Decode the request data
Link to this function

decode_request_noz(Mime, Context)

-spec decode_request_noz(undefined | cow_http_hd:media_type(), z:context()) ->
                      {map() | binary(), z:context()}.
Decode the request data - remove zotonic arguments that are part of the query string and/or post.
Link to this function

encode_response(Mime, Data)

-spec encode_response(Mime :: cow_http_hd:media_type(), term()) -> binary().
Encode the response data
Link to this function

get_configured_id(Context)

-spec get_configured_id(z:context()) -> m_rsc:resource_id() | undefined.
Fetch the id from the dispatch configuration.
Link to this function

get_id(Context)

-spec get_id(z:context()) -> m_rsc:resource_id() | undefined.
Fetch the id from the request or the dispatch configuration.
Link to this function

is_authorized(OptRscId, Context)

-spec is_authorized(OptRscId, Context) -> {boolean(), Context1}
                 when
                     OptRscId :: m_rsc:resource_id() | undefined,
                     Context :: z:context(),
                     Context1 :: z:context();
             (ACLs, Context) -> {boolean(), Context1}
                 when ACLs :: z_acl:acl(), Context :: z:context(), Context1 :: z:context().
Check if the current user is allowed to access the controller.
Link to this function

is_authorized(OptRscId, ACL, Context)

-spec is_authorized(OptRscId, ACL, z:context()) -> {boolean(), z:context()}
                 when OptRscId :: m_rsc:resource_id() | undefined, ACL :: boolean() | z_acl:acl().
Link to this function

is_authorized_action(Action, Object, Context)

-spec is_authorized_action(z_acl:action(), z_acl:object(), z:context()) -> {boolean(), z:context()}.
Link to this function

req_body(Context)

-spec req_body(z:context()) -> {binary(), z:context()}.