Skip to content

Conversation

@Kelketek
Copy link
Contributor

Description: Provides read-only API views for Badges.
Discussion/Spec: https://docs.google.com/document/d/1ob-leRHV97agPGw5ys9uASXrcsU8qf51bzYlKH3mBEM/edit?usp=sharing
Dependencies: https://github.com/edx/edx-platform/pull/10498 https://github.com/edx/edx-platform/pull/10612
Partner information: 3rd party-hosted open edX instance, for an edX solutions client.

NOTES: The API endpoint design ended up being slightly different in implementation. The URLs have changed to fit within the existing mobile API structure and the functionality was tweaked slightly. The most notable change is that because we're allowing a badge class to be awarded multiple times, searching for a user having a particular badge class yields a list of badge assertions rather than just one. The handling of permissions is not quite as the spec says-- rather, we re-use the existing mobile API permission handling for consistency via its existing decorator functions.

To test:

  1. Log in as a user which has some badges (For instance, honor@example.com), and visit the API endpoints:

http://pr10556.sandbox.opencraft.com/api/badges/v1/assertions/user/honor/
http://pr10556.sandbox.opencraft.com/api/badges/v1/assertions/user/honor/course-v1:OpenCraftX+1+2015/
http://pr10556.sandbox.opencraft.com/api/badges/v1/assertions/user/honor/*/?slug=bloo&issuing_component=colorize
http://pr10556.sandbox.opencraft.com/api/badges/v1/assertions/user/honor/?issuing_component=edx__course&slug=robin
http://pr10556.sandbox.opencraft.com/api/badges/v1/classes/edx__course/batman/
http://pr10556.sandbox.opencraft.com/api/badges/v1/classes/colorize/bloo/course-v1:OpenCraftX+1+2015/

@openedx-webhooks
Copy link

Thanks for the pull request, @Kelketek! It looks like you're a member of a company that does contract work for edX. If you're doing this work as part of a paid contract with edX, you should talk to edX about who will review this pull request. If this work is not part of a paid contract with edX, then you should ensure that there is an OSPR issue to track this work in JIRA, so that we don't lose track of your pull request.

To automatically create an OSPR issue for this pull request, just visit this link: https://openedx-webhooks.herokuapp.com/github/process_pr?repo=edx%2Fedx-platform&number=10732

@Kelketek
Copy link
Contributor Author

@smarnach This is ready for your review. Only the last commit is relevant-- the rest are dependencies.

@Kelketek Kelketek force-pushed the badges-mobile-api branch 4 times, most recently from d501788 to c0b14aa Compare November 25, 2015 22:46
Copy link
Contributor

Choose a reason for hiding this comment

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

How about using string.islower() instead?

@smarnach
Copy link
Contributor

@Kelketek Looks good so far. I've added a bunch of minor comments, and the tests aren't passing yet.

@Kelketek Kelketek force-pushed the badges-mobile-api branch 2 times, most recently from 7a3a537 to 8ff9b5c Compare November 30, 2015 21:38
@Kelketek
Copy link
Contributor Author

Kelketek commented Dec 2, 2015

@smarnach Is there anything else you need to give this a +1?

@Kelketek Kelketek force-pushed the feature/badges-v2 branch 2 times, most recently from 98f1635 to 1b618aa Compare December 3, 2015 17:21
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 change supposed to be included in the final merge?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, it will be removed as part of the final rebase.

@smarnach
Copy link
Contributor

smarnach commented Dec 3, 2015

@Kelketek Looks all good now; 👍 after replying to the question about the django-wiki requirement change.

My original review comments have all disappeared because I commented on the commit and the PR was rebased. I'd prefer if we don't rebase during reviews (and merge instead). This would make it much easier to see what changed since the last review.

@Kelketek Kelketek force-pushed the badges-mobile-api branch 2 times, most recently from ff847f3 to 2d36518 Compare December 4, 2015 03:23
@Kelketek
Copy link
Contributor Author

Kelketek commented Dec 4, 2015

@nedbat This is ready for your review.

@Kelketek Kelketek changed the title (WIP) Badges mobile api Badges mobile api Dec 4, 2015
@Kelketek
Copy link
Contributor Author

Kelketek commented Dec 4, 2015

@nasthagiri This is ready for your review, as well.

