Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
f5abeaa
Initial commit on grades_controller
pya1097 Mar 7, 2025
7e1d2e7
Updated ReadMe with run commands
10PriyaA Mar 16, 2025
186230c
edit, update, update_team, list_questions completed for round 1
Mar 17, 2025
75d6c9e
Gemfile commit
Mar 17, 2025
0d3f374
Merge branch 'main' of https://github.com/10PriyaA/reimplementation-b…
Mar 17, 2025
f2cbf0f
Removed unfinished work for the main branch
chrisandrews1012 Mar 17, 2025
691a09b
action_allowed and instructor_review implemented
Mar 17, 2025
8a0b2df
Merge branch 'main' of https://github.com/10PriyaA/reimplementation-b…
Mar 17, 2025
488ef51
Update grades_controller.rb
chrisandrews1012 Mar 17, 2025
5a22806
Added self_review_response_map model
10PriyaA Mar 17, 2025
3ee7eec
implemented self_review_finished? and are_needed_authorizations_present?
Mar 17, 2025
0fbf373
Merge branch 'main' of https://github.com/10PriyaA/reimplementation-b…
Mar 17, 2025
5a337c7
Added helper methods for View actions and finalized action_allowed? w…
Mar 17, 2025
e063f99
Added helpers for grades and penalties
10PriyaA Mar 17, 2025
1ae3323
Finished the three view methods and came up with questions to ask the…
Mar 17, 2025
be289cf
Added the populate_view_model
Mar 17, 2025
8fa3f71
Refactored unsubmitted_self_review and Penalty Helper
10PriyaA Mar 18, 2025
d30b2f1
Refactored redirect_when_disallowed
10PriyaA Mar 18, 2025
4b6b368
Renamed edit and update functions
10PriyaA Mar 18, 2025
83535e9
Merge pull request #1 from expertiza/main
10PriyaA Mar 18, 2025
239abfe
Added end to view function
10PriyaA Mar 20, 2025
ed638ed
Renamed view function
10PriyaA Mar 20, 2025
5ff4ea8
Updated action-allowed for OCP, removed AuthorizationHelper
10PriyaA Mar 22, 2025
2f12c0e
Wrote all of the comments for the methods and private methods in grad…
Mar 22, 2025
3078ba0
Rspec test action_allowed for TA
10PriyaA Mar 22, 2025
e6ca7bd
resolved merge conflict
10PriyaA Mar 22, 2025
17e4487
Removed the extra end and the end of the controller
10PriyaA Mar 22, 2025
1ee167f
Completed test for action_allowed
10PriyaA Mar 22, 2025
bdc3901
Added missing function in penalties
10PriyaA Mar 22, 2025
8c512eb
Added test for instructor_review
10PriyaA Mar 22, 2025
e0c8506
changed update_team method to avoid DoubleRenderError and added rspec…
10PriyaA Mar 23, 2025
86b5135
Added grade column to Participant column, updated update_participant_…
10PriyaA Mar 23, 2025
aac04fd
Added Question Model, rspec foredit_participant_scores
10PriyaA Mar 23, 2025
e3f6ae4
Moved helper functions to grades_helper
10PriyaA Mar 24, 2025
739b147
rspec for vie_team
10PriyaA Mar 24, 2025
769d8fe
added missing functions to assignment, signed_up_team, teams_user mod…
10PriyaA Mar 24, 2025
9d97168
Rspec for view_grading_reprort
10PriyaA Mar 24, 2025
347a692
Dummy data and Working API for view_grading_report, view_team, view_m…
10PriyaA Apr 18, 2025
aa1f165
participants and reviews
10PriyaA Apr 20, 2025
8515d16
Updated unit tests for controller
10PriyaA Apr 20, 2025
9c8079a
Action allowed for UI
10PriyaA Apr 22, 2025
aa6bf8c
team details
10PriyaA Apr 22, 2025
ca6e63a
Reverting some spec changes
10PriyaA Apr 24, 2025
17d4f0a
Reverted run commands
10PriyaA Apr 24, 2025
61db494
Reverted run commands
10PriyaA Apr 24, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
163 changes: 163 additions & 0 deletions app/controllers/api/v1/grades_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
class Api::V1::GradesController < ApplicationController
include GradesHelper

def action_allowed
permitted = check_permission(params[:requested_action])
render json: { allowed: permitted }, status: permitted ? :ok : :forbidden
end

# The view_grading_report offers instructors a comprehensive overview of all grades for an assignment.
# It displays all participants and the reviews they have received.
# Additionally, it provides a final score, which is the average of all reviews, and highlights the greatest
# difference in scores among the reviews.
def view_grading_report
assignment_id = params[:id].to_i
data = get_data_for_heat_map(assignment_id)

render json: data, status: :ok
end

# The view_my_scores method provides participants with a detailed overview of their performance in an assignment.
# It retrieves and their questions and calculated scores and prepares feedback summaries.
# Additionally, it applies any penalties and determines the current stage of the assignment.
# This method ensures participants have a comprehensive understanding of their scores and feedback
def view_my_scores
participant = AssignmentParticipant.find(params[:id].to_i)
assignment = participant.assignment
team_id = TeamsUser.team_id(participant.assignment_id, participant.user_id)

