Skip to content

Update /assessments endpoint #729

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 36 commits into from
Apr 8, 2021
Merged

Update /assessments endpoint #729

merged 36 commits into from
Apr 8, 2021

Conversation

bnjmnt4n
Copy link
Contributor

@bnjmnt4n bnjmnt4n commented Feb 23, 2021

This PR updates the /assessments endpoint by:

  • creating /admin/assessments endpoints:
    • POST /admin/assessments to add new assessments
    • POST /admin/assessments/{assessmentId} to update properties of assessments
    • DELETE /admin/assessments/{assessmentId} to delete assessments
  • shifting role validation into AnswerController

Todo

  • Split POST /assessments/{assessmentId} into two separate requests to unlock assessments with passwords as suggested by @angelsl
    • I'm not sure how we might want to do this for now: maybe add a password column to the submissions table, so that POST /assessments/{assessmentId}/unlock would add the user-input password into that column, and GET /assessments/{assessmentId} can compare passwords between the Assessment and Submission?

Reference

https://docs.google.com/document/d/1SF0w0OxQFHecu3JBjyUPHEIidFlyGrbY5efwKGWcAOk/edit#

@bnjmnt4n bnjmnt4n requested review from angelsl and qreoct February 24, 2021 04:34
Copy link
Contributor

@qreoct qreoct left a comment

Choose a reason for hiding this comment

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

Looks great.

Copy link
Contributor

@angelsl angelsl left a comment

Choose a reason for hiding this comment

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

I took a glance, looks generally OK. (Note, I didn't read in detail!)

See my comments on the routes.

Also, test coverage seems to have dropped a bit? (The test coverage on master is 97.095%)

@qreoct qreoct mentioned this pull request Mar 18, 2021
`AssesmentsController#unlock` unlocks password-protected assessments and
creates a Submission for them, following which the assessments do not
require requests with the password.
@bnjmnt4n bnjmnt4n force-pushed the bnjmnt4n/assessments branch 2 times, most recently from 57ecf0a to 8704108 Compare March 29, 2021 14:15
@bnjmnt4n bnjmnt4n force-pushed the bnjmnt4n/assessments branch from 8704108 to d9aaeba Compare March 29, 2021 15:20
@coveralls
Copy link

coveralls commented Mar 29, 2021

Pull Request Test Coverage Report for Build a6e47b02113c7bca39c93ece5e29fa588862de15-PR-729

  • 73 of 76 (96.05%) changed or added relevant lines in 5 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.6%) to 96.344%

Changes Missing Coverage Covered Lines Changed/Added Lines %
lib/cadet_web/admin_controllers/admin_assessments_controller.ex 31 34 91.18%
Totals Coverage Status
Change from base Build 27658cb5299a0fad2a275223511c302848a8a92d-PR-721: 0.6%
Covered Lines: 1502
Relevant Lines: 1559

💛 - Coveralls

Copy link
Contributor

@angelsl angelsl left a comment

Choose a reason for hiding this comment

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

This is great, thank you! Just a few minor tweaks.

Comment on lines +9 to +18
def create(conn, %{"assessment" => assessment, "forceUpdate" => force_update}) do
file =
assessment["file"].path
|> File.read!()

result =
case force_update do
"true" -> parse_xml(file, true)
"false" -> parse_xml(file, false)
end
Copy link
Contributor

Choose a reason for hiding this comment

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

Just checking, forceUpdate is a string because this is submitted as multipart/form-data, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, this is the case.

@bnjmnt4n
Copy link
Contributor Author

bnjmnt4n commented Apr 8, 2021

I'm going to merge this into v2 since I've addressed the feedback. If there are changes to the coverage, we can look into it in v2 also.

