Skip to content
Permalink
Browse files

Merge branch 'master' into glitch-soc/merge-upstream

Conflicts:
- app/controllers/directories_controller.rb
- package.json
- yarn.lock
  • Loading branch information
ThibG committed Jul 30, 2019
2 parents f48c768 + b31b232 commit 24968d20a07d483cd36b4747bd1db8bd512002c2
Showing with 779 additions and 221 deletions.
  1. +4 −4 Gemfile
  2. +14 −13 Gemfile.lock
  3. +5 −0 app/controllers/about_controller.rb
  4. +2 −0 app/controllers/activitypub/base_controller.rb
  5. +1 −1 app/controllers/activitypub/inboxes_controller.rb
  6. +40 −0 app/controllers/admin/domain_allows_controller.rb
  7. +25 −3 app/controllers/admin/instances_controller.rb
  8. +9 −0 app/controllers/api/base_controller.rb
  9. +2 −0 app/controllers/api/v1/accounts_controller.rb
  10. +2 −0 app/controllers/api/v1/apps_controller.rb
  11. +2 −1 app/controllers/api/v1/instances/activity_controller.rb
  12. +2 −1 app/controllers/api/v1/instances/peers_controller.rb
  13. +1 −0 app/controllers/api/v1/instances_controller.rb
  14. +3 −1 app/controllers/application_controller.rb
  15. +1 −0 app/controllers/concerns/account_owned_concern.rb
  16. +3 −2 app/controllers/directories_controller.rb
  17. +1 −1 app/controllers/home_controller.rb
  18. +1 −0 app/controllers/media_controller.rb
  19. +2 −0 app/controllers/media_proxy_controller.rb
  20. +3 −2 app/controllers/public_timelines_controller.rb
  21. +1 −0 app/controllers/remote_interaction_controller.rb
  22. +1 −0 app/controllers/tags_controller.rb
  23. +9 −1 app/helpers/domain_control_helper.rb
  24. +4 −4 app/javascript/mastodon/actions/compose.js
  25. +5 −5 app/javascript/mastodon/components/autosuggest_input.js
  26. +5 −5 app/javascript/mastodon/components/autosuggest_textarea.js
  27. +90 −0 app/javascript/mastodon/components/status_content.js
  28. +1 −10 app/javascript/mastodon/features/status/components/card.js
  29. +3 −3 app/javascript/mastodon/reducers/compose.js
  30. +2 −1 app/javascript/mastodon/reducers/search.js
  31. +10 −0 app/javascript/mastodon/utils/idna.js
  32. +33 −0 app/models/domain_allow.rb
  33. +2 −1 app/models/instance.rb
  34. +4 −0 app/models/instance_filter.rb
  35. +4 −4 app/models/tag.rb
  36. +11 −0 app/policies/domain_allow_policy.rb
  37. +1 −1 app/services/concerns/payloadable.rb
  38. +11 −0 app/services/unallow_domain_service.rb
  39. +14 −0 app/views/admin/domain_allows/new.html.haml
  40. +22 −13 app/views/admin/instances/index.html.haml
  41. +3 −1 app/views/admin/instances/show.html.haml
  42. +15 −13 app/views/admin/settings/edit.html.haml
  43. +1 −1 app/views/auth/registrations/new.html.haml
  44. +6 −3 app/views/layouts/public.html.haml
  45. +5 −0 config/initializers/2_whitelist_mode.rb
  46. +7 −0 config/locales/en.yml
  47. +2 −0 config/locales/simple_form.en.yml
  48. +1 −1 config/navigation.rb
  49. +1 −0 config/routes.rb
  50. +9 −0 db/migrate/20190705002136_create_domain_allows.rb
  51. +13 −0 db/migrate/20190726175042_add_case_insensitive_index_to_tags.rb
  52. +8 −1 db/schema.rb
  53. +19 −3 lib/mastodon/domains_cli.rb
  54. +5 −5 package.json
  55. +3 −0 spec/fabricators/domain_allow_fabricator.rb
  56. +5 −0 spec/models/domain_allow_spec.rb
  57. +34 −0 spec/models/tag_spec.rb
  58. +3 −2 streaming/index.js
  59. +283 −114 yarn.lock
@@ -15,7 +15,7 @@ gem 'makara', '~> 0.4'
gem 'pghero', '~> 2.2'
gem 'dotenv-rails', '~> 2.7'

