Skip to content

Commit

Permalink
[WIP] Upgrade to avo 3
Browse files Browse the repository at this point in the history
  • Loading branch information
segiddins committed Jan 10, 2024
1 parent 7390a9b commit 4653038
Show file tree
Hide file tree
Showing 88 changed files with 917 additions and 822 deletions.
3 changes: 2 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ gem "strong_migrations", "~> 1.7"
gem "phlex-rails", "~> 1.1"

# Admin dashboard
gem "avo", "~> 2.46"
gem "avo", "~> 3.2"
# gem "avo-pro", "~> 3.2", source: "https://packager.dev/avo-hq/"
gem "view_component", "~> 3.9"
gem "pundit", "~> 2.3"
gem "chartkick", "~> 5.0"
Expand Down
25 changes: 13 additions & 12 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,11 @@ GEM
attr_required (1.0.2)
autoprefixer-rails (10.4.16.0)
execjs (~> 2)
avo (2.46.0)
actionview (>= 6.0)
avo (3.2.3)
actionview (>= 6.1)
active_link_to
activerecord (>= 6.0)
activerecord (>= 6.1)
activesupport (>= 6.1)
addressable
docile
dry-initializer
Expand All @@ -96,9 +97,9 @@ GEM
meta-tags
pagy
turbo-rails
turbo_power (~> 0.5.0)
view_component (>= 2.54.0)
zeitwerk (>= 2.6.2)
turbo_power (>= 0.6.0)
view_component (>= 3.7.0)
zeitwerk (>= 2.6.12)
awrence (1.2.1)
aws-eventstream (1.3.0)
aws-partitions (1.873.0)
Expand Down Expand Up @@ -347,8 +348,8 @@ GEM
marcel (1.0.2)
matrix (0.4.2)
memory_profiler (1.0.1)
meta-tags (2.19.0)
actionpack (>= 3.2.0, < 7.2)
meta-tags (2.20.0)
actionpack (>= 6.0.0, < 7.2)
method_source (1.0.0)
mini_histogram (0.3.1)
mini_mime (1.1.5)
Expand Down Expand Up @@ -427,7 +428,7 @@ GEM
openssl-signature_algorithm (1.3.0)
openssl (> 2.0)
optimist (3.1.0)
pagy (6.2.0)
pagy (6.3.0)
parallel (1.22.1)
parser (3.2.2.4)
ast (~> 2.4.1)
Expand Down Expand Up @@ -646,8 +647,8 @@ GEM
actionpack (>= 6.0.0)
activejob (>= 6.0.0)
railties (>= 6.0.0)
turbo_power (0.5.0)
turbo-rails (~> 1.3)
turbo_power (0.6.1)
turbo-rails (>= 1.3.0)
tzinfo (2.0.6)
concurrent-ruby (~> 1.0)
unicode-display_width (2.4.2)
Expand Down Expand Up @@ -699,7 +700,7 @@ DEPENDENCIES
aggregate_assertions (~> 0.2.0)
amazing_print (~> 1.4)
autoprefixer-rails (~> 10.4)
avo (~> 2.46)
avo (~> 3.2)
aws-sdk-s3 (~> 1.142)
aws-sdk-sqs (~> 1.69)
bcrypt (~> 3.1)
Expand Down
12 changes: 7 additions & 5 deletions app/avo/actions/add_owner.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
class AddOwner < BaseAction
class Avo::Actions::AddOwner < Avo::Actions::ApplicationAction

Check warning on line 1 in app/avo/actions/add_owner.rb

View check run for this annotation

Codecov / codecov/patch

app/avo/actions/add_owner.rb#L1

Added line #L1 was not covered by tests
self.name = "Add owner"
self.visible = lambda {
current_user.team_member?("rubygems-org") && view == :show
}

field :owner, as: :select_record, searchable: true, name: "New owner", use_resource: UserResource
def fields
field :owner, as: :select_record, searchable: true, name: "New owner", use_resource: Avo::Resources::User
end

Check warning on line 9 in app/avo/actions/add_owner.rb

View check run for this annotation

Codecov / codecov/patch

app/avo/actions/add_owner.rb#L7-L9

Added lines #L7 - L9 were not covered by tests

