-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
115 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,12 @@ | ||
class Federails::Moderation::Report | ||
class Federails::Moderation::Report < ApplicationRecord | ||
belongs_to :federails_actor, class_name: "Federails::Actor" | ||
belongs_to :object, polymorphic: true | ||
|
||
def resolve! | ||
update!(resolved_at: DateTime.now, resolution: "resolved") | ||
end | ||
|
||
def ignore! | ||
update!(resolved_at: DateTime.now, resolution: "ignored") | ||
end | ||
end |
13 changes: 13 additions & 0 deletions
13
db/migrate/20241127105043_create_federails_moderation_reports.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
class CreateFederailsModerationReports < ActiveRecord::Migration[8.0] | ||
def change | ||
create_table :federails_moderation_reports do |t| | ||
t.string :federated_url | ||
t.references :federails_actor, null: false, foreign_key: true | ||
t.string :content | ||
t.references :object, polymorphic: true, null: false | ||
t.datetime :resolved_at | ||
t.string :resolution | ||
t.timestamps | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,5 +3,8 @@ | |
|
||
module Federails | ||
module Moderation | ||
def self.table_name_prefix | ||
"federails_moderation_" | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
FactoryBot.define do | ||
factory :distant_actor, class: 'Federails::Actor' do | ||
entity { nil } | ||
federated_url { "https://example.com/actors/#{rand(1...10_000)}" } | ||
username { Faker::Internet.username separators: [ '-', '_' ] } | ||
server { 'example.com' } | ||
inbox_url { "#{federated_url}/inbox" } | ||
outbox_url { "#{federated_url}/outbox" } | ||
followers_url { "#{federated_url}/followers" } | ||
followings_url { "#{federated_url}/followings" } | ||
profile_url { "https://example.com/users/#{federated_url.split('/').last}" } | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
FactoryBot.define do | ||
factory :report, class: 'Federails::Moderation::Report' do | ||
federails_actor { create :distant_actor } | ||
object { create :user } | ||
content { Faker::Lorem.sentence } | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
RSpec.describe Federails::Moderation::Report do | ||
let(:actor) { create :distant_actor } | ||
let(:object) { create :user } | ||
let(:report) { create :report, federails_actor: actor, object: object } | ||
|
||
it "is reported by an actor" do | ||
expect(report.federails_actor).to eq actor | ||
end | ||
|
||
it "is associated with a polymorphic object" do | ||
expect(report.object).to eq object | ||
end | ||
|
||
it "has text content" do | ||
expect(report.content).to be_present | ||
end | ||
|
||
it "can be resolved" do | ||
report.resolve! | ||
expect(report.resolution).to eq "resolved" | ||
end | ||
|
||
it "can be ignored" do | ||
report.ignore! | ||
expect(report.resolution).to eq "ignored" | ||
end | ||
|
||
it "stores resolution timestamp when resolved" do | ||
report.resolve! | ||
expect(report.resolved_at).to be_present | ||
end | ||
|
||
it "stores resolution timestamp when ignored" do | ||
report.ignore! | ||
expect(report.resolved_at).to be_present | ||
end | ||
end |