Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem "byebug", platforms: [:mri, :mingw, :x64_mingw]
gem "rspec-rails"
gem "standard", "~> 1.50"
gem "standard", "~> 1.51"
gem "factory_bot"
gem "faker", "~> 3.5"
gem "guard", "~> 2.19"
Expand Down
14 changes: 7 additions & 7 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -732,15 +732,15 @@ GEM
rswag-ui (2.16.0)
actionpack (>= 5.2, < 8.1)
railties (>= 5.2, < 8.1)
rubocop (1.75.8)
rubocop (1.80.2)
json (~> 2.3)
language_server-protocol (~> 3.17.0.2)
lint_roller (~> 1.1.0)
parallel (~> 1.10)
parser (>= 3.3.0.2)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 2.9.3, < 3.0)
rubocop-ast (>= 1.44.0, < 2.0)
rubocop-ast (>= 1.46.0, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 2.4.0, < 4.0)
rubocop-ast (1.47.1)
Expand Down Expand Up @@ -834,10 +834,10 @@ GEM
sqlite3_ar_regexp (3.0.0)
activerecord (>= 6.0)
sqlite3 (>= 1.4)
standard (1.50.0)
standard (1.51.0)
language_server-protocol (~> 3.17.0.2)
lint_roller (~> 1.0)
rubocop (~> 1.75.5)
rubocop (~> 1.80.2)
standard-custom (~> 1.0.0)
standard-performance (~> 1.8)
standard-custom (1.0.2)
Expand Down Expand Up @@ -1034,7 +1034,7 @@ DEPENDENCIES
spdx (~> 4.1)
spring
sqlite3_ar_regexp (~> 3.0)
standard (~> 1.50)
standard (~> 1.51)
stimulus-rails (~> 1.3.4)
stopwords-filter2
string-similarity (~> 2.1)
Expand Down Expand Up @@ -1312,7 +1312,7 @@ CHECKSUMS
rswag-api (2.16.0) sha256=b653f7bd92e98be18b01ab4525d88950d7b0960e293a99f856b9efcee3ae6074
rswag-specs (2.16.0) sha256=8ba26085c408b0bd2ed21dc8015c80f417c7d34c63720ab7133c2549b5bd2a91
rswag-ui (2.16.0) sha256=a1f49e927dceda92e6e6e7c1000f1e217ee66c565f69e28131dc98b33cd3a04f
rubocop (1.75.8) sha256=c80ab4286c5dcfc49d7ad1787cdba5569b63b58c96ee7afde4ec47a9c8a85be9
rubocop (1.80.2)
rubocop-ast (1.47.1) sha256=592682017855408b046a8190689490763aecea175238232b1b526826349d01ae
rubocop-capybara (2.22.1) sha256=ced88caef23efea53f46e098ff352f8fc1068c649606ca75cb74650970f51c0c
rubocop-factory_bot (2.27.1) sha256=9d744b5916778c1848e5fe6777cc69855bd96548853554ec239ba9961b8573fe
Expand Down Expand Up @@ -1349,7 +1349,7 @@ CHECKSUMS
sqlite3 (2.5.0-x86_64-darwin) sha256=e3c6d2fa04db9d0773455cb6c79835f230c363424b69c34dd718e1aff8609d35
sqlite3 (2.5.0-x86_64-linux-gnu) sha256=c62c8d625da7e2ce93d694f02cd9c9d537638f56b09f2e8f28bea2d030b3923b
sqlite3_ar_regexp (3.0.0) sha256=90ce99f00b9256721104550853a227e31972c6488963f203aa50f053a8c7c005
standard (1.50.0) sha256=b6c67f61fd6cedeec90ee338c6e913d9ccc4c467660ad1575da8aa6ba10f4aec
standard (1.51.0)
standard-custom (1.0.2) sha256=424adc84179a074f1a2a309bb9cf7cd6bfdb2b6541f20c6bf9436c0ba22a652b
standard-performance (1.8.0) sha256=ed17b7d0e061b2a19a91dd434bef629439e2f32310f22f26acb451addc92b788
starry (0.2.0) sha256=2696b0a165694269177bd7d98f77b6e76fd62b69455f297684ba416088d429b1
Expand Down
1 change: 1 addition & 0 deletions app/components/link_list.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ def initialize(links:)

