Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

Support remindable visible? check

Kabiru Mwenja7efa737e9eee
diff --git a/app/models/reminder.rb b/app/models/reminder.rb
index ab4466dda9c..1d20d2c5d33 100644
--- a/app/models/reminder.rb
+++ b/app/models/reminder.rb
@@ -45,6 +45,10 @@ class Reminder < ApplicationRecord
.where.missing(:reminder_notifications)
end
+ def visible?(user = User.current)
+ creator == user && remindable.visible?(user)
+ end
+
def unread_notifications?
unread_notifications.exists?
end
diff --git a/spec/models/reminder_spec.rb b/spec/models/reminder_spec.rb
index 85e04873499..6ea6b49f9cf 100644
--- a/spec/models/reminder_spec.rb
+++ b/spec/models/reminder_spec.rb
@@ -69,6 +69,57 @@ RSpec.describe Reminder do
end
end
+ describe "#visible?" do
+ let(:user) { build_stubbed(:user) }
+ let(:other_user) { build_stubbed(:user) }
+ let(:remindable) { build_stubbed(:work_package) }
+ let(:reminder) { build_stubbed(:reminder, creator: user, remindable: remindable) }
+
+ context "when the creator is the current user" do
+ context "and the user has access to the remindable" do
+ current_user { user }
+
+ before do
+ mock_permissions_for(user) do |mock|
+ mock.allow_in_project(:view_work_packages, project: remindable.project)
+ end
+ end
+
+ it "returns true" do
+ expect(reminder).to be_visible
+ end
+ end
+
+ context "and the user does not have access to the remindable" do
+ current_user { user }
+
+ it "returns false" do
+ expect(reminder).not_to be_visible
+ end
+ end
+ end
+
+ context "when the current user is not the same as the creator" do
+ current_user { other_user }
+
+ context "and the user has access to the remindable" do
+ before do
+ mock_permissions_for(other_user) do |mock|
+ mock.allow_in_project(:view_work_packages, project: remindable.project)
+ end
+ end
+
+ it "returns false" do
+ expect(reminder).not_to be_visible
+
+ aggregate_failures "remindable is visible to the other user" do
+ expect(remindable.visible?(other_user)).to be(true)
+ end
+ end
+ end
+ end
+ end
+
describe "#unread_notifications?" do
context "with an unread notification" do
subject { create(:reminder, :with_unread_notifications) }