From f3d232381d60cbc93cb7a35285eb24c30cd0aba0 Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Sun, 8 Dec 2019 15:37:12 +0100 Subject: Add `tootctl media remove-orphans` (#12568) --- app/models/media_attachment.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'app/models') diff --git a/app/models/media_attachment.rb b/app/models/media_attachment.rb index 5d5034a52..573ef5dfc 100644 --- a/app/models/media_attachment.rb +++ b/app/models/media_attachment.rb @@ -167,6 +167,18 @@ class MediaAttachment < ApplicationRecord audio? || video? end + def variant?(other_file_name) + return true if file_file_name == other_file_name + + formats = file.styles.values.map(&:format).compact + + return false if formats.empty? + + extension = File.extname(other_file_name) + + formats.include?(extension.delete('.')) && File.basename(other_file_name, extension) == File.basename(file_file_name, File.extname(file_file_name)) + end + def to_param shortcode end -- cgit From 668f6980774e124a1cc4c80b280172de04ca7973 Mon Sep 17 00:00:00 2001 From: Alice Gaudon Date: Mon, 16 Dec 2019 23:55:50 +0100 Subject: Admin setting to disable default follows (#12566) --- app/javascript/packs/admin.js | 22 ++++++++++++++++++++-- app/models/form/admin_settings.rb | 2 ++ app/services/bootstrap_timeline_service.rb | 2 +- app/views/admin/settings/edit.html.haml | 7 ++++++- config/locales/en.yml | 2 ++ config/settings.yml | 1 + 6 files changed, 32 insertions(+), 4 deletions(-) (limited to 'app/models') diff --git a/app/javascript/packs/admin.js b/app/javascript/packs/admin.js index 42c747d2e..b318cadc6 100644 --- a/app/javascript/packs/admin.js +++ b/app/javascript/packs/admin.js @@ -45,7 +45,25 @@ const onDomainBlockSeverityChange = (target) => { delegate(document, '#domain_block_severity', 'change', ({ target }) => onDomainBlockSeverityChange(target)); +const onEnableBootstrapTimelineAccountsChange = (target) => { + const bootstrapTimelineAccountsField = document.querySelector('#form_admin_settings_bootstrap_timeline_accounts'); + + if (bootstrapTimelineAccountsField) { + bootstrapTimelineAccountsField.disabled = !target.checked; + if (target.checked) { + bootstrapTimelineAccountsField.parentElement.classList.remove('disabled'); + } else { + bootstrapTimelineAccountsField.parentElement.classList.add('disabled'); + } + } +}; + +delegate(document, '#form_admin_settings_enable_bootstrap_timeline_accounts', 'change', ({ target }) => onEnableBootstrapTimelineAccountsChange(target)); + ready(() => { - const input = document.getElementById('domain_block_severity'); - if (input) onDomainBlockSeverityChange(input); + const domainBlockSeverityInput = document.getElementById('domain_block_severity'); + if (domainBlockSeverityInput) onDomainBlockSeverityChange(domainBlockSeverityInput); + + const enableBootstrapTimelineAccounts = document.getElementById('form_admin_settings_enable_bootstrap_timeline_accounts'); + if (enableBootstrapTimelineAccounts) onEnableBootstrapTimelineAccountsChange(enableBootstrapTimelineAccounts); }); diff --git a/app/models/form/admin_settings.rb b/app/models/form/admin_settings.rb index 70e9c21f1..390836f28 100644 --- a/app/models/form/admin_settings.rb +++ b/app/models/form/admin_settings.rb @@ -16,6 +16,7 @@ class Form::AdminSettings open_deletion timeline_preview show_staff_badge + enable_bootstrap_timeline_accounts bootstrap_timeline_accounts theme min_invite_role @@ -40,6 +41,7 @@ class Form::AdminSettings open_deletion timeline_preview show_staff_badge + enable_bootstrap_timeline_accounts activity_api_enabled peers_api_enabled show_known_fediverse_at_about_page diff --git a/app/services/bootstrap_timeline_service.rb b/app/services/bootstrap_timeline_service.rb index c489601c1..8412aa7e7 100644 --- a/app/services/bootstrap_timeline_service.rb +++ b/app/services/bootstrap_timeline_service.rb @@ -5,7 +5,7 @@ class BootstrapTimelineService < BaseService @source_account = source_account autofollow_inviter! - autofollow_bootstrap_timeline_accounts! + autofollow_bootstrap_timeline_accounts! if Setting.enable_bootstrap_timeline_accounts end private diff --git a/app/views/admin/settings/edit.html.haml b/app/views/admin/settings/edit.html.haml index 6282bb39c..d7b493051 100644 --- a/app/views/admin/settings/edit.html.haml +++ b/app/views/admin/settings/edit.html.haml @@ -1,3 +1,6 @@ +- content_for :header_tags do + = javascript_pack_tag 'admin', integrity: true, async: true, crossorigin: 'anonymous' + - content_for :page_title do = t('admin.settings.title') @@ -38,7 +41,9 @@ %hr.spacer/ .fields-group - = f.input :bootstrap_timeline_accounts, wrapper: :with_block_label, label: t('admin.settings.bootstrap_timeline_accounts.title'), hint: t('admin.settings.bootstrap_timeline_accounts.desc_html') + = f.input :enable_bootstrap_timeline_accounts, as: :boolean, wrapper: :with_label, label: t('admin.settings.enable_bootstrap_timeline_accounts.title') + .fields-group + = f.input :bootstrap_timeline_accounts, wrapper: :with_block_label, label: t('admin.settings.bootstrap_timeline_accounts.title'), hint: t('admin.settings.bootstrap_timeline_accounts.desc_html'), disabled: !Setting.enable_bootstrap_timeline_accounts %hr.spacer/ diff --git a/config/locales/en.yml b/config/locales/en.yml index ea94928e7..5edd6e0d3 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -456,6 +456,8 @@ en: users: To logged-in local users domain_blocks_rationale: title: Show rationale + enable_bootstrap_timeline_accounts: + title: Enable default follows for new users hero: desc_html: Displayed on the frontpage. At least 600x100px recommended. When not set, falls back to server thumbnail title: Hero image diff --git a/config/settings.yml b/config/settings.yml index f66e3922e..002473643 100644 --- a/config/settings.yml +++ b/config/settings.yml @@ -61,6 +61,7 @@ defaults: &defaults - mod - moderator disallowed_hashtags: # space separated string or list of hashtags without the hash + enable_bootstrap_timeline_accounts: true bootstrap_timeline_accounts: '' activity_api_enabled: true peers_api_enabled: true -- cgit From 3830c0b74168070cdd410d311ba85a3b323bca9f Mon Sep 17 00:00:00 2001 From: scd31 <57571338+scd31@users.noreply.github.com> Date: Tue, 17 Dec 2019 12:30:58 +0000 Subject: Increase max backup size (#12602) * Increased max backup size * partially reverted schema.rb --- app/models/backup.rb | 2 +- db/migrate/20191212003415_increase_backup_size.rb | 9 ++++++++ db/schema.rb | 28 ++--------------------- 3 files changed, 12 insertions(+), 27 deletions(-) create mode 100644 db/migrate/20191212003415_increase_backup_size.rb (limited to 'app/models') diff --git a/app/models/backup.rb b/app/models/backup.rb index c2651313b..8eeb1748a 100644 --- a/app/models/backup.rb +++ b/app/models/backup.rb @@ -7,7 +7,7 @@ # user_id :bigint(8) # dump_file_name :string # dump_content_type :string -# dump_file_size :integer +# dump_file_size :bigint # dump_updated_at :datetime # processed :boolean default(FALSE), not null # created_at :datetime not null diff --git a/db/migrate/20191212003415_increase_backup_size.rb b/db/migrate/20191212003415_increase_backup_size.rb new file mode 100644 index 000000000..782c67db1 --- /dev/null +++ b/db/migrate/20191212003415_increase_backup_size.rb @@ -0,0 +1,9 @@ +class IncreaseBackupSize < ActiveRecord::Migration[5.2] + def up + change_column :backups, :dump_file_size, :bigint + end + + def down + change_column :backups, :dump_file_size, :integer + end +end diff --git a/db/schema.rb b/db/schema.rb index 84c76e4ce..5a6b2530c 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2019_10_31_163205) do +ActiveRecord::Schema.define(version: 2019_12_12_003415) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -200,7 +200,7 @@ ActiveRecord::Schema.define(version: 2019_10_31_163205) do t.bigint "user_id" t.string "dump_file_name" t.string "dump_content_type" - t.integer "dump_file_size" + t.bigint "dump_file_size" t.datetime "dump_updated_at" t.boolean "processed", default: false, null: false t.datetime "created_at", null: false @@ -703,30 +703,6 @@ ActiveRecord::Schema.define(version: 2019_10_31_163205) do t.index ["tag_id", "status_id"], name: "index_statuses_tags_on_tag_id_and_status_id", unique: true end - create_table "stream_entries", force: :cascade do |t| - t.bigint "activity_id" - t.string "activity_type" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - t.boolean "hidden", default: false, null: false - t.bigint "account_id" - t.index ["account_id", "activity_type", "id"], name: "index_stream_entries_on_account_id_and_activity_type_and_id" - t.index ["activity_id", "activity_type"], name: "index_stream_entries_on_activity_id_and_activity_type" - end - - create_table "subscriptions", force: :cascade do |t| - t.string "callback_url", default: "", null: false - t.string "secret" - t.datetime "expires_at" - t.boolean "confirmed", default: false, null: false - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - t.datetime "last_successful_delivery_at" - t.string "domain" - t.bigint "account_id", null: false - t.index ["account_id", "callback_url"], name: "index_subscriptions_on_account_id_and_callback_url", unique: true - end - create_table "tags", force: :cascade do |t| t.string "name", default: "", null: false t.datetime "created_at", null: false -- cgit From da2143b3089ec16fca449b97acbfb65acfe92197 Mon Sep 17 00:00:00 2001 From: ThibG Date: Tue, 17 Dec 2019 13:31:56 +0100 Subject: Fixes featured hashtag setting page erroring out instead of rejecting invalid tags (#12436) * Revert "Fix ignoring whole status because of one invalid hashtag (#11621)" This reverts commit dff46b260b2f7d765d254c84a4b89105c7de5e97. * Fix statuses being rejected because of invalid hashtag names * Add spec for invalid hashtag names in statuses * Add test for featured tags controller --- app/lib/activitypub/activity/create.rb | 2 +- app/models/tag.rb | 2 +- .../settings/featured_tags_controller_spec.rb | 43 ++++++++++++++++++++++ spec/lib/activitypub/activity/create_spec.rb | 22 +++++++++++ 4 files changed, 67 insertions(+), 2 deletions(-) create mode 100644 spec/controllers/settings/featured_tags_controller_spec.rb (limited to 'app/models') diff --git a/app/lib/activitypub/activity/create.rb b/app/lib/activitypub/activity/create.rb index 8a12a2b08..756d5cb1c 100644 --- a/app/lib/activitypub/activity/create.rb +++ b/app/lib/activitypub/activity/create.rb @@ -157,7 +157,7 @@ class ActivityPub::Activity::Create < ActivityPub::Activity return if tag['name'].blank? Tag.find_or_create_by_names(tag['name']) do |hashtag| - @tags << hashtag unless @tags.include?(hashtag) + @tags << hashtag unless @tags.include?(hashtag) || !hashtag.valid? end rescue ActiveRecord::RecordInvalid nil diff --git a/app/models/tag.rb b/app/models/tag.rb index d3a7e1e6d..bce76fc16 100644 --- a/app/models/tag.rb +++ b/app/models/tag.rb @@ -117,7 +117,7 @@ class Tag < ApplicationRecord class << self def find_or_create_by_names(name_or_names) Array(name_or_names).map(&method(:normalize)).uniq { |str| str.mb_chars.downcase.to_s }.map do |normalized_name| - tag = matching_name(normalized_name).first || create!(name: normalized_name) + tag = matching_name(normalized_name).first || create(name: normalized_name) yield tag if block_given? diff --git a/spec/controllers/settings/featured_tags_controller_spec.rb b/spec/controllers/settings/featured_tags_controller_spec.rb new file mode 100644 index 000000000..33b87f9f6 --- /dev/null +++ b/spec/controllers/settings/featured_tags_controller_spec.rb @@ -0,0 +1,43 @@ +require 'rails_helper' + +describe Settings::FeaturedTagsController do + render_views + + shared_examples 'authenticate user' do + it 'redirects to sign_in page' do + is_expected.to redirect_to new_user_session_path + end + end + + describe 'POST #create' do + context 'when user is not sign in' do + subject { post :create } + + it_behaves_like 'authenticate user' + end + + context 'when user is sign in' do + subject { post :create, params: { featured_tag: params } } + + let(:user) { Fabricate(:user, password: '12345678') } + + before { sign_in user, scope: :user } + + context 'when parameter is valid' do + let(:params) { { name: 'test' } } + + it 'creates featured tag' do + expect { subject }.to change { user.account.featured_tags.count }.by(1) + end + end + + context 'when parameter is invalid' do + let(:params) { { name: 'test, #foo !bleh' } } + + it 'renders new' do + expect(subject).to render_template :index + end + end + end + end +end diff --git a/spec/lib/activitypub/activity/create_spec.rb b/spec/lib/activitypub/activity/create_spec.rb index b709954a3..c4efb5cc9 100644 --- a/spec/lib/activitypub/activity/create_spec.rb +++ b/spec/lib/activitypub/activity/create_spec.rb @@ -378,6 +378,28 @@ RSpec.describe ActivityPub::Activity::Create do end end + context 'with hashtags invalid name' do + let(:object_json) do + { + id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join, + type: 'Note', + content: 'Lorem ipsum', + tag: [ + { + type: 'Hashtag', + href: 'http://example.com/blah', + name: 'foo, #eh !', + }, + ], + } + end + + it 'creates status' do + status = sender.statuses.first + expect(status).to_not be_nil + end + end + context 'with emojis' do let(:object_json) do { -- cgit From c0ed53b810351b61db543701c4938d41723a6e4e Mon Sep 17 00:00:00 2001 From: ThibG Date: Wed, 18 Dec 2019 16:56:59 +0100 Subject: Fix custom emoji category creation silently erroring out on duplicate category (#12647) Instead, just re-use the existing category if any. Fixes #12608 --- app/models/form/custom_emoji_batch.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app/models') diff --git a/app/models/form/custom_emoji_batch.rb b/app/models/form/custom_emoji_batch.rb index 076e8c9e3..6b7ea5355 100644 --- a/app/models/form/custom_emoji_batch.rb +++ b/app/models/form/custom_emoji_batch.rb @@ -40,7 +40,7 @@ class Form::CustomEmojiBatch if category_id.present? CustomEmojiCategory.find(category_id) elsif category_name.present? - CustomEmojiCategory.create!(name: category_name) + CustomEmojiCategory.find_or_create_by!(name: category_name) end end -- cgit