[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 = { text = {
loading: this.I18n.t('js.ajax.loading'), loading: this.I18n.t('js.ajax.loading'),
placeholder: this.I18n.t('js.placeholders.default'),
}; };
constructor( constructor(
@ -124,7 +125,7 @@ export class InAppNotificationEntryComponent implements OnInit {
private buildTranslatedReason() { private buildTranslatedReason() {
this.translatedReason = this.I18n.t( this.translatedReason = this.I18n.t(
`js.notifications.reasons.${this.notification.reason}`, `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) .call(params)
end end
def notification_scope
::Notification
.recipient(current_user)
.where.not(reason_ian: nil)
end
def bulk_update_status(attributes) def bulk_update_status(attributes)
if notification_query.valid? if notification_query.valid?
notification_query.results.update_all({ updated_at: Time.zone.now }.merge(attributes)) notification_query.results.update_all({ updated_at: Time.zone.now }.merge(attributes))
@ -53,7 +59,7 @@ module API
end end
get &::API::V3::Utilities::Endpoints::Index get &::API::V3::Utilities::Endpoints::Index
.new(model: Notification, scope: -> { Notification.recipient(current_user) }) .new(model: Notification, scope: -> { notification_scope })
.mount .mount
post :read_ian do post :read_ian do
@ -66,7 +72,7 @@ module API
route_param :id, type: Integer, desc: 'Notification ID' do route_param :id, type: Integer, desc: 'Notification ID' do
after_validation do after_validation do
@notification = Notification.recipient(current_user).find(params[:id]) @notification = notification_scope.find(params[:id])
end end
helpers do helpers do

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

@ -64,6 +64,15 @@ describe ::API::V3::Notifications::NotificationsAPI,
it_behaves_like 'API V3 collection response', 2, 2, 'Notification' 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 context 'with a readIAN filter' do
let(:nil_notification) { FactoryBot.create :notification, recipient: recipient, read_ian: nil } let(:nil_notification) { FactoryBot.create :notification, recipient: recipient, read_ian: nil }

Loading…
Cancel
Save