Création de RuleSet/Rule/Action
This commit is contained in:
parent
8ded622dfe
commit
c12bf5af8f
5
app/models/action.rb
Normal file
5
app/models/action.rb
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
class Action < ApplicationRecord
|
||||||
|
belongs_to :ruleset
|
||||||
|
end
|
5
app/models/rule.rb
Normal file
5
app/models/rule.rb
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
class Rule < ApplicationRecord
|
||||||
|
belongs_to :ruleset
|
||||||
|
end
|
4
app/models/rule_set.rb
Normal file
4
app/models/rule_set.rb
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
class RuleSet < ApplicationRecord
|
||||||
|
end
|
15
app/services/email_action/base.rb
Normal file
15
app/services/email_action/base.rb
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
module EmailAction
|
||||||
|
|
||||||
|
class Error < ::StandardError
|
||||||
|
end
|
||||||
|
|
||||||
|
class Base
|
||||||
|
|
||||||
|
def process(email)
|
||||||
|
fail NotImplementedError
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
11
db/migrate/20210118130305_create_rule_sets.rb
Normal file
11
db/migrate/20210118130305_create_rule_sets.rb
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
class CreateRuleSets < ActiveRecord::Migration[6.1]
|
||||||
|
def change
|
||||||
|
create_table :rule_sets do |t|
|
||||||
|
t.string :name
|
||||||
|
t.text :description
|
||||||
|
t.boolean :enabled, default: true
|
||||||
|
|
||||||
|
t.timestamps
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
16
db/migrate/20210118130313_create_rules.rb
Normal file
16
db/migrate/20210118130313_create_rules.rb
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
class CreateRules < ActiveRecord::Migration[6.1]
|
||||||
|
def change
|
||||||
|
create_table :rules do |t|
|
||||||
|
t.references :ruleset, null: false, foreign_key: true
|
||||||
|
t.string :name
|
||||||
|
t.boolean :enabled, default: true
|
||||||
|
t.string :criteria_type
|
||||||
|
t.string :criteria_value
|
||||||
|
t.string :operator, default: "contain"
|
||||||
|
t.boolean :operator_inverted, default: false
|
||||||
|
t.string :value
|
||||||
|
|
||||||
|
t.timestamps
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
12
db/migrate/20210118132809_create_actions.rb
Normal file
12
db/migrate/20210118132809_create_actions.rb
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
class CreateActions < ActiveRecord::Migration[6.1]
|
||||||
|
def change
|
||||||
|
create_table :actions do |t|
|
||||||
|
t.references :ruleset, null: false, foreign_key: true
|
||||||
|
t.string :name
|
||||||
|
t.boolean :enabled, default: true
|
||||||
|
t.string :action_class
|
||||||
|
|
||||||
|
t.timestamps
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
36
db/schema.rb
36
db/schema.rb
|
@ -10,7 +10,7 @@
|
||||||
#
|
#
|
||||||
# It's strongly recommended that you check this file into your version control system.
|
# It's strongly recommended that you check this file into your version control system.
|
||||||
|
|
||||||
ActiveRecord::Schema.define(version: 2021_01_16_165351) do
|
ActiveRecord::Schema.define(version: 2021_01_18_132809) do
|
||||||
|
|
||||||
create_table "action_mailbox_inbound_emails", force: :cascade do |t|
|
create_table "action_mailbox_inbound_emails", force: :cascade do |t|
|
||||||
t.integer "status", default: 0, null: false
|
t.integer "status", default: 0, null: false
|
||||||
|
@ -21,6 +21,16 @@ ActiveRecord::Schema.define(version: 2021_01_16_165351) do
|
||||||
t.index ["message_id", "message_checksum"], name: "index_action_mailbox_inbound_emails_uniqueness", unique: true
|
t.index ["message_id", "message_checksum"], name: "index_action_mailbox_inbound_emails_uniqueness", unique: true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
create_table "actions", force: :cascade do |t|
|
||||||
|
t.integer "ruleset_id", null: false
|
||||||
|
t.string "name"
|
||||||
|
t.boolean "enabled", default: true
|
||||||
|
t.string "action_class"
|
||||||
|
t.datetime "created_at", precision: 6, null: false
|
||||||
|
t.datetime "updated_at", precision: 6, null: false
|
||||||
|
t.index ["ruleset_id"], name: "index_actions_on_ruleset_id"
|
||||||
|
end
|
||||||
|
|
||||||
create_table "active_storage_attachments", force: :cascade do |t|
|
create_table "active_storage_attachments", force: :cascade do |t|
|
||||||
t.string "name", null: false
|
t.string "name", null: false
|
||||||
t.string "record_type", null: false
|
t.string "record_type", null: false
|
||||||
|
@ -77,6 +87,28 @@ ActiveRecord::Schema.define(version: 2021_01_16_165351) do
|
||||||
t.index ["input"], name: "index_metadata_mappings_on_input"
|
t.index ["input"], name: "index_metadata_mappings_on_input"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
create_table "rule_sets", force: :cascade do |t|
|
||||||
|
t.string "name"
|
||||||
|
t.text "description"
|
||||||
|
t.boolean "enabled", default: true
|
||||||
|
t.datetime "created_at", precision: 6, null: false
|
||||||
|
t.datetime "updated_at", precision: 6, null: false
|
||||||
|
end
|
||||||
|
|
||||||
|
create_table "rules", force: :cascade do |t|
|
||||||
|
t.integer "ruleset_id", null: false
|
||||||
|
t.string "name"
|
||||||
|
t.boolean "enabled", default: true
|
||||||
|
t.string "criteria_type"
|
||||||
|
t.string "criteria_value"
|
||||||
|
t.string "operator", default: "contain"
|
||||||
|
t.boolean "operator_inverted", default: false
|
||||||
|
t.string "value"
|
||||||
|
t.datetime "created_at", precision: 6, null: false
|
||||||
|
t.datetime "updated_at", precision: 6, null: false
|
||||||
|
t.index ["ruleset_id"], name: "index_rules_on_ruleset_id"
|
||||||
|
end
|
||||||
|
|
||||||
create_table "users", force: :cascade do |t|
|
create_table "users", force: :cascade do |t|
|
||||||
t.string "email", default: "", null: false
|
t.string "email", default: "", null: false
|
||||||
t.string "encrypted_password", default: "", null: false
|
t.string "encrypted_password", default: "", null: false
|
||||||
|
@ -94,6 +126,8 @@ ActiveRecord::Schema.define(version: 2021_01_16_165351) do
|
||||||
t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true
|
t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
add_foreign_key "actions", "rulesets"
|
||||||
add_foreign_key "active_storage_attachments", "active_storage_blobs", column: "blob_id"
|
add_foreign_key "active_storage_attachments", "active_storage_blobs", column: "blob_id"
|
||||||
add_foreign_key "active_storage_variant_records", "active_storage_blobs", column: "blob_id"
|
add_foreign_key "active_storage_variant_records", "active_storage_blobs", column: "blob_id"
|
||||||
|
add_foreign_key "rules", "rulesets"
|
||||||
end
|
end
|
||||||
|
|
13
test/fixtures/actions.yml
vendored
Normal file
13
test/fixtures/actions.yml
vendored
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
|
||||||
|
|
||||||
|
one:
|
||||||
|
ruleset: one
|
||||||
|
name: MyString
|
||||||
|
enabled: false
|
||||||
|
action_class: MyString
|
||||||
|
|
||||||
|
two:
|
||||||
|
ruleset: two
|
||||||
|
name: MyString
|
||||||
|
enabled: false
|
||||||
|
action_class: MyString
|
11
test/fixtures/rule_sets.yml
vendored
Normal file
11
test/fixtures/rule_sets.yml
vendored
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
|
||||||
|
|
||||||
|
one:
|
||||||
|
name: MyString
|
||||||
|
description: MyText
|
||||||
|
enabled: false
|
||||||
|
|
||||||
|
two:
|
||||||
|
name: MyString
|
||||||
|
description: MyText
|
||||||
|
enabled: false
|
21
test/fixtures/rules.yml
vendored
Normal file
21
test/fixtures/rules.yml
vendored
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
|
||||||
|
|
||||||
|
one:
|
||||||
|
ruleset: one
|
||||||
|
name: MyString
|
||||||
|
enabled: false
|
||||||
|
criteria_type: MyString
|
||||||
|
criteria_value: MyString
|
||||||
|
operator: MyString
|
||||||
|
operator_inverted: false
|
||||||
|
value: MyString
|
||||||
|
|
||||||
|
two:
|
||||||
|
ruleset: two
|
||||||
|
name: MyString
|
||||||
|
enabled: false
|
||||||
|
criteria_type: MyString
|
||||||
|
criteria_value: MyString
|
||||||
|
operator: MyString
|
||||||
|
operator_inverted: false
|
||||||
|
value: MyString
|
7
test/models/action_test.rb
Normal file
7
test/models/action_test.rb
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
require "test_helper"
|
||||||
|
|
||||||
|
class ActionTest < ActiveSupport::TestCase
|
||||||
|
# test "the truth" do
|
||||||
|
# assert true
|
||||||
|
# end
|
||||||
|
end
|
7
test/models/rule_set_test.rb
Normal file
7
test/models/rule_set_test.rb
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
require "test_helper"
|
||||||
|
|
||||||
|
class RuleSetTest < ActiveSupport::TestCase
|
||||||
|
# test "the truth" do
|
||||||
|
# assert true
|
||||||
|
# end
|
||||||
|
end
|
7
test/models/rule_test.rb
Normal file
7
test/models/rule_test.rb
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
require "test_helper"
|
||||||
|
|
||||||
|
class RuleTest < ActiveSupport::TestCase
|
||||||
|
# test "the truth" do
|
||||||
|
# assert true
|
||||||
|
# end
|
||||||
|
end
|
Loading…
Reference in a new issue