From 6ea09c0dc0d5d79b2a27587769da40b37929b6f8 Mon Sep 17 00:00:00 2001 From: Zee Spencer <50284+zspencer@users.noreply.github.com> Date: Mon, 12 Feb 2024 15:29:22 -0800 Subject: [PATCH 1/8] =?UTF-8?q?=E2=9C=A8=20`Tobias`:=20Sprout=20`Tobias`?= =?UTF-8?q?=20Gizmo?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - https://github.com/zinc-collective/tobias/issues/1 - https://github.com/zinc-collective/convene/issues/709 - For a https://github.com/zinc-collective/tobias/issues/9 to leverage the behavior we described, we need a way to put tobias on the web. https://github.com/zinc-collective/convene/issues/709 are the equivalent of an "App" in the Convene world. - Note: `Gizmo` and `Furniture` are equivalent. We probably should finish https://github.com/zinc-collective/convene/issues/1472 - The migration change makes sure that ahttps://github.com/zinc-collective/tobias/issues/4 is connected to https://github.com/zinc-collective/tobias/issues/1 --- app/furniture/tobias.rb | 13 ++++++++++++- app/furniture/tobias/record.rb | 9 +++++++++ app/furniture/tobias/routes.rb | 9 +++++++++ app/furniture/tobias/trust.rb | 6 +++++- app/furniture/tobias/trusts/show.html.erb | 0 app/furniture/tobias/trusts_controller.rb | 8 ++++++++ app/models/furniture.rb | 1 + db/migrate/20240127063826_create_tobias_payouts.rb | 1 + db/schema.rb | 7 +++++-- spec/tobias/factories/tobias_factory.rb | 5 +++++ spec/tobias/factories/trust_factory.rb | 3 +++ 11 files changed, 58 insertions(+), 4 deletions(-) create mode 100644 app/furniture/tobias/record.rb create mode 100644 app/furniture/tobias/routes.rb create mode 100644 app/furniture/tobias/trusts/show.html.erb create mode 100644 app/furniture/tobias/trusts_controller.rb create mode 100644 spec/tobias/factories/tobias_factory.rb diff --git a/app/furniture/tobias.rb b/app/furniture/tobias.rb index 0dd845ca6..f81576e89 100644 --- a/app/furniture/tobias.rb +++ b/app/furniture/tobias.rb @@ -1,2 +1,13 @@ -class Tobias +class Tobias < Furniture + has_many :trusts, inverse_of: :tobias + default_scope { where(furniture_kind: "tobias") } + location(parent: :room) +end + +# TOBIAS is hard to pluralize... Rails presumed TOBIAS was plural... +# So this tells Rails that TOBIAS is the singular form, and that TOBIASes +# is the plural. +ActiveSupport::Inflector.inflections(:en) do |inflect| + inflect.plural(/^(tobias)$/i, '\1\2es') + inflect.singular(/^(tobias)es/i, '\1') end diff --git a/app/furniture/tobias/record.rb b/app/furniture/tobias/record.rb new file mode 100644 index 000000000..6763703c1 --- /dev/null +++ b/app/furniture/tobias/record.rb @@ -0,0 +1,9 @@ +class Tobias + class Record < ApplicationRecord + self.abstract_class = true + + def self.model_name + @_model_name ||= ActiveModel::Name.new(self, ::Tobias) + end + end +end diff --git a/app/furniture/tobias/routes.rb b/app/furniture/tobias/routes.rb new file mode 100644 index 000000000..26f1f5e6b --- /dev/null +++ b/app/furniture/tobias/routes.rb @@ -0,0 +1,9 @@ +class Tobias + class Routes + def self.append_routes(router) + router.resources :tobiases, module: "tobias" do + router.resources :trusts + end + end + end +end diff --git a/app/furniture/tobias/trust.rb b/app/furniture/tobias/trust.rb index 357c690fd..852b4ef2c 100644 --- a/app/furniture/tobias/trust.rb +++ b/app/furniture/tobias/trust.rb @@ -1,7 +1,11 @@ class Tobias - class Trust < ApplicationRecord + class Trust < Record self.table_name = "tobias_trusts" + belongs_to :tobias, inverse_of: :trusts + + location(parent: :tobias) + has_many :beneficiaries, inverse_of: :trust, dependent: :destroy has_many :payouts, inverse_of: :trust, dependent: :destroy end diff --git a/app/furniture/tobias/trusts/show.html.erb b/app/furniture/tobias/trusts/show.html.erb new file mode 100644 index 000000000..e69de29bb diff --git a/app/furniture/tobias/trusts_controller.rb b/app/furniture/tobias/trusts_controller.rb new file mode 100644 index 000000000..1125f8be1 --- /dev/null +++ b/app/furniture/tobias/trusts_controller.rb @@ -0,0 +1,8 @@ +class Tobias + class TrustsController < FurnitureController + + def show + end + + end +end diff --git a/app/models/furniture.rb b/app/models/furniture.rb index 6b0f6560b..b7edeb2b8 100644 --- a/app/models/furniture.rb +++ b/app/models/furniture.rb @@ -96,6 +96,7 @@ def self.registry marketplace: ::Marketplace::Marketplace, livestream: ::Livestream, section_navigation: SectionNavigation::SectionNavigation, + tobias: Tobias, embedded_form: EmbeddedForm } end diff --git a/db/migrate/20240127063826_create_tobias_payouts.rb b/db/migrate/20240127063826_create_tobias_payouts.rb index ad6eadffb..bf70cf8a9 100644 --- a/db/migrate/20240127063826_create_tobias_payouts.rb +++ b/db/migrate/20240127063826_create_tobias_payouts.rb @@ -1,6 +1,7 @@ class CreateTobiasPayouts < ActiveRecord::Migration[7.1] def change create_table :tobias_trusts, id: :uuid do |t| + t.references :tobias, type: :uuid, foreign_key: {to_table: :furnitures} t.timestamps end diff --git a/db/schema.rb b/db/schema.rb index c52f70b69..4485f4de9 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -87,7 +87,7 @@ t.integer "sluggable_id", null: false t.string "sluggable_type", limit: 50 t.string "scope" - t.datetime "created_at", precision: nil + t.datetime "created_at" t.index ["slug", "sluggable_type", "scope"], name: "index_friendly_id_slugs_on_slug_and_sluggable_type_and_scope", unique: true t.index ["slug", "sluggable_type"], name: "index_friendly_id_slugs_on_slug_and_sluggable_type" t.index ["sluggable_type", "sluggable_id"], name: "index_friendly_id_slugs_on_sluggable_type_and_sluggable_id" @@ -291,7 +291,7 @@ t.string "email", null: false t.datetime "created_at", null: false t.datetime "updated_at", null: false - t.boolean "operator", default: false + t.boolean "operator", default: false, null: false t.index ["email"], name: "index_people_on_email", unique: true end @@ -361,8 +361,10 @@ end create_table "tobias_trusts", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| + t.uuid "tobias_id" t.datetime "created_at", null: false t.datetime "updated_at", null: false + t.index ["tobias_id"], name: "index_tobias_trusts_on_tobias_id" end create_table "utility_hookups", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| @@ -404,4 +406,5 @@ add_foreign_key "tobias_payments", "tobias_beneficiaries", column: "beneficiary_id" add_foreign_key "tobias_payments", "tobias_payouts", column: "payout_id" add_foreign_key "tobias_payouts", "tobias_trusts", column: "trust_id" + add_foreign_key "tobias_trusts", "furnitures", column: "tobias_id" end diff --git a/spec/tobias/factories/tobias_factory.rb b/spec/tobias/factories/tobias_factory.rb new file mode 100644 index 000000000..d26bdaa42 --- /dev/null +++ b/spec/tobias/factories/tobias_factory.rb @@ -0,0 +1,5 @@ +FactoryBot.define do + factory :tobias do + room + end +end diff --git a/spec/tobias/factories/trust_factory.rb b/spec/tobias/factories/trust_factory.rb index 7fd94abab..bb7123893 100644 --- a/spec/tobias/factories/trust_factory.rb +++ b/spec/tobias/factories/trust_factory.rb @@ -1,4 +1,7 @@ +require_relative "tobias_factory" + FactoryBot.define do factory :tobias_trust, class: "Tobias::Trust" do + tobias end end From 55affc07a77c10ebf6a781c5109274773bdf7ff5 Mon Sep 17 00:00:00 2001 From: chloeinnvaer <134097748+chloeinnvaer@users.noreply.github.com> Date: Mon, 26 Feb 2024 15:59:45 -0800 Subject: [PATCH 2/8] =?UTF-8?q?=E2=9C=A8=20`Tobias`:=20Flesh=20out=20the?= =?UTF-8?q?=20pathway=20to=20`Trust#show`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Next steps might include: create "New Payout" link Co-Authored-By: Zee <50284+zspencer@users.noreply.github.com> Co-Authored-By: JuanCarlosTC <153764163+juancarlostc@users.noreply.github.com> --- app/furniture/tobias/trusts/show.html.erb | 1 + app/furniture/tobias/trusts_controller.rb | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/app/furniture/tobias/trusts/show.html.erb b/app/furniture/tobias/trusts/show.html.erb index e69de29bb..667e845bd 100644 --- a/app/furniture/tobias/trusts/show.html.erb +++ b/app/furniture/tobias/trusts/show.html.erb @@ -0,0 +1 @@ + diff --git a/app/furniture/tobias/trusts_controller.rb b/app/furniture/tobias/trusts_controller.rb index 1125f8be1..d8af06b29 100644 --- a/app/furniture/tobias/trusts_controller.rb +++ b/app/furniture/tobias/trusts_controller.rb @@ -1,8 +1,16 @@ class Tobias class TrustsController < FurnitureController + expose :trust, model: Trust def show + authorize trust end end + class TrustPolicy < ApplicationPolicy + def show? + true + end + alias_method :entry, :object + end end From d7af1605a5146caf2f07d716ca4401903e5c0602 Mon Sep 17 00:00:00 2001 From: Zee Spencer <50284+zspencer@users.noreply.github.com> Date: Mon, 25 Mar 2024 14:26:45 -0700 Subject: [PATCH 3/8] =?UTF-8?q?=F0=9F=A7=B9=20Manually=20overriding`#model?= =?UTF-8?q?=5Fname`=20is=20a=20bit=20odd?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Instead, we use the mixin as a kind of "nod-to-the-odd" --- app/furniture/tobias/record.rb | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/app/furniture/tobias/record.rb b/app/furniture/tobias/record.rb index 6763703c1..eac55eb36 100644 --- a/app/furniture/tobias/record.rb +++ b/app/furniture/tobias/record.rb @@ -1,9 +1,7 @@ class Tobias class Record < ApplicationRecord self.abstract_class = true + extend StripsNamespaceFromModelName - def self.model_name - @_model_name ||= ActiveModel::Name.new(self, ::Tobias) - end end end From d38b5fc0b084062341e63ad77a00a81c933bab41 Mon Sep 17 00:00:00 2001 From: Zee Spencer <50284+zspencer@users.noreply.github.com> Date: Mon, 25 Mar 2024 14:29:18 -0700 Subject: [PATCH 4/8] =?UTF-8?q?=F0=9F=A7=B9=20Eliminate=20inappropriate=20?= =?UTF-8?q?schema=20changes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- db/schema.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/db/schema.rb b/db/schema.rb index 4485f4de9..838f16d1b 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -87,7 +87,7 @@ t.integer "sluggable_id", null: false t.string "sluggable_type", limit: 50 t.string "scope" - t.datetime "created_at" + t.datetime "created_at", precision: nil t.index ["slug", "sluggable_type", "scope"], name: "index_friendly_id_slugs_on_slug_and_sluggable_type_and_scope", unique: true t.index ["slug", "sluggable_type"], name: "index_friendly_id_slugs_on_slug_and_sluggable_type" t.index ["sluggable_type", "sluggable_id"], name: "index_friendly_id_slugs_on_sluggable_type_and_sluggable_id" @@ -291,7 +291,7 @@ t.string "email", null: false t.datetime "created_at", null: false t.datetime "updated_at", null: false - t.boolean "operator", default: false, null: false + t.boolean "operator", default: false t.index ["email"], name: "index_people_on_email", unique: true end From c672ca8b67dc26bd18d864bf68ebd752c90c6442 Mon Sep 17 00:00:00 2001 From: Zee Spencer <50284+zspencer@users.noreply.github.com> Date: Mon, 25 Mar 2024 14:30:25 -0700 Subject: [PATCH 5/8] =?UTF-8?q?=F0=9F=A7=B9=20Run=20the=20Linter?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/furniture/tobias/record.rb | 1 - app/furniture/tobias/trusts_controller.rb | 8 ++++---- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/app/furniture/tobias/record.rb b/app/furniture/tobias/record.rb index eac55eb36..fdde4bf95 100644 --- a/app/furniture/tobias/record.rb +++ b/app/furniture/tobias/record.rb @@ -2,6 +2,5 @@ class Tobias class Record < ApplicationRecord self.abstract_class = true extend StripsNamespaceFromModelName - end end diff --git a/app/furniture/tobias/trusts_controller.rb b/app/furniture/tobias/trusts_controller.rb index d8af06b29..5b9564720 100644 --- a/app/furniture/tobias/trusts_controller.rb +++ b/app/furniture/tobias/trusts_controller.rb @@ -5,12 +5,12 @@ class TrustsController < FurnitureController def show authorize trust end - end + class TrustPolicy < ApplicationPolicy - def show? - true - end + def show? + true + end alias_method :entry, :object end end From b7f902b6f6a4c230a81b8145e6b9c3c2bda2d016 Mon Sep 17 00:00:00 2001 From: Zee Spencer <50284+zspencer@users.noreply.github.com> Date: Mon, 25 Mar 2024 15:18:08 -0700 Subject: [PATCH 6/8] =?UTF-8?q?=E2=9C=A8=20`Tobias`:=20Add=20"New=20Payout?= =?UTF-8?q?"=20button=20to=20`Trust#show`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This gets us to our next interaction in the system test and prepares to build a form with the fields necessary to issue a Payout. --- app/furniture/tobias/routes.rb | 4 +++- app/furniture/tobias/trusts/show.html.erb | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/app/furniture/tobias/routes.rb b/app/furniture/tobias/routes.rb index 26f1f5e6b..75cf6babd 100644 --- a/app/furniture/tobias/routes.rb +++ b/app/furniture/tobias/routes.rb @@ -2,7 +2,9 @@ class Tobias class Routes def self.append_routes(router) router.resources :tobiases, module: "tobias" do - router.resources :trusts + router.resources :trusts do + router.resources :payouts + end end end end diff --git a/app/furniture/tobias/trusts/show.html.erb b/app/furniture/tobias/trusts/show.html.erb index 667e845bd..15aa56292 100644 --- a/app/furniture/tobias/trusts/show.html.erb +++ b/app/furniture/tobias/trusts/show.html.erb @@ -1 +1,3 @@ - +