Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avo actions to enqueue compact index file upload jobs #3970

Merged
merged 1 commit into from
Jul 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 15 additions & 0 deletions app/avo/actions/upload_info_file.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
class UploadInfoFile < BaseAction
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)
UploadInfoFileJob.perform_later(rubygem_name: rubygem.name)

succeed("Upload job scheduled")
end
end
end
18 changes: 18 additions & 0 deletions app/avo/actions/upload_versions_file.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
class UploadVersionsFile < BaseAction
self.name = "Upload Versions File"
self.visible = lambda {
current_user.team_member?("rubygems-org") && view == :index
}
self.standalone = true
self.confirm_button_label = "Upload"

class ActionHandler < ActionHandler
def handle_standalone
UploadVersionsFileJob.perform_later

succeed("Upload job scheduled")

Version.last
segiddins marked this conversation as resolved.
Show resolved Hide resolved
end
end
end
2 changes: 2 additions & 0 deletions app/avo/resources/rubygem_resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ class RubygemResource < Avo::BaseResource
action AddOwner
action YankRubygem
action ReserveNamespace
action UploadInfoFile
action UploadVersionsFile

class IndexedFilter < ScopeBooleanFilter; end
filter IndexedFilter, arguments: { default: { with_versions: true, without_versions: true } }
Expand Down
1 change: 1 addition & 0 deletions app/models/audit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ class Audit < ApplicationRecord
serialize :audited_changes, JSON

validates :action, presence: true
validates :auditable, presence: false
end
43 changes: 43 additions & 0 deletions test/system/avo/rubygems_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
class Avo::RubygemsSystemTest < ApplicationSystemTestCase
make_my_diffs_pretty!

include ActiveJob::TestHelper

def sign_in_as(user)
OmniAuth.config.mock_auth[:github] = OmniAuth::AuthHash.new(
provider: "github",
Expand Down Expand Up @@ -356,4 +358,45 @@ def sign_in_as(user)
end
page.assert_text "Namespace reserved: Successfully registered gem: foo (0.0.0.reserved.2)"
end

test "upload versions file" do
admin_user = create(:admin_github_user, :is_admin)
sign_in_as admin_user

visit avo.resources_rubygems_path

_ = create(:version)

click_button "Actions"
click_on "Upload Versions File"
fill_in "Comment", with: "A nice long comment"

assert_enqueued_jobs 1, only: UploadVersionsFileJob do
click_button "Upload"

page.assert_text "Upload job scheduled"
end

assert_not_nil Audit.last
end

test "upload info file" do
admin_user = create(:admin_github_user, :is_admin)
sign_in_as admin_user

version = create(:version)
visit avo.resources_rubygem_path(version.rubygem)

click_button "Actions"
click_on "Upload Info File"
fill_in "Comment", with: "A nice long comment"

assert_enqueued_jobs 1, only: UploadInfoFileJob do
click_button "Upload"

page.assert_text "Upload job scheduled"
end

assert_not_nil Audit.last
end
end