Move search setting to new page
This commit is contained in:
parent
37071531d3
commit
ea6499b817
13 changed files with 117 additions and 51 deletions
|
@ -0,0 +1,9 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class Settings::Preferences::ReachingController < Settings::Preferences::BaseController
|
||||
private
|
||||
|
||||
def after_update_redirect_path
|
||||
settings_preferences_reaching_path
|
||||
end
|
||||
end
|
|
@ -61,19 +61,19 @@ class SearchQueryTransformer < Parslet::Transform
|
|||
when 'library'
|
||||
[StatusesIndex]
|
||||
else
|
||||
[PublicStatusesIndex, StatusesIndex]
|
||||
@options[:current_account].user&.setting_use_public_index ? [PublicStatusesIndex, StatusesIndex] : [StatusesIndex]
|
||||
end
|
||||
end
|
||||
|
||||
def default_filter
|
||||
definition_should = [
|
||||
default_should1,
|
||||
default_should2,
|
||||
non_publicly_searchable,
|
||||
public_index,
|
||||
searchability_limited,
|
||||
]
|
||||
definition_should << searchability_public if %i(public).include?(@searchability)
|
||||
definition_should << searchability_private if %i(public unlisted private).include?(@searchability)
|
||||
definition_should << searchable_by_me if %i(public unlisted private direct).include?(@searchability)
|
||||
definition_should << self_posts if %i(public unlisted private direct).exclude?(@searchability)
|
||||
|
||||
{
|
||||
bool: {
|
||||
|
@ -83,7 +83,7 @@ class SearchQueryTransformer < Parslet::Transform
|
|||
}
|
||||
end
|
||||
|
||||
def default_should1
|
||||
def public_index
|
||||
{
|
||||
term: {
|
||||
_index: PublicStatusesIndex.index_name,
|
||||
|
@ -91,24 +91,7 @@ class SearchQueryTransformer < Parslet::Transform
|
|||
}
|
||||
end
|
||||
|
||||
def default_should2
|
||||
{
|
||||
bool: {
|
||||
must: [
|
||||
{
|
||||
term: { _index: StatusesIndex.index_name },
|
||||
},
|
||||
{
|
||||
term: {
|
||||
searchable_by: @options[:current_account].id,
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
}
|
||||
end
|
||||
|
||||
def non_publicly_searchable
|
||||
def searchable_by_me
|
||||
{
|
||||
bool: {
|
||||
must: [
|
||||
|
@ -128,6 +111,21 @@ class SearchQueryTransformer < Parslet::Transform
|
|||
}
|
||||
end
|
||||
|
||||
def self_posts
|
||||
{
|
||||
bool: {
|
||||
must: [
|
||||
{
|
||||
term: { _index: StatusesIndex.index_name },
|
||||
},
|
||||
{
|
||||
term: { account_id: @options[:current_account].id },
|
||||
},
|
||||
],
|
||||
},
|
||||
}
|
||||
end
|
||||
|
||||
def searchability_public
|
||||
{
|
||||
bool: {
|
||||
|
@ -349,6 +347,6 @@ class SearchQueryTransformer < Parslet::Transform
|
|||
end
|
||||
|
||||
rule(query: sequence(:clauses)) do
|
||||
Query.new(clauses, current_account: current_account)
|
||||
Query.new(clauses, current_account: current_account, searchability: searchability)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -204,7 +204,15 @@ module HasUserSettings
|
|||
end
|
||||
|
||||
def setting_default_searchability
|
||||
settings['default_searchability'] || 'private'
|
||||
settings['default_searchability'] || 'direct'
|
||||
end
|
||||
|
||||
def setting_default_searchability_of_search
|
||||
settings['default_searchability_of_search']
|
||||
end
|
||||
|
||||
def setting_use_public_index
|
||||
settings['use_public_index']
|
||||
end
|
||||
|
||||
def setting_disallow_unlisted_public_searchability
|
||||
|
|
|
@ -26,6 +26,8 @@ class UserSettings
|
|||
setting :stay_privacy, default: false
|
||||
setting :default_reblog_privacy, default: nil
|
||||
setting :default_searchability, default: :direct, in: %w(public private direct limited)
|
||||
setting :default_searchability_of_search, default: :public, in: %w(public private direct limited)
|
||||
setting :use_public_index, default: true
|
||||
setting :disallow_unlisted_public_searchability, default: false
|
||||
setting :public_post_to_unlisted, default: false
|
||||
setting :reject_public_unlisted_subscription, default: false
|
||||
|
|
|
@ -11,7 +11,7 @@ class SearchService < BaseService
|
|||
@offset = options[:type].blank? ? 0 : options[:offset].to_i
|
||||
@resolve = options[:resolve] || false
|
||||
@following = options[:following] || false
|
||||
@searchability = options[:searchability] || 'public'
|
||||
@searchability = options[:searchability] || account.user&.setting_default_searchability_of_search.to_s || 'public'
|
||||
|
||||
default_results.tap do |results|
|
||||
next if @query.blank? || @limit.zero?
|
||||
|
|
|
@ -14,34 +14,12 @@
|
|||
%h4= t 'preferences.posting_defaults'
|
||||
|
||||
.fields-row
|
||||
.fields-group.fields-row__column.fields-row__column-6
|
||||
= ff.input :default_privacy, collection: Status.selectable_visibilities, wrapper: :with_label, include_blank: false, label_method: ->(visibility) { safe_join([I18n.t("statuses.visibilities.#{visibility}"), I18n.t("statuses.visibilities.#{visibility}_long")], ' - ') }, required: false, hint: false, label: I18n.t('simple_form.labels.defaults.setting_default_privacy')
|
||||
|
||||
.fields-group.fields-row__column.fields-row__column-6
|
||||
= ff.input :default_reblog_privacy, collection: Status.selectable_reblog_visibilities, wrapper: :with_label, kmyblue: true, include_blank: false, label_method: lambda { |visibility| safe_join([I18n.t("statuses.visibilities.#{visibility}"), I18n.t("statuses.visibilities.#{visibility}_long")], ' - ') }, required: false, hint: false, label: I18n.t('simple_form.labels.defaults.setting_default_reblog_privacy')
|
||||
|
||||
.fields-row
|
||||
.fields-group.fields-row__column.fields-row__column-6
|
||||
= ff.input :default_searchability, collection: Status.selectable_searchabilities, wrapper: :with_label, kmyblue: true, include_blank: false, label_method: lambda { |searchability| safe_join([I18n.t("statuses.searchabilities.#{searchability}"), I18n.t("statuses.searchabilities.#{searchability}_long")], ' - ') }, required: false, hint: false, label: I18n.t('simple_form.labels.defaults.setting_default_searchability')
|
||||
|
||||
.fields-group.fields-row__column.fields-row__column-6
|
||||
.fields-group.fields-row__column.fields-row__column-12
|
||||
= ff.input :default_language, collection: [nil] + filterable_languages, wrapper: :with_label, label_method: ->(locale) { locale.nil? ? I18n.t('statuses.default_language') : native_locale_name(locale) }, required: false, include_blank: false, hint: false, label: I18n.t('simple_form.labels.defaults.setting_default_language')
|
||||
|
||||
.fields-group
|
||||
= ff.input :stay_privacy, wrapper: :with_label, kmyblue: true, label: I18n.t('simple_form.labels.defaults.setting_stay_privacy')
|
||||
|
||||
.fields-group
|
||||
= ff.input :public_post_to_unlisted, wrapper: :with_label, kmyblue: true, label: I18n.t('simple_form.labels.defaults.setting_public_post_to_unlisted'), hint: I18n.t('simple_form.hints.defaults.setting_public_post_to_unlisted')
|
||||
|
||||
.fields-group
|
||||
= ff.input :disallow_unlisted_public_searchability, wrapper: :with_label, kmyblue: true, label: I18n.t('simple_form.labels.defaults.setting_disallow_unlisted_public_searchability'), hint: I18n.t('simple_form.hints.defaults.setting_disallow_unlisted_public_searchability')
|
||||
|
||||
.fields-group
|
||||
= ff.input :default_sensitive, wrapper: :with_label, label: I18n.t('simple_form.labels.defaults.setting_default_sensitive'), hint: I18n.t('simple_form.hints.defaults.setting_default_sensitive')
|
||||
|
||||
.fields-group
|
||||
= ff.input :'web.enable_login_privacy', wrapper: :with_label, kmyblue: true, label: I18n.t('simple_form.labels.defaults.setting_enable_login_privacy'), hint: false
|
||||
|
||||
- if @dtl_enabled
|
||||
|
||||
%h4= t 'preferences.dtl'
|
||||
|
|
49
app/views/settings/preferences/reaching/show.html.haml
Normal file
49
app/views/settings/preferences/reaching/show.html.haml
Normal file
|
@ -0,0 +1,49 @@
|
|||
- content_for :page_title do
|
||||
= t('settings.preferences')
|
||||
|
||||
- content_for :heading_actions do
|
||||
= button_tag t('generic.save_changes'), class: 'button', form: 'edit_preferences'
|
||||
|
||||
= simple_form_for current_user, url: settings_preferences_reaching_path, html: { method: :put, id: 'edit_preferences' } do |f|
|
||||
= render 'shared/error_messages', object: current_user
|
||||
|
||||
= f.simple_fields_for :settings, current_user.settings do |ff|
|
||||
|
||||
%h4= t 'preferences.visibility'
|
||||
|
||||
.fields-row
|
||||
.fields-group.fields-row__column.fields-row__column-6
|
||||
= ff.input :default_privacy, collection: Status.selectable_visibilities, wrapper: :with_label, include_blank: false, label_method: ->(visibility) { safe_join([I18n.t("statuses.visibilities.#{visibility}"), I18n.t("statuses.visibilities.#{visibility}_long")], ' - ') }, required: false, hint: false, label: I18n.t('simple_form.labels.defaults.setting_default_privacy')
|
||||
|
||||
.fields-group.fields-row__column.fields-row__column-6
|
||||
= ff.input :default_reblog_privacy, collection: Status.selectable_reblog_visibilities, wrapper: :with_label, kmyblue: true, include_blank: false, label_method: lambda { |visibility| safe_join([I18n.t("statuses.visibilities.#{visibility}"), I18n.t("statuses.visibilities.#{visibility}_long")], ' - ') }, required: false, hint: false, label: I18n.t('simple_form.labels.defaults.setting_default_reblog_privacy')
|
||||
|
||||
.fields-group
|
||||
= ff.input :stay_privacy, wrapper: :with_label, kmyblue: true, label: I18n.t('simple_form.labels.defaults.setting_stay_privacy')
|
||||
|
||||
.fields-group
|
||||
= ff.input :public_post_to_unlisted, wrapper: :with_label, kmyblue: true, label: I18n.t('simple_form.labels.defaults.setting_public_post_to_unlisted'), hint: I18n.t('simple_form.hints.defaults.setting_public_post_to_unlisted')
|
||||
|
||||
.fields-group
|
||||
= ff.input :'web.enable_login_privacy', wrapper: :with_label, kmyblue: true, label: I18n.t('simple_form.labels.defaults.setting_enable_login_privacy'), hint: false
|
||||
|
||||
%h4= t 'preferences.searchability'
|
||||
|
||||
.fields-row
|
||||
.fields-group.fields-row__column.fields-row__column-12
|
||||
= ff.input :default_searchability, collection: Status.selectable_searchabilities, wrapper: :with_label, kmyblue: true, include_blank: false, label_method: lambda { |searchability| safe_join([I18n.t("statuses.searchabilities.#{searchability}"), I18n.t("statuses.searchabilities.#{searchability}_long")], ' - ') }, required: false, hint: false, label: I18n.t('simple_form.labels.defaults.setting_default_searchability')
|
||||
|
||||
.fields-group
|
||||
= ff.input :disallow_unlisted_public_searchability, wrapper: :with_label, kmyblue: true, label: I18n.t('simple_form.labels.defaults.setting_disallow_unlisted_public_searchability'), hint: I18n.t('simple_form.hints.defaults.setting_disallow_unlisted_public_searchability')
|
||||
|
||||
%h4= t 'preferences.search'
|
||||
|
||||
.fields-row
|
||||
.fields-group.fields-row__column.fields-row__column-12
|
||||
= ff.input :default_searchability_of_search, collection: Status.selectable_searchabilities, wrapper: :with_label, kmyblue: true, include_blank: false, label_method: lambda { |searchability| safe_join([I18n.t("statuses.searchabilities.#{searchability}"), I18n.t("statuses.searchabilities.#{searchability}_search_long")], ' - ') }, required: false, hint: false, label: I18n.t('simple_form.labels.defaults.setting_default_searchability_of_search')
|
||||
|
||||
.fields-group
|
||||
= ff.input :use_public_index, wrapper: :with_label, kmyblue: true, label: I18n.t('simple_form.labels.defaults.setting_use_public_index')
|
||||
|
||||
.actions
|
||||
= f.button :button, t('generic.save_changes'), type: :submit
|
Loading…
Add table
Add a link
Reference in a new issue