Skip to content

Commit

Permalink
base: allow 'user_id' as configured id for controller_redirect.
Browse files Browse the repository at this point in the history
  • Loading branch information
mworrell committed Aug 20, 2018
1 parent 3e9071a commit d41bfe5
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
10 changes: 8 additions & 2 deletions apps/zotonic_core/src/support/z_controller_helper.erl
Expand Up @@ -22,7 +22,8 @@

-export([
is_authorized/1,
get_id/1
get_id/1,
get_configured_id/1
]).


Expand Down Expand Up @@ -53,8 +54,13 @@ is_authorized(Context) ->
%% @doc Fetch the id from the request or the dispatch configuration.
-spec get_id(z:context()) -> m_rsc:resource_id() | undefined.
get_id(Context) ->
case z_context:get(id, Context) of
case get_configured_id(Context) of
undefined -> rid(z_context:get_q("id", Context), Context);
ConfId -> ConfId
end.

get_configured_id(Context) ->
case z_context:get(id, Context) of
user_id -> z_acl:user(Context);
ConfId -> rid(ConfId, Context)
end.
Expand Down
Expand Up @@ -57,7 +57,7 @@ do_redirect(Context) ->
undefined ->
case z_context:get(dispatch, Context) of
undefined ->
case z_context:get(id, Context) of
case z_controller_helper:get_configured_id(Context) of
undefined -> <<"/">>;
Id -> m_rsc:p(Id, page_url, Context)
end;
Expand Down
4 changes: 3 additions & 1 deletion doc/ref/controllers/controller_redirect.rst
Expand Up @@ -32,7 +32,9 @@ It has the following dispatch options:
| |controller will redirect to the | |
| |page_url of this id. The id can be | |
| |an integer or the name of the page | |
| |(use an atom or a binary). | |
| |(use an atom or a binary) or the | |
| |atom `user_id` for the id of the | |
| |current user. | |
+-----------------+------------------------------------+-----------------------+
|qargs |A list with querystring arguments to|{qargs, [id, slug]} |
| |use in the new dispatch | |
Expand Down

0 comments on commit d41bfe5

Please sign in to comment.