User management started.
authorrich <rich>
Wed, 8 Sep 2004 10:42:19 +0000 (10:42 +0000)
committerrich <rich>
Wed, 8 Sep 2004 10:42:19 +0000 (10:42 +0000)
cocanwiki.sql
html/_css/users.css [new file with mode: 0644]
html/_graphics/tick.png [new file with mode: 0644]
scripts/Makefile
scripts/cocanwiki_date.ml
scripts/page.ml
scripts/users.ml [new file with mode: 0644]
templates/page.html
templates/users.html [new file with mode: 0644]

index 85f072f..9471c7e 100644 (file)
@@ -37,7 +37,8 @@ CREATE TABLE pages (
     hostid integer NOT NULL,
     logged_ip text,
     redirect text,
-    css text
+    css text,
+    logged_user integer
 );
 
 
@@ -348,7 +349,7 @@ CREATE UNIQUE INDEX files_name_uq ON files USING btree (hostid, name);
 
 
 --
--- TOC entry 40 (OID 540831)
+-- TOC entry 41 (OID 540831)
 -- Name: users_name_uq; Type: INDEX; Schema: public; Owner: rich
 --
 
@@ -356,6 +357,14 @@ CREATE UNIQUE INDEX users_name_uq ON users USING btree (hostid, name);
 
 
 --
+-- TOC entry 40 (OID 540946)
+-- Name: users_id_uq; Type: INDEX; Schema: public; Owner: rich
+--
+
+CREATE UNIQUE INDEX users_id_uq ON users USING btree (hostid, id);
+
+
+--
 -- TOC entry 29 (OID 536012)
 -- Name: pages_pkey; Type: CONSTRAINT; Schema: public; Owner: rich
 --
@@ -401,7 +410,7 @@ ALTER TABLE ONLY files
 
 
 --
--- TOC entry 41 (OID 540825)
+-- TOC entry 42 (OID 540825)
 -- Name: users_pkey; Type: CONSTRAINT; Schema: public; Owner: rich
 --
 
@@ -410,7 +419,7 @@ ALTER TABLE ONLY users
 
 
 --
--- TOC entry 44 (OID 536029)
+-- TOC entry 47 (OID 536029)
 -- Name: $1; Type: FK CONSTRAINT; Schema: public; Owner: rich
 --
 
@@ -419,7 +428,7 @@ ALTER TABLE ONLY contents
 
 
 --
--- TOC entry 46 (OID 536384)
+-- TOC entry 49 (OID 536384)
 -- Name: $1; Type: FK CONSTRAINT; Schema: public; Owner: rich
 --
 
@@ -428,7 +437,7 @@ ALTER TABLE ONLY hostnames
 
 
 --
--- TOC entry 45 (OID 536394)
+-- TOC entry 48 (OID 536394)
 -- Name: hosts_hostname_cn; Type: FK CONSTRAINT; Schema: public; Owner: rich
 --
 
@@ -437,7 +446,7 @@ ALTER TABLE ONLY hosts
 
 
 --
--- TOC entry 42 (OID 536404)
+-- TOC entry 43 (OID 536404)
 -- Name: $1; Type: FK CONSTRAINT; Schema: public; Owner: rich
 --
 
@@ -446,7 +455,7 @@ ALTER TABLE ONLY pages
 
 
 --
--- TOC entry 47 (OID 536920)
+-- TOC entry 50 (OID 536920)
 -- Name: $1; Type: FK CONSTRAINT; Schema: public; Owner: rich
 --
 
@@ -455,7 +464,7 @@ ALTER TABLE ONLY email_notify
 
 
 --
--- TOC entry 48 (OID 537160)
+-- TOC entry 51 (OID 537160)
 -- Name: $1; Type: FK CONSTRAINT; Schema: public; Owner: rich
 --
 
@@ -464,7 +473,7 @@ ALTER TABLE ONLY images
 
 
 --
--- TOC entry 49 (OID 537175)
+-- TOC entry 52 (OID 537175)
 -- Name: $1; Type: FK CONSTRAINT; Schema: public; Owner: rich
 --
 
@@ -473,7 +482,7 @@ ALTER TABLE ONLY files
 
 
 --
--- TOC entry 43 (OID 539155)
+-- TOC entry 44 (OID 539155)
 -- Name: pages_redirect_cn; Type: FK CONSTRAINT; Schema: public; Owner: rich
 --
 
@@ -482,7 +491,7 @@ ALTER TABLE ONLY pages
 
 
 --
--- TOC entry 50 (OID 540827)
+-- TOC entry 53 (OID 540827)
 -- Name: $1; Type: FK CONSTRAINT; Schema: public; Owner: rich
 --
 
