Skip to content

Commit

Permalink
close #51
Browse files Browse the repository at this point in the history
Merge branch '20240710-add-notes-to-thesis' into develop
  • Loading branch information
amtuannguyen committed Jul 22, 2024
2 parents 62a4a8b + 8db6955 commit a7218e4
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 5 deletions.
7 changes: 6 additions & 1 deletion app/controllers/theses_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@ def update

@thesis.audit_comment = 'Updating thesis details.'

if current_user.role == User::STUDENT
if thesis_params.key?(:notes) && !thesis_params[:notes].blank?
redirect_to [@student, @thesis], alert: 'You cannot edit thesis notes' and return
end
end
# params[:thesis] = params[:thesis].reject { |p| Student::IMMUTABLE_THESIS_FIELDS.include?(p) } if current_user.role == User::STUDENT
## Need to check if thesis params are empty or not, if they are -> don't update
if @thesis.update(thesis_params)
Expand Down Expand Up @@ -254,7 +259,7 @@ def thesis_params
: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,
:yorkspace_licence_agreement, :etd_licence_agreement,
:yorkspace_licence_agreement, :etd_licence_agreement, :notes,
committee_members_attributes: %i[first_name last_name role id _destroy],
loc_subject_ids: [])
end
Expand Down
6 changes: 5 additions & 1 deletion app/views/theses/_form.html.erb
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
<%= simple_form_for [@student, @thesis], html: { class: "form-horizontal" } do |f| %>
<%= render partial: "form_admin_editable", locals: { f: f } %>

<%= content_for :admin_editable_part_1 %>

<hr class="fitted" style="border-color: black;"/>

<%= render partial: "form_student_editable", locals: { f: f } %>
<%= content_for :admin_editable_part_2 %>
<%= f.input :gem_record_event_id, as: :hidden %>

<hr class="fitted"/>
Expand Down
13 changes: 12 additions & 1 deletion app/views/theses/_form_admin_editable.html.erb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<% content_for :admin_editable_part_1 do %>
<%= f.input :title, as: :text, input_html: { class: "span6", rows: 2 }, readonly: read_only_if_student("title") %>
<%= f.input :author, input_html: { class: "span4" }, readonly: read_only_if_student("author") %>
<%= f.input :supervisor, input_html: { class: "span4" }, readonly: read_only_if_student("supervisor") %>
Expand Down Expand Up @@ -48,4 +49,14 @@
<% end %>
</div>
</div>
</div>
</div>
<% end %>
<% content_for :admin_editable_part_2 do %>
<div class="row">
<div class="col-12"><hr /></div>
<div class="col-12">
<%= f.input :notes, as: :text, input_html: { class: 'form-control', rows: 10, cols: 10} %>
</div>
</div>
<% end %>
9 changes: 9 additions & 0 deletions app/views/theses/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,15 @@


</div>
</div>


<div class="row">
<div class="col-12"><hr /></div>
<h6>Notes</h6>
<div class="col-12">
<p><%= @thesis.notes %></p>
</div>
</div>

<%= render partial: "documents/new_form", locals: { primary: true } %>
Expand Down
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
1 change: 1 addition & 0 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,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
24 changes: 24 additions & 0 deletions test/controllers/theses_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,23 @@ 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

put :update,
params: { id: thesis.id, student_id: @student.id,
thesis: { notes: "Updating the thesis notes..." }
}

t.reload

assert_equal "Updating the thesis notes...", 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 @@ -359,6 +376,13 @@ class ThesesControllerTest < ActionController::TestCase
# assert_not_equal "new author", thesis.author
end

should 'not be able to update notes field in thesis' do
put :update, params: { id: @thesis.id, student_id: @student.id, thesis: { notes: "updating thesis notes as student..." } }
thesis = assigns(:thesis)

assert_not_equal "updating thesis notes as student...", thesis.notes
end

should 'show edit for if thesis is editing, [CHECK FOR FIELDS PRESENT LATER]' do
get :edit, params: { id: @thesis.id, student_id: @student.id }

Expand Down

0 comments on commit a7218e4

Please sign in to comment.