self.message = lambda {
"Are you sure you would like to add an owner to #{record.name}?"
Expand All @@ -22,16 +24,16 @@ class ActionHandler < ActionHandler
error "Cannot add #{@owner.name} as an owner since they are unconfirmed" if @owner.unconfirmed?
end

def do_handle_model(rubygem)
def do_handle_record(rubygem)

Check warning on line 27 in app/avo/actions/add_owner.rb

View check run for this annotation

Codecov / codecov/patch

app/avo/actions/add_owner.rb#L27

Added line #L27 was not covered by tests
@rubygem = rubygem
super
end

set_callback :handle_model, :before do
set_callback :handle_record, :before do

Check warning on line 32 in app/avo/actions/add_owner.rb

View check run for this annotation

Codecov / codecov/patch

app/avo/actions/add_owner.rb#L32

Added line #L32 was not covered by tests
error "Cannot add #{@owner.name} as an owner since they are already an owner of #{@rubygem.name}" if @owner.rubygems.include?(@rubygem)
end

def handle_model(rubygem)
def handle_record(rubygem)

Check warning on line 36 in app/avo/actions/add_owner.rb

View check run for this annotation

Codecov / codecov/patch

app/avo/actions/add_owner.rb#L36

Added line #L36 was not covered by tests
authorizer = User.security_user
rubygem.ownerships.create!(user: @owner, authorizer: authorizer, confirmed_at: Time.current)
succeed "Added #{@owner.name} to #{@rubygem.name}"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
class BaseAction < Avo::BaseAction
class Avo::Actions::ApplicationAction < Avo::BaseAction

Check warning on line 1 in app/avo/actions/application_action.rb

View check run for this annotation

Codecov / codecov/patch

app/avo/actions/application_action.rb#L1

Added line #L1 was not covered by tests
include SemanticLogger::Loggable

field :comment, as: :textarea, required: true,
help: "A comment explaining why this action was taken.<br>Will be saved in the audit log.<br>Must be more than 10 characters."

def self.inherited(base)
super
base.items_holder = Avo::ItemsHolder.new
base.items_holder.instance_variable_get(:@items).replace items_holder.instance_variable_get(:@items).deep_dup
base.items_holder.invalid_fields.replace items_holder.invalid_fields.deep_dup
def fields
field :comment, as: :textarea, required: true,
help: "A comment explaining why this action was taken.<br>Will be saved in the audit log.<br>Must be more than 10 characters."

Check warning on line 6 in app/avo/actions/application_action.rb

View check run for this annotation

Codecov / codecov/patch

app/avo/actions/application_action.rb#L4-L6

Added lines #L4 - L6 were not covered by tests
end

# def self.inherited(base)
# super
# base.items_holder = Avo::Resources::Items::Holder.new
# base.items_holder.instance_variable_get(:@items).replace items_holder.instance_variable_get(:@items).deep_dup
# base.items_holder.invalid_fields.replace items_holder.invalid_fields.deep_dup
# end

class ActionHandler
include Auditable
include SemanticLogger::Loggable
Expand All @@ -20,7 +22,7 @@ class ActionHandler
result_lambda.call
target.errored?
}
define_callbacks :handle_model, terminator: lambda { |target, result_lambda|
define_callbacks :handle_record, terminator: lambda { |target, result_lambda|

Check warning on line 25 in app/avo/actions/application_action.rb

View check run for this annotation

Codecov / codecov/patch

app/avo/actions/application_action.rb#L25

Added line #L25 was not covered by tests
result_lambda.call
target.errored?
}
Expand All @@ -35,9 +37,9 @@ def initialize( # rubocop:disable Metrics/ParameterLists
arguments:,
resource:,
action:,
models: nil
records: nil

Check warning on line 40 in app/avo/actions/application_action.rb

View check run for this annotation

Codecov / codecov/patch

app/avo/actions/application_action.rb#L40

Added line #L40 was not covered by tests
)
@models = models
@records = records

Check warning on line 42 in app/avo/actions/application_action.rb

View check run for this annotation

Codecov / codecov/patch

app/avo/actions/application_action.rb#L42

Added line #L42 was not covered by tests
@fields = fields
@current_user = current_user
@arguments = arguments
Expand All @@ -46,7 +48,7 @@ def initialize( # rubocop:disable Metrics/ParameterLists
@action = action
end

attr_reader :models, :fields, :current_user, :arguments, :resource
attr_reader :records, :fields, :current_user, :arguments, :resource

Check warning on line 51 in app/avo/actions/application_action.rb

View check run for this annotation

Codecov / codecov/patch

app/avo/actions/application_action.rb#L51

Added line #L51 was not covered by tests

delegate :error, :avo, :keep_modal_open, :redirect_to, :inform, :action_name, :succeed, :logger,
to: :@action
Expand All @@ -72,9 +74,9 @@ def do_handle
keep_modal_open if errored?
end

def do_handle_model(model)
run_callbacks :handle_model do
handle_model(model)
def do_handle_record(record)
run_callbacks :handle_record do
handle_record(record)

Check warning on line 79 in app/avo/actions/application_action.rb

View check run for this annotation

Codecov / codecov/patch

app/avo/actions/application_action.rb#L77-L79

Added lines #L77 - L79 were not covered by tests
end
end

Expand All @@ -89,7 +91,7 @@ def do_handle_standalone
action: action_name,
fields:,
arguments:,
models:
records:

Check warning on line 94 in app/avo/actions/application_action.rb

View check run for this annotation

Codecov / codecov/patch

app/avo/actions/application_action.rb#L94

Added line #L94 was not covered by tests
) do
run_callbacks :handle_standalone do
handle_standalone
Expand All @@ -99,17 +101,17 @@ def do_handle_standalone
end

def handle
return do_handle_standalone if models.nil?
models.each do |model|
return do_handle_standalone if records.nil?
records.each do |record|

Check warning on line 105 in app/avo/actions/application_action.rb

View check run for this annotation

Codecov / codecov/patch

app/avo/actions/application_action.rb#L104-L105

Added lines #L104 - L105 were not covered by tests
_, audit = in_audited_transaction(
auditable: model,
auditable: record,

Check warning on line 107 in app/avo/actions/application_action.rb

View check run for this annotation

Codecov / codecov/patch

app/avo/actions/application_action.rb#L107

Added line #L107 was not covered by tests
admin_github_user: current_user,
action: action_name,
fields:,
arguments:,
models:
records:

Check warning on line 112 in app/avo/actions/application_action.rb

View check run for this annotation

Codecov / codecov/patch

app/avo/actions/application_action.rb#L112

Added line #L112 was not covered by tests
) do
do_handle_model(model)
do_handle_record(record)

Check warning on line 114 in app/avo/actions/application_action.rb

View check run for this annotation

Codecov / codecov/patch

app/avo/actions/application_action.rb#L114

Added line #L114 was not covered by tests
end
redirect_to avo.resources_audit_path(audit)
end
Expand Down
4 changes: 2 additions & 2 deletions app/avo/actions/block_user.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class BlockUser < BaseAction
class Avo::Actions::BlockUser < Avo::Actions::ApplicationAction

Check warning on line 1 in app/avo/actions/block_user.rb

View check run for this annotation

Codecov / codecov/patch

app/avo/actions/block_user.rb#L1

Added line #L1 was not covered by tests
self.name = "Block User"
self.visible = lambda {
current_user.team_member?("rubygems-org") && view == :show
Expand All @@ -11,7 +11,7 @@ class BlockUser < BaseAction
self.confirm_button_label = "Block User"

class ActionHandler < ActionHandler
def handle_model(user)
def handle_record(user)

Check warning on line 14 in app/avo/actions/block_user.rb

View check run for this annotation

Codecov / codecov/patch

app/avo/actions/block_user.rb#L14

Added line #L14 was not covered by tests
user.block!
end
end
Expand Down
8 changes: 5 additions & 3 deletions app/avo/actions/change_user_email.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
class ChangeUserEmail < BaseAction
field :from_email, name: "Email", as: :text, required: true
class Avo::Actions::ChangeUserEmail < Avo::Actions::ApplicationAction
def fields
field :from_email, name: "Email", as: :text, required: true
end

Check warning on line 4 in app/avo/actions/change_user_email.rb

View check run for this annotation

Codecov / codecov/patch

app/avo/actions/change_user_email.rb#L1-L4

Added lines #L1 - L4 were not covered by tests

self.name = "Change User Email"
self.visible = lambda {
Expand All @@ -9,7 +11,7 @@ class ChangeUserEmail < BaseAction
self.confirm_button_label = "Change User Email"

class ActionHandler < ActionHandler
def handle_model(user)
def handle_record(user)

Check warning on line 14 in app/avo/actions/change_user_email.rb

View check run for this annotation

Codecov / codecov/patch

app/avo/actions/change_user_email.rb#L14

Added line #L14 was not covered by tests
user.email = fields["from_email"]
user.email_confirmed = false
user.generate_confirmation_token
Expand Down
8 changes: 5 additions & 3 deletions app/avo/actions/create_user.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
class CreateUser < BaseAction
field :email, name: "Email", as: :text, required: true

class Avo::Actions::CreateUser < Avo::Actions::ApplicationAction

Check warning on line 1 in app/avo/actions/create_user.rb

View check run for this annotation

Codecov / codecov/patch

app/avo/actions/create_user.rb#L1

Added line #L1 was not covered by tests
self.name = "Create User"
self.visible = lambda {
current_user.team_member?("rubygems-org") && view == :index && !Rails.env.production?
Expand All @@ -9,6 +7,10 @@ class CreateUser < BaseAction

self.confirm_button_label = "Create User"

def fields
field :email, name: "Email", as: :text, required: true
end

Check warning on line 12 in app/avo/actions/create_user.rb

View check run for this annotation

Codecov / codecov/patch

app/avo/actions/create_user.rb#L10-L12

Added lines #L10 - L12 were not covered by tests

class ActionHandler < ActionHandler
def handle_standalone
user = User.new(
Expand Down
4 changes: 2 additions & 2 deletions app/avo/actions/delete_webhook.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class DeleteWebhook < BaseAction
class Avo::Actions::DeleteWebhook < Avo::Actions::ApplicationAction

Check warning on line 1 in app/avo/actions/delete_webhook.rb

View check run for this annotation

Codecov / codecov/patch

app/avo/actions/delete_webhook.rb#L1

Added line #L1 was not covered by tests
self.name = "Delete Webhook"
self.visible = lambda {
current_user.team_member?("rubygems-org") && view == :show
Expand All @@ -11,7 +11,7 @@ class DeleteWebhook < BaseAction
self.confirm_button_label = "Delete Webhook"

class ActionHandler < ActionHandler
def handle_model(webhook)
def handle_record(webhook)

Check warning on line 14 in app/avo/actions/delete_webhook.rb

View check run for this annotation

Codecov / codecov/patch

app/avo/actions/delete_webhook.rb#L14

Added line #L14 was not covered by tests
webhook.destroy!
WebHooksMailer.webhook_deleted(webhook.user_id, webhook.rubygem_id, webhook.url, webhook.failure_count).deliver_later
end
Expand Down
4 changes: 2 additions & 2 deletions app/avo/actions/refresh_oidc_provider.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class RefreshOIDCProvider < BaseAction
class Avo::Actions::RefreshOIDCProvider < Avo::Actions::ApplicationAction

Check warning on line 1 in app/avo/actions/refresh_oidc_provider.rb

View check run for this annotation

Codecov / codecov/patch

app/avo/actions/refresh_oidc_provider.rb#L1

Added line #L1 was not covered by tests
self.name = "Refresh OIDC Provider"
self.visible = lambda {
current_user.team_member?("rubygems-org") && view == :show
Expand All @@ -11,7 +11,7 @@ class RefreshOIDCProvider < BaseAction
self.confirm_button_label = "Refresh"

class ActionHandler < ActionHandler
def handle_model(provider)
def handle_record(provider)

Check warning on line 14 in app/avo/actions/refresh_oidc_provider.rb

View check run for this annotation

Codecov / codecov/patch

app/avo/actions/refresh_oidc_provider.rb#L14

Added line #L14 was not covered by tests
RefreshOIDCProviderJob.perform_now(provider:)
end
end
Expand Down
4 changes: 2 additions & 2 deletions app/avo/actions/release_reserved_namespace.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class ReleaseReservedNamespace < BaseAction
class Avo::Actions::ReleaseReservedNamespace < Avo::Actions::ApplicationAction

Check warning on line 1 in app/avo/actions/release_reserved_namespace.rb

View check run for this annotation

Codecov / codecov/patch

app/avo/actions/release_reserved_namespace.rb#L1

Added line #L1 was not covered by tests
self.name = "Release reserved namespace"
self.visible = lambda {
current_user.team_member?("rubygems-org") && view == :show
Expand All @@ -11,7 +11,7 @@ class ReleaseReservedNamespace < BaseAction
self.confirm_button_label = "Release namespace"

class ActionHandler < ActionHandler
def handle_model(rubygem)
def handle_record(rubygem)

Check warning on line 14 in app/avo/actions/release_reserved_namespace.rb

View check run for this annotation

Codecov / codecov/patch

app/avo/actions/release_reserved_namespace.rb#L14

Added line #L14 was not covered by tests
rubygem.release_reserved_namespace!
end
end
Expand Down
18 changes: 10 additions & 8 deletions app/avo/actions/reset_api_key.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class ResetApiKey < BaseAction
class Avo::Actions::ResetApiKey < Avo::Actions::ApplicationAction

Check warning on line 1 in app/avo/actions/reset_api_key.rb

View check run for this annotation

Codecov / codecov/patch

app/avo/actions/reset_api_key.rb#L1

Added line #L1 was not covered by tests
self.name = "Reset Api Key"
self.visible = lambda {
current_user.team_member?("rubygems-org") && view == :show
Expand All @@ -8,15 +8,17 @@ class ResetApiKey < BaseAction
}
self.confirm_button_label = "Reset Api Key"

field :template, as: :select,
options: {
"Public Gem": :public_gem_reset_api_key,
Honeycomb: :honeycomb_reset_api_key
},
help: "Select mailer template"
def fields
field :template, as: :select,
options: {
"Public Gem": :public_gem_reset_api_key,
Honeycomb: :honeycomb_reset_api_key
},
help: "Select mailer template"
end

Check warning on line 18 in app/avo/actions/reset_api_key.rb

View check run for this annotation

Codecov / codecov/patch

app/avo/actions/reset_api_key.rb#L11-L18

Added lines #L11 - L18 were not covered by tests

class ActionHandler < ActionHandler
def handle_model(user)
def handle_record(user)

Check warning on line 21 in app/avo/actions/reset_api_key.rb

View check run for this annotation

Codecov / codecov/patch

app/avo/actions/reset_api_key.rb#L21

Added line #L21 was not covered by tests
user.reset_api_key!

Mailer.reset_api_key(user, fields["template"]).deliver_later
Expand Down
4 changes: 2 additions & 2 deletions app/avo/actions/reset_user_2fa.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class ResetUser2fa < BaseAction
class Avo::Actions::ResetUser2fa < Avo::Actions::ApplicationAction

Check warning on line 1 in app/avo/actions/reset_user_2fa.rb

View check run for this annotation

Codecov / codecov/patch

app/avo/actions/reset_user_2fa.rb#L1

Added line #L1 was not covered by tests
self.name = "Reset User 2FA"
self.visible = lambda {
current_user.team_member?("rubygems-org") && view == :show
Expand All @@ -11,7 +11,7 @@ class ResetUser2fa < BaseAction
self.confirm_button_label = "Reset MFA"

class ActionHandler < ActionHandler
def handle_model(user)
def handle_record(user)

Check warning on line 14 in app/avo/actions/reset_user_2fa.rb

View check run for this annotation

Codecov / codecov/patch

app/avo/actions/reset_user_2fa.rb#L14

Added line #L14 was not covered by tests
user.disable_totp!
user.password = SecureRandom.hex(20).encode("UTF-8")
user.save!
Expand Down
6 changes: 3 additions & 3 deletions app/avo/actions/restore_version.rb
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
class RestoreVersion < BaseAction
class Avo::Actions::RestoreVersion < Avo::Actions::ApplicationAction

Check warning on line 1 in app/avo/actions/restore_version.rb

View check run for this annotation

Codecov / codecov/patch

app/avo/actions/restore_version.rb#L1

Added line #L1 was not covered by tests
self.name = "Restore version"
self.visible = lambda {
current_user.team_member?("rubygems-org") &&
view == :show &&
resource.model.deletion.present?
resource.record.deletion.present?

Check warning on line 6 in app/avo/actions/restore_version.rb

View check run for this annotation

Codecov / codecov/patch

app/avo/actions/restore_version.rb#L6

Added line #L6 was not covered by tests
}
self.message = lambda {
"Are you sure you would like to restore #{record.slug} with "
}
self.confirm_button_label = "Restore version"

class ActionHandler < ActionHandler
def handle_model(version)
def handle_record(version)

Check warning on line 14 in app/avo/actions/restore_version.rb

View check run for this annotation

Codecov / codecov/patch

app/avo/actions/restore_version.rb#L14

Added line #L14 was not covered by tests
version.deletion&.restore!
end
end
Expand Down
4 changes: 2 additions & 2 deletions app/avo/actions/upload_info_file.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
class UploadInfoFile < BaseAction
class Avo::Actions::UploadInfoFile < Avo::Actions::ApplicationAction

Check warning on line 1 in app/avo/actions/upload_info_file.rb

View check run for this annotation

Codecov / codecov/patch

app/avo/actions/upload_info_file.rb#L1

Added line #L1 was not covered by tests
self.name = "Upload Info File"
self.visible = lambda {
current_user.team_member?("rubygems-org") && view == :show
}
self.confirm_button_label = "Upload"

class ActionHandler < ActionHandler
def handle_model(rubygem)
def handle_record(rubygem)

Check warning on line 9 in app/avo/actions/upload_info_file.rb

View check run for this annotation

Codecov / codecov/patch

app/avo/actions/upload_info_file.rb#L9

Added line #L9 was not covered by tests
UploadInfoFileJob.perform_later(rubygem_name: rubygem.name)

succeed("Upload job scheduled")
Expand Down
Loading

0 comments on commit 4653038

Please sign in to comment.