Skip to content

Commit

Permalink
Merge 13b9830 into af5f58e
Browse files Browse the repository at this point in the history
  • Loading branch information
dinesh-pasupuleti committed Apr 28, 2024
2 parents af5f58e + 13b9830 commit d789842
Show file tree
Hide file tree
Showing 18 changed files with 242 additions and 5 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -220,4 +220,5 @@ pg_data
.ruby-version
mysql2psql.yml
*.pem
t.csv
t.csvdb/schema.rb
db/schema.rb
10 changes: 10 additions & 0 deletions app/controllers/grades_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,17 @@ def save_grade_and_comment_for_submission
@team = participant.team
@team.grade_for_submission = params[:grade_for_submission]
@team.comment_for_submission = params[:comment_for_submission]
# E2237 - create a grading history entry for this assignment
# save the grade, comment, receiver, and instructor
# this should be updated to Rails 5 convention at some point
# but it works for now
begin
GradingHistory.create(instructor_id: session[:user].id,
assignment_id: participant.assignment.id,
grading_type: 'Submission',
grade_receiver_id: @team.id,
grade: @team.grade_for_submission,
comment: @team.comment_for_submission)
@team.save
flash[:success] = 'Grade and comment for submission successfully saved.'
rescue StandardError
Expand Down
44 changes: 44 additions & 0 deletions app/controllers/grading_histories_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
class GradingHistoriesController < ApplicationController
include AuthorizationHelper
before_action :set_grading_history, only: %i[show]

# Checks if user is allowed to view a grading history
def action_allowed?
# admins and superadmins are always allowed
return true if current_user_has_admin_privileges?
# populate assignment fields
assignment_for_history(params[:grade_type])
# if not admin/superadmin, check permissions
if @assignment.instructor_id == current_user.id
true
elsif TaMapping.exists?(ta_id: current_user.id, course_id: @assignment.course_id) &&
(TaMapping.where(course_id: @assignment.course_id).include? TaMapping.where(ta_id: current_user.id, course_id: @assignment.course_id).first)
true
elsif @assignment.course_id && Course.find(@assignment.course_id).instructor_id == current_user.id
true
end
end

# populate the assignment fields according to type
def assignment_for_history(type)
# for a submission, the receiver is an AssignmentTeam
# use this AssignmentTeam to find the assignment
if type.eql? 'Submission'
assignment_team = AssignmentTeam.find(params[:grade_receiver_id])
@assignment = Assignment.find(assignment_team.parent_id)
end
# for a review, the receiver is an AssignmentParticipant
# use this AssignmentParticipant to find the assignment
if type.eql? 'Review'
participant_id = params[:participant_id]
grade_receiver = AssignmentParticipant.find(participant_id)
@assignment = Assignment.find(grade_receiver.parent_id)
end
end

# return all grading history entries for the assignment
# entries are returned in chronological order
def index
@grading_histories = GradingHistory.where(grade_receiver_id: params[:grade_receiver_id], grading_type: params[:grade_type]).reverse_order
end
end
10 changes: 10 additions & 0 deletions app/controllers/review_mapping_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,17 @@ def save_grade_and_comment_for_reviewer
review_grade.attributes = review_mapping_params
review_grade.review_graded_at = Time.now
review_grade.reviewer_id = session[:user].id
# E2237 create a grading history entry for this review
# save the grade, comment, receiver, and instructor
# E2383 Update the previous teams creation to match
# the current expertiza since it was outdated
begin
GradingHistory.create(instructor_id: session[:user].id,
assignment_id: Participant.find(params[:review_grade][:participant_id]).parent_id,
grading_type: 'Review',
grade_receiver_id: Participant.find(params[:review_grade][:participant_id]).user_id,
grade: review_grade.grade_for_reviewer,
comment: review_grade.comment_for_reviewer)
review_grade.save!
flash[:success] = 'Grade and comment for reviewer successfully saved.'
rescue StandardError
Expand Down
6 changes: 6 additions & 0 deletions app/models/grading_history.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# E2383 Added for tracking histories

