activity_notification 2.3.3 → 2.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/build.yml +8 -41
- data/CHANGELOG.md +31 -0
- data/Gemfile +1 -3
- data/README.md +30 -28
- data/activity_notification.gemspec +5 -5
- data/ai-curated-specs/issues/172/design.md +220 -0
- data/ai-curated-specs/issues/172/tasks.md +326 -0
- data/ai-curated-specs/issues/188/design.md +227 -0
- data/ai-curated-specs/issues/188/requirements.md +78 -0
- data/ai-curated-specs/issues/188/tasks.md +203 -0
- data/ai-curated-specs/issues/188/upstream-contributions.md +592 -0
- data/ai-curated-specs/issues/50/design.md +235 -0
- data/ai-curated-specs/issues/50/requirements.md +49 -0
- data/ai-curated-specs/issues/50/tasks.md +232 -0
- data/app/controllers/activity_notification/notifications_api_controller.rb +22 -0
- data/app/controllers/activity_notification/notifications_controller.rb +27 -1
- data/app/mailers/activity_notification/mailer.rb +2 -2
- data/app/views/activity_notification/notifications/default/_index.html.erb +6 -1
- data/app/views/activity_notification/notifications/default/destroy_all.js.erb +6 -0
- data/docs/Functions.md +5 -11
- data/docs/Setup.md +73 -4
- data/docs/Testing.md +12 -1
- data/gemfiles/Gemfile.rails-7.0 +2 -0
- data/gemfiles/Gemfile.rails-8.0 +0 -2
- data/lib/activity_notification/apis/notification_api.rb +51 -2
- data/lib/activity_notification/controllers/concerns/swagger/notifications_api.rb +59 -0
- data/lib/activity_notification/helpers/view_helpers.rb +28 -0
- data/lib/activity_notification/mailers/helpers.rb +14 -7
- data/lib/activity_notification/models/concerns/swagger/subscription_schema.rb +1 -1
- data/lib/activity_notification/models/concerns/target.rb +16 -0
- data/lib/activity_notification/models.rb +1 -1
- data/lib/activity_notification/notification_resilience.rb +115 -0
- data/lib/activity_notification/orm/dynamoid/extension.rb +4 -87
- data/lib/activity_notification/orm/dynamoid/notification.rb +19 -2
- data/lib/activity_notification/orm/dynamoid.rb +42 -6
- data/lib/activity_notification/rails/routes.rb +1 -0
- data/lib/activity_notification/version.rb +1 -1
- data/lib/activity_notification.rb +1 -0
- data/lib/generators/templates/controllers/notifications_api_controller.rb +5 -0
- data/lib/generators/templates/controllers/notifications_api_with_devise_controller.rb +5 -0
- data/lib/generators/templates/controllers/notifications_controller.rb +5 -0
- data/lib/generators/templates/controllers/notifications_with_devise_controller.rb +5 -0
- data/spec/concerns/apis/notification_api_spec.rb +161 -5
- data/spec/concerns/models/target_spec.rb +7 -0
- data/spec/controllers/controller_spec_utility.rb +2 -2
- data/spec/controllers/notifications_api_controller_shared_examples.rb +113 -0
- data/spec/controllers/notifications_controller_shared_examples.rb +150 -0
- data/spec/generators/migration/migration_generator_spec.rb +18 -4
- data/spec/helpers/view_helpers_spec.rb +14 -0
- data/spec/jobs/notification_resilience_job_spec.rb +167 -0
- data/spec/mailers/notification_resilience_spec.rb +263 -0
- data/spec/models/notification_spec.rb +1 -1
- data/spec/models/subscription_spec.rb +1 -1
- data/spec/rails_app/app/helpers/devise_helper.rb +2 -0
- data/spec/rails_app/config/application.rb +1 -0
- data/spec/rails_app/config/initializers/zeitwerk.rb +10 -0
- metadata +35 -22
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: d670191ff319b7ca33142f0f92cdd3d0332287082d4512515175492431a14b2d
|
|
4
|
+
data.tar.gz: da39c715f28ae37adc1da46ca3b148b7664627f9e0a9bd924200707340599b18
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 82104cb3b70c4530714d56a91bec204bc7ffc5c4a0f93c6646f483b7eff888b5906c20613410df2df423c155eb8a18771538e30b07c59e07d525dda35afbf9a7
|
|
7
|
+
data.tar.gz: c0c9027327dbd0667bced6899cb619a4463bef3ff131c8818d3388ea6e5abeeffa51ce63990f6770210d98d06c504972cc33996593f58f14dce4de4089d95632
|
data/.github/workflows/build.yml
CHANGED
|
@@ -17,11 +17,6 @@ jobs:
|
|
|
17
17
|
fail-fast: false
|
|
18
18
|
matrix:
|
|
19
19
|
gemfile:
|
|
20
|
-
- gemfiles/Gemfile.rails-5.0
|
|
21
|
-
- gemfiles/Gemfile.rails-5.1
|
|
22
|
-
- gemfiles/Gemfile.rails-5.2
|
|
23
|
-
- gemfiles/Gemfile.rails-6.0
|
|
24
|
-
- gemfiles/Gemfile.rails-6.1
|
|
25
20
|
- gemfiles/Gemfile.rails-7.0
|
|
26
21
|
- gemfiles/Gemfile.rails-7.1
|
|
27
22
|
- gemfiles/Gemfile.rails-7.2
|
|
@@ -32,53 +27,26 @@ jobs:
|
|
|
32
27
|
- dynamoid
|
|
33
28
|
include:
|
|
34
29
|
# https://www.ruby-lang.org/en/downloads
|
|
35
|
-
- gemfile: gemfiles/Gemfile.rails-5.0
|
|
36
|
-
ruby-version: 2.7.7
|
|
37
|
-
- gemfile: gemfiles/Gemfile.rails-5.1
|
|
38
|
-
ruby-version: 2.7.7
|
|
39
|
-
- gemfile: gemfiles/Gemfile.rails-5.2
|
|
40
|
-
ruby-version: 2.7.7
|
|
41
|
-
- gemfile: gemfiles/Gemfile.rails-6.0
|
|
42
|
-
ruby-version: 2.7.7
|
|
43
|
-
- gemfile: gemfiles/Gemfile.rails-6.1
|
|
44
|
-
ruby-version: 2.7.7
|
|
45
30
|
- gemfile: gemfiles/Gemfile.rails-7.0
|
|
46
|
-
ruby-version: 3.
|
|
31
|
+
ruby-version: 3.2.9
|
|
47
32
|
- gemfile: gemfiles/Gemfile.rails-7.1
|
|
48
|
-
ruby-version: 3.2.
|
|
33
|
+
ruby-version: 3.2.9
|
|
49
34
|
- gemfile: gemfiles/Gemfile.rails-7.2
|
|
50
|
-
ruby-version: 3.3.
|
|
35
|
+
ruby-version: 3.3.9
|
|
51
36
|
- gemfile: gemfiles/Gemfile.rails-8.0
|
|
52
|
-
ruby-version: 3.
|
|
37
|
+
ruby-version: 3.4.5
|
|
53
38
|
- gemfile: Gemfile
|
|
54
|
-
ruby-version: 3.
|
|
39
|
+
ruby-version: 3.4.5
|
|
55
40
|
orm: active_record
|
|
56
41
|
test-db: mysql
|
|
57
42
|
- gemfile: Gemfile
|
|
58
|
-
ruby-version: 3.
|
|
43
|
+
ruby-version: 3.4.5
|
|
59
44
|
orm: active_record
|
|
60
45
|
test-db: postgresql
|
|
61
46
|
- gemfile: Gemfile
|
|
62
|
-
ruby-version: 3.
|
|
47
|
+
ruby-version: 3.4.5
|
|
63
48
|
orm: mongoid
|
|
64
49
|
test-db: mongodb
|
|
65
|
-
- gemfile: Gemfile
|
|
66
|
-
ruby-version: head
|
|
67
|
-
orm: active_record
|
|
68
|
-
allow_failures: 'true'
|
|
69
|
-
exclude:
|
|
70
|
-
- gemfile: gemfiles/Gemfile.rails-6.0
|
|
71
|
-
orm: dynamoid
|
|
72
|
-
- gemfile: gemfiles/Gemfile.rails-6.1
|
|
73
|
-
orm: dynamoid
|
|
74
|
-
- gemfile: gemfiles/Gemfile.rails-7.0
|
|
75
|
-
orm: dynamoid
|
|
76
|
-
- gemfile: gemfiles/Gemfile.rails-7.1
|
|
77
|
-
orm: dynamoid
|
|
78
|
-
- gemfile: gemfiles/Gemfile.rails-7.2
|
|
79
|
-
orm: dynamoid
|
|
80
|
-
- gemfile: gemfiles/Gemfile.rails-8.0
|
|
81
|
-
orm: dynamoid
|
|
82
50
|
|
|
83
51
|
env:
|
|
84
52
|
RAILS_ENV: test
|
|
@@ -127,7 +95,6 @@ jobs:
|
|
|
127
95
|
bin/install_dynamodblocal.sh
|
|
128
96
|
bin/start_dynamodblocal.sh
|
|
129
97
|
- name: Run tests with RSpec
|
|
130
|
-
run: bundle exec rspec
|
|
131
|
-
continue-on-error: ${{ matrix.allow_failures == 'true' }}
|
|
98
|
+
run: bundle exec rspec --format progress
|
|
132
99
|
- name: Coveralls
|
|
133
100
|
uses: coverallsapp/github-action@v2
|
data/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,34 @@
|
|
|
1
|
+
## 2.4.1 / 2025-12-31
|
|
2
|
+
[Full Changelog](http://github.com/simukappu/activity_notification/compare/v2.4.0...v2.4.1)
|
|
3
|
+
|
|
4
|
+
Enhancements:
|
|
5
|
+
|
|
6
|
+
* Make Mongoid and Dynamoid optional dependencies - [#190](https://github.com/simukappu/activity_notification/issues/190)
|
|
7
|
+
|
|
8
|
+
Bug Fixes:
|
|
9
|
+
|
|
10
|
+
* Fix OpenAPI schema validation errors in Subscription model
|
|
11
|
+
* Fix Dynamoid ORM datetime format issue in optional_targets API response
|
|
12
|
+
* Fix OpenAPI parser deprecation warning by adding strict_reference_validation configuration
|
|
13
|
+
|
|
14
|
+
## 2.4.0 / 2025-08-20
|
|
15
|
+
[Full Changelog](http://github.com/simukappu/activity_notification/compare/v2.3.3...v2.4.0)
|
|
16
|
+
|
|
17
|
+
Enhancements:
|
|
18
|
+
|
|
19
|
+
* Support for Mongoid v9 - [#189](https://github.com/simukappu/activity_notification/issues/189)
|
|
20
|
+
* Support for Dynamoid v3.11.0+ (upgraded from v3.1.0) - [#188](https://github.com/simukappu/activity_notification/issues/188)
|
|
21
|
+
* Add bulk destroy notifications API - [#172](https://github.com/simukappu/activity_notification/issues/172)
|
|
22
|
+
* Add ids parameter to open_all notifications API - [#172](https://github.com/simukappu/activity_notification/issues/172)
|
|
23
|
+
* Add skip_validation option to open! method for notification handling - [#186](https://github.com/simukappu/activity_notification/issues/186) [#187](https://github.com/simukappu/activity_notification/pull/187)
|
|
24
|
+
* Add exception handling to Mailer jobs for missing notification - [#50](https://github.com/simukappu/activity_notification/issues/50)
|
|
25
|
+
|
|
26
|
+
Dependency:
|
|
27
|
+
|
|
28
|
+
* Remove support for Rails 5 and 6
|
|
29
|
+
* Update Mongoid dependency from development to runtime dependency - [#189](https://github.com/simukappu/activity_notification/issues/189)
|
|
30
|
+
* Update Dynamoid dependency from development to runtime dependency - [#188](https://github.com/simukappu/activity_notification/issues/188)
|
|
31
|
+
|
|
1
32
|
## 2.3.3 / 2025-01-13
|
|
2
33
|
[Full Changelog](http://github.com/simukappu/activity_notification/compare/v2.3.2...v2.3.3)
|
|
3
34
|
|
data/Gemfile
CHANGED
|
@@ -9,9 +9,7 @@ group :production do
|
|
|
9
9
|
gem 'puma'
|
|
10
10
|
gem 'pg'
|
|
11
11
|
gem 'devise'
|
|
12
|
-
|
|
13
|
-
gem 'devise_token_auth', git: 'https://github.com/lynndylanhurley/devise_token_auth.git'
|
|
14
|
-
gem 'sqlite3', ">= 2.1"
|
|
12
|
+
gem 'devise_token_auth'
|
|
15
13
|
end
|
|
16
14
|
|
|
17
15
|
group :development do
|
data/README.md
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
|
|
11
11
|
*activity_notification* provides integrated user activity notifications for [Ruby on Rails](https://rubyonrails.org). You can easily use it to configure multiple notification targets and make activity notifications with notifiable models, like adding comments, responding etc.
|
|
12
12
|
|
|
13
|
-
*activity_notification* supports Rails
|
|
13
|
+
*activity_notification* supports Rails 7.0+ with [ActiveRecord](https://guides.rubyonrails.org/active_record_basics.html), [Mongoid](https://mongoid.org) and [Dynamoid](https://github.com/Dynamoid/dynamoid) ORM. It is tested for [MySQL](https://www.mysql.com), [PostgreSQL](https://www.postgresql.org), [SQLite3](https://www.sqlite.org) with ActiveRecord, [MongoDB](https://www.mongodb.com) with Mongoid and [Amazon DynamoDB](https://aws.amazon.com/dynamodb) with Dynamoid v3.11.0+. If you are using Rails 5 or Rails 6, use [v2.3.3](https://rubygems.org/gems/activity_notification/versions/2.3.3) or older version of *activity_notification*.
|
|
14
14
|
|
|
15
15
|
|
|
16
16
|
## About
|
|
@@ -31,22 +31,6 @@
|
|
|
31
31
|
* Activity notifications stream integrated into cloud computing using [Amazon DynamoDB Streams](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Streams.html)
|
|
32
32
|
* Optional notification targets (Configurable optional notification targets like [Amazon SNS](https://aws.amazon.com/sns), [Slack](https://slack.com), SMS and so on)
|
|
33
33
|
|
|
34
|
-
### Online Demo
|
|
35
|
-
|
|
36
|
-
You can see an actual application using this gem here:
|
|
37
|
-
* **https://activity-notification-example.herokuapp.com/**
|
|
38
|
-
|
|
39
|
-
Login as the following test users to experience user activity notifications:
|
|
40
|
-
|
|
41
|
-
| Email | Password | Admin? |
|
|
42
|
-
|:---:|:---:|:---:|
|
|
43
|
-
| ichiro@example.com | changeit | Yes |
|
|
44
|
-
| stephen@example.com | changeit | |
|
|
45
|
-
| klay@example.com | changeit | |
|
|
46
|
-
| kevin@example.com | changeit | |
|
|
47
|
-
|
|
48
|
-
The deployed demo application is included in this gem's source code as a test application here: *[/spec/rails_app](/spec/rails_app/)*
|
|
49
|
-
|
|
50
34
|
### Notification index and plugin notifications
|
|
51
35
|
|
|
52
36
|
<kbd></kbd>
|
|
@@ -70,16 +54,12 @@ The deployed demo application is included in this gem's source code as a test ap
|
|
|
70
54
|
REST API reference as OpenAPI Specification is published in SwaggerHub here:
|
|
71
55
|
* **https://app.swaggerhub.com/apis-docs/simukappu/activity-notification/**
|
|
72
56
|
|
|
73
|
-
You can see sample single page application using [Vue.js](https://vuejs.org) as a part of example Rails application
|
|
74
|
-
* **https://activity-notification-example.herokuapp.com/spa/**
|
|
75
|
-
|
|
76
|
-
This sample application works with *activity_notification* REST API backend.
|
|
57
|
+
You can see sample single page application using [Vue.js](https://vuejs.org) as a part of example Rails application in *[/spec/rails_app](/spec/rails_app/)*. This sample application works with *activity_notification* REST API backend.
|
|
77
58
|
|
|
78
59
|
|
|
79
60
|
## Table of Contents
|
|
80
61
|
|
|
81
62
|
- [About](#about)
|
|
82
|
-
- [Online Demo](#online-demo)
|
|
83
63
|
- [Public REST API reference as OpenAPI Specification](#public-rest-apu-reference-as-openapi-specification)
|
|
84
64
|
- [Getting Started](#getting-started)
|
|
85
65
|
- [Setup](/docs/Setup.md#Setup)
|
|
@@ -106,6 +86,8 @@ This sample application works with *activity_notification* REST API backend.
|
|
|
106
86
|
- [Rendering notifications](/docs/Setup.md#rendering-notifications)
|
|
107
87
|
- [Notification views](/docs/Setup.md#notification-views)
|
|
108
88
|
- [i18n for notifications](/docs/Setup.md#i18n-for-notifications)
|
|
89
|
+
- [Managing notifications](/docs/Setup.md#managing-notifications)
|
|
90
|
+
- [Managing notifications](/docs/Setup.md#managing-notifications)
|
|
109
91
|
- [Customizing controllers (optional)](/docs/Setup.md#customizing-controllers-optional)
|
|
110
92
|
- [Functions](/docs/Functions.md#Functions)
|
|
111
93
|
- [Email notification](/docs/Functions.md#email-notification)
|
|
@@ -153,6 +135,7 @@ This sample application works with *activity_notification* REST API backend.
|
|
|
153
135
|
- [Testing gem alone](/docs/Testing.md#testing-gem-alone)
|
|
154
136
|
- [Documentation](#documentation)
|
|
155
137
|
- [Common Examples](#common-examples)
|
|
138
|
+
- [Example Rails application](/docs/Testing.md#example-rails-application)
|
|
156
139
|
- [Contributing](#contributing)
|
|
157
140
|
- [License](#license)
|
|
158
141
|
|
|
@@ -182,6 +165,24 @@ $ bin/rails generate activity_notification:install
|
|
|
182
165
|
|
|
183
166
|
The generator will install an initializer which describes all configuration options of *activity_notification*.
|
|
184
167
|
|
|
168
|
+
#### ORM Dependencies
|
|
169
|
+
|
|
170
|
+
By default, *activity_notification* uses **ActiveRecord** as the ORM and no additional ORM gems are required.
|
|
171
|
+
|
|
172
|
+
If you intend to use **Mongoid** support, you need to add the `mongoid` gem separately to your Gemfile:
|
|
173
|
+
|
|
174
|
+
```ruby
|
|
175
|
+
gem 'activity_notification'
|
|
176
|
+
gem 'mongoid', '>= 4.0.0', '< 10.0'
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
If you intend to use **Dynamoid** support for Amazon DynamoDB, you need to add the `dynamoid` gem separately to your Gemfile:
|
|
180
|
+
|
|
181
|
+
```ruby
|
|
182
|
+
gem 'activity_notification'
|
|
183
|
+
gem 'dynamoid', '>= 3.11.0', '< 4.0'
|
|
184
|
+
```
|
|
185
|
+
|
|
185
186
|
### Database setup
|
|
186
187
|
|
|
187
188
|
When you use *activity_notification* with ActiveRecord ORM as default configuration,
|
|
@@ -284,6 +285,12 @@ See [Creating notifications](/docs/Setup.md#creating-notifications) for more det
|
|
|
284
285
|
|
|
285
286
|
See [Displaying notifications](/docs/Setup.md#displaying-notifications) for more details.
|
|
286
287
|
|
|
288
|
+
### Managing notifications
|
|
289
|
+
|
|
290
|
+
*activity_notification* provides APIs to manage notifications programmatically. You can mark notifications as opened (read), filter them, and perform bulk operations.
|
|
291
|
+
|
|
292
|
+
See [Managing notifications](/docs/Setup.md#managing-notifications) for more details.
|
|
293
|
+
|
|
287
294
|
### Run example Rails application
|
|
288
295
|
|
|
289
296
|
Test module includes example Rails application in *[spec/rails_app](/spec/rails_app)*.
|
|
@@ -334,12 +341,7 @@ Then you can see the documents at <http://localhost:8808/docs/index>.
|
|
|
334
341
|
|
|
335
342
|
## Common Examples
|
|
336
343
|
|
|
337
|
-
See example Rails application in *[/spec/rails_app](/spec/rails_app)*.
|
|
338
|
-
|
|
339
|
-
You can also try this example Rails application as Online Demo here:
|
|
340
|
-
* **https://activity-notification-example.herokuapp.com/**
|
|
341
|
-
|
|
342
|
-
You can login as test users to experience user activity notifications. For more details, see [Online Demo](#online-demo).
|
|
344
|
+
See example Rails application in *[/spec/rails_app](/spec/rails_app)*. You can login as test users to experience user activity notifications. For more details, see [Example Rails application](/docs/Testing.md#example-rails-application).
|
|
343
345
|
|
|
344
346
|
|
|
345
347
|
## Contributing
|
|
@@ -20,19 +20,19 @@ Gem::Specification.new do |s|
|
|
|
20
20
|
s.require_paths = ["lib"]
|
|
21
21
|
s.required_ruby_version = '>= 2.1.0'
|
|
22
22
|
|
|
23
|
-
s.add_dependency 'railties', '>=
|
|
23
|
+
s.add_dependency 'railties', '>= 7.0.0', '< 8.1'
|
|
24
24
|
s.add_dependency 'i18n', '>= 0.5.0'
|
|
25
25
|
s.add_dependency 'jquery-rails', '>= 3.1.1'
|
|
26
26
|
s.add_dependency 'swagger-blocks', '>= 3.0.0'
|
|
27
27
|
|
|
28
28
|
s.add_development_dependency 'puma', '>= 3.12.0'
|
|
29
|
-
s.add_development_dependency 'sqlite3', '>= 1.3.13'
|
|
29
|
+
s.add_development_dependency 'sqlite3', '>= 1.3.13'
|
|
30
30
|
s.add_development_dependency 'mysql2', '>= 0.5.2'
|
|
31
31
|
s.add_development_dependency 'pg', '>= 1.0.0'
|
|
32
|
-
s.add_development_dependency 'mongoid', '>= 4.0.0', '<
|
|
33
|
-
s.add_development_dependency 'dynamoid', '3.
|
|
32
|
+
s.add_development_dependency 'mongoid', '>= 4.0.0', '< 10.0'
|
|
33
|
+
s.add_development_dependency 'dynamoid', '>= 3.11.0', '< 4.0'
|
|
34
34
|
s.add_development_dependency 'rspec-rails', '>= 3.8.0'
|
|
35
|
-
s.add_development_dependency 'factory_bot_rails', '>= 4.11.0'
|
|
35
|
+
s.add_development_dependency 'factory_bot_rails', '>= 4.11.0'
|
|
36
36
|
s.add_development_dependency 'simplecov', '~> 0'
|
|
37
37
|
s.add_development_dependency 'yard', '>= 0.9.16'
|
|
38
38
|
s.add_development_dependency 'yard-activesupport-concern', '>= 0.0.1'
|
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
# Design Document: Bulk destroy notifications API
|
|
2
|
+
|
|
3
|
+
## Issue Summary
|
|
4
|
+
GitHub Issue [#172](https://github.com/simukappu/activity_notification/issues/172) requests the ability to delete more than one notification for a target. Currently, only single notification deletion is available through the `destroy` API. The user wants a `bulk_destroy` API or provision to create custom APIs for bulk destroying notifications.
|
|
5
|
+
|
|
6
|
+
## Current State Analysis
|
|
7
|
+
|
|
8
|
+
### Existing Destroy Functionality
|
|
9
|
+
- **Single Destroy**: `DELETE /:target_type/:target_id/notifications/:id`
|
|
10
|
+
- Implemented in `NotificationsController#destroy`
|
|
11
|
+
- API version in `NotificationsApiController#destroy`
|
|
12
|
+
- Simply calls `@notification.destroy` on individual notification
|
|
13
|
+
|
|
14
|
+
### Existing Bulk Operations Pattern
|
|
15
|
+
- **Bulk Open**: `POST /:target_type/:target_id/notifications/open_all`
|
|
16
|
+
- Implemented in `NotificationsController#open_all`
|
|
17
|
+
- Uses `@target.open_all_notifications(params)`
|
|
18
|
+
- Backend implementation in `NotificationApi#open_all_of`
|
|
19
|
+
- Uses `update_all(opened_at: opened_at)` for efficient bulk updates
|
|
20
|
+
|
|
21
|
+
## Proposed Implementation
|
|
22
|
+
|
|
23
|
+
### 1. Backend API Method (NotificationApi)
|
|
24
|
+
**File**: `lib/activity_notification/apis/notification_api.rb`
|
|
25
|
+
|
|
26
|
+
Add a new class method `destroy_all_of` following the pattern of `open_all_of`:
|
|
27
|
+
|
|
28
|
+
```ruby
|
|
29
|
+
# Destroys all notifications of the target matching the filter criteria.
|
|
30
|
+
#
|
|
31
|
+
# @param [Object] target Target of the notifications to destroy
|
|
32
|
+
# @param [Hash] options Options for filtering notifications to destroy
|
|
33
|
+
# @option options [String] :filtered_by_type (nil) Notifiable type for filter
|
|
34
|
+
# @option options [Object] :filtered_by_group (nil) Group instance for filter
|
|
35
|
+
# @option options [String] :filtered_by_group_type (nil) Group type for filter, valid with :filtered_by_group_id
|
|
36
|
+
# @option options [String] :filtered_by_group_id (nil) Group instance id for filter, valid with :filtered_by_group_type
|
|
37
|
+
# @option options [String] :filtered_by_key (nil) Key of the notification for filter
|
|
38
|
+
# @option options [String] :later_than (nil) ISO 8601 format time to filter notifications later than specified time
|
|
39
|
+
# @option options [String] :earlier_than (nil) ISO 8601 format time to filter notifications earlier than specified time
|
|
40
|
+
# @option options [Array] :ids (nil) Array of specific notification IDs to destroy
|
|
41
|
+
# @return [Array<Notification>] Destroyed notification records
|
|
42
|
+
def destroy_all_of(target, options = {})
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
### 2. Target Model Method
|
|
46
|
+
**File**: `lib/activity_notification/models/concerns/target.rb`
|
|
47
|
+
|
|
48
|
+
Add instance method `destroy_all_notifications` following the pattern of `open_all_notifications`:
|
|
49
|
+
|
|
50
|
+
```ruby
|
|
51
|
+
# Destroys all notifications of the target matching the filter criteria.
|
|
52
|
+
#
|
|
53
|
+
# @param [Hash] options Options for filtering notifications to destroy
|
|
54
|
+
# @option options [String] :filtered_by_type (nil) Notifiable type for filter
|
|
55
|
+
# @option options [Object] :filtered_by_group (nil) Group instance for filter
|
|
56
|
+
# @option options [String] :filtered_by_group_type (nil) Group type for filter, valid with :filtered_by_group_id
|
|
57
|
+
# @option options [String] :filtered_by_group_id (nil) Group instance id for filter, valid with :filtered_by_group_type
|
|
58
|
+
# @option options [String] :filtered_by_key (nil) Key of the notification for filter
|
|
59
|
+
# @option options [String] :later_than (nil) ISO 8601 format time to filter notifications later than specified time
|
|
60
|
+
# @option options [String] :earlier_than (nil) ISO 8601 format time to filter notifications earlier than specified time
|
|
61
|
+
# @option options [Array] :ids (nil) Array of specific notification IDs to destroy
|
|
62
|
+
# @return [Array<Notification>] Destroyed notification records
|
|
63
|
+
def destroy_all_notifications(options = {})
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
### 3. Controller Actions
|
|
67
|
+
|
|
68
|
+
#### Web Controller
|
|
69
|
+
**File**: `app/controllers/activity_notification/notifications_controller.rb`
|
|
70
|
+
|
|
71
|
+
Add new action `destroy_all`:
|
|
72
|
+
|
|
73
|
+
```ruby
|
|
74
|
+
# Destroys all notifications of the target matching filter criteria.
|
|
75
|
+
#
|
|
76
|
+
# POST /:target_type/:target_id/notifications/destroy_all
|
|
77
|
+
# @overload destroy_all(params)
|
|
78
|
+
# @param [Hash] params Request parameters
|
|
79
|
+
# @option params [String] :filter (nil) Filter option to load notification index by their status (Nothing as auto, 'opened' or 'unopened')
|
|
80
|
+
# @option params [String] :limit (nil) Maximum number of notifications to return
|
|
81
|
+
# @option params [String] :without_grouping ('false') Whether notification index will include group members
|
|
82
|
+
# @option params [String] :with_group_members ('false') Whether notification index will include group members
|
|
83
|
+
# @option params [String] :filtered_by_type (nil) Notifiable type to filter notifications
|
|
84
|
+
# @option params [String] :filtered_by_group_type (nil) Group type to filter notifications, valid with :filtered_by_group_id
|
|
85
|
+
# @option params [String] :filtered_by_group_id (nil) Group instance ID to filter notifications, valid with :filtered_by_group_type
|
|
86
|
+
# @option params [String] :filtered_by_key (nil) Key of notifications to filter
|
|
87
|
+
# @option params [String] :later_than (nil) ISO 8601 format time to filter notifications later than specified time
|
|
88
|
+
# @option params [String] :earlier_than (nil) ISO 8601 format time to filter notifications earlier than specified time
|
|
89
|
+
# @option params [Array] :ids (nil) Array of specific notification IDs to destroy
|
|
90
|
+
# @option params [String] :reload ('true') Whether notification index will be reloaded
|
|
91
|
+
# @return [Response] JavaScript view for ajax request or redirects to back as default
|
|
92
|
+
def destroy_all
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
#### API Controller
|
|
96
|
+
**File**: `app/controllers/activity_notification/notifications_api_controller.rb`
|
|
97
|
+
|
|
98
|
+
Add new action `destroy_all`:
|
|
99
|
+
|
|
100
|
+
```ruby
|
|
101
|
+
# Destroys all notifications of the target matching filter criteria.
|
|
102
|
+
#
|
|
103
|
+
# POST /:target_type/:target_id/notifications/destroy_all
|
|
104
|
+
# @overload destroy_all(params)
|
|
105
|
+
# @param [Hash] params Request parameters
|
|
106
|
+
# @option params [String] :filtered_by_type (nil) Notifiable type to filter notifications
|
|
107
|
+
# @option params [String] :filtered_by_group_type (nil) Group type to filter notifications, valid with :filtered_by_group_id
|
|
108
|
+
# @option params [String] :filtered_by_group_id (nil) Group instance ID to filter notifications, valid with :filtered_by_group_type
|
|
109
|
+
# @option params [String] :filtered_by_key (nil) Key of notifications to filter
|
|
110
|
+
# @option params [String] :later_than (nil) ISO 8601 format time to filter notifications later than specified time
|
|
111
|
+
# @option params [String] :earlier_than (nil) ISO 8601 format time to filter notifications earlier than specified time
|
|
112
|
+
# @option params [Array] :ids (nil) Array of specific notification IDs to destroy
|
|
113
|
+
# @return [JSON] count: number of destroyed notification records, notifications: destroyed notifications
|
|
114
|
+
def destroy_all
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
### 4. Routes Configuration
|
|
118
|
+
**File**: Routes will be automatically generated by the existing `notify_to` helper
|
|
119
|
+
|
|
120
|
+
The route will be: `POST /:target_type/:target_id/notifications/destroy_all`
|
|
121
|
+
|
|
122
|
+
### 5. View Templates
|
|
123
|
+
**Files**:
|
|
124
|
+
- `app/views/activity_notification/notifications/default/destroy_all.js.erb`
|
|
125
|
+
- Template generators will need to be updated to include the new view
|
|
126
|
+
|
|
127
|
+
### 6. Swagger API Documentation
|
|
128
|
+
**File**: Update Swagger documentation to include the new bulk destroy endpoint
|
|
129
|
+
|
|
130
|
+
### 7. Generator Templates
|
|
131
|
+
**Files**: Update controller generator templates to include the new `destroy_all` action:
|
|
132
|
+
- `lib/generators/templates/controllers/notifications_api_controller.rb`
|
|
133
|
+
- `lib/generators/templates/controllers/notifications_controller.rb`
|
|
134
|
+
- `lib/generators/templates/controllers/notifications_with_devise_controller.rb`
|
|
135
|
+
|
|
136
|
+
## Implementation Details
|
|
137
|
+
|
|
138
|
+
### Filter Options Support
|
|
139
|
+
The bulk destroy API will support the same filtering options as the existing `open_all` functionality:
|
|
140
|
+
- `filtered_by_type`: Filter by notifiable type
|
|
141
|
+
- `filtered_by_group_type` + `filtered_by_group_id`: Filter by group
|
|
142
|
+
- `filtered_by_key`: Filter by notification key
|
|
143
|
+
- `later_than` / `earlier_than`: Filter by time range
|
|
144
|
+
- `ids`: Array of specific notification IDs (new option for precise control)
|
|
145
|
+
|
|
146
|
+
### Safety Considerations
|
|
147
|
+
1. **Validation**: Ensure all notifications belong to the specified target
|
|
148
|
+
2. **Permissions**: Leverage existing authentication/authorization patterns
|
|
149
|
+
3. **Soft Delete**: Consider if soft delete should be supported (follow existing destroy pattern)
|
|
150
|
+
4. **Callbacks**: Ensure any existing destroy callbacks are properly triggered
|
|
151
|
+
|
|
152
|
+
### Performance Considerations
|
|
153
|
+
1. **Batch Operations**: Use `destroy_all` for efficient database operations
|
|
154
|
+
2. **Memory Usage**: For large datasets, consider pagination or streaming
|
|
155
|
+
3. **Callbacks**: Balance between performance and callback execution
|
|
156
|
+
|
|
157
|
+
### Error Handling
|
|
158
|
+
1. **Partial Failures**: Handle cases where some notifications can't be destroyed
|
|
159
|
+
2. **Validation Errors**: Provide meaningful error messages
|
|
160
|
+
3. **Authorization Errors**: Consistent with existing error handling patterns
|
|
161
|
+
|
|
162
|
+
## Testing Requirements
|
|
163
|
+
|
|
164
|
+
### Unit Tests
|
|
165
|
+
- Test `NotificationApi#destroy_all_of` method
|
|
166
|
+
- Test `Target#destroy_all_notifications` method
|
|
167
|
+
- Test controller actions for both web and API versions
|
|
168
|
+
|
|
169
|
+
### Integration Tests
|
|
170
|
+
- Test complete request/response cycle
|
|
171
|
+
- Test with various filter combinations
|
|
172
|
+
- Test error scenarios
|
|
173
|
+
|
|
174
|
+
### Performance Tests
|
|
175
|
+
- Test with large datasets
|
|
176
|
+
- Verify efficient database queries
|
|
177
|
+
|
|
178
|
+
## Migration Considerations
|
|
179
|
+
- No database schema changes required
|
|
180
|
+
- Backward compatible addition
|
|
181
|
+
- Follows existing patterns and conventions
|
|
182
|
+
|
|
183
|
+
## Documentation Updates
|
|
184
|
+
- Update README.md with new bulk destroy functionality
|
|
185
|
+
- Update API documentation
|
|
186
|
+
- Update controller documentation
|
|
187
|
+
- Add examples to documentation
|
|
188
|
+
|
|
189
|
+
## Alternative Implementation Options
|
|
190
|
+
|
|
191
|
+
### Option 1: Single Endpoint with Multiple IDs
|
|
192
|
+
Instead of filter-based bulk destroy, accept an array of notification IDs:
|
|
193
|
+
```
|
|
194
|
+
POST /:target_type/:target_id/notifications/destroy_all
|
|
195
|
+
Body: { "ids": [1, 2, 3, 4, 5] }
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
### Option 2: RESTful Bulk Operations
|
|
199
|
+
Follow RESTful conventions with a bulk operations endpoint:
|
|
200
|
+
```
|
|
201
|
+
POST /:target_type/:target_id/notifications/bulk
|
|
202
|
+
Body: { "action": "destroy", "filters": {...} }
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
### Option 3: Query Parameter Approach
|
|
206
|
+
Use existing destroy endpoint with query parameters:
|
|
207
|
+
```
|
|
208
|
+
DELETE /:target_type/:target_id/notifications?ids[]=1&ids[]=2&ids[]=3
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
## Recommended Approach
|
|
212
|
+
The proposed implementation follows the existing pattern established by `open_all` functionality, making it consistent with the current codebase architecture. This approach provides:
|
|
213
|
+
|
|
214
|
+
1. **Consistency**: Matches existing bulk operation patterns
|
|
215
|
+
2. **Flexibility**: Supports various filtering options
|
|
216
|
+
3. **Safety**: Leverages existing validation and authorization
|
|
217
|
+
4. **Performance**: Uses efficient bulk database operations
|
|
218
|
+
5. **Maintainability**: Follows established code organization
|
|
219
|
+
|
|
220
|
+
The implementation should prioritize the filter-based approach (similar to `open_all`) while also supporting the `ids` parameter for precise control when needed.
|