rails-image-post-solution 0.1.0 → 0.1.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/README.md +158 -5
- 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: 32426dffba22192bd75b188bd48b57c794cfa2f64b28d699f7dc375c55060d21
|
|
4
|
+
data.tar.gz: dad18086d9ff9c6d613ecded2c48fcb17e6de7543f87fefbddcf33e196669fa4
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 30ce677ce249bc09956d4ac0948946a3046840342db546de43b5c4b620a3bf8d47cb2a6d8d6c65b36cbc080c9abf724bfe096430a4f9a35ef840450ec5dd5e8c
|
|
7
|
+
data.tar.gz: '08acf121746c98771333797ac6bd58d1060c3176c049e56422e237e2c4591cbabe3afbad39d6cb67ce7d4457c5bdf73500c4c7d62bb55ef4c15fc75ac02ea915'
|
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
|
|
|
@@ -90,7 +96,15 @@ export OPENAI_API_KEY=sk-...
|
|
|
90
96
|
|
|
91
97
|
### User Reporting
|
|
92
98
|
|
|
93
|
-
|
|
99
|
+
The gem provides shared view partials for easy integration:
|
|
100
|
+
|
|
101
|
+
```erb
|
|
102
|
+
<%# In your view %>
|
|
103
|
+
<%= render 'shared/image_report_button', image: @attachment %>
|
|
104
|
+
<%= render 'shared/image_report_modal' %>
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
Or manually via POST request:
|
|
94
108
|
|
|
95
109
|
```ruby
|
|
96
110
|
# In your view
|
|
@@ -113,6 +127,12 @@ fetch('/moderation/image_reports', {
|
|
|
113
127
|
});
|
|
114
128
|
```
|
|
115
129
|
|
|
130
|
+
The provided partials include:
|
|
131
|
+
- `_image_report_button.html.erb` - Report button with status display
|
|
132
|
+
- `_image_report_modal.html.erb` - Modal dialog for submitting reports with category selection
|
|
133
|
+
|
|
134
|
+
**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.
|
|
135
|
+
|
|
116
136
|
### Admin Dashboard
|
|
117
137
|
|
|
118
138
|
Admins can access the dashboard at:
|
|
@@ -144,17 +164,43 @@ To enable automatic post freezing, add a `freeze_post!` method to your models th
|
|
|
144
164
|
class Post < ApplicationRecord
|
|
145
165
|
has_many_attached :images
|
|
146
166
|
|
|
167
|
+
# Scopes for frozen posts management
|
|
168
|
+
scope :frozen, -> { where.not(frozen_at: nil) }
|
|
169
|
+
scope :temporarily_frozen, -> { frozen.where(frozen_type: "temporary") }
|
|
170
|
+
scope :permanently_frozen, -> { frozen.where(frozen_type: "permanent") }
|
|
171
|
+
scope :recent, -> { order(created_at: :desc) }
|
|
172
|
+
|
|
147
173
|
def freeze_post!(type:, reason:)
|
|
148
174
|
update!(
|
|
149
|
-
frozen: true,
|
|
150
175
|
frozen_type: type,
|
|
151
176
|
frozen_reason: reason,
|
|
152
177
|
frozen_at: Time.current
|
|
153
178
|
)
|
|
154
179
|
end
|
|
155
180
|
|
|
181
|
+
def unfreeze!
|
|
182
|
+
update!(
|
|
183
|
+
frozen_type: nil,
|
|
184
|
+
frozen_reason: nil,
|
|
185
|
+
frozen_at: nil
|
|
186
|
+
)
|
|
187
|
+
end
|
|
188
|
+
|
|
156
189
|
def frozen?
|
|
157
|
-
|
|
190
|
+
frozen_at.present?
|
|
191
|
+
end
|
|
192
|
+
end
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
Add the required columns to your model:
|
|
196
|
+
|
|
197
|
+
```ruby
|
|
198
|
+
class AddFrozenFieldsToPosts < ActiveRecord::Migration[8.1]
|
|
199
|
+
def change
|
|
200
|
+
add_column :posts, :frozen_type, :string
|
|
201
|
+
add_column :posts, :frozen_reason, :text
|
|
202
|
+
add_column :posts, :frozen_at, :datetime
|
|
203
|
+
add_index :posts, :frozen_at
|
|
158
204
|
end
|
|
159
205
|
end
|
|
160
206
|
```
|
|
@@ -183,6 +229,69 @@ class User < ApplicationRecord
|
|
|
183
229
|
end
|
|
184
230
|
```
|
|
185
231
|
|
|
232
|
+
### Additional User Model Methods (for Extended Features)
|
|
233
|
+
|
|
234
|
+
If you plan to use the extended admin features (user management, frozen posts), add these methods to your User model:
|
|
235
|
+
|
|
236
|
+
```ruby
|
|
237
|
+
class User < ApplicationRecord
|
|
238
|
+
# Status check methods
|
|
239
|
+
def active?
|
|
240
|
+
!suspended? && !banned?
|
|
241
|
+
end
|
|
242
|
+
|
|
243
|
+
def suspended?
|
|
244
|
+
suspended_until.present? && suspended_until > Time.current
|
|
245
|
+
end
|
|
246
|
+
|
|
247
|
+
def banned?
|
|
248
|
+
banned_at.present?
|
|
249
|
+
end
|
|
250
|
+
|
|
251
|
+
# User management methods
|
|
252
|
+
def suspend!(reason:, duration: 7.days)
|
|
253
|
+
update!(
|
|
254
|
+
suspended_until: Time.current + duration,
|
|
255
|
+
suspension_reason: reason
|
|
256
|
+
)
|
|
257
|
+
end
|
|
258
|
+
|
|
259
|
+
def unsuspend!
|
|
260
|
+
update!(
|
|
261
|
+
suspended_until: nil,
|
|
262
|
+
suspension_reason: nil
|
|
263
|
+
)
|
|
264
|
+
end
|
|
265
|
+
|
|
266
|
+
def ban!(reason:)
|
|
267
|
+
update!(
|
|
268
|
+
banned_at: Time.current,
|
|
269
|
+
ban_reason: reason
|
|
270
|
+
)
|
|
271
|
+
end
|
|
272
|
+
|
|
273
|
+
def unban!
|
|
274
|
+
update!(
|
|
275
|
+
banned_at: nil,
|
|
276
|
+
ban_reason: nil
|
|
277
|
+
)
|
|
278
|
+
end
|
|
279
|
+
end
|
|
280
|
+
```
|
|
281
|
+
|
|
282
|
+
And add the corresponding database columns:
|
|
283
|
+
|
|
284
|
+
```ruby
|
|
285
|
+
class AddModerationFieldsToUsers < ActiveRecord::Migration[8.1]
|
|
286
|
+
def change
|
|
287
|
+
add_column :users, :suspended_until, :datetime
|
|
288
|
+
add_column :users, :suspension_reason, :text
|
|
289
|
+
add_column :users, :banned_at, :datetime
|
|
290
|
+
add_column :users, :ban_reason, :text
|
|
291
|
+
end
|
|
292
|
+
end
|
|
293
|
+
```
|
|
294
|
+
|
|
186
295
|
## Routes
|
|
187
296
|
|
|
188
297
|
The engine provides the following routes:
|
|
@@ -195,6 +304,50 @@ PATCH /moderation/admin/image_reports/:id/confirm # Mark as inappropriate
|
|
|
195
304
|
PATCH /moderation/admin/image_reports/:id/dismiss # Mark as safe
|
|
196
305
|
```
|
|
197
306
|
|
|
307
|
+
### Extended Admin Features (Optional)
|
|
308
|
+
|
|
309
|
+
The gem includes additional admin controllers for extended functionality. To use these, add the following routes to your `config/routes.rb`:
|
|
310
|
+
|
|
311
|
+
```ruby
|
|
312
|
+
namespace :admin do
|
|
313
|
+
# User management
|
|
314
|
+
resources :users, only: [:index, :show] do
|
|
315
|
+
member do
|
|
316
|
+
post :suspend
|
|
317
|
+
post :unsuspend
|
|
318
|
+
post :ban
|
|
319
|
+
post :unban
|
|
320
|
+
end
|
|
321
|
+
end
|
|
322
|
+
|
|
323
|
+
# Frozen posts management
|
|
324
|
+
resources :frozen_posts, only: [:index] do
|
|
325
|
+
collection do
|
|
326
|
+
post 'unfreeze_stage/:id', action: :unfreeze_stage, as: :unfreeze_stage
|
|
327
|
+
post 'unfreeze_comment/:id', action: :unfreeze_comment, as: :unfreeze_comment
|
|
328
|
+
post 'permanent_freeze_stage/:id', action: :permanent_freeze_stage, as: :permanent_freeze_stage
|
|
329
|
+
post 'permanent_freeze_comment/:id', action: :permanent_freeze_comment, as: :permanent_freeze_comment
|
|
330
|
+
delete 'destroy_stage/:id', action: :destroy_stage, as: :destroy_stage
|
|
331
|
+
delete 'destroy_comment/:id', action: :destroy_comment, as: :destroy_comment
|
|
332
|
+
end
|
|
333
|
+
end
|
|
334
|
+
|
|
335
|
+
# Extended image reports (alternative to engine's admin controller)
|
|
336
|
+
resources :image_reports, only: [:index, :show] do
|
|
337
|
+
member do
|
|
338
|
+
patch :confirm
|
|
339
|
+
patch :dismiss
|
|
340
|
+
end
|
|
341
|
+
end
|
|
342
|
+
end
|
|
343
|
+
```
|
|
344
|
+
|
|
345
|
+
These extended features include:
|
|
346
|
+
|
|
347
|
+
- **User Management**: Suspend, unsuspend, ban, and unban users
|
|
348
|
+
- **Frozen Posts Management**: View, unfreeze, permanently freeze, or delete frozen posts
|
|
349
|
+
- **Enhanced Image Reports**: Additional views and functionality for managing image reports
|
|
350
|
+
|
|
198
351
|
## Customization
|
|
199
352
|
|
|
200
353
|
### Custom Admin Check
|
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: [ :index, :show ] do
|
|
18
|
+
member do
|
|
19
|
+
patch :suspend
|
|
20
|
+
patch :unsuspend
|
|
21
|
+
patch :ban
|
|
22
|
+
patch :unban
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
# Frozen posts management
|
|
27
|
+
resources :frozen_posts, only: [ :index ] do
|
|
28
|
+
collection do
|
|
29
|
+
patch "unfreeze_stage/:id", to: "frozen_posts#unfreeze_stage", as: :unfreeze_stage
|
|
30
|
+
patch "unfreeze_comment/:id", to: "frozen_posts#unfreeze_comment", as: :unfreeze_comment
|
|
31
|
+
patch "permanent_freeze_stage/:id", to: "frozen_posts#permanent_freeze_stage", as: :permanent_freeze_stage
|
|
32
|
+
patch "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
|
===============================================================================
|