From 142baaf3aca31090ef41981a8cd7820116c3e949 Mon Sep 17 00:00:00 2001 From: Jan Werkhoven Date: Sat, 27 Jan 2024 19:51:16 +1100 Subject: [PATCH 01/12] WIP --- .rubocop.yml | 7 +++++ app/controllers/application_controller.rb | 9 ++++-- .../public/article_categories_controller.rb | 2 +- .../v1/public/articles_controller.rb | 2 +- .../v1/public/companies_controller.rb | 2 +- .../v1/public/company_markets_controller.rb | 2 +- .../v1/public/containers_controller.rb | 2 +- .../v1/public/countries_controller.rb | 2 +- .../public/document_categories_controller.rb | 2 +- .../v1/public/documents_controller.rb | 2 +- .../v1/public/events_controller.rb | 2 +- .../v1/public/features_controller.rb | 2 +- .../v1/public/images_controller.rb | 2 +- .../v1/public/languages_controller.rb | 2 +- .../v1/public/people_controller.rb | 2 +- .../v1/public/permalinks_controller.rb | 2 +- .../v1/public/person_images_controller.rb | 2 +- .../v1/public/product_families_controller.rb | 2 +- .../v1/public/product_features_controller.rb | 2 +- .../v1/public/product_images_controller.rb | 2 +- .../v1/public/product_qualities_controller.rb | 2 +- .../v1/public/product_uses_controller.rb | 2 +- .../v1/public/product_variants_controller.rb | 2 +- .../v1/public/product_videos_controller.rb | 2 +- .../v1/public/products_controller.rb | 2 +- .../v1/public/qualities_controller.rb | 2 +- .../v1/public/sessions_controller.rb | 2 +- .../public/simulation_requests_controller.rb | 2 +- .../v1/public/translations_controller.rb | 2 +- app/controllers/v1/public/uses_controller.rb | 2 +- .../v1/public/videos_controller.rb | 2 +- .../v1/public/webinar_attendees_controller.rb | 2 +- .../v1/public/webinars_controller.rb | 2 +- app/controllers/v1/public_controller.rb | 29 +++++++++++++++++++ app/models/visit.rb | 14 +++++++++ config/routes.rb | 10 ++++--- db/migrate/20240121003248_create_visits.rb | 16 ++++++++++ db/schema.rb | 15 +++++++++- test/fixtures/visits.yml | 11 +++++++ test/models/visit_test.rb | 7 +++++ 40 files changed, 142 insertions(+), 38 deletions(-) create mode 100644 app/models/visit.rb create mode 100644 db/migrate/20240121003248_create_visits.rb create mode 100644 test/fixtures/visits.yml create mode 100644 test/models/visit_test.rb diff --git a/.rubocop.yml b/.rubocop.yml index 24a44ecb..be599a84 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -57,6 +57,11 @@ Style/FrozenStringLiteralComment: Style/PercentLiteralDelimiters: Enabled: false +# Until today I have never needed to know created_at and updated_at. ¯\_(ツ)_/¯ +# Let's only add them when we have a good reason. +Rails/CreateTableWithTimestamps: + Enabled: false + # Because warning asked to add these... Lint/RaiseException: Enabled: true @@ -68,3 +73,5 @@ Style/HashTransformKeys: Enabled: true Style/HashTransformValues: Enabled: true + + diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index daed0b2c..8153e6a1 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1,7 +1,12 @@ class ApplicationController < ActionController::API - # To give all controllers the tools to be JSON API spec compliant. + # Give all controllers the methods for handling requests per JSON API spec. include JsonApiController - # To allow controllers to set and read cookies. + # Allow controllers to set and read cookies. include ActionController::Cookies + + # Allow all controllers to log with a shorthand. + def log + Rails.logger + end end diff --git a/app/controllers/v1/public/article_categories_controller.rb b/app/controllers/v1/public/article_categories_controller.rb index d4134afa..238923ee 100644 --- a/app/controllers/v1/public/article_categories_controller.rb +++ b/app/controllers/v1/public/article_categories_controller.rb @@ -1,6 +1,6 @@ module V1 module Public - class ArticleCategoriesController < ApplicationController + class ArticleCategoriesController < V1::PublicController def index allow_index end diff --git a/app/controllers/v1/public/articles_controller.rb b/app/controllers/v1/public/articles_controller.rb index 7bf91290..d7bf28f0 100644 --- a/app/controllers/v1/public/articles_controller.rb +++ b/app/controllers/v1/public/articles_controller.rb @@ -1,6 +1,6 @@ module V1 module Public - class ArticlesController < ApplicationController + class ArticlesController < V1::PublicController def index allow_index end diff --git a/app/controllers/v1/public/companies_controller.rb b/app/controllers/v1/public/companies_controller.rb index 3310ad46..33a45772 100644 --- a/app/controllers/v1/public/companies_controller.rb +++ b/app/controllers/v1/public/companies_controller.rb @@ -1,6 +1,6 @@ module V1 module Public - class CompaniesController < ApplicationController + class CompaniesController < V1::PublicController def index allow_index end diff --git a/app/controllers/v1/public/company_markets_controller.rb b/app/controllers/v1/public/company_markets_controller.rb index 89ab2ef7..cf9f91ef 100644 --- a/app/controllers/v1/public/company_markets_controller.rb +++ b/app/controllers/v1/public/company_markets_controller.rb @@ -1,6 +1,6 @@ module V1 module Public - class CompanyMarketsController < ApplicationController + class CompanyMarketsController < V1::PublicController def index allow_index end diff --git a/app/controllers/v1/public/containers_controller.rb b/app/controllers/v1/public/containers_controller.rb index 8f1550bb..a8e6dabc 100644 --- a/app/controllers/v1/public/containers_controller.rb +++ b/app/controllers/v1/public/containers_controller.rb @@ -1,6 +1,6 @@ module V1 module Public - class ContainersController < ApplicationController + class ContainersController < V1::PublicController def index allow_index end diff --git a/app/controllers/v1/public/countries_controller.rb b/app/controllers/v1/public/countries_controller.rb index 48e6c8cf..cdc2da25 100644 --- a/app/controllers/v1/public/countries_controller.rb +++ b/app/controllers/v1/public/countries_controller.rb @@ -1,6 +1,6 @@ module V1 module Public - class CountriesController < ApplicationController + class CountriesController < V1::PublicController def index allow_index end diff --git a/app/controllers/v1/public/document_categories_controller.rb b/app/controllers/v1/public/document_categories_controller.rb index b72f8561..30bbe20c 100644 --- a/app/controllers/v1/public/document_categories_controller.rb +++ b/app/controllers/v1/public/document_categories_controller.rb @@ -1,6 +1,6 @@ module V1 module Public - class DocumentCategoriesController < ApplicationController + class DocumentCategoriesController < V1::PublicController def index allow_index end diff --git a/app/controllers/v1/public/documents_controller.rb b/app/controllers/v1/public/documents_controller.rb index 7a12eae7..ce473f0a 100644 --- a/app/controllers/v1/public/documents_controller.rb +++ b/app/controllers/v1/public/documents_controller.rb @@ -1,6 +1,6 @@ module V1 module Public - class DocumentsController < ApplicationController + class DocumentsController < V1::PublicController def index allow_index end diff --git a/app/controllers/v1/public/events_controller.rb b/app/controllers/v1/public/events_controller.rb index b0ed40f7..2449bc7d 100644 --- a/app/controllers/v1/public/events_controller.rb +++ b/app/controllers/v1/public/events_controller.rb @@ -1,6 +1,6 @@ module V1 module Public - class EventsController < ApplicationController + class EventsController < V1::PublicController def index allow_index end diff --git a/app/controllers/v1/public/features_controller.rb b/app/controllers/v1/public/features_controller.rb index 27e2798f..e6d75661 100644 --- a/app/controllers/v1/public/features_controller.rb +++ b/app/controllers/v1/public/features_controller.rb @@ -1,6 +1,6 @@ module V1 module Public - class FeaturesController < ApplicationController + class FeaturesController < V1::PublicController def index allow_index end diff --git a/app/controllers/v1/public/images_controller.rb b/app/controllers/v1/public/images_controller.rb index 1a72f3b8..edd31574 100644 --- a/app/controllers/v1/public/images_controller.rb +++ b/app/controllers/v1/public/images_controller.rb @@ -1,6 +1,6 @@ module V1 module Public - class ImagesController < ApplicationController + class ImagesController < V1::PublicController def index allow_index end diff --git a/app/controllers/v1/public/languages_controller.rb b/app/controllers/v1/public/languages_controller.rb index e8d49d7f..67ecac03 100644 --- a/app/controllers/v1/public/languages_controller.rb +++ b/app/controllers/v1/public/languages_controller.rb @@ -1,6 +1,6 @@ module V1 module Public - class LanguagesController < ApplicationController + class LanguagesController < V1::PublicController def index allow_index end diff --git a/app/controllers/v1/public/people_controller.rb b/app/controllers/v1/public/people_controller.rb index f57d4836..5cb7cc00 100644 --- a/app/controllers/v1/public/people_controller.rb +++ b/app/controllers/v1/public/people_controller.rb @@ -1,6 +1,6 @@ module V1 module Public - class PeopleController < ApplicationController + class PeopleController < V1::PublicController def index allow_index end diff --git a/app/controllers/v1/public/permalinks_controller.rb b/app/controllers/v1/public/permalinks_controller.rb index e96eee77..1735c869 100644 --- a/app/controllers/v1/public/permalinks_controller.rb +++ b/app/controllers/v1/public/permalinks_controller.rb @@ -1,6 +1,6 @@ module V1 module Public - class PermalinksController < ApplicationController + class PermalinksController < V1::PublicController def index allow_index end diff --git a/app/controllers/v1/public/person_images_controller.rb b/app/controllers/v1/public/person_images_controller.rb index 143fc82b..ccbc1a25 100644 --- a/app/controllers/v1/public/person_images_controller.rb +++ b/app/controllers/v1/public/person_images_controller.rb @@ -1,6 +1,6 @@ module V1 module Public - class PersonImagesController < ApplicationController + class PersonImagesController < V1::PublicController def index forbidden end diff --git a/app/controllers/v1/public/product_families_controller.rb b/app/controllers/v1/public/product_families_controller.rb index 796b6d1e..d9b01661 100644 --- a/app/controllers/v1/public/product_families_controller.rb +++ b/app/controllers/v1/public/product_families_controller.rb @@ -1,6 +1,6 @@ module V1 module Public - class ProductFamiliesController < ApplicationController + class ProductFamiliesController < V1::PublicController def index allow_index end diff --git a/app/controllers/v1/public/product_features_controller.rb b/app/controllers/v1/public/product_features_controller.rb index e1b27934..84488fc7 100644 --- a/app/controllers/v1/public/product_features_controller.rb +++ b/app/controllers/v1/public/product_features_controller.rb @@ -1,6 +1,6 @@ module V1 module Public - class ProductFeaturesController < ApplicationController + class ProductFeaturesController < V1::PublicController def index allow_index end diff --git a/app/controllers/v1/public/product_images_controller.rb b/app/controllers/v1/public/product_images_controller.rb index d35b2e96..255ed70a 100644 --- a/app/controllers/v1/public/product_images_controller.rb +++ b/app/controllers/v1/public/product_images_controller.rb @@ -1,6 +1,6 @@ module V1 module Public - class ProductImagesController < ApplicationController + class ProductImagesController < V1::PublicController def index allow_index end diff --git a/app/controllers/v1/public/product_qualities_controller.rb b/app/controllers/v1/public/product_qualities_controller.rb index 7fc6e8cd..43c9af60 100644 --- a/app/controllers/v1/public/product_qualities_controller.rb +++ b/app/controllers/v1/public/product_qualities_controller.rb @@ -1,6 +1,6 @@ module V1 module Public - class ProductQualitiesController < ApplicationController + class ProductQualitiesController < V1::PublicController def index allow_index end diff --git a/app/controllers/v1/public/product_uses_controller.rb b/app/controllers/v1/public/product_uses_controller.rb index 4b240975..5d7a51aa 100644 --- a/app/controllers/v1/public/product_uses_controller.rb +++ b/app/controllers/v1/public/product_uses_controller.rb @@ -1,6 +1,6 @@ module V1 module Public - class ProductUsesController < ApplicationController + class ProductUsesController < V1::PublicController def index allow_index end diff --git a/app/controllers/v1/public/product_variants_controller.rb b/app/controllers/v1/public/product_variants_controller.rb index e7d4c7ab..0a4fae85 100644 --- a/app/controllers/v1/public/product_variants_controller.rb +++ b/app/controllers/v1/public/product_variants_controller.rb @@ -1,6 +1,6 @@ module V1 module Public - class ProductVariantsController < ApplicationController + class ProductVariantsController < V1::PublicController def index allow_index end diff --git a/app/controllers/v1/public/product_videos_controller.rb b/app/controllers/v1/public/product_videos_controller.rb index b13a1d73..f03554d5 100644 --- a/app/controllers/v1/public/product_videos_controller.rb +++ b/app/controllers/v1/public/product_videos_controller.rb @@ -1,6 +1,6 @@ module V1 module Public - class ProductVideosController < ApplicationController + class ProductVideosController < V1::PublicController def index allow_index end diff --git a/app/controllers/v1/public/products_controller.rb b/app/controllers/v1/public/products_controller.rb index cd11304f..f73eb750 100644 --- a/app/controllers/v1/public/products_controller.rb +++ b/app/controllers/v1/public/products_controller.rb @@ -1,6 +1,6 @@ module V1 module Public - class ProductsController < ApplicationController + class ProductsController < V1::PublicController def index allow_index end diff --git a/app/controllers/v1/public/qualities_controller.rb b/app/controllers/v1/public/qualities_controller.rb index 4fd586cd..01b123b3 100644 --- a/app/controllers/v1/public/qualities_controller.rb +++ b/app/controllers/v1/public/qualities_controller.rb @@ -1,6 +1,6 @@ module V1 module Public - class QualitiesController < ApplicationController + class QualitiesController < V1::PublicController def index allow_index end diff --git a/app/controllers/v1/public/sessions_controller.rb b/app/controllers/v1/public/sessions_controller.rb index 04cdf845..821467de 100644 --- a/app/controllers/v1/public/sessions_controller.rb +++ b/app/controllers/v1/public/sessions_controller.rb @@ -1,6 +1,6 @@ module V1 module Public - class SessionsController < ApplicationController + class SessionsController < V1::PublicController def index forbidden end diff --git a/app/controllers/v1/public/simulation_requests_controller.rb b/app/controllers/v1/public/simulation_requests_controller.rb index 5e97592c..472fd1d5 100644 --- a/app/controllers/v1/public/simulation_requests_controller.rb +++ b/app/controllers/v1/public/simulation_requests_controller.rb @@ -1,6 +1,6 @@ module V1 module Public - class SimulationRequestsController < ApplicationController + class SimulationRequestsController < V1::PublicController def index forbidden end diff --git a/app/controllers/v1/public/translations_controller.rb b/app/controllers/v1/public/translations_controller.rb index 25621282..e20375c0 100644 --- a/app/controllers/v1/public/translations_controller.rb +++ b/app/controllers/v1/public/translations_controller.rb @@ -1,6 +1,6 @@ module V1 module Public - class TranslationsController < ApplicationController + class TranslationsController < V1::PublicController def index allow_index end diff --git a/app/controllers/v1/public/uses_controller.rb b/app/controllers/v1/public/uses_controller.rb index 7ff54de7..de06a456 100644 --- a/app/controllers/v1/public/uses_controller.rb +++ b/app/controllers/v1/public/uses_controller.rb @@ -1,6 +1,6 @@ module V1 module Public - class UsesController < ApplicationController + class UsesController < V1::PublicController def index allow_index end diff --git a/app/controllers/v1/public/videos_controller.rb b/app/controllers/v1/public/videos_controller.rb index ab71d9f0..dae62d64 100644 --- a/app/controllers/v1/public/videos_controller.rb +++ b/app/controllers/v1/public/videos_controller.rb @@ -1,6 +1,6 @@ module V1 module Public - class VideosController < ApplicationController + class VideosController < V1::PublicController def index allow_index end diff --git a/app/controllers/v1/public/webinar_attendees_controller.rb b/app/controllers/v1/public/webinar_attendees_controller.rb index 333874c3..193634c9 100644 --- a/app/controllers/v1/public/webinar_attendees_controller.rb +++ b/app/controllers/v1/public/webinar_attendees_controller.rb @@ -1,6 +1,6 @@ module V1 module Public - class WebinarAttendeesController < ApplicationController + class WebinarAttendeesController < V1::PublicController def index # TODO: only allow current user index allow_index diff --git a/app/controllers/v1/public/webinars_controller.rb b/app/controllers/v1/public/webinars_controller.rb index afb032f4..d06ff9c4 100644 --- a/app/controllers/v1/public/webinars_controller.rb +++ b/app/controllers/v1/public/webinars_controller.rb @@ -1,6 +1,6 @@ module V1 module Public - class WebinarsController < ApplicationController + class WebinarsController < V1::PublicController def index allow_index end diff --git a/app/controllers/v1/public_controller.rb b/app/controllers/v1/public_controller.rb index fae6bb1a..4ebdff78 100644 --- a/app/controllers/v1/public_controller.rb +++ b/app/controllers/v1/public_controller.rb @@ -1,4 +1,33 @@ module V1 class PublicController < ApplicationController + before_action :create_visit + + private + + def create_visit + id = request.headers['Visit-ID'] + + return nil if id.nil? + + record = Visit.find_by(id: id) + + if record.nil? + Visit.create!( + id: id, + start_time: DateTime.current, + user_agent_ssr: request.headers['SSR-User-Agent'] + ) + log.debug '🌈 visit created' + elsif !record.user_agent? || !request.browser_width + Visit.update( + user_agent: request.user_agent, + browser_width: request.headers['Browser-Width'], + browser_height: request.headers['Browser-Height'] + ) + log.debug '🌳 visit updated' + else + log.debug '❌ doing nothing' + end + end end end diff --git a/app/models/visit.rb b/app/models/visit.rb new file mode 100644 index 00000000..d4d8246e --- /dev/null +++ b/app/models/visit.rb @@ -0,0 +1,14 @@ +class Visit < ApplicationRecord + belongs_to :user, optional: true + # TODO: belongs_to :monthly_visitor_report + + # TODO: interpret the user agent + def is_robot + false + end + + # TODO: interpret the user, IP and ISP + def is_interflux + false + end +end diff --git a/config/routes.rb b/config/routes.rb index 77f001d0..4730bb94 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -9,11 +9,13 @@ # such as scrapers and bots, to read from them. # # Used by: - # https://app.interflux.com - # https://www.interflux.com - # https://lmpa.interflux.com + # https://interflux.com + # https://interflux.de + # https://interflux.fr + # https://interflux.es + # https://interflux.group + # https://lmpa-q.com # - namespace :public do resources :article_categories, path: '/article-categories' resources :articles diff --git a/db/migrate/20240121003248_create_visits.rb b/db/migrate/20240121003248_create_visits.rb new file mode 100644 index 00000000..3bde89ab --- /dev/null +++ b/db/migrate/20240121003248_create_visits.rb @@ -0,0 +1,16 @@ +class CreateVisits < ActiveRecord::Migration[6.1] + def change + create_table :visits, id: :uuid do |t| + t.string :ip + t.string :ip_isp + t.string :ip_country + t.string :user_agent + t.string :user_agent_ssr + t.string :browser_width + t.string :browser_height + t.datetime :start_time + t.datetime :end_time + t.uuid :user_id + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 55bd96ea..cb2f2dbc 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: 2023_12_29_043350) do +ActiveRecord::Schema.define(version: 2024_01_21_003248) do # These are extensions that must be enabled in order to support this database enable_extension "pgcrypto" @@ -552,6 +552,19 @@ t.datetime "updated_at", precision: 6, null: false end + create_table "visits", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| + t.string "ip" + t.string "ip_isp" + t.string "ip_country" + t.string "user_agent" + t.string "user_agent_ssr" + t.string "browser_width" + t.string "browser_height" + t.datetime "start_time" + t.datetime "end_time" + t.uuid "user_id" + end + create_table "webinar_attendees", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| t.uuid "webinar_id" t.uuid "person_id" diff --git a/test/fixtures/visits.yml b/test/fixtures/visits.yml new file mode 100644 index 00000000..51816369 --- /dev/null +++ b/test/fixtures/visits.yml @@ -0,0 +1,11 @@ +# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +# This model initially had no columns defined. If you add columns to the +# model remove the '{}' from the fixture names and add the columns immediately +# below each fixture, per the syntax in the comments below +# +one: {} +# column: value +# +two: {} +# column: value diff --git a/test/models/visit_test.rb b/test/models/visit_test.rb new file mode 100644 index 00000000..2e6cc98c --- /dev/null +++ b/test/models/visit_test.rb @@ -0,0 +1,7 @@ +require "test_helper" + +class VisitTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end From fdb38175cb5efb179f43b324bfd04241f77f8947 Mon Sep 17 00:00:00 2001 From: Jan Werkhoven Date: Sat, 10 Feb 2024 21:02:07 +1100 Subject: [PATCH 02/12] WIP --- .../concerns/json_api_controller.rb | 9 +- .../admin/client_side_renders_controller.rb | 84 +++++++++++++++++++ .../v1/admin/page_views_controller.rb | 84 +++++++++++++++++++ .../admin/server_side_renders_controller.rb | 84 +++++++++++++++++++ app/controllers/v1/admin/visits_controller.rb | 84 +++++++++++++++++++ .../public/client_side_renders_controller.rb | 54 ++++++++++++ .../v1/public/page_views_controller.rb | 84 +++++++++++++++++++ .../public/server_side_renders_controller.rb | 50 +++++++++++ app/models/article.rb | 19 +++++ app/models/article_category.rb | 15 ++++ app/models/article_tag.rb | 15 ++++ app/models/cdn_file.rb | 19 +++++ app/models/client_side_render.rb | 20 +++++ app/models/company.rb | 42 ++++++++++ app/models/company_market.rb | 13 +++ app/models/company_member.rb | 26 ++++++ app/models/container.rb | 13 +++ app/models/country.rb | 22 +++++ app/models/country_currency.rb | 15 ++++ app/models/country_language.rb | 15 ++++ app/models/currency.rb | 10 +++ app/models/document.rb | 24 +++--- app/models/document_category.rb | 13 +++ app/models/employee.rb | 15 ++++ app/models/event.rb | 15 ++++ app/models/feature.rb | 13 +++ app/models/image.rb | 16 ++++ app/models/language.rb | 12 +++ app/models/lead.rb | 25 ++++++ app/models/page_view.rb | 12 +++ app/models/permalink.rb | 9 ++ app/models/person.rb | 20 +++++ app/models/person_image.rb | 10 +++ app/models/product.rb | 35 ++++++++ app/models/product_complement.rb | 15 ++++ app/models/product_document.rb | 12 +++ app/models/product_family.rb | 14 ++++ app/models/product_family_image.rb | 12 +++ app/models/product_feature.rb | 10 +++ app/models/product_image.rb | 12 +++ app/models/product_quality.rb | 14 ++++ app/models/product_related_article.rb | 15 ++++ app/models/product_substitute.rb | 15 ++++ app/models/product_use.rb | 15 ++++ app/models/product_video.rb | 10 +++ app/models/quality.rb | 12 +++ app/models/server_side_render.rb | 16 ++++ app/models/session.rb | 23 +++++ app/models/simulation_request.rb | 24 ++++++ app/models/tag.rb | 14 ++++ app/models/translation.rb | 21 +++++ app/models/use.rb | 13 +++ app/models/use_image.rb | 12 +++ app/models/user.rb | 16 ++++ app/models/video.rb | 11 +++ app/models/visit.rb | 31 +++++-- app/models/webinar.rb | 19 +++++ app/models/webinar_attendee.rb | 10 +++ app/models/webinar_image.rb | 10 +++ app/models/webinar_invitee.rb | 10 +++ app/models/webinar_video.rb | 10 +++ .../v1/admin/client_side_render_serializer.rb | 16 ++++ .../v1/admin/page_view_serializer.rb | 10 +++ .../v1/admin/server_side_render_serializer.rb | 11 +++ app/serializers/v1/admin/visit_serializer.rb | 24 ++++++ .../public/client_side_render_serializer.rb | 6 ++ .../v1/public/page_view_serializer.rb | 6 ++ .../public/server_side_render_serializer.rb | 6 ++ config/routes.rb | 9 +- db/migrate/20240121003248_create_visits.rb | 16 ---- ...240210021834_create_server_side_renders.rb | 14 ++++ ...240210021840_create_client_side_renders.rb | 18 ++++ db/migrate/20240210021852_create_visits.rb | 22 +++++ .../20240210021903_create_page_views.rb | 9 ++ db/schema.rb | 48 +++++++++-- lib/tasks/auto_annotate_models.rake | 59 +++++++++++++ test/fixtures/article_categories.yml | 5 ++ test/fixtures/article_tags.yml | 9 +- test/fixtures/articles.yml | 11 ++- test/fixtures/cdn_files.yml | 20 +++-- test/fixtures/client_side_renders.yml | 26 ++++++ test/fixtures/companies.yml | 57 ++++++++----- test/fixtures/company_markets.yml | 13 +-- test/fixtures/company_members.yml | 33 +++++--- test/fixtures/containers.yml | 4 + test/fixtures/country_currencies.yml | 9 +- test/fixtures/country_languages.yml | 9 +- test/fixtures/document_categories.yml | 15 ++-- test/fixtures/documents.yml | 11 +-- test/fixtures/employees.yml | 9 +- test/fixtures/events.yml | 15 ++++ test/fixtures/images.yml | 20 +++-- test/fixtures/leads.yml | 19 +++-- test/fixtures/page_views.yml | 19 +++++ test/fixtures/people.yml | 25 +++--- test/fixtures/product_complements.yml | 9 +- test/fixtures/product_documents.yml | 8 +- test/fixtures/product_families.yml | 14 ++++ test/fixtures/product_qualities.yml | 10 ++- test/fixtures/product_related_articles.yml | 9 +- test/fixtures/product_substitutes.yml | 9 +- test/fixtures/product_uses.yml | 17 ++-- test/fixtures/product_videos.yml | 8 +- test/fixtures/products.yml | 47 +++++++---- test/fixtures/server_side_renders.yml | 23 +++++ test/fixtures/sessions.yml | 23 +++++ test/fixtures/simulation_requests.yml | 24 ++++++ test/fixtures/tags.yml | 6 +- test/fixtures/translations.yml | 21 +++++ test/fixtures/users.yml | 7 +- test/fixtures/videos.yml | 11 +++ test/fixtures/visits.yml | 20 ++++- test/fixtures/webinar_attendees.yml | 10 +++ test/fixtures/webinar_images.yml | 10 +++ test/fixtures/webinar_videos.yml | 10 +++ test/fixtures/webinars.yml | 25 +++--- .../client_side_renders_integration_test.rb | 9 ++ .../v1/admin/page_views_integration_test.rb | 9 ++ .../server_side_renders_integration_test.rb | 9 ++ .../v1/admin/visits_integration_test.rb | 9 ++ .../client_side_renders_integration_test.rb | 9 ++ .../v1/public/page_views_integration_test.rb | 9 ++ .../server_side_renders_integration_test.rb | 9 ++ test/models/client_side_render_test.rb | 23 +++++ test/models/page_view_test.rb | 16 ++++ test/models/product_test.rb | 35 ++++++++ test/models/server_side_render_test.rb | 20 +++++ test/models/visit_test.rb | 19 +++++ 128 files changed, 2298 insertions(+), 194 deletions(-) create mode 100644 app/controllers/v1/admin/client_side_renders_controller.rb create mode 100644 app/controllers/v1/admin/page_views_controller.rb create mode 100644 app/controllers/v1/admin/server_side_renders_controller.rb create mode 100644 app/controllers/v1/admin/visits_controller.rb create mode 100644 app/controllers/v1/public/client_side_renders_controller.rb create mode 100644 app/controllers/v1/public/page_views_controller.rb create mode 100644 app/controllers/v1/public/server_side_renders_controller.rb create mode 100644 app/models/client_side_render.rb create mode 100644 app/models/page_view.rb create mode 100644 app/models/server_side_render.rb create mode 100644 app/serializers/v1/admin/client_side_render_serializer.rb create mode 100644 app/serializers/v1/admin/page_view_serializer.rb create mode 100644 app/serializers/v1/admin/server_side_render_serializer.rb create mode 100644 app/serializers/v1/admin/visit_serializer.rb create mode 100644 app/serializers/v1/public/client_side_render_serializer.rb create mode 100644 app/serializers/v1/public/page_view_serializer.rb create mode 100644 app/serializers/v1/public/server_side_render_serializer.rb delete mode 100644 db/migrate/20240121003248_create_visits.rb create mode 100644 db/migrate/20240210021834_create_server_side_renders.rb create mode 100644 db/migrate/20240210021840_create_client_side_renders.rb create mode 100644 db/migrate/20240210021852_create_visits.rb create mode 100644 db/migrate/20240210021903_create_page_views.rb create mode 100644 lib/tasks/auto_annotate_models.rake create mode 100644 test/fixtures/client_side_renders.yml create mode 100644 test/fixtures/page_views.yml create mode 100644 test/fixtures/server_side_renders.yml create mode 100644 test/integration/v1/admin/client_side_renders_integration_test.rb create mode 100644 test/integration/v1/admin/page_views_integration_test.rb create mode 100644 test/integration/v1/admin/server_side_renders_integration_test.rb create mode 100644 test/integration/v1/admin/visits_integration_test.rb create mode 100644 test/integration/v1/public/client_side_renders_integration_test.rb create mode 100644 test/integration/v1/public/page_views_integration_test.rb create mode 100644 test/integration/v1/public/server_side_renders_integration_test.rb create mode 100644 test/models/client_side_render_test.rb create mode 100644 test/models/page_view_test.rb create mode 100644 test/models/server_side_render_test.rb diff --git a/app/controllers/concerns/json_api_controller.rb b/app/controllers/concerns/json_api_controller.rb index ad3b339c..69d8fe65 100644 --- a/app/controllers/concerns/json_api_controller.rb +++ b/app/controllers/concerns/json_api_controller.rb @@ -391,8 +391,13 @@ def forbidden_filters # allow_create # end # - def allow_create - resource = model_class.new(attributes_and_relationships) + def allow_create(controller_attributes) + hash = strong_attributes + .merge(strong_relationships) + .merge(controller_attributes) + + resource = model_class.new(hash) + if resource.save! json = serializer_class.new(resource).serializable_hash.to_json render status: 201, json: json diff --git a/app/controllers/v1/admin/client_side_renders_controller.rb b/app/controllers/v1/admin/client_side_renders_controller.rb new file mode 100644 index 00000000..765572dc --- /dev/null +++ b/app/controllers/v1/admin/client_side_renders_controller.rb @@ -0,0 +1,84 @@ +module V1 + module Admin + class ClientSideRendersController < ApplicationController + def index + allow_index + end + + def show + allow_show + end + + def create + forbidden + end + + def update + forbidden + end + + def destroy + forbidden + end + + private + + def model_class + ClientSideRender + end + + def serializer_class + V1::Admin::ClientSideRenderSerializer + end + + def creatable_attributes + %[] + # %i[ + # name + # company + # email + # mobile + # message + # purpose + # source + # ip + # ip_region + # ip_city + # ] + end + + def creatable_relationships + %[] + # %i[ + # country + # ip_country + # ] + end + + def permitted_filters + %[] + # %i[ + # main_group_id + # sub_group_id + # ] + end + + def permanent_filters + {} + # { + # public: true + # } + end + + def permitted_includes + %[] + # %i[ + # related_articles + # related_products + # related_products.main_group + # translations + # ] + end + end + end +end diff --git a/app/controllers/v1/admin/page_views_controller.rb b/app/controllers/v1/admin/page_views_controller.rb new file mode 100644 index 00000000..ca6a4236 --- /dev/null +++ b/app/controllers/v1/admin/page_views_controller.rb @@ -0,0 +1,84 @@ +module V1 + module Admin + class PageViewsController < ApplicationController + def index + allow_index + end + + def show + allow_show + end + + def create + forbidden + end + + def update + forbidden + end + + def destroy + forbidden + end + + private + + def model_class + PageView + end + + def serializer_class + V1::Admin::PageViewSerializer + end + + def creatable_attributes + %[] + # %i[ + # name + # company + # email + # mobile + # message + # purpose + # source + # ip + # ip_region + # ip_city + # ] + end + + def creatable_relationships + %[] + # %i[ + # country + # ip_country + # ] + end + + def permitted_filters + %[] + # %i[ + # main_group_id + # sub_group_id + # ] + end + + def permanent_filters + {} + # { + # public: true + # } + end + + def permitted_includes + %[] + # %i[ + # related_articles + # related_products + # related_products.main_group + # translations + # ] + end + end + end +end diff --git a/app/controllers/v1/admin/server_side_renders_controller.rb b/app/controllers/v1/admin/server_side_renders_controller.rb new file mode 100644 index 00000000..c334d077 --- /dev/null +++ b/app/controllers/v1/admin/server_side_renders_controller.rb @@ -0,0 +1,84 @@ +module V1 + module Admin + class ServerSideRendersController < ApplicationController + def index + allow_index + end + + def show + allow_show + end + + def create + forbidden + end + + def update + forbidden + end + + def destroy + forbidden + end + + private + + def model_class + ServerSideRender + end + + def serializer_class + V1::Admin::ServerSideRenderSerializer + end + + def creatable_attributes + %[] + # %i[ + # name + # company + # email + # mobile + # message + # purpose + # source + # ip + # ip_region + # ip_city + # ] + end + + def creatable_relationships + %[] + # %i[ + # country + # ip_country + # ] + end + + def permitted_filters + %[] + # %i[ + # main_group_id + # sub_group_id + # ] + end + + def permanent_filters + {} + # { + # public: true + # } + end + + def permitted_includes + %[] + # %i[ + # related_articles + # related_products + # related_products.main_group + # translations + # ] + end + end + end +end diff --git a/app/controllers/v1/admin/visits_controller.rb b/app/controllers/v1/admin/visits_controller.rb new file mode 100644 index 00000000..59332897 --- /dev/null +++ b/app/controllers/v1/admin/visits_controller.rb @@ -0,0 +1,84 @@ +module V1 + module Admin + class VisitsController < ApplicationController + def index + allow_index + end + + def show + allow_show + end + + def create + forbidden + end + + def update + forbidden + end + + def destroy + forbidden + end + + private + + def model_class + Visit + end + + def serializer_class + V1::Admin::VisitSerializer + end + + def creatable_attributes + %[] + # %i[ + # name + # company + # email + # mobile + # message + # purpose + # source + # ip + # ip_region + # ip_city + # ] + end + + def creatable_relationships + %[] + # %i[ + # country + # ip_country + # ] + end + + def permitted_filters + %[] + # %i[ + # main_group_id + # sub_group_id + # ] + end + + def permanent_filters + {} + # { + # public: true + # } + end + + def permitted_includes + %[] + # %i[ + # related_articles + # related_products + # related_products.main_group + # translations + # ] + end + end + end +end diff --git a/app/controllers/v1/public/client_side_renders_controller.rb b/app/controllers/v1/public/client_side_renders_controller.rb new file mode 100644 index 00000000..40604472 --- /dev/null +++ b/app/controllers/v1/public/client_side_renders_controller.rb @@ -0,0 +1,54 @@ +module V1 + module Public + class ClientSideRendersController < ApplicationController + def index + forbidden + end + + def show + forbidden + end + + def create + allow_create({ ip: request.remote_ip }) + end + + def update + forbidden + end + + def destroy + forbidden + end + + private + + def model_class + ClientSideRender + end + + def serializer_class + V1::Public::ClientSideRenderSerializer + end + + def creatable_attributes + %i[ + visit_id + host + referrer + user_agent + viewport_width + viewport_height + user_id + ] + end + + def creatable_relationships + %[ + visit + user + ] + end + end + end +end diff --git a/app/controllers/v1/public/page_views_controller.rb b/app/controllers/v1/public/page_views_controller.rb new file mode 100644 index 00000000..4d1f5f67 --- /dev/null +++ b/app/controllers/v1/public/page_views_controller.rb @@ -0,0 +1,84 @@ +module V1 + module Public + class PageViewsController < ApplicationController + def index + allow_index + end + + def show + allow_show + end + + def create + forbidden + end + + def update + forbidden + end + + def destroy + forbidden + end + + private + + def model_class + PageView + end + + def serializer_class + V1::Public::PageViewSerializer + end + + def creatable_attributes + %[] + # %i[ + # name + # company + # email + # mobile + # message + # purpose + # source + # ip + # ip_region + # ip_city + # ] + end + + def creatable_relationships + %[] + # %i[ + # country + # ip_country + # ] + end + + def permitted_filters + %[] + # %i[ + # main_group_id + # sub_group_id + # ] + end + + def permanent_filters + {} + # { + # public: true + # } + end + + def permitted_includes + %[] + # %i[ + # related_articles + # related_products + # related_products.main_group + # translations + # ] + end + end + end +end diff --git a/app/controllers/v1/public/server_side_renders_controller.rb b/app/controllers/v1/public/server_side_renders_controller.rb new file mode 100644 index 00000000..1a0ec78a --- /dev/null +++ b/app/controllers/v1/public/server_side_renders_controller.rb @@ -0,0 +1,50 @@ +module V1 + module Public + class ServerSideRendersController < ApplicationController + def index + forbidden + end + + def show + forbidden + end + + def create + allow_create({ ip: request.remote_ip }) + end + + def update + forbidden + end + + def destroy + forbidden + end + + private + + def model_class + ServerSideRender + end + + def serializer_class + V1::Public::ServerSideRenderSerializer + end + + def creatable_attributes + %i[ + visit_id + host + referrer + user_agent + ] + end + + def creatable_relationships + %[ + visit + ] + end + end + end +end diff --git a/app/models/article.rb b/app/models/article.rb index 26e45898..d30f176d 100644 --- a/app/models/article.rb +++ b/app/models/article.rb @@ -1,3 +1,22 @@ +# == Schema Information +# +# Table name: articles +# +# id :uuid not null, primary key +# body :text +# date :date +# public :boolean default(FALSE) +# slug :string +# title :string +# created_at :datetime not null +# updated_at :datetime not null +# article_category_id :uuid +# +# Indexes +# +# index_articles_on_slug (slug) UNIQUE +# index_articles_on_title (title) UNIQUE +# class Article < ApplicationRecord belongs_to :article_category alias_attribute :category, :article_category diff --git a/app/models/article_category.rb b/app/models/article_category.rb index 8ed306bb..6a8bcfee 100644 --- a/app/models/article_category.rb +++ b/app/models/article_category.rb @@ -1,3 +1,18 @@ +# == Schema Information +# +# Table name: article_categories +# +# id :uuid not null, primary key +# name :string +# slug :string +# created_at :datetime not null +# updated_at :datetime not null +# +# Indexes +# +# index_article_categories_on_name (name) UNIQUE +# index_article_categories_on_slug (slug) UNIQUE +# class ArticleCategory < ApplicationRecord has_many :articles end diff --git a/app/models/article_tag.rb b/app/models/article_tag.rb index 23d562b9..d2b96d69 100644 --- a/app/models/article_tag.rb +++ b/app/models/article_tag.rb @@ -1,3 +1,18 @@ +# == Schema Information +# +# Table name: article_tags +# +# id :uuid not null, primary key +# created_at :datetime not null +# updated_at :datetime not null +# article_id :uuid +# tag_id :uuid +# +# Indexes +# +# index_article_tags_on_article_id (article_id) +# index_article_tags_on_tag_id (tag_id) +# class ArticleTag < ApplicationRecord # Relate to a model # belongs_to :company diff --git a/app/models/cdn_file.rb b/app/models/cdn_file.rb index 3b211711..c46ad8d3 100644 --- a/app/models/cdn_file.rb +++ b/app/models/cdn_file.rb @@ -1,3 +1,22 @@ +# == Schema Information +# +# Table name: cdn_files +# +# id :uuid not null, primary key +# locale :string +# original_file_name :string +# path :string +# created_at :datetime not null +# updated_at :datetime not null +# document_id :string +# image_id :string +# user_id :uuid +# video_id :string +# +# Indexes +# +# index_cdn_files_on_path (path) +# class CdnFile < ApplicationRecord validates :path, uniqueness: true, allow_blank: true diff --git a/app/models/client_side_render.rb b/app/models/client_side_render.rb new file mode 100644 index 00000000..a213534a --- /dev/null +++ b/app/models/client_side_render.rb @@ -0,0 +1,20 @@ +# == Schema Information +# +# Table name: client_side_renders +# +# id :uuid not null, primary key +# host :string +# ip :string +# referrer :string +# user_agent :string +# viewport_height :integer +# viewport_width :integer +# created_at :datetime not null +# updated_at :datetime not null +# user_id :uuid +# visit_id :uuid +# +class ClientSideRender < ApplicationRecord + belongs_to :visit, optional: true, dependent: nil + belongs_to :user, optional: true +end diff --git a/app/models/company.rb b/app/models/company.rb index 7b460212..3a017ce4 100644 --- a/app/models/company.rb +++ b/app/models/company.rb @@ -1,3 +1,45 @@ +# == Schema Information +# +# Table name: companies +# +# id :uuid not null, primary key +# address :string +# business_name :string +# core_activity :string +# description :text +# email_accounting :string +# email_general :string +# email_orders :string +# email_support :string +# emails :string +# fax :string +# head_count :integer default(1) +# history :string +# is_headquarter :boolean default(FALSE) +# latitude :decimal(, ) +# legal_name :string +# longitude :decimal(, ) +# notes :text +# order :integer +# phone :string +# public :boolean +# rank_on_group_website :integer default(999) +# show_markets :boolean default(TRUE) +# shown_on_group_website :boolean default(FALSE) +# shown_on_icsf_website :boolean default(FALSE) +# shown_on_main_website :boolean default(FALSE) +# slug :string +# website :string +# created_at :datetime not null +# updated_at :datetime not null +# country_id :string +# +# Indexes +# +# index_companies_on_business_name (business_name) UNIQUE +# index_companies_on_country_id (country_id) +# index_companies_on_slug (slug) UNIQUE +# class Company < ApplicationRecord belongs_to :country, optional: true diff --git a/app/models/company_market.rb b/app/models/company_market.rb index 131a530e..c4a2c5ad 100644 --- a/app/models/company_market.rb +++ b/app/models/company_market.rb @@ -1,3 +1,16 @@ +# == Schema Information +# +# Table name: company_markets +# +# id :uuid not null, primary key +# company_is_recommended :boolean default(FALSE) +# rank_among_companies :integer +# rank_among_countries :integer +# created_at :datetime not null +# updated_at :datetime not null +# company_id :uuid +# country_id :string +# class CompanyMarket < ApplicationRecord belongs_to :company belongs_to :country diff --git a/app/models/company_member.rb b/app/models/company_member.rb index 0d18de62..9039d3ea 100644 --- a/app/models/company_member.rb +++ b/app/models/company_member.rb @@ -1,3 +1,29 @@ +# == Schema Information +# +# Table name: company_members +# +# id :uuid not null, primary key +# email :string +# landline :string +# phone :string +# public :boolean default(FALSE) +# public_email :boolean default(FALSE) +# public_landline :boolean default(FALSE) +# public_phone :boolean default(FALSE) +# public_title :boolean default(FALSE) +# rank_among_companies :integer +# rank_among_members :integer +# title :string +# created_at :datetime not null +# updated_at :datetime not null +# company_id :uuid +# person_id :uuid +# +# Indexes +# +# index_company_members_on_company_id (company_id) +# index_company_members_on_person_id (person_id) +# class CompanyMember < ApplicationRecord belongs_to :company belongs_to :person diff --git a/app/models/container.rb b/app/models/container.rb index 86d9d970..312cba6a 100644 --- a/app/models/container.rb +++ b/app/models/container.rb @@ -1,3 +1,16 @@ +# == Schema Information +# +# Table name: containers +# +# id :uuid not null, primary key +# name :string +# created_at :datetime not null +# updated_at :datetime not null +# +# Indexes +# +# index_containers_on_name (name) UNIQUE +# class Container < ApplicationRecord has_many :product_variants diff --git a/app/models/country.rb b/app/models/country.rb index 0c049c87..adcd9790 100644 --- a/app/models/country.rb +++ b/app/models/country.rb @@ -1,3 +1,25 @@ +# == Schema Information +# +# Table name: countries +# +# area :integer +# calling_codes :string +# flag_url :string +# latitude :decimal(, ) +# longitude :decimal(, ) +# name_english :string +# name_native :string +# numeric_code :string +# population :integer +# region :string +# subregion :string +# three_letter_code :string +# timezones :string +# top_level_domains :string +# two_letter_code :string not null, primary key +# created_at :datetime not null +# updated_at :datetime not null +# class Country < ApplicationRecord has_many :country_languages, dependent: :destroy has_many :languages, through: :country_languages, source: :language diff --git a/app/models/country_currency.rb b/app/models/country_currency.rb index 47d6325d..a652d20c 100644 --- a/app/models/country_currency.rb +++ b/app/models/country_currency.rb @@ -1,3 +1,18 @@ +# == Schema Information +# +# Table name: country_currencies +# +# id :uuid not null, primary key +# created_at :datetime not null +# updated_at :datetime not null +# country_id :uuid +# currency_id :uuid +# +# Indexes +# +# index_country_currencies_on_country_id (country_id) +# index_country_currencies_on_currency_id (currency_id) +# class CountryCurrency < ApplicationRecord belongs_to :country belongs_to :currency diff --git a/app/models/country_language.rb b/app/models/country_language.rb index 59114de7..81d65704 100644 --- a/app/models/country_language.rb +++ b/app/models/country_language.rb @@ -1,3 +1,18 @@ +# == Schema Information +# +# Table name: country_languages +# +# id :uuid not null, primary key +# created_at :datetime not null +# updated_at :datetime not null +# country_id :string +# language_id :string +# +# Indexes +# +# index_country_languages_on_country_id (country_id) +# index_country_languages_on_language_id (language_id) +# class CountryLanguage < ApplicationRecord belongs_to :country belongs_to :language diff --git a/app/models/currency.rb b/app/models/currency.rb index 449468c0..67db11fd 100644 --- a/app/models/currency.rb +++ b/app/models/currency.rb @@ -1,3 +1,13 @@ +# == Schema Information +# +# Table name: currencies +# +# code :string not null, primary key +# name :string +# symbol :string +# created_at :datetime not null +# updated_at :datetime not null +# class Currency < ApplicationRecord # Relate to a model # belongs_to :company diff --git a/app/models/document.rb b/app/models/document.rb index 66df668e..2eedbc58 100644 --- a/app/models/document.rb +++ b/app/models/document.rb @@ -1,13 +1,17 @@ -# create_table "documents", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| -# t.string "path", null: false -# t.string "name" -# t.string "language_id" -# t.string "document_category_id" -# t.datetime "created_at", null: false -# t.datetime "updated_at", null: false -# t.string "variations" -# t.boolean "public", default: false -# end +# == Schema Information +# +# Table name: documents +# +# id :uuid not null, primary key +# name :string +# path :string not null +# public :boolean default(FALSE) +# variations :string +# created_at :datetime not null +# updated_at :datetime not null +# document_category_id :string +# language_id :string +# class Document < ApplicationRecord belongs_to :document_category, optional: true diff --git a/app/models/document_category.rb b/app/models/document_category.rb index 6410c075..72430a78 100644 --- a/app/models/document_category.rb +++ b/app/models/document_category.rb @@ -1,3 +1,16 @@ +# == Schema Information +# +# Table name: document_categories +# +# gist :string +# icon :string +# name :string +# name_single :string +# order :integer +# slug :string not null, primary key +# created_at :datetime not null +# updated_at :datetime not null +# class DocumentCategory < ApplicationRecord has_many :documents end diff --git a/app/models/employee.rb b/app/models/employee.rb index fdac3306..fb921c24 100644 --- a/app/models/employee.rb +++ b/app/models/employee.rb @@ -1,3 +1,18 @@ +# == Schema Information +# +# Table name: employees +# +# id :uuid not null, primary key +# created_at :datetime not null +# updated_at :datetime not null +# company_id :uuid +# person_id :uuid +# +# Indexes +# +# index_employees_on_company_id (company_id) +# index_employees_on_person_id (person_id) +# class Employee < ApplicationRecord # Relate to a model # belongs_to :company diff --git a/app/models/event.rb b/app/models/event.rb index 3c5e9f0f..f7308a0c 100644 --- a/app/models/event.rb +++ b/app/models/event.rb @@ -1,3 +1,18 @@ +# == Schema Information +# +# Table name: events +# +# id :uuid not null, primary key +# city :string +# dates :string +# description :string +# end_date :string +# name :string +# start_date :string +# created_at :datetime not null +# updated_at :datetime not null +# country_id :string +# class Event < ApplicationRecord belongs_to :country end diff --git a/app/models/feature.rb b/app/models/feature.rb index 051999a7..eb7bf57c 100644 --- a/app/models/feature.rb +++ b/app/models/feature.rb @@ -1,3 +1,16 @@ +# == Schema Information +# +# Table name: features +# +# category :string +# gist :string +# has_page :boolean +# icon :string +# slug :string not null, primary key +# text :string +# created_at :datetime not null +# updated_at :datetime not null +# class Feature < ApplicationRecord has_many :product_features, dependent: :destroy has_many :products, through: :product_features, source: :product diff --git a/app/models/image.rb b/app/models/image.rb index 4407f38f..121b6565 100644 --- a/app/models/image.rb +++ b/app/models/image.rb @@ -1,3 +1,19 @@ +# == Schema Information +# +# Table name: images +# +# alt :string +# caption :string +# conversion_error_log :string +# converting :boolean +# original :string +# path :string not null, primary key +# variations :string +# created_at :datetime not null +# updated_at :datetime not null +# company_id :uuid +# user_id :uuid +# class Image < ApplicationRecord # key :path, String, ID # key :original, String diff --git a/app/models/language.rb b/app/models/language.rb index 9f806b07..ebd73b19 100644 --- a/app/models/language.rb +++ b/app/models/language.rb @@ -1,3 +1,15 @@ +# == Schema Information +# +# Table name: languages +# +# name_english :string +# name_native :string +# public :boolean default(FALSE) +# three_letter_code :string +# two_letter_code :string not null, primary key +# created_at :datetime not null +# updated_at :datetime not null +# class Language < ApplicationRecord has_many :country_languages, dependent: :destroy has_many :countries, through: :country_languages, source: :country diff --git a/app/models/lead.rb b/app/models/lead.rb index 58b64509..d4f65b56 100644 --- a/app/models/lead.rb +++ b/app/models/lead.rb @@ -1,3 +1,28 @@ +# == Schema Information +# +# Table name: leads +# +# id :uuid not null, primary key +# company :string +# email :string +# ip :string +# ip_city :string +# ip_region :string +# message :text +# mobile :string +# name :string +# purpose :string +# source :string +# created_at :datetime not null +# updated_at :datetime not null +# country_id :uuid +# ip_country_id :uuid +# +# Indexes +# +# index_leads_on_country_id (country_id) +# index_leads_on_ip_country_id (ip_country_id) +# class Lead < ApplicationRecord # Relate to a model # belongs_to :company diff --git a/app/models/page_view.rb b/app/models/page_view.rb new file mode 100644 index 00000000..c7572e46 --- /dev/null +++ b/app/models/page_view.rb @@ -0,0 +1,12 @@ +# == Schema Information +# +# Table name: page_views +# +# id :uuid not null, primary key +# path :string +# created_at :datetime not null +# updated_at :datetime not null +# +class PageView < ApplicationRecord + belongs_to :visit +end diff --git a/app/models/permalink.rb b/app/models/permalink.rb index e904fca9..c8fa0fd0 100644 --- a/app/models/permalink.rb +++ b/app/models/permalink.rb @@ -1,3 +1,12 @@ +# == Schema Information +# +# Table name: permalinks +# +# id :uuid not null, primary key +# notes :string +# redirect_to :string +# slug :string +# class Permalink < ApplicationRecord # attr :redirect_from # attr :redirect_to diff --git a/app/models/person.rb b/app/models/person.rb index 281e2e12..4be8cb8a 100644 --- a/app/models/person.rb +++ b/app/models/person.rb @@ -1,3 +1,23 @@ +# == Schema Information +# +# Table name: people +# +# id :uuid not null, primary key +# avatar_alt :string +# avatar_caption :string +# avatar_path :string +# avatar_variations :string +# chinese_name :string +# email :string +# first_name :string +# full_name :string +# last_name :string +# male :boolean +# phone :string +# created_at :datetime not null +# updated_at :datetime not null +# image_id :string +# class Person < ApplicationRecord has_one :user diff --git a/app/models/person_image.rb b/app/models/person_image.rb index 83faca44..1477621f 100644 --- a/app/models/person_image.rb +++ b/app/models/person_image.rb @@ -1,3 +1,13 @@ +# == Schema Information +# +# Table name: person_images +# +# id :uuid not null, primary key +# created_at :datetime not null +# updated_at :datetime not null +# image_id :string +# person_id :uuid +# class PersonImage < ApplicationRecord belongs_to :person belongs_to :image diff --git a/app/models/product.rb b/app/models/product.rb index 85a65acb..ae69b960 100644 --- a/app/models/product.rb +++ b/app/models/product.rb @@ -1,3 +1,38 @@ +# == Schema Information +# +# Table name: products +# +# avatar_alt :string +# avatar_caption :string +# avatar_path :string +# avatar_variations :string +# complies_with_iec :boolean +# complies_with_ipcjstd004_a :boolean +# complies_with_ipcjstd004_b :boolean +# complies_with_ipcjstd005 :boolean +# complies_with_iso :boolean +# complies_with_rohs :boolean +# front_page_rank :integer default(9) +# instructions :string +# label :string +# name :string +# on_front_page :boolean default(FALSE) +# pitch :text +# properties :text +# public :boolean default(FALSE) +# rank_among_family :integer +# slug :string not null, primary key +# status :string default("offline") +# summary :string +# test_results :string +# created_at :datetime not null +# updated_at :datetime not null +# image_id :string +# main_family_id :string +# product_family_id :string +# sub_family_id :string +# superior_product_id :string +# class Product < ApplicationRecord # key: label diff --git a/app/models/product_complement.rb b/app/models/product_complement.rb index c77725a2..036a24ec 100644 --- a/app/models/product_complement.rb +++ b/app/models/product_complement.rb @@ -1,3 +1,18 @@ +# == Schema Information +# +# Table name: product_complements +# +# id :uuid not null, primary key +# created_at :datetime not null +# updated_at :datetime not null +# complement_id :uuid +# product_id :uuid +# +# Indexes +# +# index_product_complements_on_complement_id (complement_id) +# index_product_complements_on_product_id (product_id) +# class ProductComplement < ApplicationRecord belongs_to :product belongs_to :complement, class_name: 'Product', foreign_key: 'complement_id' diff --git a/app/models/product_document.rb b/app/models/product_document.rb index de77242f..ea21dd21 100644 --- a/app/models/product_document.rb +++ b/app/models/product_document.rb @@ -1,3 +1,15 @@ +# == Schema Information +# +# Table name: product_documents +# +# id :uuid not null, primary key +# rank_among_documents :integer +# rank_among_products :integer +# created_at :datetime not null +# updated_at :datetime not null +# document_id :uuid +# product_id :string +# class ProductDocument < ApplicationRecord belongs_to :product belongs_to :document diff --git a/app/models/product_family.rb b/app/models/product_family.rb index 963c43e6..fdb0c241 100644 --- a/app/models/product_family.rb +++ b/app/models/product_family.rb @@ -1,3 +1,17 @@ +# == Schema Information +# +# Table name: product_families +# +# gist :string +# name_plural :string +# name_single :string +# rank :integer +# slug :string not null, primary key +# the_full_monty :string +# created_at :datetime not null +# updated_at :datetime not null +# product_family_id :string +# class ProductFamily < ApplicationRecord belongs_to :product_family, optional: true alias_attribute :parent, :product_family diff --git a/app/models/product_family_image.rb b/app/models/product_family_image.rb index 66436eed..cf417d4a 100644 --- a/app/models/product_family_image.rb +++ b/app/models/product_family_image.rb @@ -1,3 +1,15 @@ +# == Schema Information +# +# Table name: product_family_images +# +# id :uuid not null, primary key +# rank_among_families :integer +# rank_among_images :integer +# created_at :datetime not null +# updated_at :datetime not null +# image_id :string +# product_family_id :string +# class ProductFamilyImage < ApplicationRecord belongs_to :product_family belongs_to :image diff --git a/app/models/product_feature.rb b/app/models/product_feature.rb index 325e262b..1e9a5c32 100644 --- a/app/models/product_feature.rb +++ b/app/models/product_feature.rb @@ -1,3 +1,13 @@ +# == Schema Information +# +# Table name: product_features +# +# id :uuid not null, primary key +# created_at :datetime not null +# updated_at :datetime not null +# feature_id :string +# product_id :string +# class ProductFeature < ApplicationRecord belongs_to :product belongs_to :feature diff --git a/app/models/product_image.rb b/app/models/product_image.rb index d96c8748..c360317b 100644 --- a/app/models/product_image.rb +++ b/app/models/product_image.rb @@ -1,3 +1,15 @@ +# == Schema Information +# +# Table name: product_images +# +# id :uuid not null, primary key +# public :boolean +# rank :integer +# created_at :datetime not null +# updated_at :datetime not null +# image_id :string +# product_id :string +# class ProductImage < ApplicationRecord belongs_to :product belongs_to :image diff --git a/app/models/product_quality.rb b/app/models/product_quality.rb index 2285d032..690e6955 100644 --- a/app/models/product_quality.rb +++ b/app/models/product_quality.rb @@ -1,3 +1,17 @@ +# == Schema Information +# +# Table name: product_qualities +# +# id :uuid not null, primary key +# rank :integer +# rank_among_products :integer +# rank_among_qualities :integer +# show_on_product_list :boolean +# created_at :datetime not null +# updated_at :datetime not null +# product_id :string +# quality_id :string +# class ProductQuality < ApplicationRecord belongs_to :product belongs_to :quality diff --git a/app/models/product_related_article.rb b/app/models/product_related_article.rb index 72be3e4f..022c850d 100644 --- a/app/models/product_related_article.rb +++ b/app/models/product_related_article.rb @@ -1,3 +1,18 @@ +# == Schema Information +# +# Table name: product_related_articles +# +# id :uuid not null, primary key +# created_at :datetime not null +# updated_at :datetime not null +# article_id :uuid +# product_id :uuid +# +# Indexes +# +# index_product_related_articles_on_article_id (article_id) +# index_product_related_articles_on_product_id (product_id) +# class ProductRelatedArticle < ApplicationRecord belongs_to :product belongs_to :article diff --git a/app/models/product_substitute.rb b/app/models/product_substitute.rb index de05cdd4..6f6375e6 100644 --- a/app/models/product_substitute.rb +++ b/app/models/product_substitute.rb @@ -1,3 +1,18 @@ +# == Schema Information +# +# Table name: product_substitutes +# +# id :uuid not null, primary key +# created_at :datetime not null +# updated_at :datetime not null +# product_id :uuid +# substitute_id :uuid +# +# Indexes +# +# index_product_substitutes_on_product_id (product_id) +# index_product_substitutes_on_substitute_id (substitute_id) +# class ProductSubstitute < ApplicationRecord belongs_to :product belongs_to :substitute, class_name: 'Product', foreign_key: 'substitute_id' diff --git a/app/models/product_use.rb b/app/models/product_use.rb index e8d2a095..ec1d17fe 100644 --- a/app/models/product_use.rb +++ b/app/models/product_use.rb @@ -1,3 +1,18 @@ +# == Schema Information +# +# Table name: product_uses +# +# id :uuid not null, primary key +# rank_among_products :integer +# rank_among_uses :integer +# show_alternative_avatar :boolean default(FALSE) +# show_on_product_list :boolean +# created_at :datetime not null +# updated_at :datetime not null +# image_id :string +# product_id :string +# use_id :string +# class ProductUse < ApplicationRecord belongs_to :product belongs_to :use diff --git a/app/models/product_video.rb b/app/models/product_video.rb index 248b3b4f..cf1d4ecf 100644 --- a/app/models/product_video.rb +++ b/app/models/product_video.rb @@ -1,3 +1,13 @@ +# == Schema Information +# +# Table name: product_videos +# +# id :uuid not null, primary key +# public :boolean +# rank :integer +# product_id :string +# video_id :string +# class ProductVideo < ApplicationRecord belongs_to :product belongs_to :video diff --git a/app/models/quality.rb b/app/models/quality.rb index 62331510..25de30ac 100644 --- a/app/models/quality.rb +++ b/app/models/quality.rb @@ -1,3 +1,15 @@ +# == Schema Information +# +# Table name: qualities +# +# gist :text +# icon :string +# slug :string not null, primary key +# text :string +# created_at :datetime not null +# updated_at :datetime not null +# image_id :string +# class Quality < ApplicationRecord belongs_to :image, optional: true diff --git a/app/models/server_side_render.rb b/app/models/server_side_render.rb new file mode 100644 index 00000000..6775655c --- /dev/null +++ b/app/models/server_side_render.rb @@ -0,0 +1,16 @@ +# == Schema Information +# +# Table name: server_side_renders +# +# id :uuid not null, primary key +# host :string +# ip :string +# referrer :string +# user_agent :string +# created_at :datetime not null +# updated_at :datetime not null +# visit_id :uuid +# +class ServerSideRender < ApplicationRecord + belongs_to :visit, optional: true, dependent: nil +end diff --git a/app/models/session.rb b/app/models/session.rb index 71930475..5c607e5a 100644 --- a/app/models/session.rb +++ b/app/models/session.rb @@ -1,3 +1,26 @@ +# == Schema Information +# +# Table name: sessions +# +# id :uuid not null, primary key +# browser_app :string +# browser_height :string +# browser_languages :string +# browser_width :string +# href :string +# ip :string +# ip_isp :string +# ip_request_duration :integer +# ip_response_body :string +# ip_response_code :string +# ip_timezone :string +# is_interflux_member :boolean default(FALSE) +# referrer :string +# created_at :datetime not null +# updated_at :datetime not null +# ip_country_id :string +# user_id :uuid +# class Session < ApplicationRecord belongs_to :user, optional: true belongs_to :country, class_name: 'Country', foreign_key: 'ip_country_id', optional: true diff --git a/app/models/simulation_request.rb b/app/models/simulation_request.rb index f8f004eb..23ea217b 100644 --- a/app/models/simulation_request.rb +++ b/app/models/simulation_request.rb @@ -1,3 +1,27 @@ +# == Schema Information +# +# Table name: simulation_requests +# +# id :uuid not null, primary key +# board_reference :string +# company_name :string +# cycle_time :string +# email :string +# flux_brand :string +# flux_consumption :string +# flux_process :string +# full_name :string +# image :string +# known_issue :string +# pallet_length :string +# pallet_width :string +# project_name :string +# sequence :integer +# solder_process :string +# wave_speed :string +# created_at :datetime not null +# updated_at :datetime not null +# class SimulationRequest < ApplicationRecord after_create :send_email_to_singapore diff --git a/app/models/tag.rb b/app/models/tag.rb index 50171eca..e2e1d166 100644 --- a/app/models/tag.rb +++ b/app/models/tag.rb @@ -1,3 +1,17 @@ +# == Schema Information +# +# Table name: tags +# +# id :uuid not null, primary key +# name :string +# slug :string +# created_at :datetime not null +# updated_at :datetime not null +# +# Indexes +# +# index_tags_on_slug (slug) UNIQUE +# class Tag < ApplicationRecord # Relate to a model # belongs_to :company diff --git a/app/models/translation.rb b/app/models/translation.rb index 712a2fef..2c3da363 100644 --- a/app/models/translation.rb +++ b/app/models/translation.rb @@ -1,3 +1,24 @@ +# == Schema Information +# +# Table name: translations +# +# id :uuid not null, primary key +# english :string +# english_before :text +# error :string +# language :string +# location :string +# native :string +# status :string +# created_at :datetime not null +# updated_at :datetime not null +# +# Indexes +# +# index_translations_on_language (language) +# index_translations_on_location (location) +# unique_location_per_language_index (language,location) UNIQUE +# class Translation < ApplicationRecord validates :location, uniqueness: { scope: %i[language] } validates :status, inclusion: { diff --git a/app/models/use.rb b/app/models/use.rb index fe4fddc7..ef8c9da7 100644 --- a/app/models/use.rb +++ b/app/models/use.rb @@ -1,3 +1,16 @@ +# == Schema Information +# +# Table name: uses +# +# gist :text +# icon :string +# rank :integer +# slug :string not null, primary key +# text :string +# created_at :datetime not null +# updated_at :datetime not null +# image_id :string +# class Use < ApplicationRecord belongs_to :image, optional: true diff --git a/app/models/use_image.rb b/app/models/use_image.rb index cf97cecf..df976b8e 100644 --- a/app/models/use_image.rb +++ b/app/models/use_image.rb @@ -1,3 +1,15 @@ +# == Schema Information +# +# Table name: use_images +# +# id :uuid not null, primary key +# rank_among_images :integer +# rank_among_uses :integer +# created_at :datetime not null +# updated_at :datetime not null +# image_id :string +# use_id :string +# class UseImage < ApplicationRecord belongs_to :use belongs_to :image diff --git a/app/models/user.rb b/app/models/user.rb index fa0fb80e..4efb03cb 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1,3 +1,19 @@ +# == Schema Information +# +# Table name: users +# +# id :uuid not null, primary key +# abilities :string +# email :string +# password_digest :string +# created_at :datetime not null +# updated_at :datetime not null +# person_id :uuid +# +# Indexes +# +# index_users_on_email (email) UNIQUE +# class User < ApplicationRecord has_secure_password diff --git a/app/models/video.rb b/app/models/video.rb index b067a541..c489e38c 100644 --- a/app/models/video.rb +++ b/app/models/video.rb @@ -1,3 +1,14 @@ +# == Schema Information +# +# Table name: videos +# +# notes :string +# path :string not null, primary key +# title :string +# variations :string +# created_at :datetime not null +# updated_at :datetime not null +# class Video < ApplicationRecord belongs_to :webinar, optional: true has_many :product_videos, dependent: :destroy diff --git a/app/models/visit.rb b/app/models/visit.rb index d4d8246e..8c305584 100644 --- a/app/models/visit.rb +++ b/app/models/visit.rb @@ -1,14 +1,27 @@ +# == Schema Information +# +# Table name: visits +# +# id :uuid not null, primary key +# host :string +# ip :string +# ip_isp :string +# is_bot :boolean +# is_interflux :boolean +# referrer :string +# user_agent :string +# viewport_height :integer +# viewport_width :integer +# created_at :datetime not null +# updated_at :datetime not null +# ip_country_id :string +# user_id :uuid +# class Visit < ApplicationRecord belongs_to :user, optional: true - # TODO: belongs_to :monthly_visitor_report - # TODO: interpret the user agent - def is_robot - false - end + has_one :server_side_render, optional: true, dependent: nil + has_one :client_side_render, optional: true, dependent: nil - # TODO: interpret the user, IP and ISP - def is_interflux - false - end + has_many :page_view, dependent: :restrict_with_exception end diff --git a/app/models/webinar.rb b/app/models/webinar.rb index 34489b91..a05c52f8 100644 --- a/app/models/webinar.rb +++ b/app/models/webinar.rb @@ -1,3 +1,22 @@ +# == Schema Information +# +# Table name: webinars +# +# id :uuid not null, primary key +# audience :string +# duration :integer +# public :boolean default(FALSE) +# start_time :bigint +# title :string +# topic :string +# url :string +# created_at :datetime not null +# updated_at :datetime not null +# document_id :string +# image_id :string +# person_id :uuid +# video_id :string +# class Webinar < ApplicationRecord belongs_to :person, optional: true belongs_to :image, optional: true diff --git a/app/models/webinar_attendee.rb b/app/models/webinar_attendee.rb index d55b593a..2d1d3eda 100644 --- a/app/models/webinar_attendee.rb +++ b/app/models/webinar_attendee.rb @@ -1,3 +1,13 @@ +# == Schema Information +# +# Table name: webinar_attendees +# +# id :uuid not null, primary key +# created_at :datetime not null +# updated_at :datetime not null +# person_id :uuid +# webinar_id :uuid +# class WebinarAttendee < ApplicationRecord belongs_to :webinar belongs_to :person diff --git a/app/models/webinar_image.rb b/app/models/webinar_image.rb index aa53e2ba..dedef16f 100644 --- a/app/models/webinar_image.rb +++ b/app/models/webinar_image.rb @@ -1,3 +1,13 @@ +# == Schema Information +# +# Table name: webinar_images +# +# id :uuid not null, primary key +# created_at :datetime not null +# updated_at :datetime not null +# image_id :uuid +# webinar_id :uuid +# class WebinarImage < ApplicationRecord belongs_to :webinar belongs_to :image diff --git a/app/models/webinar_invitee.rb b/app/models/webinar_invitee.rb index 57528d4b..f40123ad 100644 --- a/app/models/webinar_invitee.rb +++ b/app/models/webinar_invitee.rb @@ -1,3 +1,13 @@ +# == Schema Information +# +# Table name: webinar_invitees +# +# id :uuid not null, primary key +# created_at :datetime not null +# updated_at :datetime not null +# person_id :uuid +# webinar_id :uuid +# class WebinarInvitee < ApplicationRecord belongs_to :webinar belongs_to :person diff --git a/app/models/webinar_video.rb b/app/models/webinar_video.rb index a0e0707d..89ca16a4 100644 --- a/app/models/webinar_video.rb +++ b/app/models/webinar_video.rb @@ -1,3 +1,13 @@ +# == Schema Information +# +# Table name: webinar_videos +# +# id :uuid not null, primary key +# created_at :datetime not null +# updated_at :datetime not null +# video_id :uuid +# webinar_id :uuid +# class WebinarVideo < ApplicationRecord belongs_to :webinar belongs_to :video diff --git a/app/serializers/v1/admin/client_side_render_serializer.rb b/app/serializers/v1/admin/client_side_render_serializer.rb new file mode 100644 index 00000000..08384905 --- /dev/null +++ b/app/serializers/v1/admin/client_side_render_serializer.rb @@ -0,0 +1,16 @@ +module V1 + module Admin + class ClientSideRenderSerializer < ApplicationSerializer + attributes :host, + :referrer, + :user_agent, + :ip, + :viewport_width, + :viewport_height, + :created_at + + belongs_to :server_side_render + belongs_to :user + end + end +end diff --git a/app/serializers/v1/admin/page_view_serializer.rb b/app/serializers/v1/admin/page_view_serializer.rb new file mode 100644 index 00000000..d85b637a --- /dev/null +++ b/app/serializers/v1/admin/page_view_serializer.rb @@ -0,0 +1,10 @@ +module V1 + module Admin + class PageViewSerializer < ApplicationSerializer + attributes :path, + :created_at + + belongs_to :Visit + end + end +end diff --git a/app/serializers/v1/admin/server_side_render_serializer.rb b/app/serializers/v1/admin/server_side_render_serializer.rb new file mode 100644 index 00000000..43e14d1b --- /dev/null +++ b/app/serializers/v1/admin/server_side_render_serializer.rb @@ -0,0 +1,11 @@ +module V1 + module Admin + class ServerSideRenderSerializer < ApplicationSerializer + attributes :host, + :referrer, + :user_agent, + :ip, + :created_at + end + end +end diff --git a/app/serializers/v1/admin/visit_serializer.rb b/app/serializers/v1/admin/visit_serializer.rb new file mode 100644 index 00000000..40283fb1 --- /dev/null +++ b/app/serializers/v1/admin/visit_serializer.rb @@ -0,0 +1,24 @@ +module V1 + module Admin + class VisitSerializer < ApplicationSerializer + attributes :host, + :referrer, + :user_agent, + :ip, + :ip_isp, + :ip, + :viewport_width, + :viewport_height, + :is_interflux, + :is_bot, + :created_at + + belongs_to :server_side_render + belongs_to :client_side_render + belongs_to :user + belongs_to :country + + has_many :page_views + end + end +end diff --git a/app/serializers/v1/public/client_side_render_serializer.rb b/app/serializers/v1/public/client_side_render_serializer.rb new file mode 100644 index 00000000..73a35dea --- /dev/null +++ b/app/serializers/v1/public/client_side_render_serializer.rb @@ -0,0 +1,6 @@ +module V1 + module Public + class ClientSideRenderSerializer < ApplicationSerializer + end + end +end diff --git a/app/serializers/v1/public/page_view_serializer.rb b/app/serializers/v1/public/page_view_serializer.rb new file mode 100644 index 00000000..ad318ade --- /dev/null +++ b/app/serializers/v1/public/page_view_serializer.rb @@ -0,0 +1,6 @@ +module V1 + module Public + class PageViewSerializer < ApplicationSerializer + end + end +end diff --git a/app/serializers/v1/public/server_side_render_serializer.rb b/app/serializers/v1/public/server_side_render_serializer.rb new file mode 100644 index 00000000..0d4cf528 --- /dev/null +++ b/app/serializers/v1/public/server_side_render_serializer.rb @@ -0,0 +1,6 @@ +module V1 + module Public + class ServerSideRenderSerializer < ApplicationSerializer + end + end +end diff --git a/config/routes.rb b/config/routes.rb index 4730bb94..f27e0f67 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -19,6 +19,7 @@ namespace :public do resources :article_categories, path: '/article-categories' resources :articles + resources :client_side_renders, path: '/client-side-renders' resources :companies resources :company_markets, path: '/company-markets' resources :countries @@ -29,12 +30,14 @@ resources :images resources :languages resources :leads + resources :page_views, path: '/page-views' resources :permalinks resources :product_families, path: '/product-families' resources :product_qualities, path: '/product-qualities' resources :product_uses, path: '/product-uses' resources :products resources :qualities + resources :server_side_renders, path: '/server-side-renders' resources :sessions resources :simulation_requests, path: '/simulation-requests' resources :translations @@ -58,6 +61,7 @@ resources :article_categories, path: '/article-categories' resources :articles resources :cdn_files, path: '/cdn-files' + resources :client_side_renders, path: '/client-side-renders' resources :companies resources :company_markets, path: '/company-markets' resources :company_members, path: '/company-members' @@ -69,6 +73,7 @@ resources :images resources :languages resources :leads + resources :page_views, path: '/page-views' resources :people resources :permalinks resources :person_images, path: '/person-images' @@ -77,17 +82,19 @@ resources :product_family_images, path: '/product-family-images' resources :product_features, path: '/product-features' resources :product_images, path: '/product-images' - resources :product_videos, path: '/product-videos' resources :product_qualities, path: '/product-qualities' resources :product_uses, path: '/product-uses' + resources :product_videos, path: '/product-videos' resources :products, path: '/products' resources :qualities + resources :server_side_renders, path: '/server-side-renders' resources :sessions resources :translations resources :use_images, path: '/use-images' resources :users resources :uses resources :videos + resources :visits resources :webinar_attendees, path: '/webinar-attendees' resources :webinar_images, path: '/webinar-images' resources :webinar_invitees, path: '/webinar-invitees' diff --git a/db/migrate/20240121003248_create_visits.rb b/db/migrate/20240121003248_create_visits.rb deleted file mode 100644 index 3bde89ab..00000000 --- a/db/migrate/20240121003248_create_visits.rb +++ /dev/null @@ -1,16 +0,0 @@ -class CreateVisits < ActiveRecord::Migration[6.1] - def change - create_table :visits, id: :uuid do |t| - t.string :ip - t.string :ip_isp - t.string :ip_country - t.string :user_agent - t.string :user_agent_ssr - t.string :browser_width - t.string :browser_height - t.datetime :start_time - t.datetime :end_time - t.uuid :user_id - end - end -end diff --git a/db/migrate/20240210021834_create_server_side_renders.rb b/db/migrate/20240210021834_create_server_side_renders.rb new file mode 100644 index 00000000..7f45e18a --- /dev/null +++ b/db/migrate/20240210021834_create_server_side_renders.rb @@ -0,0 +1,14 @@ +class CreateServerSideRenders < ActiveRecord::Migration[6.1] + def change + create_table :server_side_renders, id: :uuid do |t| + t.string :host + t.string :referrer + t.string :user_agent + t.string :ip + + t.uuid :visit_id + + t.timestamps + end + end +end diff --git a/db/migrate/20240210021840_create_client_side_renders.rb b/db/migrate/20240210021840_create_client_side_renders.rb new file mode 100644 index 00000000..70714f60 --- /dev/null +++ b/db/migrate/20240210021840_create_client_side_renders.rb @@ -0,0 +1,18 @@ +class CreateClientSideRenders < ActiveRecord::Migration[6.1] + def change + create_table :client_side_renders, id: :uuid do |t| + t.string :host + t.string :referrer + t.string :user_agent + t.string :ip + + t.integer :viewport_width + t.integer :viewport_height + + t.uuid :visit_id + t.uuid :user_id + + t.timestamps + end + end +end diff --git a/db/migrate/20240210021852_create_visits.rb b/db/migrate/20240210021852_create_visits.rb new file mode 100644 index 00000000..fc18ba6e --- /dev/null +++ b/db/migrate/20240210021852_create_visits.rb @@ -0,0 +1,22 @@ +class CreateVisits < ActiveRecord::Migration[6.1] + def change + create_table :visits, id: :uuid do |t| + t.string :host + t.string :referrer + t.string :user_agent + t.string :ip + t.string :ip_isp + t.string :ip_country_id + + t.integer :viewport_width + t.integer :viewport_height + + t.uuid :user_id + + t.boolean :is_interflux + t.boolean :is_bot + + t.timestamps + end + end +end diff --git a/db/migrate/20240210021903_create_page_views.rb b/db/migrate/20240210021903_create_page_views.rb new file mode 100644 index 00000000..96c4d180 --- /dev/null +++ b/db/migrate/20240210021903_create_page_views.rb @@ -0,0 +1,9 @@ +class CreatePageViews < ActiveRecord::Migration[6.1] + def change + create_table :page_views, id: :uuid do |t| + t.string :path + + t.timestamps + end + end +end diff --git a/db/schema.rb b/db/schema.rb index f3969faf..67133115 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: 2024_01_27_091511) do +ActiveRecord::Schema.define(version: 2024_02_10_021903) do # These are extensions that must be enabled in order to support this database enable_extension "pgcrypto" @@ -60,6 +60,19 @@ t.index ["path"], name: "index_cdn_files_on_path" end + create_table "client_side_renders", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| + t.string "host" + t.string "referrer" + t.string "user_agent" + t.string "ip" + t.integer "viewport_width" + t.integer "viewport_height" + t.uuid "visit_id" + t.uuid "user_id" + t.datetime "created_at", precision: 6, null: false + t.datetime "updated_at", precision: 6, null: false + end + create_table "companies", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| t.string "slug" t.string "business_name" @@ -270,6 +283,12 @@ t.index ["ip_country_id"], name: "index_leads_on_ip_country_id" end + create_table "page_views", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| + t.string "path" + t.datetime "created_at", precision: 6, null: false + t.datetime "updated_at", precision: 6, null: false + end + create_table "people", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| t.datetime "created_at", null: false t.datetime "updated_at", null: false @@ -452,6 +471,16 @@ t.string "image_id" end + create_table "server_side_renders", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| + t.string "host" + t.string "referrer" + t.string "user_agent" + t.string "ip" + t.uuid "visit_id" + t.datetime "created_at", precision: 6, null: false + t.datetime "updated_at", precision: 6, null: false + end + create_table "sessions", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| t.string "href" t.string "referrer" @@ -554,16 +583,19 @@ end create_table "visits", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| + t.string "host" + t.string "referrer" + t.string "user_agent" t.string "ip" t.string "ip_isp" - t.string "ip_country" - t.string "user_agent" - t.string "user_agent_ssr" - t.string "browser_width" - t.string "browser_height" - t.datetime "start_time" - t.datetime "end_time" + t.string "ip_country_id" + t.integer "viewport_width" + t.integer "viewport_height" t.uuid "user_id" + t.boolean "is_interflux" + t.boolean "is_bot" + t.datetime "created_at", precision: 6, null: false + t.datetime "updated_at", precision: 6, null: false end create_table "webinar_attendees", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| diff --git a/lib/tasks/auto_annotate_models.rake b/lib/tasks/auto_annotate_models.rake new file mode 100644 index 00000000..e96283ea --- /dev/null +++ b/lib/tasks/auto_annotate_models.rake @@ -0,0 +1,59 @@ +# NOTE: only doing this in development as some production environments (Heroku) +# NOTE: are sensitive to local FS writes, and besides -- it's just not proper +# NOTE: to have a dev-mode tool do its thing in production. +if Rails.env.development? + require 'annotate' + task :set_annotation_options do + # You can override any of these by setting an environment variable of the + # same name. + Annotate.set_defaults( + 'active_admin' => 'false', + 'additional_file_patterns' => [], + 'routes' => 'false', + 'models' => 'true', + 'position_in_routes' => 'before', + 'position_in_class' => 'before', + 'position_in_test' => 'before', + 'position_in_fixture' => 'before', + 'position_in_factory' => 'before', + 'position_in_serializer' => 'before', + 'show_foreign_keys' => 'true', + 'show_complete_foreign_keys' => 'false', + 'show_indexes' => 'true', + 'simple_indexes' => 'false', + 'model_dir' => 'app/models', + 'root_dir' => '', + 'include_version' => 'false', + 'require' => '', + 'exclude_tests' => 'false', + 'exclude_fixtures' => 'false', + 'exclude_factories' => 'false', + 'exclude_serializers' => 'false', + 'exclude_scaffolds' => 'true', + 'exclude_controllers' => 'true', + 'exclude_helpers' => 'true', + 'exclude_sti_subclasses' => 'false', + 'ignore_model_sub_dir' => 'false', + 'ignore_columns' => nil, + 'ignore_routes' => nil, + 'ignore_unknown_models' => 'false', + 'hide_limit_column_types' => 'integer,bigint,boolean', + 'hide_default_column_types' => 'json,jsonb,hstore', + 'skip_on_db_migrate' => 'false', + 'format_bare' => 'true', + 'format_rdoc' => 'false', + 'format_yard' => 'false', + 'format_markdown' => 'false', + 'sort' => 'false', + 'force' => 'false', + 'frozen' => 'false', + 'classified_sort' => 'true', + 'trace' => 'false', + 'wrapper_open' => nil, + 'wrapper_close' => nil, + 'with_comment' => 'true' + ) + end + + Annotate.load_tasks +end diff --git a/test/fixtures/article_categories.yml b/test/fixtures/article_categories.yml index 207b486e..c646de47 100644 --- a/test/fixtures/article_categories.yml +++ b/test/fixtures/article_categories.yml @@ -8,6 +8,11 @@ # created_at :datetime not null # updated_at :datetime not null # +# Indexes +# +# index_article_categories_on_name (name) UNIQUE +# index_article_categories_on_slug (slug) UNIQUE +# # article_category_fixture_1: # name: Some Name diff --git a/test/fixtures/article_tags.yml b/test/fixtures/article_tags.yml index 51ba6576..6ca72d08 100644 --- a/test/fixtures/article_tags.yml +++ b/test/fixtures/article_tags.yml @@ -3,10 +3,15 @@ # Table name: article_tags # # id :uuid not null, primary key -# article_id :uuid -# tag_id :uuid # created_at :datetime not null # updated_at :datetime not null +# article_id :uuid +# tag_id :uuid +# +# Indexes +# +# index_article_tags_on_article_id (article_id) +# index_article_tags_on_tag_id (tag_id) # # article_tag_fixture_1: diff --git a/test/fixtures/articles.yml b/test/fixtures/articles.yml index d69b0255..56e87144 100644 --- a/test/fixtures/articles.yml +++ b/test/fixtures/articles.yml @@ -3,15 +3,20 @@ # Table name: articles # # id :uuid not null, primary key +# body :text +# date :date +# public :boolean default(FALSE) # slug :string # title :string -# public :boolean default(FALSE) # created_at :datetime not null # updated_at :datetime not null -# body :text -# date :date # article_category_id :uuid # +# Indexes +# +# index_articles_on_slug (slug) UNIQUE +# index_articles_on_title (title) UNIQUE +# # article_fixture_1: # name: Some Name diff --git a/test/fixtures/cdn_files.yml b/test/fixtures/cdn_files.yml index fa145046..c3dd92fc 100644 --- a/test/fixtures/cdn_files.yml +++ b/test/fixtures/cdn_files.yml @@ -2,12 +2,20 @@ # # Table name: cdn_files # -# id :uuid not null, primary key -# path :string -# created_at :datetime not null -# updated_at :datetime not null -# image_id :string -# document_id :string +# id :uuid not null, primary key +# locale :string +# original_file_name :string +# path :string +# created_at :datetime not null +# updated_at :datetime not null +# document_id :string +# image_id :string +# user_id :uuid +# video_id :string +# +# Indexes +# +# index_cdn_files_on_path (path) # # cdn_file_fixture_1: diff --git a/test/fixtures/client_side_renders.yml b/test/fixtures/client_side_renders.yml new file mode 100644 index 00000000..af0cd0b8 --- /dev/null +++ b/test/fixtures/client_side_renders.yml @@ -0,0 +1,26 @@ +# == Schema Information +# +# Table name: client_side_renders +# +# id :uuid not null, primary key +# host :string +# ip :string +# referrer :string +# user_agent :string +# viewport_height :integer +# viewport_width :integer +# created_at :datetime not null +# updated_at :datetime not null +# user_id :uuid +# visit_id :uuid +# + +# This model initially had no columns defined. If you add columns to the +# model remove the '{}' from the fixture names and add the columns immediately +# below each fixture, per the syntax in the comments below +# +one: {} +# column: value +# +two: {} +# column: value diff --git a/test/fixtures/companies.yml b/test/fixtures/companies.yml index af496f4b..b2933fc6 100644 --- a/test/fixtures/companies.yml +++ b/test/fixtures/companies.yml @@ -2,26 +2,43 @@ # # Table name: companies # -# id :uuid not null, primary key -# slug :string -# business_name :string -# address :string -# emails :string -# phone :string -# fax :string -# latitude :decimal(, ) -# longitude :decimal(, ) -# country_id :string -# created_at :datetime not null -# updated_at :datetime not null -# legal_name :string -# website :string -# public :boolean -# order :integer -# email_general :string -# email_support :string -# email_orders :string -# email_accounting :string +# id :uuid not null, primary key +# address :string +# business_name :string +# core_activity :string +# description :text +# email_accounting :string +# email_general :string +# email_orders :string +# email_support :string +# emails :string +# fax :string +# head_count :integer default(1) +# history :string +# is_headquarter :boolean default(FALSE) +# latitude :decimal(, ) +# legal_name :string +# longitude :decimal(, ) +# notes :text +# order :integer +# phone :string +# public :boolean +# rank_on_group_website :integer default(999) +# show_markets :boolean default(TRUE) +# shown_on_group_website :boolean default(FALSE) +# shown_on_icsf_website :boolean default(FALSE) +# shown_on_main_website :boolean default(FALSE) +# slug :string +# website :string +# created_at :datetime not null +# updated_at :datetime not null +# country_id :string +# +# Indexes +# +# index_companies_on_business_name (business_name) UNIQUE +# index_companies_on_country_id (country_id) +# index_companies_on_slug (slug) UNIQUE # # company_fixture_1: diff --git a/test/fixtures/company_markets.yml b/test/fixtures/company_markets.yml index a2835b36..e3282ceb 100644 --- a/test/fixtures/company_markets.yml +++ b/test/fixtures/company_markets.yml @@ -2,11 +2,14 @@ # # Table name: company_markets # -# id :uuid not null, primary key -# company_id :uuid -# country_id :string -# created_at :datetime not null -# updated_at :datetime not null +# id :uuid not null, primary key +# company_is_recommended :boolean default(FALSE) +# rank_among_companies :integer +# rank_among_countries :integer +# created_at :datetime not null +# updated_at :datetime not null +# company_id :uuid +# country_id :string # # company_market_fixture_1: diff --git a/test/fixtures/company_members.yml b/test/fixtures/company_members.yml index ad2bdeee..f7f0a020 100644 --- a/test/fixtures/company_members.yml +++ b/test/fixtures/company_members.yml @@ -2,18 +2,27 @@ # # Table name: company_members # -# company_id :uuid -# person_id :uuid -# title :string -# email :string -# phone :string -# public :boolean default(FALSE) -# created_at :datetime not null -# updated_at :datetime not null -# public_title :boolean default(FALSE) -# public_email :boolean default(FALSE) -# public_phone :boolean default(FALSE) -# id :uuid not null, primary key +# id :uuid not null, primary key +# email :string +# landline :string +# phone :string +# public :boolean default(FALSE) +# public_email :boolean default(FALSE) +# public_landline :boolean default(FALSE) +# public_phone :boolean default(FALSE) +# public_title :boolean default(FALSE) +# rank_among_companies :integer +# rank_among_members :integer +# title :string +# created_at :datetime not null +# updated_at :datetime not null +# company_id :uuid +# person_id :uuid +# +# Indexes +# +# index_company_members_on_company_id (company_id) +# index_company_members_on_person_id (person_id) # # company_member_fixture_1: diff --git a/test/fixtures/containers.yml b/test/fixtures/containers.yml index d8df4c4a..4cb5f860 100644 --- a/test/fixtures/containers.yml +++ b/test/fixtures/containers.yml @@ -7,6 +7,10 @@ # created_at :datetime not null # updated_at :datetime not null # +# Indexes +# +# index_containers_on_name (name) UNIQUE +# container_1: name: 200L HDPE drum diff --git a/test/fixtures/country_currencies.yml b/test/fixtures/country_currencies.yml index f6584e36..274ad8f7 100644 --- a/test/fixtures/country_currencies.yml +++ b/test/fixtures/country_currencies.yml @@ -3,10 +3,15 @@ # Table name: country_currencies # # id :uuid not null, primary key -# country_id :uuid -# currency_id :uuid # created_at :datetime not null # updated_at :datetime not null +# country_id :uuid +# currency_id :uuid +# +# Indexes +# +# index_country_currencies_on_country_id (country_id) +# index_country_currencies_on_currency_id (currency_id) # # country_currency_fixture_1: diff --git a/test/fixtures/country_languages.yml b/test/fixtures/country_languages.yml index b242c720..59bf26e6 100644 --- a/test/fixtures/country_languages.yml +++ b/test/fixtures/country_languages.yml @@ -3,10 +3,15 @@ # Table name: country_languages # # id :uuid not null, primary key -# country_id :uuid -# language_id :uuid # created_at :datetime not null # updated_at :datetime not null +# country_id :string +# language_id :string +# +# Indexes +# +# index_country_languages_on_country_id (country_id) +# index_country_languages_on_language_id (language_id) # # country_language_fixture_1: diff --git a/test/fixtures/document_categories.yml b/test/fixtures/document_categories.yml index 8ce7970d..671dcc90 100644 --- a/test/fixtures/document_categories.yml +++ b/test/fixtures/document_categories.yml @@ -2,13 +2,14 @@ # # Table name: document_categories # -# created_at :datetime not null -# gist :string -# icon :string -# name :string -# order :integer -# slug :string not null, primary key -# updated_at :datetime not null +# gist :string +# icon :string +# name :string +# name_single :string +# order :integer +# slug :string not null, primary key +# created_at :datetime not null +# updated_at :datetime not null # # document_category_fixture_1: diff --git a/test/fixtures/documents.yml b/test/fixtures/documents.yml index d7c75402..ab741d31 100644 --- a/test/fixtures/documents.yml +++ b/test/fixtures/documents.yml @@ -2,14 +2,15 @@ # # Table name: documents # -# path :string not null, primary key +# id :uuid not null, primary key # name :string -# language_id :string -# document_category_id :string +# path :string not null +# public :boolean default(FALSE) +# variations :string # created_at :datetime not null # updated_at :datetime not null -# variations :string -# public :boolean default(FALSE) +# document_category_id :string +# language_id :string # # document_fixture_1: diff --git a/test/fixtures/employees.yml b/test/fixtures/employees.yml index 1caab1c5..9fa6b382 100644 --- a/test/fixtures/employees.yml +++ b/test/fixtures/employees.yml @@ -3,10 +3,15 @@ # Table name: employees # # id :uuid not null, primary key -# company_id :uuid -# person_id :uuid # created_at :datetime not null # updated_at :datetime not null +# company_id :uuid +# person_id :uuid +# +# Indexes +# +# index_employees_on_company_id (company_id) +# index_employees_on_person_id (person_id) # # employee_fixture_1: diff --git a/test/fixtures/events.yml b/test/fixtures/events.yml index 7cb608fd..75d3384e 100644 --- a/test/fixtures/events.yml +++ b/test/fixtures/events.yml @@ -1,3 +1,18 @@ +# == Schema Information +# +# Table name: events +# +# id :uuid not null, primary key +# city :string +# dates :string +# description :string +# end_date :string +# name :string +# start_date :string +# created_at :datetime not null +# updated_at :datetime not null +# country_id :string +# # event_fixture_1: # name: Some Name # slug: some-name diff --git a/test/fixtures/images.yml b/test/fixtures/images.yml index 5f90c9a3..23bbde00 100644 --- a/test/fixtures/images.yml +++ b/test/fixtures/images.yml @@ -2,15 +2,17 @@ # # Table name: images # -# path :string not null, primary key -# sizes :string -# formats :string -# caption :string -# alt :string -# created_at :datetime not null -# updated_at :datetime not null -# company_id :uuid -# variations :string +# alt :string +# caption :string +# conversion_error_log :string +# converting :boolean +# original :string +# path :string not null, primary key +# variations :string +# created_at :datetime not null +# updated_at :datetime not null +# company_id :uuid +# user_id :uuid # image_1: diff --git a/test/fixtures/leads.yml b/test/fixtures/leads.yml index f9aa9664..9f8889cb 100644 --- a/test/fixtures/leads.yml +++ b/test/fixtures/leads.yml @@ -3,20 +3,25 @@ # Table name: leads # # id :uuid not null, primary key -# name :string # company :string # email :string -# mobile :string +# ip :string +# ip_city :string +# ip_region :string # message :text +# mobile :string +# name :string # purpose :string # source :string -# ip_region :string -# ip_city :string -# ip :string -# country_id :uuid -# ip_country_id :uuid # created_at :datetime not null # updated_at :datetime not null +# country_id :uuid +# ip_country_id :uuid +# +# Indexes +# +# index_leads_on_country_id (country_id) +# index_leads_on_ip_country_id (ip_country_id) # # lead_fixture_1: diff --git a/test/fixtures/page_views.yml b/test/fixtures/page_views.yml new file mode 100644 index 00000000..232d1963 --- /dev/null +++ b/test/fixtures/page_views.yml @@ -0,0 +1,19 @@ +# == Schema Information +# +# Table name: page_views +# +# id :uuid not null, primary key +# path :string +# created_at :datetime not null +# updated_at :datetime not null +# + +# This model initially had no columns defined. If you add columns to the +# model remove the '{}' from the fixture names and add the columns immediately +# below each fixture, per the syntax in the comments below +# +one: {} +# column: value +# +two: {} +# column: value diff --git a/test/fixtures/people.yml b/test/fixtures/people.yml index dffb9d8f..1a082e8c 100644 --- a/test/fixtures/people.yml +++ b/test/fixtures/people.yml @@ -2,16 +2,21 @@ # # Table name: people # -# id :uuid not null, primary key -# created_at :datetime not null -# updated_at :datetime not null -# first_name :string -# last_name :string -# chinese_name :string -# email :string -# phone :string -# male :boolean -# full_name :string +# id :uuid not null, primary key +# avatar_alt :string +# avatar_caption :string +# avatar_path :string +# avatar_variations :string +# chinese_name :string +# email :string +# first_name :string +# full_name :string +# last_name :string +# male :boolean +# phone :string +# created_at :datetime not null +# updated_at :datetime not null +# image_id :string # # person_fixture_1: diff --git a/test/fixtures/product_complements.yml b/test/fixtures/product_complements.yml index 8c86a343..574a9ab6 100644 --- a/test/fixtures/product_complements.yml +++ b/test/fixtures/product_complements.yml @@ -3,10 +3,15 @@ # Table name: product_complements # # id :uuid not null, primary key -# product_id :uuid -# complement_id :uuid # created_at :datetime not null # updated_at :datetime not null +# complement_id :uuid +# product_id :uuid +# +# Indexes +# +# index_product_complements_on_complement_id (complement_id) +# index_product_complements_on_product_id (product_id) # # product_complement_fixture_1: diff --git a/test/fixtures/product_documents.yml b/test/fixtures/product_documents.yml index 125093cf..b6feb6e2 100644 --- a/test/fixtures/product_documents.yml +++ b/test/fixtures/product_documents.yml @@ -3,12 +3,12 @@ # Table name: product_documents # # id :uuid not null, primary key -# product_id :string -# document_id :string +# rank_among_documents :integer +# rank_among_products :integer # created_at :datetime not null # updated_at :datetime not null -# rank_among_products :integer -# rank_among_documents :integer +# document_id :uuid +# product_id :string # # product_document_fixture_1: diff --git a/test/fixtures/product_families.yml b/test/fixtures/product_families.yml index fcd6d2de..56087de2 100644 --- a/test/fixtures/product_families.yml +++ b/test/fixtures/product_families.yml @@ -1,3 +1,17 @@ +# == Schema Information +# +# Table name: product_families +# +# gist :string +# name_plural :string +# name_single :string +# rank :integer +# slug :string not null, primary key +# the_full_monty :string +# created_at :datetime not null +# updated_at :datetime not null +# product_family_id :string +# --- soldering_flux: diff --git a/test/fixtures/product_qualities.yml b/test/fixtures/product_qualities.yml index c0e1bc74..fe00699e 100644 --- a/test/fixtures/product_qualities.yml +++ b/test/fixtures/product_qualities.yml @@ -3,12 +3,14 @@ # Table name: product_qualities # # id :uuid not null, primary key -# product_id :string -# quality_id :string -# created_at :datetime not null -# updated_at :datetime not null +# rank :integer # rank_among_products :integer # rank_among_qualities :integer +# show_on_product_list :boolean +# created_at :datetime not null +# updated_at :datetime not null +# product_id :string +# quality_id :string # # product_quality_fixture_1: diff --git a/test/fixtures/product_related_articles.yml b/test/fixtures/product_related_articles.yml index 6fcf6594..1a792679 100644 --- a/test/fixtures/product_related_articles.yml +++ b/test/fixtures/product_related_articles.yml @@ -3,10 +3,15 @@ # Table name: product_related_articles # # id :uuid not null, primary key -# product_id :uuid -# article_id :uuid # created_at :datetime not null # updated_at :datetime not null +# article_id :uuid +# product_id :uuid +# +# Indexes +# +# index_product_related_articles_on_article_id (article_id) +# index_product_related_articles_on_product_id (product_id) # # product_related_article_fixture_1: diff --git a/test/fixtures/product_substitutes.yml b/test/fixtures/product_substitutes.yml index 3f9da834..71381f4e 100644 --- a/test/fixtures/product_substitutes.yml +++ b/test/fixtures/product_substitutes.yml @@ -3,10 +3,15 @@ # Table name: product_substitutes # # id :uuid not null, primary key -# product_id :uuid -# substitute_id :uuid # created_at :datetime not null # updated_at :datetime not null +# product_id :uuid +# substitute_id :uuid +# +# Indexes +# +# index_product_substitutes_on_product_id (product_id) +# index_product_substitutes_on_substitute_id (substitute_id) # # product_substitute_fixture_1: diff --git a/test/fixtures/product_uses.yml b/test/fixtures/product_uses.yml index 08b40d0d..0a63a57c 100644 --- a/test/fixtures/product_uses.yml +++ b/test/fixtures/product_uses.yml @@ -2,13 +2,16 @@ # # Table name: product_uses # -# id :uuid not null, primary key -# product_id :string -# use_id :string -# created_at :datetime not null -# updated_at :datetime not null -# rank_among_products :integer -# rank_among_uses :integer +# id :uuid not null, primary key +# rank_among_products :integer +# rank_among_uses :integer +# show_alternative_avatar :boolean default(FALSE) +# show_on_product_list :boolean +# created_at :datetime not null +# updated_at :datetime not null +# image_id :string +# product_id :string +# use_id :string # # product_use_fixture_1: diff --git a/test/fixtures/product_videos.yml b/test/fixtures/product_videos.yml index fd00a848..4929008a 100644 --- a/test/fixtures/product_videos.yml +++ b/test/fixtures/product_videos.yml @@ -3,10 +3,10 @@ # Table name: product_videos # # id :uuid not null, primary key -# product_id :uuid -# video_id :uuid -# created_at :datetime not null -# updated_at :datetime not null +# public :boolean +# rank :integer +# product_id :string +# video_id :string # # product_video_fixture_1: diff --git a/test/fixtures/products.yml b/test/fixtures/products.yml index 817424fa..ee4239e1 100644 --- a/test/fixtures/products.yml +++ b/test/fixtures/products.yml @@ -2,23 +2,36 @@ # # Table name: products # -# slug :string not null, primary key -# name :string -# product_family_id :string -# image_id :string -# label :string -# pitch :text -# properties :text -# public :boolean default(FALSE) -# orderable :boolean default(FALSE) -# featured :boolean default(FALSE) -# popular :boolean default(FALSE) -# new :boolean default(FALSE) -# created_at :datetime not null -# updated_at :datetime not null -# status :string default("offline") -# superior_product_id :string -# rank_among_family :integer +# avatar_alt :string +# avatar_caption :string +# avatar_path :string +# avatar_variations :string +# complies_with_iec :boolean +# complies_with_ipcjstd004_a :boolean +# complies_with_ipcjstd004_b :boolean +# complies_with_ipcjstd005 :boolean +# complies_with_iso :boolean +# complies_with_rohs :boolean +# front_page_rank :integer default(9) +# instructions :string +# label :string +# name :string +# on_front_page :boolean default(FALSE) +# pitch :text +# properties :text +# public :boolean default(FALSE) +# rank_among_family :integer +# slug :string not null, primary key +# status :string default("offline") +# summary :string +# test_results :string +# created_at :datetime not null +# updated_at :datetime not null +# image_id :string +# main_family_id :string +# product_family_id :string +# sub_family_id :string +# superior_product_id :string # LMPA_Q6: diff --git a/test/fixtures/server_side_renders.yml b/test/fixtures/server_side_renders.yml new file mode 100644 index 00000000..54ef4bef --- /dev/null +++ b/test/fixtures/server_side_renders.yml @@ -0,0 +1,23 @@ +# == Schema Information +# +# Table name: server_side_renders +# +# id :uuid not null, primary key +# host :string +# ip :string +# referrer :string +# user_agent :string +# created_at :datetime not null +# updated_at :datetime not null +# visit_id :uuid +# + +# This model initially had no columns defined. If you add columns to the +# model remove the '{}' from the fixture names and add the columns immediately +# below each fixture, per the syntax in the comments below +# +one: {} +# column: value +# +two: {} +# column: value diff --git a/test/fixtures/sessions.yml b/test/fixtures/sessions.yml index 959f2b37..3d0d92dc 100644 --- a/test/fixtures/sessions.yml +++ b/test/fixtures/sessions.yml @@ -1,3 +1,26 @@ +# == Schema Information +# +# Table name: sessions +# +# id :uuid not null, primary key +# browser_app :string +# browser_height :string +# browser_languages :string +# browser_width :string +# href :string +# ip :string +# ip_isp :string +# ip_request_duration :integer +# ip_response_body :string +# ip_response_code :string +# ip_timezone :string +# is_interflux_member :boolean default(FALSE) +# referrer :string +# created_at :datetime not null +# updated_at :datetime not null +# ip_country_id :string +# user_id :uuid +# # session_fixture_1: # name: Some Name # slug: some-name diff --git a/test/fixtures/simulation_requests.yml b/test/fixtures/simulation_requests.yml index 1345019a..4604674e 100644 --- a/test/fixtures/simulation_requests.yml +++ b/test/fixtures/simulation_requests.yml @@ -1,3 +1,27 @@ +# == Schema Information +# +# Table name: simulation_requests +# +# id :uuid not null, primary key +# board_reference :string +# company_name :string +# cycle_time :string +# email :string +# flux_brand :string +# flux_consumption :string +# flux_process :string +# full_name :string +# image :string +# known_issue :string +# pallet_length :string +# pallet_width :string +# project_name :string +# sequence :integer +# solder_process :string +# wave_speed :string +# created_at :datetime not null +# updated_at :datetime not null +# # simulation_request_fixture_1: # name: Some Name # slug: some-name diff --git a/test/fixtures/tags.yml b/test/fixtures/tags.yml index 99aac384..8735b8a5 100644 --- a/test/fixtures/tags.yml +++ b/test/fixtures/tags.yml @@ -3,11 +3,15 @@ # Table name: tags # # id :uuid not null, primary key -# slug :string # name :string +# slug :string # created_at :datetime not null # updated_at :datetime not null # +# Indexes +# +# index_tags_on_slug (slug) UNIQUE +# # tag_fixture_1: # name: Some Name diff --git a/test/fixtures/translations.yml b/test/fixtures/translations.yml index 3d5ae6b5..b4cadade 100644 --- a/test/fixtures/translations.yml +++ b/test/fixtures/translations.yml @@ -1,3 +1,24 @@ +# == Schema Information +# +# Table name: translations +# +# id :uuid not null, primary key +# english :string +# english_before :text +# error :string +# language :string +# location :string +# native :string +# status :string +# created_at :datetime not null +# updated_at :datetime not null +# +# Indexes +# +# index_translations_on_language (language) +# index_translations_on_location (location) +# unique_location_per_language_index (language,location) UNIQUE +# # translation_fixture_1: # name: Some Name # slug: some-name diff --git a/test/fixtures/users.yml b/test/fixtures/users.yml index 65b85382..b8894fac 100644 --- a/test/fixtures/users.yml +++ b/test/fixtures/users.yml @@ -3,11 +3,16 @@ # Table name: users # # id :uuid not null, primary key +# abilities :string # email :string # password_digest :string -# person_id :uuid # created_at :datetime not null # updated_at :datetime not null +# person_id :uuid +# +# Indexes +# +# index_users_on_email (email) UNIQUE # admin: diff --git a/test/fixtures/videos.yml b/test/fixtures/videos.yml index 4cba6176..c4854aed 100644 --- a/test/fixtures/videos.yml +++ b/test/fixtures/videos.yml @@ -1,3 +1,14 @@ +# == Schema Information +# +# Table name: videos +# +# notes :string +# path :string not null, primary key +# title :string +# variations :string +# created_at :datetime not null +# updated_at :datetime not null +# # video_fixture_1: # name: Some Name # slug: some-name diff --git a/test/fixtures/visits.yml b/test/fixtures/visits.yml index 51816369..fce89600 100644 --- a/test/fixtures/visits.yml +++ b/test/fixtures/visits.yml @@ -1,4 +1,22 @@ -# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html +# == Schema Information +# +# Table name: visits +# +# id :uuid not null, primary key +# host :string +# ip :string +# ip_isp :string +# is_bot :boolean +# is_interflux :boolean +# referrer :string +# user_agent :string +# viewport_height :integer +# viewport_width :integer +# created_at :datetime not null +# updated_at :datetime not null +# ip_country_id :string +# user_id :uuid +# # This model initially had no columns defined. If you add columns to the # model remove the '{}' from the fixture names and add the columns immediately diff --git a/test/fixtures/webinar_attendees.yml b/test/fixtures/webinar_attendees.yml index 53aebfc8..8f676767 100644 --- a/test/fixtures/webinar_attendees.yml +++ b/test/fixtures/webinar_attendees.yml @@ -1,3 +1,13 @@ +# == Schema Information +# +# Table name: webinar_attendees +# +# id :uuid not null, primary key +# created_at :datetime not null +# updated_at :datetime not null +# person_id :uuid +# webinar_id :uuid +# # webinar_attendee_fixture_1: # name: Some Name # slug: some-name diff --git a/test/fixtures/webinar_images.yml b/test/fixtures/webinar_images.yml index eda083ee..87784467 100644 --- a/test/fixtures/webinar_images.yml +++ b/test/fixtures/webinar_images.yml @@ -1,3 +1,13 @@ +# == Schema Information +# +# Table name: webinar_images +# +# id :uuid not null, primary key +# created_at :datetime not null +# updated_at :datetime not null +# image_id :uuid +# webinar_id :uuid +# # webinar_image_fixture_1: # name: Some Name # slug: some-name diff --git a/test/fixtures/webinar_videos.yml b/test/fixtures/webinar_videos.yml index 0c7375e2..f1695ef7 100644 --- a/test/fixtures/webinar_videos.yml +++ b/test/fixtures/webinar_videos.yml @@ -1,3 +1,13 @@ +# == Schema Information +# +# Table name: webinar_videos +# +# id :uuid not null, primary key +# created_at :datetime not null +# updated_at :datetime not null +# video_id :uuid +# webinar_id :uuid +# # webinar_video_fixture_1: # name: Some Name # slug: some-name diff --git a/test/fixtures/webinars.yml b/test/fixtures/webinars.yml index e476748d..80229a7f 100644 --- a/test/fixtures/webinars.yml +++ b/test/fixtures/webinars.yml @@ -2,17 +2,20 @@ # # Table name: webinars # -# id :uuid not null, primary key -# title :string -# topic :string -# audience :string -# url :string -# public :boolean default(FALSE) -# start_time :bigint(8) -# duration :integer -# person_id :uuid -# created_at :datetime not null -# updated_at :datetime not null +# id :uuid not null, primary key +# audience :string +# duration :integer +# public :boolean default(FALSE) +# start_time :bigint +# title :string +# topic :string +# url :string +# created_at :datetime not null +# updated_at :datetime not null +# document_id :string +# image_id :string +# person_id :uuid +# video_id :string # # webinar_fixture_1: diff --git a/test/integration/v1/admin/client_side_renders_integration_test.rb b/test/integration/v1/admin/client_side_renders_integration_test.rb new file mode 100644 index 00000000..6cf187a7 --- /dev/null +++ b/test/integration/v1/admin/client_side_renders_integration_test.rb @@ -0,0 +1,9 @@ +# require 'test_helper' +# +# module V1 +# module Admin +# class ClientSideRenderIntegrationTest < ApplicationController +# +# end +# end +# end diff --git a/test/integration/v1/admin/page_views_integration_test.rb b/test/integration/v1/admin/page_views_integration_test.rb new file mode 100644 index 00000000..23731d68 --- /dev/null +++ b/test/integration/v1/admin/page_views_integration_test.rb @@ -0,0 +1,9 @@ +# require 'test_helper' +# +# module V1 +# module Admin +# class PageViewIntegrationTest < ApplicationController +# +# end +# end +# end diff --git a/test/integration/v1/admin/server_side_renders_integration_test.rb b/test/integration/v1/admin/server_side_renders_integration_test.rb new file mode 100644 index 00000000..16f8cd39 --- /dev/null +++ b/test/integration/v1/admin/server_side_renders_integration_test.rb @@ -0,0 +1,9 @@ +# require 'test_helper' +# +# module V1 +# module Admin +# class ServerSideRenderIntegrationTest < ApplicationController +# +# end +# end +# end diff --git a/test/integration/v1/admin/visits_integration_test.rb b/test/integration/v1/admin/visits_integration_test.rb new file mode 100644 index 00000000..3a0796f2 --- /dev/null +++ b/test/integration/v1/admin/visits_integration_test.rb @@ -0,0 +1,9 @@ +# require 'test_helper' +# +# module V1 +# module Admin +# class VisitIntegrationTest < ApplicationController +# +# end +# end +# end diff --git a/test/integration/v1/public/client_side_renders_integration_test.rb b/test/integration/v1/public/client_side_renders_integration_test.rb new file mode 100644 index 00000000..dadc13e4 --- /dev/null +++ b/test/integration/v1/public/client_side_renders_integration_test.rb @@ -0,0 +1,9 @@ +# require 'test_helper' +# +# module V1 +# module Public +# class ClientSideRenderIntegrationTest < ApplicationController +# +# end +# end +# end diff --git a/test/integration/v1/public/page_views_integration_test.rb b/test/integration/v1/public/page_views_integration_test.rb new file mode 100644 index 00000000..1b312f05 --- /dev/null +++ b/test/integration/v1/public/page_views_integration_test.rb @@ -0,0 +1,9 @@ +# require 'test_helper' +# +# module V1 +# module Public +# class PageViewIntegrationTest < ApplicationController +# +# end +# end +# end diff --git a/test/integration/v1/public/server_side_renders_integration_test.rb b/test/integration/v1/public/server_side_renders_integration_test.rb new file mode 100644 index 00000000..a884e6b8 --- /dev/null +++ b/test/integration/v1/public/server_side_renders_integration_test.rb @@ -0,0 +1,9 @@ +# require 'test_helper' +# +# module V1 +# module Public +# class ServerSideRenderIntegrationTest < ApplicationController +# +# end +# end +# end diff --git a/test/models/client_side_render_test.rb b/test/models/client_side_render_test.rb new file mode 100644 index 00000000..011ca6d2 --- /dev/null +++ b/test/models/client_side_render_test.rb @@ -0,0 +1,23 @@ +# == Schema Information +# +# Table name: client_side_renders +# +# id :uuid not null, primary key +# host :string +# ip :string +# referrer :string +# user_agent :string +# viewport_height :integer +# viewport_width :integer +# created_at :datetime not null +# updated_at :datetime not null +# user_id :uuid +# visit_id :uuid +# +require "test_helper" + +class ClientSideRenderTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end diff --git a/test/models/page_view_test.rb b/test/models/page_view_test.rb new file mode 100644 index 00000000..08abbfdb --- /dev/null +++ b/test/models/page_view_test.rb @@ -0,0 +1,16 @@ +# == Schema Information +# +# Table name: page_views +# +# id :uuid not null, primary key +# path :string +# created_at :datetime not null +# updated_at :datetime not null +# +require "test_helper" + +class PageViewTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end diff --git a/test/models/product_test.rb b/test/models/product_test.rb index 8278d36e..0e720176 100644 --- a/test/models/product_test.rb +++ b/test/models/product_test.rb @@ -1,3 +1,38 @@ +# == Schema Information +# +# Table name: products +# +# avatar_alt :string +# avatar_caption :string +# avatar_path :string +# avatar_variations :string +# complies_with_iec :boolean +# complies_with_ipcjstd004_a :boolean +# complies_with_ipcjstd004_b :boolean +# complies_with_ipcjstd005 :boolean +# complies_with_iso :boolean +# complies_with_rohs :boolean +# front_page_rank :integer default(9) +# instructions :string +# label :string +# name :string +# on_front_page :boolean default(FALSE) +# pitch :text +# properties :text +# public :boolean default(FALSE) +# rank_among_family :integer +# slug :string not null, primary key +# status :string default("offline") +# summary :string +# test_results :string +# created_at :datetime not null +# updated_at :datetime not null +# image_id :string +# main_family_id :string +# product_family_id :string +# sub_family_id :string +# superior_product_id :string +# require 'test_helper' class ProductTest < ActiveSupport::TestCase diff --git a/test/models/server_side_render_test.rb b/test/models/server_side_render_test.rb new file mode 100644 index 00000000..bca93234 --- /dev/null +++ b/test/models/server_side_render_test.rb @@ -0,0 +1,20 @@ +# == Schema Information +# +# Table name: server_side_renders +# +# id :uuid not null, primary key +# host :string +# ip :string +# referrer :string +# user_agent :string +# created_at :datetime not null +# updated_at :datetime not null +# visit_id :uuid +# +require "test_helper" + +class ServerSideRenderTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end diff --git a/test/models/visit_test.rb b/test/models/visit_test.rb index 2e6cc98c..e2b0f24d 100644 --- a/test/models/visit_test.rb +++ b/test/models/visit_test.rb @@ -1,3 +1,22 @@ +# == Schema Information +# +# Table name: visits +# +# id :uuid not null, primary key +# host :string +# ip :string +# ip_isp :string +# is_bot :boolean +# is_interflux :boolean +# referrer :string +# user_agent :string +# viewport_height :integer +# viewport_width :integer +# created_at :datetime not null +# updated_at :datetime not null +# ip_country_id :string +# user_id :uuid +# require "test_helper" class VisitTest < ActiveSupport::TestCase From 04e9442495abb7088fe76ff6b05517a6fc846f3c Mon Sep 17 00:00:00 2001 From: Jan Werkhoven Date: Sat, 10 Feb 2024 21:21:01 +1100 Subject: [PATCH 03/12] Remove model tests --- test/models/client_side_render_test.rb | 23 ----------------------- test/models/page_view_test.rb | 16 ---------------- test/models/server_side_render_test.rb | 20 -------------------- test/models/visit_test.rb | 26 -------------------------- 4 files changed, 85 deletions(-) delete mode 100644 test/models/client_side_render_test.rb delete mode 100644 test/models/page_view_test.rb delete mode 100644 test/models/server_side_render_test.rb delete mode 100644 test/models/visit_test.rb diff --git a/test/models/client_side_render_test.rb b/test/models/client_side_render_test.rb deleted file mode 100644 index 011ca6d2..00000000 --- a/test/models/client_side_render_test.rb +++ /dev/null @@ -1,23 +0,0 @@ -# == Schema Information -# -# Table name: client_side_renders -# -# id :uuid not null, primary key -# host :string -# ip :string -# referrer :string -# user_agent :string -# viewport_height :integer -# viewport_width :integer -# created_at :datetime not null -# updated_at :datetime not null -# user_id :uuid -# visit_id :uuid -# -require "test_helper" - -class ClientSideRenderTest < ActiveSupport::TestCase - # test "the truth" do - # assert true - # end -end diff --git a/test/models/page_view_test.rb b/test/models/page_view_test.rb deleted file mode 100644 index 08abbfdb..00000000 --- a/test/models/page_view_test.rb +++ /dev/null @@ -1,16 +0,0 @@ -# == Schema Information -# -# Table name: page_views -# -# id :uuid not null, primary key -# path :string -# created_at :datetime not null -# updated_at :datetime not null -# -require "test_helper" - -class PageViewTest < ActiveSupport::TestCase - # test "the truth" do - # assert true - # end -end diff --git a/test/models/server_side_render_test.rb b/test/models/server_side_render_test.rb deleted file mode 100644 index bca93234..00000000 --- a/test/models/server_side_render_test.rb +++ /dev/null @@ -1,20 +0,0 @@ -# == Schema Information -# -# Table name: server_side_renders -# -# id :uuid not null, primary key -# host :string -# ip :string -# referrer :string -# user_agent :string -# created_at :datetime not null -# updated_at :datetime not null -# visit_id :uuid -# -require "test_helper" - -class ServerSideRenderTest < ActiveSupport::TestCase - # test "the truth" do - # assert true - # end -end diff --git a/test/models/visit_test.rb b/test/models/visit_test.rb deleted file mode 100644 index e2b0f24d..00000000 --- a/test/models/visit_test.rb +++ /dev/null @@ -1,26 +0,0 @@ -# == Schema Information -# -# Table name: visits -# -# id :uuid not null, primary key -# host :string -# ip :string -# ip_isp :string -# is_bot :boolean -# is_interflux :boolean -# referrer :string -# user_agent :string -# viewport_height :integer -# viewport_width :integer -# created_at :datetime not null -# updated_at :datetime not null -# ip_country_id :string -# user_id :uuid -# -require "test_helper" - -class VisitTest < ActiveSupport::TestCase - # test "the truth" do - # assert true - # end -end From 8b283da2c4dadde04bc32a61fa67ad57b3a57b82 Mon Sep 17 00:00:00 2001 From: Jan Werkhoven Date: Sun, 11 Feb 2024 19:12:09 +1100 Subject: [PATCH 04/12] Add migrations, models and controllers for CSR and SSR logging --- .../public/client_side_renders_controller.rb | 11 ++++- .../public/server_side_renders_controller.rb | 9 ++++- app/models/client_side_render.rb | 28 +++++++------ app/models/page_view.rb | 9 +++-- app/models/server_side_render.rb | 5 ++- app/models/visit.rb | 40 ++++++++++--------- ...240210021834_create_server_side_renders.rb | 1 + ...240210021840_create_client_side_renders.rb | 5 ++- db/migrate/20240210021852_create_visits.rb | 9 ++++- .../20240210021903_create_page_views.rb | 2 + db/schema.rb | 13 +++++- test/fixtures/client_side_renders.yml | 25 +++++++----- test/fixtures/page_views.yml | 9 +++-- test/fixtures/server_side_renders.yml | 1 + test/fixtures/visits.yml | 32 ++++++++------- 15 files changed, 126 insertions(+), 73 deletions(-) diff --git a/app/controllers/v1/public/client_side_renders_controller.rb b/app/controllers/v1/public/client_side_renders_controller.rb index 40604472..fd34029f 100644 --- a/app/controllers/v1/public/client_side_renders_controller.rb +++ b/app/controllers/v1/public/client_side_renders_controller.rb @@ -10,7 +10,12 @@ def show end def create - allow_create({ ip: request.remote_ip }) + allow_create( + { + id: params[:data][:id], + ip: request.remote_ip + } + ) end def update @@ -33,12 +38,14 @@ def serializer_class def creatable_attributes %i[ - visit_id host + path referrer user_agent viewport_width viewport_height + server_side_render_id + browser_session_id user_id ] end diff --git a/app/controllers/v1/public/server_side_renders_controller.rb b/app/controllers/v1/public/server_side_renders_controller.rb index 1a0ec78a..270c4c1d 100644 --- a/app/controllers/v1/public/server_side_renders_controller.rb +++ b/app/controllers/v1/public/server_side_renders_controller.rb @@ -10,7 +10,12 @@ def show end def create - allow_create({ ip: request.remote_ip }) + allow_create( + { + id: params[:data][:id], + ip: request.remote_ip + } + ) end def update @@ -33,8 +38,8 @@ def serializer_class def creatable_attributes %i[ - visit_id host + path referrer user_agent ] diff --git a/app/models/client_side_render.rb b/app/models/client_side_render.rb index a213534a..aabbd810 100644 --- a/app/models/client_side_render.rb +++ b/app/models/client_side_render.rb @@ -2,19 +2,23 @@ # # Table name: client_side_renders # -# id :uuid not null, primary key -# host :string -# ip :string -# referrer :string -# user_agent :string -# viewport_height :integer -# viewport_width :integer -# created_at :datetime not null -# updated_at :datetime not null -# user_id :uuid -# visit_id :uuid +# id :uuid not null, primary key +# host :string +# ip :string +# path :string +# referrer :string +# user_agent :string +# viewport_height :integer +# viewport_width :integer +# created_at :datetime not null +# updated_at :datetime not null +# browser_session_id :uuid +# server_side_render_id :uuid +# user_id :uuid +# visit_id :uuid # class ClientSideRender < ApplicationRecord - belongs_to :visit, optional: true, dependent: nil + belongs_to :server_side_render, optional: true + belongs_to :visit, optional: true belongs_to :user, optional: true end diff --git a/app/models/page_view.rb b/app/models/page_view.rb index c7572e46..3bfae68a 100644 --- a/app/models/page_view.rb +++ b/app/models/page_view.rb @@ -2,10 +2,11 @@ # # Table name: page_views # -# id :uuid not null, primary key -# path :string -# created_at :datetime not null -# updated_at :datetime not null +# id :uuid not null, primary key +# path :string +# created_at :datetime not null +# updated_at :datetime not null +# browser_session_id :uuid # class PageView < ApplicationRecord belongs_to :visit diff --git a/app/models/server_side_render.rb b/app/models/server_side_render.rb index 6775655c..792d2c0a 100644 --- a/app/models/server_side_render.rb +++ b/app/models/server_side_render.rb @@ -5,6 +5,7 @@ # id :uuid not null, primary key # host :string # ip :string +# path :string # referrer :string # user_agent :string # created_at :datetime not null @@ -12,5 +13,7 @@ # visit_id :uuid # class ServerSideRender < ApplicationRecord - belongs_to :visit, optional: true, dependent: nil + belongs_to :visit, optional: true + + has_one :client_side_render end diff --git a/app/models/visit.rb b/app/models/visit.rb index 8c305584..b3c4deae 100644 --- a/app/models/visit.rb +++ b/app/models/visit.rb @@ -2,26 +2,30 @@ # # Table name: visits # -# id :uuid not null, primary key -# host :string -# ip :string -# ip_isp :string -# is_bot :boolean -# is_interflux :boolean -# referrer :string -# user_agent :string -# viewport_height :integer -# viewport_width :integer -# created_at :datetime not null -# updated_at :datetime not null -# ip_country_id :string -# user_id :uuid +# id :uuid not null, primary key +# first_seen :datetime +# host :string +# ip :string +# ip_isp :string +# is_bot :boolean +# is_interflux :boolean +# last_seen :datetime +# path :string +# referrer :string +# user_agent :string +# viewport_height :integer +# viewport_width :integer +# created_at :datetime not null +# updated_at :datetime not null +# browser_session_id :uuid +# ip_country_id :string +# user_id :uuid # class Visit < ApplicationRecord belongs_to :user, optional: true + belongs_to :ip_country, optional: true, class_name: 'Country' - has_one :server_side_render, optional: true, dependent: nil - has_one :client_side_render, optional: true, dependent: nil - - has_many :page_view, dependent: :restrict_with_exception + has_many :server_side_renders, dependent: :restrict_with_exception + has_many :client_side_renders, dependent: :restrict_with_exception + has_many :page_views, dependent: :restrict_with_exception end diff --git a/db/migrate/20240210021834_create_server_side_renders.rb b/db/migrate/20240210021834_create_server_side_renders.rb index 7f45e18a..905f6b0c 100644 --- a/db/migrate/20240210021834_create_server_side_renders.rb +++ b/db/migrate/20240210021834_create_server_side_renders.rb @@ -2,6 +2,7 @@ class CreateServerSideRenders < ActiveRecord::Migration[6.1] def change create_table :server_side_renders, id: :uuid do |t| t.string :host + t.string :path t.string :referrer t.string :user_agent t.string :ip diff --git a/db/migrate/20240210021840_create_client_side_renders.rb b/db/migrate/20240210021840_create_client_side_renders.rb index 70714f60..ba950b6c 100644 --- a/db/migrate/20240210021840_create_client_side_renders.rb +++ b/db/migrate/20240210021840_create_client_side_renders.rb @@ -2,6 +2,7 @@ class CreateClientSideRenders < ActiveRecord::Migration[6.1] def change create_table :client_side_renders, id: :uuid do |t| t.string :host + t.string :path t.string :referrer t.string :user_agent t.string :ip @@ -9,8 +10,10 @@ def change t.integer :viewport_width t.integer :viewport_height - t.uuid :visit_id + t.uuid :server_side_render_id + t.uuid :browser_session_id t.uuid :user_id + t.uuid :visit_id t.timestamps end diff --git a/db/migrate/20240210021852_create_visits.rb b/db/migrate/20240210021852_create_visits.rb index fc18ba6e..0b3da811 100644 --- a/db/migrate/20240210021852_create_visits.rb +++ b/db/migrate/20240210021852_create_visits.rb @@ -2,6 +2,7 @@ class CreateVisits < ActiveRecord::Migration[6.1] def change create_table :visits, id: :uuid do |t| t.string :host + t.string :path t.string :referrer t.string :user_agent t.string :ip @@ -11,11 +12,15 @@ def change t.integer :viewport_width t.integer :viewport_height - t.uuid :user_id - t.boolean :is_interflux t.boolean :is_bot + t.uuid :browser_session_id + t.uuid :user_id + + t.datetime :first_seen + t.datetime :last_seen + t.timestamps end end diff --git a/db/migrate/20240210021903_create_page_views.rb b/db/migrate/20240210021903_create_page_views.rb index 96c4d180..4597f521 100644 --- a/db/migrate/20240210021903_create_page_views.rb +++ b/db/migrate/20240210021903_create_page_views.rb @@ -3,6 +3,8 @@ def change create_table :page_views, id: :uuid do |t| t.string :path + t.uuid :browser_session_id + t.timestamps end end diff --git a/db/schema.rb b/db/schema.rb index 67133115..de92aefa 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -62,13 +62,16 @@ create_table "client_side_renders", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| t.string "host" + t.string "path" t.string "referrer" t.string "user_agent" t.string "ip" t.integer "viewport_width" t.integer "viewport_height" - t.uuid "visit_id" + t.uuid "server_side_render_id" + t.uuid "browser_session_id" t.uuid "user_id" + t.uuid "visit_id" t.datetime "created_at", precision: 6, null: false t.datetime "updated_at", precision: 6, null: false end @@ -285,6 +288,7 @@ create_table "page_views", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| t.string "path" + t.uuid "browser_session_id" t.datetime "created_at", precision: 6, null: false t.datetime "updated_at", precision: 6, null: false end @@ -473,6 +477,7 @@ create_table "server_side_renders", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| t.string "host" + t.string "path" t.string "referrer" t.string "user_agent" t.string "ip" @@ -584,6 +589,7 @@ create_table "visits", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| t.string "host" + t.string "path" t.string "referrer" t.string "user_agent" t.string "ip" @@ -591,9 +597,12 @@ t.string "ip_country_id" t.integer "viewport_width" t.integer "viewport_height" - t.uuid "user_id" t.boolean "is_interflux" t.boolean "is_bot" + t.uuid "browser_session_id" + t.uuid "user_id" + t.datetime "first_seen" + t.datetime "last_seen" t.datetime "created_at", precision: 6, null: false t.datetime "updated_at", precision: 6, null: false end diff --git a/test/fixtures/client_side_renders.yml b/test/fixtures/client_side_renders.yml index af0cd0b8..d94fd5fb 100644 --- a/test/fixtures/client_side_renders.yml +++ b/test/fixtures/client_side_renders.yml @@ -2,17 +2,20 @@ # # Table name: client_side_renders # -# id :uuid not null, primary key -# host :string -# ip :string -# referrer :string -# user_agent :string -# viewport_height :integer -# viewport_width :integer -# created_at :datetime not null -# updated_at :datetime not null -# user_id :uuid -# visit_id :uuid +# id :uuid not null, primary key +# host :string +# ip :string +# path :string +# referrer :string +# user_agent :string +# viewport_height :integer +# viewport_width :integer +# created_at :datetime not null +# updated_at :datetime not null +# browser_session_id :uuid +# server_side_render_id :uuid +# user_id :uuid +# visit_id :uuid # # This model initially had no columns defined. If you add columns to the diff --git a/test/fixtures/page_views.yml b/test/fixtures/page_views.yml index 232d1963..a17d32f2 100644 --- a/test/fixtures/page_views.yml +++ b/test/fixtures/page_views.yml @@ -2,10 +2,11 @@ # # Table name: page_views # -# id :uuid not null, primary key -# path :string -# created_at :datetime not null -# updated_at :datetime not null +# id :uuid not null, primary key +# path :string +# created_at :datetime not null +# updated_at :datetime not null +# browser_session_id :uuid # # This model initially had no columns defined. If you add columns to the diff --git a/test/fixtures/server_side_renders.yml b/test/fixtures/server_side_renders.yml index 54ef4bef..92028226 100644 --- a/test/fixtures/server_side_renders.yml +++ b/test/fixtures/server_side_renders.yml @@ -5,6 +5,7 @@ # id :uuid not null, primary key # host :string # ip :string +# path :string # referrer :string # user_agent :string # created_at :datetime not null diff --git a/test/fixtures/visits.yml b/test/fixtures/visits.yml index fce89600..77c2520b 100644 --- a/test/fixtures/visits.yml +++ b/test/fixtures/visits.yml @@ -2,20 +2,24 @@ # # Table name: visits # -# id :uuid not null, primary key -# host :string -# ip :string -# ip_isp :string -# is_bot :boolean -# is_interflux :boolean -# referrer :string -# user_agent :string -# viewport_height :integer -# viewport_width :integer -# created_at :datetime not null -# updated_at :datetime not null -# ip_country_id :string -# user_id :uuid +# id :uuid not null, primary key +# first_seen :datetime +# host :string +# ip :string +# ip_isp :string +# is_bot :boolean +# is_interflux :boolean +# last_seen :datetime +# path :string +# referrer :string +# user_agent :string +# viewport_height :integer +# viewport_width :integer +# created_at :datetime not null +# updated_at :datetime not null +# browser_session_id :uuid +# ip_country_id :string +# user_id :uuid # # This model initially had no columns defined. If you add columns to the From 8dc005aa567239fd8fe05e4540a0e68803e38a8b Mon Sep 17 00:00:00 2001 From: Jan Werkhoven Date: Sun, 11 Feb 2024 19:12:46 +1100 Subject: [PATCH 05/12] Add naive first pass of Rake task which will be scheduled to create Visits --- lib/tasks/visits.rake | 119 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 119 insertions(+) create mode 100644 lib/tasks/visits.rake diff --git a/lib/tasks/visits.rake b/lib/tasks/visits.rake new file mode 100644 index 00000000..748d3096 --- /dev/null +++ b/lib/tasks/visits.rake @@ -0,0 +1,119 @@ +namespace :visits do + task process: :environment do + log.info 'visits:process ⛵️' + + # For reference: + # ClientSideRender.joins(:visit) + # ClientSideRender.where.missing(:visit) + # ... are opposites. + + browser_sessions = ClientSideRender.where.missing(:visit).pluck(:browser_session_id).uniq + + browser_sessions.each do |browser_session| + csrs = ClientSideRender.where(browser_session_id: browser_session).order('created_at ASC') + + # The host, user agent and IP should be unique across the entire browser session. + + hosts = csrs.pluck(:host).uniq + user_agents = csrs.pluck(:user_agent).uniq + ips = csrs.pluck(:ip).uniq + + if hosts.count != 1 + log.warn "❌ 1 | #{browser_session}" + next + end + + if user_agents.count != 1 + log.warn "❌ 2 | #{browser_session}" + next + end + + if ips.count != 1 + log.warn "❌ 3 | #{browser_session}" + next + end + + record = Visit.create( + browser_session_id: browser_session, + + host: hosts.first, + path: csrs.first.path, + referrer: csrs.first.referrer, + user_agent: user_agents.first, + + ip: ips.first, + # ip_isp: nil, # TODO + # ip_country_id: nil, # TODO + + viewport_width: csrs.first.viewport_width, + viewport_height: csrs.first.viewport_height, + + # is_interflux: false, # TODO + # is_bot: false, # TODO + + first_seen: csrs.first.created_at + # last_seen: nil # TODO + # user_id: nil # TODO + ) + + log.info "✅ created Visit #{record.id}" + + csrs.each do |csr| + csr.update(visit: record) + + ssr = csr.server_side_render + + if ssr.nil? + log.warn '❌ no SSR' + log.warn csr.id + next + end + + ssr.update(visit: record) + + log.info '✅ - updated CSR and SSR' + + if csr.path != ssr.path + log.warn '❌ path not identical' + log.warn csr.id + log.warn csr.path + log.warn ssr.path + end + + if csr.host != ssr.host + log.warn '❌ host not identical' + log.warn csr.id + log.warn csr.host + log.warn ssr.host + end + + if csr.referrer != ssr.referrer + log.warn '❌ referrer not identical' + log.warn csr.id + log.warn csr.referrer + log.warn ssr.referrer + end + + if csr.user_agent != ssr.user_agent + log.warn '❌ UA not identical' + log.warn csr.id + log.warn csr.user_agent + log.warn ssr.user_agent + end + + next unless csr.ip != ssr.ip + + log.warn '❌ IP not identical' + log.warn csr.id + log.warn csr.ip + log.warn ssr.ip + end + end + + log.info 'visits:process ✅' + end + + def log + Rails.logger + end +end From a1fe70ef2d5e28899b4818f290d5df9d30310925 Mon Sep 17 00:00:00 2001 From: Jan Werkhoven Date: Sun, 11 Feb 2024 19:13:16 +1100 Subject: [PATCH 06/12] Change developer log levels to INFO --- config/environments/development.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/environments/development.rb b/config/environments/development.rb index b67108ac..f6013701 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -60,7 +60,7 @@ # When developing, do not log. Instead output everything in terminal. config.logger = Logger.new($stdout) - config.log_level = :debug + config.log_level = :info # config.logger.datetime_format = '%Y-%m-%d %H:%M:%S' config.logger.formatter = proc do |severity, _datetime, _progname, msg| "#{severity} #{msg}\n" From a3ae30f6255f10da3a194160698f151a9b73214f Mon Sep 17 00:00:00 2001 From: Jan Werkhoven Date: Sun, 11 Feb 2024 19:18:08 +1100 Subject: [PATCH 07/12] Remove unused tests --- test/fixtures/client_side_renders.yml | 29 ---------------- test/fixtures/page_views.yml | 20 ----------- test/fixtures/server_side_renders.yml | 24 -------------- test/fixtures/visits.yml | 33 ------------------- .../client_side_renders_integration_test.rb | 9 ----- .../server_side_renders_integration_test.rb | 9 ----- .../v1/admin/visits_integration_test.rb | 9 ----- .../client_side_renders_integration_test.rb | 9 ----- .../v1/public/page_views_integration_test.rb | 9 ----- .../server_side_renders_integration_test.rb | 9 ----- 10 files changed, 160 deletions(-) delete mode 100644 test/fixtures/client_side_renders.yml delete mode 100644 test/fixtures/page_views.yml delete mode 100644 test/fixtures/server_side_renders.yml delete mode 100644 test/fixtures/visits.yml delete mode 100644 test/integration/v1/admin/client_side_renders_integration_test.rb delete mode 100644 test/integration/v1/admin/server_side_renders_integration_test.rb delete mode 100644 test/integration/v1/admin/visits_integration_test.rb delete mode 100644 test/integration/v1/public/client_side_renders_integration_test.rb delete mode 100644 test/integration/v1/public/page_views_integration_test.rb delete mode 100644 test/integration/v1/public/server_side_renders_integration_test.rb diff --git a/test/fixtures/client_side_renders.yml b/test/fixtures/client_side_renders.yml deleted file mode 100644 index d94fd5fb..00000000 --- a/test/fixtures/client_side_renders.yml +++ /dev/null @@ -1,29 +0,0 @@ -# == Schema Information -# -# Table name: client_side_renders -# -# id :uuid not null, primary key -# host :string -# ip :string -# path :string -# referrer :string -# user_agent :string -# viewport_height :integer -# viewport_width :integer -# created_at :datetime not null -# updated_at :datetime not null -# browser_session_id :uuid -# server_side_render_id :uuid -# user_id :uuid -# visit_id :uuid -# - -# This model initially had no columns defined. If you add columns to the -# model remove the '{}' from the fixture names and add the columns immediately -# below each fixture, per the syntax in the comments below -# -one: {} -# column: value -# -two: {} -# column: value diff --git a/test/fixtures/page_views.yml b/test/fixtures/page_views.yml deleted file mode 100644 index a17d32f2..00000000 --- a/test/fixtures/page_views.yml +++ /dev/null @@ -1,20 +0,0 @@ -# == Schema Information -# -# Table name: page_views -# -# id :uuid not null, primary key -# path :string -# created_at :datetime not null -# updated_at :datetime not null -# browser_session_id :uuid -# - -# This model initially had no columns defined. If you add columns to the -# model remove the '{}' from the fixture names and add the columns immediately -# below each fixture, per the syntax in the comments below -# -one: {} -# column: value -# -two: {} -# column: value diff --git a/test/fixtures/server_side_renders.yml b/test/fixtures/server_side_renders.yml deleted file mode 100644 index 92028226..00000000 --- a/test/fixtures/server_side_renders.yml +++ /dev/null @@ -1,24 +0,0 @@ -# == Schema Information -# -# Table name: server_side_renders -# -# id :uuid not null, primary key -# host :string -# ip :string -# path :string -# referrer :string -# user_agent :string -# created_at :datetime not null -# updated_at :datetime not null -# visit_id :uuid -# - -# This model initially had no columns defined. If you add columns to the -# model remove the '{}' from the fixture names and add the columns immediately -# below each fixture, per the syntax in the comments below -# -one: {} -# column: value -# -two: {} -# column: value diff --git a/test/fixtures/visits.yml b/test/fixtures/visits.yml deleted file mode 100644 index 77c2520b..00000000 --- a/test/fixtures/visits.yml +++ /dev/null @@ -1,33 +0,0 @@ -# == Schema Information -# -# Table name: visits -# -# id :uuid not null, primary key -# first_seen :datetime -# host :string -# ip :string -# ip_isp :string -# is_bot :boolean -# is_interflux :boolean -# last_seen :datetime -# path :string -# referrer :string -# user_agent :string -# viewport_height :integer -# viewport_width :integer -# created_at :datetime not null -# updated_at :datetime not null -# browser_session_id :uuid -# ip_country_id :string -# user_id :uuid -# - -# This model initially had no columns defined. If you add columns to the -# model remove the '{}' from the fixture names and add the columns immediately -# below each fixture, per the syntax in the comments below -# -one: {} -# column: value -# -two: {} -# column: value diff --git a/test/integration/v1/admin/client_side_renders_integration_test.rb b/test/integration/v1/admin/client_side_renders_integration_test.rb deleted file mode 100644 index 6cf187a7..00000000 --- a/test/integration/v1/admin/client_side_renders_integration_test.rb +++ /dev/null @@ -1,9 +0,0 @@ -# require 'test_helper' -# -# module V1 -# module Admin -# class ClientSideRenderIntegrationTest < ApplicationController -# -# end -# end -# end diff --git a/test/integration/v1/admin/server_side_renders_integration_test.rb b/test/integration/v1/admin/server_side_renders_integration_test.rb deleted file mode 100644 index 16f8cd39..00000000 --- a/test/integration/v1/admin/server_side_renders_integration_test.rb +++ /dev/null @@ -1,9 +0,0 @@ -# require 'test_helper' -# -# module V1 -# module Admin -# class ServerSideRenderIntegrationTest < ApplicationController -# -# end -# end -# end diff --git a/test/integration/v1/admin/visits_integration_test.rb b/test/integration/v1/admin/visits_integration_test.rb deleted file mode 100644 index 3a0796f2..00000000 --- a/test/integration/v1/admin/visits_integration_test.rb +++ /dev/null @@ -1,9 +0,0 @@ -# require 'test_helper' -# -# module V1 -# module Admin -# class VisitIntegrationTest < ApplicationController -# -# end -# end -# end diff --git a/test/integration/v1/public/client_side_renders_integration_test.rb b/test/integration/v1/public/client_side_renders_integration_test.rb deleted file mode 100644 index dadc13e4..00000000 --- a/test/integration/v1/public/client_side_renders_integration_test.rb +++ /dev/null @@ -1,9 +0,0 @@ -# require 'test_helper' -# -# module V1 -# module Public -# class ClientSideRenderIntegrationTest < ApplicationController -# -# end -# end -# end diff --git a/test/integration/v1/public/page_views_integration_test.rb b/test/integration/v1/public/page_views_integration_test.rb deleted file mode 100644 index 1b312f05..00000000 --- a/test/integration/v1/public/page_views_integration_test.rb +++ /dev/null @@ -1,9 +0,0 @@ -# require 'test_helper' -# -# module V1 -# module Public -# class PageViewIntegrationTest < ApplicationController -# -# end -# end -# end diff --git a/test/integration/v1/public/server_side_renders_integration_test.rb b/test/integration/v1/public/server_side_renders_integration_test.rb deleted file mode 100644 index a884e6b8..00000000 --- a/test/integration/v1/public/server_side_renders_integration_test.rb +++ /dev/null @@ -1,9 +0,0 @@ -# require 'test_helper' -# -# module V1 -# module Public -# class ServerSideRenderIntegrationTest < ApplicationController -# -# end -# end -# end From 005519d9d934dd8d26d66aa63978e628a56aff0a Mon Sep 17 00:00:00 2001 From: Jan Werkhoven Date: Sun, 11 Feb 2024 19:49:24 +1100 Subject: [PATCH 08/12] Add comments to public serializers --- app/serializers/v1/public/client_side_render_serializer.rb | 1 + app/serializers/v1/public/page_view_serializer.rb | 1 + app/serializers/v1/public/server_side_render_serializer.rb | 1 + 3 files changed, 3 insertions(+) diff --git a/app/serializers/v1/public/client_side_render_serializer.rb b/app/serializers/v1/public/client_side_render_serializer.rb index 73a35dea..8c40b1f1 100644 --- a/app/serializers/v1/public/client_side_render_serializer.rb +++ b/app/serializers/v1/public/client_side_render_serializer.rb @@ -1,6 +1,7 @@ module V1 module Public class ClientSideRenderSerializer < ApplicationSerializer + # Return nothing apart from the ID and type. end end end diff --git a/app/serializers/v1/public/page_view_serializer.rb b/app/serializers/v1/public/page_view_serializer.rb index ad318ade..85f60fca 100644 --- a/app/serializers/v1/public/page_view_serializer.rb +++ b/app/serializers/v1/public/page_view_serializer.rb @@ -1,6 +1,7 @@ module V1 module Public class PageViewSerializer < ApplicationSerializer + # Return nothing apart from the ID and type. end end end diff --git a/app/serializers/v1/public/server_side_render_serializer.rb b/app/serializers/v1/public/server_side_render_serializer.rb index 0d4cf528..3bfdf36e 100644 --- a/app/serializers/v1/public/server_side_render_serializer.rb +++ b/app/serializers/v1/public/server_side_render_serializer.rb @@ -1,6 +1,7 @@ module V1 module Public class ServerSideRenderSerializer < ApplicationSerializer + # Return nothing apart from the ID and type. end end end From 9b4b82b025a97ab3edaa571bff552637325cd9c2 Mon Sep 17 00:00:00 2001 From: Jan Werkhoven Date: Sun, 11 Feb 2024 19:56:35 +1100 Subject: [PATCH 09/12] Complete serializers for Admin --- .../v1/admin/client_side_render_serializer.rb | 5 ++++- .../v1/admin/server_side_render_serializer.rb | 3 +++ app/serializers/v1/admin/visit_serializer.rb | 11 ++++++----- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/app/serializers/v1/admin/client_side_render_serializer.rb b/app/serializers/v1/admin/client_side_render_serializer.rb index 08384905..d27acf84 100644 --- a/app/serializers/v1/admin/client_side_render_serializer.rb +++ b/app/serializers/v1/admin/client_side_render_serializer.rb @@ -2,15 +2,18 @@ module V1 module Admin class ClientSideRenderSerializer < ApplicationSerializer attributes :host, + :path, :referrer, :user_agent, :ip, :viewport_width, :viewport_height, - :created_at + :created_at, + :browser_session_id belongs_to :server_side_render belongs_to :user + belongs_to :visit end end end diff --git a/app/serializers/v1/admin/server_side_render_serializer.rb b/app/serializers/v1/admin/server_side_render_serializer.rb index 43e14d1b..c11c6f1e 100644 --- a/app/serializers/v1/admin/server_side_render_serializer.rb +++ b/app/serializers/v1/admin/server_side_render_serializer.rb @@ -2,10 +2,13 @@ module V1 module Admin class ServerSideRenderSerializer < ApplicationSerializer attributes :host, + :path, :referrer, :user_agent, :ip, :created_at + + belongs_to :visit end end end diff --git a/app/serializers/v1/admin/visit_serializer.rb b/app/serializers/v1/admin/visit_serializer.rb index 40283fb1..248f896b 100644 --- a/app/serializers/v1/admin/visit_serializer.rb +++ b/app/serializers/v1/admin/visit_serializer.rb @@ -6,18 +6,19 @@ class VisitSerializer < ApplicationSerializer :user_agent, :ip, :ip_isp, - :ip, :viewport_width, :viewport_height, :is_interflux, :is_bot, - :created_at + :first_seen, + :last_seen, + :browser_session_id - belongs_to :server_side_render - belongs_to :client_side_render belongs_to :user - belongs_to :country + belongs_to :ip_country, record_type: :country, serializer: :country + has_many :server_side_renders + has_many :client_side_renders has_many :page_views end end From 0b432244b0dcb0ae92e43e6091ca495823cad93e Mon Sep 17 00:00:00 2001 From: Jan Werkhoven Date: Sun, 11 Feb 2024 19:59:41 +1100 Subject: [PATCH 10/12] Tune the Admin controllers for CSR and SSR --- .../admin/client_side_renders_controller.rb | 49 ------------------ .../admin/server_side_renders_controller.rb | 49 ------------------ app/controllers/v1/admin/visits_controller.rb | 51 +++---------------- 3 files changed, 8 insertions(+), 141 deletions(-) diff --git a/app/controllers/v1/admin/client_side_renders_controller.rb b/app/controllers/v1/admin/client_side_renders_controller.rb index 765572dc..23f1bebb 100644 --- a/app/controllers/v1/admin/client_side_renders_controller.rb +++ b/app/controllers/v1/admin/client_side_renders_controller.rb @@ -30,55 +30,6 @@ def model_class def serializer_class V1::Admin::ClientSideRenderSerializer end - - def creatable_attributes - %[] - # %i[ - # name - # company - # email - # mobile - # message - # purpose - # source - # ip - # ip_region - # ip_city - # ] - end - - def creatable_relationships - %[] - # %i[ - # country - # ip_country - # ] - end - - def permitted_filters - %[] - # %i[ - # main_group_id - # sub_group_id - # ] - end - - def permanent_filters - {} - # { - # public: true - # } - end - - def permitted_includes - %[] - # %i[ - # related_articles - # related_products - # related_products.main_group - # translations - # ] - end end end end diff --git a/app/controllers/v1/admin/server_side_renders_controller.rb b/app/controllers/v1/admin/server_side_renders_controller.rb index c334d077..7e36558b 100644 --- a/app/controllers/v1/admin/server_side_renders_controller.rb +++ b/app/controllers/v1/admin/server_side_renders_controller.rb @@ -30,55 +30,6 @@ def model_class def serializer_class V1::Admin::ServerSideRenderSerializer end - - def creatable_attributes - %[] - # %i[ - # name - # company - # email - # mobile - # message - # purpose - # source - # ip - # ip_region - # ip_city - # ] - end - - def creatable_relationships - %[] - # %i[ - # country - # ip_country - # ] - end - - def permitted_filters - %[] - # %i[ - # main_group_id - # sub_group_id - # ] - end - - def permanent_filters - {} - # { - # public: true - # } - end - - def permitted_includes - %[] - # %i[ - # related_articles - # related_products - # related_products.main_group - # translations - # ] - end end end end diff --git a/app/controllers/v1/admin/visits_controller.rb b/app/controllers/v1/admin/visits_controller.rb index 59332897..bb4a53de 100644 --- a/app/controllers/v1/admin/visits_controller.rb +++ b/app/controllers/v1/admin/visits_controller.rb @@ -31,53 +31,18 @@ def serializer_class V1::Admin::VisitSerializer end - def creatable_attributes - %[] - # %i[ - # name - # company - # email - # mobile - # message - # purpose - # source - # ip - # ip_region - # ip_city - # ] - end - - def creatable_relationships - %[] - # %i[ - # country - # ip_country - # ] - end - def permitted_filters - %[] - # %i[ - # main_group_id - # sub_group_id - # ] - end - - def permanent_filters - {} - # { - # public: true - # } + %i[ + host + ] end def permitted_includes - %[] - # %i[ - # related_articles - # related_products - # related_products.main_group - # translations - # ] + %i[ + server_side_renders + client_side_renders + user + ] end end end From ebf1edb624563e9699ad60f2985fcd3c73e7e61e Mon Sep 17 00:00:00 2001 From: Jan Werkhoven Date: Sun, 11 Feb 2024 20:00:49 +1100 Subject: [PATCH 11/12] Tune the Admin controllers for page views --- .../v1/admin/page_views_controller.rb | 49 ------------------- .../v1/public/page_views_controller.rb | 49 ------------------- 2 files changed, 98 deletions(-) diff --git a/app/controllers/v1/admin/page_views_controller.rb b/app/controllers/v1/admin/page_views_controller.rb index ca6a4236..ee138916 100644 --- a/app/controllers/v1/admin/page_views_controller.rb +++ b/app/controllers/v1/admin/page_views_controller.rb @@ -30,55 +30,6 @@ def model_class def serializer_class V1::Admin::PageViewSerializer end - - def creatable_attributes - %[] - # %i[ - # name - # company - # email - # mobile - # message - # purpose - # source - # ip - # ip_region - # ip_city - # ] - end - - def creatable_relationships - %[] - # %i[ - # country - # ip_country - # ] - end - - def permitted_filters - %[] - # %i[ - # main_group_id - # sub_group_id - # ] - end - - def permanent_filters - {} - # { - # public: true - # } - end - - def permitted_includes - %[] - # %i[ - # related_articles - # related_products - # related_products.main_group - # translations - # ] - end end end end diff --git a/app/controllers/v1/public/page_views_controller.rb b/app/controllers/v1/public/page_views_controller.rb index 4d1f5f67..c0e472d2 100644 --- a/app/controllers/v1/public/page_views_controller.rb +++ b/app/controllers/v1/public/page_views_controller.rb @@ -30,55 +30,6 @@ def model_class def serializer_class V1::Public::PageViewSerializer end - - def creatable_attributes - %[] - # %i[ - # name - # company - # email - # mobile - # message - # purpose - # source - # ip - # ip_region - # ip_city - # ] - end - - def creatable_relationships - %[] - # %i[ - # country - # ip_country - # ] - end - - def permitted_filters - %[] - # %i[ - # main_group_id - # sub_group_id - # ] - end - - def permanent_filters - {} - # { - # public: true - # } - end - - def permitted_includes - %[] - # %i[ - # related_articles - # related_products - # related_products.main_group - # translations - # ] - end end end end From 67cf11cd1fabc6d2ee0ac36dc33ce686b7ae87ea Mon Sep 17 00:00:00 2001 From: Jan Werkhoven Date: Sun, 11 Feb 2024 20:01:40 +1100 Subject: [PATCH 12/12] Remove unused test --- test/integration/v1/admin/page_views_integration_test.rb | 9 --------- 1 file changed, 9 deletions(-) delete mode 100644 test/integration/v1/admin/page_views_integration_test.rb diff --git a/test/integration/v1/admin/page_views_integration_test.rb b/test/integration/v1/admin/page_views_integration_test.rb deleted file mode 100644 index 23731d68..00000000 --- a/test/integration/v1/admin/page_views_integration_test.rb +++ /dev/null @@ -1,9 +0,0 @@ -# require 'test_helper' -# -# module V1 -# module Admin -# class PageViewIntegrationTest < ApplicationController -# -# end -# end -# end