Skip to content

Commit

Permalink
Merge pull request #414 from yoonka/module-specific-redirect
Browse files Browse the repository at this point in the history
Enable module specific redirect
  • Loading branch information
mworrell committed Sep 18, 2012
2 parents b70bdcb + b885896 commit e3fa112
Show file tree
Hide file tree
Showing 6 changed files with 171 additions and 171 deletions.
8 changes: 3 additions & 5 deletions modules/mod_admin/resources/resource_admin.erl
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,13 @@
-module(resource_admin).
-author("Tim Benniks <tim@timbenniks.com>").

-export([
is_authorized/2
]).
-export([is_authorized/2
]).

-include_lib("resource_html.hrl").

is_authorized(ReqData, Context) ->
z_acl:wm_is_authorized(use, z_context:get(acl_module, Context, mod_admin), ReqData, Context).

z_acl:wm_is_authorized(use, z_context:get(acl_module, Context, mod_admin), admin_logon, ReqData, Context).

html(Context) ->
Template = z_context:get(template, Context, "admin.tpl"),
Expand Down
53 changes: 26 additions & 27 deletions modules/mod_admin/resources/resource_admin_edit.erl
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,19 @@
-module(resource_admin_edit).
-author("Marc Worrell <marc@worrell.nl>").

-export([
resource_exists/2,
is_authorized/2,
event/2,
filter_props/1,
ensure_id/1
]).
-export([resource_exists/2,
is_authorized/2,
event/2,
filter_props/1,
ensure_id/1
]).

-include_lib("resource_html.hrl").

%% @todo Change this into "visible" and add a view instead of edit template.
is_authorized(ReqData, Context) ->
{Context2, Id} = ensure_id(?WM_REQ(ReqData, Context)),
z_acl:wm_is_authorized([{use, mod_admin}, {view, Id}], Context2).
z_acl:wm_is_authorized([{use, mod_admin}, {view, Id}], admin_logon, Context2).


resource_exists(ReqData, Context) ->
Expand All @@ -41,17 +40,17 @@ resource_exists(ReqData, Context) ->
undefined -> ?WM_REPLY(false, Context2);
_N -> ?WM_REPLY(m_rsc:exists(Id, Context2), Context2)
end.


html(Context) ->
Id = z_context:get(id, Context),
Blocks = z_notifier:foldl(#admin_edit_blocks{id=Id}, [], Context),
Vars = [
{id, Id},
{blocks, lists:sort(Blocks)}
],
{id, Id},
{blocks, lists:sort(Blocks)}
],
Html = z_template:render({cat, "admin_edit.tpl"}, Vars, Context),
z_context:output(Html, Context).
z_context:output(Html, Context).


%% @doc Fetch the (numerical) page id from the request
Expand Down Expand Up @@ -92,9 +91,9 @@ event(#submit{message=rscform}, Context) ->
Context4 = z_render:set_value("slug", m_rsc:p(Id, slug, Context3), Context3),
Context4b= z_render:set_value("visible_for", integer_to_list(m_rsc:p(Id, visible_for, Context4)), Context4),
Context5 = case z_convert:to_bool(m_rsc:p(Id, is_protected, Context4b)) of
true -> z_render:wire("delete-button", {disable, []}, Context4b);
false -> z_render:wire("delete-button", {enable, []}, Context4b)
end,
true -> z_render:wire("delete-button", {disable, []}, Context4b);
false -> z_render:wire("delete-button", {enable, []}, Context4b)
end,
Title = ?__(m_rsc:p(Id, title, Context5), Context5),
Context6 = z_render:growl(["Saved “", Title, "”."], Context5),
case proplists:is_defined("save_duplicate", Post) of
Expand Down Expand Up @@ -149,15 +148,15 @@ event(#postback{message={query_preview, Opts}}, Context) ->
%% @doc Remove some properties that are part of the postback
filter_props(Fs) ->
Remove = [
"triggervalue",
"postback",
"z_trigger_id",
"z_pageid",
"z_submitter",
"trigger_value",
"save_view",
"save_duplicate",
"save_stay"
],
"triggervalue",
"postback",
"z_trigger_id",
"z_pageid",
"z_submitter",
"trigger_value",
"save_view",
"save_duplicate",
"save_stay"
],
lists:foldl(fun(P, Acc) -> proplists:delete(P, Acc) end, Fs, Remove).
%[ {list_to_existing_atom(K), list_to_binary(V)} || {K,V} <- Props ].
%%[ {list_to_existing_atom(K), list_to_binary(V)} || {K,V} <- Props ].
8 changes: 2 additions & 6 deletions modules/mod_admin/resources/resource_admin_media_preview.erl
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@
-module(resource_admin_media_preview).
-author("Arjan Scherpenisse <arjan@scherpenisse.net>").

-export([
init/1,
-export([init/1,
resource_exists/2,
is_authorized/2,
content_types_provided/2,
Expand All @@ -32,10 +31,9 @@

init([]) -> {ok, []}.


is_authorized(ReqData, _Args) ->
Context = z_context:new(ReqData, ?MODULE),
z_acl:wm_is_authorized(use, mod_admin, ReqData, Context).
z_acl:wm_is_authorized(use, mod_admin, admin_logon, ReqData, Context).

resource_exists(ReqData, Context) ->
case z_context:get_q("id", Context) of
Expand All @@ -58,11 +56,9 @@ resource_exists(ReqData, Context) ->
end
end.


content_types_provided(ReqData, Context) ->
{[{"image/jpeg", to_image}], ReqData, Context}.


to_image(ReqData, Context) ->
Opts = [{mediaclass, "admin-editor"}],
Id = m_rsc:rid(z_context:get("id", Context), Context),
Expand Down
15 changes: 7 additions & 8 deletions modules/mod_admin/resources/resource_admin_referrers.erl
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,14 @@
-module(resource_admin_referrers).
-author("Marc Worrell <marc@worrell.nl").

-export([
resource_exists/2,
is_authorized/2
]).
-export([resource_exists/2,
is_authorized/2
]).

-include_lib("resource_html.hrl").

is_authorized(ReqData, Context) ->
z_acl:wm_is_authorized(use, mod_admin, ReqData, Context).
z_acl:wm_is_authorized(use, mod_admin, admin_logon, ReqData, Context).

resource_exists(ReqData, Context) ->
Context1 = ?WM_REQ(ReqData, Context),
Expand All @@ -44,7 +43,7 @@ resource_exists(ReqData, Context) ->

html(Context) ->
Vars = [
{id, z_context:get(id, Context)}
],
{id, z_context:get(id, Context)}
],
Html = z_template:render("admin_referrers.tpl", Vars, Context),
z_context:output(Html, Context).
z_context:output(Html, Context).
23 changes: 12 additions & 11 deletions modules/mod_base/templates/base.tpl
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
<!DOCTYPE html>
<html lang="{{ z_language|default:"en"|escape }}">
<head>
<head>
<meta charset="utf-8" />
<title>Zotonic{% block title %}{% endblock %}</title>

<link rel="icon" href="/favicon.ico" type="image/x-icon" />
<link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />

<link rel="icon" href="/favicon.ico" type="image/x-icon" />
<link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="author" content="Arjan Scherpenisse, Marc Worrell" />
</head>

<body>
{% block content %}
<meta name="author" content="Arjan Scherpenisse, Marc Worrell" />
</head>

<body>
{% block content_area %}
{% block content %}{% endblock %}
{% endblock %}
</body>
</body>
</html>
Loading

0 comments on commit e3fa112

Please sign in to comment.