class Mumuki::Classroom::Notification

Public Class Methods

allowed(options, permissions) click to toggle source
# File lib/mumuki/classroom/models/notification.rb, line 15
def self.allowed(options, permissions)
  where(options).select {|notification| permissions.has_permission? :teacher, notification.course}.map(&:with_assignment)
end
import_from_json!(type, assignment) click to toggle source
# File lib/mumuki/classroom/models/notification.rb, line 32
def self.import_from_json!(type, assignment)
  Mumuki::Classroom::Notification.create! organization: assignment.organization,
                       course: assignment.course,
                       type: type,
                       sender: assignment.student[:uid],
                       assignment: assignment
end
page(organization, permissions, page, per_page) click to toggle source
# File lib/mumuki/classroom/models/notification.rb, line 19
def self.page(organization, permissions, page, per_page)
  where(organization: organization)
    .sort(created_at: :desc)
    .skip(per_page * (page - 1))
    .limit(per_page)
    .select {|notification| permissions.has_permission? :teacher, notification.course}
    .map(&:with_assignment)
end
unread(organization, permissions) click to toggle source
# File lib/mumuki/classroom/models/notification.rb, line 28
def self.unread(organization, permissions)
  allowed({organization: organization, read: false}, permissions)
end

Public Instance Methods

read!() click to toggle source
# File lib/mumuki/classroom/models/notification.rb, line 40
def read!
  update! read: true
end
unread!() click to toggle source
# File lib/mumuki/classroom/models/notification.rb, line 44
def unread!
  update! read: false
end
with_assignment() click to toggle source
# File lib/mumuki/classroom/models/notification.rb, line 48
def with_assignment
  as_json.except('assignment_id').merge(assignment: assignment.notification_preview, id: id.to_s)
end