liquid_feedback_core
diff core.sql @ 79:0758a2e02620
implement auto_support and delegation checks
* users can put their support in auto_support mode that supports every new draft text, this is automaticly done for the author of the draft.
* enforce that new delegations cannot be done set on inactive members.
* delete also incomming delegations on delete of a user.
* users can put their support in auto_support mode that supports every new draft text, this is automaticly done for the author of the draft.
* enforce that new delegations cannot be done set on inactive members.
* delete also incomming delegations on delete of a user.
author | Daniel Poelzleithner <poelzi@poelzi.org> |
---|---|
date | Thu Oct 07 19:45:12 2010 +0200 (2010-10-07) |
parents | f77c0f3d443c |
children | ca13b2614d10 |
line diff
1.1 --- a/core.sql Mon Oct 04 14:24:29 2010 +0200 1.2 +++ b/core.sql Thu Oct 07 19:45:12 2010 +0200 1.3 @@ -614,6 +614,7 @@ 1.4 "initiative_id" INT4, 1.5 "member_id" INT4, 1.6 "draft_id" INT8 NOT NULL, 1.7 + "auto_support" BOOLEAN NOT NULL DEFAULT 'f', 1.8 FOREIGN KEY ("issue_id", "member_id") REFERENCES "interest" ("issue_id", "member_id") ON DELETE CASCADE ON UPDATE CASCADE, 1.9 FOREIGN KEY ("initiative_id", "draft_id") REFERENCES "draft" ("initiative_id", "id") ON DELETE CASCADE ON UPDATE CASCADE ); 1.10 CREATE INDEX "supporter_member_id_idx" ON "supporter" ("member_id"); 1.11 @@ -622,6 +623,23 @@ 1.12 1.13 COMMENT ON COLUMN "supporter"."draft_id" IS 'Latest seen draft, defaults to current draft of the initiative (implemented by trigger "default_for_draft_id")'; 1.14 1.15 +CREATE FUNCTION update_supporter_drafts() 1.16 + RETURNS trigger 1.17 + LANGUAGE 'plpgsql' AS $$ 1.18 + BEGIN 1.19 + UPDATE supporter SET draft_id = NEW.id 1.20 + WHERE initiative_id = NEW.initiative_id AND 1.21 + (auto_support = 't' OR member_id = NEW.author_id); 1.22 + RETURN new; 1.23 + END 1.24 +$$; 1.25 + 1.26 +CREATE TRIGGER "update_draft_supporter" 1.27 + AFTER INSERT ON "draft" 1.28 + FOR EACH ROW EXECUTE PROCEDURE 1.29 + update_supporter_drafts(); 1.30 + 1.31 +COMMENT ON FUNCTION "update_supporter_drafts"() IS 'Automaticly update the supported draft_id to the latest version when auto_support is enabled'; 1.32 1.33 CREATE TABLE "opinion" ( 1.34 "initiative_id" INT4 NOT NULL, 1.35 @@ -668,6 +686,26 @@ 1.36 COMMENT ON COLUMN "delegation"."area_id" IS 'Reference to area, if delegation is area-wide, otherwise NULL'; 1.37 COMMENT ON COLUMN "delegation"."issue_id" IS 'Reference to issue, if delegation is issue-wide, otherwise NULL'; 1.38 1.39 +CREATE FUNCTION "check_delegation"() 1.40 + RETURNS TRIGGER 1.41 + LANGUAGE 'plpgsql' VOLATILE AS $$ 1.42 + BEGIN 1.43 + IF EXISTS ( 1.44 + SELECT NULL FROM "member" WHERE 1.45 + "id" = NEW."trustee_id" AND active = 'n' 1.46 + ) THEN 1.47 + RAISE EXCEPTION 'Cannot delegate to an inactive member'; 1.48 + END IF; 1.49 + RETURN NEW; 1.50 + END; 1.51 +$$; 1.52 + 1.53 +CREATE TRIGGER "update_delegation" 1.54 + BEFORE INSERT OR UPDATE ON "delegation" 1.55 + FOR EACH ROW EXECUTE PROCEDURE 1.56 + check_delegation(); 1.57 + 1.58 +COMMENT ON FUNCTION "check_delegation"() IS 'Sanity checks for new delegation. Dont allow delegations to inactive members'; 1.59 1.60 CREATE TABLE "direct_population_snapshot" ( 1.61 PRIMARY KEY ("issue_id", "event", "member_id"), 1.62 @@ -3377,6 +3415,7 @@ 1.63 DELETE FROM "suggestion_setting" WHERE "member_id" = "member_id_p"; 1.64 DELETE FROM "membership" WHERE "member_id" = "member_id_p"; 1.65 DELETE FROM "delegation" WHERE "truster_id" = "member_id_p"; 1.66 + DELETE FROM "delegation" WHERE "trustee_id" = "member_id_p"; 1.67 DELETE FROM "direct_voter" USING "issue" 1.68 WHERE "direct_voter"."issue_id" = "issue"."id" 1.69 AND "issue"."closed" ISNULL