Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds ignored files as a configurable feature #3434

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
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
6 changes: 6 additions & 0 deletions app/controllers/settings_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ class SettingsController < ApplicationController
def update
# Save site-wide settings if user is an admin
update_folder_settings(params[:folders])
update_file_settings(params[:files])
update_tagging_settings(params[:model_tags])
update_multiuser_settings(params[:multiuser])
update_analysis_settings(params[:analysis])
Expand All @@ -20,6 +21,11 @@ def update_folder_settings(settings)
SiteSettings.safe_folder_names = settings[:safe_folder_names]
end

def update_file_settings(settings)
return unless settings
SiteSettings.model_ignored_files = settings[:model_ignored_files]
end

def update_tagging_settings(settings)
return unless settings
SiteSettings.model_tags_filter_stop_words = settings[:filter_stop_words] == "1"
Expand Down
11 changes: 6 additions & 5 deletions app/models/site_settings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ class SiteSettings < RailsSettings::Base
field :model_tags_custom_stop_words, type: :array, default: SupportedMimeTypes.indexable_extensions
field :model_tags_auto_tag_new, type: :string, default: "!new"
field :model_path_template, type: :string, default: "{tags}/{modelName}{modelId}"
field :model_ignored_files, type: :array, default: [
/^\.[^\.]+/, # Hidden files starting with .
/.*\/@eaDir\/.*/, # Synology temp files
/__MACOSX/ # MACOS resource forks
]
field :parse_metadata_from_path, type: :boolean, default: true
field :safe_folder_names, type: :boolean, default: true
field :analyse_manifold, type: :boolean, default: false
Expand Down Expand Up @@ -52,11 +57,7 @@ def self.default_user
end

def self.ignored_file?(pathname)
@@patterns ||= [
/^\.[^\.]+/, # Hidden files starting with .
/.*\/@eaDir\/.*/, # Synology temp files
/__MACOSX/ # MACOS resource forks
]
@@patterns ||= model_ignored_files
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this need to be a class variable anymore now that we've got :model_ignored_files?

(File.split(pathname) - ["."]).any? do |path_component|
@@patterns.any? { |pattern| path_component =~ pattern }
end
Expand Down
13 changes: 13 additions & 0 deletions app/views/settings/_file_settings.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<h3><%= t(".title") %></h3>
<p class='lead'>
<%= t ".summary" %>
</p>
<div class="row mb-2">
<p>
<%= t ".custom_ignore_filters.details" %>
</p>
<%= form.label nil, t(".custom_ignore_filters.label"), for: "files[model_ignored_files]", class: "col-sm-4 col-form-label" %>
<div class="col-sm-8 form-check form-switch">
<%= form.text_area "files[model_ignored_files]", value: SiteSettings.model_ignored_files.join("\n").gsub(/^\[|\]$/, ""), class: "form-control" %>
</div>
</div>
2 changes: 2 additions & 0 deletions app/views/settings/show.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<%= form_with url: settings_path, method: :patch do |form| %>
<%= render "folder_settings", form: form %>
<hr>
<%= render "file_settings", form: form %>
<hr>
<%= render "tag_settings", form: form %>

<%= render "submit", form: form %>
Expand Down
6 changes: 6 additions & 0 deletions config/locales/settings/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ en:
new:
submit: Block domain
title: New Domain Block
file_settings:
custom_ignore_filters:
details: Filters are in regex format separated by a new line.
label: Ignored files regex filters.
summary: Change file settings such as ignored files.
title: File settings
folder_settings:
details: Folder structure follows a template that you define using tokens. You can also include other text in the template (such as folder separators) and it will be included as-is.
model_path_template:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class AddIgnoredFilesToSiteSettings < ActiveRecord::Migration[7.2]
def change
add_column :site_settings, :ignored_files, :text, null: true, default: [
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I need help figuring out the best way to do this migration.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think SiteSettings is a flexible k/v store so you don't actually need to add the migration. But I'll check when I take a proper look at this probably tomorrow.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://github.com/huacnlee/rails-settings-cached is the gem that it's using, in case those docs help.

/^\.[^\.]+/, # Hidden files starting with .
/.*\/@eaDir\/.*/, # Synology temp files
/__MACOSX/ # MACOS resource forks
]
end
end
25 changes: 15 additions & 10 deletions db/schema.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading