z_controller_helper (zotonic_core v1.0.0-rc.17)

Helper functions commonly used in controllers.

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.

Check if we are on the correct path for the selected language version.

Redirect to another location, set correct vary and cache-control headers.

Functions

decode_request(CT, Context)

-spec decode_request(undefined | cow_http_hd:media_type(), z:context()) ->
                        {map() | binary(), z:context()}.

Decode the request data

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.

encode_response(Mime, Data)

-spec encode_response(Mime :: cow_http_hd:media_type(), term()) -> binary().

Encode the response data

get_configured_id(Context)

-spec get_configured_id(z:context()) -> m_rsc:resource_id() | undefined.

Fetch the id from the dispatch configuration.

get_id(Context)

-spec get_id(z:context()) -> m_rsc:resource_id() | undefined.

Fetch the id from the request or the dispatch configuration.

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.

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().

is_authorized_action(Action, Object, Context)

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

is_redirect_language(Context)

-spec is_redirect_language(Context) -> boolean() when Context :: z:context().

Check if we are on the correct path for the selected language version.

redirect(IsPermanent, Url, Context)

-spec redirect(IsPermanent, Url, Context) -> {{halt, StatusCode}, RespContext}
                  when
                      IsPermanent :: boolean(),
                      Url :: binary(),
                      Context :: z:context(),
                      StatusCode :: 307 | 308,
                      RespContext :: z:context().

Redirect to another location, set correct vary and cache-control headers.

req_body(Context)

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