metamaps--metamaps/app/models/access_request.rb

36 lines
845 B
Ruby
Raw Normal View History

class AccessRequest < ApplicationRecord
belongs_to :user
belongs_to :map
def approve
self.approved = true
self.answered = true
self.save
2016-12-11 23:03:59 +00:00
Mailboxer::Notification.where(notified_object: self).find_each do |notification|
Mailboxer::Receipt.where(notification: notification).update_all(is_read: true)
end
2016-12-11 23:03:59 +00:00
user_map = UserMap.create(user: user, map: map)
2016-12-13 07:42:33 +00:00
NotificationService.access_approved(self)
end
def deny
self.approved = false
self.answered = true
self.save
2016-12-11 23:03:59 +00:00
Mailboxer::Notification.where(notified_object: self).find_each do |notification|
Mailboxer::Receipt.where(notification: notification).update_all(is_read: true)
end
end
2016-12-13 07:42:33 +00:00
def requested_text
self.map.name + ' - request to edit'
end
def approved_text
self.map.name + ' - access approved'
end
end