def view_template
return if @links.empty?

ul class: "list-unstyled" do
@links.each do |link|
if link.valid?
Expand Down
2 changes: 1 addition & 1 deletion app/components/model_summary.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def view_template
end
div(class: "col-auto") do
credits
div { @model.tags.map { |it| Tag(tag: it) } }
div { @model.tags.map { Tag(tag: it) } }
end
end
end
Expand Down
2 changes: 2 additions & 0 deletions app/components/preview_frame.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ def initialize(object:)

def before_template
return if remote?

@file = @object.is_a?(Model) ? @object.preview_file : policy_scope(@object.models).first&.preview_file
end

Expand Down Expand Up @@ -67,6 +68,7 @@ def render_remote

def needs_hiding?
return false unless current_user.nil? || current_user.sensitive_content_handling.present?

case @object.class
when Model
@object.sensitive
Expand Down
1 change: 1 addition & 0 deletions app/components/search_help.rb
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ def negation

def federation
return unless SiteSettings.federation_enabled?

tr do
td do
code { "@[email protected]" }
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/activity_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ class ActivityController < ApplicationController
]

def index
@jobs = ActiveJob::Status.all.sort_by { |it| it.last_activity || "" }.reverse # rubocop:disable Pundit/UsePolicyScope
@jobs.reject! { |it| EXCLUSIONS.include? it.read.dig(:serialized_job, "job_class") }
@jobs = ActiveJob::Status.all.sort_by { it.last_activity || "" }.reverse # rubocop:disable Pundit/UsePolicyScope
@jobs.reject! { EXCLUSIONS.include? it.read.dig(:serialized_job, "job_class") }
@jobs = Kaminari.paginate_array(@jobs).page(params[:page]).per(50)
end
end
3 changes: 3 additions & 0 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
class ApplicationController < ActionController::Base
include Pundit::Authorization
include BetterContentSecurityPolicy::HasContentSecurityPolicy

after_action :verify_authorized, except: :index, unless: -> { respond_to?(:fasp_client_controller?) }
after_action :verify_policy_scoped, only: :index, unless: -> { respond_to?(:fasp_client_controller?) }
after_action :set_content_security_policy_header, if: -> { request.format.html? }
Expand Down Expand Up @@ -126,6 +127,7 @@ def switch_locale(&action)
def show_security_alerts
return unless current_user&.is_administrator?
return if ENV.fetch("SUDO_RUN_UNSAFELY", nil) === "enabled"

flash.now[:alert] = t("security.running_as_root_html") if Process.uid == 0
end

Expand Down Expand Up @@ -154,6 +156,7 @@ def set_indexable(content)

def send_file_content(attachment, disposition: :attachment, derivative: nil)
head :not_found and return if attachment.nil?

# Check if we can send a direct URL
redirect_to(attachment.url, allow_other_host: true) if /https?:\/\//.match?(attachment.url)
# Otherwise provide a direct download
Expand Down
1 change: 1 addition & 0 deletions app/controllers/benchmark_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ def login_as_admin
# should stop it happening, but *just in case* we'll check
# here as well and explode if we're in prod.
raise ActionController::BadRequest if Rails.env.production?

sign_in(:user, User.with_role(:administrator).first)
end

Expand Down
1 change: 1 addition & 0 deletions app/controllers/collections_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ def get_parent_collections
def collection_params
if is_api_request?
raise ActionController::BadRequest unless params[:json]

ManyfoldApi::V0::CollectionDeserializer.new(params[:json]).deserialize
else
Form::CollectionDeserializer.new(params).deserialize
Expand Down
1 change: 1 addition & 0 deletions app/controllers/concerns/filterable.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
module Filterable
extend ActiveSupport::Concern

