diff --git a/app/models/action.rb b/app/models/action.rb new file mode 100644 index 0000000..15f6282 --- /dev/null +++ b/app/models/action.rb @@ -0,0 +1,5 @@ +# frozen_string_literal: true + +class Action < ApplicationRecord + belongs_to :ruleset +end diff --git a/app/models/rule.rb b/app/models/rule.rb new file mode 100644 index 0000000..5f70f9d --- /dev/null +++ b/app/models/rule.rb @@ -0,0 +1,5 @@ +# frozen_string_literal: true + +class Rule < ApplicationRecord + belongs_to :ruleset +end diff --git a/app/models/rule_set.rb b/app/models/rule_set.rb new file mode 100644 index 0000000..c30a12b --- /dev/null +++ b/app/models/rule_set.rb @@ -0,0 +1,4 @@ +# frozen_string_literal: true + +class RuleSet < ApplicationRecord +end diff --git a/app/services/email_action/base.rb b/app/services/email_action/base.rb new file mode 100644 index 0000000..168ba2d --- /dev/null +++ b/app/services/email_action/base.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +module EmailAction + + class Error < ::StandardError + end + + class Base + + def process(email) + fail NotImplementedError + end + end + +end diff --git a/db/migrate/20210118130305_create_rule_sets.rb b/db/migrate/20210118130305_create_rule_sets.rb new file mode 100644 index 0000000..7ef3ef2 --- /dev/null +++ b/db/migrate/20210118130305_create_rule_sets.rb @@ -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 diff --git a/db/migrate/20210118130313_create_rules.rb b/db/migrate/20210118130313_create_rules.rb new file mode 100644 index 0000000..206db84 --- /dev/null +++ b/db/migrate/20210118130313_create_rules.rb @@ -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 diff --git a/db/migrate/20210118132809_create_actions.rb b/db/migrate/20210118132809_create_actions.rb new file mode 100644 index 0000000..77be05b --- /dev/null +++ b/db/migrate/20210118132809_create_actions.rb @@ -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 diff --git a/db/schema.rb b/db/schema.rb index 9fb59b7..792d9a9 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # 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| 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 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| t.string "name", 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" 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| t.string "email", 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 end + add_foreign_key "actions", "rulesets" 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 "rules", "rulesets" end diff --git a/test/fixtures/actions.yml b/test/fixtures/actions.yml new file mode 100644 index 0000000..079d922 --- /dev/null +++ b/test/fixtures/actions.yml @@ -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 diff --git a/test/fixtures/rule_sets.yml b/test/fixtures/rule_sets.yml new file mode 100644 index 0000000..b80f1bb --- /dev/null +++ b/test/fixtures/rule_sets.yml @@ -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 diff --git a/test/fixtures/rules.yml b/test/fixtures/rules.yml new file mode 100644 index 0000000..fc33ea3 --- /dev/null +++ b/test/fixtures/rules.yml @@ -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 diff --git a/test/models/action_test.rb b/test/models/action_test.rb new file mode 100644 index 0000000..585c5df --- /dev/null +++ b/test/models/action_test.rb @@ -0,0 +1,7 @@ +require "test_helper" + +class ActionTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end diff --git a/test/models/rule_set_test.rb b/test/models/rule_set_test.rb new file mode 100644 index 0000000..616301d --- /dev/null +++ b/test/models/rule_set_test.rb @@ -0,0 +1,7 @@ +require "test_helper" + +class RuleSetTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end diff --git a/test/models/rule_test.rb b/test/models/rule_test.rb new file mode 100644 index 0000000..ac1654f --- /dev/null +++ b/test/models/rule_test.rb @@ -0,0 +1,7 @@ +require "test_helper" + +class RuleTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end