@@ -491,7 +500,7 @@ ALTER TABLE ONLY users
 
 
 --
--- TOC entry 51 (OID 540837)
+-- TOC entry 54 (OID 540837)
 -- Name: $1; Type: FK CONSTRAINT; Schema: public; Owner: rich
 --
 
@@ -499,6 +508,24 @@ ALTER TABLE ONLY usercookies
     ADD CONSTRAINT "$1" FOREIGN KEY (userid) REFERENCES users(id);
 
 
+--
+-- TOC entry 45 (OID 540942)
+-- Name: $2; Type: FK CONSTRAINT; Schema: public; Owner: rich
+--
+
+ALTER TABLE ONLY pages
+    ADD CONSTRAINT "$2" FOREIGN KEY (logged_user) REFERENCES users(id);
+
+
+--
+-- TOC entry 46 (OID 540947)
+-- Name: pages_user_cn; Type: FK CONSTRAINT; Schema: public; Owner: rich
+--
+
+ALTER TABLE ONLY pages
+    ADD CONSTRAINT pages_user_cn FOREIGN KEY (hostid, logged_user) REFERENCES users(hostid, id);
+
+
 SET SESSION AUTHORIZATION 'postgres';
 
 --
diff --git a/html/_css/users.css b/html/_css/users.css
new file mode 100644 (file)
index 0000000..0d20201
--- /dev/null
@@ -0,0 +1,4 @@
+/* Stylesheet for COCANWIKI, derived from EWM.
+ * $Id: users.css,v 1.1 2004/09/08 10:42:20 rich Exp $
+ */
+
diff --git a/html/_graphics/tick.png b/html/_graphics/tick.png
new file mode 100644 (file)
index 0000000..114dee9
Binary files /dev/null and b/html/_graphics/tick.png differ
index 33f24df..4fa484b 100644 (file)
@@ -1,5 +1,5 @@
 # Makefile for COCANWIKI.
-# $Id: Makefile,v 1.6 2004/09/07 17:16:46 rich Exp $
+# $Id: Makefile,v 1.7 2004/09/08 10:42:20 rich Exp $
 
 include ../Makefile.config
 
@@ -58,7 +58,8 @@ OBJS := create.cmo \
        upload_file.cmo \
        upload_file_form.cmo \
        upload_image.cmo \
-       upload_image_form.cmo
+       upload_image_form.cmo \
+       users.cmo
 
 ADMIN_OBJS := \
        admin/admin.cmo \
index 754fac4..38315f2 100644 (file)
@@ -1,7 +1,7 @@
 (* COCANWIKI scripts.
  * Written by Richard W.M. Jones <rich@merjis.com>.
  * Copyright (C) 2004 Merjis Ltd.
- * $Id: cocanwiki_date.ml,v 1.2 2004/09/07 14:58:34 rich Exp $
+ * $Id: cocanwiki_date.ml,v 1.3 2004/09/08 10:42:20 rich Exp $
  *)
 
 open Apache
@@ -21,9 +21,11 @@ let short_month = function
   | _ -> invalid_arg "short_month"
 
 (* Generate a printable datestamp for pages. *)
-let printable_date (date, _) =
+let printable_date' date =
   sprintf "%d %s %04d" date.Dbi.day (short_month date.Dbi.month) date.Dbi.year
 
+let printable_date (date, _) = printable_date' date
+
 let printable_date_time (date, time) =
   sprintf "%d %s %04d %02d:%02d" date.Dbi.day (short_month date.Dbi.month)
     date.Dbi.year time.Dbi.hour time.Dbi.min
index 53e6791..c34af77 100644 (file)
@@ -1,7 +1,7 @@
 (* COCANWIKI scripts.
  * Written by Richard W.M. Jones <rich@merjis.com>.
  * Copyright (C) 2004 Merjis Ltd.
- * $Id: page.ml,v 1.5 2004/09/08 09:54:28 rich Exp $
+ * $Id: page.ml,v 1.6 2004/09/08 10:42:20 rich Exp $
  *)
 
 open Apache
