Skip to content
This repository has been archived by the owner on Mar 12, 2020. It is now read-only.

Add roster identifier to assignment repos endpoint #2439

Open
wants to merge 11 commits into
base: master
Choose a base branch
from

Conversation

d12
Copy link
Contributor

@d12 d12 commented Oct 21, 2019

#2404 had to be reverted as it caused exceptions when a user had a roster + assignment repos by a user who wasn't on the roster. The fix is just conditionally grabbing the identifier off of the roster entry which may or may not exist. I broke tests by adding a second assignment repo by a user not on the roster, as seen here: https://travis-ci.org/education/classroom/jobs/600831209#L2145

55c57fb fixes it.

@d12 d12 marked this pull request as ready for review October 21, 2019 16:33
@d12 d12 requested a review from a team as a code owner October 21, 2019 16:33
@ghost ghost requested a review from andrewbredow October 21, 2019 16:33
@jeffrafter jeffrafter removed the request for review from andrewbredow October 24, 2019 21:13
@jeffrafter jeffrafter self-assigned this Oct 24, 2019
Copy link
Contributor

@jeffrafter jeffrafter left a comment

Choose a reason for hiding this comment

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

Some small comments... thanks!


def rosterIdentifier
return nil unless instance_options[:roster]
instance_options[:roster].roster_entries.find_by(user_id: object.user.id)&.identifier
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this an N+1?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The results of the roster.roster_entries query would probably be cached, but I changed this to pass in roster entries instead of roster so we don't need to make this query every time.

@@ -9,7 +9,7 @@ class AssignmentReposController < API::ApplicationController

def index
repos = AssignmentRepo.where(assignment: @assignment).order(:id)
paginate json: repos
paginate json: repos, roster: @assignment.organization.roster
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a test which covers this pagination change? Will it be surprising to folks when deployed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The roster kwarg here doesn't add anything to the JSON payload, it adds context that I can access in the serializer via instance_options. The alternative is to do something like repo.assignment.organization.roster.roster_entries.find... for every repo in the serializer 😬

@@ -9,7 +9,7 @@ class AssignmentReposController < API::ApplicationController

def index
repos = AssignmentRepo.where(assignment: @assignment).order(:id)
paginate json: repos
paginate json: repos, roster: @assignment.organization.roster
Copy link
Contributor

Choose a reason for hiding this comment

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

Is the @assignment.organization always the same as the @organization here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep, didn't see @organization, changed it to use that instead.

Nathaniel Woodthorpe added 2 commits October 25, 2019 10:25
…b.com:education/classroom into retry_add_roster_entry_to_assignment_repo_api
@d12
Copy link
Contributor Author

d12 commented Oct 25, 2019

@jeffrafter All comments addressed, this is ready for review again!

Copy link
Contributor

@jeffrafter jeffrafter left a comment

Choose a reason for hiding this comment

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

Looks good! ✨

@d12 d12 requested a deployment to production October 25, 2019 16:30 Abandoned
@tessgriffin tessgriffin temporarily deployed to github-classroom October 25, 2019 16:30 Inactive
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants