Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
DevAdm committed Jul 10, 2024
1 parent 111c96c commit e6e56e8
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 20 deletions.
34 changes: 22 additions & 12 deletions app/controllers/theses_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,16 @@ def update
end
end

def update_notes
@thesis = @student.theses.find(params[:id])

if @thesis.update(notes: params[:thesis_notes])
redirect_to [@student, @thesis], notice: 'Notes updated successfully.'
else
redirect_to @thesis, alert: 'Failed to update notes.'
end
end

def destroy
@thesis = @student.theses.find(params[:id])
@thesis.status = Thesis::REJECTED
Expand Down Expand Up @@ -149,10 +159,10 @@ def validate_active_thesis(thesis_id)
def submit_for_review
@thesis = @student.theses.find(params[:id])
@thesis.current_user = current_user

# Temporarily assign the attributes for validation
@thesis.assign_attributes(thesis_params)

if @thesis.valid?(:submit_for_review)
if @thesis.update(thesis_params)
if validate_active_thesis(@thesis.id)
Expand All @@ -178,33 +188,33 @@ def validate_licence_uplaod(thesis_id)
def accept_licences
@thesis = @student.theses.find(params[:id])
@thesis.current_user = current_user

# Temporarily assign the attributes for validation
@thesis.assign_attributes(thesis_params)
@thesis.pretty_inspect

if @thesis.valid?(:accept_licences)

if @thesis.update(thesis_params)

if validate_licence_uplaod(@thesis.id)

redirect_to student_view_thesis_process_path(@thesis, Thesis::PROCESS_SUBMIT), notice: "Updated status to #{Thesis::STATUS_ACTIONS[@thesis.status]}"
else

redirect_to student_view_thesis_process_path(@thesis, Thesis::PROCESS_REVIEW), alert: 'Missing Licence Document. Please upload LAC Licence Signed Doc.'
end
else

error_messages = @thesis.errors.full_messages.join(', ')
redirect_to student_view_thesis_process_path(@thesis, Thesis::PROCESS_REVIEW), alert: "There was an error submitting your thesis: #{error_messages}."
end
else

error_messages = @thesis.errors.full_messages.join(', ')
redirect_to student_view_thesis_process_path(@thesis, Thesis::PROCESS_REVIEW), alert: "There was an error submitting your thesis: #{error_messages}."
end

end

### THESIS ASSIGNMENT TO USERS ###
Expand Down Expand Up @@ -241,7 +251,7 @@ def thesis_params
:keywords, :embargo, :language, :degree_name, :degree_level, :program, :published_date,
:exam_date, :student_id, :committee, :abstract, :assigned_to_id, :assigned_to,
:student_accepted_terms_at, :under_review_at, :accepted_at, :published_at, :returned_at,
:committee_members_attributes, :embargoed, :certify_content_correct, :lac_licence_agreement,
:committee_members_attributes, :embargoed, :certify_content_correct, :lac_licence_agreement,
:yorkspace_licence_agreement, :etd_licence_agreement,
committee_members_attributes: %i[first_name last_name role id _destroy],
loc_subject_ids: [])
Expand Down
17 changes: 16 additions & 1 deletion app/views/theses/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,21 @@
<% end %>

</div>
</div>


</div>

<%= form_tag update_notes_student_thesis_path(@student, @thesis) do %>
<div class="row">
<div class="col-12"><hr /></div>
<h6>Notes</h6>
<div class="col-12">
<textarea name="thesis_notes" class="form-control" rows=10 cols=10 placeholder="Notes"><%= @thesis.notes %></textarea>
</div>
<div class="col-3">
<input type="submit" class= "btn btn-success" value="Save Notes" style="margin-top:10px">
</div>
</div>
<% end %>


5 changes: 3 additions & 2 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
devise_for :users

resources :gem_records, except: %i[new edit create update destroy]

resources :students do
get 'send_invite', on: :member

Expand All @@ -52,8 +52,9 @@
post 'submit_for_review'
post 'assign'
post 'unassign'
post 'update_notes'
end


resource :embargo, only: %i[new create], controller: 'theses/embargo'

Expand Down
5 changes: 5 additions & 0 deletions db/migrate/20240710191626_add_notes_to_theses.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddNotesToTheses < ActiveRecord::Migration[7.0]
def change
add_column :theses, :notes, :text
end
end
3 changes: 2 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema[7.0].define(version: 2024_06_11_142734) do
ActiveRecord::Schema[7.0].define(version: 2024_07_10_191626) do
create_table "action_text_rich_texts", charset: "utf8mb3", force: :cascade do |t|
t.string "name", null: false
t.text "body", size: :long
Expand Down Expand Up @@ -202,6 +202,7 @@
t.boolean "lac_licence_agreement", default: false
t.boolean "yorkspace_licence_agreement", default: false
t.boolean "etd_licence_agreement", default: false
t.text "notes"
t.index ["student_id"], name: "index_theses_on_student_id"
end

Expand Down
22 changes: 18 additions & 4 deletions test/controllers/theses_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,20 @@ class ThesesControllerTest < ActionController::TestCase
assert_template 'index'
end

should 'update thesis notes' do
thesis = create(:thesis, student: @student)

get :show, params: { id: thesis.id, student_id: @student.id }
t = assigns(:thesis)
assert t

post :update_notes, params: { id: t.id, student_id: @student.id, thesis_notes: "Thesis Notes Test" }

t.reload

assert_equal "Thesis Notes Test", t.notes, 'Notes should be updated'
end

should 'Show Thesis details or fail if thesis was not found' do
thesis = create(:thesis, student: @student)

Expand Down Expand Up @@ -421,12 +435,12 @@ class ThesesControllerTest < ActionController::TestCase
@thesis.update(certify_content_correct: false)

post :submit_for_review, params: { id: @thesis.id, student_id: @student.id, thesis: { certify_content_correct: false } }

assigns(:thesis)
assert_response :redirect
assert_redirected_to student_view_thesis_process_path(@thesis, Thesis::PROCESS_SUBMIT)
assert_equal "There was an error submitting your thesis: Certify content correct can't be blank.", flash[:alert]

end

## LICENCE UPLOAD CHECK
Expand All @@ -435,8 +449,8 @@ class ThesesControllerTest < ActionController::TestCase
patch :accept_licences, params: { student_id: @student.id, id: @thesis.id, thesis: { lac_licence_agreement: true, yorkspace_licence_agreement: true, etd_licence_agreement: true } }
assert_redirected_to student_view_thesis_process_path(@thesis, Thesis::PROCESS_REVIEW)
assert_equal 'Missing Licence Document. Please upload LAC Licence Signed Doc.', flash[:alert]
end
end

should "should accept licences with a licence document" do
# thesis = create(:thesis, student: @student)
# create(:document, thesis: @thesis, user: @student, usage: 'licence', supplemental: true, deleted: false)
Expand Down

0 comments on commit e6e56e8

Please sign in to comment.