Skip to content

Commit

Permalink
Merge branch 'main' into temp3_for-taruntarun
Browse files Browse the repository at this point in the history
# Conflicts:
#	app/models/form/admin_settings.rb
  • Loading branch information
mayaeh committed May 8, 2024
2 parents 7178bbb + d8c4284 commit f7d8163
Show file tree
Hide file tree
Showing 87 changed files with 2,037 additions and 464 deletions.
21 changes: 0 additions & 21 deletions .github/stylelint-matcher.json

This file was deleted.

6 changes: 1 addition & 5 deletions .github/workflows/lint-css.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,5 @@ jobs:
- name: Set up Javascript environment
uses: ./.github/actions/setup-javascript

- uses: xt0rted/stylelint-problem-matcher@v1

- run: echo "::add-matcher::.github/stylelint-matcher.json"

- name: Stylelint
run: yarn lint:css
run: yarn lint:css -f github
32 changes: 16 additions & 16 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -101,15 +101,15 @@ GEM
awrence (1.2.1)
aws-eventstream (1.3.0)
aws-partitions (1.922.0)
aws-sdk-core (3.194.0)
aws-sdk-core (3.194.1)
aws-eventstream (~> 1, >= 1.3.0)
aws-partitions (~> 1, >= 1.651.0)
aws-sigv4 (~> 1.8)
jmespath (~> 1, >= 1.6.1)
aws-sdk-kms (1.80.0)
aws-sdk-core (~> 3, >= 3.193.0)
aws-sigv4 (~> 1.1)
aws-sdk-s3 (1.149.0)
aws-sdk-s3 (1.149.1)
aws-sdk-core (~> 3, >= 3.194.0)
aws-sdk-kms (~> 1)
aws-sigv4 (~> 1.8)
Expand Down Expand Up @@ -167,9 +167,9 @@ GEM
activesupport
cbor (0.5.9.8)
charlock_holmes (0.7.7)
chewy (7.5.1)
chewy (7.6.0)
activesupport (>= 5.2)
elasticsearch (>= 7.12.0, < 7.14.0)
elasticsearch (>= 7.14.0, < 8)
elasticsearch-dsl
chunky_png (1.4.0)
climate_control (1.2.0)
Expand Down Expand Up @@ -217,17 +217,17 @@ GEM
domain_name (0.6.20240107)
doorkeeper (5.6.9)
railties (>= 5)
dotenv (3.1.1)
dotenv (3.1.2)
drb (2.2.1)
ed25519 (1.3.0)
elasticsearch (7.13.3)
elasticsearch-api (= 7.13.3)
elasticsearch-transport (= 7.13.3)
elasticsearch-api (7.13.3)
elasticsearch (7.17.10)
elasticsearch-api (= 7.17.10)
elasticsearch-transport (= 7.17.10)
elasticsearch-api (7.17.10)
multi_json
elasticsearch-dsl (0.1.10)
elasticsearch-transport (7.13.3)
faraday (~> 1)
elasticsearch-transport (7.17.10)
faraday (>= 1, < 3)
multi_json
email_spec (2.2.2)
htmlentities (~> 4.3.3)
Expand Down Expand Up @@ -346,7 +346,7 @@ GEM
activesupport (>= 3.0)
nokogiri (>= 1.6)
io-console (0.7.2)
irb (1.13.0)
irb (1.13.1)
rdoc (>= 4.0.0)
reline (>= 0.4.2)
jmespath (1.6.2)
Expand Down Expand Up @@ -601,7 +601,7 @@ GEM
redlock (1.3.2)
redis (>= 3.0.0, < 6.0)
regexp_parser (2.9.0)
reline (0.5.4)
reline (0.5.5)
io-console (~> 0.5)
request_store (1.6.0)
rack (>= 1.4)
Expand Down Expand Up @@ -653,8 +653,8 @@ GEM
rubocop-ast (>= 1.31.1, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 2.4.0, < 3.0)
rubocop-ast (1.31.2)
parser (>= 3.3.0.4)
rubocop-ast (1.31.3)
parser (>= 3.3.1.0)
rubocop-capybara (2.20.0)
rubocop (~> 1.41)
rubocop-factory_bot (2.25.1)
Expand All @@ -667,7 +667,7 @@ GEM
rack (>= 1.1)
rubocop (>= 1.33.0, < 2.0)
rubocop-ast (>= 1.31.1, < 2.0)
rubocop-rspec (2.29.1)
rubocop-rspec (2.29.2)
rubocop (~> 1.40)
rubocop-capybara (~> 2.17)
rubocop-factory_bot (~> 2.22)
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/admin/site_uploads_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def destroy

