From 5def59b20559a1d352d0d9c3304d9b09c2523b41 Mon Sep 17 00:00:00 2001 From: rich Date: Fri, 17 Sep 2004 15:24:54 +0000 Subject: [PATCH] Added the per-user 'manage contacts' permission. --- cocanwiki.sql | 199 ++++++++++++++++++++++++++++++++++-------- scripts/.depend | 6 +- scripts/cocanwiki.ml | 15 ++-- scripts/edit_user.ml | 7 +- scripts/edit_user_form.ml | 13 +-- scripts/page.ml | 7 +- scripts/users.ml | 12 ++- templates/edit_user_form.html | 2 + templates/page.html | 3 + templates/users.html | 16 +++- 10 files changed, 221 insertions(+), 59 deletions(-) diff --git a/cocanwiki.sql b/cocanwiki.sql index d85162b..ac84730 100644 --- a/cocanwiki.sql +++ b/cocanwiki.sql @@ -51,8 +51,10 @@ REVOKE ALL ON TABLE pages FROM PUBLIC; GRANT ALL ON TABLE pages TO "www-data"; +SET SESSION AUTHORIZATION 'rich'; + -- --- TOC entry 25 (OID 536004) +-- TOC entry 29 (OID 536004) -- Name: pages_id_seq; Type: ACL; Schema: public; Owner: rich -- @@ -60,6 +62,8 @@ REVOKE ALL ON TABLE pages_id_seq FROM PUBLIC; GRANT ALL ON TABLE pages_id_seq TO "www-data"; +SET SESSION AUTHORIZATION 'rich'; + -- -- TOC entry 7 (OID 536021) -- Name: contents; Type: TABLE; Schema: public; Owner: rich @@ -84,8 +88,10 @@ REVOKE ALL ON TABLE contents FROM PUBLIC; GRANT ALL ON TABLE contents TO "www-data"; +SET SESSION AUTHORIZATION 'rich'; + -- --- TOC entry 26 (OID 536021) +-- TOC entry 30 (OID 536021) -- Name: contents_id_seq; Type: ACL; Schema: public; Owner: rich -- @@ -93,6 +99,8 @@ REVOKE ALL ON TABLE contents_id_seq FROM PUBLIC; GRANT ALL ON TABLE contents_id_seq TO "www-data"; +SET SESSION AUTHORIZATION 'rich'; + -- -- TOC entry 9 (OID 536371) -- Name: hosts; Type: TABLE; Schema: public; Owner: rich @@ -117,8 +125,10 @@ REVOKE ALL ON TABLE hosts FROM PUBLIC; GRANT ALL ON TABLE hosts TO "www-data"; +SET SESSION AUTHORIZATION 'rich'; + -- --- TOC entry 27 (OID 536371) +-- TOC entry 31 (OID 536371) -- Name: hosts_id_seq; Type: ACL; Schema: public; Owner: rich -- @@ -126,6 +136,8 @@ REVOKE ALL ON TABLE hosts_id_seq FROM PUBLIC; GRANT ALL ON TABLE hosts_id_seq TO "www-data"; +SET SESSION AUTHORIZATION 'rich'; + -- -- TOC entry 11 (OID 536379) -- Name: hostnames; Type: TABLE; Schema: public; Owner: rich @@ -146,6 +158,8 @@ REVOKE ALL ON TABLE hostnames FROM PUBLIC; GRANT ALL ON TABLE hostnames TO "www-data"; +SET SESSION AUTHORIZATION 'rich'; + -- -- TOC entry 13 (OID 536915) -- Name: email_notify; Type: TABLE; Schema: public; Owner: rich @@ -167,6 +181,8 @@ REVOKE ALL ON TABLE email_notify FROM PUBLIC; GRANT ALL ON TABLE email_notify TO "www-data"; +SET SESSION AUTHORIZATION 'rich'; + -- -- TOC entry 15 (OID 537151) -- Name: images; Type: TABLE; Schema: public; Owner: rich @@ -202,8 +218,10 @@ REVOKE ALL ON TABLE images FROM PUBLIC; GRANT ALL ON TABLE images TO "www-data"; +SET SESSION AUTHORIZATION 'rich'; + -- --- TOC entry 28 (OID 537151) +-- TOC entry 32 (OID 537151) -- Name: images_id_seq; Type: ACL; Schema: public; Owner: rich -- @@ -211,6 +229,8 @@ REVOKE ALL ON TABLE images_id_seq FROM PUBLIC; GRANT ALL ON TABLE images_id_seq TO "www-data"; +SET SESSION AUTHORIZATION 'rich'; + -- -- TOC entry 17 (OID 537166) -- Name: files; Type: TABLE; Schema: public; Owner: rich @@ -237,8 +257,10 @@ REVOKE ALL ON TABLE files FROM PUBLIC; GRANT ALL ON TABLE files TO "www-data"; +SET SESSION AUTHORIZATION 'rich'; + -- --- TOC entry 29 (OID 537166) +-- TOC entry 33 (OID 537166) -- Name: files_id_seq; Type: ACL; Schema: public; Owner: rich -- @@ -246,6 +268,8 @@ REVOKE ALL ON TABLE files_id_seq FROM PUBLIC; GRANT ALL ON TABLE files_id_seq TO "www-data"; +SET SESSION AUTHORIZATION 'rich'; + -- -- TOC entry 19 (OID 540816) -- Name: users; Type: TABLE; Schema: public; Owner: rich @@ -259,7 +283,8 @@ CREATE TABLE users ( email text, 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_users boolean DEFAULT false NOT NULL, + can_manage_contacts boolean DEFAULT false NOT NULL ); @@ -272,8 +297,10 @@ REVOKE ALL ON TABLE users FROM PUBLIC; GRANT ALL ON TABLE users TO "www-data"; +SET SESSION AUTHORIZATION 'rich'; + -- --- TOC entry 30 (OID 540816) +-- TOC entry 34 (OID 540816) -- Name: users_id_seq; Type: ACL; Schema: public; Owner: rich -- @@ -281,6 +308,8 @@ REVOKE ALL ON TABLE users_id_seq FROM PUBLIC; GRANT ALL ON TABLE users_id_seq TO "www-data"; +SET SESSION AUTHORIZATION 'rich'; + -- -- TOC entry 21 (OID 540832) -- Name: usercookies; Type: TABLE; Schema: public; Owner: rich @@ -301,6 +330,8 @@ REVOKE ALL ON TABLE usercookies FROM PUBLIC; GRANT ALL ON TABLE usercookies TO "www-data"; +SET SESSION AUTHORIZATION 'rich'; + -- -- TOC entry 23 (OID 540961) -- Name: sitemenu; Type: TABLE; Schema: public; Owner: rich @@ -323,8 +354,67 @@ REVOKE ALL ON TABLE sitemenu FROM PUBLIC; GRANT ALL ON TABLE sitemenu TO "www-data"; +SET SESSION AUTHORIZATION 'rich'; + -- --- TOC entry 35 (OID 536388) +-- TOC entry 25 (OID 542605) +-- Name: contacts; Type: TABLE; Schema: public; Owner: rich +-- + +CREATE TABLE contacts ( + id serial NOT NULL, + hostid integer NOT NULL, + name text NOT NULL, + subject text NOT NULL +); + + +-- +-- TOC entry 26 (OID 542605) +-- Name: contacts; Type: ACL; Schema: public; Owner: rich +-- + +REVOKE ALL ON TABLE contacts FROM PUBLIC; +GRANT ALL ON TABLE contacts TO "www-data"; + + +SET SESSION AUTHORIZATION 'rich'; + +-- +-- TOC entry 35 (OID 542605) +-- Name: contacts_id_seq; Type: ACL; Schema: public; Owner: rich +-- + +REVOKE ALL ON TABLE contacts_id_seq FROM PUBLIC; +GRANT ALL ON TABLE contacts_id_seq TO "www-data"; + + +SET SESSION AUTHORIZATION 'rich'; + +-- +-- TOC entry 27 (OID 542617) +-- Name: contact_emails; Type: TABLE; Schema: public; Owner: rich +-- + +CREATE TABLE contact_emails ( + contactid integer NOT NULL, + email text NOT NULL +); + + +-- +-- TOC entry 28 (OID 542617) +-- Name: contact_emails; Type: ACL; Schema: public; Owner: rich +-- + +REVOKE ALL ON TABLE contact_emails FROM PUBLIC; +GRANT ALL ON TABLE contact_emails TO "www-data"; + + +SET SESSION AUTHORIZATION 'rich'; + +-- +-- TOC entry 40 (OID 536388) -- Name: hostnames_hostid_name_uq; Type: INDEX; Schema: public; Owner: rich -- @@ -332,7 +422,7 @@ CREATE UNIQUE INDEX hostnames_hostid_name_uq ON hostnames USING btree (hostid, n -- --- TOC entry 36 (OID 536389) +-- TOC entry 41 (OID 536389) -- Name: hostnams_name_uq; Type: INDEX; Schema: public; Owner: rich -- @@ -340,7 +430,7 @@ CREATE UNIQUE INDEX hostnams_name_uq ON hostnames USING btree (name); -- --- TOC entry 32 (OID 536419) +-- TOC entry 37 (OID 536419) -- Name: pages_url_uq; Type: INDEX; Schema: public; Owner: rich -- @@ -348,7 +438,7 @@ CREATE UNIQUE INDEX pages_url_uq ON pages USING btree (hostid, url); -- --- TOC entry 37 (OID 536924) +-- TOC entry 42 (OID 536924) -- Name: email_notify_email_uq; Type: INDEX; Schema: public; Owner: rich -- @@ -356,7 +446,7 @@ CREATE UNIQUE INDEX email_notify_email_uq ON email_notify USING btree (hostid, e -- --- TOC entry 38 (OID 540251) +-- TOC entry 43 (OID 540251) -- Name: images_name_uq; Type: INDEX; Schema: public; Owner: rich -- @@ -364,7 +454,7 @@ CREATE UNIQUE INDEX images_name_uq ON images USING btree (hostid, name); -- --- TOC entry 40 (OID 540252) +-- TOC entry 45 (OID 540252) -- Name: files_name_uq; Type: INDEX; Schema: public; Owner: rich -- @@ -372,7 +462,7 @@ CREATE UNIQUE INDEX files_name_uq ON files USING btree (hostid, name); -- --- TOC entry 43 (OID 540831) +-- TOC entry 48 (OID 540831) -- Name: users_name_uq; Type: INDEX; Schema: public; Owner: rich -- @@ -380,7 +470,7 @@ CREATE UNIQUE INDEX users_name_uq ON users USING btree (hostid, name); -- --- TOC entry 42 (OID 540946) +-- TOC entry 47 (OID 540946) -- Name: users_id_uq; Type: INDEX; Schema: public; Owner: rich -- @@ -388,7 +478,7 @@ CREATE UNIQUE INDEX users_id_uq ON users USING btree (hostid, id); -- --- TOC entry 45 (OID 540970) +-- TOC entry 50 (OID 540970) -- Name: sitemenu_ordering_uq; Type: INDEX; Schema: public; Owner: rich -- @@ -396,7 +486,7 @@ CREATE UNIQUE INDEX sitemenu_ordering_uq ON sitemenu USING btree (hostid, orderi -- --- TOC entry 46 (OID 540971) +-- TOC entry 51 (OID 540971) -- Name: sitemenu_url_uq; Type: INDEX; Schema: public; Owner: rich -- @@ -404,7 +494,15 @@ CREATE UNIQUE INDEX sitemenu_url_uq ON sitemenu USING btree (hostid, url); -- --- TOC entry 31 (OID 536012) +-- TOC entry 53 (OID 542626) +-- Name: contact_emails_uq; Type: INDEX; Schema: public; Owner: rich +-- + +CREATE UNIQUE INDEX contact_emails_uq ON contact_emails USING btree (contactid, email); + + +-- +-- TOC entry 36 (OID 536012) -- Name: pages_pkey; Type: CONSTRAINT; Schema: public; Owner: rich -- @@ -413,7 +511,7 @@ ALTER TABLE ONLY pages -- --- TOC entry 33 (OID 536027) +-- TOC entry 38 (OID 536027) -- Name: contents_pkey; Type: CONSTRAINT; Schema: public; Owner: rich -- @@ -422,7 +520,7 @@ ALTER TABLE ONLY contents -- --- TOC entry 34 (OID 536377) +-- TOC entry 39 (OID 536377) -- Name: hosts_pkey; Type: CONSTRAINT; Schema: public; Owner: rich -- @@ -431,7 +529,7 @@ ALTER TABLE ONLY hosts -- --- TOC entry 39 (OID 537158) +-- TOC entry 44 (OID 537158) -- Name: images_pkey; Type: CONSTRAINT; Schema: public; Owner: rich -- @@ -440,7 +538,7 @@ ALTER TABLE ONLY images -- --- TOC entry 41 (OID 537173) +-- TOC entry 46 (OID 537173) -- Name: files_pkey; Type: CONSTRAINT; Schema: public; Owner: rich -- @@ -449,7 +547,7 @@ ALTER TABLE ONLY files -- --- TOC entry 44 (OID 540825) +-- TOC entry 49 (OID 540825) -- Name: users_pkey; Type: CONSTRAINT; Schema: public; Owner: rich -- @@ -458,7 +556,16 @@ ALTER TABLE ONLY users -- --- TOC entry 51 (OID 536029) +-- TOC entry 52 (OID 542611) +-- Name: contacts_pkey; Type: CONSTRAINT; Schema: public; Owner: rich +-- + +ALTER TABLE ONLY contacts + ADD CONSTRAINT contacts_pkey PRIMARY KEY (id); + + +-- +-- TOC entry 58 (OID 536029) -- Name: $1; Type: FK CONSTRAINT; Schema: public; Owner: rich -- @@ -467,7 +574,7 @@ ALTER TABLE ONLY contents -- --- TOC entry 53 (OID 536384) +-- TOC entry 60 (OID 536384) -- Name: $1; Type: FK CONSTRAINT; Schema: public; Owner: rich -- @@ -476,7 +583,7 @@ ALTER TABLE ONLY hostnames -- --- TOC entry 52 (OID 536394) +-- TOC entry 59 (OID 536394) -- Name: hosts_hostname_cn; Type: FK CONSTRAINT; Schema: public; Owner: rich -- @@ -485,7 +592,7 @@ ALTER TABLE ONLY hosts -- --- TOC entry 47 (OID 536404) +-- TOC entry 54 (OID 536404) -- Name: $1; Type: FK CONSTRAINT; Schema: public; Owner: rich -- @@ -494,7 +601,7 @@ ALTER TABLE ONLY pages -- --- TOC entry 54 (OID 536920) +-- TOC entry 61 (OID 536920) -- Name: $1; Type: FK CONSTRAINT; Schema: public; Owner: rich -- @@ -503,7 +610,7 @@ ALTER TABLE ONLY email_notify -- --- TOC entry 55 (OID 537160) +-- TOC entry 62 (OID 537160) -- Name: $1; Type: FK CONSTRAINT; Schema: public; Owner: rich -- @@ -512,7 +619,7 @@ ALTER TABLE ONLY images -- --- TOC entry 56 (OID 537175) +-- TOC entry 63 (OID 537175) -- Name: $1; Type: FK CONSTRAINT; Schema: public; Owner: rich -- @@ -521,7 +628,7 @@ ALTER TABLE ONLY files -- --- TOC entry 48 (OID 539155) +-- TOC entry 55 (OID 539155) -- Name: pages_redirect_cn; Type: FK CONSTRAINT; Schema: public; Owner: rich -- @@ -530,7 +637,7 @@ ALTER TABLE ONLY pages -- --- TOC entry 57 (OID 540827) +-- TOC entry 64 (OID 540827) -- Name: $1; Type: FK CONSTRAINT; Schema: public; Owner: rich -- @@ -539,7 +646,7 @@ ALTER TABLE ONLY users -- --- TOC entry 58 (OID 540837) +-- TOC entry 65 (OID 540837) -- Name: $1; Type: FK CONSTRAINT; Schema: public; Owner: rich -- @@ -548,7 +655,7 @@ ALTER TABLE ONLY usercookies -- --- TOC entry 49 (OID 540942) +-- TOC entry 56 (OID 540942) -- Name: $2; Type: FK CONSTRAINT; Schema: public; Owner: rich -- @@ -557,7 +664,7 @@ ALTER TABLE ONLY pages -- --- TOC entry 50 (OID 540947) +-- TOC entry 57 (OID 540947) -- Name: pages_user_cn; Type: FK CONSTRAINT; Schema: public; Owner: rich -- @@ -566,7 +673,7 @@ ALTER TABLE ONLY pages -- --- TOC entry 59 (OID 540966) +-- TOC entry 66 (OID 540966) -- Name: $1; Type: FK CONSTRAINT; Schema: public; Owner: rich -- @@ -575,7 +682,7 @@ ALTER TABLE ONLY sitemenu -- --- TOC entry 60 (OID 540972) +-- TOC entry 67 (OID 540972) -- Name: sitemenu_url_cn; Type: FK CONSTRAINT; Schema: public; Owner: rich -- @@ -583,6 +690,24 @@ ALTER TABLE ONLY sitemenu ADD CONSTRAINT sitemenu_url_cn FOREIGN KEY (hostid, url) REFERENCES pages(hostid, url) DEFERRABLE; +-- +-- TOC entry 68 (OID 542613) +-- Name: $1; Type: FK CONSTRAINT; Schema: public; Owner: rich +-- + +ALTER TABLE ONLY contacts + ADD CONSTRAINT "$1" FOREIGN KEY (hostid) REFERENCES hosts(id); + + +-- +-- TOC entry 69 (OID 542622) +-- Name: $1; Type: FK CONSTRAINT; Schema: public; Owner: rich +-- + +ALTER TABLE ONLY contact_emails + ADD CONSTRAINT "$1" FOREIGN KEY (contactid) REFERENCES contacts(id); + + SET SESSION AUTHORIZATION 'postgres'; -- diff --git a/scripts/.depend b/scripts/.depend index c7c4a9f..335073e 100644 --- a/scripts/.depend +++ b/scripts/.depend @@ -16,6 +16,8 @@ cocanwiki_template.cmo: cocanwiki_files.cmo cocanwiki_version.cmo \ cocanwiki_template.cmi cocanwiki_template.cmx: cocanwiki_files.cmx cocanwiki_version.cmx \ cocanwiki_template.cmi +contact.cmo: cocanwiki.cmo cocanwiki_ok.cmo cocanwiki_template.cmi +contact.cmx: cocanwiki.cmx cocanwiki_ok.cmx cocanwiki_template.cmx create.cmo: cocanwiki.cmo cocanwiki_emailnotify.cmo cocanwiki_ok.cmo \ wikilib.cmi create.cmx: cocanwiki.cmx cocanwiki_emailnotify.cmx cocanwiki_ok.cmx \ @@ -122,8 +124,8 @@ upload_image_form.cmo: cocanwiki.cmo cocanwiki_template.cmi upload_image_form.cmx: cocanwiki.cmx cocanwiki_template.cmx users.cmo: cocanwiki.cmo cocanwiki_date.cmo cocanwiki_template.cmi users.cmx: cocanwiki.cmx cocanwiki_date.cmx cocanwiki_template.cmx -wikilib.cmo: wikilib.cmi -wikilib.cmx: wikilib.cmi +wikilib.cmo: cocanwiki_strings.cmo wikilib.cmi +wikilib.cmx: cocanwiki_strings.cmx wikilib.cmi admin/admin.cmo: cocanwiki.cmo cocanwiki_date.cmo cocanwiki_template.cmi admin/admin.cmx: cocanwiki.cmx cocanwiki_date.cmx cocanwiki_template.cmx admin/create_host.cmo: cocanwiki.cmo cocanwiki_ok.cmo cocanwiki_strings.cmo diff --git a/scripts/cocanwiki.ml b/scripts/cocanwiki.ml index b504d57..837028a 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.6 2004/09/09 12:21:22 rich Exp $ + * $Id: cocanwiki.ml,v 1.7 2004/09/17 15:24:54 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 @@ -45,7 +45,7 @@ exception CgiExit * who can use the script. For example: * register_script ~restrict:[CanEdit ; CanManageUsers] run *) -type permissions_t = CanEdit | CanManageUsers +type permissions_t = CanEdit | CanManageUsers | CanManageContacts (* The "user object". *) type user_t = Anonymous (* Not logged in. *) @@ -60,6 +60,7 @@ 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 (* The "host object". *) type host_t = { hostname : string; @@ -144,16 +145,20 @@ let register_script ?(restrict = []) ?(anonymous = true) run = let sth = dbh#prepare_cached - "select u.id, u.name, u.can_edit, u.can_manage_users + "select u.id, u.name, u.can_edit, u.can_manage_users, + u.can_manage_contacts 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_edit; `Bool can_manage_users; + `Bool can_manage_contacts ] -> let perms = (if can_edit then [ CanEdit ] else []) @ - (if can_manage_users then [ CanManageUsers ] else []) in + (if can_manage_users then [ CanManageUsers ] else []) @ + (if can_manage_contacts then [ CanManageContacts ] else []) + in User (userid, name, perms) | _ -> assert false) with diff --git a/scripts/edit_user.ml b/scripts/edit_user.ml index dc971ae..38f98b3 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.3 2004/09/09 12:21:22 rich Exp $ + * $Id: edit_user.ml,v 1.4 2004/09/17 15:24:54 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 @@ -72,6 +72,7 @@ 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 (* Trying to remove manage users permission from self? *) (match can_manage_users, self with @@ -84,9 +85,11 @@ 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_edit = ?, can_manage_users = ?, + can_manage_contacts = ? where hostid = ? and id = ?" in sth#execute [email; `Bool can_edit; `Bool can_manage_users; + `Bool can_manage_contacts; `Int hostid; `Int userid]; (* Finish up. *) diff --git a/scripts/edit_user_form.ml b/scripts/edit_user_form.ml index 8670da4..9574081 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.4 2004/09/09 12:21:22 rich Exp $ + * $Id: edit_user_form.ml,v 1.5 2004/09/17 15:24:54 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 @@ -36,22 +36,22 @@ let run r (q : cgi) (dbh : Dbi.connection) hostid _ _ = let sth = dbh#prepare_cached "select u.name, u.email, u.registration_date, - u.can_edit, u.can_manage_users, + u.can_edit, u.can_manage_users, u.can_manage_contacts, (select count(*) from pages where logged_user = u.id), (select count(*) from pages where logged_user = u.id and url_deleted is null) from users u where u.hostid = ? and u.id = ?" in sth#execute [`Int hostid; `Int userid]; - let name, email, registration_date, can_edit, can_manage_users, nr_edits, - nr_edits_live = + let name, email, registration_date, can_edit, can_manage_users, + can_manage_contacts, 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_edit; `Bool can_manage_users; `Bool can_manage_contacts; `Int nr_edits; `Int nr_edits_live] -> name, email, registration_date, can_edit, can_manage_users, - nr_edits, nr_edits_live + can_manage_contacts, nr_edits, nr_edits_live | _ -> assert false in template#set "userid" (string_of_int userid); @@ -60,6 +60,7 @@ let run r (q : cgi) (dbh : Dbi.connection) hostid _ _ = template#set "registration_date" (printable_date' registration_date); template#conditional "can_edit" can_edit; template#conditional "can_manage_users" can_manage_users; + template#conditional "can_manage_contacts" can_manage_contacts; 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 7d7bd4d..70c25b3 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.11 2004/09/09 12:21:22 rich Exp $ + * $Id: page.ml,v 1.12 2004/09/17 15:24:54 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,9 +54,10 @@ let run r (q : cgi) (dbh : Dbi.connection) hostid {edit_anon=edit_anon} user = | [ `Bool has_host_css ] -> has_host_css | _ -> assert false in - (* Can the user edit? Manage users? *) + (* Can the user edit? Manage users? etc. *) 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 (* This code generates ordinary pages. *) let make_page title description pageid last_modified_date has_page_css @@ -81,6 +82,7 @@ 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; (* Pull out the sections in this page. *) let sth = dbh#prepare_cached @@ -147,6 +149,7 @@ 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; q#template t in diff --git a/scripts/users.ml b/scripts/users.ml index 9c2030b..1f1b033 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.4 2004/09/09 12:21:22 rich Exp $ + * $Id: users.ml,v 1.5 2004/09/17 15:24:54 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 @@ -33,7 +33,8 @@ 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 + "select id, name, email, registration_date, can_edit, can_manage_users, + can_manage_contacts from users where hostid = ? order by name" in sth#execute [`Int hostid]; @@ -42,7 +43,8 @@ let run r (q : cgi) (dbh : Dbi.connection) hostid _ _ = (function [`Int userid; `String name; (`Null | `String _) as email; `Date registration_date; - `Bool can_edit; `Bool can_manage_users] -> + `Bool can_edit; `Bool can_manage_users; + `Bool can_manage_contacts] -> let email = match email with `Null -> "" | `String s -> s in [ "userid", Template.VarString (string_of_int userid); "name", Template.VarString name; @@ -50,7 +52,9 @@ let run r (q : cgi) (dbh : Dbi.connection) hostid _ _ = "registration_date", Template.VarString (printable_date' registration_date); "can_edit", Template.VarConditional can_edit; - "can_manage_users", Template.VarConditional can_manage_users ] + "can_manage_users", Template.VarConditional can_manage_users; + "can_manage_contacts", + Template.VarConditional can_manage_contacts ] | _ -> assert false) in template#table "users" table; diff --git a/templates/edit_user_form.html b/templates/edit_user_form.html index 3475925..d31e3cf 100644 --- a/templates/edit_user_form.html +++ b/templates/edit_user_form.html @@ -34,6 +34,8 @@
+
+ diff --git a/templates/page.html b/templates/page.html index 8cde60f..e32169e 100644 --- a/templates/page.html +++ b/templates/page.html @@ -68,6 +68,9 @@ ::if(can_manage_users)::
  • Manage users
  • ::end:: +::if(can_manage_contacts):: +
  • Contact forms
  • +::end:: ::if(can_edit)::
  • Server administration
  • ::end:: diff --git a/templates/users.html b/templates/users.html index 73e6ad9..6a6e8aa 100644 --- a/templates/users.html +++ b/templates/users.html @@ -18,11 +18,12 @@ Username Email address Registration - Permissions + Permissions Edit Manage users + Manage contacts ::table(users):: @@ -32,6 +33,7 @@ ::registration_date_html:: ::if(can_edit)::Can edit::end:: ::if(can_manage_users)::Can manage users::end:: + ::if(can_manage_contacts)::Can manage contacts::end:: ::end:: @@ -79,6 +81,18 @@ If set, user may: + +
    Manage contacts
    +
    + +

    +If set, user may view and change the list of email +addresses associated with contact forms, and create +and delete contact forms. +

    + +
    +