New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
E1745. [TLD] Refactor response_controller.rb #1025
Merged
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
fe78de4
Adding test cases for response_controller_spec
8ebe1bc
Added test case for delete function in response controller
f8f7e16
Added test case for edit function in response controller
763667c
Added test case for new function and updated edit test case
dcf9969
Added test case for update function in response controller in case of…
f84cfb1
Modified test cases and added test case for update successfull
b5b435c
Refactor response conroller
pavneetanand93 b407570
Merge branch 'master' of https://github.com/dipanshagupta/expertiza
pavneetanand93 d2c908d
Adding tests for create
316a41e
Merge branch 'master' of https://github.com/dipanshagupta/expertiza
f97d5e3
Added test case for save function in response controller
e8372f8
Reverting
d1c4714
Merge branch 'master' of https://github.com/dipanshagupta/expertiza
f7510e8
Correcting redirection method and it's test
78a8b37
Merge branch 'master' of https://github.com/expertiza/expertiza
8e2d213
Rubycop changes
ed0dc13
Rubycop changes
1e4e5b3
Rubycop fixes
6e05d26
Rubycop changes
6892b6d
Moved uncommon stubs to respective methods
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 |
---|---|---|
|
@@ -3,31 +3,37 @@ class ResponseController < ApplicationController | |
helper :file | ||
|
||
def action_allowed? | ||
case params[:action] | ||
when 'edit' # If response has been submitted, no further editing allowed | ||
response = user_id = nil | ||
action = params[:action] | ||
if %w(edit delete update view).include?(action) | ||
response = Response.find(params[:id]) | ||
user_id = response.map.reviewer.user_id if (response.map.reviewer) | ||
end | ||
case action | ||
when 'edit' # If response has been submitted, no further editing allowed | ||
return false if response.is_submitted | ||
return current_user_id?(response.map.reviewer.user_id) | ||
return current_user_id?(user_id) | ||
# Deny access to anyone except reviewer & author's team | ||
when 'delete', 'update' | ||
response = Response.find(params[:id]) | ||
return current_user_id?(response.map.reviewer.user_id) | ||
return current_user_id?(user_id) | ||
when 'view' | ||
response = Response.find(params[:id]) | ||
map = response.map | ||
assignment = response.map.reviewer.assignment | ||
# if it is a review response map, all the members of reviewee team should be able to view the reponse (can be done from heat map) | ||
if map.is_a? ReviewResponseMap | ||
reviewee_team = AssignmentTeam.find(map.reviewee_id) | ||
return current_user_id?(response.map.reviewer.user_id) || reviewee_team.has_user(current_user) || current_user.role.name == 'Administrator' || (current_user.role.name == 'Instructor' and assignment.instructor_id == current_user.id) || (current_user.role.name == 'Teaching Assistant' and TaMapping.exists?(ta_id: current_user.id, course_id: assignment.course.id)) | ||
else | ||
return current_user_id?(response.map.reviewer.user_id) | ||
end | ||
return edit_allowed?(response.map, user_id) | ||
else | ||
current_user | ||
end | ||
end | ||
|
||
def edit_allowed?(map, user_id) | ||
assignment = map.reviewer.assignment | ||
# if it is a review response map, all the members of reviewee team should be able to view the reponse (can be done from heat map) | ||
if map.is_a? ReviewResponseMap | ||
reviewee_team = AssignmentTeam.find(map.reviewee_id) | ||
return current_user_id?(user_id) || reviewee_team.has_user(current_user) || current_user.role.name == 'Administrator' || (current_user.role.name == 'Instructor' and assignment.instructor_id == current_user.id) || (current_user.role.name == 'Teaching Assistant' and TaMapping.exists?(ta_id: current_user.id, course_id: assignment.course.id)) | ||
else | ||
return current_user_id?(user_id) | ||
end | ||
end | ||
|
||
def delete | ||
@response = Response.find(params[:id]) | ||
# user cannot delete other people's responses. Needs to be authenticated. | ||
|
@@ -163,8 +169,7 @@ def saving | |
def redirection | ||
flash[:error] = params[:error_msg] unless params[:error_msg] and params[:error_msg].empty? | ||
flash[:note] = params[:msg] unless params[:msg] and params[:msg].empty? | ||
@map = Response.find_by_map_id(params[:id]) | ||
|
||
@map = Response.find_by(map_id: params[:id]) | ||
if params[:return] == "feedback" | ||
redirect_to controller: 'grades', action: 'view_my_scores', id: @map.reviewer.id | ||
elsif params[:return] == "teammate" | ||
|
@@ -200,49 +205,28 @@ def pending_surveys | |
return | ||
end | ||
|
||
# Get all the participant(course or assignment) entries for this user | ||
course_participants = CourseParticipant.where(user_id: session[:user].id) | ||
assignment_participants = AssignmentParticipant.where(user_id: session[:user].id) | ||
|
||
# Get all the course survey deployments for this user | ||
@surveys = [] | ||
if course_participants | ||
course_participants.each do |cp| | ||
survey_deployments = CourseSurveyDeployment.where(parent_id: cp.parent_id) | ||
next unless survey_deployments | ||
survey_deployments.each do |survey_deployment| | ||
next unless survey_deployment && Time.now > survey_deployment.start_date && Time.now < survey_deployment.end_date | ||
@surveys << | ||
[ | ||
'survey' => Questionnaire.find(survey_deployment.questionnaire_id), | ||
'survey_deployment_id' => survey_deployment.id, | ||
'start_date' => survey_deployment.start_date, | ||
'end_date' => survey_deployment.end_date, | ||
'parent_id' => cp.parent_id, | ||
'participant_id' => cp.id, | ||
'global_survey_id' => survey_deployment.global_survey_id | ||
] | ||
end | ||
end | ||
end | ||
|
||
# Get all the assignment survey deployments for this user | ||
if assignment_participants | ||
assignment_participants.each do |ap| | ||
survey_deployments = AssignmentSurveyDeployment.where(parent_id: ap.parent_id) | ||
[CourseParticipant, AssignmentParticipant].each do |item| | ||
# Get all the participant(course or assignment) entries for this user | ||
participant_type = item.where(user_id: session[:user].id) | ||
next unless participant_type | ||
participant_type.each do |p| | ||
survey_deployment_type = participant_type == CourseParticipant ? AssignmentSurveyDeployment : CourseSurveyDeployment | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think the logic here is correct. |
||
survey_deployments = survey_deployment_type.where(parent_id: p.parent_id) | ||
next unless survey_deployments | ||
survey_deployments.each do |survey_deployment| | ||
next unless survey_deployment && Time.now > survey_deployment.start_date && Time.now < survey_deployment.end_date | ||
@surveys << | ||
[ | ||
'survey' => Questionnaire.find(survey_deployment.questionnaire_id), | ||
'survey_deployment_id' => survey_deployment.id, | ||
'start_date' => survey_deployment.start_date, | ||
'end_date' => survey_deployment.end_date, | ||
'parent_id' => ap.parent_id, | ||
'participant_id' => ap.id, | ||
'global_survey_id' => survey_deployment.global_survey_id | ||
] | ||
[ | ||
'survey' => Questionnaire.find(survey_deployment.questionnaire_id), | ||
'survey_deployment_id' => survey_deployment.id, | ||
'start_date' => survey_deployment.start_date, | ||
'end_date' => survey_deployment.end_date, | ||
'parent_id' => p.parent_id, | ||
'participant_id' => p.id, | ||
'global_survey_id' => survey_deployment.global_survey_id | ||
] | ||
end | ||
end | ||
end | ||
|
@@ -313,7 +297,7 @@ def set_dropdown_or_scale | |
end | ||
|
||
def sort_questions(questions) | ||
questions.sort {|a, b| a.seq <=> b.seq } | ||
questions.sort_by(&:seq) | ||
end | ||
|
||
def create_answers(params, questions) | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good refactoring!