Skip to content

Commit 0e84683

Browse files
author
Strand McCutchen
committed
disable SRGB's assignment editing for past grading periods
Fixes CNVS-22398 CNVS-22398 was previously fixed with c428f832, however, that commit created issues in Continious Integration, with failures which only happened when the tests were run in parallel. c428f832 was reverted in f566717. This commit differs from the c428f832 by avoiding using fakeENV to manage creating an ENV for testing purposes. The function isInPastGradingPeriodAndNotAdmin is not as well tested as it was in c428f832, but this is preferable to having intermittent spec failures in CI. Test Plan: 1. As an admin, create an account-level grading period which ends in the past. 2. Create an assignment that is due within that grading period. 3. As a teacher, go to Gradebook, click on the grades for that assignment. 4. Observe that they are not editable. 5. Navigate to Individual View. Select the past grading period. 6. Select the assignment and a student in the Content Selection section. 7. Verify that you are unable to edit this grade. 8. Click "Submission Details." 9. Verify that you are unable to edit this grade. Change-Id: I381c3d3c78f00eabc7a685ef3a0e8fea0f886ac2 Reviewed-on: https://gerrit.instructure.com/65417 Tested-by: Jenkins Reviewed-by: Derek Bender <djbender@instructure.com> QA-Review: Jason Carter <jcarter@instructure.com> Product-Review: Christi Wruck
1 parent 23aef7c commit 0e84683

7 files changed

Lines changed: 104 additions & 22 deletions

File tree

