PageRenderTime 10ms CodeModel.GetById 6ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

/modules/mod_admin_identity/mod_admin_identity.erl

https://code.google.com/p/zotonic/
Erlang | 63 lines | 33 code | 9 blank | 21 comment | 3 complexity | e174a4622c709ad9e691b61c246e90dc MD5 | raw file
 1%% @author Marc Worrell <marc@worrell.nl>
 2%% @copyright 2009 Marc Worrell
 3%% Date: 2009-06-13
 4%% @doc Identity administration.  Adds overview of users to the admin and enables to add passwords on the edit page.
 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(mod_admin_identity).
21-author("Marc Worrell <marc@worrell.nl>").
22
23-mod_title("Admin identity/user supports").
24-mod_description("Adds an user overview and possibility to edit passwords.").
25
26
27%% interface functions
28-export([
29    observe_search_query/2
30]).
31
32-include("zotonic.hrl").
33
34observe_search_query({search_query, Req, OffsetLimit}, Context) ->
35    search(Req, OffsetLimit, Context).
36
37%%====================================================================
38%% support functions
39%%====================================================================
40
41search({users, [{text,QueryText}]}, _OffsetLimit, Context) ->
42    case QueryText of
43        A when A == undefined orelse A == "" orelse A == <<>> ->
44            #search_sql{
45                select="r.id, max(r.modified) AS rank",
46                from="rsc r join identity i on r.id = i.rsc_id",
47                order="rank desc",
48                group_by="r.id",
49                tables=[{rsc,"r"}]
50            };
51        _ ->
52            #search_sql{
53                select="r.id, max(ts_rank_cd(pivot_tsv, query, 32)) AS rank",
54                from="rsc r join identity i on r.id = i.rsc_id, plainto_tsquery($2, $1) query",
55                where=" query @@ pivot_tsv",
56                order="rank desc",
57                group_by="r.id",
58                args=[QueryText, z_pivot_rsc:pg_lang(Context#context.language)],
59                tables=[{rsc,"r"}]
60            }
61    end;
62search(_, _, _) ->
63    undefined.