prevent deleting frozen assignments and their groups on index page

fixes CNVS-7669

test plan:
- enable draft mode
- create a course with frozen assignments
- from the assignments index page only
- verify that "delete" option does not appear under gear wheel for:
 * frozen assignments
 * groups with frozen assignments

Change-Id: I55c7a429efc58d014b3e28d7681bc6a245578d81
Reviewed-on: https://gerrit.instructure.com/24203
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:
Liz Abinante 2013-09-09 15:44:23 -05:00
parent e6870fce02
commit 5aa7691a34
6 changed files with 61 additions and 16 deletions

View File

@ -54,3 +54,7 @@ define [
assignments = @get('assignments')
return [] unless assignments?
assignments.pluck('id')
hasFrozenAssignments: ->
@get('assignments').any (m) ->
m.get('frozen')

View File

@ -121,6 +121,7 @@ define [
showWeight: showWeight
groupWeight: data.group_weight
toggleMessage: @messages.toggleMessage
hasFrozenAssignments: @model.hasFrozenAssignments? and @model.hasFrozenAssignments()
})
displayableRules: ->

View File

@ -64,14 +64,16 @@
data-focus-returns-to="ag_{{id}}_manage_link"
>{{#t "edit"}}Edit{{/t}}</a>
</li>
<li>
<a
href="#"
class="delete_group icon-trash"
title='{{#t "title_delete"}}Delete Assignment Group?{{/t}}'
data-focus-returns-to="ag_{{id}}_manage_link"
>{{#t "delete"}}Delete{{/t}}</a>
</li>
{{#unless hasFrozenAssignments}}
<li>
<a
href="#"
class="delete_group icon-trash"
title='{{#t "title_delete"}}Delete Assignment Group?{{/t}}'
data-focus-returns-to="ag_{{id}}_manage_link"
>{{#t "delete"}}Delete{{/t}}</a>
</li>
{{/unless}}
</ul>
{{/if}}
</div>

View File

@ -88,6 +88,7 @@
data-focus-returns-to="assign_{{id}}_manage_link"
>{{#t "edit"}}Edit{{/t}}</a>
</li>
{{#unless frozen }}
<li role="presentation">
<a
href="#"
@ -98,6 +99,7 @@
title="{{#t "delete_asssignment_title"}}Delete this assignment{{/t}}"
>{{#t "delete"}}Delete{{/t}}</a>
</li>
{{/unless}}
</ul>
</div>

View File

@ -1,6 +1,7 @@
define [
'compiled/models/Assignment'
'compiled/models/AssignmentGroup'
], (AssignmentGroup) ->
], (Assignment, AssignmentGroup) ->
module "AssignmentGroup"
@ -39,3 +40,11 @@ define [
test "#countRules returns false if the group has no rules", ->
ag = new AssignmentGroup
strictEqual ag.countRules(), 0
module "AssignmentGroup#hasFrozenAssignments"
test "returns true if AssignmentGroup has frozen assignments", ->
assignment = new Assignment name: 'cheese'
assignment.set 'frozen', [ true ]
group = new AssignmentGroup name: 'taco', assignments: [ assignment ]
deepEqual group.hasFrozenAssignments(), true

View File

@ -523,13 +523,6 @@ describe "assignments" do
end
@asmnt.reload.assignment_group.name.should == "other"
end
it "should not allow assignment group to be deleted by teacher if "+
"assignment group id frozen" do
get "/courses/#{@course.id}/assignments"
fj("#group_#{@asmnt.assignment_group_id} .delete_group_link").should be_nil
fj("#assignment_#{@asmnt.id} .delete_assignment_link").should be_nil
end
end
context "draft state" do
@ -672,6 +665,40 @@ describe "assignments" do
end
end
context "frozen assignments" do
before do
@att_map = {
"assignment_group_id" => "true"
}
PluginSetting.stubs(:settings_for_plugin).returns(@att_map)
@asmnt = @course.assignments.create!(
:name => "frozen",
:due_at => Time.now.utc + 2.days,
:assignment_group => @course.assignment_groups.create!(:name => "default"),
:freeze_on_copy => true
)
@asmnt.copied = true
@asmnt.save!
@course.assignment_groups.create!(:name => "other")
end
it "should not allow assignment group to be deleted by teacher if assignments are frozen" do
get "/courses/#{@course.id}/assignments"
fj("#ag_#{@asmnt.assignment_group_id}_manage_link").click
wait_for_ajaximations
element_exists("div#assignment_group_#{@asmnt.assignment_group_id} a.delete_group").should be_false
end
it "should not allow deleting a frozen assignment from index page" do
get "/courses/#{@course.id}/assignments"
fj("div#assignment_#{@asmnt.id} a.al-trigger").click
wait_for_ajaximations
element_exists("div#assignment_#{@asmnt.id} a.delete_assignment:visible").should be_false
end
end
context 'publishing' do
before do
ag = @course.assignment_groups.first