gem 'aws-sdk-s3', '~> 1.45', require: false
gem 'aws-sdk-s3', '~> 1.46', require: false
gem 'fog-core', '<= 2.1.0'
gem 'fog-openstack', '~> 0.3', require: false
gem 'paperclip', '~> 6.0'
@@ -53,7 +53,7 @@ gem 'html2text'
gem 'htmlentities', '~> 4.3'
gem 'http', '~> 3.3'
gem 'http_accept_language', '~> 2.1'
gem 'http_parser.rb', '~> 0.6', git: 'https://github.com/tmm1/http_parser.rb', ref: '54b17ba8c7d8d20a16dfc65d1775241833219cf2'
gem 'http_parser.rb', '~> 0.6', git: 'https://github.com/tmm1/http_parser.rb', ref: '54b17ba8c7d8d20a16dfc65d1775241833219cf2', submodules: true
gem 'httplog', '~> 1.3'
gem 'idn-ruby', require: 'idn'
gem 'kaminari', '~> 1.1'
@@ -113,7 +113,7 @@ group :production, :test do
end

group :test do
gem 'capybara', '~> 3.26'
gem 'capybara', '~> 3.27'
gem 'climate_control', '~> 0.2'
gem 'faker', '~> 1.9'
gem 'microformats', '~> 4.1'
@@ -135,7 +135,7 @@ group :development do
gem 'memory_profiler'
gem 'rubocop', '~> 0.73', require: false
gem 'rubocop-rails', '~> 2.2', require: false
gem 'brakeman', '~> 4.5', require: false
gem 'brakeman', '~> 4.6', require: false
gem 'bundler-audit', '~> 0.6', require: false

gem 'capistrano', '~> 3.11'
@@ -22,6 +22,7 @@ GIT
remote: https://github.com/tmm1/http_parser.rb
revision: 54b17ba8c7d8d20a16dfc65d1775241833219cf2
ref: 54b17ba8c7d8d20a16dfc65d1775241833219cf2
submodules: true
specs:
http_parser.rb (0.6.1)

@@ -96,17 +97,17 @@ GEM
av (0.9.0)
cocaine (~> 0.5.3)
aws-eventstream (1.0.3)
aws-partitions (1.184.0)
aws-sdk-core (3.59.0)
aws-partitions (1.193.0)
aws-sdk-core (3.61.1)
aws-eventstream (~> 1.0, >= 1.0.2)
aws-partitions (~> 1.0)
aws-sigv4 (~> 1.1)
jmespath (~> 1.0)
aws-sdk-kms (1.23.0)
aws-sdk-core (~> 3, >= 3.58.0)
aws-sdk-kms (1.24.0)
aws-sdk-core (~> 3, >= 3.61.1)
aws-sigv4 (~> 1.1)
aws-sdk-s3 (1.45.0)
aws-sdk-core (~> 3, >= 3.58.0)
aws-sdk-s3 (1.46.0)
aws-sdk-core (~> 3, >= 3.61.1)
aws-sdk-kms (~> 1)
aws-sigv4 (~> 1.1)
aws-sigv4 (1.1.0)
@@ -123,7 +124,7 @@ GEM
ffi (~> 1.10.0)
bootsnap (1.4.4)
msgpack (~> 1.0)
brakeman (4.5.1)
brakeman (4.6.1)
browser (2.6.1)
builder (3.2.3)
bullet (6.0.1)
@@ -149,7 +150,7 @@ GEM
sshkit (~> 1.3)
capistrano-yarn (2.0.2)
capistrano (~> 3.0)
capybara (3.26.0)
capybara (3.27.0)
addressable
mini_mime (>= 0.1.3)
nokogiri (~> 1.8)
@@ -291,7 +292,7 @@ GEM
domain_name (~> 0.5)
http-form_data (2.1.1)
http_accept_language (2.1.1)
httplog (1.3.1)
httplog (1.3.2)
rack (>= 1.0)
rainbow (>= 2.0.0)
i18n (1.6.0)
@@ -386,7 +387,7 @@ GEM
concurrent-ruby (~> 1.0, >= 1.0.2)
sidekiq (>= 3.5)
statsd-ruby (~> 1.4, >= 1.4.0)
oj (3.8.0)
oj (3.8.1)
omniauth (1.9.0)
hashie (>= 3.4.6, < 3.7.0)
rack (>= 1.6.2, < 3)
@@ -670,20 +671,20 @@ DEPENDENCIES
active_record_query_trace (~> 1.6)
addressable (~> 2.6)
annotate (~> 2.7)
aws-sdk-s3 (~> 1.45)
aws-sdk-s3 (~> 1.46)
better_errors (~> 2.5)
binding_of_caller (~> 0.7)
blurhash (~> 0.1)
bootsnap (~> 1.4)
brakeman (~> 4.5)
brakeman (~> 4.6)
browser
bullet (~> 6.0)
bundler-audit (~> 0.6)
capistrano (~> 3.11)
capistrano-rails (~> 1.4)
capistrano-rbenv (~> 2.1)
capistrano-yarn (~> 2.0)
capybara (~> 3.26)
capybara (~> 3.27)
charlock_holmes (~> 0.7.6)
chewy (~> 5.0)
cld3 (~> 3.2.4)
@@ -4,6 +4,7 @@ class AboutController < ApplicationController
before_action :set_pack
layout 'public'

