diff --git a/app/models/categorization.rb b/app/models/categorization.rb index e5d9d1f..b5969de 100644 --- a/app/models/categorization.rb +++ b/app/models/categorization.rb @@ -19,10 +19,13 @@ # detector_version :string # created_at :datetime not null # updated_at :datetime not null +# validatable_type :string +# validatable_id :integer # class Categorization < ApplicationRecord belongs_to :term belongs_to :category + has_many :validations, as: :validatable, dependent: :destroy # These scopes allow for easy filtering of Categorization records by a single parameter. scope :current, -> { where(detector_version: ENV.fetch('DETECTOR_VERSION', 'unset')) } diff --git a/app/models/detection.rb b/app/models/detection.rb index 7729e28..ed1f2a5 100644 --- a/app/models/detection.rb +++ b/app/models/detection.rb @@ -18,10 +18,13 @@ # detector_version :string # created_at :datetime not null # updated_at :datetime not null +# validatable_type :string +# validatable_id :integer # class Detection < ApplicationRecord belongs_to :term belongs_to :detector + has_many :validations, as: :validatable, dependent: :destroy # These scopes allow for easy filtering of Detection records by a single parameter. scope :current, -> { where(detector_version: ENV.fetch('DETECTOR_VERSION', 'unset')) } diff --git a/app/models/user.rb b/app/models/user.rb index 99d9d99..a8ebbf3 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -14,6 +14,8 @@ class User < ApplicationRecord include FakeAuthConfig + has_many :validations, dependent: :destroy + if FakeAuthConfig.fake_auth_enabled? devise :omniauthable, omniauth_providers: [:developer] else diff --git a/app/models/validation.rb b/app/models/validation.rb new file mode 100644 index 0000000..302aaad --- /dev/null +++ b/app/models/validation.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +# == Schema Information +# +# Table name: validations +# +# id :integer not null, primary key +# validatable_type :string +# validatable_id :integer +# user_id :integer not null +# detector_version :string +# judgement :integer +# created_at :datetime not null +# updated_at :datetime not null +# +class Validation < ApplicationRecord + belongs_to :validatable, polymorphic: true +end diff --git a/db/migrate/20241021184739_create_validations.rb b/db/migrate/20241021184739_create_validations.rb new file mode 100644 index 0000000..2791c2a --- /dev/null +++ b/db/migrate/20241021184739_create_validations.rb @@ -0,0 +1,17 @@ +class CreateValidations < ActiveRecord::Migration[7.1] + def change + create_table :validations do |t| + t.references :validatable, polymorphic: true + t.belongs_to :user, null: false, foreign_key: true + t.string :detector_version + t.integer :judgement + + t.timestamps + end + + add_index :validations, [:validatable_id, :validatable_type, :user_id, :detector_version], unique: true + + add_reference :detections, :validatable, polymorphic: true + add_reference :categorizations, :validatable, polymorphic: true + end +end diff --git a/db/schema.rb b/db/schema.rb index 3a9f440..24a7871 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[7.1].define(version: 2024_10_11_181823) do +ActiveRecord::Schema[7.1].define(version: 2024_10_21_184739) do create_table "categories", force: :cascade do |t| t.string "name" t.text "description" @@ -26,10 +26,13 @@ t.string "detector_version" t.datetime "created_at", null: false t.datetime "updated_at", null: false + t.string "validatable_type" + t.integer "validatable_id" t.index ["category_id", "term_id", "detector_version"], name: "idx_on_category_id_term_id_detector_version_9f24c39900", unique: true t.index ["category_id"], name: "index_categorizations_on_category_id" t.index ["term_id", "category_id", "detector_version"], name: "idx_on_term_id_category_id_detector_version_4e10ba6204", unique: true t.index ["term_id"], name: "index_categorizations_on_term_id" + t.index ["validatable_type", "validatable_id"], name: "index_categorizations_on_validatable" end create_table "detections", force: :cascade do |t| @@ -38,10 +41,13 @@ t.string "detector_version" t.datetime "created_at", null: false t.datetime "updated_at", null: false + t.string "validatable_type" + t.integer "validatable_id" t.index ["detector_id", "term_id", "detector_version"], name: "idx_on_detector_id_term_id_detector_version_2afa383b1f", unique: true t.index ["detector_id"], name: "index_detections_on_detector_id" t.index ["term_id", "detector_id", "detector_version"], name: "idx_on_term_id_detector_id_detector_version_03898e846f", unique: true t.index ["term_id"], name: "index_detections_on_term_id" + t.index ["validatable_type", "validatable_id"], name: "index_detections_on_validatable" end create_table "detector_categories", force: :cascade do |t| @@ -123,10 +129,24 @@ t.index ["uid"], name: "index_users_on_uid", unique: true end + create_table "validations", force: :cascade do |t| + t.string "validatable_type" + t.integer "validatable_id" + t.integer "user_id", null: false + t.string "detector_version" + t.integer "judgement" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.index ["user_id"], name: "index_validations_on_user_id" + t.index ["validatable_id", "validatable_type", "user_id", "detector_version"], name: "idx_on_validatable_id_validatable_type_user_id_dete_34f39b7bda", unique: true + t.index ["validatable_type", "validatable_id"], name: "index_validations_on_validatable" + end + add_foreign_key "categorizations", "categories" add_foreign_key "categorizations", "terms" add_foreign_key "detections", "detectors" add_foreign_key "detections", "terms" add_foreign_key "detector_categories", "categories" add_foreign_key "detector_categories", "detectors" + add_foreign_key "validations", "users" end diff --git a/docs/reference/classes.md b/docs/reference/classes.md index 99071e7..14e56d2 100644 --- a/docs/reference/classes.md +++ b/docs/reference/classes.md @@ -7,6 +7,7 @@ The application includes the following entities, most of which an be broken into between the two which TACOS defines and maintains, and which is consulted during categorization; and * The linkages between these search terms and the graph, which record which signals are detected in each term, and how those signals are interpreted to place the term into a category. +* The validations ```mermaid classDiagram @@ -24,6 +25,10 @@ classDiagram Detector "1" --> "0..*" DetectorCategory + Validation --> Detection: polymorphic + Validation --> Categorization: polymorphic + User --> Validation : provides many + class User User: +String uid User: +String email @@ -93,6 +98,12 @@ classDiagram DetectorSuggestedResource: record() DetectorSuggestedResource: update_fingerprint() + class Validation + Validation: +Integer id + Validation: +Integer user_id + Validation: +Polymorphic action_id + Validation: +String detector_version + Validation: +Integer judgement namespace SearchActivity{ class Term @@ -113,6 +124,12 @@ classDiagram class DetectorSuggestedResource["Detector::SuggestedResource"] } + namespace UserActivity { + class Validation + class User + + } + style SearchEvent fill:#000,stroke:#66c2a5,color:#66c2a5,stroke-width:4px; style Term fill:#000,stroke:#66c2a5,color:#66c2a5,stroke-width:4px; @@ -126,4 +143,7 @@ classDiagram style Categorization fill:#000,stroke:#8da0cb,color:#8da0cb,stroke-dasharray: 3 5; style Detection fill:#000,stroke:#8da0cb,color:#8da0cb,stroke-dasharray: 3 5; + + style Validation fill:#000,stroke:#ffd407 + style User fill:#000,stroke:#ffd407 ``` diff --git a/test/fixtures/categorizations.yml b/test/fixtures/categorizations.yml index 5af399c..34d334f 100644 --- a/test/fixtures/categorizations.yml +++ b/test/fixtures/categorizations.yml @@ -9,6 +9,8 @@ # detector_version :string # created_at :datetime not null # updated_at :datetime not null +# validatable_type :string +# validatable_id :integer # one: category: transactional diff --git a/test/fixtures/detections.yml b/test/fixtures/detections.yml index 4dea115..0c6829f 100644 --- a/test/fixtures/detections.yml +++ b/test/fixtures/detections.yml @@ -8,6 +8,8 @@ # detector_version :string # created_at :datetime not null # updated_at :datetime not null +# validatable_type :string +# validatable_id :integer # one: term: doi diff --git a/test/models/categorization_test.rb b/test/models/categorization_test.rb index 39f4486..dbd770f 100644 --- a/test/models/categorization_test.rb +++ b/test/models/categorization_test.rb @@ -11,6 +11,8 @@ # detector_version :string # created_at :datetime not null # updated_at :datetime not null +# validatable_type :string +# validatable_id :integer # require 'test_helper' diff --git a/test/models/detection_test.rb b/test/models/detection_test.rb index 6a49d18..8504f1b 100644 --- a/test/models/detection_test.rb +++ b/test/models/detection_test.rb @@ -10,6 +10,8 @@ # detector_version :string # created_at :datetime not null # updated_at :datetime not null +# validatable_type :string +# validatable_id :integer # require 'test_helper'