prevent non work package notifications to leak via the API

pull/9665/head
ulferts 3 years ago
parent 18e4c37cf3
commit bbf05016b4
No known key found for this signature in database
GPG Key ID: A205708DE1284017
  1. 2
      app/services/notifications/create_from_model_service.rb
  2. 2
      lib/api/decorators/polymorphic_resource.rb
  3. 2
      lib/api/v3/notifications/notifications_api.rb
  4. 4
      modules/documents/spec/services/notifications/create_from_model_service_document_spec.rb
  5. 19
      spec/requests/api/v3/notifications/index_resource_spec.rb
  6. 4
      spec/services/notifications/create_from_model_service_comment_spec.rb
  7. 12
      spec/services/notifications/create_from_model_service_message_spec.rb
  8. 2
      spec/services/notifications/create_from_model_service_news_spec.rb
  9. 10
      spec/services/notifications/create_from_model_service_wiki_spec.rb

@ -68,7 +68,7 @@ class Notifications::CreateFromModelService
journal: journal,
actor: user_with_fallback,
reason: reasons.first,
read_ian: false,
read_ian: strategy.supports_ian? ? false : nil,
mail_reminder_sent: strategy.supports_mail_digest? ? false : nil,
mail_alert_sent: strategy.supports_mail? ? false : nil
}