class GradingHistory < ActiveRecord::Base
belongs_to :instructor, inverse_of: :instructor_id
belongs_to :assignment, inverse_of: :assignment_id
end
4 changes: 4 additions & 0 deletions app/models/review_grading_history.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class ReviewGradingHistory < GradingHistory
attr_protected
belongs_to :grade_receiver, class_name: 'Participant', inverse_of: :grade_receiver_id
end
4 changes: 4 additions & 0 deletions app/models/submission_grading_history.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class SubmissionGradingHistory < GradingHistory
attr_protected
belongs_to :grade_receiver, class_name: 'Team', inverse_of: :grade_receiver_id
end
4 changes: 3 additions & 1 deletion app/views/assignments/list_submissions.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,9 @@
</td>
<td width="10%">

<%= link_to "History", submission_records_path(team_id: team.id) %>
<%= link_to "Submission History", submission_records_path(team_id: team.id) %> <br/>
<br/>
<%= link_to "Grading History", grading_histories_path(grade_receiver_id: team.id, grade_type: "Submission") %>

</td>
</tr>
Expand Down
10 changes: 10 additions & 0 deletions app/views/grading_histories/_form.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
= form_for @grading_history do |f|
- if @grading_history.errors.any?
#error_explanation
%h2= "#{pluralize(@grading_history.errors.count, "error")} prohibited this grading_history from being saved:"
%ul
- @grading_history.errors.full_messages.each do |message|
%li= message

.actions
= f.submit 'Save'
38 changes: 38 additions & 0 deletions app/views/grading_histories/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<% record = @grading_histories[0]
if record == nil
receiver = ""
assignment = ""
else
if record.grading_type == "Submission"
receiver = "of " + Team.where(id: record.grade_receiver_id).pluck(:name).first
assignment = "for the submission " + Assignment.where(id: record.assignment_id).pluck(:name).first
else
receiver = "of " + User.where(id: record.grade_receiver_id).pluck(:fullname).first
assignment = "for review in " + Assignment.where(id: record.assignment_id).pluck(:name).first
end

end
%>
<h1 class="center">Grade History <%= receiver %> <%= assignment %></h1>

<table style="border-collapse:collapse; table-layout:fixed; width:1350px;">
<thead>
<tr>
<th style="padding:10px; border:solid 1.5px black; width:50px; word-wrap:break-word;">Instructor</th>
<th style="padding:10px; border:solid 1.5px black; width:50px; word-wrap:break-word;">Grade</th>
<th style="padding:10px; border:solid 1.5px black; width:50px; word-wrap:break-word;">Comment</th>
<th style="padding:10px; border:solid 1.5px black; width:50px; word-wrap:break-word;">Graded At</th>
</tr>

<!--This is the main view of the table. This will add table with either hyperlink or the content nased on the operation. -->
<tbody>
<% @grading_histories.each do |record| %>
<tr>
<td style="padding:10px; border:solid 1.5px black; width:50px; word-wrap:break-word;"><%= User.where(id: record.instructor_id).pluck(:fullname).first %></td>
<td style="padding:10px; border:solid 1.5px black; width:50px; word-wrap:break-word;"><%= record.grade %></td>
<td style="padding:10px; border:solid 1.5px black; width:50px; word-wrap:break-word;"><%= record.comment %></td>
<td style="padding:10px; border:solid 1.5px black; width:50px; word-wrap:break-word;"><%= record.created_at %></td>
</tr>
<% end %>
</tbody>
</table>
4 changes: 4 additions & 0 deletions app/views/reports/_review_report.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,10 @@
<td>
<%= form.submit 'Save' %>
</td>
<!--E2383 Added the Grading History link to the appropriate place-->
<td>
<%= link_to "Grading History", grading_histories_path(grade_receiver_id: Participant.where(id: reviewer.id).pluck(:user_id).first, participant_id: reviewer.id, grade_type: "Review")%>
</td>
</tr>
</table>
<% end %>
Expand Down
2 changes: 2 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
Expertiza::Application.routes.draw do
require 'sidekiq/web'
mount Sidekiq::Web => '/sidekiq'
#E2383 added path for grading histories
resources :grading_histories, only: [:index]

resources :admin, only: [] do
collection do
Expand Down
14 changes: 14 additions & 0 deletions spec/controllers/grading_histories_controller_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
describe GradingHistoriesController do
let(:grading_history) { build(:grading_history) }

describe ':create' do
it 'successfully creates a grading history with valid parameters' do
expect(grading_history.grade).to eq(100)
expect(grading_history.comment).to eq("Good work!")
expect(grading_history.instructor_id).to eq(6)
expect(grading_history.assignment_id).to eq(1)
expect(grading_history.grade_receiver_id).to eq(1)
expect(grading_history.id).to eq(1)
end
end
end
10 changes: 10 additions & 0 deletions spec/factories/factories.rb
Original file line number Diff line number Diff line change
Expand Up @@ -761,4 +761,14 @@
ta_id 1
course_id 1
end

