Skip to content

Commit

Permalink
Merge pull request #2562 from ClearlyClaire/glitch-soc/merge-upstream
Browse files Browse the repository at this point in the history
Merge upstream changes up to 0a7cff5
  • Loading branch information
ClearlyClaire committed Jan 11, 2024
2 parents e5b97ea + 0830407 commit cbc9516
Show file tree
Hide file tree
Showing 128 changed files with 745 additions and 668 deletions.
11 changes: 2 additions & 9 deletions .haml-lint_todo.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,13 @@
# This configuration was generated by
# `haml-lint --auto-gen-config`
# on 2024-01-08 14:02:57 -0500 using Haml-Lint version 0.53.0.
# on 2024-01-09 11:30:07 -0500 using Haml-Lint version 0.53.0.
# The point is for the user to remove these configuration records
# one by one as the lints are removed from the code base.
# Note that changes in the inspected code, or installation of new
# versions of Haml-Lint, may require this file to be generated again.

linters:
# Offense count: 10
# Offense count: 1
LineLength:
exclude:
- 'app/views/admin/roles/_form.html.haml'
- 'app/views/auth/registrations/edit.html.haml'
- 'app/views/auth/registrations/new.html.haml'
- 'app/views/media/player.html.haml'
- 'app/views/settings/applications/_fields.html.haml'
- 'app/views/settings/imports/index.html.haml'
- 'app/views/settings/preferences/appearance/show.html.haml'
- 'app/views/settings/preferences/other/show.html.haml'
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ gem 'omniauth', '~> 2.0'
gem 'omniauth-rails_csrf_protection', '~> 1.0'

gem 'color_diff', '~> 0.1'
gem 'csv', '~> 3.2'
gem 'discard', '~> 1.2'
gem 'doorkeeper', '~> 5.6'
gem 'ed25519', '~> 1.3'
Expand Down Expand Up @@ -75,7 +76,6 @@ gem 'premailer-rails'
gem 'rack-attack', '~> 6.6'
gem 'rack-cors', '~> 2.0', require: 'rack/cors'
gem 'rails-i18n', '~> 7.0'
gem 'rails-settings-cached', '~> 0.6', git: 'https://github.com/mastodon/rails-settings-cached.git', branch: 'v0.6.6-aliases-true'
gem 'redcarpet', '~> 3.6'
gem 'redis', '~> 4.5', require: ['redis', 'redis/connection/hiredis']
gem 'mario-redis-lock', '~> 1.2', require: 'redis_lock'
Expand Down
25 changes: 9 additions & 16 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,6 @@ GIT
sidekiq (>= 3.5)
statsd-ruby (~> 1.4, >= 1.4.0)

GIT
remote: https://github.com/mastodon/rails-settings-cached.git
revision: 86328ef0bd04ce21cc0504ff5e334591e8c2ccab
branch: v0.6.6-aliases-true
specs:
rails-settings-cached (0.6.6)
rails (>= 4.2.0)

GIT
remote: https://github.com/stanhu/omniauth-cas.git
revision: 4211e6d05941b4a981f9a36b49ec166cecd0e271
Expand Down Expand Up @@ -216,6 +208,7 @@ GEM
crass (1.0.6)
css_parser (1.14.0)
addressable
csv (3.2.8)
database_cleaner-active_record (2.1.0)
activerecord (>= 5.a)
database_cleaner-core (~> 2.0.0)
Expand Down Expand Up @@ -272,7 +265,7 @@ GEM
erubi (1.12.0)
et-orbi (1.2.7)
tzinfo
excon (0.104.0)
excon (0.109.0)
fabrication (2.31.0)
faker (3.2.2)
i18n (>= 1.8.11, < 2)
Expand Down Expand Up @@ -307,7 +300,7 @@ GEM
ffi-compiler (1.0.1)
ffi (>= 1.0.0)
rake
fog-core (2.3.0)
fog-core (2.4.0)
builder
excon (~> 0.71)
formatador (>= 0.2, < 2.0)
Expand Down Expand Up @@ -378,9 +371,9 @@ GEM
terminal-table (>= 1.5.1)
idn-ruby (0.1.5)
io-console (0.7.1)
irb (1.11.0)
irb (1.11.1)
rdoc
reline (>= 0.3.8)
reline (>= 0.4.2)
jmespath (1.6.2)
json (2.7.1)
json-canonicalization (1.0.0)
Expand Down Expand Up @@ -624,7 +617,7 @@ GEM
redlock (1.3.2)
redis (>= 3.0.0, < 6.0)
regexp_parser (2.8.3)
reline (0.4.1)
reline (0.4.2)
io-console (~> 0.5)
request_store (1.5.1)
rack (>= 1.4)
Expand Down Expand Up @@ -692,7 +685,7 @@ GEM
rubocop (~> 1.40)
rubocop-capybara (~> 2.17)
rubocop-factory_bot (~> 2.22)
ruby-prof (1.6.3)
ruby-prof (1.7.0)
ruby-progressbar (1.13.0)
ruby-saml (1.15.0)
nokogiri (>= 1.13.10)
Expand Down Expand Up @@ -724,7 +717,7 @@ GEM
rufus-scheduler (~> 3.2)
sidekiq (>= 6, < 8)
tilt (>= 1.4.0)
sidekiq-unique-jobs (7.1.30)
sidekiq-unique-jobs (7.1.31)
brpoplpush-redis_script (> 0.1.1, <= 2.0.0)
concurrent-ruby (~> 1.0, >= 1.0.5)
redis (< 5.0)
Expand Down Expand Up @@ -853,6 +846,7 @@ DEPENDENCIES
color_diff (~> 0.1)
concurrent-ruby
connection_pool
csv (~> 3.2)
database_cleaner-active_record
debug (~> 1.8)
devise (~> 4.9)
Expand Down Expand Up @@ -922,7 +916,6 @@ DEPENDENCIES
rails (~> 7.1.1)
rails-controller-testing (~> 1.0)
rails-i18n (~> 7.0)
rails-settings-cached (~> 0.6)!
rdf-normalize (~> 0.5)
redcarpet (~> 3.6)
redis (~> 4.5)
Expand Down
7 changes: 6 additions & 1 deletion app/controllers/api/v1/streaming_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

