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
-spec decode_request(undefined | cow_http_hd:media_type(), z:context()) -> {map() | binary(), z:context()}.
Decode the request data
-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.
-spec encode_response(Mime :: cow_http_hd:media_type(), term()) -> binary().
Encode the response data
-spec get_configured_id(z:context()) -> m_rsc:resource_id() | undefined.
Fetch the id from the dispatch configuration.
-spec get_id(z:context()) -> m_rsc:resource_id() | undefined.
Fetch the id from the request or the dispatch configuration.
-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.
-spec is_authorized_action(z_acl:action(), z_acl:object(), z:context()) -> {boolean(), z:context()}.
Check if we are on the correct path for the selected language version.
-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.