included do
before_action :get_filters, only: [:index, :show] # rubocop:todo Rails/LexicallyScopedActionFilter
end
Expand Down
1 change: 1 addition & 0 deletions app/controllers/creators_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ def get_creator
def creator_params
if is_api_request?
raise ActionController::BadRequest unless params[:json]

ManyfoldApi::V0::CreatorDeserializer.new(params[:json]).deserialize
else
Form::CreatorDeserializer.new(params).deserialize
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/follows_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,13 @@ def destroy
def get_recommended_accounts
@recommended = FaspClient::Provider.find_each.map do |provider|
provider.follow_recommendation(current_user.federails_actor.federated_url)
end.flatten.uniq.map { |it| Federails::Actor.find_or_create_by_federation_url it }.reject(&:local)
end.flatten.uniq.map { Federails::Actor.find_or_create_by_federation_url it }.reject(&:local)
end

def search(query)
FaspClient::Provider.find_each.map do |provider|
provider.account_search(query)
end.flatten.uniq.map { |it| Federails::Actor.find_or_create_by_federation_url it }.reject(&:local)
end.flatten.uniq.map { Federails::Actor.find_or_create_by_federation_url it }.reject(&:local)
end

def get_target
Expand Down
1 change: 1 addition & 0 deletions app/controllers/libraries_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ class LibrariesController < ApplicationController

def index
redirect_to new_library_path and return if Library.count === 0 # rubocop:disable Pundit/UsePolicyScope

render layout: "settings"
end

Expand Down
2 changes: 2 additions & 0 deletions app/controllers/model_files_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ def bulk_update_params
def file_params
if is_api_request?
raise ActionController::BadRequest unless params[:json]

ManyfoldApi::V0::ModelFileDeserializer.new(params[:json]).deserialize
else
Form::ModelFileDeserializer.new(params).deserialize
Expand All @@ -147,6 +148,7 @@ def file_params
def upload_params
if is_api_request?
raise ActionController::BadRequest unless params[:json]

ManyfoldApi::V0::UploadedFileDeserializer.new(params[:json]).deserialize
else
Form::UploadedFileDeserializer.new(params).deserialize
Expand Down
2 changes: 2 additions & 0 deletions app/controllers/models_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ def bulk_update_params
def model_params
if is_api_request?
raise ActionController::BadRequest unless params[:json]

ManyfoldApi::V0::ModelDeserializer.new(params[:json]).deserialize
else
Form::ModelDeserializer.new(params).deserialize
Expand All @@ -234,6 +235,7 @@ def model_params
def upload_params
if is_api_request?
raise ActionController::BadRequest unless params[:json]

ManyfoldApi::V0::UploadedModelDeserializer.new(params[:json]).deserialize
else
Form::UploadedModelDeserializer.new(params).deserialize
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/settings/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def user_params
)
# Filter out admin privilege for anyone but admins
unless current_user.is_administrator?
filtered[:role_ids]&.delete_if { |it| @available_roles.map(&:id).exclude? it.to_i }
filtered[:role_ids]&.delete_if { @available_roles.map(&:id).exclude? it.to_i }
end
filtered
end
Expand Down
11 changes: 11 additions & 0 deletions app/controllers/settings_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,22 @@ def update

def update_folder_settings(settings)
return unless settings

