From 50f72e5597bef62747f462d26cae836c7c9ee6b9 Mon Sep 17 00:00:00 2001 From: rich Date: Fri, 24 Sep 2004 16:30:07 +0000 Subject: [PATCH] Site-wide mailing list setting enabled mailing list functionality to be turned off and on (off by default). Added mailing_lists table to the database. --- cocanwiki.sql | 137 ++++++++++++++++++++++----------- scripts/edit_host_settings.ml | 7 +- scripts/edit_host_settings_form.ml | 12 +-- scripts/host_menu.ml | 12 +-- scripts/page.ml | 12 +-- templates/edit_host_settings_form.html | 6 ++ templates/host_menu.html | 4 + templates/page.html | 3 + 8 files changed, 128 insertions(+), 65 deletions(-) diff --git a/cocanwiki.sql b/cocanwiki.sql index 76811d1..f6e4385 100644 --- a/cocanwiki.sql +++ b/cocanwiki.sql @@ -54,7 +54,7 @@ GRANT ALL ON TABLE pages TO "www-data"; SET SESSION AUTHORIZATION 'rich'; -- --- TOC entry 36 (OID 536004) +-- TOC entry 38 (OID 536004) -- Name: pages_id_seq; Type: ACL; Schema: public; Owner: rich -- @@ -91,7 +91,7 @@ GRANT ALL ON TABLE contents TO "www-data"; SET SESSION AUTHORIZATION 'rich'; -- --- TOC entry 37 (OID 536021) +-- TOC entry 39 (OID 536021) -- Name: contents_id_seq; Type: ACL; Schema: public; Owner: rich -- @@ -113,7 +113,8 @@ CREATE TABLE hosts ( edit_anon boolean DEFAULT true NOT NULL, create_account_anon boolean DEFAULT true NOT NULL, theme_css text, - feedback_email text + feedback_email text, + mailing_list boolean DEFAULT false NOT NULL ); @@ -129,7 +130,7 @@ GRANT ALL ON TABLE hosts TO "www-data"; SET SESSION AUTHORIZATION 'rich'; -- --- TOC entry 38 (OID 536371) +-- TOC entry 40 (OID 536371) -- Name: hosts_id_seq; Type: ACL; Schema: public; Owner: rich -- @@ -222,7 +223,7 @@ GRANT ALL ON TABLE images TO "www-data"; SET SESSION AUTHORIZATION 'rich'; -- --- TOC entry 39 (OID 537151) +-- TOC entry 41 (OID 537151) -- Name: images_id_seq; Type: ACL; Schema: public; Owner: rich -- @@ -261,7 +262,7 @@ GRANT ALL ON TABLE files TO "www-data"; SET SESSION AUTHORIZATION 'rich'; -- --- TOC entry 40 (OID 537166) +-- TOC entry 42 (OID 537166) -- Name: files_id_seq; Type: ACL; Schema: public; Owner: rich -- @@ -303,7 +304,7 @@ GRANT ALL ON TABLE users TO "www-data"; SET SESSION AUTHORIZATION 'rich'; -- --- TOC entry 41 (OID 540816) +-- TOC entry 43 (OID 540816) -- Name: users_id_seq; Type: ACL; Schema: public; Owner: rich -- @@ -384,7 +385,7 @@ GRANT ALL ON TABLE contacts TO "www-data"; SET SESSION AUTHORIZATION 'rich'; -- --- TOC entry 42 (OID 542605) +-- TOC entry 44 (OID 542605) -- Name: contacts_id_seq; Type: ACL; Schema: public; Owner: rich -- @@ -489,7 +490,32 @@ GRANT ALL ON TABLE page_emails TO "www-data"; SET SESSION AUTHORIZATION 'rich'; -- --- TOC entry 47 (OID 536388) +-- TOC entry 36 (OID 543785) +-- Name: mailing_lists; Type: TABLE; Schema: public; Owner: rich +-- + +CREATE TABLE mailing_lists ( + hostid integer NOT NULL, + email text NOT NULL, + entry_date date DEFAULT ('now'::text)::date NOT NULL, + pending text, + opt_out text NOT NULL +); + + +-- +-- TOC entry 37 (OID 543785) +-- Name: mailing_lists; Type: ACL; Schema: public; Owner: rich +-- + +REVOKE ALL ON TABLE mailing_lists FROM PUBLIC; +GRANT SELECT ON TABLE mailing_lists TO "www-data"; + + +SET SESSION AUTHORIZATION 'rich'; + +-- +-- TOC entry 49 (OID 536388) -- Name: hostnames_hostid_name_uq; Type: INDEX; Schema: public; Owner: rich -- @@ -497,7 +523,7 @@ CREATE UNIQUE INDEX hostnames_hostid_name_uq ON hostnames USING btree (hostid, n -- --- TOC entry 48 (OID 536389) +-- TOC entry 50 (OID 536389) -- Name: hostnams_name_uq; Type: INDEX; Schema: public; Owner: rich -- @@ -505,7 +531,7 @@ CREATE UNIQUE INDEX hostnams_name_uq ON hostnames USING btree (name); -- --- TOC entry 44 (OID 536419) +-- TOC entry 46 (OID 536419) -- Name: pages_url_uq; Type: INDEX; Schema: public; Owner: rich -- @@ -513,7 +539,7 @@ CREATE UNIQUE INDEX pages_url_uq ON pages USING btree (hostid, url); -- --- TOC entry 49 (OID 536924) +-- TOC entry 51 (OID 536924) -- Name: email_notify_email_uq; Type: INDEX; Schema: public; Owner: rich -- @@ -521,7 +547,7 @@ CREATE UNIQUE INDEX email_notify_email_uq ON email_notify USING btree (hostid, e -- --- TOC entry 50 (OID 540251) +-- TOC entry 52 (OID 540251) -- Name: images_name_uq; Type: INDEX; Schema: public; Owner: rich -- @@ -529,7 +555,7 @@ CREATE UNIQUE INDEX images_name_uq ON images USING btree (hostid, name); -- --- TOC entry 52 (OID 540252) +-- TOC entry 54 (OID 540252) -- Name: files_name_uq; Type: INDEX; Schema: public; Owner: rich -- @@ -537,7 +563,7 @@ CREATE UNIQUE INDEX files_name_uq ON files USING btree (hostid, name); -- --- TOC entry 55 (OID 540831) +-- TOC entry 57 (OID 540831) -- Name: users_name_uq; Type: INDEX; Schema: public; Owner: rich -- @@ -545,7 +571,7 @@ CREATE UNIQUE INDEX users_name_uq ON users USING btree (hostid, name); -- --- TOC entry 54 (OID 540946) +-- TOC entry 56 (OID 540946) -- Name: users_id_uq; Type: INDEX; Schema: public; Owner: rich -- @@ -553,7 +579,7 @@ CREATE UNIQUE INDEX users_id_uq ON users USING btree (hostid, id); -- --- TOC entry 57 (OID 540970) +-- TOC entry 59 (OID 540970) -- Name: sitemenu_ordering_uq; Type: INDEX; Schema: public; Owner: rich -- @@ -561,7 +587,7 @@ CREATE UNIQUE INDEX sitemenu_ordering_uq ON sitemenu USING btree (hostid, orderi -- --- TOC entry 58 (OID 540971) +-- TOC entry 60 (OID 540971) -- Name: sitemenu_url_uq; Type: INDEX; Schema: public; Owner: rich -- @@ -569,7 +595,7 @@ CREATE UNIQUE INDEX sitemenu_url_uq ON sitemenu USING btree (hostid, url); -- --- TOC entry 60 (OID 542626) +-- TOC entry 62 (OID 542626) -- Name: contact_emails_uq; Type: INDEX; Schema: public; Owner: rich -- @@ -577,7 +603,7 @@ CREATE UNIQUE INDEX contact_emails_uq ON contact_emails USING btree (contactid, -- --- TOC entry 61 (OID 543505) +-- TOC entry 63 (OID 543505) -- Name: themes_theme_css_uq; Type: INDEX; Schema: public; Owner: rich -- @@ -585,7 +611,7 @@ CREATE UNIQUE INDEX themes_theme_css_uq ON themes USING btree (theme_css); -- --- TOC entry 62 (OID 543763) +-- TOC entry 64 (OID 543763) -- Name: page_emails_email_uq; Type: INDEX; Schema: public; Owner: rich -- @@ -593,7 +619,15 @@ CREATE UNIQUE INDEX page_emails_email_uq ON page_emails USING btree (hostid, url -- --- TOC entry 43 (OID 536012) +-- TOC entry 65 (OID 543795) +-- Name: mailing_lists_email_uq; Type: INDEX; Schema: public; Owner: rich +-- + +CREATE UNIQUE INDEX mailing_lists_email_uq ON mailing_lists USING btree (hostid, email); + + +-- +-- TOC entry 45 (OID 536012) -- Name: pages_pkey; Type: CONSTRAINT; Schema: public; Owner: rich -- @@ -602,7 +636,7 @@ ALTER TABLE ONLY pages -- --- TOC entry 45 (OID 536027) +-- TOC entry 47 (OID 536027) -- Name: contents_pkey; Type: CONSTRAINT; Schema: public; Owner: rich -- @@ -611,7 +645,7 @@ ALTER TABLE ONLY contents -- --- TOC entry 46 (OID 536377) +-- TOC entry 48 (OID 536377) -- Name: hosts_pkey; Type: CONSTRAINT; Schema: public; Owner: rich -- @@ -620,7 +654,7 @@ ALTER TABLE ONLY hosts -- --- TOC entry 51 (OID 537158) +-- TOC entry 53 (OID 537158) -- Name: images_pkey; Type: CONSTRAINT; Schema: public; Owner: rich -- @@ -629,7 +663,7 @@ ALTER TABLE ONLY images -- --- TOC entry 53 (OID 537173) +-- TOC entry 55 (OID 537173) -- Name: files_pkey; Type: CONSTRAINT; Schema: public; Owner: rich -- @@ -638,7 +672,7 @@ ALTER TABLE ONLY files -- --- TOC entry 56 (OID 540825) +-- TOC entry 58 (OID 540825) -- Name: users_pkey; Type: CONSTRAINT; Schema: public; Owner: rich -- @@ -647,7 +681,7 @@ ALTER TABLE ONLY users -- --- TOC entry 59 (OID 542611) +-- TOC entry 61 (OID 542611) -- Name: contacts_pkey; Type: CONSTRAINT; Schema: public; Owner: rich -- @@ -656,7 +690,7 @@ ALTER TABLE ONLY contacts -- --- TOC entry 67 (OID 536029) +-- TOC entry 70 (OID 536029) -- Name: $1; Type: FK CONSTRAINT; Schema: public; Owner: rich -- @@ -665,7 +699,7 @@ ALTER TABLE ONLY contents -- --- TOC entry 70 (OID 536384) +-- TOC entry 73 (OID 536384) -- Name: $1; Type: FK CONSTRAINT; Schema: public; Owner: rich -- @@ -674,7 +708,7 @@ ALTER TABLE ONLY hostnames -- --- TOC entry 68 (OID 536394) +-- TOC entry 71 (OID 536394) -- Name: hosts_hostname_cn; Type: FK CONSTRAINT; Schema: public; Owner: rich -- @@ -683,7 +717,7 @@ ALTER TABLE ONLY hosts -- --- TOC entry 63 (OID 536404) +-- TOC entry 66 (OID 536404) -- Name: $1; Type: FK CONSTRAINT; Schema: public; Owner: rich -- @@ -692,7 +726,7 @@ ALTER TABLE ONLY pages -- --- TOC entry 71 (OID 536920) +-- TOC entry 74 (OID 536920) -- Name: $1; Type: FK CONSTRAINT; Schema: public; Owner: rich -- @@ -701,7 +735,7 @@ ALTER TABLE ONLY email_notify -- --- TOC entry 72 (OID 537160) +-- TOC entry 75 (OID 537160) -- Name: $1; Type: FK CONSTRAINT; Schema: public; Owner: rich -- @@ -710,7 +744,7 @@ ALTER TABLE ONLY images -- --- TOC entry 73 (OID 537175) +-- TOC entry 76 (OID 537175) -- Name: $1; Type: FK CONSTRAINT; Schema: public; Owner: rich -- @@ -719,7 +753,7 @@ ALTER TABLE ONLY files -- --- TOC entry 64 (OID 539155) +-- TOC entry 67 (OID 539155) -- Name: pages_redirect_cn; Type: FK CONSTRAINT; Schema: public; Owner: rich -- @@ -728,7 +762,7 @@ ALTER TABLE ONLY pages -- --- TOC entry 74 (OID 540827) +-- TOC entry 77 (OID 540827) -- Name: $1; Type: FK CONSTRAINT; Schema: public; Owner: rich -- @@ -737,7 +771,7 @@ ALTER TABLE ONLY users -- --- TOC entry 75 (OID 540837) +-- TOC entry 78 (OID 540837) -- Name: $1; Type: FK CONSTRAINT; Schema: public; Owner: rich -- @@ -746,7 +780,7 @@ ALTER TABLE ONLY usercookies -- --- TOC entry 65 (OID 540942) +-- TOC entry 68 (OID 540942) -- Name: $2; Type: FK CONSTRAINT; Schema: public; Owner: rich -- @@ -755,7 +789,7 @@ ALTER TABLE ONLY pages -- --- TOC entry 66 (OID 540947) +-- TOC entry 69 (OID 540947) -- Name: pages_user_cn; Type: FK CONSTRAINT; Schema: public; Owner: rich -- @@ -764,7 +798,7 @@ ALTER TABLE ONLY pages -- --- TOC entry 76 (OID 540966) +-- TOC entry 79 (OID 540966) -- Name: $1; Type: FK CONSTRAINT; Schema: public; Owner: rich -- @@ -773,7 +807,7 @@ ALTER TABLE ONLY sitemenu -- --- TOC entry 77 (OID 540972) +-- TOC entry 80 (OID 540972) -- Name: sitemenu_url_cn; Type: FK CONSTRAINT; Schema: public; Owner: rich -- @@ -782,7 +816,7 @@ ALTER TABLE ONLY sitemenu -- --- TOC entry 78 (OID 542613) +-- TOC entry 81 (OID 542613) -- Name: $1; Type: FK CONSTRAINT; Schema: public; Owner: rich -- @@ -791,7 +825,7 @@ ALTER TABLE ONLY contacts -- --- TOC entry 79 (OID 542622) +-- TOC entry 82 (OID 542622) -- Name: $1; Type: FK CONSTRAINT; Schema: public; Owner: rich -- @@ -800,7 +834,7 @@ ALTER TABLE ONLY contact_emails -- --- TOC entry 69 (OID 543506) +-- TOC entry 72 (OID 543506) -- Name: hosts_theme_css_cn; Type: FK CONSTRAINT; Schema: public; Owner: rich -- @@ -809,7 +843,7 @@ ALTER TABLE ONLY hosts -- --- TOC entry 80 (OID 543759) +-- TOC entry 83 (OID 543759) -- Name: $1; Type: FK CONSTRAINT; Schema: public; Owner: rich -- @@ -818,7 +852,7 @@ ALTER TABLE ONLY page_emails -- --- TOC entry 81 (OID 543764) +-- TOC entry 84 (OID 543764) -- Name: page_emails_url_cn; Type: FK CONSTRAINT; Schema: public; Owner: rich -- @@ -826,6 +860,15 @@ ALTER TABLE ONLY page_emails ADD CONSTRAINT page_emails_url_cn FOREIGN KEY (hostid, url) REFERENCES pages(hostid, url) DEFERRABLE; +-- +-- TOC entry 85 (OID 543791) +-- Name: $1; Type: FK CONSTRAINT; Schema: public; Owner: rich +-- + +ALTER TABLE ONLY mailing_lists + ADD CONSTRAINT "$1" FOREIGN KEY (hostid) REFERENCES hosts(id); + + SET SESSION AUTHORIZATION 'postgres'; -- diff --git a/scripts/edit_host_settings.ml b/scripts/edit_host_settings.ml index e51f320..61a039e 100644 --- a/scripts/edit_host_settings.ml +++ b/scripts/edit_host_settings.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_settings.ml,v 1.2 2004/09/23 11:56:47 rich Exp $ + * $Id: edit_host_settings.ml,v 1.3 2004/09/24 16:30:07 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 @@ -40,6 +40,7 @@ let run r (q : cgi) (dbh : Dbi.connection) hostid { hostname = hostname } _ = let create_account_anon = q#param_true "create_account_anon" in let theme_css = q#param "theme_css" in let feedback_email = q#param "feedback_email" in + let mailing_list = q#param_true "mailing_list" in let theme_css = if theme_css = "" then `Null else `String theme_css in let feedback_email = @@ -48,10 +49,10 @@ let run r (q : cgi) (dbh : Dbi.connection) hostid { hostname = hostname } _ = (* Update the database. *) let sth = dbh#prepare_cached "update hosts set edit_anon = ?, create_account_anon = ?, theme_css = ?, - feedback_email = ? + feedback_email = ?, mailing_list = ? where id = ?" in sth#execute [`Bool edit_anon; `Bool create_account_anon; - theme_css; feedback_email; + theme_css; feedback_email; `Bool mailing_list; `Int hostid]; dbh#commit (); diff --git a/scripts/edit_host_settings_form.ml b/scripts/edit_host_settings_form.ml index 3153e00..ed27bb0 100644 --- a/scripts/edit_host_settings_form.ml +++ b/scripts/edit_host_settings_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_settings_form.ml,v 1.1 2004/09/22 12:04:28 rich Exp $ + * $Id: edit_host_settings_form.ml,v 1.2 2004/09/24 16:30:07 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,29 +44,31 @@ let run r (q : cgi) (dbh : Dbi.connection) hostid _ _ = let sth = dbh#prepare_cached "select canonical_hostname, edit_anon, create_account_anon, theme_css, - feedback_email + feedback_email, mailing_list from hosts where id = ?" in sth#execute [`Int hostid]; let canonical_hostname, edit_anon, create_account_anon, theme_css, - feedback_email = + feedback_email, mailing_list = match sth#fetch1 () with [ `String canonical_hostname; `Bool edit_anon; `Bool create_account_anon; (`String _ | `Null) as theme_css; - (`String _ | `Null) as feedback_email ] -> + (`String _ | `Null) as feedback_email; + `Bool mailing_list ] -> let theme_css = match theme_css with `String s -> s | `Null -> "" in let feedback_email = match feedback_email with `String s -> s | `Null -> "" in canonical_hostname, edit_anon, create_account_anon, theme_css, - feedback_email + feedback_email, mailing_list | _ -> assert false in template#set "canonical_hostname" canonical_hostname; template#conditional "edit_anon" edit_anon; template#conditional "create_account_anon" create_account_anon; template#set "feedback_email" feedback_email; + template#conditional "mailing_list" mailing_list; (* Themes table. *) let table = diff --git a/scripts/host_menu.ml b/scripts/host_menu.ml index 2583e07..39f3143 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.1 2004/09/22 11:41:03 rich Exp $ + * $Id: host_menu.ml,v 1.2 2004/09/24 16:30:07 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 @@ -35,20 +35,21 @@ let run r (q : cgi) (dbh : Dbi.connection) hostid _ _ = 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 + t.name, t.description, h.feedback_email, h.mailing_list from hosts h left outer join themes t on h.theme_css = t.theme_css where h.id = ?" in sth#execute [`Int hostid]; let canonical_hostname, has_global_css, edit_anon, create_account_anon, has_theme_css, theme_name, theme_description, has_feedback_email, - feedback_email = + feedback_email, mailing_list = 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 ] -> + (`String _ | `Null) as feedback_email; + `Bool mailing_list ] -> let theme_name = match theme_name with `String s -> s | `Null -> "" in let theme_description = @@ -59,7 +60,7 @@ let run r (q : cgi) (dbh : Dbi.connection) hostid _ _ = | `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 + feedback_email, mailing_list | _ -> assert false in template#set "canonical_hostname" canonical_hostname; @@ -71,6 +72,7 @@ let run r (q : cgi) (dbh : Dbi.connection) hostid _ _ = 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; q#template template diff --git a/scripts/page.ml b/scripts/page.ml index 1ea4acd..d9b85ec 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.20 2004/09/24 10:44:55 rich Exp $ + * $Id: page.ml,v 1.21 2004/09/24 16:30:07 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,13 +60,14 @@ let run r (q : cgi) (dbh : Dbi.connection) hostid {edit_anon=edit_anon} user = (* Host-specific fields. *) let sth = dbh#prepare_cached "select css is not null, - feedback_email is not null + feedback_email is not null, + mailing_list from hosts where id = ?" in sth#execute [`Int hostid]; - let has_host_css, has_feedback_email = + let has_host_css, has_feedback_email, mailing_list = match sth#fetch1 () with - | [ `Bool has_host_css; `Bool has_feedback_email ] -> - has_host_css, has_feedback_email + | [ `Bool has_host_css; `Bool has_feedback_email; `Bool mailing_list ] -> + has_host_css, has_feedback_email, mailing_list | _ -> assert false in (* Can the user edit? Manage users? etc. *) @@ -166,6 +167,7 @@ let run r (q : cgi) (dbh : Dbi.connection) hostid {edit_anon=edit_anon} user = t#conditional "has_page_css" has_page_css; t#conditional "has_feedback_email" has_feedback_email; + t#conditional "mailing_list" mailing_list; t#conditional "can_edit" can_edit; t#conditional "can_manage_users" can_manage_users; diff --git a/templates/edit_host_settings_form.html b/templates/edit_host_settings_form.html index a9bae54..8818a97 100644 --- a/templates/edit_host_settings_form.html +++ b/templates/edit_host_settings_form.html @@ -23,6 +23,12 @@ + Managed mailing list: + + + + + Theme: