From b36e5c1ab955fc9cb3169f54373037c6bc2903a2 Mon Sep 17 00:00:00 2001 From: rich Date: Sat, 23 Oct 2004 09:36:10 +0000 Subject: [PATCH] Simplified edit menu. "Sitewide settings" menu now gets the other entries which used be on the edit menu. When creating new users, don't allow setting email address. Fixed permissions problem with edit_host_css scripts. --- html/_css/standard.css | 10 ++-- scripts/create_user.ml | 11 ++-- scripts/edit_host_css.ml | 4 +- scripts/edit_host_css_form.ml | 4 +- scripts/host_menu.ml | 110 ++++++++++++++++++++++------------------ scripts/page.ml | 19 +------ templates/create_user_form.html | 4 -- templates/host_menu.html | 35 +++++++++++-- templates/page.html | 37 +++++--------- 9 files changed, 122 insertions(+), 112 deletions(-) diff --git a/html/_css/standard.css b/html/_css/standard.css index 77fe8ed..7f90b88 100644 --- a/html/_css/standard.css +++ b/html/_css/standard.css @@ -1,5 +1,5 @@ /* Stylesheet for COCANWIKI. - * $Id: standard.css,v 1.21 2004/10/22 17:17:42 rich Exp $ + * $Id: standard.css,v 1.22 2004/10/23 09:36:10 rich Exp $ */ /* Based on the basic stylesheet. */ @@ -197,7 +197,7 @@ li.maillist_li a { } li.recent_li a { - padding-left: 16px; + padding-left: 18px; background: url(/_graphics/recent.png) center left no-repeat; } @@ -206,9 +206,9 @@ li.sitemap_li a { background: url(/_graphics/sitemap.png) center left no-repeat; } -li.recent_li a { - padding-left: 18px; - background: url(/_graphics/recent.png) center left no-repeat; +li.stylesheet_li a { + padding-left: 16px; + background: url(/_graphics/edit.png) center left no-repeat; } li.versions_li a { diff --git a/scripts/create_user.ml b/scripts/create_user.ml index 2767434..b8b8e6c 100644 --- a/scripts/create_user.ml +++ b/scripts/create_user.ml @@ -1,7 +1,7 @@ (* COCANWIKI - a wiki written in Objective CAML. * Written by Richard W.M. Jones . * Copyright (C) 2004 Merjis Ltd. - * $Id: create_user.ml,v 1.4 2004/10/11 14:13:04 rich Exp $ + * $Id: create_user.ml,v 1.5 2004/10/23 09:36:11 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 @@ -52,9 +52,6 @@ let run r (q : cgi) (dbh : Dbi.connection) hostid _ _ = if String.length username > 32 || String.length password > 32 then *) - let email = trim (q#param "email") in - let email = if string_is_whitespace email then `Null else `String email in - (* Not a duplicate? *) let sth = dbh#prepare_cached "select id from users where hostid = ? and name = ?" in @@ -77,13 +74,13 @@ let run r (q : cgi) (dbh : Dbi.connection) hostid _ _ = let force_password_change = q#param_true "force_password_change" in (* Create the user account. *) - let sth = dbh#prepare_cached "insert into users (name, password, email, + let sth = dbh#prepare_cached "insert into users (name, password, hostid, can_edit, can_manage_users, can_manage_contacts, can_manage_site, can_edit_global_css, can_import_mail, force_password_change) - values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)" in - sth#execute [`String username; `String password; email; `Int hostid; + values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)" in + sth#execute [`String username; `String password; `Int hostid; `Bool can_edit; `Bool can_manage_users; `Bool can_manage_contacts; `Bool can_manage_site; `Bool can_edit_global_css; `Bool can_import_mail; diff --git a/scripts/edit_host_css.ml b/scripts/edit_host_css.ml index b1a0b5c..7d48632 100644 --- a/scripts/edit_host_css.ml +++ b/scripts/edit_host_css.ml @@ -1,7 +1,7 @@ (* COCANWIKI - a wiki written in Objective CAML. * Written by Richard W.M. Jones . * Copyright (C) 2004 Merjis Ltd. - * $Id: edit_host_css.ml,v 1.2 2004/10/04 15:19:56 rich Exp $ + * $Id: edit_host_css.ml,v 1.3 2004/10/23 09:36:11 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 @@ -54,4 +54,4 @@ let run r (q : cgi) (dbh : Dbi.connection) hostid _ _ = "Note: You must RELOAD the page to see changes to stylesheets.") let () = - register_script ~restrict:[CanEdit] run + register_script ~restrict:[CanEditGlobalCSS] run diff --git a/scripts/edit_host_css_form.ml b/scripts/edit_host_css_form.ml index 3a51d28..1bef710 100644 --- a/scripts/edit_host_css_form.ml +++ b/scripts/edit_host_css_form.ml @@ -1,7 +1,7 @@ (* COCANWIKI - a wiki written in Objective CAML. * Written by Richard W.M. Jones . * Copyright (C) 2004 Merjis Ltd. - * $Id: edit_host_css_form.ml,v 1.2 2004/10/04 15:19:56 rich Exp $ + * $Id: edit_host_css_form.ml,v 1.3 2004/10/23 09:36:11 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 @@ -44,4 +44,4 @@ let run r (q : cgi) (dbh : Dbi.connection) hostid _ _ = q#template template let () = - register_script ~restrict:[CanEdit] run + register_script ~restrict:[CanEditGlobalCSS] run diff --git a/scripts/host_menu.ml b/scripts/host_menu.ml index 4a03afa..7806efc 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.5 2004/10/10 16:14:43 rich Exp $ + * $Id: host_menu.ml,v 1.6 2004/10/23 09:36:11 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,59 +27,71 @@ open Printf open Cocanwiki open Cocanwiki_template -let run r (q : cgi) (dbh : Dbi.connection) hostid _ _ = +let run r (q : cgi) (dbh : Dbi.connection) 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, h.navigation, h.view_anon - 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_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_manage_site" can_manage_site; - 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, navigation, view_anon = - 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; `Bool navigation; - `Bool view_anon ] -> - let theme_name = - match theme_name with `String s -> s | `Null -> "" in - let theme_description = - match theme_description with `String s -> s | `Null -> "" in - let feedback_email, has_feedback_email = - match feedback_email with - `String s -> s, true - | `Null -> "", false 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, navigation, view_anon - | _ -> assert false in + if can_manage_site then ( + (* 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, h.navigation, h.view_anon + from hosts h left outer join themes t on h.theme_css = t.theme_css + where h.id = ?" in + sth#execute [`Int hostid]; - 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 "navigation" navigation; - template#conditional "view_anon" view_anon; + 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, navigation, view_anon = + 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; `Bool navigation; + `Bool view_anon ] -> + let theme_name = + match theme_name with `String s -> s | `Null -> "" in + let theme_description = + match theme_description with `String s -> s | `Null -> "" in + let feedback_email, has_feedback_email = + match feedback_email with + `String s -> s, true + | `Null -> "", false 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, navigation, view_anon + | _ -> 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#conditional "navigation" navigation; + template#conditional "view_anon" view_anon + ); q#template template let () = - register_script ~restrict:[CanManageSite] run + register_script ~restrict:[CanEdit] run diff --git a/scripts/page.ml b/scripts/page.ml index 3657919..091f213 100644 --- a/scripts/page.ml +++ b/scripts/page.ml @@ -1,7 +1,7 @@ (* COCANWIKI - a wiki written in Objective CAML. * Written by Richard W.M. Jones . * Copyright (C) 2004 Merjis Ltd. - * $Id: page.ml,v 1.33 2004/10/17 19:43:19 rich Exp $ + * $Id: page.ml,v 1.34 2004/10/23 09:36:11 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 @@ -76,12 +76,8 @@ let run r (q : cgi) (dbh : Dbi.connection) hostid navigation | _ -> assert false in - (* Can the user edit? Manage users? etc. *) + (* Can the user edit? *) let can_edit = can_edit host user in - let can_manage_users = can_manage_users host user in - let can_manage_contacts = can_manage_contacts host user in - let can_manage_site = can_manage_site host user in - let can_edit_global_css = can_edit_global_css host user in (* Do we have a stats page set up? *) let has_stats = server_settings_stats_page dbh <> None in @@ -202,11 +198,6 @@ let run r (q : cgi) (dbh : Dbi.connection) hostid t#conditional "navigation" navigation; t#conditional "can_edit" can_edit; - t#conditional "can_manage_users" can_manage_users; - t#conditional "can_manage_contacts" can_manage_contacts; - t#conditional "can_manage_site" can_manage_site; - t#conditional "can_edit_global_css" can_edit_global_css; - t#conditional "has_stats" has_stats; (* Pull out the sections in this page. *) @@ -384,13 +375,7 @@ let run r (q : cgi) (dbh : Dbi.connection) hostid t#set "search_terms" search_terms; t#conditional "has_host_css" has_host_css; - t#conditional "can_edit" can_edit; - t#conditional "can_manage_users" can_manage_users; - t#conditional "can_manage_contacts" can_manage_contacts; - t#conditional "can_manage_site" can_manage_site; - t#conditional "can_edit_global_css" can_edit_global_css; - t#conditional "has_stats" has_stats; q#template t diff --git a/templates/create_user_form.html b/templates/create_user_form.html index bf9767e..1231dbf 100644 --- a/templates/create_user_form.html +++ b/templates/create_user_form.html @@ -34,10 +34,6 @@ - Email: - - - Permissions: diff --git a/templates/host_menu.html b/templates/host_menu.html index a759fa0..faa2a63 100644 --- a/templates/host_menu.html +++ b/templates/host_menu.html @@ -1,13 +1,38 @@ -Global settings +Sitewide settings -

Global settings

+

Sitewide settings

+ + + +::if(can_manage_site):: + +

Site management

@@ -17,7 +42,10 @@ +::if(can_edit_global_css):: +Edit global stylesheet ... +::end:: + @@ -68,6 +96,7 @@ +::end:: ::include(footer.html):: diff --git a/templates/page.html b/templates/page.html index 03974ad..81fe534 100644 --- a/templates/page.html +++ b/templates/page.html @@ -61,46 +61,37 @@ -- 1.8.3.1
Global stylesheet: ::if(has_global_css)::View global stylesheet::else::No global stylesheet for this site.::end::
-Edit global stylesheet ...
Allow anyone to see the site: