From c36b9cc5a6cf3feacb925213f5530c90dd31fa7a Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Sat, 9 Dec 2017 00:56:16 +0100 Subject: Ensure link thumbnails are not stretched to super low quality (#5932) --- app/models/preview_card.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app/models') diff --git a/app/models/preview_card.rb b/app/models/preview_card.rb index 5baddba8a..716b82243 100644 --- a/app/models/preview_card.rb +++ b/app/models/preview_card.rb @@ -33,7 +33,7 @@ class PreviewCard < ApplicationRecord has_and_belongs_to_many :statuses - has_attached_file :image, styles: { original: '280x280>' }, convert_options: { all: '-quality 80 -strip' } + has_attached_file :image, styles: { original: '400x400>' }, convert_options: { all: '-quality 80 -strip' } include Attachmentable include Remotable -- cgit From 2f4c5f504fa5edc2a826afa9645371f529ae904d Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Sat, 9 Dec 2017 01:32:29 +0100 Subject: Limit users to 50 lists, remove pagination from lists API (#5933) --- app/controllers/api/v1/lists_controller.rb | 38 +----------------------------- app/models/list.rb | 6 +++++ app/validators/status_pin_validator.rb | 8 +++---- config/locales/en.yml | 5 +++- 4 files changed, 15 insertions(+), 42 deletions(-) (limited to 'app/models') diff --git a/app/controllers/api/v1/lists_controller.rb b/app/controllers/api/v1/lists_controller.rb index 9437373bd..180a91d81 100644 --- a/app/controllers/api/v1/lists_controller.rb +++ b/app/controllers/api/v1/lists_controller.rb @@ -1,18 +1,14 @@ # frozen_string_literal: true class Api::V1::ListsController < Api::BaseController - LISTS_LIMIT = 50 - before_action -> { doorkeeper_authorize! :read }, only: [:index, :show] before_action -> { doorkeeper_authorize! :write }, except: [:index, :show] before_action :require_user! before_action :set_list, except: [:index, :create] - after_action :insert_pagination_headers, only: :index - def index - @lists = List.where(account: current_account).paginate_by_max_id(limit_param(LISTS_LIMIT), params[:max_id], params[:since_id]) + @lists = List.where(account: current_account).all render json: @lists, each_serializer: REST::ListSerializer end @@ -44,36 +40,4 @@ class Api::V1::ListsController < Api::BaseController def list_params params.permit(:title) end - - def insert_pagination_headers - set_pagination_headers(next_path, prev_path) - end - - def next_path - if records_continue? - api_v1_lists_url pagination_params(max_id: pagination_max_id) - end - end - - def prev_path - unless @lists.empty? - api_v1_lists_url pagination_params(since_id: pagination_since_id) - end - end - - def pagination_max_id - @lists.last.id - end - - def pagination_since_id - @lists.first.id - end - - def records_continue? - @lists.size == limit_param(LISTS_LIMIT) - end - - def pagination_params(core_params) - params.permit(:limit).merge(core_params) - end end diff --git a/app/models/list.rb b/app/models/list.rb index 910864b26..f45e4973d 100644 --- a/app/models/list.rb +++ b/app/models/list.rb @@ -13,6 +13,8 @@ class List < ApplicationRecord include Paginable + PER_ACCOUNT_LIMIT = 50 + belongs_to :account has_many :list_accounts, inverse_of: :list, dependent: :destroy @@ -20,6 +22,10 @@ class List < ApplicationRecord validates :title, presence: true + validates_each :account_id, on: :create do |record, _attr, value| + record.errors.add(:base, I18n.t('lists.errors.limit')) if List.where(account_id: value).count >= PER_ACCOUNT_LIMIT + end + before_destroy :clean_feed_manager private diff --git a/app/validators/status_pin_validator.rb b/app/validators/status_pin_validator.rb index 9760e1138..64da04120 100644 --- a/app/validators/status_pin_validator.rb +++ b/app/validators/status_pin_validator.rb @@ -2,9 +2,9 @@ class StatusPinValidator < ActiveModel::Validator def validate(pin) - pin.errors.add(:status, I18n.t('statuses.pin_errors.reblog')) if pin.status.reblog? - pin.errors.add(:status, I18n.t('statuses.pin_errors.ownership')) if pin.account_id != pin.status.account_id - pin.errors.add(:status, I18n.t('statuses.pin_errors.private')) unless %w(public unlisted).include?(pin.status.visibility) - pin.errors.add(:status, I18n.t('statuses.pin_errors.limit')) if pin.account.status_pins.count > 4 + pin.errors.add(:base, I18n.t('statuses.pin_errors.reblog')) if pin.status.reblog? + pin.errors.add(:base, I18n.t('statuses.pin_errors.ownership')) if pin.account_id != pin.status.account_id + pin.errors.add(:base, I18n.t('statuses.pin_errors.private')) unless %w(public unlisted).include?(pin.status.visibility) + pin.errors.add(:base, I18n.t('statuses.pin_errors.limit')) if pin.account.status_pins.count > 4 end end diff --git a/config/locales/en.yml b/config/locales/en.yml index 5b9d43b9f..14a88d6c8 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -458,6 +458,9 @@ en: title: Invite people landing_strip_html: "%{name} is a user on %{link_to_root_path}. You can follow them or interact with them if you have an account anywhere in the fediverse." landing_strip_signup_html: If you don't, you can sign up here. + lists: + errors: + limit: You have reached the maximum amount of lists media_attachments: validations: images_and_video: Cannot attach a video to a status that already contains images @@ -591,7 +594,7 @@ en: open_in_web: Open in web over_character_limit: character limit of %{max} exceeded pin_errors: - limit: Too many toots pinned + limit: You have already pinned the maximum number of toots ownership: Someone else's toot cannot be pinned private: Non-public toot cannot be pinned reblog: A boost cannot be pinned -- cgit From 6a82939adb823c9a65829c23dc7109a96480befe Mon Sep 17 00:00:00 2001 From: Andrea Scarpino Date: Sun, 10 Dec 2017 19:35:46 +0100 Subject: Fix account and tag searches with leading/trailing spaces (#5965) * Strip leading & trailing spaces from account query * Strip leading & trailing spaces from tag search --- app/models/tag.rb | 2 +- app/services/account_search_service.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'app/models') diff --git a/app/models/tag.rb b/app/models/tag.rb index 0fa08e157..dc2c8d129 100644 --- a/app/models/tag.rb +++ b/app/models/tag.rb @@ -23,7 +23,7 @@ class Tag < ApplicationRecord class << self def search_for(term, limit = 5) - pattern = sanitize_sql_like(term) + '%' + pattern = sanitize_sql_like(term.strip) + '%' Tag.where('lower(name) like lower(?)', pattern).order(:name).limit(limit) end end diff --git a/app/services/account_search_service.rb b/app/services/account_search_service.rb index a289ceac4..3be110665 100644 --- a/app/services/account_search_service.rb +++ b/app/services/account_search_service.rb @@ -4,7 +4,7 @@ class AccountSearchService < BaseService attr_reader :query, :limit, :options, :account def call(query, limit, account = nil, options = {}) - @query = query + @query = query.strip @limit = limit @options = options @account = account -- cgit From 481fac7c8401a47af52043cd4db05b6dd984d8a9 Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Tue, 12 Dec 2017 02:14:33 +0100 Subject: Exclude moved accounts from search results (#5984) --- app/models/account.rb | 3 +++ 1 file changed, 3 insertions(+) (limited to 'app/models') diff --git a/app/models/account.rb b/app/models/account.rb index e8a8c6560..686e74044 100644 --- a/app/models/account.rb +++ b/app/models/account.rb @@ -285,6 +285,7 @@ class Account < ApplicationRecord FROM accounts WHERE #{query} @@ #{textsearch} AND accounts.suspended = false + AND accounts.moved_to_account_id IS NULL ORDER BY rank DESC LIMIT ? SQL @@ -310,6 +311,7 @@ class Account < ApplicationRecord WHERE accounts.id IN (SELECT * FROM first_degree) AND #{query} @@ #{textsearch} AND accounts.suspended = false + AND accounts.moved_to_account_id IS NULL GROUP BY accounts.id ORDER BY rank DESC LIMIT ? @@ -325,6 +327,7 @@ class Account < ApplicationRecord LEFT OUTER JOIN follows AS f ON (accounts.id = f.account_id AND f.target_account_id = ?) OR (accounts.id = f.target_account_id AND f.account_id = ?) WHERE #{query} @@ #{textsearch} AND accounts.suspended = false + AND accounts.moved_to_account_id IS NULL GROUP BY accounts.id ORDER BY rank DESC LIMIT ? -- cgit From 14c4a33cd9bfc1212cb362897272e5ea7d1529e5 Mon Sep 17 00:00:00 2001 From: Akihiko Odaki Date: Tue, 12 Dec 2017 12:11:17 +0900 Subject: Change account_id non-nullable in lists (#5979) --- app/models/list.rb | 2 +- .../20171201000000_change_account_id_nonnullable_in_lists.rb | 7 +++++++ db/schema.rb | 4 ++-- 3 files changed, 10 insertions(+), 3 deletions(-) create mode 100644 db/migrate/20171201000000_change_account_id_nonnullable_in_lists.rb (limited to 'app/models') diff --git a/app/models/list.rb b/app/models/list.rb index f45e4973d..be85c3b87 100644 --- a/app/models/list.rb +++ b/app/models/list.rb @@ -4,7 +4,7 @@ # Table name: lists # # id :integer not null, primary key -# account_id :integer +# account_id :integer not null # title :string default(""), not null # created_at :datetime not null # updated_at :datetime not null diff --git a/db/migrate/20171201000000_change_account_id_nonnullable_in_lists.rb b/db/migrate/20171201000000_change_account_id_nonnullable_in_lists.rb new file mode 100644 index 000000000..120f74402 --- /dev/null +++ b/db/migrate/20171201000000_change_account_id_nonnullable_in_lists.rb @@ -0,0 +1,7 @@ +require Rails.root.join('lib', 'mastodon', 'migration_helpers') + +class ChangeAccountIdNonnullableInLists < ActiveRecord::Migration[5.1] + def change + change_column_null :lists, :account_id, false + end +end diff --git a/db/schema.rb b/db/schema.rb index cf0deb826..7887f26a2 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: 20171130000000) do +ActiveRecord::Schema.define(version: 20171201000000) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -209,7 +209,7 @@ ActiveRecord::Schema.define(version: 20171130000000) do end create_table "lists", force: :cascade do |t| - t.bigint "account_id" + t.bigint "account_id", null: false t.string "title", default: "", null: false t.datetime "created_at", null: false t.datetime "updated_at", null: false -- cgit