forked from saasbook/flextensions
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* modified extensions_controller for extension setup flow * fixed extensions_controller_spec.rb * updated extensions_controller_spec.rb as per extensions_controller * fixed routes for extensions_controller_spec.rb * Add models for course_to_lms * Implement creating association in course_to_lms * Test for creating association in course_to_lms * correcting rspec for extensions controller * testing of api call completed * quick typo fix * added space in schema for canvas data * Replace the external_course_id from courses table to course_to_lmss table * More detailed extensions req, still needs more * Take external_course_id into consideration * I think set up correctly, needs rest of models to test * Adjust Assignment Table, which should rely on course_to_lms instead of only lms * Add assignment model * Implement route of create in assignment controller * Add course, lms and course_to_lms model for Assignment Controller test * Add test for create in assignment controller * Refactor to pass the Codeclimate * Refactor the controller, by adding intger validation and putting ender from helper function to create function * test coverage badge update * test coverage badge update 2 * code climate yml file updated * code climate yml file updated 2 * badge fix to linux * added codeclimate test reporter * added gems * simple cov version downgraded * simplecov v17 * secret added * secret added2 * secret added3 * secret added4 * initial changes to create user * drafted * validation email added * chnages added: new+save, has many asso for extension * Merge latest main into feature branch and resolve conflict * Refactor the controller and add integer validation * tests pass. finally. * improving test coverage * slightly clarified tests * remove render json of strings * Fix potential issue in lmss_controller * Fix minor issue based on pr comments * Add one test to reach a full LOC test coverage * starting to refactor * further refactoring * fixing everything that broke because someone decided to change the schema without telling anyone else... * everything works for demo * fixing failing tests due to prev updates * missed one merge * including validation helper * fixed comments as per PR46 (except line 30 of extensions_controller_spec, idk why it errors when I try to update those hashes to new syntax) * fix: ensure test succeed * style: format for readability --------- Co-authored-by: zee6197 <[email protected]> Co-authored-by: Zzz212zzZ <[email protected]> Co-authored-by: Sepehr Behmanesh Fard <[email protected]> Co-authored-by: Connor Bernard <[email protected]>
- Loading branch information
1 parent
cd1ed11
commit 601a5c7
Showing
15 changed files
with
260 additions
and
107 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -71,3 +71,5 @@ yarn-debug.log* | |
/config/master.key | ||
|
||
/config/credentials/production.key | ||
|
||
.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,71 @@ | ||
module Api | ||
module V1 | ||
class ExtensionsController < BaseController | ||
def create | ||
render :json => 'not yet implemented'.to_json, status: 501 | ||
end | ||
|
||
before_action :set_facade | ||
|
||
def index | ||
render :json => 'not yet implemented'.to_json, status: 501 | ||
render json: { message: 'not yet implemented'}, status: 501 | ||
end | ||
|
||
def create | ||
find_extension_params | ||
# Get External Assignment object to find initial due date | ||
assignment_response = @canvas_facade.get_assignment( | ||
@course_to_lms.external_course_id.to_i, | ||
@assignment.external_assignment_id.to_i, | ||
) | ||
if (assignment_response.status != 200) | ||
render json: assignment_response.to_json, status: 500 | ||
return | ||
end | ||
assignment_json = JSON.parse(assignment_response.body) | ||
|
||
# Provision Extension | ||
response = @canvas_facade.provision_extension( | ||
@course_to_lms.external_course_id.to_i, | ||
params[:student_uid].to_i, | ||
@assignment.external_assignment_id.to_i, | ||
params[:new_due_date], | ||
) | ||
if !response.success? | ||
render json: response.body, status: response.status | ||
return | ||
end | ||
assignment_override = JSON.parse(response.body) | ||
|
||
@extension = Extension.new( | ||
assignment_id: @assignment.id, | ||
student_email: nil, | ||
initial_due_date: assignment_json["due_at"], | ||
new_due_date: assignment_override["due_at"], | ||
external_extension_id: assignment_override["id"], | ||
last_processed_by_id: nil, | ||
) | ||
if !@extension.save | ||
render json: {"error": "Extension requested, but local save failed"}.to_json, status: 500 | ||
return | ||
end | ||
render json: @extension.to_json, status: 200 | ||
end | ||
|
||
def destroy | ||
render :json => 'not yet implemented'.to_json, status: 501 | ||
render json: { message: 'not yet implemented'}, status: 501 | ||
end | ||
|
||
private | ||
|
||
def set_facade | ||
Rails.logger.info "Using CANVAS_URL: #{ENV['CANVAS_URL']}" | ||
# not sure if auth key will be in the request headers or in cookie | ||
@canvas_facade = CanvasFacade.new(request.headers['Authorization']) | ||
end | ||
|
||
def find_extension_params | ||
@lms = Lms.find(params[:lms_id]) | ||
@course = Course.find(params[:course_id]) | ||
@assignment = Assignment.find(params[:assignment_id]) | ||
@course_to_lms = CourseToLms.find(@assignment.course_to_lms_id) | ||
end | ||
|
||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,14 @@ | ||
# assignment_id: foreign key to local assignment | ||
# student_email: requires another api request to find student data (sid is given in first response). This currently doesn't exist in CanvasFacade | ||
# initial_due_date: also requires an api request to find assignment data (assignment id is given in first response) | ||
# Note that the assignment.due_at shows the due date as it is for whoever's logged in (which if it's a teacher, should be the original due date) but the actual original due date is never saved anywhere | ||
# new_due_date: | ||
# external_extension_id: | ||
# last_processed_by_id: Requires login/sessions to be properly implemented | ||
class Extension < ApplicationRecord | ||
#Relationship with Assignment | ||
belongs_to :assignment | ||
|
||
#Relationship with User | ||
has_one :user | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,14 +19,7 @@ | |
|
||
canvas = Lms.create!({ | ||
lms_name: "Canvas", | ||
use_auth_token: true | ||
}) | ||
|
||
|
||
test_assignment = Assignment.create!({ | ||
lms_id: canvas.id, | ||
name: "Test Assignment", | ||
external_assignment_id: "11111" | ||
use_auth_token: true, | ||
}) | ||
|
||
|
||
|
@@ -37,7 +30,13 @@ | |
test_course_to_lms = CourseToLms.create!({ | ||
lms_id: canvas.id, | ||
course_id: test_course.id, | ||
external_course_id: "22222" | ||
external_course_id: "22222", | ||
}) | ||
|
||
test_assignment = Assignment.create!({ | ||
course_to_lms_id: test_course_to_lms.id, | ||
name: "Test Assignment", | ||
external_assignment_id: "11111", | ||
}) | ||
|
||
test_user = User.create!({ | ||
|
@@ -47,7 +46,7 @@ | |
test_user_to_course = UserToCourse.create!({ | ||
user_id: test_user.id, | ||
course_id: test_course.id, | ||
role: "test" | ||
role: "test", | ||
}) | ||
|
||
test_extension = Extension.create!({ | ||
|
@@ -56,37 +55,12 @@ | |
initial_due_date: DateTime.iso8601('2024-04-20'), | ||
new_due_date: DateTime.iso8601('2024-04-30'), | ||
last_processed_by_id: test_user.id, | ||
external_extension_id: "33333" | ||
external_extension_id: "33333", | ||
}) | ||
|
||
test_lms_credential = LmsCredential.create!({ | ||
user_id: test_user.id, | ||
lms_name: "canvas", | ||
token: "test token", | ||
external_user_id: "44444" | ||
}) | ||
|
||
real_course = Course.create!({ | ||
course_name: "CS169L Flextension", | ||
}) | ||
|
||
real_course_to_lms = CourseToLms.create!({ | ||
lms_id: canvas.id, | ||
course_id: real_course.id, | ||
external_course_id: "1534405" | ||
external_user_id: "44444", | ||
}) | ||
|
||
real_assignment = Assignment.create!({ | ||
lms_id: canvas.id, | ||
name: "Seed Data Testing", | ||
external_assignment_id: "8741483" | ||
}) | ||
|
||
real_extension = Extension.create!({ | ||
assignment_id: real_assignment.id, | ||
student_email: "[email protected]", | ||
initial_due_date: DateTime.iso8601('2024-04-20'), | ||
new_due_date: DateTime.iso8601('2024-04-27'), | ||
last_processed_by_id: test_user.id, | ||
external_extension_id: "270163" | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.