factory :grading_history, class: GradingHistory do
id 1
instructor_id 6
assignment_id 1
grading_type 'Submission'
grade_receiver_id 1
grade 100
comment 'Good work!'
end
end
42 changes: 42 additions & 0 deletions spec/features/grade_histories_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
include GradeHistoriesHelperSpec

describe "Feature Tests to check the grade audit trail: " do
before(:each) do
assignment_setup
make_submission
end

describe 'The grade history' do
it 'should be visible' do
user = User.find_by(name: "instructor6")
stub_current_user(user, user.role.name, user.role)
visit '/assignments/list_submissions?id=1'
click_link 'Assign Grade'
fill_in "grade_for_submission", with: '80'
fill_in "comment_for_submission", with: 'first comment'
click_button 'Save'
visit '/grading_histories?grade_receiver_id=1&grade_type=Submission'
expect_page_content_to_have('first comment')
end

it 'should be shown in chronological order' do
user = User.find_by(name: "instructor6")
stub_current_user(user, user.role.name, user.role)
visit '/assignments/list_submissions?id=1'
click_link 'Assign Grade'
fill_in "grade_for_submission", with: '80'
fill_in "comment_for_submission", with: 'first comment'
visit '/assignments/list_submissions?id=1'
click_button 'Save'
click_link 'Assign Grade'
fill_in "grade_for_submission", with: '50'
fill_in "comment_for_submission", with: 'second comment'
click_button 'Save'
visit '/grading_histories?grade_receiver_id=1&grade_type=Submission'
table = page.all('table tr')
expect(table[0]).to have_content?("second comment")
expect(table[1]).to_have_content?("first comment")
end

end
end
36 changes: 36 additions & 0 deletions spec/helpers/grade_histories_helper_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
module GradeHistoriesHelperSpec
def assignment_setup
create(:assignment, name: "Assignment1684", directory_path: "Assignment1684")
create_list(:participant, 3)
create(:topic, topic_name: "Topic")
create(:deadline_type, name: "submission")
create(:deadline_type, name: "review")
create(:deadline_type, name: "metareview")
create(:deadline_type, name: "drop_topic")
create(:deadline_type, name: "signup")
create(:deadline_type, name: "team_formation")
create(:deadline_right)
create(:deadline_right, name: 'Late')
create(:deadline_right, name: 'OK')
create(:assignment_due_date, deadline_type: DeadlineType.where(name: "submission").first, due_at: DateTime.now.in_time_zone + 1.day)
login_as("instructor6")
user = User.find_by(name: "student2064")
stub_current_user(user, user.role.name, user.role)
visit '/student_task/list'
click_link 'Assignment1684'
click_link 'Signup sheet'
assignment_id = Assignment.first.id
visit "/sign_up_sheet/sign_up?id=#{assignment_id}&topic_id=1"
visit '/student_task/list'
click_link 'Assignment1684'
click_link 'Your team'
end

def make_submission
visit '/student_task/list'
click_link "Assignment1684"
click_link "Your work"
fill_in 'submission', with: "https://www.ncsu.edu"
click_on 'Upload link'
end
end
4 changes: 2 additions & 2 deletions spec/helpers/participants_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@

it 'returns correct authorizations when participant_permissions is called with participant authorization' do
#Checking permissions for a participant
result = participant_permissions('paricipant')
expect(result).to eq(can_submit: true, can_review: true, can_take_quiz: true, can_mentor: false)
result = participant_permissions('participant')
expect(result).to eq(can_submit: true, can_review: true, can_take_quiz: true)
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/models/collusion_cycle_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@
context 'when the reviewers of current reviewer (ap2) includes current assignment participant' do
# This before-each function is used to extract out re-appearing code used in three_node_cycle tests
# More specifically, it is used to extract out the common code used to
# create a relationship between three reviewing participants.
# create a relationship between three renewing participants.
before(:each) do
# Sets up stubs for test
allow(ReviewResponseMap).to receive(:where).with('reviewee_id = ?', team1.id).and_return([response_map_team_1_2])
Expand Down

0 comments on commit d789842

Please sign in to comment.