-
-
Notifications
You must be signed in to change notification settings - Fork 484
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'rubyforgood:main' into issue-5759
- Loading branch information
Showing
11 changed files
with
140 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,25 @@ | ||
class NotificationsController < ApplicationController | ||
after_action :verify_authorized | ||
before_action :set_notification, only: %i[mark_as_read] | ||
|
||
def index | ||
authorize Noticed::Notification, policy_class: NotificationPolicy | ||
|
||
@deploy_time = Health.instance.latest_deploy_time | ||
@notifications = current_user.notifications.includes([:event]).newest_first | ||
@patch_notes = PatchNote.notes_available_for_user(current_user) | ||
end | ||
|
||
def mark_as_read | ||
@notification = Noticed::Notification.find(params[:id]) | ||
authorize @notification, policy_class: NotificationPolicy | ||
|
||
@notification.mark_as_read unless @notification.read? | ||
redirect_to @notification.event.url | ||
end | ||
|
||
private | ||
|
||
def set_notification | ||
@notification = Noticed::Notification.find(params[:id]) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
class NotificationPolicy < ApplicationPolicy | ||
def index? | ||
admin_or_supervisor_or_volunteer? | ||
end | ||
|
||
def mark_as_read? | ||
record&.recipient == user | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
require "rails_helper" | ||
|
||
RSpec.describe NotificationPolicy, type: :policy do | ||
subject { described_class } | ||
|
||
let(:recipient) { create(:volunteer) } | ||
let(:casa_admin) { create(:casa_admin) } | ||
let(:volunteer) { build(:volunteer) } | ||
let(:supervisor) { build(:supervisor) } | ||
|
||
permissions :index? do | ||
it "allows any volunteer" do | ||
is_expected.to permit(casa_admin) | ||
end | ||
|
||
it "allows any supervisor" do | ||
is_expected.to permit(supervisor) | ||
end | ||
|
||
it "allows any admin" do | ||
is_expected.to permit(volunteer) | ||
end | ||
end | ||
|
||
permissions :mark_as_read? do | ||
let(:notification) { create(:notification, recipient: recipient) } | ||
|
||
it "allows recipient" do | ||
is_expected.to permit(recipient, notification) | ||
end | ||
|
||
it "does not allow other volunteer" do | ||
is_expected.to_not permit(volunteer, notification) | ||
end | ||
|
||
it "does not permit other supervisor" do | ||
is_expected.to_not permit(supervisor, notification) | ||
end | ||
|
||
it "does not permit other admin" do | ||
is_expected.to_not permit(casa_admin, notification) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters