2016-12-13 03:28:10 +00:00
|
|
|
# frozen_string_literal: true
|
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
|
2016-12-13 03:28:10 +00:00
|
|
|
save
|
2016-12-09 17:04:17 +00:00
|
|
|
|
2016-12-11 22:29:48 +00:00
|
|
|
Mailboxer::Notification.where(notified_object: self).find_each do |notification|
|
2016-12-09 17:04:17 +00:00
|
|
|
Mailboxer::Receipt.where(notification: notification).update_all(is_read: true)
|
|
|
|
end
|
2016-12-11 22:29:48 +00:00
|
|
|
|
2016-12-09 16:55:53 +00:00
|
|
|
user_map = UserMap.create(user: user, map: map)
|
2016-12-13 07:42:33 +00:00
|
|
|
NotificationService.access_approved(self)
|
2016-10-17 00:22:00 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def deny
|
|
|
|
self.approved = false
|
|
|
|
self.answered = true
|
2016-12-13 03:28:10 +00:00
|
|
|
save
|
2016-12-09 17:04:17 +00:00
|
|
|
|
2016-12-11 22:29:48 +00:00
|
|
|
Mailboxer::Notification.where(notified_object: self).find_each do |notification|
|
2016-12-09 17:04:17 +00:00
|
|
|
Mailboxer::Receipt.where(notification: notification).update_all(is_read: true)
|
|
|
|
end
|
2016-10-17 00:22:00 +00:00
|
|
|
end
|
2016-12-13 07:42:33 +00:00
|
|
|
|
|
|
|
def requested_text
|
2016-12-13 03:28:10 +00:00
|
|
|
map.name + ' - request to edit'
|
2016-12-13 07:42:33 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def approved_text
|
2016-12-13 03:28:10 +00:00
|
|
|
map.name + ' - access approved'
|
2016-12-13 07:42:33 +00:00
|
|
|
end
|
2016-10-17 00:22:00 +00:00
|
|
|
end
|