From 4819d1e541df4069b950ca91b886502b30cfdc2b Mon Sep 17 00:00:00 2001 From: Martin Emde Date: Sat, 16 Nov 2024 16:56:56 -0600 Subject: [PATCH] fix avo resources for organizations (#5246) --- app/avo/resources/organization.rb | 11 +++++++++++ app/avo/resources/rubygem.rb | 2 ++ app/models/organization.rb | 4 +++- 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/app/avo/resources/organization.rb b/app/avo/resources/organization.rb index f15ebb2922d..b70f952cf09 100644 --- a/app/avo/resources/organization.rb +++ b/app/avo/resources/organization.rb @@ -7,6 +7,10 @@ class Avo::Resources::Organization < Avo::BaseResource } } + self.find_record_method = lambda { + query.find_by_handle!(id) + } + class DeletedFilter < Avo::Filters::ScopeBooleanFilter; end def filters @@ -20,5 +24,12 @@ def fields field :name, as: :text field :deleted_at, as: :date_time # add fields here + tabs style: :pills do + field :memberships, as: :has_many + field :unconfirmed_memberships, as: :has_many + field :users, as: :has_many + field :rubygems, as: :has_many + field :organization_onboarding, as: :belongs_to + end end end diff --git a/app/avo/resources/rubygem.rb b/app/avo/resources/rubygem.rb index fd9da1ca5f1..4f3c81c1698 100644 --- a/app/avo/resources/rubygem.rb +++ b/app/avo/resources/rubygem.rb @@ -37,6 +37,7 @@ def fields field :ownerships_including_unconfirmed, as: :has_many field :ownership_calls, as: :has_many field :ownership_requests, as: :has_many + field :organization, as: :belongs_to field :subscriptions, as: :has_many field :subscribers, as: :has_many, through: :subscriptions @@ -49,6 +50,7 @@ def fields field :oidc_rubygem_trusted_publishers, as: :has_many field :audits, as: :has_many + field :events, as: :has_many end end end diff --git a/app/models/organization.rb b/app/models/organization.rb index c13aadf846b..1e6560d26a9 100644 --- a/app/models/organization.rb +++ b/app/models/organization.rb @@ -13,7 +13,9 @@ class Organization < ApplicationRecord has_many :rubygems, dependent: :nullify has_one :organization_onboarding, foreign_key: :onboarded_organization_id, inverse_of: :organization, dependent: :destroy - scope :deleted, -> { where.not(deleted_at: nil) } + default_scope { not_deleted } + scope :not_deleted, -> { where(deleted_at: nil) } + scope :deleted, -> { unscoped.where.not(deleted_at: nil) } after_create do record_event!(Events::OrganizationEvent::CREATED, actor_gid: memberships.first&.to_gid)