~cytrogen/masto-fe

ref: 16681e0f20e1f8584e11439953c8d59b322571f5 masto-fe/app/models/software_update.rb -rw-r--r-- 969 bytes
16681e0f — Claire Add admin notifications for new Mastodon versions (#26582) 2 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# frozen_string_literal: true

# == Schema Information
#
# Table name: software_updates
#
#  id            :bigint(8)        not null, primary key
#  version       :string           not null
#  urgent        :boolean          default(FALSE), not null
#  type          :integer          default("patch"), not null
#  release_notes :string           default(""), not null
#  created_at    :datetime         not null
#  updated_at    :datetime         not null
#

class SoftwareUpdate < ApplicationRecord
  self.inheritance_column = nil

  enum type: { patch: 0, minor: 1, major: 2 }, _suffix: :type

  def gem_version
    Gem::Version.new(version)
  end

  class << self
    def check_enabled?
      ENV['UPDATE_CHECK_URL'] != ''
    end

    def pending_to_a
      return [] unless check_enabled?

      all.to_a.filter { |update| update.gem_version > Mastodon::Version.gem_version }
    end

    def urgent_pending?
      pending_to_a.any?(&:urgent?)
    end
  end
end