mirror of
https://github.com/glitch-soc/mastodon.git
synced 2024-11-27 10:30:15 -05:00
Limit users to 50 lists, remove pagination from lists API (#5933)
This commit is contained in:
parent
f08e6e9ab5
commit
2f4c5f504f
@ -1,18 +1,14 @@
|
|||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
class Api::V1::ListsController < Api::BaseController
|
class Api::V1::ListsController < Api::BaseController
|
||||||
LISTS_LIMIT = 50
|
|
||||||
|
|
||||||
before_action -> { doorkeeper_authorize! :read }, only: [:index, :show]
|
before_action -> { doorkeeper_authorize! :read }, only: [:index, :show]
|
||||||
before_action -> { doorkeeper_authorize! :write }, except: [:index, :show]
|
before_action -> { doorkeeper_authorize! :write }, except: [:index, :show]
|
||||||
|
|
||||||
before_action :require_user!
|
before_action :require_user!
|
||||||
before_action :set_list, except: [:index, :create]
|
before_action :set_list, except: [:index, :create]
|
||||||
|
|
||||||
after_action :insert_pagination_headers, only: :index
|
|
||||||
|
|
||||||
def 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
|
render json: @lists, each_serializer: REST::ListSerializer
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -44,36 +40,4 @@ class Api::V1::ListsController < Api::BaseController
|
|||||||
def list_params
|
def list_params
|
||||||
params.permit(:title)
|
params.permit(:title)
|
||||||
end
|
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
|
end
|
||||||
|
@ -13,6 +13,8 @@
|
|||||||
class List < ApplicationRecord
|
class List < ApplicationRecord
|
||||||
include Paginable
|
include Paginable
|
||||||
|
|
||||||
|
PER_ACCOUNT_LIMIT = 50
|
||||||
|
|
||||||
belongs_to :account
|
belongs_to :account
|
||||||
|
|
||||||
has_many :list_accounts, inverse_of: :list, dependent: :destroy
|
has_many :list_accounts, inverse_of: :list, dependent: :destroy
|
||||||
@ -20,6 +22,10 @@ class List < ApplicationRecord
|
|||||||
|
|
||||||
validates :title, presence: true
|
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
|
before_destroy :clean_feed_manager
|
||||||
|
|
||||||
private
|
private
|
||||||
|
@ -2,9 +2,9 @@
|
|||||||
|
|
||||||
class StatusPinValidator < ActiveModel::Validator
|
class StatusPinValidator < ActiveModel::Validator
|
||||||
def validate(pin)
|
def validate(pin)
|
||||||
pin.errors.add(:status, I18n.t('statuses.pin_errors.reblog')) if pin.status.reblog?
|
pin.errors.add(:base, 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(:base, 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(:base, 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.limit')) if pin.account.status_pins.count > 4
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -458,6 +458,9 @@ en:
|
|||||||
title: Invite people
|
title: Invite people
|
||||||
landing_strip_html: "<strong>%{name}</strong> 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_html: "<strong>%{name}</strong> 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 <a href="%{sign_up_path}">sign up here</a>.
|
landing_strip_signup_html: If you don't, you can <a href="%{sign_up_path}">sign up here</a>.
|
||||||
|
lists:
|
||||||
|
errors:
|
||||||
|
limit: You have reached the maximum amount of lists
|
||||||
media_attachments:
|
media_attachments:
|
||||||
validations:
|
validations:
|
||||||
images_and_video: Cannot attach a video to a status that already contains images
|
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
|
open_in_web: Open in web
|
||||||
over_character_limit: character limit of %{max} exceeded
|
over_character_limit: character limit of %{max} exceeded
|
||||||
pin_errors:
|
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
|
ownership: Someone else's toot cannot be pinned
|
||||||
private: Non-public toot cannot be pinned
|
private: Non-public toot cannot be pinned
|
||||||
reblog: A boost cannot be pinned
|
reblog: A boost cannot be pinned
|
||||||
|
Loading…
Reference in New Issue
Block a user