arel-ify scopes
s/named_scope/scope/g refs CNVS-4707 Change-Id: I930d229fc9985c7c0096a0f4888933addd4f3aee Reviewed-on: https://gerrit.instructure.com/18834 Reviewed-by: Duane Johnson <duane@instructure.com> Reviewed-by: Cody Cutrer <cody@instructure.com> QA-Review: Cody Cutrer <cody@instructure.com> Tested-by: Jenkins <jenkins@instructure.com> Product-Review: Cody Cutrer <cody@instructure.com>
This commit is contained in:
parent
7ae59c6442
commit
8c94e53dc7
|
@ -38,9 +38,7 @@ class AbstractCourse < ActiveRecord::Base
|
|||
save!
|
||||
end
|
||||
|
||||
named_scope :active, lambda {
|
||||
{ :conditions => ['abstract_courses.workflow_state != ?', 'deleted'] }
|
||||
}
|
||||
scope :active, where("abstract_courses.workflow_state<>'deleted'")
|
||||
|
||||
include StickySisFields
|
||||
are_sis_sticky :name, :short_name, :enrollment_term_id
|
||||
|
|
|
@ -12,9 +12,7 @@ class AccessToken < ActiveRecord::Base
|
|||
# on the scope defined in the auth process (scope has not
|
||||
# yet been implemented)
|
||||
|
||||
named_scope :active, lambda {
|
||||
{ :conditions => ['expires_at IS NULL OR expires_at > ?', Time.zone.now] }
|
||||
}
|
||||
scope :active, lambda { where("expires_at IS NULL OR expires_at>?", Time.zone.now) }
|
||||
|
||||
TOKEN_SIZE = 64
|
||||
OAUTH2_SCOPE_NAMESPACE = '/auth/'
|
||||
|
|
|
@ -1227,15 +1227,12 @@ class Account < ActiveRecord::Base
|
|||
:closed
|
||||
end
|
||||
|
||||
named_scope :root_accounts, :conditions => {:root_account_id => nil}
|
||||
named_scope :processing_sis_batch, :conditions => ['accounts.current_sis_batch_id IS NOT NULL'], :order => :updated_at
|
||||
named_scope :name_like, lambda { |name|
|
||||
{ :conditions => wildcard('accounts.name', name) }
|
||||
}
|
||||
named_scope :active, :conditions => ['accounts.workflow_state != ?', 'deleted']
|
||||
named_scope :limit, lambda {|limit|
|
||||
{:limit => limit}
|
||||
scope :root_accounts, where(:root_account_id => nil)
|
||||
scope :processing_sis_batch, where("accounts.current_sis_batch_id IS NOT NULL").order(:updated_at)
|
||||
scope :name_like, lambda { |name|
|
||||
where(wildcard('accounts.name', name))
|
||||
}
|
||||
scope :active, where("accounts.workflow_state<>'deleted'")
|
||||
|
||||
def canvas_network_enabled?
|
||||
false
|
||||
|
|
|
@ -33,18 +33,11 @@ class AccountReport < ActiveRecord::Base
|
|||
state :deleted
|
||||
end
|
||||
|
||||
named_scope :last_complete_of_type, lambda{|type|
|
||||
{ :conditions => [ "report_type = ? AND workflow_state = 'complete'", type],
|
||||
:order => "updated_at DESC",
|
||||
:limit => 1
|
||||
}
|
||||
}
|
||||
scope :last_complete_of_type, lambda{ |type|
|
||||
last_of_type(type).where(:workflow_state => 'complete') }
|
||||
|
||||
named_scope :last_of_type, lambda{|type|
|
||||
{ :conditions => [ "report_type = ?", type ],
|
||||
:order => "updated_at DESC",
|
||||
:limit => 1
|
||||
}
|
||||
scope :last_of_type, lambda {|type|
|
||||
where(:report_type => type).order("updated_at DESC").limit(1)
|
||||
}
|
||||
|
||||
def context
|
||||
|
|
|
@ -148,7 +148,5 @@ class AccountUser < ActiveRecord::Base
|
|||
account_ids_for_user(user).include?(account_id)
|
||||
end
|
||||
|
||||
named_scope :for_user, lambda{|user|
|
||||
{:conditions => ['account_users.user_id = ?', user.id] }
|
||||
}
|
||||
scope :for_user, lambda { |user| where(:user_id => user) }
|
||||
end
|
||||
|
|
|
@ -161,7 +161,7 @@ class AppointmentGroup < ActiveRecord::Base
|
|||
end
|
||||
|
||||
# complements :reserve permission
|
||||
named_scope :reservable_by, lambda { |*options|
|
||||
scope :reservable_by, lambda { |*options|
|
||||
user = options.shift
|
||||
restrict_to_codes = options.shift
|
||||
|
||||
|
@ -170,13 +170,12 @@ class AppointmentGroup < ActiveRecord::Base
|
|||
codes[:full] &= restrict_to_codes
|
||||
codes[:limited] &= restrict_to_codes
|
||||
end
|
||||
{
|
||||
:select => "DISTINCT appointment_groups.*",
|
||||
:joins => "JOIN appointment_group_contexts agc " \
|
||||
"ON appointment_groups.id = agc.appointment_group_id " \
|
||||
"LEFT JOIN appointment_group_sub_contexts sc " \
|
||||
"ON appointment_groups.id = sc.appointment_group_id",
|
||||
:conditions => [<<-COND, codes[:primary], codes[:secondary]]
|
||||
uniq.
|
||||
joins("JOIN appointment_group_contexts agc " \
|
||||
"ON appointment_groups.id = agc.appointment_group_id " \
|
||||
"LEFT JOIN appointment_group_sub_contexts sc " \
|
||||
"ON appointment_groups.id = sc.appointment_group_id").
|
||||
where(<<-COND, codes[:primary], codes[:secondary])
|
||||
workflow_state = 'active'
|
||||
AND agc.context_code IN (?)
|
||||
AND (
|
||||
|
@ -184,10 +183,9 @@ class AppointmentGroup < ActiveRecord::Base
|
|||
OR sc.sub_context_code IN (?)
|
||||
)
|
||||
COND
|
||||
}
|
||||
}
|
||||
# complements :manage permission
|
||||
named_scope :manageable_by, lambda { |*options|
|
||||
scope :manageable_by, lambda { |*options|
|
||||
user = options.shift
|
||||
restrict_to_codes = options.shift
|
||||
|
||||
|
@ -196,13 +194,12 @@ class AppointmentGroup < ActiveRecord::Base
|
|||
codes[:full] &= restrict_to_codes
|
||||
codes[:limited] &= restrict_to_codes
|
||||
end
|
||||
{
|
||||
:select => "DISTINCT appointment_groups.*",
|
||||
:joins => "JOIN appointment_group_contexts agc " \
|
||||
"ON appointment_groups.id = agc.appointment_group_id " \
|
||||
"LEFT JOIN appointment_group_sub_contexts sc " \
|
||||
"ON appointment_groups.id = sc.appointment_group_id",
|
||||
:conditions => [<<-COND, codes[:full] + codes[:limited], codes[:full], codes[:secondary]]
|
||||
uniq.
|
||||
joins("JOIN appointment_group_contexts agc " \
|
||||
"ON appointment_groups.id = agc.appointment_group_id " \
|
||||
"LEFT JOIN appointment_group_sub_contexts sc " \
|
||||
"ON appointment_groups.id = sc.appointment_group_id").
|
||||
where(<<-COND, codes[:full] + codes[:limited], codes[:full], codes[:secondary])
|
||||
workflow_state <> 'deleted'
|
||||
AND agc.context_code IN (?)
|
||||
AND (
|
||||
|
@ -210,17 +207,10 @@ class AppointmentGroup < ActiveRecord::Base
|
|||
OR sc.sub_context_code IN (?)
|
||||
)
|
||||
COND
|
||||
}
|
||||
}
|
||||
named_scope :current, lambda {
|
||||
{:conditions => ["end_at >= ?", Time.zone.today.to_datetime.utc]}
|
||||
}
|
||||
named_scope :current_or_undated, lambda {
|
||||
{:conditions => ["end_at >= ? OR end_at IS NULL", Time.zone.today.to_datetime.utc]}
|
||||
}
|
||||
named_scope :intersecting, lambda { |start_date, end_date|
|
||||
{:conditions => ["start_at < ? AND end_at > ?", end_date, start_date]}
|
||||
}
|
||||
scope :current, lambda { where("end_at>=?", Time.zone.now.midnight) }
|
||||
scope :current_or_undated, lambda { where("end_at>=? OR end_at IS NULL", Time.zone.now.midnight) }
|
||||
scope :intersecting, lambda { |start_date, end_date| where("start_at<? AND end_at>?", end_date, start_date) }
|
||||
|
||||
set_policy do
|
||||
given { |user, session|
|
||||
|
|
|
@ -564,7 +564,5 @@ class AssessmentQuestion < ActiveRecord::Base
|
|||
hash
|
||||
end
|
||||
|
||||
named_scope :active, lambda {
|
||||
{:conditions => ['assessment_questions.workflow_state != ?', 'deleted'] }
|
||||
}
|
||||
scope :active, where("assessment_questions.workflow_state<>'deleted'")
|
||||
end
|
||||
|
|
|
@ -129,7 +129,5 @@ class AssessmentQuestionBank < ActiveRecord::Base
|
|||
quiz_groups.destroy_all
|
||||
end
|
||||
|
||||
named_scope :active, lambda {
|
||||
{:conditions => ['assessment_question_banks.workflow_state != ?', 'deleted'] }
|
||||
}
|
||||
scope :active, where("assessment_question_banks.workflow_state<>'deleted'")
|
||||
end
|
||||
|
|
|
@ -51,12 +51,8 @@ class AssessmentRequest < ActiveRecord::Base
|
|||
}
|
||||
end
|
||||
|
||||
named_scope :incomplete, lambda {
|
||||
{:conditions => ['assessment_requests.workflow_state = ?', 'assigned'] }
|
||||
}
|
||||
named_scope :for_assessee, lambda{|user_id|
|
||||
{:conditions => ['assessment_requests.user_id = ?', user_id]}
|
||||
}
|
||||
scope :incomplete, where(:workflow_state => 'assigned')
|
||||
scope :for_assessee, lambda { |user_id| where(:user_id => user_id) }
|
||||
|
||||
def send_invitation!
|
||||
@send_invitation = true
|
||||
|
|
|
@ -27,14 +27,10 @@ class AssetUserAccess < ActiveRecord::Base
|
|||
before_save :infer_defaults
|
||||
attr_accessible :user, :asset_code
|
||||
|
||||
named_scope :for_context, lambda{|context|
|
||||
{:conditions => ["asset_user_accesses.context_id = ? AND asset_user_accesses.context_type = ?", context.id, context.class.to_s]}
|
||||
}
|
||||
named_scope :for_user, lambda{ |user|
|
||||
{ :conditions => {:user_id => user} }
|
||||
}
|
||||
named_scope :participations, {:conditions => { :action_level => 'participate' }}
|
||||
named_scope :most_recent, {:order => 'updated_at DESC'}
|
||||
scope :for_context, lambda { |context| where(:context_id => context, :context_type => context.class.to_s) }
|
||||
scope :for_user, lambda { |user| where(:user_id => user) }
|
||||
scope :participations, where(:action_level => 'participate')
|
||||
scope :most_recent, order('updated_at DESC')
|
||||
|
||||
def category
|
||||
self.asset_category
|
||||
|
|
|
@ -1351,124 +1351,98 @@ class Assignment < ActiveRecord::Base
|
|||
0.5
|
||||
end
|
||||
|
||||
named_scope :include_submitted_count, lambda {
|
||||
{:select => "assignments.*, (SELECT COUNT(*) FROM submissions
|
||||
WHERE assignments.id = submissions.assignment_id
|
||||
AND submissions.submission_type IS NOT NULL) AS submitted_count"
|
||||
}
|
||||
scope :include_submitted_count, select(
|
||||
"assignments.*, (SELECT COUNT(*) FROM submissions
|
||||
WHERE assignments.id = submissions.assignment_id
|
||||
AND submissions.submission_type IS NOT NULL) AS submitted_count")
|
||||
|
||||
scope :include_graded_count, select(
|
||||
"assignments.*, (SELECT COUNT(*) FROM submissions
|
||||
WHERE assignments.id = submissions.assignment_id
|
||||
AND submissions.grade IS NOT NULL) AS graded_count")
|
||||
|
||||
scope :include_quiz_and_topic, includes(:quiz, :discussion_topic)
|
||||
|
||||
scope :no_graded_quizzes_or_topics, where("submission_types NOT IN ('online_quiz', 'discussion_topic')")
|
||||
|
||||
scope :with_submissions, includes(:submissions)
|
||||
|
||||
scope :for_context_codes, lambda { |codes| where(:context_code => codes) }
|
||||
scope :for_course, lambda { |course_id| where(:context_type => 'Course', :context_id => course_id) }
|
||||
|
||||
scope :due_before, lambda { |date| where("assignments.due_at<?", date) }
|
||||
|
||||
scope :due_after, lambda { |date| where("assignments.due_at>?", date) }
|
||||
scope :undated, where(:due_at => nil)
|
||||
|
||||
scope :only_graded, where("submission_types<>'not_graded'")
|
||||
|
||||
scope :with_just_calendar_attributes, lambda {
|
||||
select(((Assignment.column_names & CalendarEvent.column_names) + ['due_at', 'assignment_group_id', 'could_be_locked', 'unlock_at', 'lock_at', 'submission_types', '(freeze_on_copy AND copied) AS frozen'] - ['cloned_item_id', 'migration_id']).join(", "))
|
||||
}
|
||||
|
||||
named_scope :include_graded_count, lambda {
|
||||
{:select => "assignments.*, (SELECT COUNT(*) FROM submissions
|
||||
WHERE assignments.id = submissions.assignment_id
|
||||
AND submissions.grade IS NOT NULL) AS graded_count"
|
||||
}
|
||||
}
|
||||
|
||||
named_scope :include_quiz_and_topic, lambda {
|
||||
{:include => [:quiz, :discussion_topic] }
|
||||
}
|
||||
|
||||
named_scope :no_graded_quizzes_or_topics, :conditions=>"submission_types NOT IN ('online_quiz', 'discussion_topic')"
|
||||
|
||||
named_scope :with_submissions, lambda {
|
||||
{:include => :submissions }
|
||||
}
|
||||
|
||||
named_scope :for_context_codes, lambda {|codes|
|
||||
{:conditions => ['assignments.context_code IN (?)', codes] }
|
||||
}
|
||||
named_scope :for_course, lambda { |course_id|
|
||||
{:conditions => {:context_type => 'Course', :context_id => course_id}}
|
||||
}
|
||||
|
||||
named_scope :due_before, lambda{|date|
|
||||
{:conditions => ['assignments.due_at < ?', date] }
|
||||
}
|
||||
|
||||
named_scope :due_after, lambda{|date|
|
||||
{:conditions => ['assignments.due_at > ?', date] }
|
||||
}
|
||||
named_scope :undated, :conditions => {:due_at => nil}
|
||||
|
||||
named_scope :only_graded, :conditions => "submission_types != 'not_graded'"
|
||||
|
||||
named_scope :with_just_calendar_attributes, lambda {
|
||||
{ :select => ((Assignment.column_names & CalendarEvent.column_names) + ['due_at', 'assignment_group_id', 'could_be_locked', 'unlock_at', 'lock_at', 'submission_types', '(freeze_on_copy AND copied) AS frozen'] - ['cloned_item_id', 'migration_id']).join(", ") }
|
||||
}
|
||||
|
||||
named_scope :due_between, lambda { |start, ending|
|
||||
{ :conditions => { :due_at => (start)..(ending) } }
|
||||
}
|
||||
scope :due_between, lambda { |start, ending| where(:due_at => start..ending) }
|
||||
|
||||
# Return all assignments and their active overrides where either the
|
||||
# assignment or one of its overrides is due between start and ending.
|
||||
named_scope :due_between_with_overrides, lambda { |start, ending|
|
||||
{ :include => :assignment_overrides,
|
||||
:conditions => ['assignments.due_at BETWEEN ? AND ?
|
||||
OR assignment_overrides.due_at_overridden = TRUE AND
|
||||
assignment_overrides.due_at BETWEEN ? AND ?', start, ending, start, ending]}
|
||||
scope :due_between_with_overrides, lambda { |start, ending|
|
||||
includes(:assignment_overrides).
|
||||
where('assignments.due_at BETWEEN ? AND ?
|
||||
OR assignment_overrides.due_at_overridden AND
|
||||
assignment_overrides.due_at BETWEEN ? AND ?', start, ending, start, ending)
|
||||
}
|
||||
|
||||
named_scope :updated_after, lambda { |*args|
|
||||
scope :updated_after, lambda { |*args|
|
||||
if args.first
|
||||
{ :conditions => [ "assignments.updated_at IS NULL OR assignments.updated_at > ?", args.first ] }
|
||||
where("assignments.updated_at IS NULL OR assignments.updated_at>?", args.first)
|
||||
else
|
||||
scoped
|
||||
end
|
||||
}
|
||||
|
||||
named_scope :not_ignored_by, lambda { |user, purpose|
|
||||
{:conditions =>
|
||||
["NOT EXISTS (SELECT * FROM ignores WHERE asset_type='Assignment' AND asset_id=assignments.id AND user_id=? AND purpose=?)",
|
||||
user.id, purpose]}
|
||||
scope :not_ignored_by, lambda { |user, purpose|
|
||||
where("NOT EXISTS (SELECT * FROM ignores WHERE asset_type='Assignment' AND asset_id=assignments.id AND user_id=? AND purpose=?)",
|
||||
user, purpose)
|
||||
}
|
||||
|
||||
# This should only be used in the course drop down to show assignments needing a submission
|
||||
named_scope :need_submitting_info, lambda{|user_id, limit|
|
||||
ignored_ids ||= []
|
||||
{:select => API_NEEDED_FIELDS.join( ',' ) +
|
||||
',(SELECT name FROM courses WHERE id = assignments.context_id) AS context_name',
|
||||
:conditions =>["(SELECT COUNT(id) FROM submissions
|
||||
scope :need_submitting_info, lambda { |user_id, limit|
|
||||
select(API_NEEDED_FIELDS).
|
||||
select("(SELECT name FROM courses WHERE id = assignments.context_id) AS context_name").
|
||||
where("(SELECT COUNT(id) FROM submissions
|
||||
WHERE assignment_id = assignments.id
|
||||
AND submission_type IS NOT NULL
|
||||
AND user_id = ?) = 0", user_id],
|
||||
:limit => limit,
|
||||
:order => 'due_at ASC'
|
||||
}
|
||||
AND user_id = ?) = 0", user_id).
|
||||
limit(limit).
|
||||
order(:due_at)
|
||||
}
|
||||
|
||||
# This should only be used in the course drop down to show assignments not yet graded.
|
||||
named_scope :need_grading_info, lambda{|limit|
|
||||
ignore_ids ||= []
|
||||
{
|
||||
:select => API_NEEDED_FIELDS.join(',') +
|
||||
',(SELECT name FROM courses WHERE id = assignments.context_id) AS context_name, needs_grading_count',
|
||||
:conditions => "needs_grading_count > 0",
|
||||
:limit => limit,
|
||||
:order=>'due_at ASC'
|
||||
}
|
||||
scope :need_grading_info, lambda { |limit|
|
||||
select(API_NEEDED_FIELDS).
|
||||
select("(SELECT name FROM courses WHERE id = assignments.context_id) AS context_name, needs_grading_count").
|
||||
where("needs_grading_count>0").
|
||||
limit(limit).
|
||||
order(:due_at)
|
||||
}
|
||||
|
||||
named_scope :expecting_submission, :conditions=>"submission_types NOT IN ('', 'none', 'not_graded', 'on_paper') AND submission_types IS NOT NULL"
|
||||
scope :expecting_submission, where("submission_types NOT IN ('', 'none', 'not_graded', 'on_paper') AND submission_types IS NOT NULL")
|
||||
|
||||
named_scope :gradeable, lambda {
|
||||
{:conditions => ['assignments.submission_types != ?', 'not_graded'] }
|
||||
scope :gradeable, where("assignments.submission_types<>'not_graded'")
|
||||
|
||||
scope :need_publishing, lambda {
|
||||
where("assignments.due_at<? AND assignments.workflow_state='available'", 1.week.ago)
|
||||
}
|
||||
|
||||
named_scope :need_publishing, lambda {
|
||||
{:conditions => ['assignments.due_at < ? AND assignments.workflow_state = ?', 1.week.ago, 'available'] }
|
||||
scope :active, where("assignments.workflow_state<>'deleted'")
|
||||
scope :before, lambda { |date| where("assignments.created_at<?", date) }
|
||||
|
||||
scope :not_locked, lambda {
|
||||
where("(assignments.unlock_at IS NULL OR assignments.unlock_at<:now) AND (assignments.lock_at IS NULL OR assignments.lock_at>:now)",
|
||||
:now => Time.zone.now)
|
||||
}
|
||||
|
||||
named_scope :active, :conditions => ['assignments.workflow_state != ?', 'deleted']
|
||||
named_scope :before, lambda{|date|
|
||||
{:conditions => ['assignments.created_at < ?', date]}
|
||||
}
|
||||
|
||||
named_scope :not_locked, lambda {
|
||||
{:conditions => ['(assignments.unlock_at IS NULL OR assignments.unlock_at < :now) AND (assignments.lock_at IS NULL OR assignments.lock_at > :now)',
|
||||
{:now => Time.zone.now}]}
|
||||
}
|
||||
|
||||
named_scope :order_by_base_due_at, :order => 'assignments.due_at ASC'
|
||||
scope :order_by_base_due_at, order("assignments.due_at")
|
||||
|
||||
def needs_publishing?
|
||||
self.due_at && self.due_at < 1.week.ago && self.available?
|
||||
|
|
|
@ -122,17 +122,11 @@ class AssignmentGroup < ActiveRecord::Base
|
|||
self.assignments.map{|a| a.points_possible || 0}.sum
|
||||
end
|
||||
|
||||
named_scope :include_active_assignments, lambda{
|
||||
{:include => :active_assignments}
|
||||
}
|
||||
named_scope :active, :conditions => ['assignment_groups.workflow_state != ?', 'deleted']
|
||||
named_scope :before, lambda{|date|
|
||||
{:conditions => ['assignment_groups.created_at < ?', date]}
|
||||
}
|
||||
named_scope :for_context_codes, lambda {|codes|
|
||||
{:conditions => ['assignment_groups.context_code IN (?) and assignment_groups.workflow_state != ?', codes, 'deleted'], :order => :position }
|
||||
}
|
||||
|
||||
scope :include_active_assignments, includes(:active_assignments)
|
||||
scope :active, where("assignment_groups.workflow_state<>'deleted'")
|
||||
scope :before, lambda { |date| where("assignment_groups.created_at<?", date) }
|
||||
scope :for_context_codes, lambda { |codes| active.where(:context_code => codes).order(:position) }
|
||||
|
||||
def group_weight_changed
|
||||
@group_weight_changed = self.group_weight_changed?
|
||||
true
|
||||
|
|
|
@ -110,7 +110,7 @@ class AssignmentOverride < ActiveRecord::Base
|
|||
end
|
||||
end
|
||||
|
||||
named_scope :active, :conditions => { :workflow_state => 'active' }
|
||||
scope :active, where(:workflow_state => 'active')
|
||||
|
||||
before_validation :default_values
|
||||
def default_values
|
||||
|
@ -172,7 +172,7 @@ class AssignmentOverride < ActiveRecord::Base
|
|||
true
|
||||
end
|
||||
|
||||
named_scope "overriding_#{field}", :conditions => { "#{field}_overridden" => true }
|
||||
scope "overriding_#{field}", where("#{field}_overridden" => true)
|
||||
end
|
||||
|
||||
override :due_at
|
||||
|
@ -256,7 +256,7 @@ class AssignmentOverride < ActiveRecord::Base
|
|||
p.whenever { |record| record.notify_change? }
|
||||
end
|
||||
|
||||
named_scope :visible_to, lambda{ |admin, course|
|
||||
scope :visible_to, lambda { |admin, course|
|
||||
scopes = []
|
||||
|
||||
# adhoc overrides for visible students
|
||||
|
@ -281,7 +281,12 @@ class AssignmentOverride < ActiveRecord::Base
|
|||
joins("INNER JOIN assignment_overrides ON assignment_overrides.set_type='CourseSection' AND enrollments.course_section_id=assignment_overrides.set_id")
|
||||
|
||||
# union the visible override subselects and join against them
|
||||
subselect = scopes.map{ |scope| scope.construct_finder_sql({}) }.join(' UNION ')
|
||||
{ :joins => "INNER JOIN (#{subselect}) AS visible_overrides ON visible_overrides.id=assignment_overrides.id", :readonly => false }
|
||||
subselect = scopes.map{ |scope| scope.to_sql }.join(' UNION ')
|
||||
join_clause = "INNER JOIN (#{subselect}) AS visible_overrides ON visible_overrides.id=assignment_overrides.id"
|
||||
if Rails.version < '3'
|
||||
{ :joins => join_clause, :readonly => false }
|
||||
else
|
||||
joins(join_clause).readonly(false)
|
||||
end
|
||||
}
|
||||
end
|
||||
|
|
|
@ -1204,17 +1204,15 @@ class Attachment < ActiveRecord::Base
|
|||
state :unattached_temporary
|
||||
end
|
||||
|
||||
named_scope :to_be_zipped, lambda{
|
||||
{:conditions => ['attachments.workflow_state = ? AND attachments.scribd_attempts < ?', 'to_be_zipped', 10], :order => 'created_at' }
|
||||
}
|
||||
scope :to_be_zipped, where("attachments.workflow_state='to_be_zipped' AND attachments.scribd_attempts<10").order(:created_at)
|
||||
|
||||
named_scope :active, lambda {
|
||||
{ :conditions => ['attachments.file_state != ?', 'deleted'] }
|
||||
}
|
||||
scope :active, where("attachments.file_state<>'deleted'")
|
||||
|
||||
named_scope :not_hidden, :conditions => ['attachments.file_state != ?', 'hidden']
|
||||
named_scope :not_locked, lambda {{:conditions => ['(attachments.locked IS NULL OR attachments.locked = ?) AND ((attachments.lock_at IS NULL) OR
|
||||
(attachments.lock_at > ? OR (attachments.unlock_at IS NOT NULL AND attachments.unlock_at < ?)))', false, Time.now, Time.now]}}
|
||||
scope :not_hidden, where("attachments.file_state<>'hidden'")
|
||||
scope :not_locked, lambda {
|
||||
where("(attachments.locked IS NULL OR attachments.locked=?) AND ((attachments.lock_at IS NULL) OR
|
||||
(attachments.lock_at>? OR (attachments.unlock_at IS NOT NULL AND attachments.unlock_at<?)))", false, Time.now.utc, Time.now.utc)
|
||||
}
|
||||
|
||||
alias_method :destroy!, :destroy
|
||||
# file_state is like workflow_state, which was already taken
|
||||
|
@ -1484,14 +1482,14 @@ class Attachment < ActiveRecord::Base
|
|||
cattr_accessor :skip_thumbnails
|
||||
|
||||
|
||||
named_scope :scribdable?, :conditions => ['scribd_mime_type_id is not null']
|
||||
named_scope :recyclable, :conditions => ['attachments.scribd_attempts < ? AND attachments.workflow_state = ?', MAX_SCRIBD_ATTEMPTS, 'errored']
|
||||
named_scope :needing_scribd_conversion_status, :conditions => ['attachments.workflow_state = ? AND attachments.updated_at < ?', 'processing', 30.minutes.ago], :limit => 50
|
||||
named_scope :uploadable, :conditions => ['workflow_state = ?', 'pending_upload']
|
||||
named_scope :active, :conditions => ['file_state = ?', 'available']
|
||||
named_scope :thumbnailable?, :conditions => {:content_type => Technoweenie::AttachmentFu.content_types}
|
||||
named_scope :by_display_name, :order => display_name_order_by_clause('attachments')
|
||||
named_scope :by_position_then_display_name, :order => "attachments.position, #{display_name_order_by_clause('attachments')}"
|
||||
scope :scribdable?, where("scribd_mime_type_id IS NOT NULL")
|
||||
scope :recyclable, where("attachments.scribd_attempts<? AND attachments.workflow_state='errored'", MAX_SCRIBD_ATTEMPTS)
|
||||
scope :needing_scribd_conversion_status, lambda { where("attachments.workflow_state='processing' AND attachments.updated_at<?", 30.minutes.ago).limit(50) }
|
||||
scope :uploadable, where(:workflow_state => 'pending_upload')
|
||||
scope :active, where(:file_state => 'available')
|
||||
scope :thumbnailable?, where(:content_type => Technoweenie::AttachmentFu.content_types)
|
||||
scope :by_display_name, order(display_name_order_by_clause('attachments'))
|
||||
scope :by_position_then_display_name, order("attachments.position, #{display_name_order_by_clause('attachments')}")
|
||||
def self.serialization_excludes; [:uuid, :namespace]; end
|
||||
def set_serialization_options
|
||||
if self.scribd_doc
|
||||
|
|
|
@ -105,23 +105,21 @@ class CalendarEvent < ActiveRecord::Base
|
|||
effective_context_code && ActiveRecord::Base.find_by_asset_string(effective_context_code) || context
|
||||
end
|
||||
|
||||
named_scope :order_by_start_at, :order => :start_at
|
||||
scope :order_by_start_at, order(:start_at)
|
||||
|
||||
named_scope :active, :conditions => ['calendar_events.workflow_state != ?', 'deleted']
|
||||
named_scope :locked, :conditions => ["calendar_events.workflow_state = 'locked'"]
|
||||
named_scope :unlocked, :conditions => ['calendar_events.workflow_state NOT IN (?)', ['deleted', 'locked']]
|
||||
scope :active, where("calendar_events.workflow_state<>'deleted'")
|
||||
scope :locked, where(:workflow_state => 'locked')
|
||||
scope :unlocked, where("calendar_events.workflow_state NOT IN ('deleted', 'locked')")
|
||||
|
||||
# controllers/apis/etc. should generally use for_user_and_context_codes instead
|
||||
named_scope :for_context_codes, lambda { |codes|
|
||||
{:conditions => ['calendar_events.context_code IN (?)', codes] }
|
||||
}
|
||||
scope :for_context_codes, lambda { |codes| where(:context_code => codes) }
|
||||
|
||||
# appointments and appointment_participants have the appointment_group and
|
||||
# the user as the context, respectively. we are actually interested in
|
||||
# grouping them under the effective context (i.e. appointment_group.context).
|
||||
# it's the responsibility of the caller to ensure the user has rights to the
|
||||
# specified codes (e.g. using User#appointment_context_codes)
|
||||
named_scope :for_user_and_context_codes, lambda { |user, *args|
|
||||
scope :for_user_and_context_codes, lambda { |user, *args|
|
||||
codes = args.shift
|
||||
section_codes = args.shift || user.section_context_codes(codes)
|
||||
effectively_courses_codes = [user.asset_string] + section_codes
|
||||
|
@ -135,7 +133,7 @@ class CalendarEvent < ActiveRecord::Base
|
|||
}.join(" OR ")
|
||||
codes_conditions = self.connection.quote(false) if codes_conditions.blank?
|
||||
|
||||
{:conditions => [<<-SQL, all_codes, codes, group_codes, effectively_courses_codes]}
|
||||
where(<<-SQL, all_codes, codes, group_codes, effectively_courses_codes)
|
||||
calendar_events.context_code IN (?)
|
||||
AND (
|
||||
( -- explicit contexts (e.g. course_123)
|
||||
|
@ -153,22 +151,20 @@ class CalendarEvent < ActiveRecord::Base
|
|||
SQL
|
||||
}
|
||||
|
||||
named_scope :undated, :conditions => {:start_at => nil, :end_at => nil}
|
||||
scope :undated, where(:start_at => nil, :end_at => nil)
|
||||
|
||||
named_scope :between, lambda { |start, ending|
|
||||
{ :conditions => { :start_at => (start)..(ending) } }
|
||||
}
|
||||
named_scope :current, lambda {
|
||||
{ :conditions => ['calendar_events.end_at >= ?', Time.zone.today.to_datetime.utc] }
|
||||
}
|
||||
named_scope :updated_after, lambda { |*args|
|
||||
scope :between, lambda { |start, ending| where(:start_at => start..ending) }
|
||||
scope :current, lambda { where("calendar_events.end_at>=?", Time.zone.now.midnight) }
|
||||
scope :updated_after, lambda { |*args|
|
||||
if args.first
|
||||
{ :conditions => [ "calendar_events.updated_at IS NULL OR calendar_events.updated_at > ?", args.first ] }
|
||||
where("calendar_events.updated_at IS NULL OR calendar_events.updated_at>?", args.first)
|
||||
else
|
||||
scoped
|
||||
end
|
||||
}
|
||||
|
||||
named_scope :events_without_child_events, :conditions => "NOT EXISTS (SELECT 1 FROM calendar_events children WHERE children.parent_calendar_event_id = calendar_events.id AND children.workflow_state <> 'deleted')"
|
||||
named_scope :events_with_child_events, :conditions => "EXISTS (SELECT 1 FROM calendar_events children WHERE children.parent_calendar_event_id = calendar_events.id AND children.workflow_state <> 'deleted')"
|
||||
scope :events_without_child_events, where("NOT EXISTS (SELECT 1 FROM calendar_events children WHERE children.parent_calendar_event_id = calendar_events.id AND children.workflow_state<>'deleted')")
|
||||
scope :events_with_child_events, where("EXISTS (SELECT 1 FROM calendar_events children WHERE children.parent_calendar_event_id = calendar_events.id AND children.workflow_state<>'deleted')")
|
||||
|
||||
def validate_context!
|
||||
@validate_context = true
|
||||
|
|
|
@ -79,17 +79,11 @@ class Collaboration < ActiveRecord::Base
|
|||
can :read and can :update and can :delete
|
||||
end
|
||||
|
||||
named_scope :active, lambda {
|
||||
{ :conditions => ['collaborations.workflow_state != ?', 'deleted'] }
|
||||
}
|
||||
scope :active, where("collaborations.workflow_state<>'deleted'")
|
||||
|
||||
named_scope :after, lambda { |date|
|
||||
{ :conditions => ['collaborations.updated_at > ?', date] }
|
||||
}
|
||||
scope :after, lambda { |date| where("collaborations.updated_at>?", date) }
|
||||
|
||||
named_scope :for_context_codes, lambda { |context_codes|
|
||||
{ :conditions => { :context_code => context_codes } }
|
||||
}
|
||||
scope :for_context_codes, lambda { |context_codes| where(:context_code => context_codes) }
|
||||
|
||||
# These methods should be implemented in child classes.
|
||||
|
||||
|
|
|
@ -34,8 +34,8 @@ class Collection < ActiveRecord::Base
|
|||
before_save :handle_visibility_change
|
||||
after_create :check_auto_follow_users
|
||||
|
||||
named_scope :public, :conditions => { :visibility => 'public' }
|
||||
named_scope :newest_first, { :order => "id desc" }
|
||||
scope :public, where(:visibility => 'public')
|
||||
scope :newest_first, order("id DESC")
|
||||
|
||||
def public?
|
||||
self.visibility == 'public'
|
||||
|
@ -46,7 +46,7 @@ class Collection < ActiveRecord::Base
|
|||
state :deleted
|
||||
end
|
||||
|
||||
named_scope :active, { :conditions => { :workflow_state => 'active' } }
|
||||
scope :active, where(:workflow_state => 'active')
|
||||
|
||||
def destroy
|
||||
self.workflow_state = 'deleted'
|
||||
|
|
|
@ -52,8 +52,8 @@ class CollectionItem < ActiveRecord::Base
|
|||
state :deleted
|
||||
end
|
||||
|
||||
named_scope :active, { :conditions => { :workflow_state => 'active' } }
|
||||
named_scope :newest_first, { :order => "id desc" }
|
||||
scope :active, where(:workflow_state => 'active')
|
||||
scope :newest_first, order("id DESC")
|
||||
|
||||
def discussion_topic
|
||||
DiscussionTopic.find_by_context_type_and_context_id(self.class.name, self.id) ||
|
||||
|
|
|
@ -206,33 +206,33 @@ class CommunicationChannel < ActiveRecord::Base
|
|||
end
|
||||
end
|
||||
|
||||
named_scope :for, lambda { |context|
|
||||
scope :for, lambda { |context|
|
||||
case context
|
||||
when User
|
||||
{ :conditions => ['communication_channels.user_id = ?', context.id] }
|
||||
where(:user_id => context)
|
||||
when Notification
|
||||
{ :include => [:notification_policies], :conditions => ['notification_policies.notification_id = ?', context.id] }
|
||||
includes(:notification_policies).where(:notification_policies => { :notification_id => context })
|
||||
else
|
||||
{}
|
||||
scoped
|
||||
end
|
||||
}
|
||||
|
||||
named_scope :by_path, lambda { |path|
|
||||
scope :by_path, lambda { |path|
|
||||
if %{mysql mysql2}.include?(connection_pool.spec.config[:adapter])
|
||||
{ :conditions => {:path => path } }
|
||||
where(:path => path)
|
||||
else
|
||||
{ :conditions => ["LOWER(communication_channels.path)=?", path.try(:downcase)]}
|
||||
where("LOWER(communication_channels.path)=?", path.try(:downcase))
|
||||
end
|
||||
}
|
||||
|
||||
named_scope :email, :conditions => { :path_type => TYPE_EMAIL }
|
||||
named_scope :sms, :conditions => { :path_type => TYPE_SMS }
|
||||
scope :email, where(:path_type => TYPE_EMAIL)
|
||||
scope :sms, where(:path_type => TYPE_SMS)
|
||||
|
||||
named_scope :active, :conditions => { :workflow_state => 'active' }
|
||||
named_scope :unretired, :conditions => ['communication_channels.workflow_state<>?', 'retired']
|
||||
scope :active, where(:workflow_state => 'active')
|
||||
scope :unretired, where("communication_channels.workflow_state<>'retired'")
|
||||
|
||||
named_scope :for_notification_frequency, lambda {|notification, frequency|
|
||||
{ :include => [:notification_policies], :conditions => ['notification_policies.notification_id = ? and notification_policies.frequency = ?', notification.id, frequency] }
|
||||
scope :for_notification_frequency, lambda { |notification, frequency|
|
||||
includes(:notification_policies).where(:notification_policies => { :notification_id => notification, :frequency => frequency })
|
||||
}
|
||||
|
||||
# Get the list of communication channels that overrides an association's default order clause.
|
||||
|
@ -252,10 +252,10 @@ class CommunicationChannel < ActiveRecord::Base
|
|||
all
|
||||
end
|
||||
|
||||
named_scope :include_policies, :include => :notification_policies
|
||||
scope :include_policies, includes(:notification_policies)
|
||||
|
||||
named_scope :in_state, lambda { |state| { :conditions => ["communication_channels.workflow_state = ?", state.to_s]}}
|
||||
named_scope :of_type, lambda {|type| { :conditions => ['communication_channels.path_type = ?', type] } }
|
||||
scope :in_state, lambda { |state| where(:workflow_state => state.to_s) }
|
||||
scope :of_type, lambda {|type| where(:path_type => type) }
|
||||
|
||||
def can_notify?
|
||||
self.notification_policies.any? { |np| np.frequency == 'never' } ? false : true
|
||||
|
|
|
@ -182,12 +182,12 @@ class ContentExport < ActiveRecord::Base
|
|||
ContentExport.where(:id => self).update_all(:progress=>val)
|
||||
end
|
||||
|
||||
named_scope :active, {:conditions => ['workflow_state != ?', 'deleted']}
|
||||
named_scope :not_for_copy, {:conditions => ['workflow_state != ?', 'exported_for_course_copy']}
|
||||
named_scope :common_cartridge, {:conditions => ['export_type == ?', COMMON_CARTRIDGE]}
|
||||
named_scope :qti, {:conditions => ['export_type == ?', QTI]}
|
||||
named_scope :course_copy, {:conditions => ['export_type == ?', COURSE_COPY]}
|
||||
named_scope :running, {:conditions => ['workflow_state IN (?)', ['created', 'exporting']]}
|
||||
scope :active, where("workflow_state<>'deleted'")
|
||||
scope :not_for_copy, where("workflow_state<>'exported_for_course_copy'")
|
||||
scope :common_cartridge, where(:export_type => COMMON_CARTRIDGE)
|
||||
scope :qti, where(:export_type => QTI)
|
||||
scope :course_copy, where(:export_type => COURSE_COPY)
|
||||
scope :running, where(:workflow_state => ['created', 'exporting'])
|
||||
|
||||
private
|
||||
|
||||
|
|
|
@ -429,14 +429,12 @@ class ContentMigration < ActiveRecord::Base
|
|||
end
|
||||
handle_asynchronously :copy_course, :priority => Delayed::LOW_PRIORITY, :max_attempts => 1
|
||||
|
||||
named_scope :for_context, lambda{|context|
|
||||
{:conditions => {:context_id => context.id, :context_type => context.class.to_s} }
|
||||
}
|
||||
|
||||
named_scope :successful, :conditions=>"workflow_state = 'imported'"
|
||||
named_scope :running, :conditions=>"workflow_state IN ('exporting', 'importing')"
|
||||
named_scope :waiting, :conditions=>"workflow_state IN ('exported')"
|
||||
named_scope :failed, :conditions=>"workflow_state IN ('failed', 'pre_process_error')"
|
||||
scope :for_context, lambda { |context| where(:context_id => context, :context_type => context.class.to_s) }
|
||||
|
||||
scope :successful, where(:workflow_state => 'imported')
|
||||
scope :running, where(:workflow_state => ['exporting', 'importing'])
|
||||
scope :waiting, where(:workflow_state => 'exported')
|
||||
scope :failed, where(:workflow_state => ['failed', 'pre_process_error'])
|
||||
|
||||
def complete?
|
||||
%w[imported failed pre_process_error].include?(workflow_state)
|
||||
|
|
|
@ -58,9 +58,7 @@ class ContentTag < ActiveRecord::Base
|
|||
state :deleted
|
||||
end
|
||||
|
||||
named_scope :active, lambda{
|
||||
{:conditions => ['content_tags.workflow_state != ?', 'deleted'] }
|
||||
}
|
||||
scope :active, where("content_tags.workflow_state<>'deleted'")
|
||||
|
||||
attr_accessor :skip_touch
|
||||
def touch_context_module
|
||||
|
@ -308,14 +306,12 @@ class ContentTag < ActiveRecord::Base
|
|||
dup
|
||||
end
|
||||
|
||||
named_scope :for_tagged_url, lambda{|url, tag|
|
||||
{:conditions => ['content_tags.url = ? AND content_tags.tag = ?', url, tag] }
|
||||
}
|
||||
named_scope :for_context, lambda{|context|
|
||||
scope :for_tagged_url, lambda { |url, tag| where(:url => url, :tag => tag) }
|
||||
scope :for_context, lambda { |context|
|
||||
case context
|
||||
when Account
|
||||
{ :select => 'content_tags.*',
|
||||
:joins => "INNER JOIN (
|
||||
select("content_tags.*").
|
||||
joins("INNER JOIN (
|
||||
SELECT DISTINCT ct.id AS content_tag_id FROM content_tags AS ct
|
||||
INNER JOIN course_account_associations AS caa ON caa.course_id = ct.context_id
|
||||
AND ct.context_type = 'Course'
|
||||
|
@ -323,17 +319,13 @@ class ContentTag < ActiveRecord::Base
|
|||
UNION
|
||||
SELECT ct.id AS content_tag_id FROM content_tags AS ct
|
||||
WHERE ct.context_id = #{context.id} AND context_type = 'Account')
|
||||
AS related_content_tags ON related_content_tags.content_tag_id = content_tags.id" }
|
||||
AS related_content_tags ON related_content_tags.content_tag_id = content_tags.id")
|
||||
else
|
||||
{:conditions => ['content_tags.context_type = ? AND content_tags.context_id = ?', context.class.to_s, context.id]}
|
||||
where(:context_type => context.class.to_s, :context_id => context)
|
||||
end
|
||||
}
|
||||
named_scope :learning_outcome_alignments, lambda{
|
||||
{ :conditions => {:tag_type => 'learning_outcome'} }
|
||||
}
|
||||
named_scope :learning_outcome_links, lambda{
|
||||
{ :conditions => {:tag_type => 'learning_outcome_association', :associated_asset_type => 'LearningOutcomeGroup', :content_type => 'LearningOutcome'} }
|
||||
}
|
||||
scope :learning_outcome_alignments, where(:tag_type => 'learning_outcome')
|
||||
scope :learning_outcome_links, where(:tag_type => 'learning_outcome_association', :associated_asset_type => 'LearningOutcomeGroup', :content_type => 'LearningOutcome')
|
||||
|
||||
# only intended for learning outcome links
|
||||
def self.outcome_title_order_by_clause
|
||||
|
|
|
@ -445,10 +445,8 @@ class ContextExternalTool < ActiveRecord::Base
|
|||
nil
|
||||
end
|
||||
|
||||
named_scope :having_setting, lambda{|setting|
|
||||
{:conditions => {"has_#{setting.to_s}" => true} }
|
||||
}
|
||||
|
||||
scope :having_setting, lambda { |setting| where("has_#{setting.to_s}" => true) }
|
||||
|
||||
def self.find_for(id, context, type)
|
||||
tool = context.context_external_tools.having_setting(type).find_by_id(id)
|
||||
if !tool && context.is_a?(Group)
|
||||
|
@ -462,7 +460,7 @@ class ContextExternalTool < ActiveRecord::Base
|
|||
raise ActiveRecord::RecordNotFound if !tool
|
||||
tool
|
||||
end
|
||||
named_scope :active, :conditions => ['context_external_tools.workflow_state != ?', 'deleted']
|
||||
scope :active, where("context_external_tools.workflow_state<>'deleted'")
|
||||
|
||||
def self.find_all_for(context, type)
|
||||
tools = []
|
||||
|
|
|
@ -105,9 +105,9 @@ class ContextModule < ActiveRecord::Base
|
|||
state :deleted
|
||||
end
|
||||
|
||||
named_scope :active, :conditions => ['context_modules.workflow_state = ?', 'active']
|
||||
named_scope :unpublished, :conditions => ['context_modules.workflow_state = ?', 'unpublished']
|
||||
named_scope :not_deleted, :conditions => ['context_modules.workflow_state != ?', 'deleted']
|
||||
scope :active, where(:workflow_state => 'active')
|
||||
scope :unpublished, where(:workflow_state => 'unpublished')
|
||||
scope :not_deleted, where("context_modules.workflow_state<>'deleted'")
|
||||
|
||||
def update_student_progressions(user=nil)
|
||||
# modules are ordered by position, so running through them in order will
|
||||
|
|
|
@ -95,14 +95,9 @@ class ContextModuleProgression < ActiveRecord::Base
|
|||
self.save if orig_reqs != new_reqs
|
||||
end
|
||||
|
||||
named_scope :for_user, lambda{|user|
|
||||
{:conditions => {:user_id => user && user.id} }
|
||||
}
|
||||
named_scope :for_modules, lambda{|mods|
|
||||
mods = Array(mods)
|
||||
{:conditions => {:context_module_id => mods.map(&:id) } }
|
||||
}
|
||||
|
||||
scope :for_user, lambda { |user| where(:user_id => user) }
|
||||
scope :for_modules, lambda { |mods| where(:context_module_id => mods) }
|
||||
|
||||
workflow do
|
||||
state :locked
|
||||
state :unlocked
|
||||
|
|
|
@ -8,7 +8,7 @@ class ConversationBatch < ActiveRecord::Base
|
|||
before_save :serialize_conversation_message_ids
|
||||
after_create :queue_delivery
|
||||
|
||||
named_scope :in_progress, :conditions => {:workflow_state => ['created', 'sending']}
|
||||
scope :in_progress, where(:workflow_state => ['created', 'sending'])
|
||||
|
||||
attr_accessible
|
||||
attr_accessor :mode
|
||||
|
|
|
@ -34,13 +34,11 @@ class ConversationMessage < ActiveRecord::Base
|
|||
|
||||
after_create :generate_user_note!
|
||||
|
||||
named_scope :human, :conditions => "NOT generated"
|
||||
named_scope :with_attachments, :conditions => "attachment_ids <> '' OR has_attachments" # TODO: simplify post-migration
|
||||
named_scope :with_media_comments, :conditions => "media_comment_id IS NOT NULL OR has_media_objects" # TODO: simplify post-migration
|
||||
named_scope :by_user, lambda { |user_or_id|
|
||||
user_or_id = user_or_id.id if user_or_id.is_a?(User)
|
||||
{:conditions => {:author_id => user_or_id}}
|
||||
}
|
||||
scope :human, where("NOT generated")
|
||||
scope :with_attachments, where("attachment_ids<>'' OR has_attachments") # TODO: simplify post-migration
|
||||
scope :with_media_comments, where("media_comment_id IS NOT NULL OR has_media_objects") # TODO: simplify post-migration
|
||||
scope :by_user, lambda { |user_or_id| where(:author_id => user_or_id) }
|
||||
|
||||
def self.preload_latest(conversation_participants, author=nil)
|
||||
return unless conversation_participants.present?
|
||||
|
||||
|
|
|
@ -27,10 +27,8 @@ class ConversationMessageParticipant < ActiveRecord::Base
|
|||
|
||||
attr_accessible
|
||||
|
||||
named_scope :for_conversation_and_message, lambda { |conversation_id, message_id|
|
||||
{
|
||||
:joins => "INNER JOIN conversation_participants ON conversation_participants.id = conversation_participant_id",
|
||||
:conditions => ["conversation_id = ? AND conversation_message_id = ?", conversation_id, message_id]
|
||||
}
|
||||
scope :for_conversation_and_message, lambda { |conversation_id, message_id|
|
||||
joins("INNER JOIN conversation_participants ON conversation_participants.id = conversation_participant_id").
|
||||
where(:conversation_id => conversation_id, :conversation_message_id => message_id)
|
||||
}
|
||||
end
|
|
@ -28,15 +28,15 @@ class ConversationParticipant < ActiveRecord::Base
|
|||
has_many :conversation_message_participants
|
||||
after_destroy :destroy_conversation_message_participants
|
||||
|
||||
named_scope :visible, :conditions => "last_message_at IS NOT NULL"
|
||||
named_scope :default, :conditions => "workflow_state IN ('read', 'unread')"
|
||||
named_scope :unread, :conditions => "workflow_state = 'unread'"
|
||||
named_scope :archived, :conditions => "workflow_state = 'archived'"
|
||||
named_scope :starred, :conditions => "label = 'starred'"
|
||||
named_scope :sent, :conditions => "visible_last_authored_at IS NOT NULL", :order => "visible_last_authored_at DESC, conversation_id DESC"
|
||||
named_scope :for_masquerading_user, lambda { |user|
|
||||
scope :visible, where("last_message_at IS NOT NULL")
|
||||
scope :default, where(:workflow_state => ['read', 'unread'])
|
||||
scope :unread, where(:workflow_state => 'unread')
|
||||
scope :archived, where(:workflow_state => 'archived')
|
||||
scope :starred, where(:label => 'starred')
|
||||
scope :sent, where("visible_last_authored_at IS NOT NULL").order("visible_last_authored_at DESC, conversation_id DESC")
|
||||
scope :for_masquerading_user, lambda { |user|
|
||||
# site admins can see everything
|
||||
return {} if user.account_users.map(&:account_id).include?(Account.site_admin.id)
|
||||
return scoped if user.account_users.map(&:account_id).include?(Account.site_admin.id)
|
||||
|
||||
# we need to ensure that the user can access *all* of each conversation's
|
||||
# accounts (and that each conversation has at least one account). so given
|
||||
|
@ -57,7 +57,7 @@ class ConversationParticipant < ActiveRecord::Base
|
|||
end
|
||||
id_string = "[" + own_root_account_ids.sort.join("][") + "]"
|
||||
root_account_id_matcher = "'%[' || REPLACE(conversation_participants.root_account_ids, ',', ']%[') || ']%'"
|
||||
{:conditions => ["conversation_participants.root_account_ids <> '' AND " + like_condition('?', root_account_id_matcher, false), id_string]}
|
||||
where("conversation_participants.root_account_ids <> '' AND " + like_condition('?', root_account_id_matcher, false), id_string)
|
||||
}
|
||||
|
||||
# Produces a subscope for conversations in which the given users are
|
||||
|
|
|
@ -428,43 +428,21 @@ class Course < ActiveRecord::Base
|
|||
self.non_unique_associated_accounts.all.uniq
|
||||
end
|
||||
|
||||
named_scope :recently_started, lambda {
|
||||
{:conditions => ['start_at < ? and start_at > ?', Time.now.utc, 1.month.ago], :order => 'start_at DESC', :limit => 10}
|
||||
}
|
||||
named_scope :recently_ended, lambda {
|
||||
{:conditions => ['conclude_at < ? and conclude_at > ?', Time.now.utc, 1.month.ago], :order => 'start_at DESC', :limit => 10}
|
||||
}
|
||||
named_scope :recently_created, lambda {
|
||||
{:conditions => ['created_at > ?', 1.month.ago], :order => 'created_at DESC', :limit => 50, :include => :teachers}
|
||||
}
|
||||
named_scope :for_term, lambda {|term|
|
||||
term ? {:conditions => ['courses.enrollment_term_id = ?', term.id]} : {}
|
||||
}
|
||||
named_scope :active_first, lambda {
|
||||
{:order => "CASE WHEN courses.workflow_state='available' THEN 0 ELSE 1 END, name"}
|
||||
}
|
||||
named_scope :limit, lambda {|limit|
|
||||
{:limit => limit }
|
||||
}
|
||||
named_scope :name_like, lambda { |name|
|
||||
{ :conditions => wildcard('courses.name', 'courses.sis_source_id', 'courses.course_code', name) }
|
||||
}
|
||||
named_scope :needs_account, lambda{|account, limit|
|
||||
{:conditions => {:account_id => nil, :root_account_id => account.id}, :limit => limit }
|
||||
}
|
||||
named_scope :active, lambda{
|
||||
{:conditions => ['courses.workflow_state != ?', 'deleted'] }
|
||||
}
|
||||
named_scope :least_recently_updated, lambda{|limit|
|
||||
{:order => 'updated_at', :limit => limit }
|
||||
}
|
||||
named_scope :manageable_by_user, lambda{ |*args|
|
||||
scope :recently_started, lambda { where(:start_at => 1.month.ago..Time.zone.now).order("start_at DESC").limit(10) }
|
||||
scope :recently_ended, lambda { where(:conclude_at => 1.month.ago..Time.zone.now).order("start_at DESC").limit(10) }
|
||||
scope :recently_created, lambda { where("created_at>?", 1.month.ago).order("created_at DESC").limit(50).includes(:teachers) }
|
||||
scope :for_term, lambda {|term| term ? where(:enrollment_term_id => term) : scoped }
|
||||
scope :active_first, order("CASE WHEN courses.workflow_state='available' THEN 0 ELSE 1 END, name")
|
||||
scope :name_like, lambda { |name| where(wildcard('courses.name', 'courses.sis_source_id', 'courses.course_code', name)) }
|
||||
scope :needs_account, lambda { |account, limit| where(:account_id => nil, :root_account_id => account).limit(limit) }
|
||||
scope :active, where("courses.workflow_state<>'deleted'")
|
||||
scope :least_recently_updated, lambda { |limit| order(:updated_at).limit(limit) }
|
||||
scope :manageable_by_user, lambda { |*args|
|
||||
# args[0] should be user_id, args[1], if true, will include completed
|
||||
# enrollments as well as active enrollments
|
||||
user_id = args[0]
|
||||
workflow_states = (args[1].present? ? %w{'active' 'completed'} : %w{'active'}).join(', ')
|
||||
{ :select => 'DISTINCT courses.*',
|
||||
:joins => "INNER JOIN (
|
||||
uniq.joins("INNER JOIN (
|
||||
SELECT caa.course_id, au.user_id FROM course_account_associations AS caa
|
||||
INNER JOIN accounts AS a ON a.id = caa.account_id AND a.workflow_state = 'active'
|
||||
INNER JOIN account_users AS au ON au.account_id = a.id AND au.user_id = #{user_id.to_i}
|
||||
|
@ -472,43 +450,38 @@ class Course < ActiveRecord::Base
|
|||
INNER JOIN enrollments AS e ON e.course_id = courses.id AND e.user_id = #{user_id.to_i}
|
||||
AND e.workflow_state IN(#{workflow_states}) AND e.type IN ('TeacherEnrollment', 'TaEnrollment', 'DesignerEnrollment')
|
||||
WHERE courses.workflow_state <> 'deleted') as course_users
|
||||
ON course_users.course_id = courses.id"
|
||||
}
|
||||
ON course_users.course_id = courses.id")
|
||||
}
|
||||
named_scope :not_deleted, {:conditions => ['workflow_state != ?', 'deleted']}
|
||||
scope :not_deleted, where("workflow_state<>'deleted'")
|
||||
|
||||
named_scope :with_enrollments, lambda {
|
||||
{ :conditions => ["exists (#{Enrollment.active.send(:construct_finder_sql, {:select => "1", :conditions => ["enrollments.course_id = courses.id"]})})"] }
|
||||
scope :with_enrollments, lambda {
|
||||
where("EXISTS (#{Enrollment.active.select("1").where("enrollments.course_id=courses.id").to_sql})")
|
||||
}
|
||||
named_scope :without_enrollments, lambda {
|
||||
{ :conditions => ["NOT EXISTS (#{Enrollment.active.send(:construct_finder_sql, {:select => "1", :conditions => ["enrollments.course_id = courses.id"]})})"] }
|
||||
scope :without_enrollments, lambda {
|
||||
where("NOT EXISTS (#{Enrollment.active.select("1").where("enrollments.course_id=courses.id").to_sql})")
|
||||
}
|
||||
named_scope :completed, lambda {
|
||||
{ :joins => :enrollment_term,
|
||||
:conditions => ["courses.workflow_state = 'completed' or courses.conclude_at < ? or enrollment_terms.end_at < ?", Time.now.utc, Time.now.utc]
|
||||
}
|
||||
scope :completed, lambda {
|
||||
joins(:enrollment_term).
|
||||
where("courses.workflow_state='completed' OR courses.conclude_at<? OR enrollment_terms.end_at<?", Time.now.utc, Time.now.utc)
|
||||
}
|
||||
named_scope :not_completed, lambda {
|
||||
{ :joins => :enrollment_term,
|
||||
:conditions => [%{courses.workflow_state <> 'completed' AND
|
||||
(courses.conclude_at IS NULL OR courses.conclude_at >= ?) AND
|
||||
(enrollment_terms.end_at IS NULL OR enrollment_terms.end_at >= ?)}, Time.now.utc, Time.now.utc]
|
||||
}
|
||||
scope :not_completed, lambda {
|
||||
joins(:enrollment_term).
|
||||
where("courses.workflow_state<>'completed' AND
|
||||
(courses.conclude_at IS NULL OR courses.conclude_at>=?) AND
|
||||
(enrollment_terms.end_at IS NULL OR enrollment_terms.end_at>=?)", Time.now.utc, Time.now.utc)
|
||||
}
|
||||
named_scope :by_teachers, lambda{ |teacher_ids|
|
||||
teacher_ids.empty? ? { :conditions => "1 = 0" } :
|
||||
{ :conditions => ["EXISTS (#{Enrollment.active.send(:construct_finder_sql, {:select => "1",
|
||||
:conditions => ["enrollments.course_id = courses.id AND enrollments.type = 'TeacherEnrollment' AND enrollments.user_id IN (#{teacher_ids.join(',')})"]})})"]
|
||||
}
|
||||
scope :by_teachers, lambda { |teacher_ids|
|
||||
teacher_ids.empty? ?
|
||||
where("?", false) :
|
||||
where("EXISTS (#{Enrollment.active.select("1").where("enrollments.course_id=courses.id AND enrollments.type='TeacherEnrollment' AND enrollments.user_id IN (?)", teacher_ids).to_sql})")
|
||||
}
|
||||
named_scope :by_associated_accounts, lambda{ |account_ids|
|
||||
account_ids.empty? ? { :conditions => "1 = 0" } :
|
||||
{ :conditions => ["EXISTS (#{CourseAccountAssociation.send(:construct_finder_sql, {:select => "1",
|
||||
:conditions => ["course_account_associations.course_id = courses.id AND course_account_associations.account_id IN (#{account_ids.join(',')})"]})})"]
|
||||
}
|
||||
scope :by_associated_accounts, lambda{ |account_ids|
|
||||
account_ids.empty? ?
|
||||
where("?", false) :
|
||||
where("EXISTS (#{CourseAccountAssociation.select("1").where("course_account_associations.course_id=courses.id AND course_account_associations.account_id IN (?)", account_ids).to_sql})")
|
||||
}
|
||||
|
||||
named_scope :deleted, :conditions => ["workflow_state = ? ", 'deleted']
|
||||
scope :deleted, where(:workflow_state => 'deleted')
|
||||
|
||||
set_broadcast_policy do |p|
|
||||
p.dispatch :grade_weight_changed
|
||||
|
|
|
@ -62,7 +62,5 @@ class CourseImport < ActiveRecord::Base
|
|||
end
|
||||
handle_asynchronously :perform_later, :max_attempts => 1, :priority => Delayed::LOW_PRIORITY
|
||||
|
||||
named_scope :for_course, lambda{|course, type|
|
||||
{:conditions => ['course_imports.course_id = ? AND course_imports.import_type = ?', course.id, type], :order => 'course_imports.created_at DESC' }
|
||||
}
|
||||
scope :for_course, lambda { |course, type| where(:course_id => course, :import_type => type).order("course_imports.created_at DESC") }
|
||||
end
|
||||
|
|
|
@ -231,13 +231,9 @@ class CourseSection < ActiveRecord::Base
|
|||
save!
|
||||
end
|
||||
|
||||
named_scope :active, lambda {
|
||||
{ :conditions => ['course_sections.workflow_state != ?', 'deleted'] }
|
||||
}
|
||||
scope :active, where("course_sections.workflow_state<>'deleted'")
|
||||
|
||||
named_scope :sis_sections, lambda{|account, *source_ids|
|
||||
{:conditions => {:root_account_id => account.id, :sis_source_id => source_ids}, :order => :sis_source_id}
|
||||
}
|
||||
scope :sis_sections, lambda { |account, *source_ids| where(:root_account_id => account, :sis_source_id => source_ids).order(:sis_source_id) }
|
||||
|
||||
def common_to_users?(users)
|
||||
users.all?{ |user| self.student_enrollments.active.for_user(user).count > 0 }
|
||||
|
|
|
@ -36,35 +36,33 @@ class DelayedMessage < ActiveRecord::Base
|
|||
end
|
||||
end
|
||||
|
||||
named_scope :for, lambda { |context|
|
||||
scope :for, lambda { |context|
|
||||
case context
|
||||
when :daily
|
||||
{ :conditions => { :frequency => 'daily' } }
|
||||
where(:frequency => 'daily')
|
||||
when :weekly
|
||||
{ :conditions => { :frequency => 'weekly' } }
|
||||
where(:frequency => 'weekly')
|
||||
when Notification
|
||||
{ :conditions => { :notification_id => context.id} }
|
||||
where(:notification_id => context)
|
||||
when NotificationPolicy
|
||||
{ :conditions => { :notification_policy_id => context.id} }
|
||||
where(:notification_policy_id => context)
|
||||
when CommunicationChannel
|
||||
{ :conditions => { :communication_channel_id => context.id} }
|
||||
where(:communication_channel_id => context)
|
||||
else
|
||||
{ :conditions => { :context_id => context.id, :context_type => context.class.base_ar_class.to_s } }
|
||||
where(:context_id => context, :context_type => context.class.base_ar_class.to_s)
|
||||
end
|
||||
}
|
||||
|
||||
named_scope :by, lambda {|field| { :order => field } }
|
||||
scope :by, lambda { |field| order(field) }
|
||||
|
||||
named_scope :in_state, lambda { |state|
|
||||
{ :conditions => ["workflow_state = ?", state.to_s]}
|
||||
scope :in_state, lambda { |state| where(:workflow_state => state.to_s) }
|
||||
|
||||
scope :to_summarize, lambda {
|
||||
where("delayed_messages.workflow_state='pending' and delayed_messages.send_at<=?", Time.now.utc)
|
||||
}
|
||||
|
||||
named_scope :to_summarize, lambda {
|
||||
{ :conditions => ['delayed_messages.workflow_state = ? and delayed_messages.send_at <= ?', 'pending', Time.now.utc ] }
|
||||
}
|
||||
|
||||
named_scope :next_to_summarize, lambda {
|
||||
{ :conditions => ['delayed_messages.workflow_state = ?', 'pending'], :order => :send_at, :limit => 1 }
|
||||
scope :next_to_summarize, lambda {
|
||||
where(:workflow_state => 'pending').order(:send_at).limit(1)
|
||||
}
|
||||
|
||||
def self.ids_for_messages_with_communication_channel_id(cc_id)
|
||||
|
|
|
@ -76,7 +76,7 @@ class DelayedNotification < ActiveRecord::Base
|
|||
end
|
||||
memoize :to_list
|
||||
|
||||
named_scope :to_be_processed, lambda {|limit|
|
||||
{:conditions => ['delayed_notifications.workflow_state = ?', 'to_be_processed'], :limit => limit, :order => 'delayed_notifications.created_at'}
|
||||
scope :to_be_processed, lambda { |limit|
|
||||
where(:workflow_state => 'to_be_processed').limit(limit).order("delayed_notifications.created_at")
|
||||
}
|
||||
end
|
||||
|
|
|
@ -207,8 +207,8 @@ class DiscussionEntry < ActiveRecord::Base
|
|||
end
|
||||
end
|
||||
|
||||
named_scope :active, :conditions => ['discussion_entries.workflow_state != ?', 'deleted']
|
||||
named_scope :deleted, :conditions => ['discussion_entries.workflow_state = ?', 'deleted']
|
||||
scope :active, where("discussion_entries.workflow_state<>'deleted'")
|
||||
scope :deleted, where(:workflow_state => 'deleted')
|
||||
|
||||
def user_name
|
||||
self.user.name rescue t :default_user_name, "User Name"
|
||||
|
@ -274,28 +274,12 @@ class DiscussionEntry < ActiveRecord::Base
|
|||
can :create
|
||||
end
|
||||
|
||||
named_scope :for_user, lambda{|user|
|
||||
{:conditions => ['discussion_entries.user_id = ?', (user.is_a?(User) ? user.id : user)], :order => 'discussion_entries.created_at'}
|
||||
}
|
||||
named_scope :for_users, lambda{|users|
|
||||
user_ids = users.map{ |u| u.is_a?(User) ? u.id : u }
|
||||
{:conditions => ['discussion_entries.user_id IN (?)', user_ids]}
|
||||
}
|
||||
named_scope :after, lambda{|date|
|
||||
{:conditions => ['created_at > ?', date] }
|
||||
}
|
||||
named_scope :include_subentries, lambda{
|
||||
{:include => discussion_subentries}
|
||||
}
|
||||
named_scope :top_level_for_topics, lambda {|topics|
|
||||
topic_ids = topics.map{ |t| t.is_a?(DiscussionTopic) ? t.id : t }
|
||||
{:conditions => ['discussion_entries.root_entry_id IS NULL AND discussion_entries.discussion_topic_id IN (?)', topic_ids]}
|
||||
}
|
||||
named_scope :all_for_topics, lambda { |topics|
|
||||
topic_ids = topics.map{ |t| t.is_a?(DiscussionTopic) ? t.id : t }
|
||||
{:conditions => ['discussion_entries.discussion_topic_id IN (?)', topic_ids]}
|
||||
}
|
||||
named_scope :newest_first, :order => 'discussion_entries.created_at DESC'
|
||||
scope :for_user, lambda { |user| where(:user_id => user).order("discussion_entries.created_at") }
|
||||
scope :for_users, lambda { |users| where(:user_id => users) }
|
||||
scope :after, lambda { |date| where("created_at>?", date) }
|
||||
scope :top_level_for_topics, lambda {|topics| where(:root_entry_id => nil, :discussion_topic_id => topics) }
|
||||
scope :all_for_topics, lambda { |topics| where(:discussion_topic_id => topics) }
|
||||
scope :newest_first, order("discussion_entries.created_at DESC")
|
||||
|
||||
def to_atom(opts={})
|
||||
author_name = self.user.present? ? self.user.name : t('atom_no_author', "No Author")
|
||||
|
|
|
@ -310,28 +310,18 @@ class DiscussionTopic < ActiveRecord::Base
|
|||
topic_participant
|
||||
end
|
||||
|
||||
named_scope :recent, lambda{
|
||||
{:conditions => ['discussion_topics.last_reply_at > ?', 2.weeks.ago], :order => 'discussion_topics.last_reply_at DESC'}
|
||||
}
|
||||
named_scope :only_discussion_topics, lambda {
|
||||
{:conditions => ['discussion_topics.type IS NULL'] }
|
||||
}
|
||||
named_scope :for_subtopic_refreshing, lambda {
|
||||
{:conditions => ['discussion_topics.subtopics_refreshed_at IS NOT NULL AND discussion_topics.subtopics_refreshed_at < discussion_topics.updated_at'], :order => 'discussion_topics.subtopics_refreshed_at' }
|
||||
}
|
||||
named_scope :for_delayed_posting, lambda {
|
||||
{:conditions => ['discussion_topics.workflow_state = ? AND discussion_topics.delayed_post_at < ?', 'post_delayed', Time.now.utc], :order => 'discussion_topics.delayed_post_at'}
|
||||
}
|
||||
named_scope :active, :conditions => ['discussion_topics.workflow_state != ?', 'deleted']
|
||||
named_scope :for_context_codes, lambda {|codes|
|
||||
{:conditions => ['discussion_topics.context_code IN (?)', codes] }
|
||||
scope :recent, lambda { where("discussion_topics.last_reply_at>?", 2.weeks.ago).order("discussion_topics.last_reply_at DESC") }
|
||||
scope :only_discussion_topics, where(:type => nil)
|
||||
scope :for_subtopic_refreshing, where("discussion_topics.subtopics_refreshed_at IS NOT NULL AND discussion_topics.subtopics_refreshed_at<discussion_topics.updated_at").order("discussion_topics.subtopics_refreshed_at")
|
||||
scope :for_delayed_posting, lambda {
|
||||
where("discussion_topics.workflow_state='post_delayed' AND discussion_topics.delayed_post_at<?", Time.now.utc).order("discussion_topics.delayed_post_at")
|
||||
}
|
||||
scope :active, where("discussion_topics.workflow_state<>'deleted'")
|
||||
scope :for_context_codes, lambda {|codes| where(:context_code => codes) }
|
||||
|
||||
named_scope :before, lambda {|date|
|
||||
{:conditions => ['discussion_topics.created_at < ?', date]}
|
||||
}
|
||||
scope :before, lambda { |date| where("discussion_topics.created_at<?", date) }
|
||||
|
||||
named_scope :by_position, :order => "discussion_topics.position DESC, discussion_topics.created_at DESC"
|
||||
scope :by_position, order("discussion_topics.position DESC, discussion_topics.created_at DESC")
|
||||
|
||||
def try_posting_delayed
|
||||
if self.post_delayed? && Time.now >= self.delayed_post_at
|
||||
|
|
|
@ -136,68 +136,60 @@ class Enrollment < ActiveRecord::Base
|
|||
}
|
||||
end
|
||||
|
||||
named_scope :active,
|
||||
:conditions => ['enrollments.workflow_state != ?', 'deleted']
|
||||
scope :active, where("enrollments.workflow_state<>'deleted'")
|
||||
|
||||
named_scope :admin,
|
||||
:select => 'course_id',
|
||||
:joins => :course,
|
||||
:conditions => "enrollments.type IN ('TeacherEnrollment','TaEnrollment', 'DesignerEnrollment')
|
||||
AND (courses.workflow_state = 'claimed' OR (enrollments.workflow_state = 'active' and courses.workflow_state = 'available'))"
|
||||
scope :admin,
|
||||
select(:course_id).
|
||||
joins(:course).
|
||||
where("enrollments.type IN ('TeacherEnrollment','TaEnrollment', 'DesignerEnrollment')
|
||||
AND (courses.workflow_state='claimed' OR (enrollments.workflow_state='active' AND courses.workflow_state='available'))")
|
||||
|
||||
named_scope :of_admin_type,
|
||||
:conditions => "enrollments.type IN ('TeacherEnrollment','TaEnrollment', 'DesignerEnrollment')"
|
||||
scope :of_admin_type, where(:type => ['TeacherEnrollment','TaEnrollment', 'DesignerEnrollment'])
|
||||
|
||||
named_scope :of_instructor_type,
|
||||
:conditions => "enrollments.type IN ('TeacherEnrollment','TaEnrollment')"
|
||||
scope :of_instructor_type, where(:type => ['TeacherEnrollment', 'TaEnrollment'])
|
||||
|
||||
named_scope :of_content_admins,
|
||||
:conditions => "enrollments.type IN ('TeacherEnrollment', 'DesignerEnrollment')"
|
||||
scope :of_content_admins, where(:type => ['TeacherEnrollment', 'DesignerEnrollment'])
|
||||
|
||||
named_scope :student,
|
||||
:select => 'course_id',
|
||||
:joins => :course,
|
||||
:conditions => "enrollments.type = 'StudentEnrollment'
|
||||
AND enrollments.workflow_state = 'active'
|
||||
AND courses.workflow_state = 'available'"
|
||||
scope :student,
|
||||
select(:course_id).
|
||||
joins(:course).
|
||||
where(:type => 'StudentEnrollment', :workflow_state => 'active', :courses => { :workflow_state => 'available' })
|
||||
|
||||
named_scope :student_in_claimed_or_available,
|
||||
:select => 'course_id',
|
||||
:joins => :course,
|
||||
:conditions => "enrollments.type = 'StudentEnrollment'
|
||||
AND enrollments.workflow_state = 'active'
|
||||
AND courses.workflow_state IN ('available', 'claimed')"
|
||||
scope :student_in_claimed_or_available,
|
||||
select(:course_id).
|
||||
joins(:course).
|
||||
where(:type => 'StudentEnrollment', :workflow_state => 'active', :courses => { :workflow_state => ['available', 'claimed'] })
|
||||
|
||||
named_scope :all_student,
|
||||
:include => :course,
|
||||
:conditions => "(enrollments.type = 'StudentEnrollment'
|
||||
AND enrollments.workflow_state IN ('invited', 'active', 'completed')
|
||||
AND courses.workflow_state IN ('available', 'completed')) OR
|
||||
(enrollments.type = 'StudentViewEnrollment'
|
||||
AND enrollments.workflow_state = 'active'
|
||||
AND courses.workflow_state != 'deleted')"
|
||||
scope :all_student,
|
||||
includes(:course).
|
||||
where("(enrollments.type = 'StudentEnrollment'
|
||||
AND enrollments.workflow_state IN ('invited', 'active', 'completed')
|
||||
AND courses.workflow_state IN ('available', 'completed')) OR
|
||||
(enrollments.type = 'StudentViewEnrollment'
|
||||
AND enrollments.workflow_state = 'active'
|
||||
AND courses.workflow_state != 'deleted')")
|
||||
|
||||
named_scope :ended,
|
||||
:joins => :course,
|
||||
:conditions => "courses.workflow_state = 'completed' or enrollments.workflow_state = 'rejected' or enrollments.workflow_state = 'completed'"
|
||||
scope :ended,
|
||||
joins(:course).
|
||||
where("courses.workflow_state='completed' OR enrollments.workflow_state='rejected' OR enrollments.workflow_state='completed'")
|
||||
|
||||
named_scope :future, lambda { {
|
||||
:joins => :course,
|
||||
:conditions => ["(courses.start_at > ?
|
||||
AND courses.workflow_state = 'available'
|
||||
AND courses.restrict_enrollments_to_course_dates = ?
|
||||
AND enrollments.workflow_state IN ('invited', 'active', 'completed'))
|
||||
OR (courses.workflow_state IN ('created', 'claimed')
|
||||
AND enrollments.workflow_state IN ('invited', 'active', 'completed', 'creation_pending'))", Time.now, true]
|
||||
} }
|
||||
scope :future, lambda {
|
||||
joins(:course).
|
||||
where("(courses.start_at>?
|
||||
AND courses.workflow_state='available'
|
||||
AND courses.restrict_enrollments_to_course_dates=?
|
||||
AND enrollments.workflow_state IN ('invited', 'active', 'completed'))
|
||||
OR (courses.workflow_state IN ('created', 'claimed')
|
||||
AND enrollments.workflow_state IN ('invited', 'active', 'completed', 'creation_pending'))", Time.now.utc, true)
|
||||
}
|
||||
|
||||
named_scope :past,
|
||||
:joins => :course,
|
||||
:conditions => "(courses.workflow_state = 'completed'
|
||||
AND enrollments.workflow_state NOT IN ('invited', 'deleted'))
|
||||
OR enrollments.workflow_state IN ('rejected', 'completed')"
|
||||
scope :past,
|
||||
joins(:course).
|
||||
where("(courses.workflow_state='completed'
|
||||
AND enrollments.workflow_state NOT IN ('invited', 'deleted'))
|
||||
OR enrollments.workflow_state IN ('rejected', 'completed')")
|
||||
|
||||
named_scope :not_fake, :conditions => "enrollments.type != 'StudentViewEnrollment'"
|
||||
scope :not_fake, where("enrollments.type<>'StudentViewEnrollment'")
|
||||
|
||||
|
||||
READABLE_TYPES = {
|
||||
|
@ -846,33 +838,36 @@ class Enrollment < ActiveRecord::Base
|
|||
can :read and can :read_grades and can :read_services
|
||||
end
|
||||
|
||||
named_scope :before, lambda{|date|
|
||||
{:conditions => ['enrollments.created_at < ?', date]}
|
||||
scope :before, lambda{ |date|
|
||||
where("enrollments.created_at<?", date)
|
||||
}
|
||||
|
||||
named_scope :for_user, lambda{|user|
|
||||
{:conditions => ['enrollments.user_id = ?', user.id] }
|
||||
}
|
||||
scope :for_user, lambda { |user| where(:user_id => user) }
|
||||
|
||||
named_scope :for_courses_with_user_name, lambda{|courses|
|
||||
{
|
||||
:conditions => {:course_id => courses.map(&:id)},
|
||||
:joins => :user,
|
||||
:select => 'user_id, course_id, users.name AS user_name'
|
||||
}
|
||||
scope :for_courses_with_user_name, lambda { |courses|
|
||||
where(:course_id => courses).
|
||||
joins(:user).
|
||||
select("user_id, course_id, users.name AS user_name")
|
||||
}
|
||||
named_scope :invited, :conditions => { :workflow_state => 'invited' }
|
||||
named_scope :accepted, :conditions => ['enrollments.workflow_state != ?', 'invited']
|
||||
named_scope :active_or_pending, :conditions => {:workflow_state => ['invited', 'creation_pending', 'active']}
|
||||
named_scope :currently_online, :joins => :pseudonyms, :conditions => ['pseudonyms.last_request_at > ?', 5.minutes.ago]
|
||||
scope :invited, where(:workflow_state => 'invited')
|
||||
scope :accepted, where("enrollments.workflow_state<>'invited'")
|
||||
scope :active_or_pending, where(:workflow_state => ['invited', 'creation_pending', 'active'])
|
||||
scope :currently_online, joins(:pseudonyms).where("pseudonyms.last_request_at>?", 5.minutes.ago)
|
||||
# this returns enrollments for creation_pending users; should always be used in conjunction with the invited scope
|
||||
named_scope :for_email, lambda { |email|
|
||||
{
|
||||
:joins => { :user => :communication_channels },
|
||||
:conditions => ["users.workflow_state='creation_pending' AND communication_channels.workflow_state='unconfirmed' AND path_type='email' AND LOWER(path)=?", email.downcase],
|
||||
:select => 'enrollments.*',
|
||||
:readonly => false
|
||||
}
|
||||
scope :for_email, lambda { |email|
|
||||
if Rails.version < '3.0'
|
||||
{
|
||||
:joins => { :user => :communication_channels },
|
||||
:conditions => ["users.workflow_state='creation_pending' AND communication_channels.workflow_state='unconfirmed' AND path_type='email' AND LOWER(path)=?", email.downcase],
|
||||
:select => 'enrollments.*',
|
||||
:readonly => false
|
||||
}
|
||||
else
|
||||
joins(:user => :communication_channels).
|
||||
where("users.workflow_state='creation_pending' AND communication_channels.workflow_state='unconfirmed' AND path_type='email' AND LOWER(path)=?", email.downcase).
|
||||
select("enrollments.*").
|
||||
readonly(false)
|
||||
end
|
||||
}
|
||||
def self.cached_temporary_invitations(email)
|
||||
if Enrollment.cross_shard_invitations?
|
||||
|
|
|
@ -131,7 +131,5 @@ class EnrollmentTerm < ActiveRecord::Base
|
|||
save!
|
||||
end
|
||||
|
||||
named_scope :active, lambda {
|
||||
{ :conditions => ['enrollment_terms.workflow_state != ?', 'deleted'] }
|
||||
}
|
||||
scope :active, where("enrollment_terms.workflow_state<>'deleted'")
|
||||
end
|
||||
|
|
|
@ -38,7 +38,7 @@ class Eportfolio < ActiveRecord::Base
|
|||
self.save
|
||||
end
|
||||
|
||||
named_scope :active, :conditions => ['eportfolios.workflow_state != ?', 'deleted']
|
||||
scope :active, where("eportfolios.workflow_state<>'deleted'")
|
||||
|
||||
before_create :assign_uuid
|
||||
def assign_uuid
|
||||
|
|
|
@ -51,14 +51,12 @@ class ExternalFeed < ActiveRecord::Base
|
|||
write_attribute(:header_match, str.to_s.strip.presence)
|
||||
end
|
||||
|
||||
named_scope :to_be_polled, lambda {
|
||||
{ :conditions => ['external_feeds.consecutive_failures < ? and external_feeds.refresh_at < ?', 5, Time.now ], :order => :refresh_at }
|
||||
}
|
||||
|
||||
named_scope :for, lambda {|obj|
|
||||
{ :conditions => ['external_feeds.feed_purpose = ?', obj] }
|
||||
scope :to_be_polled, lambda {
|
||||
where("external_feeds.consecutive_failures<5 AND external_feeds.refresh_at<?", Time.now.utc).order(:refresh_at)
|
||||
}
|
||||
|
||||
scope :for, lambda { |obj| where(:feed_purpose => obj) }
|
||||
|
||||
def add_rss_entries(rss)
|
||||
items = rss.items.map{|item| add_entry(item, rss, :rss) }.compact
|
||||
self.context.add_aggregate_entries(items, self) if self.context && self.context.respond_to?(:add_aggregate_entries)
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
class Favorite < ActiveRecord::Base
|
||||
belongs_to :context, :polymorphic => true
|
||||
named_scope :by, lambda { |type| {:conditions => {:context_type => type}} }
|
||||
scope :by, lambda { |type| where(:context_type => type) }
|
||||
attr_accessible :context, :context_id, :context_type
|
||||
end
|
||||
|
|
|
@ -88,12 +88,12 @@ class Folder < ActiveRecord::Base
|
|||
self.save
|
||||
end
|
||||
|
||||
named_scope :active, :conditions => ['folders.workflow_state != ?', 'deleted']
|
||||
named_scope :not_hidden, :conditions => ['folders.workflow_state != ?', 'hidden']
|
||||
named_scope :not_locked, lambda {{:conditions => ['(folders.locked IS NULL OR folders.locked = ?) AND ((folders.lock_at IS NULL) OR
|
||||
(folders.lock_at > ? OR (folders.unlock_at IS NOT NULL AND folders.unlock_at < ?)))', false, Time.now, Time.now]}}
|
||||
named_scope :by_position, :order => 'position'
|
||||
named_scope :by_name, :order => name_order_by_clause('folders')
|
||||
scope :active, where("folders.workflow_state<>'deleted'")
|
||||
scope :not_hidden, where("folders.workflow_state<>'hidden'")
|
||||
scope :not_locked, lambda { where("(folders.locked IS NULL OR folders.locked=?) AND ((folders.lock_at IS NULL) OR
|
||||
(folders.lock_at>? OR (folders.unlock_at IS NOT NULL AND folders.unlock_at<?)))", false, Time.now.utc, Time.now.utc) }
|
||||
scope :by_position, order(:position)
|
||||
scope :by_name, order(name_order_by_clause('folders'))
|
||||
|
||||
def display_name
|
||||
name
|
||||
|
|
|
@ -51,8 +51,8 @@ class GradingStandard < ActiveRecord::Base
|
|||
state :deleted
|
||||
end
|
||||
|
||||
named_scope :active, :conditions => ['grading_standards.workflow_state != ?', 'deleted']
|
||||
named_scope :sorted, :order => "usage_count >= 3 DESC, title ASC"
|
||||
scope :active, where("grading_standards.workflow_state<>'deleted'")
|
||||
scope :sorted, order("usage_count >= 3 DESC, title ASC")
|
||||
|
||||
VERSION = 2
|
||||
|
||||
|
|
|
@ -189,7 +189,7 @@ class Group < ActiveRecord::Base
|
|||
group_memberships.update_all(:workflow_state => 'deleted')
|
||||
end
|
||||
|
||||
named_scope :active, :conditions => ['groups.workflow_state != ?', 'deleted']
|
||||
scope :active, where("groups.workflow_state<>'deleted'")
|
||||
|
||||
def full_name
|
||||
res = before_label(self.name) + " "
|
||||
|
|
|
@ -23,13 +23,9 @@ class GroupCategory < ActiveRecord::Base
|
|||
has_many :assignments, :dependent => :nullify
|
||||
validates_length_of :name, :maximum => maximum_string_length, :allow_nil => true, :allow_blank => true
|
||||
|
||||
named_scope :active, lambda {
|
||||
{ :conditions => ['group_categories.deleted_at is null'] }
|
||||
}
|
||||
scope :active, where(:deleted_at => nil)
|
||||
|
||||
named_scope :other_than, lambda{ |cat|
|
||||
{ :conditions => ['group_categories.id != ?', cat.id || 0] }
|
||||
}
|
||||
scope :other_than, lambda { |cat| where("group_categories.id<>?", cat.id || 0) }
|
||||
|
||||
class << self
|
||||
def protected_name_for_context?(name, context)
|
||||
|
|
|
@ -39,10 +39,10 @@ class GroupMembership < ActiveRecord::Base
|
|||
|
||||
has_a_broadcast_policy
|
||||
|
||||
named_scope :include_user, :include => :user
|
||||
scope :include_user, includes(:user)
|
||||
|
||||
named_scope :active, :conditions => ['group_memberships.workflow_state != ?', 'deleted']
|
||||
named_scope :moderators, :conditions => { :moderator => true }
|
||||
scope :active, where("group_memberships.workflow_state<>'deleted'")
|
||||
scope :moderators, where(:moderator => true)
|
||||
|
||||
alias_method :context, :group
|
||||
|
||||
|
|
|
@ -39,8 +39,8 @@ class InboxItem < ActiveRecord::Base
|
|||
attr_accessible :user_id, :asset, :subject, :body_teaser, :sender_id
|
||||
|
||||
# Named scopes
|
||||
named_scope :active, :conditions => "workflow_state NOT IN ('deleted', 'retired', 'retired_unread')"
|
||||
named_scope :unread, :conditions => {:workflow_state => 'unread'}
|
||||
scope :active, where("workflow_state NOT IN ('deleted', 'retired', 'retired_unread')")
|
||||
scope :unread, where(:workflow_state => 'unread')
|
||||
|
||||
# State machine
|
||||
workflow do
|
||||
|
|
|
@ -121,10 +121,8 @@ class LearningOutcome < ActiveRecord::Base
|
|||
state :deleted
|
||||
end
|
||||
|
||||
named_scope :active, lambda{
|
||||
{:conditions => ['workflow_state != ?', 'deleted'] }
|
||||
}
|
||||
|
||||
scope :active, where("workflow_state<>'deleted'")
|
||||
|
||||
def cached_context_short_name
|
||||
@cached_context_name ||= Rails.cache.fetch(['short_name_lookup', self.context_code].cache_key) do
|
||||
self.context.short_name rescue ""
|
||||
|
@ -295,21 +293,14 @@ class LearningOutcome < ActiveRecord::Base
|
|||
|
||||
item
|
||||
end
|
||||
|
||||
named_scope :for_context_codes, lambda{|codes|
|
||||
{:conditions => {:context_code => Array(codes)} }
|
||||
}
|
||||
named_scope :active, lambda{
|
||||
{:conditions => ['learning_outcomes.workflow_state != ?', 'deleted'] }
|
||||
}
|
||||
named_scope :has_result_for, lambda{|user|
|
||||
{:joins => [:learning_outcome_results],
|
||||
:conditions => ['learning_outcomes.id = learning_outcome_results.learning_outcome_id AND learning_outcome_results.user_id = ?', user.id],
|
||||
:order => 'short_description'
|
||||
}
|
||||
|
||||
scope :for_context_codes, lambda { |codes| where(:context_code => codes) }
|
||||
scope :active, where("learning_outcomes.workflow_state<>'deleted'")
|
||||
scope :has_result_for, lambda { |user|
|
||||
joins(:learning_outcome_results).
|
||||
where("learning_outcomes.id=learning_outcome_results.learning_outcome_id AND learning_outcome_results.user_id=?", user).
|
||||
order(:short_description)
|
||||
}
|
||||
|
||||
named_scope :global, lambda{
|
||||
{:conditions => {:context_id => nil} }
|
||||
}
|
||||
scope :global, where(:context_id => nil)
|
||||
end
|
||||
|
|
|
@ -270,17 +270,11 @@ class LearningOutcomeGroup < ActiveRecord::Base
|
|||
item
|
||||
end
|
||||
|
||||
named_scope :active, lambda{
|
||||
{:conditions => ['learning_outcome_groups.workflow_state != ?', 'deleted'] }
|
||||
}
|
||||
scope :active, where("learning_outcome_groups.workflow_state<>'deleted'")
|
||||
|
||||
named_scope :global, lambda{
|
||||
{:conditions => {:context_id => nil} }
|
||||
}
|
||||
scope :global, where(:context_id => nil)
|
||||
|
||||
named_scope :root, lambda{
|
||||
{:conditions => {:learning_outcome_group_id => nil} }
|
||||
}
|
||||
scope :root, where(:learning_outcome_group_id => nil)
|
||||
|
||||
def self.for_context(context)
|
||||
context ? context.learning_outcome_groups : LearningOutcomeGroup.global
|
||||
|
|
|
@ -79,37 +79,26 @@ class LearningOutcomeResult < ActiveRecord::Base
|
|||
end
|
||||
end
|
||||
|
||||
named_scope :for_context_codes, lambda{|codes|
|
||||
scope :for_context_codes, lambda { |codes|
|
||||
if codes == 'all'
|
||||
{}
|
||||
scoped
|
||||
else
|
||||
{:conditions => {:context_code => Array(codes)} }
|
||||
where(:context_code => codes)
|
||||
end
|
||||
}
|
||||
named_scope :for_user, lambda{|user|
|
||||
{:conditions => {:user_id => user.id} }
|
||||
}
|
||||
named_scope :custom_ordering, lambda{|param|
|
||||
scope :for_user, lambda { |user| where(:user_id => user) }
|
||||
scope :custom_ordering, lambda { |param|
|
||||
orders = {
|
||||
'recent' => "assessed_at DESC",
|
||||
'highest' => "score DESC",
|
||||
'oldest' => "score ASC",
|
||||
'default' => "assessed_at DESC"
|
||||
}
|
||||
order = orders[param] || orders['default']
|
||||
{:order => order }
|
||||
}
|
||||
named_scope :for_outcome_ids, lambda{|ids|
|
||||
{:conditions => {:learning_outcome_id => ids} }
|
||||
}
|
||||
named_scope :for_association, lambda{|association|
|
||||
{:conditions => {:association_type => association.class.to_s, :association_id => association.id} }
|
||||
}
|
||||
named_scope :for_associated_asset, lambda{|associated_asset|
|
||||
{:conditions => {:associated_asset_type => associated_asset.class.to_s, :associated_asset_id => associated_asset.id} }
|
||||
}
|
||||
named_scope :for_user, lambda{|user|
|
||||
user_id = user.is_a?(User) ? user.id : user
|
||||
{:conditions => {:user_id => user_id} }
|
||||
order_clause = orders[param] || orders['default']
|
||||
order(order_clause)
|
||||
}
|
||||
scope :for_outcome_ids, lambda { |ids| where(:learning_outcome_id => ids) }
|
||||
scope :for_association, lambda { |association| where(:association_type => association.class.to_s, :association_id => association.id) }
|
||||
scope :for_associated_asset, lambda { |associated_asset| where(:associated_asset_type => associated_asset.class.to_s, :associated_asset_id => associated_asset.id) }
|
||||
scope :for_user, lambda { |user| where(:user_id => user) }
|
||||
end
|
||||
|
|
|
@ -299,17 +299,11 @@ class MediaObject < ActiveRecord::Base
|
|||
save!
|
||||
end
|
||||
|
||||
named_scope :active, lambda{
|
||||
{:conditions => ['media_objects.workflow_state != ?', 'deleted'] }
|
||||
}
|
||||
scope :active, where("media_objects.workflow_state<>'deleted'")
|
||||
|
||||
named_scope :by_media_id, lambda { |media_id|
|
||||
{ :conditions => [ 'media_objects.media_id = ? OR media_objects.old_media_id = ?', media_id, media_id ] }
|
||||
}
|
||||
scope :by_media_id, lambda { |media_id| where("media_objects.media_id=? OR media_objects.old_media_id=?", media_id, media_id) }
|
||||
|
||||
named_scope :by_media_type, lambda { |media_type|
|
||||
{ :conditions => [ 'media_objects.media_type = ?', media_type ]}
|
||||
}
|
||||
scope :by_media_type, lambda { |media_type| where(:media_type => media_type) }
|
||||
|
||||
workflow do
|
||||
state :active
|
||||
|
|
|
@ -121,64 +121,39 @@ class Message < ActiveRecord::Base
|
|||
end
|
||||
|
||||
# Named scopes
|
||||
named_scope :for_asset_context_codes, lambda { |context_codes|
|
||||
{ :conditions => { :asset_context_code => context_codes } }
|
||||
scope :for_asset_context_codes, lambda { |context_codes| where(:asset_context_code => context_codes) }
|
||||
|
||||
scope :for, lambda { |context| where(:context_type => context.class.base_ar_class.to_s, :context_id => context) }
|
||||
|
||||
scope :after, lambda { |date| where("messages.created_at>?", date) }
|
||||
|
||||
scope :to_dispatch, lambda {
|
||||
where("messages.workflow_state='staged' AND messages.dispatch_at<=? AND 'messages.to'<>'dashboard'", Time.now.utc)
|
||||
}
|
||||
|
||||
named_scope :for, lambda { |context|
|
||||
{ :conditions => ['messages.context_type = ? and messages.context_id = ?',
|
||||
context.class.base_ar_class.to_s, context.id] }
|
||||
}
|
||||
scope :to_email, where(:path_type => ['email', 'sms'])
|
||||
|
||||
named_scope :after, lambda { |date|
|
||||
{ :conditions => ['messages.created_at > ?', date] }
|
||||
}
|
||||
scope :to_facebook, where(:path_type => 'facebook', :workflow_state => 'sent').order("sent_at DESC").limit(25)
|
||||
|
||||
named_scope :to_dispatch, lambda {
|
||||
{ :conditions => ["messages.workflow_state = ? and messages.dispatch_at <= ? and 'messages.to' != ?",
|
||||
'staged', Time.now.utc, 'dashboard'] }
|
||||
}
|
||||
scope :not_to_email, where("messages.path_type NOT IN ('email', 'sms')")
|
||||
|
||||
named_scope :to_email, { :conditions =>
|
||||
['messages.path_type = ? OR messages.path_type = ?', 'email', 'sms'] }
|
||||
scope :by_name, lambda { |notification_name| where(:notification_name => notification_name) }
|
||||
|
||||
named_scope :to_facebook, { :conditions =>
|
||||
['messages.path_type = ? AND messages.workflow_state = ?',
|
||||
'facebook', 'sent'], :order => 'sent_at DESC', :limit => 25 }
|
||||
scope :before, lambda { |date| where("messages.created_at<?", date) }
|
||||
|
||||
named_scope :not_to_email, { :conditions =>
|
||||
['messages.path_type != ? AND messages.path_type != ?', 'email', 'sms'] }
|
||||
|
||||
named_scope :by_name, lambda { |notification_name|
|
||||
{ :conditions => ['messages.notification_name = ?', notification_name] }
|
||||
}
|
||||
|
||||
named_scope :before, lambda { |date|
|
||||
{ :conditions => ['messages.created_at < ?', date] }
|
||||
}
|
||||
|
||||
named_scope :for_user, lambda { |user|
|
||||
{ :conditions => {:user_id => user} }
|
||||
}
|
||||
scope :for_user, lambda { |user| where(:user_id => user)}
|
||||
|
||||
# messages that can be moved to the 'cancelled' state. dashboard messages
|
||||
# can be closed by calling 'cancel', but aren't included
|
||||
named_scope :cancellable, { :conditions =>
|
||||
{ :workflow_state => ['created', 'staged', 'sending'] }
|
||||
}
|
||||
|
||||
scope :cancellable, where(:workflow_state => ['created', 'staged', 'sending'])
|
||||
|
||||
# For finding a very particular message:
|
||||
# Message.for(context).by_name(name).directed_to(to).for_user(user), or
|
||||
# messages.for(context).by_name(name).directed_to(to).for_user(user)
|
||||
# Where user can be a User or id, name needs to be the Notification name.
|
||||
named_scope :staged, lambda {
|
||||
{ :conditions => ['messages.workflow_state = ? and messages.dispatch_at > ?',
|
||||
'staged', DateTime.now.utc.to_s(:db) ]}
|
||||
}
|
||||
scope :staged, lambda { where("messages.workflow_state='staged' AND messages.dispatch_at>?", Time.now.utc) }
|
||||
|
||||
named_scope :in_state, lambda { |state|
|
||||
{ :conditions => { :workflow_state => Array(state).map { |f| f.to_s } } }
|
||||
}
|
||||
scope :in_state, lambda { |state| where(:workflow_state => Array(state).map(&:to_s)) }
|
||||
|
||||
# Public: Helper to generate a URI for the given subject. Overrides Rails'
|
||||
# built-in ActionController::PolymorphicRoutes#polymorphic_url method because
|
||||
|
|
|
@ -16,8 +16,8 @@ class MigrationIssue < ActiveRecord::Base
|
|||
state :resolved
|
||||
end
|
||||
|
||||
named_scope :active, :conditions => { :workflow_state => 'active' }
|
||||
named_scope :by_created_at, :order => :created_at
|
||||
scope :active, where(:workflow_state => 'active')
|
||||
scope :by_created_at, order(:created_at)
|
||||
|
||||
set_policy do
|
||||
given { |user| Account.site_admin.grants_right?(user, :view_error_reports) }
|
||||
|
|
|
@ -47,7 +47,7 @@ class Notification < ActiveRecord::Base
|
|||
|
||||
attr_accessible :name, :subject, :main_link, :delay_for, :category
|
||||
|
||||
named_scope :to_show_in_feed, :conditions => ["messages.category = ? OR messages.notification_name IN (?) ", "TestImmediately", TYPES_TO_SHOW_IN_FEED]
|
||||
scope :to_show_in_feed, where("messages.category='TestImmediately' OR messages.notification_name IN (?)", TYPES_TO_SHOW_IN_FEED)
|
||||
|
||||
validates_uniqueness_of :name
|
||||
|
||||
|
|
|
@ -30,30 +30,23 @@ class NotificationPolicy < ActiveRecord::Base
|
|||
# This is for choosing a policy for another context, so:
|
||||
# NotificationPolicy.for(notification) or
|
||||
# communication_channel.notification_policies.for(notification)
|
||||
named_scope :for, lambda { |context|
|
||||
scope :for, lambda { |context|
|
||||
case context
|
||||
when User
|
||||
{ :joins => :communication_channel,
|
||||
:conditions => ["communication_channels.user_id = ? AND communication_channels.workflow_state <> 'retired'", context.id] }
|
||||
joins(:communication_channel).
|
||||
where("communication_channels.user_id=? AND communication_channels.workflow_state<>'retired'", context)
|
||||
when Notification
|
||||
{ :conditions => ['notification_policies.notification_id = ?', context.id] }
|
||||
where(:notification_id => context)
|
||||
else
|
||||
{}
|
||||
scoped
|
||||
end
|
||||
}
|
||||
|
||||
# TODO: the named_scope name should be self-explanatory... change this to
|
||||
# TODO: the scope name should be self-explanatory... change this to
|
||||
# by_frequency or something This is for choosing a policy by frequency
|
||||
named_scope :by, lambda { |freq|
|
||||
case freq
|
||||
when Array
|
||||
{ :conditions => { :frequency => freq.map{|f| f.to_s} } }
|
||||
else
|
||||
{ :conditions => ['notification_policies.frequency = ?', freq.to_s] }
|
||||
end
|
||||
}
|
||||
|
||||
named_scope :in_state, lambda { |state| { :conditions => ["notification_policies.workflow_state = ?", state.to_s] } }
|
||||
scope :by, lambda { |freq| where(:frequency => Array(freq).map(&:to_s)) }
|
||||
|
||||
scope :in_state, lambda { |state| where(:workflow_state => state.to_s) }
|
||||
|
||||
def infer_frequency
|
||||
self.frequency ||= "immediately"
|
||||
|
|
|
@ -22,10 +22,8 @@ class PageComment < ActiveRecord::Base
|
|||
validates_length_of :message, :maximum => maximum_text_length, :allow_nil => true, :allow_blank => true
|
||||
attr_accessible :message
|
||||
|
||||
named_scope :for_user, lambda{|user|
|
||||
{:conditions => ['page_comments.user_id = ?', user.id]}
|
||||
}
|
||||
|
||||
scope :for_user, lambda { |user| where(:user_id => user) }
|
||||
|
||||
def user_name
|
||||
self.user.name rescue t(:default_user_name, "Anonymous")
|
||||
end
|
||||
|
|
|
@ -209,10 +209,8 @@ class PageView < ActiveRecord::Base
|
|||
end
|
||||
end
|
||||
|
||||
named_scope :for_context, proc { |ctx| { :conditions => { :context_type => ctx.class.name, :context_id => ctx.id } } }
|
||||
named_scope :for_users, lambda{ |users|
|
||||
{ :conditions => {:user_id => users} }
|
||||
}
|
||||
scope :for_context, proc { |ctx| where(:context_type => ctx.class.name, :context_id => ctx) }
|
||||
scope :for_users, lambda { |users| where(:user_id => users) }
|
||||
|
||||
module CassandraBookmarker
|
||||
def self.bookmark_for(item)
|
||||
|
|
|
@ -103,11 +103,11 @@ class Pseudonym < ActiveRecord::Base
|
|||
@send_confirmation = false
|
||||
end
|
||||
|
||||
named_scope :by_unique_id, lambda { |unique_id|
|
||||
scope :by_unique_id, lambda { |unique_id|
|
||||
if %w{mysql mysql2}.include?(connection_pool.spec.config[:adapter])
|
||||
{ :conditions => {:unique_id => unique_id } }
|
||||
where(:unique_id => unique_id)
|
||||
else
|
||||
{ :conditions => ["LOWER(#{quoted_table_name}.unique_id)=?", unique_id.mb_chars.downcase] }
|
||||
where("LOWER(#{quoted_table_name}.unique_id)=?", unique_id.mb_chars.downcase)
|
||||
end
|
||||
}
|
||||
|
||||
|
@ -374,10 +374,7 @@ class Pseudonym < ActiveRecord::Base
|
|||
nil
|
||||
end
|
||||
|
||||
named_scope :account_unique_ids, lambda{|account, *unique_ids|
|
||||
{:conditions => {:account_id => account.id, :unique_id => unique_ids}, :order => :unique_id}
|
||||
}
|
||||
named_scope :active, :conditions => ['pseudonyms.workflow_state IS NULL OR pseudonyms.workflow_state != ?', 'deleted']
|
||||
scope :active, where("pseudonyms.workflow_state IS NULL OR pseudonyms.workflow_state<>'deleted'")
|
||||
|
||||
def self.serialization_excludes; [:crypted_password, :password_salt, :reset_password_token, :persistence_token, :single_access_token, :perishable_token, :sis_ssha]; end
|
||||
|
||||
|
|
|
@ -1337,18 +1337,10 @@ class Quiz < ActiveRecord::Base
|
|||
given { |user, session| self.available? && self.cached_context_grants_right?(user, session, :participate_as_student) }#students.include?(user) }
|
||||
can :read and can :submit
|
||||
end
|
||||
named_scope :include_assignment, lambda{
|
||||
{ :include => :assignment }
|
||||
}
|
||||
named_scope :before, lambda{|date|
|
||||
{:conditions => ['quizzes.created_at < ?', date]}
|
||||
}
|
||||
named_scope :active, lambda{
|
||||
{:conditions => ['quizzes.workflow_state != ?', 'deleted'] }
|
||||
}
|
||||
named_scope :not_for_assignment, lambda{
|
||||
{:conditions => ['quizzes.assignment_id IS NULL'] }
|
||||
}
|
||||
scope :include_assignment, includes(:assignment)
|
||||
scope :before, lambda { |date| where("quizzes.created_at<?", date) }
|
||||
scope :active, where("quizzes.workflow_state<>'deleted'")
|
||||
scope :not_for_assignment, where(:assignment_id => nil)
|
||||
|
||||
def migrate_file_links
|
||||
QuizQuestionLinkMigrator.migrate_file_links_in_quiz(self)
|
||||
|
|
|
@ -626,15 +626,9 @@ class QuizSubmission < ActiveRecord::Base
|
|||
return result
|
||||
end
|
||||
|
||||
named_scope :before, lambda{|date|
|
||||
{:conditions => ['quiz_submissions.created_at < ?', date]}
|
||||
}
|
||||
named_scope :updated_after, lambda{|date|
|
||||
if date
|
||||
{:conditions => ['quiz_submissions.updated_at > ?', date]}
|
||||
end
|
||||
}
|
||||
named_scope :for_user_ids, lambda{|user_ids|
|
||||
{:conditions => {:user_id => user_ids} }
|
||||
scope :before, lambda { |date| where("quiz_submissions.created_at<?", date) }
|
||||
scope :updated_after, lambda { |date|
|
||||
date ? where("quiz_submissions.updated_at>?", date) : scoped
|
||||
}
|
||||
scope :for_user_ids, lambda { |user_ids| where(:user_id => user_ids) }
|
||||
end
|
||||
|
|
|
@ -74,10 +74,10 @@ class ReportSnapshot < ActiveRecord::Base
|
|||
write_attribute(:data, data.to_json)
|
||||
end
|
||||
|
||||
named_scope :detailed, :conditions => { :report_type => 'counts_detailed' }
|
||||
named_scope :progressive, :conditions => { :report_type => 'counts_progressive_detailed' }
|
||||
named_scope :overview, :conditions => { :report_type => 'counts_overview' }
|
||||
named_scope :progressive_overview, :conditions => { :report_type => 'counts_progressive_overview' }
|
||||
scope :detailed, where(:report_type => 'counts_detailed')
|
||||
scope :progressive, where(:report_type => 'counts_progressive_detailed')
|
||||
scope :overview, where(:report_type => 'counts_overview')
|
||||
scope :progressive_overview, where(:report_type => 'counts_progressive_overview')
|
||||
|
||||
def push_to_instructure_if_collection_enabled
|
||||
begin
|
||||
|
|
|
@ -71,12 +71,12 @@ class Role < ActiveRecord::Base
|
|||
save!
|
||||
end
|
||||
|
||||
named_scope :not_deleted, :conditions => ['roles.workflow_state != ?', 'deleted']
|
||||
named_scope :deleted, :conditions => ['roles.workflow_state = ?', 'deleted']
|
||||
named_scope :active, :conditions => ['roles.workflow_state = ?', 'active']
|
||||
named_scope :inactive, :conditions => ['roles.workflow_state = ?', 'inactive']
|
||||
named_scope :for_courses, :conditions => ['roles.base_role_type != ?', AccountUser::BASE_ROLE_NAME]
|
||||
named_scope :for_accounts, :conditions => ['roles.base_role_type = ?', AccountUser::BASE_ROLE_NAME]
|
||||
scope :not_deleted, where("roles.workflow_state<>'deleted'")
|
||||
scope :deleted, where(:workflow_state => 'deleted')
|
||||
scope :active, where(:workflow_state => 'active')
|
||||
scope :inactive, where(:workflow_state => 'inactive')
|
||||
scope :for_courses, where("roles.base_role_type<>?", AccountUser::BASE_ROLE_NAME)
|
||||
scope :for_accounts, where(:base_role_type => AccountUser::BASE_ROLE_NAME)
|
||||
|
||||
def self.is_base_role?(role_name)
|
||||
RoleOverride.base_role_types.include?(role_name)
|
||||
|
|
|
@ -33,19 +33,11 @@ class Rubric < ActiveRecord::Base
|
|||
serialize :data
|
||||
simply_versioned
|
||||
|
||||
named_scope :publicly_reusable, lambda {
|
||||
{:conditions => {:reusable => true}, :order => :title}
|
||||
}
|
||||
named_scope :matching, lambda {|search|
|
||||
{:order => 'rubrics.association_count DESC', :conditions => wildcard('rubrics.title', search)}
|
||||
}
|
||||
named_scope :before, lambda{|date|
|
||||
{:conditions => ['rubrics.created_at < ?', date]}
|
||||
}
|
||||
named_scope :active, lambda{
|
||||
{:conditions => ['workflow_state != ?', 'deleted'] }
|
||||
}
|
||||
|
||||
scope :publicly_reusable, where(:reusable => true).order(:title)
|
||||
scope :matching, lambda { |search| where(wildcard('rubrics.title', search)).order("rubrics.association_count DESC") }
|
||||
scope :before, lambda { |date| where("rubrics.created_at<?", date) }
|
||||
scope :active, where("workflow_state<>'deleted'")
|
||||
|
||||
set_policy do
|
||||
given {|user, session| self.cached_context_grants_right?(user, session, :manage_rubrics)}
|
||||
can :read and can :create and can :delete_associations
|
||||
|
|
|
@ -166,10 +166,8 @@ class RubricAssessment < ActiveRecord::Base
|
|||
can :update
|
||||
end
|
||||
|
||||
named_scope :of_type, lambda {|type|
|
||||
{:conditions => ['rubric_assessments.assessment_type = ?', type.to_s]}
|
||||
}
|
||||
|
||||
scope :of_type, lambda { |type| where(:assessment_type => type.to_s) }
|
||||
|
||||
def methods_for_serialization(*methods)
|
||||
@serialization_methods = methods
|
||||
end
|
||||
|
|
|
@ -73,25 +73,13 @@ class RubricAssociation < ActiveRecord::Base
|
|||
}
|
||||
end
|
||||
|
||||
named_scope :bookmarked, lambda {
|
||||
{:conditions => {:bookmarked => true} }
|
||||
}
|
||||
named_scope :for_purpose, lambda {|purpose|
|
||||
{:conditions => {:purpose => purpose} }
|
||||
}
|
||||
named_scope :for_grading, lambda {
|
||||
{:conditions => {:purpose => 'grading'}}
|
||||
}
|
||||
named_scope :for_context_codes, lambda{|codes|
|
||||
{:conditions => {:context_code => codes} }
|
||||
}
|
||||
named_scope :include_rubric, lambda{
|
||||
{:include => :rubric}
|
||||
}
|
||||
named_scope :before, lambda{|date|
|
||||
{:conditions => ['rubric_associations.created_at < ?', date]}
|
||||
}
|
||||
|
||||
scope :bookmarked, where(:bookmarked => true)
|
||||
scope :for_purpose, lambda { |purpose| where(:purpose => purpose) }
|
||||
scope :for_grading, where(:purpose => 'grading')
|
||||
scope :for_context_codes, lambda { |codes| where(:context_code => codes) }
|
||||
scope :include_rubric, includes(:rubric)
|
||||
scope :before, lambda { |date| where("rubric_associations.created_at<?", date) }
|
||||
|
||||
def assert_uniqueness
|
||||
if purpose == 'grading'
|
||||
RubricAssociation.find_all_by_association_id_and_association_type_and_purpose(association_id, association_type, 'grading').each do |ra|
|
||||
|
|
|
@ -116,7 +116,7 @@ class SisBatch < ActiveRecord::Base
|
|||
self.save
|
||||
end
|
||||
|
||||
named_scope :needs_processing, :conditions => { :workflow_state => 'created' }, :order => :created_at
|
||||
scope :needs_processing, where(:workflow_state => 'created').order(:created_at)
|
||||
|
||||
def self.process_all_for_account(account)
|
||||
loop do
|
||||
|
|
|
@ -358,12 +358,8 @@ class StreamItem < ActiveRecord::Base
|
|||
count
|
||||
end
|
||||
|
||||
named_scope :before, lambda {|id|
|
||||
{:conditions => ['id < ?', id], :order => 'updated_at DESC', :limit => 21 }
|
||||
}
|
||||
named_scope :after, lambda {|start_at|
|
||||
{:conditions => ['updated_at > ?', start_at], :order => 'updated_at DESC', :limit => 21 }
|
||||
}
|
||||
scope :before, lambda { |id| where("id<?", id).order("updated_at DESC").limit(21) }
|
||||
scope :after, lambda { |start_at| where("updated_at>?", start_at).order("updated_at DESC").limit(21) }
|
||||
|
||||
def associated_shards
|
||||
if self.context.try(:respond_to?, :associated_shards)
|
||||
|
|
|
@ -46,40 +46,28 @@ class Submission < ActiveRecord::Base
|
|||
include CustomValidations
|
||||
validates_as_url :url
|
||||
|
||||
named_scope :with_comments, :include => [:submission_comments ]
|
||||
named_scope :after, lambda{|date|
|
||||
{:conditions => ['submissions.created_at > ?', date] }
|
||||
}
|
||||
named_scope :before, lambda{|date|
|
||||
{:conditions => ['submissions.created_at < ?', date]}
|
||||
}
|
||||
named_scope :submitted_before, lambda{|date|
|
||||
{:conditions => ['submitted_at < ?', date] }
|
||||
}
|
||||
named_scope :submitted_after, lambda{|date|
|
||||
{:conditions => ['submitted_at > ?', date] }
|
||||
}
|
||||
scope :with_comments, includes(:submission_comments)
|
||||
scope :after, lambda { |date| where("submissions.created_at>?", date) }
|
||||
scope :before, lambda { |date| where("submissions.created_at<?", date) }
|
||||
scope :submitted_before, lambda { |date| where("submitted_at<?", date) }
|
||||
scope :submitted_after, lambda { |date| where("submitted_at>?", date) }
|
||||
|
||||
named_scope :for_context_codes, lambda { |context_codes|
|
||||
{ :conditions => {:context_code => context_codes} }
|
||||
}
|
||||
scope :for_context_codes, lambda { |context_codes| where(:context_code => context_codes) }
|
||||
|
||||
# This should only be used in the course drop down to show assignments recently graded.
|
||||
named_scope :recently_graded_assignments, lambda{|user_id, date, limit|
|
||||
{
|
||||
:select => 'assignments.id, assignments.title, assignments.points_possible, assignments.due_at,
|
||||
submissions.grade, submissions.score, submissions.graded_at, assignments.grading_type,
|
||||
assignments.context_id, assignments.context_type, courses.name AS context_name',
|
||||
:joins => 'JOIN assignments ON assignments.id = submissions.assignment_id
|
||||
JOIN courses ON courses.id = assignments.context_id',
|
||||
:conditions => ["graded_at > ? AND user_id = ? AND muted = ?", date.to_s(:db), user_id, false],
|
||||
:order => 'graded_at DESC',
|
||||
:limit => limit
|
||||
}
|
||||
scope :recently_graded_assignments, lambda { |user_id, date, limit|
|
||||
select("assignments.id, assignments.title, assignments.points_possible, assignments.due_at,
|
||||
submissions.grade, submissions.score, submissions.graded_at, assignments.grading_type,
|
||||
assignments.context_id, assignments.context_type, courses.name AS context_name").
|
||||
joins("JOIN assignments ON assignments.id=submissions.assignment_id
|
||||
JOIN courses ON courses.id=assignments.context_id").
|
||||
where("graded_at>? AND user_id=? AND muted=?", date, user_id, false).
|
||||
order("graded_at DESC").
|
||||
limit(limit)
|
||||
}
|
||||
|
||||
named_scope :for_course, lambda{ |course|
|
||||
{ :conditions => ["submissions.assignment_id IN (SELECT assignments.id FROM assignments WHERE assignments.context_id = ? AND assignments.context_type = 'Course')", course.id] }
|
||||
scope :for_course, lambda { |course|
|
||||
where("submissions.assignment_id IN (SELECT assignments.id FROM assignments WHERE assignments.context_id = ? AND assignments.context_type = 'Course')", course)
|
||||
}
|
||||
|
||||
def self.needs_grading_conditions(prefix = nil)
|
||||
|
@ -96,7 +84,7 @@ class Submission < ActiveRecord::Base
|
|||
conditions
|
||||
end
|
||||
|
||||
named_scope :needs_grading, :conditions => needs_grading_conditions
|
||||
scope :needs_grading, where(needs_grading_conditions)
|
||||
|
||||
|
||||
sanitize_field :body, Instructure::SanitizeField::SANITIZE
|
||||
|
@ -730,49 +718,22 @@ class Submission < ActiveRecord::Base
|
|||
state :graded
|
||||
end
|
||||
|
||||
named_scope :graded, lambda {
|
||||
{:conditions => ['submissions.grade IS NOT NULL']}
|
||||
}
|
||||
scope :graded, where("submissions.grade IS NOT NULL")
|
||||
|
||||
named_scope :ungraded, lambda {
|
||||
{:conditions => ['submissions.grade IS NULL'], :include => :assignment}
|
||||
}
|
||||
scope :ungraded, where(:grade => nil).includes(:assignment)
|
||||
|
||||
named_scope :in_workflow_state, lambda { |provided_state|
|
||||
{ :conditions => { :workflow_state => provided_state } }
|
||||
}
|
||||
scope :in_workflow_state, lambda { |provided_state| where(:workflow_state => provided_state) }
|
||||
|
||||
named_scope :having_submission, :conditions => 'submissions.submission_type IS NOT NULL'
|
||||
scope :having_submission, where("submissions.submission_type IS NOT NULL")
|
||||
|
||||
named_scope :include_user, lambda {
|
||||
{:include => [:user] }
|
||||
}
|
||||
scope :include_user, includes(:user)
|
||||
|
||||
named_scope :include_teacher, lambda{
|
||||
{:include => {:assignment => :teacher_enrollment} }
|
||||
}
|
||||
named_scope :include_assessment_requests, lambda {
|
||||
{:include => [:assessment_requests, :assigned_assessments] }
|
||||
}
|
||||
named_scope :include_versions, lambda{
|
||||
{:include => [:versions] }
|
||||
}
|
||||
named_scope :include_submission_comments, lambda{
|
||||
{:include => [:submission_comments] }
|
||||
}
|
||||
named_scope :speed_grader_includes, lambda{
|
||||
{:include => [:versions, :submission_comments, :attachments, :rubric_assessment]}
|
||||
}
|
||||
named_scope :for, lambda {|context|
|
||||
{:include => :assignment, :conditions => ['assignments.context_id = ? AND assignments.context_type = ?', context.id, context.class.to_s]}
|
||||
}
|
||||
named_scope :for_user, lambda {|user|
|
||||
user_id = user.is_a?(User) ? user.id : user
|
||||
{:conditions => ['submissions.user_id IN (?)', Array(user_id)]}
|
||||
}
|
||||
named_scope :needing_screenshot, lambda {
|
||||
{:conditions => ['submissions.submission_type = ? AND submissions.attachment_id IS NULL AND submissions.process_attempts < 3', 'online_url'], :order => :updated_at}
|
||||
}
|
||||
scope :include_assessment_requests, includes(:assessment_requests, :assigned_assessments)
|
||||
scope :include_versions, includes(:versions)
|
||||
scope :include_submission_comments, includes(:submission_comments)
|
||||
scope :speed_grader_includes, includes(:versions, :submission_comments, :attachments, :rubric_assessment)
|
||||
scope :for_user, lambda { |user| where(:user_id => user) }
|
||||
scope :needing_screenshot, where("submissions.submission_type='online_url' AND submissions.attachment_id IS NULL AND submissions.process_attempts<3").order(:updated_at)
|
||||
|
||||
def needs_regrading?
|
||||
graded? && !grade_matches_current_submission?
|
||||
|
@ -824,12 +785,12 @@ class Submission < ActiveRecord::Base
|
|||
nil
|
||||
end
|
||||
|
||||
named_scope :for, lambda { |obj|
|
||||
scope :for, lambda { |obj|
|
||||
case obj
|
||||
when User
|
||||
{:conditions => ['user_id = ?', obj]}
|
||||
where(:user_id => obj)
|
||||
else
|
||||
{}
|
||||
scoped
|
||||
end
|
||||
}
|
||||
|
||||
|
|
|
@ -44,9 +44,7 @@ class SubmissionComment < ActiveRecord::Base
|
|||
|
||||
serialize :cached_attachments
|
||||
|
||||
named_scope :for_assignment_id, lambda { |assignment_id|
|
||||
{ :conditions => ['submissions.assignment_id = ?', assignment_id], :joins => :submission }
|
||||
}
|
||||
scope :for_assignment_id, lambda { |assignment_id| where(:submissions => { :assignment_id => assignment_id }).joins(:submission) }
|
||||
|
||||
def delete_other_comments_in_this_group
|
||||
return if !self.group_comment_id || @skip_destroy_callbacks
|
||||
|
@ -219,14 +217,10 @@ class SubmissionComment < ActiveRecord::Base
|
|||
self.ar_to_json(options, &block)
|
||||
end
|
||||
|
||||
named_scope :visible, :conditions => { :hidden => false }
|
||||
scope :visible, where(:hidden => false)
|
||||
|
||||
named_scope :after, lambda{|date|
|
||||
{:conditions => ['submission_comments.created_at > ?', date] }
|
||||
}
|
||||
named_scope :for_context, lambda{|context|
|
||||
{:conditions => ['submission_comments.context_id = ? AND submission_comments.context_type = ?', context.id, context.class.to_s] }
|
||||
}
|
||||
scope :after, lambda { |date| where("submission_comments.created_at>?", date) }
|
||||
scope :for_context, lambda { |context| where(:context_id => context, :context_type => context.class.to_s) }
|
||||
|
||||
def update_participation
|
||||
# id_changed? because new_record? is false in after_save callbacks
|
||||
|
|
|
@ -185,39 +185,27 @@ class User < ActiveRecord::Base
|
|||
PageView.for_user(self)
|
||||
end
|
||||
|
||||
named_scope :of_account, lambda { |account|
|
||||
{
|
||||
:joins => :user_account_associations,
|
||||
:conditions => ['user_account_associations.account_id = ?', account.id]
|
||||
}
|
||||
scope :of_account, lambda { |account| joins(:user_account_associations).where(:user_account_associations => { :account_id => account }) }
|
||||
scope :recently_logged_in, lambda {
|
||||
includes(:pseudonyms).
|
||||
where("pseudonyms.current_login_at>?", 1.month.ago).
|
||||
order("pseudonyms.current_login_at DESC").
|
||||
limit(25)
|
||||
}
|
||||
named_scope :recently_logged_in, lambda{
|
||||
{
|
||||
:include => :pseudonyms,
|
||||
:conditions => ['pseudonyms.current_login_at > ?', 1.month.ago],
|
||||
:order => 'pseudonyms.current_login_at DESC',
|
||||
:limit => 25
|
||||
}
|
||||
}
|
||||
named_scope :include_pseudonym, lambda{
|
||||
{:include => :pseudonym }
|
||||
}
|
||||
named_scope :restrict_to_sections, lambda{|sections|
|
||||
section_ids = Array(sections).map{|s| s.is_a?(Fixnum) ? s : s.id }
|
||||
if section_ids.empty?
|
||||
{:conditions => {}}
|
||||
scope :include_pseudonym, includes(:pseudonym)
|
||||
scope :restrict_to_sections, lambda { |sections|
|
||||
if sections.empty?
|
||||
scoped
|
||||
else
|
||||
{:conditions => ["enrollments.limit_privileges_to_course_section IS NULL OR enrollments.limit_privileges_to_course_section != ? OR enrollments.course_section_id IN (?)", true, section_ids]}
|
||||
where("enrollments.limit_privileges_to_course_section IS NULL OR enrollments.limit_privileges_to_course_section<>? OR enrollments.course_section_id IN (?)", true, sections)
|
||||
end
|
||||
}
|
||||
named_scope :name_like, lambda { |name|
|
||||
{ :conditions => ["(", wildcard('users.name', 'users.short_name', name), " OR exists (select 1 from pseudonyms where ", wildcard('pseudonyms.sis_user_id', 'pseudonyms.unique_id', name), " and pseudonyms.user_id = users.id and (", User.send(:sanitize_sql_array, Pseudonym.active.proxy_options[:conditions]), ")))"].join }
|
||||
}
|
||||
named_scope :active, lambda {
|
||||
{ :conditions => ["users.workflow_state != ?", 'deleted'] }
|
||||
scope :name_like, lambda { |name|
|
||||
where("#{wildcard('users.name', 'users.short_name', name)} OR EXISTS (#{Pseudonym.select("1").where(wildcard('pseudonyms.sis_user_id', 'pseudonyms.unique_id', name)).where("pseudonyms.user_id=users.id").active.to_sql})")
|
||||
}
|
||||
scope :active, where("users.workflow_state<>'deleted'")
|
||||
|
||||
named_scope :has_current_student_enrollments, :conditions => "EXISTS (SELECT * FROM enrollments JOIN courses ON courses.id = enrollments.course_id AND courses.workflow_state = 'available' WHERE enrollments.user_id = users.id AND enrollments.workflow_state IN ('active','invited') AND enrollments.type = 'StudentEnrollment')"
|
||||
scope :has_current_student_enrollments, where("EXISTS (SELECT * FROM enrollments JOIN courses ON courses.id=enrollments.course_id AND courses.workflow_state='available' WHERE enrollments.user_id=users.id AND enrollments.workflow_state IN ('active','invited') AND enrollments.type='StudentEnrollment')")
|
||||
|
||||
def self.order_by_sortable_name(options = {})
|
||||
clause = sortable_name_order_by_clause
|
||||
|
@ -243,30 +231,20 @@ class User < ActiveRecord::Base
|
|||
order_by_sortable_name
|
||||
end
|
||||
|
||||
named_scope :enrolled_in_course_between, lambda{|course_ids, start_at, end_at|
|
||||
ids_string = course_ids.join(",")
|
||||
{
|
||||
:joins => :enrollments,
|
||||
:conditions => ["enrollments.course_id in (#{ids_string}) AND enrollments.created_at > ? AND enrollments.created_at < ?", start_at, end_at]
|
||||
}
|
||||
}
|
||||
scope :enrolled_in_course_between, lambda { |course_ids, start_at, end_at| joins(:enrollments).where(:enrollments => { :course_id => course_ids, :created_at => start_at..end_at }) }
|
||||
|
||||
named_scope :for_course_with_last_login, lambda {|course, root_account_id, enrollment_type|
|
||||
course_id = course.is_a?(Course) ? course.id : course
|
||||
enrollment_conditions = sanitize_sql(['enrollments.course_id = ? AND enrollments.workflow_state != ?', course_id, 'deleted'])
|
||||
enrollment_conditions += sanitize_sql(['AND enrollments.type = ?', enrollment_type]) if enrollment_type
|
||||
{
|
||||
# add a field to each user that is the aggregated max from current_login_at and last_login_at from their pseudonyms
|
||||
:select => 'users.*, MAX(current_login_at) as last_login, MAX(current_login_at) IS NULL as login_info_exists',
|
||||
scope :for_course_with_last_login, lambda { |course, root_account_id, enrollment_type|
|
||||
# add a field to each user that is the aggregated max from current_login_at and last_login_at from their pseudonyms
|
||||
scope = select("users.*, MAX(current_login_at) as last_login, MAX(current_login_at) IS NULL as login_info_exists").
|
||||
# left outer join ensures we get the user even if they don't have a pseudonym
|
||||
:joins => sanitize_sql([<<-SQL, root_account_id]),
|
||||
joins(sanitize_sql([<<-SQL, root_account_id])).where(:enrollments => { :course_id => course })
|
||||
LEFT OUTER JOIN pseudonyms ON pseudonyms.user_id = users.id AND pseudonyms.account_id = ?
|
||||
INNER JOIN enrollments ON enrollments.user_id = users.id
|
||||
SQL
|
||||
:conditions => enrollment_conditions,
|
||||
# the trick to get unique users
|
||||
:group => 'users.id'
|
||||
}
|
||||
scope = scope.where("enrollments.workflow_state<>'deleted'")
|
||||
scope = scope.where(:enrollments => { :type => enrollment_type }) if enrollment_type
|
||||
# the trick to get unique users
|
||||
scope.group("users.id")
|
||||
}
|
||||
|
||||
has_a_broadcast_policy
|
||||
|
@ -567,16 +545,11 @@ class User < ActiveRecord::Base
|
|||
end
|
||||
protected :assign_uuid
|
||||
|
||||
named_scope :with_service, lambda { |service|
|
||||
if service.is_a?(UserService)
|
||||
{:include => :user_services, :conditions => ['user_services.service = ?', service.service]}
|
||||
else
|
||||
{:include => :user_services, :conditions => ['user_services.service = ?', service.to_s]}
|
||||
end
|
||||
}
|
||||
named_scope :enrolled_before, lambda{|date|
|
||||
{:conditions => ['enrollments.created_at < ?', date]}
|
||||
scope :with_service, lambda { |service|
|
||||
service = service.service if service.is_a?(UserService)
|
||||
includes(:user_services).where(:user_services => { :service => service.to_s })
|
||||
}
|
||||
scope :enrolled_before, lambda { |date| where("enrollments.created_at<?", date) }
|
||||
|
||||
def group_memberships_for(context)
|
||||
groups.where('groups.context_id' => context,
|
||||
|
@ -1263,17 +1236,12 @@ class User < ActiveRecord::Base
|
|||
end
|
||||
end
|
||||
|
||||
named_scope :with_avatar_state, lambda{|state|
|
||||
scope :with_avatar_state, lambda { |state|
|
||||
scope = where("avatar_image_url IS NOT NULL").order("avatar_image_updated_at DESC")
|
||||
if state == 'any'
|
||||
{
|
||||
:conditions =>['avatar_image_url IS NOT NULL AND avatar_state IS NOT NULL AND avatar_state != ?', 'none'],
|
||||
:order => 'avatar_image_updated_at DESC'
|
||||
}
|
||||
scope.where("avatar_state IS NOT NULL AND avatar_state<>'none'")
|
||||
else
|
||||
{
|
||||
:conditions => ['avatar_image_url IS NOT NULL AND avatar_state = ?', state],
|
||||
:order => 'avatar_image_updated_at DESC'
|
||||
}
|
||||
scope.where(:avatar_state => state)
|
||||
end
|
||||
}
|
||||
|
||||
|
|
|
@ -31,8 +31,8 @@ class UserNote < ActiveRecord::Base
|
|||
state :deleted
|
||||
end
|
||||
|
||||
named_scope :active, :conditions => ['workflow_state != ?', 'deleted']
|
||||
named_scope :desc_by_date, :order => 'created_at DESC'
|
||||
scope :active, where("workflow_state<>'deleted'")
|
||||
scope :desc_by_date, order('created_at DESC')
|
||||
|
||||
set_policy do
|
||||
given { |user| self.creator == user }
|
||||
|
|
|
@ -71,25 +71,15 @@ class UserService < ActiveRecord::Base
|
|||
state :failed
|
||||
end
|
||||
|
||||
named_scope :of_type, lambda { |type|
|
||||
{ :conditions => ['user_services.type = ?', type.to_s]}
|
||||
scope :of_type, lambda { |type| where(:type => type.to_s) }
|
||||
|
||||
scope :to_be_polled, lambda { where("refresh_at<", Time.now.utc).order(:refresh_at).limit(1) }
|
||||
scope :for_user, lambda { |user| where(:user_id => user) }
|
||||
scope :for_service, lambda { |service|
|
||||
service = service.service if service.is_a?(UserService)
|
||||
where(:service => service.to_s)
|
||||
}
|
||||
|
||||
named_scope :to_be_polled, lambda {
|
||||
{ :conditions => ['refresh_at < ?', Time.now.utc], :order => :refresh_at, :limit => 1 }
|
||||
}
|
||||
named_scope :for_user, lambda{|user|
|
||||
users = Array(user)
|
||||
{:conditions => {:user_id => users.map(&:id)} }
|
||||
}
|
||||
named_scope :for_service, lambda { |service|
|
||||
if(service.is_a?(UserService))
|
||||
{ :conditions => ['user_services.service = ?', service.service]}
|
||||
else
|
||||
{ :conditions => ['user_services.service = ?', service.to_s]}
|
||||
end
|
||||
}
|
||||
named_scope :visible, {:conditions => 'visible'}
|
||||
scope :visible, where("visible")
|
||||
|
||||
def service_name
|
||||
self.service.titleize rescue ""
|
||||
|
|
|
@ -37,9 +37,7 @@ class WebConference < ActiveRecord::Base
|
|||
|
||||
has_a_broadcast_policy
|
||||
|
||||
named_scope :for_context_codes, lambda { |context_codes| {
|
||||
:conditions => {:context_code => context_codes} }
|
||||
}
|
||||
scope :for_context_codes, lambda { |context_codes| where(:context_code => context_codes) }
|
||||
|
||||
serialize :settings
|
||||
def settings
|
||||
|
@ -350,10 +348,8 @@ class WebConference < ActiveRecord::Base
|
|||
dup
|
||||
end
|
||||
|
||||
named_scope :after, lambda{|date|
|
||||
{:conditions => ['web_conferences.start_at IS NULL OR web_conferences.start_at > ?', date] }
|
||||
}
|
||||
|
||||
scope :after, lambda { |date| where("web_conferences.start_at IS NULL OR web_conferences.start_at>?", date) }
|
||||
|
||||
set_policy do
|
||||
given { |user, session| self.users.include?(user) && self.cached_context_grants_right?(user, session, :read) }
|
||||
can :read and can :join
|
||||
|
@ -391,9 +387,8 @@ class WebConference < ActiveRecord::Base
|
|||
config[:class_name] == self.class.to_s
|
||||
end
|
||||
end
|
||||
|
||||
named_scope :active, lambda {
|
||||
}
|
||||
|
||||
scope :active, scoped
|
||||
|
||||
def as_json(options={})
|
||||
super(options.merge(:methods => [:has_advanced_settings]))
|
||||
|
|
|
@ -71,7 +71,7 @@ class WikiPage < ActiveRecord::Base
|
|||
end
|
||||
# make stringex scoping a little more useful/flexible... in addition to
|
||||
# the normal constructed attribute scope(s), it also supports paramater-
|
||||
# less named_scopeds. note that there needs to be an instance_method of
|
||||
# less scopeds. note that there needs to be an instance_method of
|
||||
# the same name for this to work
|
||||
scopes = self.class.scope_for_url ? Array(self.class.scope_for_url) : []
|
||||
base_scope = self.class
|
||||
|
@ -156,23 +156,18 @@ class WikiPage < ActiveRecord::Base
|
|||
self.versions.map(&:model)
|
||||
end
|
||||
|
||||
named_scope :active, lambda{
|
||||
{:conditions => ['wiki_pages.workflow_state = ?', 'active'] }
|
||||
}
|
||||
scope :active, where(:workflow_state => 'active')
|
||||
|
||||
named_scope :deleted_last, lambda{
|
||||
{:order => "workflow_state = 'deleted'" }
|
||||
}
|
||||
scope :deleted_last, order("workflow_state='deleted'")
|
||||
|
||||
scope :not_deleted, where("wiki_pages.workflow_state<>'deleted'")
|
||||
|
||||
named_scope :not_deleted, lambda{
|
||||
{:conditions => ['wiki_pages.workflow_state <> ?', 'deleted'] }
|
||||
}
|
||||
def not_deleted
|
||||
!deleted?
|
||||
end
|
||||
|
||||
named_scope :visible_to_students, :conditions => { :hide_from_students => false }
|
||||
named_scope :order_by_id, :order => "id"
|
||||
scope :visible_to_students, where(:hide_from_students => false)
|
||||
scope :order_by_id, order(:id)
|
||||
|
||||
def locked_for?(context, user, opts={})
|
||||
return false unless self.could_be_locked
|
||||
|
|
|
@ -62,13 +62,7 @@ class WikiPageComment < ActiveRecord::Base
|
|||
can :read
|
||||
end
|
||||
|
||||
named_scope :active, lambda{
|
||||
{:conditions => ['workflow_state != ?', 'deleted'] }
|
||||
}
|
||||
named_scope :current, lambda{
|
||||
{:conditions => {:workflow_state => :current} }
|
||||
}
|
||||
named_scope :current_first, lambda{
|
||||
{:order => 'workflow_state'}
|
||||
}
|
||||
scope :active, where("workflow_state<>'deleted'")
|
||||
scope :current, where(:workflow_state => :current)
|
||||
scope :current_first, order(:workflow_state)
|
||||
end
|
||||
|
|
|
@ -114,6 +114,23 @@ ActiveRecord::Base.class_eval do
|
|||
includes = new_options.delete(:include)
|
||||
with_exclusive_scope(:find => new_options) { joins(includes).all.map(&column) }
|
||||
end
|
||||
|
||||
# allow defining scopes Rails 3 style (scope, not named_scope)
|
||||
# scope is still a Rails 2 method, so we have to call the correct method
|
||||
# depending on the argument types
|
||||
def scope_with_named_scope(*args, &block)
|
||||
if args.length == 2
|
||||
case args[1]
|
||||
when String, Symbol
|
||||
scope_without_named_scope(*args)
|
||||
else
|
||||
named_scope *args, &block
|
||||
end
|
||||
else
|
||||
scope_without_named_scope(*args)
|
||||
end
|
||||
end
|
||||
alias_method_chain :scope, :named_scope
|
||||
end
|
||||
|
||||
# support 0 arguments
|
||||
|
@ -141,6 +158,14 @@ ActiveRecord::NamedScope::Scope.class_eval do
|
|||
self.scoped(:select => Array.wrap(value).join(','))
|
||||
end
|
||||
end
|
||||
|
||||
# fake_arel does this in a really complicated way, trying to reproduce
|
||||
# with_scope's merging rules. It has bugs merging select clauses.
|
||||
# Instead, just take the easy way out and let with_scope do all
|
||||
# the hard work
|
||||
def unspin
|
||||
with_exclusive_scope { self.scope(:find) }
|
||||
end
|
||||
end
|
||||
|
||||
ActiveRecord::Associations::AssociationCollection.class_eval do
|
||||
|
|
|
@ -92,7 +92,7 @@ ActiveRecord::Base.class_eval do
|
|||
end
|
||||
end
|
||||
|
||||
named_scope :shard, lambda { |shard| {} }
|
||||
scope :shard, lambda { |shard| scoped }
|
||||
|
||||
def shard(shard = nil)
|
||||
Shard.default
|
||||
|
|
|
@ -2178,7 +2178,7 @@ describe Assignment do
|
|||
|
||||
end
|
||||
|
||||
context "not_locked named_scope" do
|
||||
context "not_locked scope" do
|
||||
before :each do
|
||||
course_with_student_logged_in(:active_all => true)
|
||||
assignment_quiz([], :course => @course, :user => @user)
|
||||
|
|
|
@ -66,11 +66,7 @@ describe DelayedMessage do
|
|||
@delayed_message.save!
|
||||
DelayedMessage.for(@assignment).should eql([@delayed_message])
|
||||
end
|
||||
|
||||
# named_scope :in_state, lambda { |state|
|
||||
# { :context => ["workflow_state = ?", state.to_s]}
|
||||
# }
|
||||
|
||||
|
||||
it "should have a scope to order the messages by a field" do
|
||||
notification = notification_model
|
||||
cc = CommunicationChannel.create!(:path => 'path@example.com')
|
||||
|
|
|
@ -64,27 +64,33 @@ module Delayed
|
|||
end
|
||||
end
|
||||
|
||||
named_scope :current, lambda {
|
||||
{ :conditions => ["run_at <= ?", db_time_now] }
|
||||
}
|
||||
def self.current
|
||||
where("run_at<=?", db_time_now)
|
||||
end
|
||||
|
||||
named_scope :future, lambda {
|
||||
{ :conditions => ["run_at > ?", db_time_now] }
|
||||
}
|
||||
def self.future
|
||||
where("run_at>?", db_time_now)
|
||||
end
|
||||
|
||||
named_scope :failed, :conditions => ["failed_at IS NOT NULL"]
|
||||
def self.failed
|
||||
where("failed_at IS NOT NULL")
|
||||
end
|
||||
|
||||
named_scope :running, :conditions => ["locked_at is NOT NULL AND locked_by <> 'on hold'"]
|
||||
def self.running
|
||||
where("locked_at IS NOT NULL AND locked_by<>'on hold'")
|
||||
end
|
||||
|
||||
# a nice stress test:
|
||||
# 10_000.times { |i| Kernel.send_later_enqueue_args(:system, { :strand => 's1', :run_at => (24.hours.ago + (rand(24.hours.to_i))) }, "echo #{i} >> test1.txt") }
|
||||
# 500.times { |i| "ohai".send_later_enqueue_args(:reverse, { :run_at => (12.hours.ago + (rand(24.hours.to_i))) }) }
|
||||
# then fire up your workers
|
||||
# you can check out strand correctness: diff test1.txt <(sort -n test1.txt)
|
||||
named_scope :ready_to_run, lambda {
|
||||
{ :conditions => ["run_at <= ? AND locked_at IS NULL AND next_in_strand = ?", db_time_now, true] }
|
||||
}
|
||||
named_scope :by_priority, :order => 'priority ASC, run_at ASC'
|
||||
def self.ready_to_run
|
||||
where("run_at<=? AND locked_at IS NULL AND next_in_strand=?", db_time_now, true)
|
||||
end
|
||||
def self.by_priority
|
||||
order("priority ASC, run_at ASC")
|
||||
end
|
||||
|
||||
# When a worker is exiting, make sure we don't have any locked jobs.
|
||||
def self.clear_locks!(worker_name)
|
||||
|
|
Loading…
Reference in New Issue