This commit is contained in:
2026-08-25 14:49:23 +02:00
parent c802605525
commit 552fdbe3a4
40 changed files with 207 additions and 182 deletions
@@ -0,0 +1,22 @@
module WarpEngine
module SoftDeletable
extend ActiveSupport::Concern
included do
scope :kept, -> { where(deleted_at: nil) }
scope :discarded, -> { where.not(deleted_at: nil) }
end
def soft_delete!
update_column(:deleted_at, Time.current)
end
def restore!
update_column(:deleted_at, nil)
end
def discarded?
deleted_at.present?
end
end
end
@@ -1,5 +1,13 @@
module WarpEngine
class ApplicationRecord < ActiveRecord::Base
self.abstract_class = true
def self.ransackable_attributes(auth_object = nil)
column_names
end
def self.ransackable_associations(auth_object = nil)
reflect_on_all_associations.map(&:name).map(&:to_s)
end
end
end
+4 -7
View File
@@ -9,12 +9,13 @@ module WarpEngine
CATALOG_SCOPE = "catalog".freeze
include SoftDeletable
attr_reader :plain_token
belongs_to :owner, polymorphic: true
default_scope { where(deleted_at: nil) }
scope :active, -> { where("expires_at IS NULL OR expires_at > ?", Time.current) }
scope :active, -> { kept.where("expires_at IS NULL OR expires_at > ?", Time.current) }
before_validation :assign_owner_type, on: :create
before_validation :generate_token, on: :create
@@ -45,7 +46,7 @@ module WarpEngine
end
def revoke!
update_column(:deleted_at, Time.current)
soft_delete!
end
def touch_last_used!
@@ -60,10 +61,6 @@ module WarpEngine
self.scopes = value.to_s.split(",").map(&:strip).reject(&:blank?).uniq
end
def self.ransackable_attributes(auth_object = nil)
%w[created_at deleted_at expires_at id last_used_at name owner_id owner_type token_prefix unrestricted updated_at]
end
def self.ransackable_associations(auth_object = nil)
[]
end
-4
View File
@@ -46,10 +46,6 @@ module WarpEngine
where(expires_at: ...Time.current).where.not(issued_token: nil).update_all(issued_token: nil)
end
def self.ransackable_attributes(auth_object = nil)
%w[approved_at client_name created_at denied_at expires_at id subject_id subject_type updated_at user_code]
end
def self.ransackable_associations(auth_object = nil)
[]
end
+2 -10
View File
@@ -1,19 +1,11 @@
module WarpEngine
class Download < ApplicationRecord
include SoftDeletable
belongs_to :release, optional: true
validates :file_path, presence: true
default_scope { where(deleted_at: nil) }
def self.ransackable_attributes(auth_object = nil)
%w[created_at deleted_at file_path id ip_address referer release_id updated_at user_agent]
end
def self.ransackable_associations(auth_object = nil)
%w[release]
end
ActiveSupport.run_load_hooks(:warp_engine_download, self)
end
end
+2 -10
View File
@@ -2,21 +2,13 @@ module WarpEngine
class ExternalLink < ApplicationRecord
self.table_name = "external_links"
include SoftDeletable
belongs_to :software
validates :label, presence: true
validates :url, presence: true
default_scope { where(deleted_at: nil) }
def self.ransackable_attributes(auth_object = nil)
%w[created_at deleted_at id label software_id updated_at url]
end
def self.ransackable_associations(auth_object = nil)
%w[software]
end
ActiveSupport.run_load_hooks(:warp_engine_external_link, self)
end
end
+7 -10
View File
@@ -4,12 +4,12 @@ module WarpEngine
UNKNOWN_PLATFORM = "unknown".freeze
include SoftDeletable
belongs_to :software, class_name: "WarpEngine::Software", optional: true
attr_reader :software_taken_from
default_scope { where(deleted_at: nil) }
before_save :claim_software_from_other_pipelines, if: :will_save_change_to_software_id?
validates :woodpecker_repo_id, presence: true, uniqueness: true
@@ -18,7 +18,9 @@ module WarpEngine
validates :platform, presence: true,
inclusion: { in: WarpEngine::PlatformLink::SUPPORTED_PLATFORMS + [ UNKNOWN_PLATFORM ] }
scope :active, -> { where(active: true) }
scope :active, -> { kept.where(active: true) }
scope :by_remote_repo_id, ->(id) { where(woodpecker_repo_id: id) }
def full_name
"#{repo_owner}/#{repo_name}"
@@ -32,13 +34,8 @@ module WarpEngine
self.woodpecker_repo_id = value
end
def self.ransackable_attributes(auth_object = nil)
%w[active created_at deleted_at id last_pipeline_at last_pipeline_status
platform repo_name repo_owner software_id woodpecker_repo_id]
end
def self.ransackable_associations(auth_object = nil)
%w[software]
def self.find_or_initialize_by_remote_repo_id(id)
find_or_initialize_by(woodpecker_repo_id: id)
end
private
+3 -10
View File
@@ -4,23 +4,16 @@ module WarpEngine
SUPPORTED_PLATFORMS = WarpEngine::Platform::NAMES
include SoftDeletable
validates :name, presence: true
validates :url, presence: true
validates :platform, presence: true, inclusion: { in: SUPPORTED_PLATFORMS }
default_scope { where(deleted_at: nil) }
scope :ordered, -> { order(:position) }
def self.ransackable_attributes(auth_object = nil)
%w[created_at deleted_at id name platform position updated_at url]
end
def self.ransackable_associations(auth_object = nil)
[]
end
def self.for_platform(platform)
ordered.where(platform: platform).to_a
kept.ordered.where(platform: platform).to_a
end
ActiveSupport.run_load_hooks(:warp_engine_platform_link, self)
+10 -12
View File
@@ -2,19 +2,25 @@ module WarpEngine
class Release < ApplicationRecord
self.table_name = "releases"
include SoftDeletable
belongs_to :software
has_many :downloads
has_many :release_assets
has_many :downloads, -> { kept }
has_many :release_assets, -> { kept }
accepts_nested_attributes_for :release_assets, allow_destroy: true
validates :version, presence: true
validates :version, uniqueness: { scope: :software_id }
default_scope { where(deleted_at: nil) }
validate :c64_cannot_be_web_playable
def self.latest_non_dev(releases)
sorted = releases.sort_by { |r| [r.created_at || Time.at(0), r.id] }.reverse
candidates = sorted.reject { |r| r.version.to_s.start_with?("dev-") }
candidates.empty? ? sorted.first : candidates.first
end
def c64_cannot_be_web_playable
return unless software&.platform == "c64"
@@ -24,14 +30,6 @@ module WarpEngine
end
end
def self.ransackable_attributes(auth_object = nil)
%w[created_at deleted_at id software_id updated_at version]
end
def self.ransackable_associations(auth_object = nil)
%w[downloads release_assets software]
end
ActiveSupport.run_load_hooks(:warp_engine_release, self)
end
end
+2 -10
View File
@@ -4,6 +4,8 @@ module WarpEngine
win_x86 win_x64 linux_x86 linux_x64 linux_arm64
mac_x64 mac_arm64 mac_universal].freeze
include SoftDeletable
belongs_to :release
enum :kind, KINDS.index_by(&:itself)
@@ -11,21 +13,11 @@ module WarpEngine
validates :path, presence: true
validates :kind, uniqueness: { scope: :release_id }
default_scope { where(deleted_at: nil) }
def self.for_relative_path(relative)
absolute = File.join(WarpEngine.config.file_container_path, relative.to_s)
find_by(path: absolute) || where("path LIKE ?", "%/#{sanitize_sql_like(relative.to_s)}").first
end
def self.ransackable_attributes(auth_object = nil)
%w[created_at deleted_at id kind path release_id updated_at]
end
def self.ransackable_associations(auth_object = nil)
%w[release]
end
ActiveSupport.run_load_hooks(:warp_engine_release_asset, self)
end
end
+5 -13
View File
@@ -4,14 +4,16 @@ module WarpEngine
STATUSES = %w[development demo released archived].freeze
include SoftDeletable
belongs_to :owner, polymorphic: true, optional: true
has_many :software_images, -> { ordered }, foreign_key: :software_id, dependent: :destroy
has_many :images, through: :software_images
has_many :releases, foreign_key: :software_id
has_many :releases, -> { kept }, foreign_key: :software_id
has_many :downloads, through: :releases
has_many :external_links, foreign_key: :software_id
has_one :pipeline, foreign_key: :software_id
has_many :external_links, -> { kept }, foreign_key: :software_id
has_one :pipeline, -> { kept }, foreign_key: :software_id
accepts_nested_attributes_for :software_images, allow_destroy: true
accepts_nested_attributes_for :external_links, allow_destroy: true
@@ -22,16 +24,6 @@ module WarpEngine
validates :platform, presence: true, inclusion: { in: WarpEngine::Platform::NAMES }
validates :status, inclusion: { in: STATUSES }, allow_blank: true
default_scope { where(deleted_at: nil) }
def self.ransackable_attributes(auth_object = nil)
%w[author created_at desc highlighted id license name owner_id owner_type platform site status story title updated_at]
end
def self.ransackable_associations(auth_object = nil)
%w[releases external_links software_images images]
end
ActiveSupport.run_load_hooks(:warp_engine_software, self)
end
end
-8
View File
@@ -15,14 +15,6 @@ module WarpEngine
scope :ordered, -> { order(:position) }
def self.ransackable_attributes(auth_object = nil)
%w[created_at id image_id is_default position software_id updated_at]
end
def self.ransackable_associations(auth_object = nil)
%w[image software]
end
ActiveSupport.run_load_hooks(:warp_engine_software_image, self)
private