@site_upload.destroy!

redirect_to admin_settings_path, notice: I18n.t('admin.site_uploads.destroyed_msg')
redirect_back fallback_location: admin_settings_path, notice: I18n.t('admin.site_uploads.destroyed_msg')
end

private
Expand Down
30 changes: 26 additions & 4 deletions app/controllers/api/v1/accounts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,22 @@ class Api::V1::AccountsController < Api::BaseController
before_action -> { doorkeeper_authorize! :follow, :write, :'write:blocks' }, only: [:block, :unblock]
before_action -> { doorkeeper_authorize! :write, :'write:accounts' }, only: [:create]

before_action :require_user!, except: [:show, :create]
before_action :set_account, except: [:create]
before_action :check_account_approval, except: [:create]
before_action :check_account_confirmation, except: [:create]
before_action :require_user!, except: [:index, :show, :create]
before_action :set_account, except: [:index, :create]
before_action :set_accounts, only: [:index]
before_action :check_account_approval, except: [:index, :create]
before_action :check_account_confirmation, except: [:index, :create]
before_action :check_enabled_registrations, only: [:create]
before_action :check_accounts_limit, only: [:index]

skip_before_action :require_authenticated_user!, only: :create

override_rate_limit_headers :follow, family: :follows

def index
render json: @accounts, each_serializer: REST::AccountSerializer
end

def show
cache_if_unauthenticated!
render json: @account, serializer: REST::AccountSerializer
Expand Down Expand Up @@ -79,6 +85,10 @@ def set_account
@account = Account.find(params[:id])
end

def set_accounts
@accounts = Account.where(id: account_ids).without_unapproved
end

def check_account_approval
raise(ActiveRecord::RecordNotFound) if @account.local? && @account.user_pending?
end
Expand All @@ -87,10 +97,22 @@ def check_account_confirmation
raise(ActiveRecord::RecordNotFound) if @account.local? && !@account.user_confirmed?
end

def check_accounts_limit
raise(Mastodon::ValidationError) if account_ids.size > DEFAULT_ACCOUNTS_LIMIT
end

def relationships(**options)
AccountRelationshipsPresenter.new([@account], current_user.account_id, **options)
end

def account_ids
Array(accounts_params[:ids]).uniq.map(&:to_i)
end

def accounts_params
params.permit(ids: [])
end

def account_params
params.permit(:username, :email, :password, :agreement, :locale, :reason, :time_zone, :invite_code)
end
Expand Down
33 changes: 21 additions & 12 deletions app/controllers/api/v1/push/subscriptions_controller.rb
Original file line number Diff line number Diff line change
@@ -1,26 +1,31 @@
# frozen_string_literal: true

class Api::V1::Push::SubscriptionsController < Api::BaseController
include Redisable
include Lockable

before_action -> { doorkeeper_authorize! :push }
before_action :require_user!
before_action :set_push_subscription
before_action :set_push_subscription, only: [:show, :update]
before_action :check_push_subscription, only: [:show, :update]

def show
render json: @push_subscription, serializer: REST::WebPushSubscriptionSerializer
end

def create
@push_subscription&.destroy!
with_redis_lock("push_subscription:#{current_user.id}") do
destroy_web_push_subscriptions!

@push_subscription = Web::PushSubscription.create!(
endpoint: subscription_params[:endpoint],
key_p256dh: subscription_params[:keys][:p256dh],
key_auth: subscription_params[:keys][:auth],
data: data_params,
user_id: current_user.id,
access_token_id: doorkeeper_token.id
)
@push_subscription = Web::PushSubscription.create!(
endpoint: subscription_params[:endpoint],
key_p256dh: subscription_params[:keys][:p256dh],
key_auth: subscription_params[:keys][:auth],
data: data_params,
user_id: current_user.id,
access_token_id: doorkeeper_token.id
)
end

