From: rich Date: Wed, 22 Sep 2004 10:19:25 +0000 (+0000) Subject: Added the can_manage_site and can_edit_global_css permissions. X-Git-Url: http://git.annexia.org/?a=commitdiff_plain;h=0d88075fa62c0a801ea1e9246d85389f9161a4e1;p=cocanwiki.git Added the can_manage_site and can_edit_global_css permissions. Added hosts.feedback_email field to the database. Moved the edit menu around to make it slightly more logical. --- diff --git a/cocanwiki.sql b/cocanwiki.sql index 32b0387..f919920 100644 --- a/cocanwiki.sql +++ b/cocanwiki.sql @@ -112,7 +112,8 @@ CREATE TABLE hosts ( css text, edit_anon boolean DEFAULT true NOT NULL, create_account_anon boolean DEFAULT true NOT NULL, - theme_css text + theme_css text, + feedback_email text ); @@ -284,7 +285,9 @@ CREATE TABLE users ( registration_date date DEFAULT ('now'::text)::date NOT NULL, can_edit boolean DEFAULT true NOT NULL, can_manage_users boolean DEFAULT false NOT NULL, - can_manage_contacts boolean DEFAULT false NOT NULL + can_manage_contacts boolean DEFAULT false NOT NULL, + can_manage_site boolean DEFAULT false NOT NULL, + can_edit_global_css boolean DEFAULT false NOT NULL ); diff --git a/scripts/cocanwiki.ml b/scripts/cocanwiki.ml index ae07362..55097e4 100644 --- a/scripts/cocanwiki.ml +++ b/scripts/cocanwiki.ml @@ -1,7 +1,7 @@ (* COCANWIKI - a wiki written in Objective CAML. * Written by Richard W.M. Jones . * Copyright (C) 2004 Merjis Ltd. - * $Id: cocanwiki.ml,v 1.8 2004/09/20 15:34:36 rich Exp $ + * $Id: cocanwiki.ml,v 1.9 2004/09/22 10:19:26 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 @@ -47,6 +47,7 @@ exception CgiExit * register_script ~restrict:[CanEdit ; CanManageUsers] run *) type permissions_t = CanEdit | CanManageUsers | CanManageContacts + | CanManageSite | CanEditGlobalCSS (* The "user object". *) type user_t = Anonymous (* Not logged in. *) @@ -62,6 +63,8 @@ let test_permission edit_anon perm user = let can_edit edit_anon = test_permission edit_anon CanEdit let can_manage_users = test_permission false CanManageUsers let can_manage_contacts = test_permission false CanManageContacts +let can_manage_site = test_permission false CanManageSite +let can_edit_global_css = test_permission false CanEditGlobalCSS (* The "host object". *) type host_t = { hostname : string; @@ -147,19 +150,29 @@ let register_script ?(restrict = []) ?(anonymous = true) run = let sth = dbh#prepare_cached "select u.id, u.name, u.can_edit, u.can_manage_users, - u.can_manage_contacts + u.can_manage_contacts, u.can_manage_site, + u.can_edit_global_css from usercookies uc, users u where uc.cookie = ? and uc.userid = u.id and u.hostid = ?" in sth#execute [`String cookie; `Int hostid]; (match sth#fetch1 () with [ `Int userid; `String name; `Bool can_edit; `Bool can_manage_users; - `Bool can_manage_contacts ] -> + `Bool can_manage_contacts; `Bool can_manage_site; + `Bool can_edit_global_css ] -> + let perms = if can_edit then [ CanEdit ] else [] in let perms = - (if can_edit then [ CanEdit ] else []) @ - (if can_manage_users then [ CanManageUsers ] else []) @ - (if can_manage_contacts then [ CanManageContacts ] else []) - in + if can_manage_users then CanManageUsers :: perms + else perms in + let perms = + if can_manage_contacts then CanManageContacts :: perms + else perms in + let perms = + if can_manage_site then CanManageSite :: perms + else perms in + let perms = + if can_edit_global_css then CanEditGlobalCSS :: perms + else perms in User (userid, name, perms) | _ -> assert false) with @@ -175,7 +188,7 @@ let register_script ?(restrict = []) ?(anonymous = true) run = match restrict with [] -> true (* empty list = no restrictions *) | rs -> - List.fold_left ((||)) false + List.fold_left (||) false (List.map (fun r -> test_permission edit_anon r user) rs) in if permitted then ( diff --git a/scripts/create_user.ml b/scripts/create_user.ml index dc72b3b..2e08209 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.1 2004/09/21 13:01:15 rich Exp $ + * $Id: create_user.ml,v 1.2 2004/09/22 10:19:26 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 @@ -71,15 +71,19 @@ let run r (q : cgi) (dbh : Dbi.connection) hostid _ _ = let can_edit = q#param_true "can_edit" in let can_manage_users = q#param_true "can_manage_users" in let can_manage_contacts = q#param_true "can_manage_contacts" in + let can_manage_site = q#param_true "can_manage_site" in + let can_edit_global_css = q#param_true "can_edit_global_css" in (* Create the user account. *) let sth = dbh#prepare_cached "insert into users (name, password, email, hostid, can_edit, can_manage_users, - can_manage_contacts) - values (?, ?, ?, ?, ?, ?, ?)" in + can_manage_contacts, can_manage_site, + can_edit_global_css) + values (?, ?, ?, ?, ?, ?, ?, ?, ?)" in sth#execute [`String username; `String password; email; `Int hostid; `Bool can_edit; `Bool can_manage_users; - `Bool can_manage_contacts]; + `Bool can_manage_contacts; `Bool can_manage_site; + `Bool can_edit_global_css]; dbh#commit (); diff --git a/scripts/edit_user.ml b/scripts/edit_user.ml index 38f98b3..7f2148e 100644 --- a/scripts/edit_user.ml +++ b/scripts/edit_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: edit_user.ml,v 1.4 2004/09/17 15:24:54 rich Exp $ + * $Id: edit_user.ml,v 1.5 2004/09/22 10:19:26 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 @@ -73,6 +73,8 @@ let run r (q : cgi) (dbh : Dbi.connection) hostid _ self = let can_edit = q#param_true "can_edit" in let can_manage_users = q#param_true "can_manage_users" in let can_manage_contacts = q#param_true "can_manage_contacts" in + let can_manage_site = q#param_true "can_manage_site" in + let can_edit_global_css = q#param_true "can_edit_global_css" in (* Trying to remove manage users permission from self? *) (match can_manage_users, self with @@ -86,10 +88,13 @@ let run r (q : cgi) (dbh : Dbi.connection) hostid _ self = let sth = dbh#prepare_cached "update users set email = ?, can_edit = ?, can_manage_users = ?, - can_manage_contacts = ? + can_manage_contacts = ?, + can_manage_site = ?, + can_edit_global_css = ? where hostid = ? and id = ?" in sth#execute [email; `Bool can_edit; `Bool can_manage_users; - `Bool can_manage_contacts; + `Bool can_manage_contacts; `Bool can_manage_site; + `Bool can_edit_global_css; `Int hostid; `Int userid]; (* Finish up. *) diff --git a/scripts/edit_user_form.ml b/scripts/edit_user_form.ml index 9574081..26e0a2f 100644 --- a/scripts/edit_user_form.ml +++ b/scripts/edit_user_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_user_form.ml,v 1.5 2004/09/17 15:24:54 rich Exp $ + * $Id: edit_user_form.ml,v 1.6 2004/09/22 10:19:26 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 @@ -37,6 +37,7 @@ let run r (q : cgi) (dbh : Dbi.connection) hostid _ _ = dbh#prepare_cached "select u.name, u.email, u.registration_date, u.can_edit, u.can_manage_users, u.can_manage_contacts, + u.can_manage_site, u.can_edit_global_css, (select count(*) from pages where logged_user = u.id), (select count(*) from pages where logged_user = u.id and url_deleted is null) @@ -44,14 +45,17 @@ let run r (q : cgi) (dbh : Dbi.connection) hostid _ _ = sth#execute [`Int hostid; `Int userid]; let name, email, registration_date, can_edit, can_manage_users, - can_manage_contacts, nr_edits, nr_edits_live = + can_manage_contacts, can_manage_site, can_edit_global_css, + nr_edits, nr_edits_live = match sth#fetch1 () with [`String name; (`Null | `String _) as email; `Date registration_date; `Bool can_edit; `Bool can_manage_users; `Bool can_manage_contacts; + `Bool can_manage_site; `Bool can_edit_global_css; `Int nr_edits; `Int nr_edits_live] -> name, email, registration_date, can_edit, can_manage_users, - can_manage_contacts, nr_edits, nr_edits_live + can_manage_contacts, can_manage_site, can_edit_global_css, + nr_edits, nr_edits_live | _ -> assert false in template#set "userid" (string_of_int userid); @@ -61,6 +65,8 @@ let run r (q : cgi) (dbh : Dbi.connection) hostid _ _ = template#conditional "can_edit" can_edit; template#conditional "can_manage_users" can_manage_users; template#conditional "can_manage_contacts" can_manage_contacts; + template#conditional "can_manage_site" can_manage_site; + template#conditional "can_edit_global_css" can_edit_global_css; template#set "nr_edits" (string_of_int nr_edits); template#set "nr_edits_live" (string_of_int nr_edits_live); diff --git a/scripts/page.ml b/scripts/page.ml index 3ff3e01..03c3537 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.16 2004/09/20 17:18:26 rich Exp $ + * $Id: page.ml,v 1.17 2004/09/22 10:19:26 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 @@ -60,6 +60,8 @@ let run r (q : cgi) (dbh : Dbi.connection) hostid {edit_anon=edit_anon} user = let can_edit = can_edit edit_anon user in let can_manage_users = can_manage_users user in let can_manage_contacts = can_manage_contacts user in + let can_manage_site = can_manage_site user in + let can_edit_global_css = can_edit_global_css user in (* This code generates ordinary pages. *) let make_page title description pageid last_modified_date has_page_css @@ -87,6 +89,8 @@ let run r (q : cgi) (dbh : Dbi.connection) hostid {edit_anon=edit_anon} user = 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; (* Pull out the sections in this page. *) let sth = dbh#prepare_cached @@ -163,6 +167,8 @@ let run r (q : cgi) (dbh : Dbi.connection) hostid {edit_anon=edit_anon} user = 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; q#template t in diff --git a/scripts/users.ml b/scripts/users.ml index 1f1b033..120998d 100644 --- a/scripts/users.ml +++ b/scripts/users.ml @@ -1,7 +1,7 @@ (* COCANWIKI - a wiki written in Objective CAML. * Written by Richard W.M. Jones . * Copyright (C) 2004 Merjis Ltd. - * $Id: users.ml,v 1.5 2004/09/17 15:24:54 rich Exp $ + * $Id: users.ml,v 1.6 2004/09/22 10:19:26 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 @@ -34,7 +34,7 @@ let run r (q : cgi) (dbh : Dbi.connection) hostid _ _ = let sth = dbh#prepare_cached "select id, name, email, registration_date, can_edit, can_manage_users, - can_manage_contacts + can_manage_contacts, can_manage_site, can_edit_global_css from users where hostid = ? order by name" in sth#execute [`Int hostid]; @@ -44,7 +44,8 @@ let run r (q : cgi) (dbh : Dbi.connection) hostid _ _ = [`Int userid; `String name; (`Null | `String _) as email; `Date registration_date; `Bool can_edit; `Bool can_manage_users; - `Bool can_manage_contacts] -> + `Bool can_manage_contacts; `Bool can_manage_site; + `Bool can_edit_global_css] -> let email = match email with `Null -> "" | `String s -> s in [ "userid", Template.VarString (string_of_int userid); "name", Template.VarString name; @@ -54,7 +55,10 @@ let run r (q : cgi) (dbh : Dbi.connection) hostid _ _ = "can_edit", Template.VarConditional can_edit; "can_manage_users", Template.VarConditional can_manage_users; "can_manage_contacts", - Template.VarConditional can_manage_contacts ] + Template.VarConditional can_manage_contacts; + "can_manage_site", Template.VarConditional can_manage_site; + "can_edit_global_css", + Template.VarConditional can_edit_global_css; ] | _ -> assert false) in template#table "users" table; diff --git a/templates/create_user_form.html b/templates/create_user_form.html index 5dc64fa..3de4413 100644 --- a/templates/create_user_form.html +++ b/templates/create_user_form.html @@ -41,6 +41,10 @@
+
+ +
+ diff --git a/templates/edit_user_form.html b/templates/edit_user_form.html index f5189be..35b325f 100644 --- a/templates/edit_user_form.html +++ b/templates/edit_user_form.html @@ -36,6 +36,10 @@
+
+ +
+ diff --git a/templates/page.html b/templates/page.html index 91d8735..77075fa 100644 --- a/templates/page.html +++ b/templates/page.html @@ -61,18 +61,24 @@
  • Edit this page
  • Recent changes
  • Versions of this page
  • -
  • Images
  • -
  • Files
  • -
  • Largest pages
  • Edit stylesheet for this page
  • Edit site menu
  • +
  • Largest pages
  • +
  • Images
  • +
  • Files
  • ::end:: ::if(can_manage_users):: -
  • Manage users
  • +
  • Users
  • ::end:: ::if(can_manage_contacts)::
  • Contact forms
  • ::end:: +::if(can_manage_site):: +
  • Global settings
  • +::end:: +::if(can_edit_global_css):: +
  • Edit global stylesheet
  • +::end:: ::if(can_edit)::
  • Server administration
  • ::end:: diff --git a/templates/users.html b/templates/users.html index 6248630..983e386 100644 --- a/templates/users.html +++ b/templates/users.html @@ -18,12 +18,14 @@ Username Email address Registration - Permissions + Permissions Edit Manage users Manage contacts + Manage site + Edit global stylesheet ::table(users):: @@ -34,6 +36,8 @@ ::if(can_edit)::Can edit::end:: ::if(can_manage_users)::Can manage users::end:: ::if(can_manage_contacts)::Can manage contacts::end:: + ::if(can_manage_site)::Can manage site::end:: + ::if(can_edit_global_css)::Can edit global stylesheet::end:: ::end:: @@ -93,6 +97,31 @@ and delete contact forms. +
    Manage site
    +
    + +

    +If set, user may: +

    + +
      +
    • control the global theme for the site
    • +
    • set whether anonymous editing and signup are allowed (note: this will allow them to indirectly create extra user accounts)
    • +
    • set email address for feedback
    • +
    + +
    + +
    Edit global stylesheet
    +
    + +

    +If set, user may edit the global stylesheet which controls +the look and feel of the site across all pages. +

    + +
    +