@ -31,7 +31,7 @@
module API
module Decorators
module PolymorphicResource
# Dynamically derive a linked resource from the given polymporphic resource
# Dynamically derive a linked resource from the given polymorphic resource
def polymorphic_resource(name,
as: nil,
skip_render: ->(*) { false },

@ -46,6 +46,8 @@ module API
::Notification
.recipient(current_user)
.includes(NotificationRepresenter.to_eager_load)
.where
.not(read_ian: nil)
end
def bulk_update_status(attributes)

@ -61,7 +61,7 @@ describe Notifications::CreateFromModelService, 'document', with_settings: { jou
it_behaves_like 'creates notification' do
let(:notification_channel_reasons) do
{
read_ian: false,
read_ian: nil,
reason: :subscribed,
mail_alert_sent: false,
mail_reminder_sent: nil
@ -109,7 +109,7 @@ describe Notifications::CreateFromModelService, 'document', with_settings: { jou
it_behaves_like 'creates notification' do
let(:notification_channel_reasons) do
{
read_ian: false,
read_ian: nil,
reason: :subscribed,
mail_alert_sent: false,
mail_reminder_sent: nil

@ -216,6 +216,25 @@ describe ::API::V3::Notifications::NotificationsAPI,
end
end
context 'with a non ian notification' do
let(:wiki_page) { FactoryBot.create(:wiki_page_with_content) }
let(:non_ian_notification) do
FactoryBot.create :notification,
read_ian: nil,
recipient: recipient,
resource: wiki_page,
project: wiki_page.wiki.project,
journal: wiki_page.content.journals.first
end
let(:notifications) { [notification2, notification1, non_ian_notification] }
it_behaves_like 'API V3 collection response', 2, 2, 'Notification' do
let(:elements) { [notification2, notification1] }
end
end
context 'with a reason groupBy' do
let(:responsible_notification) do
FactoryBot.create :notification,

@ -66,7 +66,7 @@ describe Notifications::CreateFromModelService, 'comment', with_settings: { jour
it_behaves_like 'creates notification' do
let(:notification_channel_reasons) do
{
read_ian: false,
read_ian: nil,
reason: :subscribed,
mail_reminder_sent: nil,
mail_alert_sent: false
@ -109,7 +109,7 @@ describe Notifications::CreateFromModelService, 'comment', with_settings: { jour
it_behaves_like 'creates notification' do
let(:notification_channel_reasons) do
{
read_ian: false,
read_ian: nil,
reason: :watched,
mail_reminder_sent: nil,
mail_alert_sent: false

@ -67,7 +67,7 @@ describe Notifications::CreateFromModelService, 'message', with_settings: { jour
it_behaves_like 'creates notification' do
let(:notification_channel_reasons) do
{
read_ian: false,
read_ian: nil,
reason: :subscribed,
mail_reminder_sent: nil,
mail_alert_sent: false
@ -110,7 +110,7 @@ describe Notifications::CreateFromModelService, 'message', with_settings: { jour
it_behaves_like 'creates notification' do
let(:notification_channel_reasons) do
{
read_ian: false,
read_ian: nil,
reason: :watched,
mail_reminder_sent: nil,
mail_alert_sent: false
@ -157,7 +157,7 @@ describe Notifications::CreateFromModelService, 'message', with_settings: { jour
it_behaves_like 'creates notification' do
let(:notification_channel_reasons) do
{
read_ian: false,
read_ian: nil,
reason: :watched,
mail_reminder_sent: nil,
mail_alert_sent: false
@ -199,7 +199,7 @@ describe Notifications::CreateFromModelService, 'message', with_settings: { jour
it_behaves_like 'creates notification' do
let(:notification_channel_reasons) do
{
read_ian: false,
read_ian: nil,
reason: :subscribed,
mail_reminder_sent: nil,
mail_alert_sent: false
@ -242,7 +242,7 @@ describe Notifications::CreateFromModelService, 'message', with_settings: { jour
it_behaves_like 'creates notification' do
let(:notification_channel_reasons) do
{
read_ian: false,
read_ian: nil,
reason: :watched,
mail_reminder_sent: nil,
mail_alert_sent: false
@ -289,7 +289,7 @@ describe Notifications::CreateFromModelService, 'message', with_settings: { jour
it_behaves_like 'creates notification' do
let(:notification_channel_reasons) do
{
read_ian: false,
read_ian: nil,
reason: :watched,
mail_reminder_sent: nil,
mail_alert_sent: false

@ -59,7 +59,7 @@ describe Notifications::CreateFromModelService, 'news', with_settings: { journal
it_behaves_like 'creates notification' do
let(:notification_channel_reasons) do
{
read_ian: false,
read_ian: nil,
reason: :subscribed,
mail_reminder_sent: nil,
mail_alert_sent: false

@ -65,7 +65,7 @@ describe Notifications::CreateFromModelService, 'wiki', with_settings: { journal
it_behaves_like 'creates notification' do
let(:notification_channel_reasons) do
{
read_ian: false,
read_ian: nil,
reason: :subscribed,
mail_alert_sent: false,
mail_reminder_sent: nil
@ -108,7 +108,7 @@ describe Notifications::CreateFromModelService, 'wiki', with_settings: { journal
it_behaves_like 'creates notification' do
let(:notification_channel_reasons) do
{
read_ian: false,
read_ian: nil,
reason: :watched,
mail_alert_sent: false,
mail_reminder_sent: nil
@ -158,7 +158,7 @@ describe Notifications::CreateFromModelService, 'wiki', with_settings: { journal
it_behaves_like 'creates notification' do
let(:notification_channel_reasons) do
{
read_ian: false,
read_ian: nil,
reason: :subscribed,
mail_alert_sent: false,
mail_reminder_sent: nil
@ -201,7 +201,7 @@ describe Notifications::CreateFromModelService, 'wiki', with_settings: { journal
it_behaves_like 'creates notification' do
let(:notification_channel_reasons) do
{
read_ian: false,
read_ian: nil,
reason: :watched,
mail_reminder_sent: nil,
mail_alert_sent: false
@ -248,7 +248,7 @@ describe Notifications::CreateFromModelService, 'wiki', with_settings: { journal
it_behaves_like 'creates notification' do
let(:notification_channel_reasons) do
{
read_ian: false,
read_ian: nil,
reason: :watched,
mail_alert_sent: false,
mail_reminder_sent: nil

Loading…
Cancel
Save