Merge commit '4aea3f88a6d30f102a79c2da7fcfac96465ba1a8' into merging-upstream

This commit is contained in:
Ondřej Hruška
2017-09-28 09:12:17 +02:00
282 changed files with 4626 additions and 1622 deletions

View File

@@ -0,0 +1,34 @@
# frozen_string_literal: true
module Admin
class CustomEmojisController < BaseController
def index
@custom_emojis = CustomEmoji.where(domain: nil)
end
def new
@custom_emoji = CustomEmoji.new
end
def create
@custom_emoji = CustomEmoji.new(resource_params)
if @custom_emoji.save
redirect_to admin_custom_emojis_path, notice: I18n.t('admin.custom_emojis.created_msg')
else
render :new
end
end
def destroy
CustomEmoji.find(params[:id]).destroy
redirect_to admin_custom_emojis_path, notice: I18n.t('admin.custom_emojis.destroyed_msg')
end
private
def resource_params
params.require(:custom_emoji).permit(:shortcode, :image)
end
end
end

View File

@@ -14,8 +14,12 @@ module Admin
private
def filtered_instances
InstanceFilter.new(filter_params).results
end
def paginated_instances
Account.remote.by_domain_accounts.page(params[:page])
filtered_instances.page(params[:page])
end
helper_method :paginated_instances
@@ -27,5 +31,11 @@ module Admin
def subscribeable_accounts
Account.with_followers.remote.where(domain: params[:by_domain])
end
def filter_params
params.permit(
:domain_name
)
end
end
end

View File

@@ -14,6 +14,7 @@ module Admin
open_deletion
timeline_preview
bootstrap_timeline_accounts
thumbnail
).freeze
BOOLEAN_SETTINGS = %w(
@@ -22,14 +23,23 @@ module Admin
timeline_preview
).freeze
UPLOAD_SETTINGS = %w(
thumbnail
).freeze
def edit
@admin_settings = Form::AdminSettings.new
end
def update
settings_params.each do |key, value|
setting = Setting.where(var: key).first_or_initialize(var: key)
setting.update(value: value_for_update(key, value))
if UPLOAD_SETTINGS.include?(key)
upload = SiteUpload.where(var: key).first_or_initialize(var: key)
upload.update(file: value)
else
setting = Setting.where(var: key).first_or_initialize(var: key)
setting.update(value: value_for_update(key, value))
end
end
flash[:notice] = I18n.t('generic.changes_saved_msg')

View File

@@ -12,7 +12,30 @@ class HomeController < ApplicationController
private
def authenticate_user!
redirect_to(single_user_mode? ? account_path(Account.first) : about_path) unless user_signed_in?
return if user_signed_in?
matches = request.path.match(/\A\/web\/(statuses|accounts)\/([\d]+)\z/)
if matches
case matches[1]
when 'statuses'
status = Status.find_by(id: matches[2])
if status && (status.public_visibility? || status.unlisted_visibility?)
redirect_to(ActivityPub::TagManager.instance.url_for(status))
return
end
when 'accounts'
account = Account.find_by(id: matches[2])
if account
redirect_to(ActivityPub::TagManager.instance.url_for(account))
return
end
end
end
redirect_to(default_redirect_path)
end
def set_initial_state_json
@@ -29,4 +52,14 @@ class HomeController < ApplicationController
admin: Account.find_local(Setting.site_contact_username),
}
end
def default_redirect_path
if request.path.start_with?('/web')
new_user_session_path
elsif single_user_mode?
short_account_path(Account.first)
else
about_path
end
end
end

View File

@@ -0,0 +1,40 @@
# frozen_string_literal: true
class MediaProxyController < ApplicationController
include RoutingHelper
def show
RedisLock.acquire(lock_options) do |lock|
if lock.acquired?
@media_attachment = MediaAttachment.remote.find(params[:id])
redownload! if @media_attachment.needs_redownload? && !reject_media?
end
end
redirect_to full_asset_url(@media_attachment.file.url(version))
end
private
def redownload!
@media_attachment.file_remote_url = @media_attachment.remote_url
@media_attachment.created_at = Time.now.utc
@media_attachment.save!
end
def version
if request.path.ends_with?('/small')
:small
else
:original
end
end
def lock_options
{ redis: Redis.current, key: "media_download:#{params[:id]}" }
end
def reject_media?
DomainBlock.find_by(domain: @media_attachment.account.domain)&.reject_media?
end
end