/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. %% 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(mod_admin_identity).
  19. -author("Marc Worrell <marc@worrell.nl>").
  20. -mod_title("Admin identity/user supports").
  21. -mod_description("Adds an user overview and possibility to edit passwords.").
  22. %% interface functions
  23. -export([
  24. observe_search_query/2
  25. ]).
  26. -include("zotonic.hrl").
  27. observe_search_query({search_query, Req, OffsetLimit}, Context) ->
  28. search(Req, OffsetLimit, Context).
  29. %%====================================================================
  30. %% support functions
  31. %%====================================================================
  32. search({users, [{text,QueryText}]}, _OffsetLimit, Context) ->
  33. case QueryText of
  34. A when A == undefined orelse A == "" orelse A == <<>> ->
  35. #search_sql{
  36. select="r.id, max(r.modified) AS rank",
  37. from="rsc r join identity i on r.id = i.rsc_id",
  38. order="rank desc",
  39. group_by="r.id",
  40. tables=[{rsc,"r"}]
  41. };
  42. _ ->
  43. #search_sql{
  44. select="r.id, max(ts_rank_cd(pivot_tsv, query, 32)) AS rank",
  45. from="rsc r join identity i on r.id = i.rsc_id, plainto_tsquery($2, $1) query",
  46. where=" query @@ pivot_tsv",
  47. order="rank desc",
  48. group_by="r.id",
  49. args=[QueryText, z_pivot_rsc:pg_lang(Context#context.language)],
  50. tables=[{rsc,"r"}]
  51. }
  52. end;
  53. search(_, _, _) ->
  54. undefined.