From 8e74ec9a0b98a2f19ec83eecc1213aefd419608e Mon Sep 17 00:00:00 2001 From: Devin Howard Date: Fri, 9 Dec 2016 12:04:17 -0500 Subject: [PATCH] grant/deny buttons mark access request notifications as read --- app/controllers/access_controller.rb | 4 ++-- app/models/access_request.rb | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/app/controllers/access_controller.rb b/app/controllers/access_controller.rb index 08528507..6f3518d5 100644 --- a/app/controllers/access_controller.rb +++ b/app/controllers/access_controller.rb @@ -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 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