-
Notifications
You must be signed in to change notification settings - Fork 4
feat(voting): let projects target award categories #149
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
5619e5d
feat(projects): restore nomination lifecycle
HazAT 7fa5f2a
feat(voting): enforce project nomination eligibility
HazAT 22b1be5
feat(projects): add award targeting form
HazAT 4c5f34b
feat(voting): surface project award eligibility
HazAT ea0dbc5
fix(voting): freeze live project nominations
HazAT d71154c
fix(ui): remove award targeting accent border
HazAT File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,83 @@ | ||
| PRAGMA foreign_keys = ON; | ||
|
|
||
| DROP TRIGGER IF EXISTS votes_validate_insert; | ||
| DROP TRIGGER IF EXISTS votes_validate_update; | ||
|
|
||
| CREATE TRIGGER votes_validate_insert BEFORE INSERT ON votes | ||
| BEGIN | ||
| SELECT RAISE(ABORT, 'voting is not enabled for this year') | ||
| WHERE NOT EXISTS ( | ||
| SELECT 1 FROM years WHERE id = NEW.year_id AND voting_enabled = 1 | ||
| ); | ||
| SELECT RAISE(ABORT, 'vote project must be an active project in vote year') | ||
| WHERE NOT EXISTS ( | ||
| SELECT 1 FROM projects | ||
| WHERE id = NEW.project_id AND year_id = NEW.year_id | ||
| AND kind = 'project' AND status = 'active' | ||
| ); | ||
| SELECT RAISE(ABORT, 'vote category must belong to vote year') | ||
| WHERE NOT EXISTS ( | ||
| SELECT 1 FROM award_categories | ||
| WHERE id = NEW.award_category_id AND year_id = NEW.year_id | ||
| ); | ||
| SELECT RAISE(ABORT, 'vote project is not eligible for this award category') | ||
| WHERE EXISTS ( | ||
| SELECT 1 FROM project_nominations WHERE project_id = NEW.project_id | ||
| ) AND NOT EXISTS ( | ||
| SELECT 1 FROM project_nominations | ||
| WHERE project_id = NEW.project_id | ||
| AND award_category_id = NEW.award_category_id | ||
| ); | ||
| SELECT RAISE(ABORT, 'users cannot vote for their own project') | ||
| WHERE EXISTS ( | ||
| SELECT 1 FROM projects p | ||
| WHERE p.id = NEW.project_id | ||
| AND ( | ||
| p.creator_id = NEW.creator_id | ||
| OR EXISTS ( | ||
| SELECT 1 FROM project_members pm | ||
| WHERE pm.project_id = p.id AND pm.user_id = NEW.creator_id | ||
| ) | ||
| ) | ||
| ); | ||
| END; | ||
|
|
||
| CREATE TRIGGER votes_validate_update | ||
| BEFORE UPDATE OF year_id, creator_id, project_id, award_category_id ON votes | ||
| BEGIN | ||
| SELECT RAISE(ABORT, 'voting is not enabled for this year') | ||
| WHERE NOT EXISTS ( | ||
| SELECT 1 FROM years WHERE id = NEW.year_id AND voting_enabled = 1 | ||
| ); | ||
| SELECT RAISE(ABORT, 'vote project must be an active project in vote year') | ||
| WHERE NOT EXISTS ( | ||
| SELECT 1 FROM projects | ||
| WHERE id = NEW.project_id AND year_id = NEW.year_id | ||
| AND kind = 'project' AND status = 'active' | ||
| ); | ||
| SELECT RAISE(ABORT, 'vote category must belong to vote year') | ||
| WHERE NOT EXISTS ( | ||
| SELECT 1 FROM award_categories | ||
| WHERE id = NEW.award_category_id AND year_id = NEW.year_id | ||
| ); | ||
| SELECT RAISE(ABORT, 'vote project is not eligible for this award category') | ||
| WHERE EXISTS ( | ||
| SELECT 1 FROM project_nominations WHERE project_id = NEW.project_id | ||
| ) AND NOT EXISTS ( | ||
| SELECT 1 FROM project_nominations | ||
| WHERE project_id = NEW.project_id | ||
| AND award_category_id = NEW.award_category_id | ||
| ); | ||
| SELECT RAISE(ABORT, 'users cannot vote for their own project') | ||
| WHERE EXISTS ( | ||
| SELECT 1 FROM projects p | ||
| WHERE p.id = NEW.project_id | ||
| AND ( | ||
| p.creator_id = NEW.creator_id | ||
| OR EXISTS ( | ||
| SELECT 1 FROM project_members pm | ||
| WHERE pm.project_id = p.id AND pm.user_id = NEW.creator_id | ||
| ) | ||
| ) | ||
| ); | ||
| END; |
This file contains hidden or 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,40 @@ | ||
| PRAGMA foreign_keys = ON; | ||
|
|
||
| CREATE TRIGGER project_nominations_lock_insert | ||
| BEFORE INSERT ON project_nominations | ||
| BEGIN | ||
| SELECT RAISE(ABORT, 'award nominations cannot change while voting is enabled') | ||
| WHERE EXISTS ( | ||
| SELECT 1 FROM projects p | ||
| JOIN years y ON y.id = p.year_id | ||
| WHERE p.id = NEW.project_id | ||
| AND y.voting_enabled = 1 | ||
| AND y.id = (SELECT MAX(id) FROM years) | ||
| ); | ||
| END; | ||
|
|
||
| CREATE TRIGGER project_nominations_lock_update | ||
| BEFORE UPDATE OF project_id, award_category_id, position ON project_nominations | ||
| BEGIN | ||
| SELECT RAISE(ABORT, 'award nominations cannot change while voting is enabled') | ||
| WHERE EXISTS ( | ||
| SELECT 1 FROM projects p | ||
| JOIN years y ON y.id = p.year_id | ||
| WHERE p.id IN (OLD.project_id, NEW.project_id) | ||
| AND y.voting_enabled = 1 | ||
| AND y.id = (SELECT MAX(id) FROM years) | ||
| ); | ||
| END; | ||
|
|
||
| CREATE TRIGGER project_nominations_lock_delete | ||
| BEFORE DELETE ON project_nominations | ||
| BEGIN | ||
| SELECT RAISE(ABORT, 'award nominations cannot change while voting is enabled') | ||
| WHERE EXISTS ( | ||
| SELECT 1 FROM projects p | ||
| JOIN years y ON y.id = p.year_id | ||
| WHERE p.id = OLD.project_id | ||
| AND y.voting_enabled = 1 | ||
| AND y.id = (SELECT MAX(id) FROM years) | ||
| ); | ||
| END; |
This file contains hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Create and claim ignore voting lock
Medium Severity
nominationsLockedis true only when an existing project is being edited, so create and claim still allow focused award targeting after voting opens. Those writes are rejected by the database lock, so teams can fill in one or two categories and then hit a conflict instead of seeing targeting frozen like the edit form.Additional Locations (2)
src/app/routes/ProjectEditorPage.tsx#L7-L29src/app/routes/ProjectEditorPage.tsx#L61-L62Reviewed by Cursor Bugbot for commit d71154c. Configure here.