Skip to content

Commit a486dcf

Browse files
committed
allow students in new assignment index page
closes CNVS-7159 test plan: - go to the new assignment index page as a student - it should show the assignment list - it should not show any of the add/edit/delete controls - it should not show unpublished assignments note: this only enables support for the page arranged by assignment group for students. we will add support for arranging the assignments by due date (and make that the default) soon. Change-Id: I2ebe8d65289152ff37d13b0a7e9b9ebbf5aae371 Reviewed-on: https://gerrit.instructure.com/22681 Tested-by: Jenkins <jenkins@instructure.com> Reviewed-by: Cameron Sutter <csutter@instructure.com> QA-Review: Amber Taniuchi <amber@instructure.com> Product-Review: Simon Williams <simon@instructure.com>
1 parent 4dcafce commit a486dcf

13 files changed

Lines changed: 237 additions & 140 deletions

app/coffeescripts/bundles/assignment_index.coffee

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,26 +35,32 @@ require [
3535
modules: ENV.MODULES
3636
params:
3737
include: ["assignments"]
38-
override_assignment_dates: false
39-
40-
assignmentSettingsView = new AssignmentSettingsView
41-
model: course
42-
assignmentGroups: assignmentGroups
43-
weightsView: AssignmentGroupWeightsView
38+
override_assignment_dates: !ENV.PERMISSIONS.manage
4439

4540
inputFilterView = new InputFilterView
4641
collection: assignmentGroups
4742

4843
assignmentGroupsView = new AssignmentGroupListView
4944
collection: assignmentGroups
5045

46+
assignmentSettingsView = false
47+
createGroupView = false
48+
49+
if ENV.PERMISSIONS.manage
50+
assignmentSettingsView = new AssignmentSettingsView
51+
model: course
52+
assignmentGroups: assignmentGroups
53+
weightsView: AssignmentGroupWeightsView
54+
55+
createGroupView = new CreateGroupView
56+
assignmentGroups: assignmentGroups
57+
course: course
58+
5159
@app = new IndexView
5260
assignmentGroupsView: assignmentGroupsView
5361
inputFilterView: inputFilterView
5462
assignmentSettingsView: assignmentSettingsView
55-
createGroupView: new CreateGroupView
56-
assignmentGroups: assignmentGroups
57-
course: course
63+
createGroupView: createGroupView
5864

5965
@app.render()
6066

app/coffeescripts/views/assignments/AssignmentGroupListItemView.coffee

Lines changed: 36 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -38,19 +38,25 @@ define [
3838
# we need to make sure that all children view are also children dom
3939
# elements first.
4040
render: ->
41-
@createAssignmentView.remove()
42-
@editGroupView.remove()
41+
@createAssignmentView.remove() if @createAssignmentView
42+
@editGroupView.remove() if @editGroupView
4343
super
4444

4545
afterRender: ->
46-
# child views so they get rendered automatically, need to stop it
47-
@createAssignmentView.hide()
48-
@editGroupView.hide()
49-
@deleteGroupView.hide()
50-
# its trigger would not be rendered yet, set it manually
51-
@createAssignmentView.setTrigger @$addAssignmentButton
52-
@editGroupView.setTrigger @$editGroupButton
53-
@deleteGroupView.setTrigger @$deleteGroupButton
46+
# need to hide child views and set trigger manually
47+
48+
if @createAssignmentView
49+
@createAssignmentView.hide()
50+
@createAssignmentView.setTrigger @$addAssignmentButton
51+
52+
if @editGroupView
53+
@editGroupView.hide()
54+
@editGroupView.setTrigger @$editGroupButton
55+
56+
if @deleteGroupView
57+
@deleteGroupView.hide()
58+
@deleteGroupView.setTrigger @$deleteGroupButton
59+
5460
#listen for events that cause auto-expanding
5561
@collection.on('add', => if !@isExpanded() then @toggle() )
5662

@@ -68,23 +74,29 @@ define [
6874
@model.groupView = @
6975
@initCache()
7076

71-
@editGroupView = new CreateGroupView
72-
assignmentGroup: @model
73-
assignments: @collection.models
74-
@createAssignmentView = new CreateAssignmentView
75-
assignmentGroup: @model
76-
collection: @collection
77-
@deleteGroupView = new DeleteGroupView
78-
model: @model
79-
assignments: @collection
77+
@editGroupView = false
78+
@createAssignmentView = false
79+
@deleteGroupView = false
80+
81+
if ENV.PERMISSIONS.manage
82+
@editGroupView = new CreateGroupView
83+
assignmentGroup: @model
84+
assignments: @collection.models
85+
@createAssignmentView = new CreateAssignmentView
86+
assignmentGroup: @model
87+
collection: @collection
88+
@deleteGroupView = new DeleteGroupView
89+
model: @model
90+
assignments: @collection
8091

8192
# this is the only way to get the number of assignments to update properly
8293
# when an assignment is created in a new assignment group (before refreshing the page)
8394
refreshDeleteDialog: =>
84-
@deleteGroupView.remove()
85-
@deleteGroupView = new DeleteGroupView
86-
model: @model
87-
assignments: @collection
95+
if @deleteGroupView
96+
@deleteGroupView.remove()
97+
@deleteGroupView = new DeleteGroupView
98+
model: @model
99+
assignments: @collection
88100

89101
initCache: ->
90102
$.extend true, @, Cache
@@ -95,7 +107,7 @@ define [
95107

96108
toJSON: ->
97109
count = @countRules()
98-
showRules = count != 0
110+
showRules = count != 0 and ENV.PERMISSIONS.manage
99111

100112
data = @model.toJSON()
101113
showWeight = @model.collection.course?.get('apply_assignment_group_weights')

app/coffeescripts/views/assignments/AssignmentListItemView.coffee

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,11 @@ define [
1313

1414
initialize: ->
1515
super
16-
@publishIconView = new PublishIconView(model: @model)
17-
@model.on('change:published', @upatePublishState)
16+
17+
@publishIconView = false
18+
if ENV.PERMISSIONS.manage
19+
@publishIconView = new PublishIconView(model: @model)
20+
@model.on('change:published', @upatePublishState)
1821

1922
upatePublishState: =>
2023
@$('.ig-row').toggleClass('ig-published', @model.get('published'))

app/coffeescripts/views/assignments/IndexView.coffee

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,12 @@ define [
1818
'#assignmentSettingsCog': '$assignmentSettingsButton'
1919

2020
afterRender: ->
21-
# child views so they get rendered automatically, need to stop it
22-
@createGroupView.hide()
23-
@assignmentSettingsView.hide()
24-
# its trigger would not be rendered yet, set it manually
25-
@assignmentSettingsView.setTrigger @$assignmentSettingsButton
26-
@createGroupView.setTrigger @$addGroupButton
21+
# need to hide child views and set trigger manually
22+
23+
if @createGroupView
24+
@createGroupView.hide()
25+
@createGroupView.setTrigger @$addGroupButton
26+
27+
if @assignmentSettingsView
28+
@assignmentSettingsView.hide()
29+
@assignmentSettingsView.setTrigger @$assignmentSettingsButton

app/controllers/assignments_api_controller.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -303,12 +303,12 @@ def index
303303

304304
@assignments = Assignment.search_by_attribute(@assignments, :title, params[:search_term])
305305

306-
#fake assignment used for checking if the @current_user can read unpublished assignments
306+
# fake assignment used for checking if the @current_user can read unpublished assignments
307307
fake = @context.assignments.new
308308
fake.workflow_state = 'unpublished'
309309

310310
if @domain_root_account.enable_draft? && !fake.grants_right?(@current_user, session, :read)
311-
#user is a student and assignment is not published
311+
# user should not see unpublished assignments
312312
@assignments = @assignments.published
313313
end
314314

@@ -355,7 +355,7 @@ def show
355355
:include => [:assignment_group, :rubric_association, :rubric])
356356

357357
if @domain_root_account.enable_draft? && !@assignment.grants_right?(@current_user, session, :read)
358-
#assignment is not published and user is a student
358+
# user should not see unpublished assignments
359359
render_unauthorized_action @assignment
360360
return
361361
end

app/controllers/assignments_controller.rb

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -37,23 +37,22 @@ def index
3737
if authorized_action(@context, @current_user, :read)
3838
return unless tab_enabled?(@context.class::TAB_ASSIGNMENTS)
3939

40-
if @context.grants_right?(@current_user, :update)
41-
js_env({
42-
:URLS => {
43-
:new_assignment_url => new_polymorphic_url([@context, :assignment]),
44-
:course_url => api_v1_course_url(@context),
45-
},
46-
:MODULES => get_module_names
47-
})
48-
49-
respond_to do |format|
50-
format.html do
51-
@padless = true
52-
render :action => :new_index
53-
end
40+
permissions = @context.grants_rights?(@current_user, :manage_assignments, :manage_grades)
41+
permissions[:manage] = permissions[:manage_assignments] || permissions[:manage_grades]
42+
js_env({
43+
:URLS => {
44+
:new_assignment_url => new_polymorphic_url([@context, :assignment]),
45+
:course_url => api_v1_course_url(@context),
46+
},
47+
:PERMISSIONS => permissions,
48+
:MODULES => get_module_names
49+
})
50+
51+
respond_to do |format|
52+
format.html do
53+
@padless = true
54+
render :action => :new_index
5455
end
55-
else
56-
old_index
5756
end
5857
end
5958
end

app/stylesheets/new_assignments.sass

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,6 @@
4949
line-height: 20px
5050
border-bottom: 0
5151
font-weight: bold
52+
53+
.ig-details
54+
width: 450px

app/views/jst/assignments/AssignmentGroupListItem.handlebars

Lines changed: 39 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -23,46 +23,51 @@
2323
</ul>
2424
{{/ifAny}}
2525

26-
<a
27-
href="#"
28-
class="btn add_assignment"
29-
title='{{#t "add_assignment_to"}}Add Assignment to {{name}}{{/t}}'
30-
>
31-
{{! icon is separate from <a> tag because it is the only visible content in the button }}
32-
<span class="screenreader-only">{{#t "add_assignment_to"}}Add Assignment to {{name}}{{/t}}</span>
33-
<i class="icon-plus"></i>
34-
</a>
26+
{{#if ENV.PERMISSIONS.manage}}
27+
<a
28+
href="#"
29+
class="btn add_assignment"
30+
title='{{#t "add_assignment_to"}}Add Assignment to {{name}}{{/t}}'
31+
>
32+
{{! icon is separate from <a> tag because it is the only visible content in the button }}
33+
<span class="screenreader-only">{{#t "add_assignment_to"}}Add Assignment to {{name}}{{/t}}</span>
34+
<i class="icon-plus"></i>
35+
</a>
3536

36-
<a id="ag_{{id}}_manage_link" class="al-trigger btn">
37-
<span class="screenreader-only">{{#t "manage"}}Manage{{/t}}</span>
38-
<i class="icon-settings"></i><i class="icon-mini-arrow-down"></i>
39-
</a>
40-
<ul class="al-options">
41-
<li>
42-
<a
43-
href="#"
44-
class="edit_group icon-edit"
45-
title='{{#t "title_edit"}}Edit Assignment Group{{/t}}'
46-
data-focus-returns-to="ag_{{id}}_manage_link"
47-
>{{#t "edit"}}Edit{{/t}}</a>
48-
</li>
49-
<li>
50-
<a
51-
href="#"
52-
class="delete_group icon-trash"
53-
title='{{#t "title_delete"}}Delete Assignment Group?{{/t}}'
54-
data-focus-returns-to="ag_{{id}}_manage_link"
55-
>{{#t "delete"}}Delete{{/t}}</a>
56-
</li>
57-
</ul>
37+
<a id="ag_{{id}}_manage_link" class="al-trigger btn">
38+
<span class="screenreader-only">{{#t "manage"}}Manage{{/t}}</span>
39+
<i class="icon-settings"></i><i class="icon-mini-arrow-down"></i>
40+
</a>
41+
<ul class="al-options">
42+
<li>
43+
<a
44+
href="#"
45+
class="edit_group icon-edit"
46+
title='{{#t "title_edit"}}Edit Assignment Group{{/t}}'
47+
data-focus-returns-to="ag_{{id}}_manage_link"
48+
>{{#t "edit"}}Edit{{/t}}</a>
49+
</li>
50+
<li>
51+
<a
52+
href="#"
53+
class="delete_group icon-trash"
54+
title='{{#t "title_delete"}}Delete Assignment Group?{{/t}}'
55+
data-focus-returns-to="ag_{{id}}_manage_link"
56+
>{{#t "delete"}}Delete{{/t}}</a>
57+
</li>
58+
</ul>
59+
{{/if}}
5860
</div>
5961

6062
</h2>
6163

6264
<div id="assignment_group_{{id}}_assignments" >
6365
<ul class="collectionViewItems ig-list"></ul>
6466
</div>
65-
<form data-view="createAssignment" class="form-dialog"></form>
66-
<form data-view="editAssignmentGroup" class="form-dialog"></form>
67-
<form data-view="deleteAssignmentGroup" class="form-dialog" serialize-radio-value></form>
67+
68+
{{#if ENV.PERMISSIONS.manage}}
69+
<form data-view="createAssignment" class="form-dialog"></form>
70+
<form data-view="editAssignmentGroup" class="form-dialog"></form>
71+
<form data-view="deleteAssignmentGroup" class="form-dialog" serialize-radio-value></form>
72+
{{/if}}
6873
</div>

app/views/jst/assignments/AssignmentListItem.handlebars

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,36 +4,41 @@
44
{{name}}
55
</a>
66
<div class="ig-details row-fluid">
7-
<div class="span4 ellipses modules">
8-
{{#ifEqual module_count 1}}
9-
{{module_name}} {{#t "module"}}Module{{/t}}
10-
{{else}}
11-
{{#if has_modules}}
7+
{{#if ENV.PERMISSIONS.manage}}
8+
<div class="span4 ellipses modules">
9+
{{#if has_modules}}
10+
{{#ifEqual module_count 1}}
11+
{{module_name}} {{#t "module"}}Module{{/t}}
12+
{{else}}
1213
<a href='#' title='{{joined_names}}' class="tooltip_link" data-tooltip-selector="#module_tooltip_{{labelId}}">
1314
{{#t "multiple_modules"}}Multiple Modules{{/t}}
1415
</a>
15-
{{/if}}
16-
{{/ifEqual}}
17-
</div>
18-
{{#if has_modules}}
19-
<div id="module_tooltip_{{labelId}}" style="display:none;">
20-
{{#each modules}}
21-
<span>{{this}}</span><br/>
22-
{{/each}}
16+
{{/ifEqual}}
17+
<div id="module_tooltip_{{labelId}}" style="display:none;">
18+
{{#each modules}}
19+
<span>{{this}}</span><br/>
20+
{{/each}}
21+
</div>
22+
{{/if}}
2323
</div>
2424
{{/if}}
25+
2526
<div class="span4 ellipses">
2627
<!-- TODO: VDD -->
2728
{{#if dueAt}}
2829
<strong>{{#t "due_date"}}Due{{/t}}</strong>
2930
{{datetimeFormatted dueAt}}
3031
{{/if}}
3132
</div>
33+
3234
<div class="span4 ellipses">
3335
{{#if pointsPossible}}{{#t "points_possible"}}{{pointsPossible}} pts{{/t}}{{/if}}
3436
</div>
3537
</div>
36-
<div class="ig-admin">
37-
<span class="publish-icon" data-view="publish-icon"></span>
38-
</div>
38+
39+
{{#if ENV.PERMISSIONS.manage}}
40+
<div class="ig-admin">
41+
<span class="publish-icon" data-view="publish-icon"></span>
42+
</div>
43+
{{/if}}
3944
</div>

0 commit comments

Comments
 (0)