From 6a625f5272f12360803c0d97f738d3174622784c Mon Sep 17 00:00:00 2001 From: dinesh-pasupuleti <78731527+dinesh-pasupuleti@users.noreply.github.com> Date: Sun, 27 Oct 2024 20:50:02 -0400 Subject: [PATCH] fixed the "your work" feature (#2862) * fixed the your work feature * fixed test cases in assignment_spec file --------- Co-authored-by: root --- app/controllers/submitted_content_controller.rb | 5 ++++- app/models/assignment.rb | 12 ++++++------ app/models/due_date.rb | 8 ++++++-- app/views/submitted_content/_hyperlink.html.erb | 2 +- .../submitted_content/_submitted_files.html.erb | 2 +- spec/models/assignment_spec.rb | 14 +++++++------- 6 files changed, 25 insertions(+), 18 deletions(-) diff --git a/app/controllers/submitted_content_controller.rb b/app/controllers/submitted_content_controller.rb index b11252b808b..bea8a24c96c 100644 --- a/app/controllers/submitted_content_controller.rb +++ b/app/controllers/submitted_content_controller.rb @@ -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 diff --git a/app/models/assignment.rb b/app/models/assignment.rb index 8f9bed41aab..4c1f6580e97 100755 --- a/app/models/assignment.rb +++ b/app/models/assignment.rb @@ -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 @@ -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. diff --git a/app/models/due_date.rb b/app/models/due_date.rb index 94b07c9137a..e7ee32dec9a 100644 --- a/app/models/due_date.rb +++ b/app/models/due_date.rb @@ -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. @@ -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 diff --git a/app/views/submitted_content/_hyperlink.html.erb b/app/views/submitted_content/_hyperlink.html.erb index 6b6117f5c34..6b1cade25a6 100644 --- a/app/views/submitted_content/_hyperlink.html.erb +++ b/app/views/submitted_content/_hyperlink.html.erb @@ -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)%> diff --git a/app/views/submitted_content/_submitted_files.html.erb b/app/views/submitted_content/_submitted_files.html.erb index dbf2d09f1c6..eb64b756b25 100644 --- a/app/views/submitted_content/_submitted_files.html.erb +++ b/app/views/submitted_content/_submitted_files.html.erb @@ -22,7 +22,7 @@

<% if files.length > 0 || stage != "Finished" %> - <% if same_team_flag && stage != "Finished" %> + <% if same_team_flag && stage != "Finished" && @can_submit%>

• <%=t ".submit_file"%>

<%= 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 %> diff --git a/spec/models/assignment_spec.rb b/spec/models/assignment_spec.rb index 033df68b938..e2e1f6758c1 100644 --- a/spec/models/assignment_spec.rb +++ b/spec/models/assignment_spec.rb @@ -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