@bnjmnt4n bnjmnt4n merged commit 77dc886 into v2 Apr 8, 2021
@bnjmnt4n bnjmnt4n deleted the bnjmnt4n/assessments branch April 8, 2021 05:50
bnjmnt4n added a commit to source-academy/frontend that referenced this pull request Apr 9, 2021
angelsl pushed a commit that referenced this pull request Apr 17, 2021
* Update `/assets` endpoint (#713)

* Assets: remove role validation in model

* AssetsController: update API endpoint and validation

The endpoint is updated to `/v2/admin/assets`, and validation is
performed within the router instead.

* Shift to `AdminAssetsController`

* Rename `AdminAssetsController` to `.exs`

* Assets: switch to `case` instead of `with`

* (1) Clearer Swagger documentation in Grading (2) Code documentation cleaup in auth_controller

* Notifications changed to plural throughout

* Settings swagger docs cleanup

* User docs typo fix

* CI fix formatting

* Update `/settings` endpoint (#722)

* `/auth`: shift `/auth` to `/auth/login`

* `/devices`: fix typo and shift to v2

* Update `/grading` endpoint (#727)

* shift role validation for Settings

* shift Grading controller to AdminGrading

* fix formatting and add details to docs

Co-authored-by: Benjamin Tan <benjamin@dev.ofcr.se>

* Rename `assets_controller_test` to `admin_assets_controller_test`

* update swagger docs for /grading

* Update `/assessments` endpoint (#729)

* `/assessments`: split out separate `/admin` endpoint

* Consistently use `/assessments/:assessmentid`

* Merge `/admin/assessments/:assessmentid/{update,publish}` endpoints

* Quick swagger docs fix for `AdminAssessmentsController`

* Format code via `mix format`

* Formatting fix

* `/assessments/{assessmentid}/submit`: shift role validation to controller

* Add more guards

* `/assessments/question/{questionid}/submit`: shift role validation to AnswerController

* clean up some docs

* Modify `AnswerController#submit` path

* Assessments: remove unused definitions

* Remove leftover unused route

* Split `AssesmentsController#unlock` out of `AssessmentsController#show`

`AssesmentsController#unlock` unlocks password-protected assessments and
creates a Submission for them, following which the assessments do not
require requests with the password.

* Fix formatting issues

* `/assessments`: split out separate `/admin` endpoint

* Consistently use `/assessments/:assessmentid`

* Merge `/admin/assessments/:assessmentid/{update,publish}` endpoints

* Quick swagger docs fix for `AdminAssessmentsController`

* Format code via `mix format`

* `/assessments/{assessmentid}/submit`: shift role validation to controller

* Add more guards

* `/assessments/question/{questionid}/submit`: shift role validation to AnswerController

* clean up some docs

* Modify `AnswerController#submit` path

* Assessments: remove unused definitions

* Remove leftover unused route

* Split `AssesmentsController#unlock` out of `AssessmentsController#show`

`AssesmentsController#unlock` unlocks password-protected assessments and
creates a Submission for them, following which the assessments do not
require requests with the password.

* Fix formatting issues

* formatting

* Update per PR feedback

* Remove unused variable

Co-authored-by: qreoct <9080974+qreoct@users.noreply.github.com>

* Change to v2 API throughout

* Fix Swagger references

* AdminGradingControllerTest: Add swagger path definition

* Remove duplicated route

* Rename file as per convention

* Swagger documentation: Switch to enums for string values

* /auth/login: shift parameters to query string in docs

* UserController: add an empty UserGameStates map to the schema

* Add comments to clarify invalid OpenAPI 2.0 types

* Swagger: shift request parameters to separate schemas

Request parameters were previously declared as separate body parameters
in the Swagger schema, which was technically invalid. For endpoints
which require more than 1 parameter, which is sent as JSON, I've created
separated schemas which represent the parameters, to make the generated
`swagger.json` more compliant.

* Story: Fix inaccurate Swagger documentation

* Shift all Swagger enums into their own schemas

This allows `swagger-typescript-api` in `cadet-frontend` to generate
TypeScript `enum`s for the corresponding type.

* Fix inaccurate types

* Update based on code review feedback

* clean up docs

* clean up docs

* Endpoints: update to mark as required

* More changes to the Swagger types

* Even more type updates

* more swagger docs consistency

* /admin/assessments: update swagger to FormData parameters

Co-authored-by: qreoct <9080974+qreoct@users.noreply.github.com>
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.

4 participants