canvas-lms/app/serializers/progress_serializer.rb

13 lines
310 B
Ruby
Raw Normal View History

Quiz Reports API - Index An endpoint for retrieving all quiz reports for a given quiz. Closes CNVS-12172 CHANGES ------- The biggest effort in this patch was to normalize the way QuizReport objects are interfaced with, and the generation of their CSV attachments in particular: - Quiz#current_statistics_for() now ALWAYS returns a persisted object while still considering the freshness of the stats - Quiz#statistics_csv() is no longer responsible for testing whether the attachment should be generated or not, but instead ensures that the CSV will be generated ASAP - QuizStatistics#generate_csv() now guards against generating multiple attachments - QuizStatistics#generate_csv_in_background() now guards against queueing multiple generation jobs (by testing the status of the Progress object) QuizReport API changes: - new property: "generatable" - new property: "readable_type" - new property: "url" - now accepts JSON-API format for all endpoints: - JSON-API allows you to embed file and progress objects directly in the QuizReport document, just pass ?include=file,progress Quizzes API changes: - new property (JSON): "quiz_reports_url" - new property (JSON-API): "links.quiz_reports" Some AMS changes: - added support for accepting side-loading requests from controllers by passing an :includes array to the serializer initializer - added support for embedding objects in root, using `embed: :object and embed_in_root: true` for has_one associations - also, in that same scenario, AMS's default behavior is to wrap single objects (has_one) in an array, which didn't work for me, so I added a new option called "wrap_in_array" which you can set to false when defining the association to override this behavior Other changes: - covered the front-end/javascript that utilizes the reports and allows teachers to generate them - QuizReport in the front-end no longer relies on magical course_id exposed in window.ENV, but instead uses its URL to construct the generation URL (see QuizReport#baseURL) - Attachment now has a shallow-AMSerializer that proxies to the legacy one in lib/api/v1 which allows us to at least side-load them - Progress now has an AMS - QuizReport legacy serializer in lib/api/v1 removed entirely, replaced by the new AMS one TEST PLAN ---- ---- Endpoint: [GET] /api/v1/courses/:course_id/quizzes/:quiz_id/reports - as a teacher, make a request to the endpoint above: - it should return a set of two quiz report objects - add a parameter "includes_all_versions=true" to the query parameters and verify that the "student_analysis" report in the returned set now reflects the new value (the reports have a field called "includes_all_versions" which should be true in this case, false otherwise) - as a student, make the request and verify that it rejects you Endpoint: [GET] /api/v1/courses/:course_id/quizzes/:quiz_id/reports/:id - turn on JSON-API mode - as a teacher: - don't generate the report from the UI yet - make the request, and verify that you get only the report - generate - repeat the request, verify that you still get only the report - add a ?include=file query parameter - you should read the file document now - add a ?include=progress query parameter - you should read the progress document now - turn off JSON-API mode - as a teacher: - make the request, and verify you get the "progress_url" field and that the file document is embedded automatically without having to specify the ?include= parameter Front-end testing: - go to the statistics page - generate all reports: - verify that the progress bar updates - verify that you can download them - verify that auto-download occurs unless you refresh the page before the report is generated - toggle on the "Count All Attempts" button and repeat the above: - verify that Item Analysis is not generatable anymore since it's not affected by that parameter Please note that "item_analysis" reports will always have "includes_all_versions" as true. Change-Id: I0dc6d5108cbcef78b2fa17ba0476f470d33d402d Reviewed-on: https://gerrit.instructure.com/32731 Tested-by: Jenkins <jenkins@instructure.com> Reviewed-by: Derek DeVries <ddevries@instructure.com> QA-Review: Caleb Guanzon <cguanzon@instructure.com> Product-Review: Derek DeVries <ddevries@instructure.com>
2014-04-02 12:52:00 +08:00
class ProgressSerializer < Canvas::APISerializer
root :progress
attributes :id, :context_id, :context_type, :user_id, :tag, :completion,
:workflow_state, :created_at, :updated_at, :message, :url
def_delegators :@controller, :api_v1_progress_url
def url
api_v1_progress_url(object)
end
end