X-Git-Url: http://git.annexia.org/?a=blobdiff_plain;f=scripts%2Fhost_menu.ml;h=59909eb16665b5ff51513c2abafa9ab6dad0cd30;hb=8a6ae4a5a2f14da7b1fe0bf6bf95e3100856a079;hp=ee67282c90e4b037f26e2ba0ea3cd11f1077816b;hpb=df32ab1d0dd164b73cfa9607797eaf85e0a0154d;p=cocanwiki.git diff --git a/scripts/host_menu.ml b/scripts/host_menu.ml index ee67282..59909eb 100644 --- a/scripts/host_menu.ml +++ b/scripts/host_menu.ml @@ -1,7 +1,7 @@ (* COCANWIKI - a wiki written in Objective CAML. * Written by Richard W.M. Jones . * Copyright (C) 2004 Merjis Ltd. - * $Id: host_menu.ml,v 1.3 2004/09/27 16:21:09 rich Exp $ + * $Id: host_menu.ml,v 1.11 2006/08/14 10:04:25 rich Exp $ * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -27,56 +27,91 @@ open Printf open Cocanwiki open Cocanwiki_template -let run r (q : cgi) (dbh : Dbi.connection) hostid _ _ = +let run r (q : cgi) dbh hostid host user = let template = get_template dbh hostid "host_menu.html" in - (* Get lots of host-specific stuff from the database. *) - let sth = - dbh#prepare_cached - "select h.canonical_hostname, h.css is not null, h.edit_anon, - h.create_account_anon, h.theme_css is not null, - t.name, t.description, h.feedback_email, h.mailing_list, - h.search_box - from hosts h left outer join themes t on h.theme_css = t.theme_css - where h.id = ?" in - sth#execute [`Int hostid]; + (* Get user's specific permissions. *) + let can_manage_users = can_manage_users host user in + let can_manage_contacts = can_manage_contacts host user in + let can_edit_global_css = can_edit_global_css host user in + let can_edit_macros = can_edit_macros host user in + let can_manage_site = can_manage_site host user in + template#conditional "can_manage_users" can_manage_users; + template#conditional "can_manage_contacts" can_manage_contacts; + template#conditional "can_edit_global_css" can_edit_global_css; + template#conditional "can_edit_macros" can_edit_macros; + template#conditional "can_manage_site" can_manage_site; - let canonical_hostname, has_global_css, edit_anon, create_account_anon, + if can_manage_site then ( + (* Get lots of host-specific stuff from the database. *) + let rows = + PGSQL(dbh) "nullable-results" + "select h.canonical_hostname, h.css is not null, h.edit_anon, + h.create_account_anon, h.theme_css is not null, + t.name, t.description, h.feedback_email, h.mailing_list, + h.search_box, h.navigation, h.view_anon, + h.brand, coalesce (h.brand_tagline, ''), + coalesce (h.brand_description, ''), + h.ie_imagetoolbar_no + from hosts h left outer join themes t on h.theme_css = t.theme_css + where h.id = $hostid" in + + let canonical_hostname, has_global_css, edit_anon, create_account_anon, has_theme_css, theme_name, theme_description, has_feedback_email, - feedback_email, mailing_list, search_box = - match sth#fetch1 () with - [ `String canonical_hostname; `Bool has_global_css; - `Bool edit_anon; `Bool create_account_anon; `Bool has_theme_css; - (`String _ | `Null) as theme_name; - (`String _ | `Null) as theme_description; - (`String _ | `Null) as feedback_email; - `Bool mailing_list; `Bool search_box ] -> + feedback_email, mailing_list, search_box, navigation, view_anon, + has_brand, brand, brand_tagline, brand_description, + ie_imagetoolbar_no = + match rows with + [ Some canonical_hostname, Some has_global_css, + Some edit_anon, Some create_account_anon, Some has_theme_css, + theme_name, theme_description, + feedback_email, + Some mailing_list, Some search_box, Some navigation, Some view_anon, + brand, brand_tagline, brand_description, Some ie_imagetoolbar_no ] -> let theme_name = - match theme_name with `String s -> s | `Null -> "" in + match theme_name with Some s -> s | None -> "" in let theme_description = - match theme_description with `String s -> s | `Null -> "" in + match theme_description with Some s -> s | None -> "" in let feedback_email, has_feedback_email = match feedback_email with - `String s -> s, true - | `Null -> "", false in + Some s -> s, true + | None -> "", false in + let brand, has_brand = + match brand with + Some s -> s, true + | None -> "", false in + let brand_tagline = + match brand_tagline with None -> "" | Some s -> s in + let brand_description = + match brand_description with None -> "" | Some s -> s in canonical_hostname, has_global_css, edit_anon, create_account_anon, has_theme_css, theme_name, theme_description, has_feedback_email, - feedback_email, mailing_list, search_box + feedback_email, mailing_list, search_box, navigation, view_anon, + has_brand, brand, brand_tagline, brand_description, + ie_imagetoolbar_no | _ -> assert false in - template#set "canonical_hostname" canonical_hostname; - template#conditional "has_global_css" has_global_css; - template#conditional "edit_anon" edit_anon; - template#conditional "create_account_anon" create_account_anon; - template#conditional "has_theme_css" has_theme_css; - template#set "theme_name" theme_name; - template#set "theme_description" theme_description; - template#conditional "has_feedback_email" has_feedback_email; - template#set "feedback_email" feedback_email; - template#conditional "mailing_list" mailing_list; - template#conditional "search_box" search_box; + template#set "canonical_hostname" canonical_hostname; + template#conditional "has_global_css" has_global_css; + template#conditional "edit_anon" edit_anon; + template#conditional "create_account_anon" create_account_anon; + template#conditional "has_theme_css" has_theme_css; + template#set "theme_name" theme_name; + template#set "theme_description" theme_description; + template#conditional "has_feedback_email" has_feedback_email; + template#set "feedback_email" feedback_email; + template#conditional "mailing_list" mailing_list; + template#conditional "search_box" search_box; + template#conditional "ie_imagetoolbar_no" ie_imagetoolbar_no; + template#conditional "navigation" navigation; + template#conditional "view_anon" view_anon; + template#conditional "has_brand" has_brand; + template#set "brand" brand; + template#set "brand_tagline" brand_tagline; + template#set "brand_description" brand_description; + ); q#template template let () = - register_script ~restrict:[CanManageSite] run + register_script ~restrict:[CanEdit] run