Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
brwali committed Oct 29, 2024
2 parents f466be4 + 6a625f5 commit 363b57e
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 18 deletions.
5 changes: 4 additions & 1 deletion app/controllers/submitted_content_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,11 @@ def edit
# hence use team count for the check
SignUpSheet.signup_team(@assignment.id, @participant.user_id, nil) if @participant.team.nil?
# @can_submit is the flag indicating if the user can submit or not in current stage
@can_submit = !params.key?(:view)
@can_submit = false
@stage = @assignment.current_stage(SignedUpTeam.topic_id(@participant.parent_id, @participant.user_id))
if @stage == "submission"
@can_submit = true
end
end

# view is called when @assignment.submission_allowed(topic_id) is false
Expand Down
12 changes: 6 additions & 6 deletions app/models/assignment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,8 @@ def path
# Check whether review, metareview, etc.. is allowed
# The permissions of TopicDueDate is the same as AssignmentDueDate.
# Here, column is usually something like 'review_allowed_id'
def check_condition(column, topic_id = nil)
next_due_date = DueDate.get_next_due_date(id, topic_id)
def check_condition(column, topic_id = nil, deadline_type_id)
next_due_date = DueDate.get_next_due_date(id, topic_id, deadline_type_id)
return false if next_due_date.nil?

right_id = next_due_date.send column
Expand All @@ -200,22 +200,22 @@ def check_condition(column, topic_id = nil)

# Determine if the next due date from now allows for submissions
def submission_allowed(topic_id = nil)
check_condition('submission_allowed_id', topic_id)
check_condition('submission_allowed_id', topic_id, 1)
end

# Determine if the next due date from now allows to take the quizzes
def quiz_allowed(topic_id = nil)
check_condition('quiz_allowed_id', topic_id)
check_condition('quiz_allowed_id', topic_id, 11)
end

# Determine if the next due date from now allows for reviews
def can_review(topic_id = nil)
check_condition('review_allowed_id', topic_id)
check_condition('review_allowed_id', topic_id, 2)
end

# Determine if the next due date from now allows for metareviews
def metareview_allowed(topic_id = nil)
check_condition('review_of_review_allowed_id', topic_id)
check_condition('review_of_review_allowed_id', topic_id, 5)
end

# Deletes all instances created as part of assignment and finally destroys itself.
Expand Down
8 changes: 6 additions & 2 deletions app/models/due_date.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def self.done_in_assignment_round(assignment_id, response)
round
end

def self.get_next_due_date(assignment_id, topic_id = nil)
def self.get_next_due_date(assignment_id, topic_id = nil, deadline_type_id = 0)
if Assignment.find(assignment_id).staggered_deadline?
next_due_date = TopicDueDate.find_by(['parent_id = ? and due_at >= ?', topic_id, Time.zone.now])
# if certion TopicDueDate is not exist, we should query next corresponding AssignmentDueDate.
Expand All @@ -113,7 +113,11 @@ def self.get_next_due_date(assignment_id, topic_id = nil)
end
end
else
next_due_date = AssignmentDueDate.find_by(['parent_id = ? && due_at >= ?', assignment_id, Time.zone.now])
if deadline_type_id == 0
next_due_date = AssignmentDueDate.find_by(['parent_id = ? && due_at >= ? ', assignment_id, Time.zone.now])
else
next_due_date = AssignmentDueDate.find_by(['parent_id = ? && deadline_type_id = ? && due_at >= ? ', assignment_id, deadline_type_id, Time.zone.now])
end
end
next_due_date
end
Expand Down
2 changes: 1 addition & 1 deletion app/views/submitted_content/_hyperlink.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<%= form_for :hyperlinks, url: '/submitted_content/remove_hyperlink' do |f| %>
<% unless stage == "Finished" %>
<% if stage != "Finished" && @can_submit%>
<% team_id = TeamsUser.team_id(participant.parent_id, participant.user_id) %>
<% display_to_author = Team.exists?(team_id) && Team.find(team_id).user?(@current_user)%>

Expand Down
2 changes: 1 addition & 1 deletion app/views/submitted_content/_submitted_files.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<br/><br/>

<% if files.length > 0 || stage != "Finished" %>
<% if same_team_flag && stage != "Finished" %>
<% if same_team_flag && stage != "Finished" && @can_submit%>
<h4>&#8226; <%=t ".submit_file"%></h4>
<%= form_tag({:controller=>'submitted_content',:action=>'submit_file',:id => participant.id, :origin => origin ||= nil, :response_map_id => response_map_id ||= nil},{:method => 'post', :enctype => "multipart/form-data", :onSubmit => "return checkIfFileExists(uploaded_file.value,1);"}) do %>
<!--<input type="checkbox" name="unzip" value=""/> Unzip submission-->
Expand Down
14 changes: 7 additions & 7 deletions spec/models/assignment_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -240,39 +240,39 @@
describe '#check_condition' do
context 'when the next due date is nil' do
it 'returns false ' do
allow(DueDate).to receive(:get_next_due_date).with(1, nil).and_return(nil)
expect(assignment.check_condition('review_allowed_id')).to be false
allow(DueDate).to receive(:get_next_due_date).with(1, nil, 2).and_return(nil)
expect(assignment.check_condition('review_allowed_id', nil, 2)).to be false
end
end

context 'when the next due date is allowed to review submissions' do
it 'returns true' do
assignment_due_date = double('AssignmentDueDate')
allow(DueDate).to receive(:get_next_due_date).with(1, nil).and_return(assignment_due_date)
allow(DueDate).to receive(:get_next_due_date).with(1, nil, 2).and_return(assignment_due_date)
allow(assignment_due_date).to receive(:send).with('review_allowed_id').and_return(1)
allow(DeadlineRight).to receive(:find).with(1).and_return(double('DeadlineRight', name: 'OK'))
expect(assignment.check_condition('review_allowed_id')).to be true
expect(assignment.check_condition('review_allowed_id', nil, 2)).to be true
end
end
end

describe '#submission_allowed' do
it 'returns true when the next topic due date is allowed to submit sth' do
allow(assignment).to receive(:check_condition).with('submission_allowed_id', 123).and_return(true)
allow(assignment).to receive(:check_condition).with('submission_allowed_id', 123, 1).and_return(true)
expect(assignment.submission_allowed(123)).to be true
end
end

describe '#quiz_allowed' do
it 'returns false when the next topic due date is not allowed to do quiz' do
allow(assignment).to receive(:check_condition).with('quiz_allowed_id', 456).and_return(false)
allow(assignment).to receive(:check_condition).with('quiz_allowed_id', 456, 11).and_return(false)
expect(assignment.quiz_allowed(456)).to be false
end
end

describe '#can_review' do
it "returns false when the next assignment due date is not allowed to review other's work" do
allow(assignment).to receive(:check_condition).with('review_allowed_id', nil).and_return(true)
allow(assignment).to receive(:check_condition).with('review_allowed_id', nil, 2).and_return(true)
expect(assignment.can_review).to be true
end
end
Expand Down

0 comments on commit 363b57e

Please sign in to comment.