2016-10-17 00:22:00 +00:00
|
|
|
class AccessRequest < ApplicationRecord
|
|
|
|
belongs_to :user
|
|
|
|
belongs_to :map
|
|
|
|
|
|
|
|
def approve
|
|
|
|
self.approved = true
|
|
|
|
self.answered = true
|
|
|
|
self.save
|
2016-12-09 17:04:17 +00:00
|
|
|
|
|
|
|
Mailboxer::Notification.where(notified_object: self).each do |notification|
|
|
|
|
Mailboxer::Receipt.where(notification: notification).update_all(is_read: true)
|
|
|
|
end
|
|
|
|
|
2016-12-11 21:47:18 +00:00
|
|
|
user_map = UserMap.create(user: user, map: map)
|
2016-12-09 17:04:17 +00:00
|
|
|
mail = MapMailer.invite_to_edit_email(map, map.user, user)
|
2016-12-11 21:47:18 +00:00
|
|
|
user.notify(mail.subject, 'invite to edit', user_map, true, MAILBOXER_CODE_INVITED_TO_EDIT)
|
2016-10-17 00:22:00 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def deny
|
|
|
|
self.approved = false
|
|
|
|
self.answered = true
|
|
|
|
self.save
|
2016-12-09 17:04:17 +00:00
|
|
|
|
|
|
|
Mailboxer::Notification.where(notified_object: self).each do |notification|
|
|
|
|
Mailboxer::Receipt.where(notification: notification).update_all(is_read: true)
|
|
|
|
end
|
2016-10-17 00:22:00 +00:00
|
|
|
end
|
|
|
|
end
|