Skip to content
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

Rework nominations #447

Merged
merged 30 commits into from
Mar 8, 2021
Merged

Rework nominations #447

merged 30 commits into from
Mar 8, 2021

Conversation

ks129
Copy link
Member

@ks129 ks129 commented Feb 22, 2021

Note! This HAVE to be merged EXACTLY the same time as bot PR

Changes

Instead of one nominations table, there are now 2 tables: Nominations and nomination entries. The nominations table got one new field reviewed (boolean). Here are schemas of these tables:

Table: nomination

active (boolean)
user (User)
inserted_at (datetime)
end_reason (string)
ended_at (datetime)
reviewed (boolean)
Table: nomination entries

nomination (Nomination)
actor (User)
reason (string)
inserted_at (datetime)

Now is also allowed multiple nominations per-user and they are created as nomination entries. One user can create only 1 entry for each nomination.

Also updated tests to match with all these changes.

What to test?

  • Is the migration script properly moving data from old schema to new.
  • Is GET routes working as expected?
  • Is the POST route creating a new nomination entry if nomination already exists?
  • Is the PATCH route reviewed field setting works?
  • Is the PATCH patching behaviors correct?
  • Is tests covering everything (there is one place where I had to ignore it)?

Closes #445

@ks129 ks129 added area: API Related to or causes API changes priority: 1 - high High Priority labels Feb 22, 2021
@coveralls
Copy link

coveralls commented Feb 22, 2021

Coverage Status

Coverage remained the same at 100.0% when pulling 3429fe5 on ks123/nomination/split into f17075f on master.

Copy link
Member

@SebastiaanZ SebastiaanZ left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I ran out of time for now, but I'm a few commits in. I've just gone over the code as of now and I wanted to give my feedback early, rather than late, as I'm not sure when I'll have time again.

Things I haven't reviewed yet:

  • Grammar
  • Functional test

As a general comment: None of the commit messages I've read have a meaningful commit message body and some of the titles are a bit too long. Ideally, a commit message should explain the what and why of the change you're committing to the history instead of having just a single summary line.

Some of these commits are fairly sizeable and you've made a number of choices within those commits; try to add the reasoning behind those choices into the commit message body so that reasoning becomes part of the git history of the repository.

These are few links @lemonsaurus typically shares when talking about commit messages:

https://chris.beams.io/posts/git-commit/
https://thoughtbot.com/blog/5-useful-tips-for-a-better-commit-message
http://ablogaboutcode.com/2011/03/23/proper-git-commit-messages-and-an-elegant-git-history
https://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html

A more extreme example: https://dhwthompson.com/2019/my-favourite-git-commit

This page is also really nice: https://mtlynch.io/code-review-love/

pydis_site/apps/api/models/bot/nomination.py Outdated Show resolved Hide resolved
pydis_site/apps/api/models/bot/nomination.py Show resolved Hide resolved
pydis_site/apps/api/serializers.py Show resolved Hide resolved
pydis_site/apps/api/viewsets/bot/nomination.py Outdated Show resolved Hide resolved
pydis_site/apps/api/viewsets/bot/nomination.py Outdated Show resolved Hide resolved
In order to use entries in serializer without manually
setting entries key we have to use related_name option to
automatically fetch all related entries.
Set it here so we don't have to set it every place where we
fetch entries.
This doesn't make sense to have 3 small migrations for one PR,
so I merged 2 existing migrations and 1 new, ordering and related_name adding migrations to one.
After setting related_name in NominationEntry model nomination field,
we can just provide serializer and DRF automatically fetch
all related entries.
After moving entries to nomination serializer we can get rid
from GET request handlers and let DRF handle this.
Also PATCH and POST handlers got some simplification by
removing manual entries setting.
Entries isn't handled manually anymore so these tests have no point.
For string fields NULL as default is not suggested, so use empty string instead.
@HassanAbouelela
Copy link
Member

I've looked over the new schema, and from a functional standpoint, it seems good.

Here are the old vs new schemas if anyone wants to compare (you can play around with it here):

Old image
New image

Copy link
Member

@lemonsaurus lemonsaurus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm mostly okay with this PR. There are grammar issues, but it looks like it does what it needs to do.

pydis_site/apps/api/viewsets/bot/nomination.py Outdated Show resolved Hide resolved
pydis_site/apps/api/viewsets/bot/nomination.py Outdated Show resolved Hide resolved
pydis_site/apps/api/viewsets/bot/nomination.py Outdated Show resolved Hide resolved
pydis_site/apps/api/viewsets/bot/nomination.py Outdated Show resolved Hide resolved
Copy link
Member

@jb3 jb3 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mainly grammar + code style fixes, but otherwise looks good.

pydis_site/apps/api/viewsets/bot/nomination.py Outdated Show resolved Hide resolved
pydis_site/apps/api/viewsets/bot/nomination.py Outdated Show resolved Hide resolved
pydis_site/apps/api/viewsets/bot/nomination.py Outdated Show resolved Hide resolved
pydis_site/apps/api/viewsets/bot/nomination.py Outdated Show resolved Hide resolved
pydis_site/apps/api/viewsets/bot/nomination.py Outdated Show resolved Hide resolved
pydis_site/apps/api/viewsets/bot/nomination.py Outdated Show resolved Hide resolved
pydis_site/apps/api/viewsets/bot/nomination.py Outdated Show resolved Hide resolved
pydis_site/apps/api/viewsets/bot/nomination.py Outdated Show resolved Hide resolved
pydis_site/apps/api/viewsets/bot/nomination.py Outdated Show resolved Hide resolved
ks129 and others added 4 commits March 5, 2021 07:48
Copy link
Member

@mbaruh mbaruh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few more

pydis_site/apps/api/models/bot/nomination.py Outdated Show resolved Hide resolved
pydis_site/apps/api/models/bot/nomination.py Outdated Show resolved Hide resolved
pydis_site/apps/api/viewsets/bot/nomination.py Outdated Show resolved Hide resolved
pydis_site/apps/api/viewsets/bot/nomination.py Outdated Show resolved Hide resolved
pydis_site/apps/api/viewsets/bot/nomination.py Outdated Show resolved Hide resolved
@ks129 ks129 requested a review from mbaruh March 6, 2021 12:14
@mbaruh mbaruh merged commit e0fc61a into master Mar 8, 2021
@mbaruh mbaruh deleted the ks123/nomination/split branch March 8, 2021 17:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: API Related to or causes API changes priority: 1 - high High Priority
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow many nominations per user
7 participants