before_action :require_open_federation!, only: [:show, :more]
before_action :set_body_classes, only: :show
before_action :set_instance_presenter
before_action :set_expires_in
@@ -20,6 +21,10 @@ def terms; end

private

def require_open_federation!
not_found if whitelist_mode?
end

def new_user
User.new.tap do |user|
user.build_account
@@ -1,6 +1,8 @@
# frozen_string_literal: true

class ActivityPub::BaseController < Api::BaseController
skip_before_action :require_authenticated_user!

private

def set_cache_headers
@@ -1,6 +1,6 @@
# frozen_string_literal: true

class ActivityPub::InboxesController < Api::BaseController
class ActivityPub::InboxesController < ActivityPub::BaseController
include SignatureVerification
include JsonLdHelper
include AccountOwnedConcern
@@ -0,0 +1,40 @@
# frozen_string_literal: true

class Admin::DomainAllowsController < Admin::BaseController
before_action :set_domain_allow, only: [:destroy]

def new
authorize :domain_allow, :create?

@domain_allow = DomainAllow.new(domain: params[:_domain])
end

def create
authorize :domain_allow, :create?

@domain_allow = DomainAllow.new(resource_params)

if @domain_allow.save
log_action :create, @domain_allow
redirect_to admin_instances_path, notice: I18n.t('admin.domain_allows.created_msg')
else
render :new
end
end

def destroy
authorize @domain_allow, :destroy?
UnallowDomainService.new.call(@domain_allow)
redirect_to admin_instances_path, notice: I18n.t('admin.domain_allows.destroyed_msg')
end

private

def set_domain_allow
@domain_allow = DomainAllow.find(params[:id])
end

def resource_params
params.require(:domain_allow).permit(:domain)
end
end
@@ -2,6 +2,10 @@

module Admin
class InstancesController < BaseController
before_action :set_domain_block, only: :show
before_action :set_domain_allow, only: :show
before_action :set_instance, only: :show

def index
authorize :instance, :index?

@@ -11,20 +15,38 @@ def index
def show
authorize :instance, :show?

@instance = Instance.new(Account.by_domain_accounts.find_by(domain: params[:id]) || DomainBlock.find_by!(domain: params[:id]))
@following_count = Follow.where(account: Account.where(domain: params[:id])).count
@followers_count = Follow.where(target_account: Account.where(domain: params[:id])).count
@reports_count = Report.where(target_account: Account.where(domain: params[:id])).count
@blocks_count = Block.where(target_account: Account.where(domain: params[:id])).count
@available = DeliveryFailureTracker.available?(Account.select(:shared_inbox_url).where(domain: params[:id]).first&.shared_inbox_url)
@media_storage = MediaAttachment.where(account: Account.where(domain: params[:id])).sum(:file_file_size)
@domain_block = DomainBlock.rule_for(params[:id])
end

private

def set_domain_block
@domain_block = DomainBlock.rule_for(params[:id])
end

def set_domain_allow
@domain_allow = DomainAllow.rule_for(params[:id])
end

def set_instance
resource = Account.by_domain_accounts.find_by(domain: params[:id])
resource ||= @domain_block
resource ||= @domain_allow

