Skip to content

Commit

Permalink
added method to assignment_group api to deal with showing only gradab…
Browse files Browse the repository at this point in the history
…le assignments, used that method in assignment_groups_controller and updated gradebook2_controller to only show gradable assignments.
  • Loading branch information
Dansbeerlist committed Oct 8, 2013
1 parent 2bf98ef commit a2a663a
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 2 deletions.
3 changes: 2 additions & 1 deletion app/controllers/assignment_groups_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ def index
format.json {
json = @groups.map { |g|
g.context = @context
assignment_group_json(g, @current_user, session, params[:include],
#Empowered: added empowered's custom gradable_assignment_group_json method
gradable_assignment_group_json(g, @current_user, session, params[:include],
override_assignment_dates: override_dates,
preloaded_user_content_attachments: user_content_attachments)
}
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/gradebook2_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def show
per_page = Setting.get_cached('api_max_per_page', '50').to_i
js_env :GRADEBOOK_OPTIONS => {
:chunk_size => Setting.get_cached('gradebook2.submissions_chunk_size', '35').to_i,
:assignment_groups_url => api_v1_course_assignment_groups_url(@context, :include => [:assignments], :override_assignment_dates => "false"),
:assignment_groups_url => api_v1_course_assignment_groups_url(@context, :include => [:assignments,:gradable_assignments], :override_assignment_dates => "false"),
:sections_url => api_v1_course_sections_url(@context),
:students_url => api_v1_course_enrollments_url(@context, :include => [:avatar_url], :type => ['StudentEnrollment', 'StudentViewEnrollment'], :per_page => per_page),
:students_url_with_concluded_enrollments => api_v1_course_enrollments_url(@context, :include => [:avatar_url], :type => ['StudentEnrollment', 'StudentViewEnrollment'], :state => ['active', 'invited', 'completed'], :per_page => per_page),
Expand Down
48 changes: 48 additions & 0 deletions lib/api/v1/assignment_group.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,54 @@ def assignment_group_json(group, user, session, includes = [], opts = {})
hash
end

#Empowered: custom method for showing gradable assignments
def gradable_assignment_group_json(group, user, session, includes = [], opts = {})
includes ||= []
opts.reverse_merge! override_assignment_dates: true

hash = api_json(group, user, session,
:only => %w(id name position group_weight))
hash['rules'] = group.rules_hash

if includes.include?('assignments')
assignment_scope = group.active_assignments
include_gradable_assignments= Array(params[:include]).include?('gradable_assignments')
if include_gradable_assignments
## show assignments with points.
with_points = group.assignments.active.where('points_possible > 0')
hash['assignments'] = with_points.map { |a| assignment_json(a, @current_user, session) }
else
## default code

# fake assignment used for checking if the @current_user can read unpublished assignments
fake = group.context.assignments.new
fake.workflow_state = 'unpublished'
if @domain_root_account.enable_draft? && !fake.grants_right?(user, session, :read)
# user should not see unpublished assignments
assignment_scope = assignment_scope.published
end
include_discussion_topic = includes.include?('discussion_topic')
user_content_attachments = opts[:preloaded_user_content_attachments]
user_content_attachments ||= api_bulk_load_user_content_attachments(
assignment_scope.map(&:description),
group.context,
user
)
hash['assignments'] = assignment_scope.map { |a|
a.context = group.context
assignment_json(a, user, session,
include_discussion_topic: include_discussion_topic,
override_dates: opts[:override_assignment_dates],
preloaded_user_content_attachments: user_content_attachments)
}
end
end

hash
end

#End Empowered

def update_assignment_group(assignment_group, params)
return nil unless params.is_a?(Hash)

Expand Down

0 comments on commit a2a663a

Please sign in to comment.