app/coffeescripts/SubmissionDetailsDialog.coffee

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,18 @@ define [
2121
else
2222
null
2323

24+
isInPastGradingPeriodAndNotAdmin = ((assignment) ->
25+
return false unless ENV.GRADEBOOK_OPTIONS.multiple_grading_periods_enabled
26+
return false unless ENV.GRADEBOOK_OPTIONS.latest_end_date_of_admin_created_grading_periods_in_the_past
27+
28+
return false unless ENV.current_user_roles
29+
return false unless typeof ENV.current_user_roles.find == 'function'
30+
return false if ENV.current_user_roles.find (elem) -> elem == 'admin'
31+
32+
latest_end_date = new Date(ENV.GRADEBOOK_OPTIONS.latest_end_date_of_admin_created_grading_periods_in_the_past)
33+
assignment.due_at <= latest_end_date
34+
)(@assignment)
35+
2436
@url = @options.change_grade_url.replace(":assignment", @assignment.id).replace(":submission", @student.id)
2537
@submission = $.extend {}, @student["assignment_#{@assignment.id}"],
2638
label: "student_grading_#{@assignment.id}"
@@ -30,6 +42,7 @@ define [
3042
loading: true
3143
showPointsPossible: (@assignment.points_possible || @assignment.points_possible == '0') && @assignment.grading_type != "gpa_scale"
3244
shouldShowExcusedOption: true
45+
isInPastGradingPeriodAndNotAdmin: isInPastGradingPeriodAndNotAdmin
3346
@submission["assignment_grading_type_is_#{@assignment.grading_type}"] = true
3447
@submission.grade = "EX" if @submission.excused
3548
@$el = $('<div class="use-css-transitions-for-show-hide" style="padding:0;"/>')
@@ -91,4 +104,4 @@ define [
91104
@scrollCommentsToBottom()
92105

93106
@open: (assignment, student, options) ->
94-
new SubmissionDetailsDialog(assignment, student, options).open()
107+
new SubmissionDetailsDialog(assignment, student, options, ENV).open()

app/coffeescripts/ember/screenreader_gradebook/components/grading_cell_component.coffee

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,15 @@ define [
1717
isPercent: Ember.computed.equal('assignment.grading_type', 'percent')
1818
isLetterGrade: Ember.computed.equal('assignment.grading_type', 'letter_grade')
1919
isPassFail: Ember.computed.equal('assignment.grading_type', 'pass_fail')
20+
isInPastGradingPeriodAndNotAdmin: ( ->
21+
return false unless ENV.GRADEBOOK_OPTIONS.multiple_grading_periods_enabled
22+
return false unless ENV.GRADEBOOK_OPTIONS.latest_end_date_of_admin_created_grading_periods_in_the_past
23+
return false if ENV.current_user_roles.contains("admin")
24+
25+
latest_end_date = new Date(ENV.GRADEBOOK_OPTIONS.latest_end_date_of_admin_created_grading_periods_in_the_past)
26+
27+
@assignment.due_at <= latest_end_date
28+
).property('assignment')
2029
nilPointsPossible: Ember.computed.none('assignment.points_possible')
2130
isGpaScale: Ember.computed.equal('assignment.grading_type', 'gpa_scale')
2231

app/coffeescripts/ember/screenreader_gradebook/templates/components/grading-cell.hbs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,13 @@
66
value=value
77
}}
88
{{ else }}
9-
{{input value=value id=input-id type="text"}}
9+
{{
10+
input
11+
value=value
12+
id=input-id
13+
type="text"
14+
disabled=isInPastGradingPeriodAndNotAdmin
15+
}}
1016
{{/if}}
1117
{{outOfText}}
1218

@@ -19,6 +25,7 @@
1925
id="submission-excused"
2026
name="submission-excused"
2127
checked=excused
28+
disabled=isInPastGradingPeriodAndNotAdmin
2229
}}
2330
{{#t}}Excuse This Assignment for the Selected Student{{/t}}
2431
</label>

app/coffeescripts/gradebook2/Gradebook.coffee

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ define [
193193
closedAdminGradingPeriods = @getClosedAdminGradingPeriods()
194194

195195
if closedAdminGradingPeriods.length > 0
196-
assignments = @getAssignmentsInClosedGradingPeriods(closedAdminGradingPeriods)
196+
assignments = @getAssignmentsInClosedGradingPeriods()
197197
@disabledAssignments = assignments.map (a) ->
198198
a.id
199199

@@ -221,10 +221,8 @@ define [
221221
else
222222
ENV.GRADEBOOK_OPTIONS.current_grading_period_id
223223

224-
getAssignmentsInClosedGradingPeriods: (gradingPeriods) ->
225-
latestEndDate = new Date(gradingPeriods[0]?.end_date)
226-
for gradingPeriod in gradingPeriods
227-
latestEndDate = new Date(gradingPeriod.end_date) if latestEndDate < new Date(gradingPeriod.end_date)
224+
getAssignmentsInClosedGradingPeriods: () ->
225+
latestEndDate = new Date(ENV.GRADEBOOK_OPTIONS.latest_end_date_of_admin_created_grading_periods_in_the_past)
228226
#return assignments whose end date is within the latest closed's end date
229227
_.select @assignments, (a) =>
230228
@assignmentIsDueBeforeEndDate(a, latestEndDate)

app/controllers/gradebooks_controller.rb

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def grade_summary
5353
gp_id = nil
5454
if multiple_grading_periods?
5555
set_current_grading_period
56-
@grading_periods = get_active_grading_periods
56+
@grading_periods = active_grading_periods
5757
gp_id = @current_grading_period_id unless view_all_grading_periods?
5858
end
5959

@@ -250,14 +250,26 @@ def view_all_grading_periods?
250250
@current_grading_period_id == 0
251251
end
252252

253-
def get_active_grading_periods
254-
GradingPeriod.for(@context).map do |gp|
253+
def active_grading_periods
254+
@active_grading_periods ||= GradingPeriod.for(@context).map do |gp|
255255
json = gp.as_json(only: [:id, :title, :start_date, :end_date], permissions: {user: @current_user})
256256
json[:grading_period][:is_last] = gp.last?
257257
json[:grading_period]
258258
end
259259
end
260260

261+
def latest_end_date_of_admin_created_grading_periods_in_the_past
262+
periods = active_grading_periods.select do |period|
263+
# false if current user is an admin
264+
admin_created = period["permissions"]["manage"] == false
265+
in_the_past = period["end_date"] <= Time.zone.now
266+
267+
admin_created && in_the_past
268+
end
269+
periods.map { |period| period["end_date"] }.compact.sort.last
270+
end
271+
private :latest_end_date_of_admin_created_grading_periods_in_the_past
272+
261273
def set_js_env
262274
@gradebook_is_editable = @context.grants_right?(@current_user, session, :manage_grades)
263275
per_page = Setting.get('api_max_per_page', '50').to_i
@@ -299,7 +311,8 @@ def set_js_env
299311
:speed_grader_enabled => @context.allows_speed_grader?,
300312
:differentiated_assignments_enabled => @context.feature_enabled?(:differentiated_assignments),
301313
:multiple_grading_periods_enabled => multiple_grading_periods?,
302-
:active_grading_periods => get_active_grading_periods,
314+
:active_grading_periods => active_grading_periods,
315+
:latest_end_date_of_admin_created_grading_periods_in_the_past => latest_end_date_of_admin_created_grading_periods_in_the_past,
303316
:current_grading_period_id => @current_grading_period_id,
304317
:outcome_gradebook_enabled => @context.feature_enabled?(:outcome_gradebook),
305318
:custom_columns_url => api_v1_course_custom_gradebook_columns_url(@context),

app/views/jst/_grading_box.handlebars

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
class="grading_value grading_box"
55
id="student_grading_{{assignment.id}}"
66
aria-labelledby="default_grade_points"
7-
aria-describedby="default_grade_description"/>
7+
aria-describedby="default_grade_description"
8+
{{ disabledIf isInPastGradingPeriodAndNotAdmin }}
9+
/>
810
{{/if}}
911
{{#if assignment_grading_type_is_percent}}
1012
<span name="{{inputName}}" class="grading_box" id="student_grading_{{assignment.id}}">
@@ -14,7 +16,9 @@
1416
value="{{ grade }}"
1517
class="grading_value"
1618
aria-labelledby="default_grade_points"
17-
aria-describedby="default_grade_description"/>
19+
aria-describedby="default_grade_description"
20+
{{ disabledIf isInPastGradingPeriodAndNotAdmin }}
21+
/>
1822
</span>
1923
{{/if}}
2024
{{#if assignment_grading_type_is_letter_grade}}
@@ -24,7 +28,9 @@
2428
class="grading_value grading_box score_value"
2529
id="student_grading_{{assignment.id}}"
2630
aria-labelledby="default_grade_points"
27-
aria-describedby="default_grade_description"/>
31+
aria-describedby="default_grade_description"
32+
{{ disabledIf isInPastGradingPeriodAndNotAdmin }}
33+
/>
2834
{{/if}}
2935
{{#if assignment_grading_type_is_gpa_scale}}
3036
<input name="{{inputName}}"
@@ -33,10 +39,16 @@
3339
class="grading_value grading_box score_value"
3440
id="student_grading_{{assignment.id}}"
3541
aria-labelledby="default_grade_points"
36-
aria-describedby="default_grade_description"/>
42+
aria-describedby="default_grade_description"
43+
{{ disabledIf isInPastGradingPeriodAndNotAdmin }}
44+
/>
3745
{{/if}}
3846
{{#if assignment_grading_type_is_pass_fail}}
39-
<select name="{{inputName}}" class="grading_value grading_box pass_fail" id="student_grading_{{assignment.id}} %>">
47+
<select name="{{inputName}}"
48+
class="grading_value grading_box pass_fail"
49+
id="student_grading_{{assignment.id}}"
50+
{{ disabledIf isInPastGradingPeriodAndNotAdmin }}
51+
>
4052
<option value="">---</option>
4153
<option value="complete" {{selectedIf grade "complete"}}>{{#t "#gradebooks.grades.complete"}}Complete{{/t}}</option>
4254
<option value="incomplete" {{selectedIf grade "incomplete"}}>{{#t "#gradebooks.grades.incomplete"}}Incomplete{{/t}}</option>

spec/coffeescripts/gradebook/SubmissionDetailsDialogSpec.coffee

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,38 @@ define [
22
'jquery'
33
'compiled/models/Assignment'
44
'compiled/SubmissionDetailsDialog'
5+
'underscore'
56
'jst/SubmissionDetailsDialog'
6-
], ($, Assignment, SubmissionDetailsDialog) ->
7+
], ($, Assignment, SubmissionDetailsDialog, _) ->
78

89
module 'SubmissionDetailsDialog',
9-
1010
setup: ->
11+
defaults =
12+
current_user_roles: [ "teacher" ]
13+
GRADEBOOK_OPTIONS:
14+
multiple_grading_periods_enabled: true
15+
latest_end_date_of_admin_created_grading_periods_in_the_past: 'Thu Jul 30 2015 00:00:00 GMT-0700 (PDT)'
16+
@previousWindowENV = window.ENV
17+
18+
_.extend(window.ENV, defaults)
19+
1120
@assignment = new Assignment(id: 1)
1221
@user = { assignment_1: {}, id: 1, name: 'Test student' }
1322
@options = { speed_grader_enabled: true, change_grade_url: 'magic' }
1423

1524
teardown: ->
25+
window.ENV = @previousWindowENV
1626
$('.submission_details_dialog').remove()
1727

1828
test 'speed_grader_enabled sets speedgrader url', ->
19-
dialog = new SubmissionDetailsDialog(@assignment, @user, speed_grader_enabled: true, change_grade_url: ':assignment/:student')
29+
dialog = new SubmissionDetailsDialog(@assignment, @user, {speed_grader_enabled: true, change_grade_url: ':assignment/:student'})
2030
ok dialog.submission.speedGraderUrl
2131
dialog.open()
2232

2333
equal dialog.dialog.find('.more-details-link').length, 1
2434

2535
test 'speed_grader_enabled as false does not set speedgrader url', ->
26-
dialog = new SubmissionDetailsDialog(@assignment, @user, speed_grader_enabled: false, change_grade_url: ':assignment/:student')
36+
dialog = new SubmissionDetailsDialog(@assignment, @user, { speed_grader_enabled: false, change_grade_url: ':assignment/:student' })
2737
equal dialog.submission.speedGraderUrl, null
2838
dialog.open()
2939

@@ -40,33 +50,53 @@ define [
4050
module '_submission_detail',
4151

4252
setup: ->
53+
defaults =
54+
current_user_roles: [ "teacher" ]
55+
GRADEBOOK_OPTIONS:
56+
multiple_grading_periods_enabled: true
57+
latest_end_date_of_admin_created_grading_periods_in_the_past: 'Thu Jul 30 2015 00:00:00 GMT-0700 (PDT)'
58+
@previousWindowENV = window.ENV
59+
60+
_.extend(window.ENV, defaults)
61+
4362
@assignment = new Assignment(id: 1)
4463
@options = { speed_grader_enabled: true, change_grade_url: 'magic'}
4564

4665
teardown: ->
66+
window.ENV = @previousWindowENV
4767
$('.submission_details_dialog').remove()
4868

4969
test 'partial correctly makes url field if submission type is url', ->
5070
@user = { assignment_1: { submission_history: [{ submission_type: "online_url", url: "www.cnn.com" }] }, id: 1, name: 'Test student' }
51-
dialog = new SubmissionDetailsDialog(@assignment, @user, speed_grader_enabled: true, change_grade_url: ':assignment/:student')
71+
dialog = new SubmissionDetailsDialog(@assignment, @user, {speed_grader_enabled: true, change_grade_url: ':assignment/:student'})
5272
dialog.open()
5373

5474
equal dialog.dialog.find('.url-submission').length, 1
5575

5676
test 'partial correctly makes attachment fields if submission included attachments', ->
5777
@user = { assignment_1: { submission_history: [{ submission_type: "online_url", attachments: [{},{},{}] }] }, id: 1, name: 'Test student' }
58-
dialog = new SubmissionDetailsDialog(@assignment, @user, speed_grader_enabled: true, change_grade_url: ':assignment/:student')
78+
dialog = new SubmissionDetailsDialog(@assignment, @user, {speed_grader_enabled: true, change_grade_url: ':assignment/:student'})
5979
dialog.open()
6080

6181
equal dialog.dialog.find('.submisison-attachment').length, 3
6282

6383
module '_grading_box',
6484

6585
setup: ->
86+
defaults =
87+
current_user_roles: [ "teacher" ]
88+
GRADEBOOK_OPTIONS:
89+
multiple_grading_periods_enabled: true
90+
latest_end_date_of_admin_created_grading_periods_in_the_past: 'Thu Jul 30 2015 00:00:00 GMT-0700 (PDT)'
91+
@previousWindowENV = window.ENV
92+
93+
_.extend(window.ENV, defaults)
94+
6695
@assignment = new Assignment(id: 1, name: 'Test assignment', due_at: "2014-04-14T00:00:00Z")
6796
@user = { assignment_1: { submitted_at: "2014-04-20T00:00:00Z" }, id: 1, name: 'Test student' }
6897
@options = { speed_grader_enabled: false, change_grade_url: ':assignment/:student' }
6998
teardown: ->
99+
window.ENV = @previousWindowENV
70100
$('.submission_details_dialog').remove()
71101

72102
test "displays the grade as 'EX' if the submission is excused", ->

0 commit comments

Comments
 (0)