@@ -39,8 +39,9 @@ let run r (q : cgi) (dbh : Dbi.connection) (hostid, _, edit_anon) user =
       | [ `Bool has_host_css ] -> has_host_css
       | _ -> assert false in
 
-  (* Can the user edit? *)
+  (* Can the user edit?  Manage users? *)
   let can_edit = can_edit edit_anon user in
+  let can_manage_users = can_manage_users user in
 
   (* This code generates ordinary pages. *)
   let make_page title description pageid last_modified_date has_page_css
@@ -66,6 +67,7 @@ let run r (q : cgi) (dbh : Dbi.connection) (hostid, _, edit_anon) user =
     t#conditional "has_page_css" has_page_css;
 
     t#conditional "can_edit" can_edit;
+    t#conditional "can_manage_users" can_manage_users;
 
     (* Pull out the sections in this page. *)
     let sth = dbh#prepare_cached
diff --git a/scripts/users.ml b/scripts/users.ml
new file mode 100644 (file)
index 0000000..8fff55c
--- /dev/null
@@ -0,0 +1,46 @@
+(* COCANWIKI scripts.
+ * Written by Richard W.M. Jones <rich@merjis.com>.
+ * Copyright (C) 2004 Merjis Ltd.
+ * $Id: users.ml,v 1.1 2004/09/08 10:42:20 rich Exp $
+ *)
+
+open Apache
+open Registry
+open Cgi
+open Printf
+
+open Cocanwiki
+open Cocanwiki_template
+open Cocanwiki_date
+
+let template = get_template "users.html"
+
+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
+         from users where hostid = ? order by name" in
+  sth#execute [`Int hostid];
+
+  let table =
+    sth#map
+      (function
+          [`Int userid; `String name; (`Null | `String _) as email;
+           `Date registration_date;
+           `Bool can_edit; `Bool can_manage_users] ->
+            let email = match email with `Null -> "" | `String s -> s in
+            [ "userid", Template.VarString (string_of_int userid);
+              "name", Template.VarString name;
+              "email", Template.VarString email;
+              "registration_date",
+                Template.VarString (printable_date' registration_date);
+              "can_edit", Template.VarConditional can_edit;
+              "can_manage_users", Template.VarConditional can_manage_users ]
+        | _ -> assert false) in
+
+  template#table "users" table;
+
+  q#template template
+
+let () =
+  register_script ~restrict:[CanManageUsers] run
index 10aab87..6b64934 100644 (file)
 <li> <a href="/::page_html_tag::/editcss">Edit&nbsp;stylesheet&nbsp;for&nbsp;this&nbsp;page</a> | </li>
 <li> <a href="/_bin/admin/admin.cmo">Wiki&nbsp;administration</a> | </li>
 ::end::
-<li> ::if(user_logged_in):: ::username_html:: <a href="/_logout">(logout)</a> ::else:: <a href="/_login">Create&nbsp;account&nbsp;or&nbsp;login</a> ::end:: </li>
+<li> ::if(user_logged_in):: ::username_html:: <a href="/_logout">(logout)</a> ::else:: <a href="/_login">Create&nbsp;account&nbsp;or&nbsp;log&nbsp;in</a> ::end:: | </li>
+::if(can_manage_users)::
+<li> <a href="/_bin/users.cmo">Manage&nbsp;users</a> </li>
+::end::
 </ul>
 
 <hr/>
diff --git a/templates/users.html b/templates/users.html
new file mode 100644 (file)
index 0000000..79c2d5e
--- /dev/null
@@ -0,0 +1,59 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+<head>
+<title>Users</title>
+<meta name="author" content="http://www.merjis.com/" />
+<link rel="stylesheet" href="/_css/standard.css" type="text/css" title="Standard"/>
+<link rel="stylesheet" href="/_css/users.css" type="text/css" title="Standard"/>
+</head><body>
+
+<h1>Users</h1>
+
+<ul class="menu">
+<li><a href="/_bin/create_user_form.cmo">Create a user account</a></li>
+</ul>
+
+<table id="users">
+<tr>
+<th rowspan="2"> Name </th>
+<th rowspan="2"> Email address </th>
+<th rowspan="2"> Registration </th>
+<th colspan="2"> Permissions </th>
+</tr>
+<tr>
+<th> Can edit </th>
+<th> Can manage users </th>
+</tr>
+
+::table(users)::
+<tr>
+<td> <a href="/_bin/edit_user_form.cmo" title="Modify details, permissions, set password, or delete this user"><strong>::name_html::</strong></a> </td>
+<td> ::email_html:: </td>
+<td> ::registration_date_html:: </td>
+<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>
+</tr>
+::end::
+
+</table>
+
+<ul id="topmenu" class="menu">
+<li> <a href="/">Home&nbsp;page</a> | </li>
+<li> <a href="/_sitemap">Sitemap</a> | </li>
+<li> <a href="/_recent">Recent&nbsp;changes</a> </li>
+</ul>
+
+<ul id="bottommenu" class="menu">
+<li> <a href="/">Home&nbsp;page</a> | </li>
+<li> <a href="/_sitemap">Sitemap</a> | </li>
+<li> <a href="/_recent">Recent&nbsp;changes</a> </li>
+</ul>
+
+<hr/>
+
+<ul id="footer" class="menu">
+<li> <a href="/copyright">Copyright &copy; 2004</a> </li>
+</ul>
+
+</body>
+</html>
\ No newline at end of file