diff --git a/app/controllers/access_controller.rb b/app/controllers/access_controller.rb index a287ca1b..d3808a1a 100644 --- a/app/controllers/access_controller.rb +++ b/app/controllers/access_controller.rb @@ -49,7 +49,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 @@ -58,7 +58,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 diff --git a/app/models/access_request.rb b/app/models/access_request.rb index 185a04f0..504e0ff2 100644 --- a/app/models/access_request.rb +++ b/app/models/access_request.rb @@ -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