grant/deny buttons mark access request notifications as read

This commit is contained in:
Devin Howard 2016-12-09 12:04:17 -05:00
parent 7aa19365a1
commit 8e74ec9a0b
2 changed files with 14 additions and 4 deletions

View file

@ -50,7 +50,7 @@ class AccessController < ApplicationController
# GET maps/:id/approve_access/:request_id
def approve_access
request = AccessRequest.find(params[:request_id])
request.approve
request.approve # also marks mailboxer notification as read
respond_to do |format|
format.html { redirect_to map_path(@map), notice: 'Request was approved' }
end
@ -59,7 +59,7 @@ class AccessController < ApplicationController
# GET maps/:id/deny_access/:request_id
def deny_access
request = AccessRequest.find(params[:request_id])
request.deny
request.deny # also marks mailboxer notification as read
respond_to do |format|
format.html { redirect_to map_path(@map), notice: 'Request was turned down' }
end

View file

@ -6,13 +6,23 @@ class AccessRequest < ApplicationRecord
self.approved = true
self.answered = true
self.save
UserMap.create(user: self.user, map: self.map)
MapMailer.invite_to_edit_email(self.map, self.map.user, self.user).deliver_later
Mailboxer::Notification.where(notified_object: self).each do |notification|
Mailboxer::Receipt.where(notification: notification).update_all(is_read: true)
end
UserMap.create(user: user, map: map)
mail = MapMailer.invite_to_edit_email(map, map.user, user)
user.notify(mail.subject, 'invite to edit', self, true, MAILBOXER_CODE_INVITED_TO_EDIT)
end
def deny
self.approved = false
self.answered = true
self.save
Mailboxer::Notification.where(notified_object: self).each do |notification|
Mailboxer::Receipt.where(notification: notification).update_all(is_read: true)
end
end
end