if resource
@instance = Instance.new(resource)
else
not_found
end
end

def filtered_instances
InstanceFilter.new(filter_params).results
InstanceFilter.new(whitelist_mode? ? { allowed: true } : filter_params).results
end

def paginated_instances
@@ -9,6 +9,7 @@ class Api::BaseController < ApplicationController
skip_before_action :store_current_location
skip_before_action :require_functional!

before_action :require_authenticated_user!, if: :disallow_unauthenticated_api_access?
before_action :set_cache_headers

protect_from_forgery with: :null_session
@@ -69,6 +70,10 @@ def current_user
nil
end

def require_authenticated_user!
render json: { error: 'This API requires an authenticated user' }, status: 401 unless current_user
end

def require_user!
if !current_user
render json: { error: 'This method requires an authenticated user' }, status: 422
@@ -94,4 +99,8 @@ def authorize_if_got_token!(*scopes)
def set_cache_headers
response.headers['Cache-Control'] = 'no-cache, no-store, max-age=0, must-revalidate'
end

def disallow_unauthenticated_api_access?
authorized_fetch_mode?
end
end
@@ -12,6 +12,8 @@ class Api::V1::AccountsController < Api::BaseController
before_action :check_account_suspension, only: [:show]
before_action :check_enabled_registrations, only: [:create]

skip_before_action :require_authenticated_user!, only: :create

respond_to :json

def show
@@ -1,6 +1,8 @@
# frozen_string_literal: true

class Api::V1::AppsController < Api::BaseController
skip_before_action :require_authenticated_user!

def create
@app = Doorkeeper::Application.create!(application_options)
render json: @app, serializer: REST::ApplicationSerializer
@@ -2,6 +2,7 @@

class Api::V1::Instances::ActivityController < Api::BaseController
before_action :require_enabled_api!

skip_before_action :set_cache_headers

respond_to :json
@@ -33,6 +34,6 @@ def activity
end

def require_enabled_api!
head 404 unless Setting.activity_api_enabled
head 404 unless Setting.activity_api_enabled && !whitelist_mode?
end
end
@@ -2,6 +2,7 @@

class Api::V1::Instances::PeersController < Api::BaseController
before_action :require_enabled_api!

skip_before_action :set_cache_headers

respond_to :json
@@ -14,6 +15,6 @@ def index
private

def require_enabled_api!
head 404 unless Setting.peers_api_enabled
head 404 unless Setting.peers_api_enabled && !whitelist_mode?
end
end
@@ -2,6 +2,7 @@

class Api::V1::InstancesController < Api::BaseController
respond_to :json

skip_before_action :set_cache_headers

def show
@@ -11,13 +11,15 @@ class ApplicationController < ActionController::Base
include UserTrackingConcern
include SessionTrackingConcern
include CacheConcern
include DomainControlHelper

helper_method :current_account
helper_method :current_session
helper_method :current_flavour
helper_method :current_skin
helper_method :single_user_mode?
helper_method :use_seamless_external_login?
helper_method :whitelist_mode?

rescue_from ActionController::RoutingError, with: :not_found
rescue_from ActiveRecord::RecordNotFound, with: :not_found
@@ -39,7 +41,7 @@ def https_enabled?
end

def authorized_fetch_mode?
ENV['AUTHORIZED_FETCH'] == 'true'
ENV['AUTHORIZED_FETCH'] == 'true' || Rails.configuration.x.whitelist_mode
end

def public_fetch_mode?
@@ -4,6 +4,7 @@ module AccountOwnedConcern
extend ActiveSupport::Concern

included do
before_action :authenticate_user!, if: -> { whitelist_mode? && request.format != :json }
before_action :set_account, if: :account_required?
before_action :check_account_approval, if: :account_required?
before_action :check_account_suspension, if: :account_required?
@@ -3,7 +3,8 @@
class DirectoriesController < ApplicationController
layout 'public'

before_action :check_enabled
before_action :authenticate_user!, if: :whitelist_mode?
before_action :require_enabled!
before_action :set_instance_presenter
before_action :set_tag, only: :show
before_action :set_tags
@@ -24,7 +25,7 @@ def set_pack
use_pack 'share'
end

def check_enabled
def require_enabled!
return not_found unless Setting.profile_directory
end

0 comments on commit 24968d2

Please sign in to comment.
You can’t perform that action at this time.