/modules/mod_admin_config/resources/resource_admin_config.erl

http://github.com/zotonic/zotonic · Erlang · 62 lines · 31 code · 12 blank · 19 comment · 6 complexity · 2ec5a1d94a045fa626ea3a9f3af05e78 MD5 · raw file

  1. %% @author Marc Worrell <marc@worrell.nl>
  2. %% @copyright 2009 Marc Worrell
  3. %% Date: 2009-08-07
  4. %% @doc Overview of all config settings with string values.
  5. %% Copyright 2009 Marc Worrell
  6. %%
  7. %% Licensed under the Apache License, Version 2.0 (the "License");
  8. %% you may not use this file except in compliance with the License.
  9. %% You may obtain a copy of the License at
  10. %%
  11. %% http://www.apache.org/licenses/LICENSE-2.0
  12. %%
  13. %% Unless required by applicable law or agreed to in writing, software
  14. %% distributed under the License is distributed on an "AS IS" BASIS,
  15. %% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16. %% See the License for the specific language governing permissions and
  17. %% limitations under the License.
  18. -module(resource_admin_config).
  19. -author("Marc Worrell <marc@worrell.nl>").
  20. -export([
  21. is_authorized/2
  22. ]).
  23. -include_lib("resource_html.hrl").
  24. is_authorized(ReqData, Context) ->
  25. z_acl:wm_is_authorized(use, mod_admin_config, ReqData, Context).
  26. html(Context) ->
  27. All = m_config:all(Context),
  28. AllWithValue = lists:sort(lists:map(fun only_value_config/1, All)),
  29. Vars = [
  30. {page_admin_config, true},
  31. {config, AllWithValue}
  32. ],
  33. Html = z_template:render("admin_config.tpl", Vars, Context),
  34. z_context:output(Html, Context).
  35. %% @doc Check if the config does not have a non-string setting. We only edit string values.
  36. %% @spec only_value_config({module, [{key,Value}]}) -> bool()
  37. only_value_config({Module, Keys}) ->
  38. {Module, lists:filter(fun is_value_config_key/1, Keys)}.
  39. is_value_config_key({_Key, Props}) ->
  40. is_value_config_props(Props).
  41. is_value_config_props([]) ->
  42. true;
  43. is_value_config_props([{Prop,_}|Rest]) when Prop == created; Prop == modified; Prop == value; Prop == id; Prop == module; Prop == key ->
  44. is_value_config_props(Rest);
  45. is_value_config_props([{props,<<>>}|Rest]) ->
  46. is_value_config_props(Rest);
  47. is_value_config_props([{props,undefined}|Rest]) ->
  48. is_value_config_props(Rest);
  49. is_value_config_props(_X) ->
  50. false.