Added the can_manage_site and can_edit_global_css permissions.
authorrich <rich>
Wed, 22 Sep 2004 10:19:25 +0000 (10:19 +0000)
committerrich <rich>
Wed, 22 Sep 2004 10:19:25 +0000 (10:19 +0000)
Added hosts.feedback_email field to the database.
Moved the edit menu around to make it slightly more logical.

cocanwiki.sql
scripts/cocanwiki.ml
scripts/create_user.ml
scripts/edit_user.ml
scripts/edit_user_form.ml
scripts/page.ml
scripts/users.ml
templates/create_user_form.html
templates/edit_user_form.html
templates/page.html
templates/users.html

index 32b0387..f919920 100644 (file)
@@ -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
 );
 
 
index ae07362..55097e4 100644 (file)
@@ -1,7 +1,7 @@
 (* COCANWIKI - a wiki written in Objective CAML.
  * Written by Richard W.M. Jones <rich@merjis.com>.
  * 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 (
index dc72b3b..2e08209 100644 (file)
@@ -1,7 +1,7 @@
 (* COCANWIKI - a wiki written in Objective CAML.
  * Written by Richard W.M. Jones <rich@merjis.com>.
  * 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 ();
 
index 38f98b3..7f2148e 100644 (file)
@@ -1,7 +1,7 @@
 (* COCANWIKI - a wiki written in Objective CAML.
  * Written by Richard W.M. Jones <rich@merjis.com>.
  * 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. *)
index 9574081..26e0a2f 100644 (file)
@@ -1,7 +1,7 @@
 (* COCANWIKI - a wiki written in Objective CAML.
  * Written by Richard W.M. Jones <rich@merjis.com>.
  * 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);
 
index 3ff3e01..03c3537 100644 (file)
@@ -1,7 +1,7 @@
 (* COCANWIKI - a wiki written in Objective CAML.
  * Written by Richard W.M. Jones <rich@merjis.com>.
  * 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
index 1f1b033..120998d 100644 (file)
@@ -1,7 +1,7 @@
 (* COCANWIKI - a wiki written in Objective CAML.
  * Written by Richard W.M. Jones <rich@merjis.com>.
  * 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;
index 5dc64fa..3de4413 100644 (file)
 <input id="can_manage_users" type="checkbox" name="can_manage_users" value="1"/><label for="can_manage_users">Manage users</label>
 <br/>
 <input id="can_manage_contacts" type="checkbox" name="can_manage_contacts" value="1"/><label for="can_manage_contacts">Manage contacts</label>
+<br/>
+<input id="can_manage_site" type="checkbox" name="can_manage_site" value="1"/><label for="can_manage_site">Manage site</label>
+<br/>
+<input id="can_edit_global_css" type="checkbox" name="can_edit_global_css" value="1"/><label for="can_edit_global_css">Edit global stylesheet</label>
 </td>
 </tr>
 <tr>
index f5189be..35b325f 100644 (file)
 <input id="can_manage_users" type="checkbox" name="can_manage_users" value="1" ::if(can_manage_users)::checked="checked"::end::/><label for="can_manage_users">Manage users</label>
 <br/>
 <input id="can_manage_contacts" type="checkbox" name="can_manage_contacts" value="1" ::if(can_manage_contacts)::checked="checked"::end::/><label for="can_manage_contacts">Manage contacts</label>
+<br/>
+<input id="can_manage_site" type="checkbox" name="can_manage_site" value="1" ::if(can_manage_site)::checked="checked"::end::/><label for="can_manage_site">Manage site</label>
+<br/>
+<input id="can_edit_global_css" type="checkbox" name="can_edit_global_css" value="1" ::if(can_edit_global_css)::checked="checked"::end::/><label for="can_edit_global_css">Edit global stylesheet</label>
 </td>
 </tr>
 <tr>
index 91d8735..77075fa 100644 (file)
 <li> <a href="/::page_html_tag::/edit"><strong>Edit this page</strong></a> </li>
 <li> <a href="/_recent">Recent changes</a> </li>
 <li> <a href="/::page_html_tag::/history">Versions of this page</a> </li>
-<li> <a href="/_images">Images</a> </li>
-<li> <a href="/_files">Files</a> </li>
-<li> <a href="/_bin/largest_pages.cmo">Largest pages</a> </li>
 <li> <a href="/::page_html_tag::/editcss">Edit stylesheet for this page</a> </li>
 <li> <a href="/_bin/edit_sitemenu.cmo">Edit site menu</a> </li>
+<li> <a href="/_bin/largest_pages.cmo">Largest pages</a> </li>
+<li> <a href="/_images">Images</a> </li>
+<li> <a href="/_files">Files</a> </li>
 ::end::
 ::if(can_manage_users)::
-<li> <a href="/_users">Manage users</a> </li>
+<li> <a href="/_users">Users</a> </li>
 ::end::
 ::if(can_manage_contacts)::
 <li> <a href="/_bin/contacts.cmo">Contact forms</a> </li>
 ::end::
+::if(can_manage_site)::
+<li> <a href="/_bin/sitemenu.cmo">Global settings</a> </li>
+::end::
+::if(can_edit_global_css)::
+<li> <a href="/_bin/edit_host_css_form.cmo">Edit global stylesheet</a> </li>
+::end::
 ::if(can_edit)::
 <li> <a href="/_admin">Server administration</a> </li>
 ::end::
index 6248630..983e386 100644 (file)
 <th rowspan="2"> Username </th>
 <th rowspan="2"> Email address </th>
 <th rowspan="2"> Registration </th>
-<th colspan="3"> Permissions </th>
+<th colspan="5"> Permissions </th>
 </tr>
 <tr>
 <th> Edit </th>
 <th> Manage users </th>
 <th> Manage contacts </th>
+<th> Manage site </th>
+<th> Edit global stylesheet </th>
 </tr>
 
 ::table(users)::
@@ -34,6 +36,8 @@
 <td> ::if(can_edit)::<img src="/_graphics/tick.png" width="10" height="10" alt="Can edit"/>::end:: </td>
 <td> ::if(can_manage_users)::<img src="/_graphics/tick.png" width="10" height="10" alt="Can manage users"/>::end:: </td>
 <td> ::if(can_manage_contacts)::<img src="/_graphics/tick.png" width="10" height="10" alt="Can manage contacts"/>::end:: </td>
+<td> ::if(can_manage_site)::<img src="/_graphics/tick.png" width="10" height="10" alt="Can manage site"/>::end:: </td>
+<td> ::if(can_edit_global_css)::<img src="/_graphics/tick.png" width="10" height="10" alt="Can edit global stylesheet"/>::end:: </td>
 </tr>
 ::end::
 
@@ -93,6 +97,31 @@ and delete contact forms.
 
 </dd>
 
+<dt> <strong>Manage site</strong> </dt>
+<dd>
+
+<p>
+If set, user may:
+</p>
+
+<ul>
+<li>control the global theme for the site</li>
+<li>set whether anonymous editing and signup are allowed (<strong>note:</strong> this will allow them to indirectly create extra user accounts)</li>
+<li>set email address for feedback</li>
+</ul>
+
+</dd>
+
+<dt> <strong>Edit global stylesheet</strong> </dt>
+<dd>
+
+<p>
+If set, user may edit the global stylesheet which controls
+the look and feel of the site across all pages.
+</p>
+
+</dd>
+
 </dl>
 
 <ul id="topmenu" class="menu">