render json: @push_subscription, serializer: REST::WebPushSubscriptionSerializer
end
Expand All @@ -31,14 +36,18 @@ def update
end

def destroy
@push_subscription&.destroy!
destroy_web_push_subscriptions!
render_empty
end

private

def destroy_web_push_subscriptions!
doorkeeper_token.web_push_subscriptions.destroy_all
end

def set_push_subscription
@push_subscription = Web::PushSubscription.find_by(access_token_id: doorkeeper_token.id)
@push_subscription = doorkeeper_token.web_push_subscriptions.first
end

def check_push_subscription
Expand Down
29 changes: 26 additions & 3 deletions app/controllers/api/v1/statuses_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ class Api::V1::StatusesController < Api::BaseController

before_action -> { authorize_if_got_token! :read, :'read:statuses' }, except: [:create, :update, :destroy]
before_action -> { doorkeeper_authorize! :write, :'write:statuses' }, only: [:create, :update, :destroy]
before_action :require_user!, except: [:show, :context]
before_action :set_status, only: [:show, :context]
before_action :set_thread, only: [:create]
before_action :require_user!, except: [:index, :show, :context]
before_action :set_statuses, only: [:index]
before_action :set_status, only: [:show, :context]
before_action :set_thread, only: [:create]
before_action :check_statuses_limit, only: [:index]

override_rate_limit_headers :create, family: :statuses
override_rate_limit_headers :update, family: :statuses
Expand All @@ -23,6 +25,11 @@ class Api::V1::StatusesController < Api::BaseController
DESCENDANTS_LIMIT = 60
DESCENDANTS_DEPTH_LIMIT = 20

def index
@statuses = cache_collection(@statuses, Status)
render json: @statuses, each_serializer: REST::StatusSerializer
end

def show
cache_if_unauthenticated!
@status = cache_collection([@status], Status).first
Expand Down Expand Up @@ -111,6 +118,10 @@ def destroy

private

def set_statuses
@statuses = Status.permitted_statuses_from_ids(status_ids, current_account)
end

def set_status
@status = Status.find(params[:id])
authorize @status, :show?
Expand All @@ -125,6 +136,18 @@ def set_thread
render json: { error: I18n.t('statuses.errors.in_reply_not_found') }, status: 404
end

def check_statuses_limit
raise(Mastodon::ValidationError) if status_ids.size > DEFAULT_STATUSES_LIMIT
end

def status_ids
Array(statuses_params[:ids]).uniq.map(&:to_i)
end

def statuses_params
params.permit(ids: [])
end

def status_params
params.permit(
:status,
Expand Down
23 changes: 23 additions & 0 deletions app/controllers/well_known/oauth_metadata_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# frozen_string_literal: true

module WellKnown
class OauthMetadataController < ActionController::Base # rubocop:disable Rails/ApplicationController
include CacheConcern

# Prevent `active_model_serializer`'s `ActionController::Serialization` from calling `current_user`
# and thus re-issuing session cookies
serialization_scope nil

def show
# Due to this document potentially changing between Mastodon versions (as
# new OAuth scopes are added), we don't use expires_in to cache upstream,
# instead just caching in the rails cache:
render_with_cache(
json: ::OauthMetadataPresenter.new,
serializer: ::OauthMetadataSerializer,
content_type: 'application/json',
expires_in: 15.minutes
)
end
end
end
7 changes: 7 additions & 0 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,13 @@ def prerender_custom_emojis(html, custom_emojis, other_options = {})
EmojiFormatter.new(html, custom_emojis, other_options.merge(animate: prefers_autoplay?)).to_s
end

def site_icon_path(type, size = '48')
icon = SiteUpload.find_by(var: type)
return nil unless icon

icon.file.url(size)
end

private

def storage_host_var
Expand Down
Loading

0 comments on commit f7d8163

Please sign in to comment.