[38062] Avoid sending notifications with no ian reason

pull/9494/head
Oliver Günther 3 years ago committed by ulferts
parent b424404e9b
commit 31726649d4
No known key found for this signature in database
GPG Key ID: A205708DE1284017
  1. 3
      frontend/src/app/features/in-app-notifications/entry/in-app-notification-entry.component.ts
  2. 10
      lib/api/v3/notifications/notifications_api.rb
  3. 2
      spec/factories/notification_factory.rb
  4. 9
      spec/requests/api/v3/notifications/index_resource_spec.rb

@ -51,6 +51,7 @@ export class InAppNotificationEntryComponent implements OnInit {
text = {
loading: this.I18n.t('js.ajax.loading'),
placeholder: this.I18n.t('js.placeholders.default'),
};
constructor(
@ -124,7 +125,7 @@ export class InAppNotificationEntryComponent implements OnInit {
private buildTranslatedReason() {
this.translatedReason = this.I18n.t(
`js.notifications.reasons.${this.notification.reason}`,
{ defaultValue: this.notification.reason },
{ defaultValue: this.notification.reason || this.text.placeholder },
);
}

@ -42,6 +42,12 @@ module API
.call(params)
end
def notification_scope
::Notification
.recipient(current_user)
.where.not(reason_ian: nil)
end
def bulk_update_status(attributes)
if notification_query.valid?
notification_query.results.update_all({ updated_at: Time.zone.now }.merge(attributes))
@ -53,7 +59,7 @@ module API
end
get &::API::V3::Utilities::Endpoints::Index
.new(model: Notification, scope: -> { Notification.recipient(current_user) })
.new(model: Notification, scope: -> { notification_scope })
.mount
post :read_ian do
@ -66,7 +72,7 @@ module API
route_param :id, type: Integer, desc: 'Notification ID' do
after_validation do
@notification = Notification.recipient(current_user).find(params[:id])
@notification = notification_scope.find(params[:id])
end
helpers do

@ -5,7 +5,7 @@ FactoryBot.define do
read_mail { false }
read_mail_digest { false }
reason_ian { :mentioned }
reason_mail { :involved}
reason_mail { :involved }
reason_mail_digest { :watched }
recipient factory: :user
project { association :project }

@ -64,6 +64,15 @@ describe ::API::V3::Notifications::NotificationsAPI,
it_behaves_like 'API V3 collection response', 2, 2, 'Notification'
context 'with a digest notification' do
let(:digest_notification) { FactoryBot.create :notification, recipient: recipient, reason_ian: nil }
let(:notifications) { [notification1, notification2, digest_notification] }
it_behaves_like 'API V3 collection response', 2, 2, 'Notification' do
let(:elements) { [notification2, notification1] }
end
end
context 'with a readIAN filter' do
let(:nil_notification) { FactoryBot.create :notification, recipient: recipient, read_ian: nil }

Loading…
Cancel
Save