mirror of
https://github.com/mastodon/mastodon.git
synced 2025-03-12 17:05:25 +00:00

Some checks are pending
Check i18n / check-i18n (push) Waiting to run
CodeQL / Analyze (javascript) (push) Waiting to run
CodeQL / Analyze (ruby) (push) Waiting to run
Crowdin / Upload translations / upload-translations (push) Waiting to run
Check formatting / lint (push) Waiting to run
CSS Linting / lint (push) Waiting to run
Haml Linting / lint (push) Waiting to run
JavaScript Linting / lint (push) Waiting to run
Ruby Linting / lint (push) Waiting to run
JavaScript Testing / test (push) Waiting to run
Historical data migration test / test (14-alpine) (push) Waiting to run
Historical data migration test / test (15-alpine) (push) Waiting to run
Historical data migration test / test (16-alpine) (push) Waiting to run
Historical data migration test / test (17-alpine) (push) Waiting to run
Ruby Testing / build (production) (push) Waiting to run
Ruby Testing / build (test) (push) Waiting to run
Ruby Testing / test (.ruby-version) (push) Blocked by required conditions
Ruby Testing / test (3.2) (push) Blocked by required conditions
Ruby Testing / test (3.3) (push) Blocked by required conditions
Ruby Testing / Libvips tests (.ruby-version) (push) Blocked by required conditions
Ruby Testing / Libvips tests (3.2) (push) Blocked by required conditions
Ruby Testing / Libvips tests (3.3) (push) Blocked by required conditions
Ruby Testing / End to End testing (.ruby-version) (push) Blocked by required conditions
Ruby Testing / End to End testing (3.2) (push) Blocked by required conditions
Ruby Testing / End to End testing (3.3) (push) Blocked by required conditions
Ruby Testing / Elastic Search integration testing (.ruby-version, docker.elastic.co/elasticsearch/elasticsearch:7.17.13) (push) Blocked by required conditions
Ruby Testing / Elastic Search integration testing (.ruby-version, docker.elastic.co/elasticsearch/elasticsearch:8.10.2) (push) Blocked by required conditions
Ruby Testing / Elastic Search integration testing (.ruby-version, opensearchproject/opensearch:2) (push) Blocked by required conditions
Ruby Testing / Elastic Search integration testing (3.2, docker.elastic.co/elasticsearch/elasticsearch:7.17.13) (push) Blocked by required conditions
Ruby Testing / Elastic Search integration testing (3.3, docker.elastic.co/elasticsearch/elasticsearch:7.17.13) (push) Blocked by required conditions
56 lines
1.7 KiB
Ruby
56 lines
1.7 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
# == Schema Information
|
|
#
|
|
# Table name: terms_of_services
|
|
#
|
|
# id :bigint(8) not null, primary key
|
|
# changelog :text default(""), not null
|
|
# effective_date :date
|
|
# notification_sent_at :datetime
|
|
# published_at :datetime
|
|
# text :text default(""), not null
|
|
# created_at :datetime not null
|
|
# updated_at :datetime not null
|
|
#
|
|
class TermsOfService < ApplicationRecord
|
|
scope :published, -> { where.not(published_at: nil).order(Arel.sql('coalesce(effective_date, published_at) DESC')) }
|
|
scope :live, -> { published.where('effective_date IS NULL OR effective_date < now()').limit(1) }
|
|
scope :draft, -> { where(published_at: nil).order(id: :desc).limit(1) }
|
|
|
|
validates :text, presence: true
|
|
validates :changelog, :effective_date, presence: true, if: -> { published? }
|
|
|
|
validate :effective_date_cannot_be_in_the_past
|
|
|
|
def published?
|
|
published_at.present?
|
|
end
|
|
|
|
def effective?
|
|
published? && effective_date&.past?
|
|
end
|
|
|
|
def succeeded_by
|
|
TermsOfService.published.where(effective_date: (effective_date..)).where.not(id: id).first
|
|
end
|
|
|
|
def notification_sent?
|
|
notification_sent_at.present?
|
|
end
|
|
|
|
def scope_for_notification
|
|
User.confirmed.joins(:account).merge(Account.without_suspended).where(created_at: (..published_at))
|
|
end
|
|
|
|
private
|
|
|
|
def effective_date_cannot_be_in_the_past
|
|
return if effective_date.blank?
|
|
|
|
min_date = TermsOfService.live.pick(:effective_date) || Time.zone.today
|
|
|
|
errors.add(:effective_date, :too_soon, date: min_date) if effective_date < min_date
|
|
end
|
|
end
|