add publish state to assignments

fixes CNVS-5680

test plan:
- create an account that has enable_draft enabled
- as a teacher within that account, create an assignment
- using the api, get that assignment and check for the 'published' flag
- there should be a 'published' flag that is either true/false
- now, turn off enable_draft on the account
- using the api, get that assignment and check for the 'published' flag
- there should not be a 'published' flag

Change-Id: I161e3144ca6b82e41e72d5dbb56bebcee03e6fa4
Reviewed-on: https://gerrit.instructure.com/20609
Tested-by: Jenkins <jenkins@instructure.com>
Reviewed-by: Simon Williams <simon@instructure.com>
Product-Review: Simon Williams <simon@instructure.com>
QA-Review: Simon Williams <simon@instructure.com>
This commit is contained in:
Cameron Sutter 2013-05-13 12:53:20 -06:00
parent bc7ea54537
commit 648c3c3aab
8 changed files with 65 additions and 3 deletions

View File

@ -155,6 +155,10 @@
# // Valid if grading_type is "letter_grade".
# grading_standard_id: null,
#
# // (Only visible if 'enable draft' account setting is on)
# // whether the assignment is published
# published: true,
#
# // (Optional) explanation of lock status
# lock_explanation: "This assignment is locked until September 1 at 12:00am",
#

View File

@ -542,6 +542,9 @@ class Assignment < ActiveRecord::Base
state :published do
event :unpublish, :transitions_to => :available
end
state :unpublished do
event :publish, :transitions_to => :published
end
state :deleted
end
@ -1445,6 +1448,8 @@ class Assignment < ActiveRecord::Base
scope :order_by_base_due_at, order("assignments.due_at")
scope :unpublished, where(:workflow_state => 'unpublished')
def needs_publishing?
self.due_at && self.due_at < 1.week.ago && self.available?
end

View File

@ -136,6 +136,11 @@ module Api::V1::Assignment
!:include_assignment)
end
#show published/unpublished if account.settings[:enable_draft]
if @domain_root_account.enable_draft?
hash['published'] = ! assignment.unpublished?
end
if submission
hash['submission'] = submission_json(submission,assignment,user,session)
end

View File

@ -148,6 +148,33 @@ describe AssignmentsApiController, :type => :integration do
json.size.should == 0
end
describe "enable draft" do
before do
#set @domain_root_account
@domain_root_account = Account.default
course_with_teacher(:active_all => true)
@assignment = @course.assignments.create :name => 'some assignment'
@assignment.workflow_state = 'unpublished'
@assignment.save!
end
it "should exclude published flag for accounts that do not have enabled_draft" do
@json = api_get_assignment_in_course(@assignment, @course)
@json.has_key?('published').should be_false
end
it "should include published flag for accounts that do have enabled_draft" do
Account.default.settings[:enable_draft] = true
Account.default.save!
@json = api_get_assignment_in_course(@assignment, @course)
@json.has_key?('published').should be_true
@json['published'].should be_false
end
end
it "includes submission info with include flag" do
course_with_student_logged_in(:active_all => true)
assignment,submission = create_submitted_assignment_with_user(@user)
@ -996,6 +1023,9 @@ describe AssignmentsApiController, :type => :integration do
let(:result) { assignment_json(@assignment, @user, {}) }
before do
#set @domain_root_account
@domain_root_account = Account.default
course_with_teacher(:active_all => true)
@assignment = @course.assignments.create!(:title => "some assignment")
end

View File

@ -57,6 +57,9 @@ describe Api::V1::DiscussionTopics do
end
it "should recognize include_assignment flag" do
#set @domain_root_account
@test_api.instance_variable_set(:@domain_root_account, Account.default)
data = @test_api.discussion_topic_api_json(@topic, @topic.context, @me, nil)
data[:assignment].should be_nil

View File

@ -57,7 +57,9 @@ module Api::V1
submit(@assignment1, students[1], now, @grader2)
submit(@assignment1, students[2], yesterday, @grader2)
submit(@assignment2, students[0], yesterday, @grader2)
@days = GradebookHistoryHarness.new.days_json(course, api_context)
harness = GradebookHistoryHarness.new
harness.instance_variable_set(:@domain_root_account, ::Account.default)
@days = harness.days_json(course, api_context)
end
it 'has a top level key for each day represented' do
@ -85,7 +87,9 @@ module Api::V1
it 'paginates' do
api_context.per_page = 2
api_context.page = 2
days = GradebookHistoryHarness.new.days_json(course, api_context)
harness = GradebookHistoryHarness.new
harness.instance_variable_set(:@domain_root_account, ::Account.default)
days = harness.days_json(course, api_context)
days.map { |d| d[:date] }.first.should == yesterday.to_date.as_json
end
@ -103,7 +107,9 @@ module Api::V1
@assignment = course.assignments.create!(:title => "some assignment")
submit(@assignment, student1, now, @grader1)
submit(@assignment, student2, now, @grader2)
@day_hash = GradebookHistoryHarness.new.json_for_date(now, course, api_context)
harness = GradebookHistoryHarness.new
harness.instance_variable_set(:@domain_root_account, ::Account.default)
@day_hash = harness.json_for_date(now, course, api_context)
end
it 'returns a grader hash for that day' do

View File

@ -259,6 +259,9 @@ describe UsersController, :type => :integration do
end
it "should format graded Submission with comments" do
#set @domain_root_account
@domain_root_account = Account.default
@assignment = @course.assignments.create!(:title => 'assignment 1', :description => 'hai', :points_possible => '14.2', :submission_types => 'online_text_entry')
@teacher = User.create!(:name => 'teacher')
@course.enroll_teacher(@teacher)
@ -351,6 +354,9 @@ describe UsersController, :type => :integration do
end
it "should format ungraded Submission with comments" do
#set @domain_root_account
@domain_root_account = Account.default
@assignment = @course.assignments.create!(:title => 'assignment 1', :description => 'hai', :points_possible => '14.2', :submission_types => 'online_text_entry')
@teacher = User.create!(:name => 'teacher')
@course.enroll_teacher(@teacher)

View File

@ -159,6 +159,9 @@ describe "BookmarkedCollection::MergeProxy" do
describe "with a merge proc" do
before :each do
#set @domain_root_account
@domain_root_account = Account.default
Course.delete_all
@courses = 6.times.map{ Course.create! }
@scope1 = Course.select("id, 1 as scope").where("id<?", @courses[4].id)