rails-image-post-solution 0.1.0 → 0.1.2
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/README.md +168 -6
- data/config/routes.rb +22 -0
- data/lib/generators/rails_image_post_solution/install/README +1 -1
- data/lib/rails_image_post_solution/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 2120b2a444d646648b7e9fe57165b4a89f2bffd99b9e6ca2e4aeb19f924dd626
|
|
4
|
+
data.tar.gz: fadbb2a26397c2f4172630cbb24ef71f63dc05fd56463097856d0c0516c797bb
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 5472105bd1e6764ff1f977b4f46900f1f7560531a0c30ee05b94b59a645ee8ca103a9d3fcc966328203295796f9cf8fae4a4c41d49034ad9ad65cfe1086bde76
|
|
7
|
+
data.tar.gz: 57655c478d8a9a30e4c4f7e3e1158cc62c58eda115725c53810b043ced3599da95c28373c8804e650f1235d99b73deace7a2e16db25ed5cbc942821722117b07
|
data/README.md
CHANGED
|
@@ -4,6 +4,7 @@ A comprehensive Rails engine for image reporting, AI-powered moderation using Op
|
|
|
4
4
|
|
|
5
5
|
## Features
|
|
6
6
|
|
|
7
|
+
### Core Features
|
|
7
8
|
- **Image Reporting System**: Allow users to report inappropriate images
|
|
8
9
|
- **AI-Powered Moderation**: Automatic content moderation using OpenAI Vision API
|
|
9
10
|
- Detects R18 (adult content)
|
|
@@ -14,10 +15,15 @@ A comprehensive Rails engine for image reporting, AI-powered moderation using Op
|
|
|
14
15
|
- **i18n Support**: Japanese and English locales included
|
|
15
16
|
- **Highly Configurable**: Customize behavior to fit your application
|
|
16
17
|
|
|
18
|
+
### Extended Admin Features (Optional)
|
|
19
|
+
- **User Management**: Suspend, ban, and manage users
|
|
20
|
+
- **Frozen Posts Management**: Review, unfreeze, or permanently freeze flagged content
|
|
21
|
+
- **Enhanced Reporting**: Extended admin views with detailed statistics
|
|
22
|
+
|
|
17
23
|
## Requirements
|
|
18
24
|
|
|
19
|
-
- Ruby >= 3.
|
|
20
|
-
- Rails >=
|
|
25
|
+
- Ruby >= 3.4.7
|
|
26
|
+
- Rails >= 8.1
|
|
21
27
|
- Active Storage
|
|
22
28
|
- OpenAI API key (for AI moderation features)
|
|
23
29
|
|
|
@@ -56,7 +62,39 @@ Mount the engine in your `config/routes.rb`:
|
|
|
56
62
|
|
|
57
63
|
```ruby
|
|
58
64
|
Rails.application.routes.draw do
|
|
65
|
+
# Mount the engine (admin routes will be at /moderation/admin/image_reports)
|
|
59
66
|
mount RailsImagePostSolution::Engine => "/moderation"
|
|
67
|
+
|
|
68
|
+
# Optional: Add direct admin routes (accessible at /admin/*)
|
|
69
|
+
namespace :admin do
|
|
70
|
+
resources :image_reports, only: %i[index show], controller: 'admin/image_reports' do
|
|
71
|
+
member do
|
|
72
|
+
patch :confirm
|
|
73
|
+
patch :dismiss
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
resources :users, only: %i[index show], controller: 'admin/users' do
|
|
78
|
+
member do
|
|
79
|
+
post :suspend
|
|
80
|
+
post :unsuspend
|
|
81
|
+
post :ban
|
|
82
|
+
post :unban
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
resources :frozen_posts, only: [:index], controller: 'admin/frozen_posts' do
|
|
87
|
+
collection do
|
|
88
|
+
post "unfreeze_stage/:id", to: "admin/frozen_posts#unfreeze_stage", as: :unfreeze_stage
|
|
89
|
+
post "unfreeze_comment/:id", to: "admin/frozen_posts#unfreeze_comment", as: :unfreeze_comment
|
|
90
|
+
post "permanent_freeze_stage/:id", to: "admin/frozen_posts#permanent_freeze_stage", as: :permanent_freeze_stage
|
|
91
|
+
post "permanent_freeze_comment/:id", to: "admin/frozen_posts#permanent_freeze_comment", as: :permanent_freeze_comment
|
|
92
|
+
delete "destroy_stage/:id", to: "admin/frozen_posts#destroy_stage", as: :destroy_stage
|
|
93
|
+
delete "destroy_comment/:id", to: "admin/frozen_posts#destroy_comment", as: :destroy_comment
|
|
94
|
+
end
|
|
95
|
+
end
|
|
96
|
+
end
|
|
97
|
+
|
|
60
98
|
# ... your other routes
|
|
61
99
|
end
|
|
62
100
|
```
|
|
@@ -90,7 +128,15 @@ export OPENAI_API_KEY=sk-...
|
|
|
90
128
|
|
|
91
129
|
### User Reporting
|
|
92
130
|
|
|
93
|
-
|
|
131
|
+
The gem provides shared view partials for easy integration:
|
|
132
|
+
|
|
133
|
+
```erb
|
|
134
|
+
<%# In your view %>
|
|
135
|
+
<%= render 'shared/image_report_button', image: @attachment %>
|
|
136
|
+
<%= render 'shared/image_report_modal' %>
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
Or manually via POST request:
|
|
94
140
|
|
|
95
141
|
```ruby
|
|
96
142
|
# In your view
|
|
@@ -113,6 +159,12 @@ fetch('/moderation/image_reports', {
|
|
|
113
159
|
});
|
|
114
160
|
```
|
|
115
161
|
|
|
162
|
+
The provided partials include:
|
|
163
|
+
- `_image_report_button.html.erb` - Report button with status display
|
|
164
|
+
- `_image_report_modal.html.erb` - Modal dialog for submitting reports with category selection
|
|
165
|
+
|
|
166
|
+
**Note**: The partials reference Stimulus controllers (`image-report`). You'll need to implement the corresponding Stimulus controller in your application or use the manual POST method above.
|
|
167
|
+
|
|
116
168
|
### Admin Dashboard
|
|
117
169
|
|
|
118
170
|
Admins can access the dashboard at:
|
|
@@ -144,17 +196,43 @@ To enable automatic post freezing, add a `freeze_post!` method to your models th
|
|
|
144
196
|
class Post < ApplicationRecord
|
|
145
197
|
has_many_attached :images
|
|
146
198
|
|
|
199
|
+
# Scopes for frozen posts management
|
|
200
|
+
scope :frozen, -> { where.not(frozen_at: nil) }
|
|
201
|
+
scope :temporarily_frozen, -> { frozen.where(frozen_type: "temporary") }
|
|
202
|
+
scope :permanently_frozen, -> { frozen.where(frozen_type: "permanent") }
|
|
203
|
+
scope :recent, -> { order(created_at: :desc) }
|
|
204
|
+
|
|
147
205
|
def freeze_post!(type:, reason:)
|
|
148
206
|
update!(
|
|
149
|
-
frozen: true,
|
|
150
207
|
frozen_type: type,
|
|
151
208
|
frozen_reason: reason,
|
|
152
209
|
frozen_at: Time.current
|
|
153
210
|
)
|
|
154
211
|
end
|
|
155
212
|
|
|
213
|
+
def unfreeze!
|
|
214
|
+
update!(
|
|
215
|
+
frozen_type: nil,
|
|
216
|
+
frozen_reason: nil,
|
|
217
|
+
frozen_at: nil
|
|
218
|
+
)
|
|
219
|
+
end
|
|
220
|
+
|
|
156
221
|
def frozen?
|
|
157
|
-
|
|
222
|
+
frozen_at.present?
|
|
223
|
+
end
|
|
224
|
+
end
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
Add the required columns to your model:
|
|
228
|
+
|
|
229
|
+
```ruby
|
|
230
|
+
class AddFrozenFieldsToPosts < ActiveRecord::Migration[8.1]
|
|
231
|
+
def change
|
|
232
|
+
add_column :posts, :frozen_type, :string
|
|
233
|
+
add_column :posts, :frozen_reason, :text
|
|
234
|
+
add_column :posts, :frozen_at, :datetime
|
|
235
|
+
add_index :posts, :frozen_at
|
|
158
236
|
end
|
|
159
237
|
end
|
|
160
238
|
```
|
|
@@ -183,9 +261,74 @@ class User < ApplicationRecord
|
|
|
183
261
|
end
|
|
184
262
|
```
|
|
185
263
|
|
|
264
|
+
### Additional User Model Methods (for Extended Features)
|
|
265
|
+
|
|
266
|
+
If you plan to use the extended admin features (user management, frozen posts), add these methods to your User model:
|
|
267
|
+
|
|
268
|
+
```ruby
|
|
269
|
+
class User < ApplicationRecord
|
|
270
|
+
# Status check methods
|
|
271
|
+
def active?
|
|
272
|
+
!suspended? && !banned?
|
|
273
|
+
end
|
|
274
|
+
|
|
275
|
+
def suspended?
|
|
276
|
+
suspended_until.present? && suspended_until > Time.current
|
|
277
|
+
end
|
|
278
|
+
|
|
279
|
+
def banned?
|
|
280
|
+
banned_at.present?
|
|
281
|
+
end
|
|
282
|
+
|
|
283
|
+
# User management methods
|
|
284
|
+
def suspend!(reason:, duration: 7.days)
|
|
285
|
+
update!(
|
|
286
|
+
suspended_until: Time.current + duration,
|
|
287
|
+
suspension_reason: reason
|
|
288
|
+
)
|
|
289
|
+
end
|
|
290
|
+
|
|
291
|
+
def unsuspend!
|
|
292
|
+
update!(
|
|
293
|
+
suspended_until: nil,
|
|
294
|
+
suspension_reason: nil
|
|
295
|
+
)
|
|
296
|
+
end
|
|
297
|
+
|
|
298
|
+
def ban!(reason:)
|
|
299
|
+
update!(
|
|
300
|
+
banned_at: Time.current,
|
|
301
|
+
ban_reason: reason
|
|
302
|
+
)
|
|
303
|
+
end
|
|
304
|
+
|
|
305
|
+
def unban!
|
|
306
|
+
update!(
|
|
307
|
+
banned_at: nil,
|
|
308
|
+
ban_reason: nil
|
|
309
|
+
)
|
|
310
|
+
end
|
|
311
|
+
end
|
|
312
|
+
```
|
|
313
|
+
|
|
314
|
+
And add the corresponding database columns:
|
|
315
|
+
|
|
316
|
+
```ruby
|
|
317
|
+
class AddModerationFieldsToUsers < ActiveRecord::Migration[8.1]
|
|
318
|
+
def change
|
|
319
|
+
add_column :users, :suspended_until, :datetime
|
|
320
|
+
add_column :users, :suspension_reason, :text
|
|
321
|
+
add_column :users, :banned_at, :datetime
|
|
322
|
+
add_column :users, :ban_reason, :text
|
|
323
|
+
end
|
|
324
|
+
end
|
|
325
|
+
```
|
|
326
|
+
|
|
186
327
|
## Routes
|
|
187
328
|
|
|
188
|
-
|
|
329
|
+
### Engine Routes (via /moderation mount point)
|
|
330
|
+
|
|
331
|
+
When you mount the engine at `/moderation`, these routes are available:
|
|
189
332
|
|
|
190
333
|
```
|
|
191
334
|
POST /moderation/image_reports # Create report
|
|
@@ -193,6 +336,25 @@ GET /moderation/admin/image_reports # List all reports
|
|
|
193
336
|
GET /moderation/admin/image_reports/:id # View report details
|
|
194
337
|
PATCH /moderation/admin/image_reports/:id/confirm # Mark as inappropriate
|
|
195
338
|
PATCH /moderation/admin/image_reports/:id/dismiss # Mark as safe
|
|
339
|
+
GET /moderation/admin/users # List all users
|
|
340
|
+
GET /moderation/admin/users/:id # View user details
|
|
341
|
+
POST /moderation/admin/users/:id/suspend # Suspend user
|
|
342
|
+
POST /moderation/admin/users/:id/unsuspend # Unsuspend user
|
|
343
|
+
POST /moderation/admin/users/:id/ban # Ban user
|
|
344
|
+
POST /moderation/admin/users/:id/unban # Unban user
|
|
345
|
+
GET /moderation/admin/frozen_posts # List frozen posts
|
|
346
|
+
```
|
|
347
|
+
|
|
348
|
+
### Optional: Direct Admin Routes (via host application routes)
|
|
349
|
+
|
|
350
|
+
If you want admin routes accessible at `/admin/*` instead of `/moderation/admin/*`, add the routes shown in the Installation section to your host application's `config/routes.rb`. This allows you to access:
|
|
351
|
+
|
|
352
|
+
```
|
|
353
|
+
GET /admin/image_reports # List all reports
|
|
354
|
+
GET /admin/image_reports/:id # View report details
|
|
355
|
+
GET /admin/users # List all users
|
|
356
|
+
GET /admin/users/:id # View user details
|
|
357
|
+
GET /admin/frozen_posts # List frozen posts
|
|
196
358
|
```
|
|
197
359
|
|
|
198
360
|
## Customization
|
data/config/routes.rb
CHANGED
|
@@ -12,5 +12,27 @@ RailsImagePostSolution::Engine.routes.draw do
|
|
|
12
12
|
patch :dismiss
|
|
13
13
|
end
|
|
14
14
|
end
|
|
15
|
+
|
|
16
|
+
# User management
|
|
17
|
+
resources :users, only: %i[index show] do
|
|
18
|
+
member do
|
|
19
|
+
post :suspend
|
|
20
|
+
post :unsuspend
|
|
21
|
+
post :ban
|
|
22
|
+
post :unban
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
# Frozen posts management
|
|
27
|
+
resources :frozen_posts, only: [:index] do
|
|
28
|
+
collection do
|
|
29
|
+
post "unfreeze_stage/:id", to: "frozen_posts#unfreeze_stage", as: :unfreeze_stage
|
|
30
|
+
post "unfreeze_comment/:id", to: "frozen_posts#unfreeze_comment", as: :unfreeze_comment
|
|
31
|
+
post "permanent_freeze_stage/:id", to: "frozen_posts#permanent_freeze_stage", as: :permanent_freeze_stage
|
|
32
|
+
post "permanent_freeze_comment/:id", to: "frozen_posts#permanent_freeze_comment", as: :permanent_freeze_comment
|
|
33
|
+
delete "destroy_stage/:id", to: "frozen_posts#destroy_stage", as: :destroy_stage
|
|
34
|
+
delete "destroy_comment/:id", to: "frozen_posts#destroy_comment", as: :destroy_comment
|
|
35
|
+
end
|
|
36
|
+
end
|
|
15
37
|
end
|
|
16
38
|
end
|
|
@@ -22,6 +22,6 @@ Next steps:
|
|
|
22
22
|
# Your implementation
|
|
23
23
|
end
|
|
24
24
|
|
|
25
|
-
For more information, see: https://github.com/
|
|
25
|
+
For more information, see: https://github.com/dhq-boiler/rails-image-post-solution
|
|
26
26
|
|
|
27
27
|
===============================================================================
|