questions = fetch_questionnaires_and_questions(assignment)

pscore = fetch_participant_scores(participant, questions)

topic_id = SignedUpTeam.find_topic_id_for_user(participant.assignment.id, participant.user_id)
stage = participant.assignment.current_stage(topic_id)

# Feedback Summary needs to be checked once
# summary_ws_url = WEBSERVICE_CONFIG['summary_webservice_url']
sum = SummaryHelper::Summary.new.summarize_reviews_by_reviewee(questions, assignment, team_id, 'http://peerlogic.csc.ncsu.edu/sum/v1.0/summary/8/lsa', session)

render json: {
participant: participant,
assignment: assignment,
team_id: team_id,
topic_id: topic_id,
stage: stage,
questions: questions,
pscore: pscore,
summary: sum.summary,
avg_scores_by_round: sum.avg_scores_by_round,
avg_scores_by_criterion: sum.avg_scores_by_criterion
}
end

# The view_team method provides an alternative view for participants, focusing on team performance.
# It retrieves the participant, assignment, and team information, and calculated scores and penalties.
# Additionally, it prepares the necessary data for displaying team-related information.
# This method ensures participants have a clear understanding of their team's performance and any associated penalties.


def view_team
participant = AssignmentParticipant.find(params[:id])
assignment = participant.assignment
team = participant.team
team_id = team.id

user_ids = TeamsUser.where(team_id: team_id).pluck(:user_id)
users = User.where(id: user_ids)

questionnaires = AssignmentQuestionnaire.where(assignment_id: assignment.id).map(&:questionnaire)
questions = retrieve_questions(questionnaires, assignment.id)
pscore = Response.participant_scores(participant, questions)
vmlist = process_questionare_for_team(assignment, team_id,questionnaires, team, participant)

render json: {
participant: participant,
assignment: assignment,
team: team,
team_id: team_id,
questions: questions,
pscore: pscore,
vmlist: vmlist,
users: users
}
end


# Prepares the necessary information for editing grade details, including the participant, questions, scores, and assignment.
# The participant refers to the student whose grade is being modified.
# The assignment is the specific task for which the participant's grade is being reviewed.
# The questions are the rubric items or criteria associated with the assignment.
# The scores represent the combined scoring information for both the participant and their team, required for frontend display.
def edit_participant_scores
@participant = find_participant(params[:id])
return unless @participant # Exit early if participant not found
@assignment = @participant.assignment
@questions = list_questions(@assignment)
@scores = Response.review_grades(@participant, @questions)

render json: {
participant: { id: @participant.id },
assignment: { id: @assignment.id },
scores: @scores
}
end


# Update method for the grade associated with a participant.
# Allows an instructor to upgrade a participant's grade and provide feedback on their assignment submission.
# The updated participant information is saved for future scoring evaluations.
# If saving the participant fails, a flash error populates.
# Finally, the instructor is redirected to the edit pages.
def update_participant_grade
participant = AssignmentParticipant.find_by(id: params[:id])
return handle_not_found unless participant

new_grade = params[:participant][:grade]

if grade_changed?(participant, new_grade)
participant.update(grade: new_grade)
render json: { message: grade_message(participant) }, status: :ok
else
render json: { error: 'Error updating participant grade.' }, status: :unprocessable_entity
end
end

# Update the grade and comment for a participant's submission.
# Save the updated information for future evaluations.
# Handle errors by returning a bad_request response.
# Provide feedback to the user about the operation's success or failure.
def update_team
participant = AssignmentParticipant.find_by(id: params[:participant_id])
return handle_not_found unless participant

if participant.team.update(grade_for_submission: params[:grade_for_submission],
comment_for_submission: params[:comment_for_submission])
render json: { message: 'Grade and comment for submission successfully saved.' }, status: :ok
return
else
render json: { error: 'Error saving grade and comment.' }, status: :unprocessable_entity
return
end
end


# Determines the appropriate controller action for an instructor's review based on the current state.
# This method checks if a review mapping exists for the participant. If it does, the instructor is directed to edit the existing review.
# If no review mapping exists, the instructor is directed to create a new review.
# The Response controller handles both creating and editing reviews through its response#new and response#edit actions.
# This method ensures the correct action is taken by checking the existence of a review mapping and utilizing the new_record functionality.
def instructor_review
participant = find_participant(params[:id])
return unless participant # Exit early if participant not found

reviewer = find_or_create_reviewer(session[:user].id, participant.assignment.id)
review_mapping = find_or_create_review_mapping(participant.team.id, reviewer.id, participant.assignment.id)

redirect_to_review(review_mapping)
end


end


15 changes: 14 additions & 1 deletion app/controllers/concerns/authorization.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,17 @@ def has_role?(required_role)
required_role = required_role.name if required_role.is_a?(Role)
current_user&.role&.name == required_role
end
end

def are_needed_authorizations_present?(id, *authorizations)
authorization = Participant.find_by(id: id)&.authorization
authorization.present? && !authorizations.include?(authorization)
end

# Check if the currently logged-in user is a participant in an assignment
def current_user_is_assignment_participant?(assignment_id)
return false unless session[:user]

AssignmentParticipant.exists?(parent_id: assignment_id, user_id: session[:user].id)
end
end

Loading