class Api::V1::StreamingController < Api::BaseController
def index
if Rails.configuration.x.streaming_api_base_url == request.host
if same_host?
not_found
else
redirect_to streaming_api_url, status: 301, allow_other_host: true
Expand All @@ -11,6 +11,11 @@ def index

private

def same_host?
base_url = Addressable::URI.parse(Rails.configuration.x.streaming_api_base_url)
request.host == base_url.host && request.port == (base_url.port || 80)
end

def streaming_api_url
Addressable::URI.parse(request.url).tap do |uri|
base_url = Addressable::URI.parse(Rails.configuration.x.streaming_api_base_url)
Expand Down
2 changes: 1 addition & 1 deletion app/helpers/languages_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ module LanguagesHelper
'en-GB': 'English (British)',
'es-AR': 'Español (Argentina)',
'es-MX': 'Español (México)',
'fr-QC': 'Français (Canadien)',
'fr-CA': 'Français (Canadien)',
'pt-BR': 'Português (Brasil)',
'pt-PT': 'Português (Portugal)',
'sr-Latn': 'Srpski (latinica)',
Expand Down
File renamed without changes.
80 changes: 0 additions & 80 deletions app/lib/settings/scoped_settings.rb

This file was deleted.

117 changes: 91 additions & 26 deletions app/models/setting.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,49 +13,114 @@
# thing_id :bigint(8)
#

class Setting < RailsSettings::Base
source Rails.root.join('config', 'settings.yml')
# This file is derived from a fork of the `rails-settings-cached` gem available at
# https://github.com/mastodon/rails-settings-cached/tree/v0.6.6-aliases-true, with
# the original available at:
# https://github.com/huacnlee/rails-settings-cached/tree/0.x

def to_param
var
end
# It is licensed as follows:

class << self
def [](key)
return super(key) unless rails_initialized?
# Copyright (c) 2006 Alex Wayne
# Some additional features added 2009 by Georg Ledermann

# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:

# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.

Rails.cache.fetch(cache_key(key, nil)) do
db_val = object(key)
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOa AND
# NONINFRINGEMENT. IN NO EVENT SaALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

if db_val
default_value = default_settings[key]
class Setting < ApplicationRecord
after_commit :rewrite_cache, on: %i(create update)
after_commit :expire_cache, on: %i(destroy)

return default_value.with_indifferent_access.merge!(db_val.value) if default_value.is_a?(Hash)
# Settings are server-wide settings only, but they were previously
# used for users too. This can be dropped later with a database
# migration dropping any scoped setting.
default_scope { where(thing_type: nil, thing_id: nil) }

db_val.value
else
default_settings[key]
end
class << self
# get or set a variable with the variable as the called method
# rubocop:disable Style/MissingRespondToMissing
def method_missing(method, *args)
# set a value for a variable
if method.end_with?('=')
var_name = method.to_s.chomp('=')
value = args.first
self[var_name] = value
else
# retrieve a value
self[method.to_s]
end
end
# rubocop:enable Style/MissingRespondToMissing

def all_as_records
vars = thing_scoped
records = vars.index_by(&:var)
def cache_prefix_by_startup
@cache_prefix_by_startup ||= Digest::MD5.hexdigest(default_settings.to_s)
end

default_settings.each do |key, default_value|
next if records.key?(key) || default_value.is_a?(Hash)
def cache_key(var_name)
"rails_settings_cached/#{cache_prefix_by_startup}/#{var_name}"
end

records[key] = Setting.new(var: key, value: default_value)
def [](key)
Rails.cache.fetch(cache_key(key)) do
db_val = find_by(var: key)
db_val ? db_val.value : default_settings[key]
end
end

records
# set a setting value by [] notation
def []=(var_name, value)
record = find_or_initialize_by(var: var_name.to_s)
record.value = value
record.save!
end

def default_settings
return {} unless RailsSettings::Default.enabled?
return @default_settings if defined?(@default_settings)

RailsSettings::Default.instance
content = Rails.root.join('config', 'settings.yml').read
hash = content.empty? ? {} : YAML.safe_load(ERB.new(content).result, aliases: true).to_hash
@default_settings = (hash[Rails.env] || {}).freeze
end
end

# get the value field, YAML decoded
def value
YAML.safe_load(self[:value], permitted_classes: [ActiveSupport::HashWithIndifferentAccess, Symbol]) if self[:value].present?
end

# set the value field, YAML encoded
def value=(new_value)
self[:value] = new_value.to_yaml
end

def rewrite_cache
Rails.cache.write(cache_key, value)
end

def expire_cache
Rails.cache.delete(cache_key)
end

def cache_key
self.class.cache_key(var)
end

def to_param
var
end
end

0 comments on commit cbc9516

Please sign in to comment.