@nasthagiri
Copy link
Contributor

@wajeeha-khalid FYI.

@Kelketek Kelketek mentioned this pull request Dec 7, 2015
@nasthagiri
Copy link
Contributor

@Kelketek Why is this API included as part of the mobile_api django project? The mobile_api project and its APIs are deprecated. Per the design spec, isn't the Badges API a generic API that is available for wider use?

@Kelketek
Copy link
Contributor Author

Kelketek commented Dec 8, 2015

@nasthagiri When I set out to start developing the API, I noticed that several API endpoints existed there. I felt it would be silly to fragment how things were, but apparently not. Would you prefer the API endpoints be migrated into the user_api app, or just placed as a separate set of endpoints within the badging app?

@nasthagiri
Copy link
Contributor

@Kelketek Since you already have a badges djangoapp, it is better for it to live in lms/djangoapps/badges.

Copy link
Contributor

Choose a reason for hiding this comment

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

This can be moved to lms/urls.py.

Copy link
Contributor

Choose a reason for hiding this comment

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

What are classes?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

They refer to Badge Classes, which are the types of badges that may be awarded to users, but not the badge assertions themselves.

@nasthagiri
Copy link
Contributor

@Kelketek Thanks for this work. Overall, it looks good. My main requirements are:

  1. To move the API into the badges djangoapp rather than within the deprecated mobile_api project
  2. Simplify/reduce the multiple URLs that have been created.

@Kelketek
Copy link
Contributor Author

Kelketek commented Dec 8, 2015

@nasthagiri Thank you. Although it isn't complete, could you please look at https://github.com/edx/edx-platform/pull/10861 's last commit to see how it modifies the user API and see if that approach handles your needs?

I should have this ready relatively shortly since the notes aren't too difficult overall. However, I am a bit concerned about trying to prune the URLs, as the reason they grew was because I realized I made a bad assumption when trying to create the ones in the spec about how badges would need to be specified and made, and had to go back to the other Pull requests and modify them before returning to this one. See my comment above about the additional URLs.

@Kelketek
Copy link
Contributor Author

Kelketek commented Dec 8, 2015

@nasthagiri I have pushed some updates to the PR. I don't think I'm going to be able to prune any URLs, but I did simplify them, and will be updating the sandbox and its example links to demonstrate.

@Kelketek Kelketek force-pushed the badges-mobile-api branch 3 times, most recently from 81958d4 to 697ebec Compare December 8, 2015 23:07
@Kelketek
Copy link
Contributor Author

Kelketek commented Dec 8, 2015

@nasthagiri Updated, and I managed to prune down the URLs a bit after all by using query params in a few places.

Copy link
Contributor

Choose a reason for hiding this comment

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

Can we remove the interdependency between the badges app and the mobile_api one? Since this app is generic enough and shouldn't be tied to mobile.
If there are items in the mobile_api project that are generally useful, feel free to refactor it and move it to a more common place that both apps can then use.

@Kelketek
Copy link
Contributor Author

Kelketek commented Dec 9, 2015

@nasthagiri This is ready for another look.

Copy link
Contributor

Choose a reason for hiding this comment

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

Please update docstring with new URL format.

Copy link
Contributor

Choose a reason for hiding this comment

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

Particularly, course_id should be moved into the "Params" section below.

@nasthagiri
Copy link
Contributor

This looks good to me. Thanks for updating the PR. I have an outstanding issue with the user field.

Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: The convention in python is to use __ for dummy, unused variables.

Copy link
Contributor

Choose a reason for hiding this comment

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

This isn't mentioned in the list of unused variable patterns, while dummy is.

Copy link
Contributor

Choose a reason for hiding this comment

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

The first character listed in that link is _. So that's what I'm referring to. And since we want to distinguish between the _ that refers to ugettext, I usually use double underscore instead.

But yeah, dummy also works as an old-style convention.

@nasthagiri
Copy link
Contributor

Great job! Thanks.

👍 Assuming quality, coverage, and jenkins are happy.
Please remember to squash.

@Kelketek Kelketek merged commit 052d2d4 into feature/badges-v2 Dec 9, 2015
@bradenmacdonald bradenmacdonald deleted the badges-mobile-api branch August 1, 2016 22:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants