This repository has been archived by the owner on Jun 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(proposals): take a proposal back to drafts for modifications
- Loading branch information
Showing
10 changed files
with
197 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
-- creating a proposals now works like this: | ||
-- * create a draft, status = initial_draft | ||
-- submit it, status = open, etc, the rest stays the same as before: | ||
-- reject -> rejected | ||
-- resolve -> resolved | ||
-- hide -> hidden | ||
|
||
-- this allows us to trigger on proposal edits, ie. | ||
-- we log a 'submit' when status = 'initial_draft' | ||
-- we log an 'edit' when status = 'open' | ||
alter type editor_schema.status add value 'initial_draft' after 'rejected'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
-- for the log | ||
alter type editor_schema.action_type add value 'proposal_edit' after 'proposal_submit'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
-- new proposals should have the new status 'initial_draft' by default | ||
alter table only editor_schema.thread alter column status set default 'initial_draft'; | ||
|
||
-- function used to take an open proposal back to a draft | ||
create or replace function editor_schema.edit_proposal( | ||
thread_id int | ||
) returns editor_schema.thread as $$ | ||
declare thread editor_schema.thread; | ||
begin | ||
update editor_schema.thread | ||
set | ||
status = 'open'::editor_schema.status, | ||
is_draft = true | ||
where id = thread_id and author_id = current_setting('jwt.claims.person_id')::integer | ||
returning * into thread; | ||
return thread; | ||
end; | ||
$$ language plpgsql strict security definer; | ||
comment on function editor_schema.edit_proposal(int) is E'Edit a proposal, restricted to proposal author.'; | ||
grant execute on function editor_schema.edit_proposal(int) to $POSTGRESQL_ROLE_PERSON; | ||
|
||
-- change submit log proposal trigger | ||
drop trigger proposal_submit_logger on editor_schema.thread; | ||
create trigger proposal_submit_logger | ||
after update on editor_schema.thread | ||
for each row | ||
when ( | ||
NEW.thread_type = 'proposal'::editor_schema.thread_type and | ||
NEW.status = 'open'::editor_schema.status and | ||
OLD.status = 'initial_draft'::editor_schema.status and | ||
OLD.external_id is null and | ||
OLD.is_draft = true and | ||
NEW.is_draft = false | ||
) | ||
execute procedure editor_private_schema.tg_log__proposal_submit(); | ||
-- new trigger to log proposal edits | ||
create function editor_private_schema.tg_log__proposal_edit() | ||
returns trigger as $$ | ||
begin | ||
insert into editor_schema.log | ||
(author_id, thread_id, action_type, event_date) | ||
values | ||
(NEW.author_id, NEW.id, 'proposal_edit', NEW.updated_at); | ||
return NEW; | ||
end; | ||
$$ language plpgsql; | ||
create trigger proposal_edit_logger | ||
after update on editor_schema.thread | ||
for each row | ||
when ( | ||
NEW.thread_type = 'proposal'::editor_schema.thread_type and | ||
NEW.status = 'open'::editor_schema.status and | ||
OLD.status = 'open'::editor_schema.status and | ||
OLD.external_id is null and | ||
OLD.is_draft = true and | ||
NEW.is_draft = false | ||
) | ||
execute procedure editor_private_schema.tg_log__proposal_edit(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters