PageRenderTime 13ms CodeModel.GetById 8ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

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