SiteSettings.model_path_template = settings[:model_path_template].gsub(/^\//, "") # Remove leading slashes
SiteSettings.parse_metadata_from_path = settings[:parse_metadata_from_path]
SiteSettings.safe_folder_names = settings[:safe_folder_names]
end

def update_file_settings(settings)
return unless settings

regexes = settings[:model_ignored_files].lines.map { |p| p.chomp.to_regexp }
SiteSettings.model_ignored_files = regexes unless regexes.any?(&:nil?)
end

def update_appearance_settings(settings)
return unless settings

SiteSettings.site_name = settings[:site_name]
SiteSettings.site_tagline = settings[:site_tagline]
SiteSettings.theme = settings[:theme]
Expand All @@ -50,11 +53,13 @@ def update_appearance_settings(settings)

def update_library_settings(settings)
return unless settings

SiteSettings.show_libraries = settings[:show] == "1"
end

def update_tagging_settings(settings)
return unless settings

SiteSettings.model_tags_filter_stop_words = settings[:filter_stop_words] == "1"
SiteSettings.model_tags_tag_model_directory_name = settings[:tag_model_directory_name] == "1"
SiteSettings.model_tags_stop_words_locale = settings[:stop_words_locale]
Expand All @@ -64,11 +69,13 @@ def update_tagging_settings(settings)

def update_analysis_settings(settings)
return unless settings

SiteSettings.analyse_manifold = settings[:manifold] == "1"
end

def update_multiuser_settings(settings)
return unless settings

SiteSettings.registration_enabled = (settings[:registration_open])
SiteSettings.approve_signups = (settings[:approve_signups])
SiteSettings.default_signup_role = settings[:default_signup_role]
Expand All @@ -80,11 +87,13 @@ def update_multiuser_settings(settings)

def update_usage_settings(settings)
return unless settings

(settings[:report] == "1") ? UsageReport.enable! : UsageReport.disable!
end

def update_discovery_settings(settings)
return unless settings

SiteSettings.allow_robots = settings[:allow_robots] == "1"
SiteSettings.allow_ai_bots = settings[:allow_ai_bots] == "1"
SiteSettings.default_indexable = settings[:default_indexable] == "1"
Expand All @@ -93,13 +102,15 @@ def update_discovery_settings(settings)

def update_download_settings(settings)
return unless settings

SiteSettings.pregenerate_downloads = (settings[:pregenerate] == "1")
SiteSettings.download_expiry_time_in_hours = (settings[:expiry].to_i)
SiteSettings.generate_image_derivatives = (settings[:image_derivatives] == "1")
end

def update_integrations_settings(settings)
return unless settings

SiteSettings.cults3d_api_username = settings[:cults3d_api_username]
SiteSettings.cults3d_api_key = settings[:cults3d_api_key]
SiteSettings.myminifactory_api_key = settings[:myminifactory_api_key]
Expand Down
4 changes: 4 additions & 0 deletions app/controllers/users/registrations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ def after_update_path_for(resource)

def pagination_json(settings)
return nil unless settings

{
"models" => settings[:models] == "1",
"creators" => settings[:creators] == "1",
Expand All @@ -162,6 +163,7 @@ def pagination_json(settings)

def tag_cloud_json(settings)
return nil unless settings

{
"threshold" => settings[:threshold].to_i,
"heatmap" => settings[:heatmap] == "1",
Expand All @@ -172,13 +174,15 @@ def tag_cloud_json(settings)

def file_list_json(settings)
return nil unless settings

{
"hide_presupported_versions" => settings[:hide_presupported_versions] == "1"
}
end

def renderer_json(settings)
return nil unless settings

{
"grid_width" => settings[:grid_width].to_i,
"grid_depth" => settings[:grid_width].to_i, # Store width in both for now. See #834
Expand Down
1 change: 1 addition & 0 deletions app/controllers/users/sessions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ def destroy

def auto_login_single_user
return if ENV.fetch("FORCE_OIDC", nil) == "enabled"

# Autocreate an admin user if there isn't one
create_admin_user if User.with_role(:administrator).empty?
# If in single user mode, or on first run,
Expand Down
2 changes: 1 addition & 1 deletion app/deserializers/activity_pub/application_deserializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def update!

def parse_link_attributes(object)
links = object.extensions&.dig("attachment") || []
links.select { |it| it["type"] == "Link" }&.map { |it| {url: it["href"]} }
links.select { it["type"] == "Link" }&.map { {url: it["href"]} }
end
end
end
1 change: 1 addition & 0 deletions app/deserializers/activity_pub/collection_deserializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ def create!

def deserialize
raise ArgumentError unless @object.is_a?(Federails::Actor)

{
name: @object.name,
slug: @object.username,
Expand Down
1 change: 1 addition & 0 deletions app/deserializers/activity_pub/creator_deserializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ def create!

def deserialize
raise ArgumentError unless @object.is_a?(Federails::Actor)

{
name: @object.name,
slug: @object.username,
Expand Down
Loading
Loading