mirror of
https://github.com/discourse/discourse.git
synced 2026-09-05 04:40:41 -05:00
DEV: Update rubocop-discourse to 3.13 and autofix issues (#35073)
Co-authored-by: Loïc Guitaut <loic@discourse.org>
This commit is contained in:
co-authored by
Loïc Guitaut
parent
9a0a99b77d
commit
71834c898f
+2
-2
@@ -562,7 +562,7 @@ GEM
|
||||
rubocop-capybara (2.22.1)
|
||||
lint_roller (~> 1.1)
|
||||
rubocop (~> 1.72, >= 1.72.1)
|
||||
rubocop-discourse (3.12.1)
|
||||
rubocop-discourse (3.13.3)
|
||||
activesupport (>= 6.1)
|
||||
lint_roller (>= 1.1.0)
|
||||
rubocop (>= 1.73.2)
|
||||
@@ -1156,7 +1156,7 @@ CHECKSUMS
|
||||
rubocop (1.81.1) sha256=352a9a6f314a4312f6c305f1f72bc466254d221c95445cd49e1b65d1f9411635
|
||||
rubocop-ast (1.47.1) sha256=592682017855408b046a8190689490763aecea175238232b1b526826349d01ae
|
||||
rubocop-capybara (2.22.1) sha256=ced88caef23efea53f46e098ff352f8fc1068c649606ca75cb74650970f51c0c
|
||||
rubocop-discourse (3.12.1) sha256=ebf7e2224f053047372071419052828c3e3a01bccb14ea1f282ac143547df9bc
|
||||
rubocop-discourse (3.13.3) sha256=637395e37ac45f0c5ba4376d7648b5f1e3a8406697c38befb66a9729738a059f
|
||||
rubocop-factory_bot (2.27.1) sha256=9d744b5916778c1848e5fe6777cc69855bd96548853554ec239ba9961b8573fe
|
||||
rubocop-rails (2.33.4) sha256=34ec8f6637706dc224483d949ccc88b3e41596a81a11a1ec0c7d74ecbea356b5
|
||||
rubocop-rspec (3.7.0) sha256=b7b214da112034db9c6d00f2d811a354847e870f7b6ed2482b29649c3d42058f
|
||||
|
||||
@@ -4,7 +4,7 @@ class Admin::AdminNoticesController < Admin::StaffController
|
||||
def destroy
|
||||
AdminNotices::Dismiss.call(service_params) do
|
||||
on_success { render(json: success_json) }
|
||||
on_failure { render(json: failed_json, status: 422) }
|
||||
on_failure { render(json: failed_json, status: :unprocessable_entity) }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -27,7 +27,7 @@ class Admin::ApiController < Admin::AdminController
|
||||
end
|
||||
|
||||
def show
|
||||
api_key = ApiKey.includes(:api_key_scopes).find_by!(id: params[:id])
|
||||
api_key = ApiKey.includes(:api_key_scopes).find(params[:id])
|
||||
render_serialized(api_key, ApiKeySerializer, root: "key")
|
||||
end
|
||||
|
||||
@@ -53,7 +53,7 @@ class Admin::ApiController < Admin::AdminController
|
||||
end
|
||||
|
||||
def update
|
||||
api_key = ApiKey.find_by!(id: params[:id])
|
||||
api_key = ApiKey.find(params[:id])
|
||||
ApiKey.transaction do
|
||||
api_key.update!(update_params)
|
||||
log_api_key(api_key, UserHistory.actions[:api_key_update], changes: api_key.saved_changes)
|
||||
@@ -62,7 +62,7 @@ class Admin::ApiController < Admin::AdminController
|
||||
end
|
||||
|
||||
def destroy
|
||||
api_key = ApiKey.find_by!(id: params[:id])
|
||||
api_key = ApiKey.find(params[:id])
|
||||
ApiKey.transaction do
|
||||
api_key.destroy
|
||||
log_api_key(api_key, UserHistory.actions[:api_key_destroy])
|
||||
|
||||
@@ -89,14 +89,14 @@ class Admin::BackupsController < Admin::AdminController
|
||||
|
||||
render body: nil
|
||||
else
|
||||
render body: nil, status: 404
|
||||
render body: nil, status: :not_found
|
||||
end
|
||||
end
|
||||
|
||||
def show
|
||||
if !EmailBackupToken.compare(current_user.id, params.fetch(:token))
|
||||
@error = I18n.t("download_backup_mailer.no_token")
|
||||
return render layout: "no_ember", status: 422, formats: [:html]
|
||||
return render layout: "no_ember", status: :unprocessable_entity, formats: [:html]
|
||||
end
|
||||
|
||||
store = BackupRestore::BackupStore.create
|
||||
@@ -112,7 +112,7 @@ class Admin::BackupsController < Admin::AdminController
|
||||
send_file backup.source
|
||||
end
|
||||
else
|
||||
render body: nil, status: 404
|
||||
render body: nil, status: :not_found
|
||||
end
|
||||
end
|
||||
|
||||
@@ -124,7 +124,7 @@ class Admin::BackupsController < Admin::AdminController
|
||||
store.delete_file(backup.filename)
|
||||
render body: nil
|
||||
else
|
||||
render body: nil, status: 404
|
||||
render body: nil, status: :not_found
|
||||
end
|
||||
end
|
||||
|
||||
@@ -193,13 +193,17 @@ class Admin::BackupsController < Admin::AdminController
|
||||
|
||||
raise Discourse::InvalidParameters.new(:resumableIdentifier) unless valid_filename?(identifier)
|
||||
unless valid_extension?(filename)
|
||||
return render status: 415, plain: I18n.t("backup.backup_file_should_be_tar_gz")
|
||||
return(
|
||||
render status: :unsupported_media_type, plain: I18n.t("backup.backup_file_should_be_tar_gz")
|
||||
)
|
||||
end
|
||||
unless has_enough_space_on_disk?(total_size)
|
||||
return render status: 415, plain: I18n.t("backup.not_enough_space_on_disk")
|
||||
return(
|
||||
render status: :unsupported_media_type, plain: I18n.t("backup.not_enough_space_on_disk")
|
||||
)
|
||||
end
|
||||
unless valid_filename?(filename)
|
||||
return render status: 415, plain: I18n.t("backup.invalid_filename")
|
||||
return render status: :unsupported_media_type, plain: I18n.t("backup.invalid_filename")
|
||||
end
|
||||
|
||||
file = params.fetch(:file)
|
||||
|
||||
@@ -24,7 +24,9 @@ class Admin::BadgesController < Admin::AdminController
|
||||
end
|
||||
|
||||
def preview
|
||||
return render json: "preview not allowed", status: 403 unless SiteSetting.enable_badge_sql
|
||||
unless SiteSetting.enable_badge_sql
|
||||
return render json: "preview not allowed", status: :forbidden
|
||||
end
|
||||
|
||||
render json:
|
||||
BadgeGranter.preview(
|
||||
|
||||
@@ -7,11 +7,11 @@ class Admin::Config::FlagsController < Admin::AdminController
|
||||
Discourse.request_refresh!
|
||||
render(json: success_json)
|
||||
end
|
||||
on_failure { render(json: failed_json, status: 422) }
|
||||
on_failure { render(json: failed_json, status: :unprocessable_entity) }
|
||||
on_model_not_found(:message) { raise Discourse::NotFound }
|
||||
on_failed_policy(:invalid_access) { raise Discourse::InvalidAccess }
|
||||
on_failed_contract do |contract|
|
||||
render(json: failed_json.merge(errors: contract.errors.full_messages), status: 400)
|
||||
render(json: failed_json.merge(errors: contract.errors.full_messages), status: :bad_request)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -31,11 +31,11 @@ class Admin::Config::FlagsController < Admin::AdminController
|
||||
Discourse.request_refresh!
|
||||
render json: flag, serializer: FlagSerializer
|
||||
end
|
||||
on_failure { render(json: failed_json, status: 422) }
|
||||
on_failure { render(json: failed_json, status: :unprocessable_entity) }
|
||||
on_failed_policy(:invalid_access) { raise Discourse::InvalidAccess }
|
||||
on_failed_policy(:unique_name) { render_json_error(I18n.t("flags.errors.unique_name")) }
|
||||
on_failed_contract do |contract|
|
||||
render(json: failed_json.merge(errors: contract.errors.full_messages), status: 400)
|
||||
render(json: failed_json.merge(errors: contract.errors.full_messages), status: :bad_request)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -46,14 +46,14 @@ class Admin::Config::FlagsController < Admin::AdminController
|
||||
Discourse.request_refresh!
|
||||
render json: flag, serializer: FlagSerializer
|
||||
end
|
||||
on_failure { render(json: failed_json, status: 422) }
|
||||
on_failure { render(json: failed_json, status: :unprocessable_entity) }
|
||||
on_model_not_found(:message) { raise Discourse::NotFound }
|
||||
on_failed_policy(:not_system) { render_json_error(I18n.t("flags.errors.system")) }
|
||||
on_failed_policy(:not_used) { render_json_error(I18n.t("flags.errors.used")) }
|
||||
on_failed_policy(:invalid_access) { raise Discourse::InvalidAccess }
|
||||
on_failed_policy(:unique_name) { render_json_error(I18n.t("flags.errors.unique_name")) }
|
||||
on_failed_contract do |contract|
|
||||
render(json: failed_json.merge(errors: contract.errors.full_messages), status: 400)
|
||||
render(json: failed_json.merge(errors: contract.errors.full_messages), status: :bad_request)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -64,12 +64,12 @@ class Admin::Config::FlagsController < Admin::AdminController
|
||||
Discourse.request_refresh!
|
||||
render(json: success_json)
|
||||
end
|
||||
on_failure { render(json: failed_json, status: 422) }
|
||||
on_failure { render(json: failed_json, status: :unprocessable_entity) }
|
||||
on_model_not_found(:message) { raise Discourse::NotFound }
|
||||
on_failed_policy(:invalid_access) { raise Discourse::InvalidAccess }
|
||||
on_failed_policy(:invalid_move) { render_json_error(I18n.t("flags.errors.wrong_move")) }
|
||||
on_failed_contract do |contract|
|
||||
render(json: failed_json.merge(errors: contract.errors.full_messages), status: 400)
|
||||
render(json: failed_json.merge(errors: contract.errors.full_messages), status: :bad_request)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -80,12 +80,12 @@ class Admin::Config::FlagsController < Admin::AdminController
|
||||
Discourse.request_refresh!
|
||||
render(json: success_json)
|
||||
end
|
||||
on_failure { render(json: failed_json, status: 422) }
|
||||
on_failure { render(json: failed_json, status: :unprocessable_entity) }
|
||||
on_failed_policy(:not_system) { render_json_error(I18n.t("flags.errors.system")) }
|
||||
on_failed_policy(:not_used) { render_json_error(I18n.t("flags.errors.used")) }
|
||||
on_failed_policy(:invalid_access) { raise Discourse::InvalidAccess }
|
||||
on_failed_contract do |contract|
|
||||
render(json: failed_json.merge(errors: contract.errors.full_messages), status: 400)
|
||||
render(json: failed_json.merge(errors: contract.errors.full_messages), status: :bad_request)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -63,11 +63,11 @@ class Admin::DashboardController < Admin::StaffController
|
||||
def toggle_feature
|
||||
Experiments::Toggle.call(service_params) do
|
||||
on_success { render(json: success_json) }
|
||||
on_failure { render(json: failed_json, status: 422) }
|
||||
on_failure { render(json: failed_json, status: :unprocessable_entity) }
|
||||
on_failed_policy(:current_user_is_admin) { raise Discourse::InvalidAccess }
|
||||
on_failed_policy(:setting_is_available) { raise Discourse::InvalidAccess }
|
||||
on_failed_contract do |contract|
|
||||
render(json: failed_json.merge(errors: contract.errors.full_messages), status: 400)
|
||||
render(json: failed_json.merge(errors: contract.errors.full_messages), status: :bad_request)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -17,7 +17,7 @@ class Admin::EmailController < Admin::AdminController
|
||||
|
||||
render json: { sent_test_email_message: I18n.t("admin.email.sent_test") }
|
||||
rescue => e
|
||||
render json: { errors: [e.message] }, status: 422
|
||||
render json: { errors: [e.message] }, status: :unprocessable_entity
|
||||
end
|
||||
end
|
||||
|
||||
@@ -55,7 +55,7 @@ class Admin::EmailController < Admin::AdminController
|
||||
Email::Sender.new(message, :digest).send
|
||||
render json: success_json
|
||||
rescue => e
|
||||
render json: { errors: [e.message] }, status: 422
|
||||
render json: { errors: [e.message] }, status: :unprocessable_entity
|
||||
end
|
||||
else
|
||||
render json: { errors: skip_reason }
|
||||
|
||||
@@ -96,7 +96,7 @@ class Admin::EmailLogsController < Admin::AdminController
|
||||
serializer = IncomingEmailDetailsSerializer.new(incoming_email, root: false)
|
||||
render_json_dump(serializer)
|
||||
rescue => e
|
||||
render json: { errors: [e.message] }, status: 404
|
||||
render json: { errors: [e.message] }, status: :not_found
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -87,7 +87,7 @@ class Admin::ReportsController < Admin::StaffController
|
||||
if report_params[:start_date].present?
|
||||
Time.parse(report_params[:start_date]).to_date
|
||||
else
|
||||
1.days.ago
|
||||
1.day.ago
|
||||
end
|
||||
).beginning_of_day
|
||||
end_date =
|
||||
|
||||
@@ -106,7 +106,7 @@ class Admin::SiteTextsController < Admin::AdminController
|
||||
else
|
||||
render json:
|
||||
failed_json.merge(message: translation_override.errors.full_messages.join("\n\n")),
|
||||
status: 422
|
||||
status: :unprocessable_entity
|
||||
end
|
||||
end
|
||||
|
||||
@@ -140,7 +140,8 @@ class Admin::SiteTextsController < Admin::AdminController
|
||||
if override.make_up_to_date!
|
||||
render json: success_json
|
||||
else
|
||||
render json: failed_json.merge(message: "Can only dismiss outdated translations"), status: 422
|
||||
render json: failed_json.merge(message: "Can only dismiss outdated translations"),
|
||||
status: :unprocessable_entity
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -205,13 +205,13 @@ class Admin::ThemesController < Admin::AdminController
|
||||
) do
|
||||
on_success { |theme:| render json: serialize_data(theme, ThemeSerializer), status: :created }
|
||||
on_failed_contract do |contract|
|
||||
render json: failed_json.merge(errors: contract.errors.full_messages), status: 400
|
||||
render json: failed_json.merge(errors: contract.errors.full_messages), status: :bad_request
|
||||
end
|
||||
on_failed_policy(:ensure_remote_themes_are_not_allowlisted) { raise Discourse::InvalidAccess }
|
||||
on_model_errors { |theme:| render json: theme.errors, status: :unprocessable_entity }
|
||||
on_model_not_found(:theme) do |result|
|
||||
raise Discourse::NotFound if !result.exception
|
||||
render json: failed_json.merge(errors: result.exception.message), status: 400
|
||||
render json: failed_json.merge(errors: result.exception.message), status: :bad_request
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -291,7 +291,7 @@ class Admin::ThemesController < Admin::AdminController
|
||||
Themes::Destroy.call(service_params) do
|
||||
on_success { head :no_content }
|
||||
on_failed_contract do |contract|
|
||||
render json: failed_json.merge(errors: contract.errors.full_messages), status: 400
|
||||
render json: failed_json.merge(errors: contract.errors.full_messages), status: :bad_request
|
||||
end
|
||||
on_model_not_found(:theme) { raise Discourse::NotFound }
|
||||
end
|
||||
@@ -301,7 +301,7 @@ class Admin::ThemesController < Admin::AdminController
|
||||
Themes::BulkDestroy.call(service_params) do
|
||||
on_success { head :no_content }
|
||||
on_failed_contract do |contract|
|
||||
render json: failed_json.merge(errors: contract.errors.full_messages), status: 400
|
||||
render json: failed_json.merge(errors: contract.errors.full_messages), status: :bad_request
|
||||
end
|
||||
on_model_not_found(:themes) { raise Discourse::NotFound }
|
||||
end
|
||||
@@ -333,7 +333,7 @@ class Admin::ThemesController < Admin::AdminController
|
||||
Themes::GetTranslations.call(service_params) do
|
||||
on_success { |translations:| render(json: success_json.merge(translations:)) }
|
||||
on_failed_contract do |contract|
|
||||
render json: failed_json.merge(errors: contract.errors.full_messages), status: 400
|
||||
render json: failed_json.merge(errors: contract.errors.full_messages), status: :bad_request
|
||||
end
|
||||
on_failed_policy(:validate_locale) { raise Discourse::InvalidParameters.new(:locale) }
|
||||
on_model_not_found(:theme) { raise Discourse::NotFound }
|
||||
|
||||
@@ -135,11 +135,11 @@ class Admin::UsersController < Admin::StaffController
|
||||
)
|
||||
end
|
||||
on_failed_contract do |contract|
|
||||
render json: failed_json.merge(errors: contract.errors.full_messages), status: 400
|
||||
render json: failed_json.merge(errors: contract.errors.full_messages), status: :bad_request
|
||||
end
|
||||
on_model_not_found(:user) { raise Discourse::NotFound }
|
||||
on_failed_policy(:not_suspended_already) do |policy|
|
||||
render json: failed_json.merge(message: policy.reason), status: 409
|
||||
render json: failed_json.merge(message: policy.reason), status: :conflict
|
||||
end
|
||||
on_failed_policy(:can_suspend_all_users) { raise Discourse::InvalidAccess.new }
|
||||
end
|
||||
@@ -163,7 +163,7 @@ class Admin::UsersController < Admin::StaffController
|
||||
@user.logged_out
|
||||
render json: success_json
|
||||
else
|
||||
render json: { error: I18n.t("admin_js.admin.users.id_not_found") }, status: 404
|
||||
render json: { error: I18n.t("admin_js.admin.users.id_not_found") }, status: :not_found
|
||||
end
|
||||
end
|
||||
|
||||
@@ -335,11 +335,11 @@ class Admin::UsersController < Admin::StaffController
|
||||
)
|
||||
end
|
||||
on_failed_contract do |contract|
|
||||
render json: failed_json.merge(errors: contract.errors.full_messages), status: 400
|
||||
render json: failed_json.merge(errors: contract.errors.full_messages), status: :bad_request
|
||||
end
|
||||
on_model_not_found(:user) { raise Discourse::NotFound }
|
||||
on_failed_policy(:not_silenced_already) do |policy|
|
||||
render json: failed_json.merge(message: policy.reason), status: 409
|
||||
render json: failed_json.merge(message: policy.reason), status: :conflict
|
||||
end
|
||||
on_failed_policy(:can_silence_all_users) { raise Discourse::InvalidAccess.new }
|
||||
end
|
||||
@@ -404,7 +404,7 @@ class Admin::UsersController < Admin::StaffController
|
||||
count: user.posts.joins(:topic).count,
|
||||
),
|
||||
},
|
||||
status: 403
|
||||
status: :forbidden
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -419,14 +419,16 @@ class Admin::UsersController < Admin::StaffController
|
||||
on_success { render json: { deleted: true } }
|
||||
|
||||
on_failed_contract do |contract|
|
||||
render json: failed_json.merge(errors: contract.errors.full_messages), status: 400
|
||||
render json: failed_json.merge(errors: contract.errors.full_messages),
|
||||
status: :bad_request
|
||||
end
|
||||
|
||||
on_failed_policy(:can_delete_users) do
|
||||
render json: failed_json.merge(errors: [I18n.t("user.cannot_bulk_delete")]), status: 403
|
||||
render json: failed_json.merge(errors: [I18n.t("user.cannot_bulk_delete")]),
|
||||
status: :forbidden
|
||||
end
|
||||
|
||||
on_model_not_found(:users) { render json: failed_json, status: 404 }
|
||||
on_model_not_found(:users) { render json: failed_json, status: :not_found }
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -445,14 +447,14 @@ class Admin::UsersController < Admin::StaffController
|
||||
end
|
||||
|
||||
def sync_sso
|
||||
return render body: nil, status: 404 unless SiteSetting.enable_discourse_connect
|
||||
return render body: nil, status: :not_found unless SiteSetting.enable_discourse_connect
|
||||
|
||||
begin
|
||||
sso = DiscourseConnect.parse("sso=#{params[:sso]}&sig=#{params[:sig]}", server_session:)
|
||||
rescue DiscourseConnect::ParseError
|
||||
return(
|
||||
render json: failed_json.merge(message: I18n.t("discourse_connect.login_error")),
|
||||
status: 422
|
||||
status: :unprocessable_entity
|
||||
)
|
||||
end
|
||||
|
||||
@@ -461,10 +463,10 @@ class Admin::UsersController < Admin::StaffController
|
||||
DiscourseEvent.trigger(:sync_sso, user)
|
||||
render_serialized(user, AdminDetailedUserSerializer, root: false)
|
||||
rescue ActiveRecord::RecordInvalid => ex
|
||||
render json: failed_json.merge(message: ex.message), status: 403
|
||||
render json: failed_json.merge(message: ex.message), status: :forbidden
|
||||
rescue DiscourseConnect::BlankExternalId => ex
|
||||
render json: failed_json.merge(message: I18n.t("discourse_connect.blank_id_error")),
|
||||
status: 422
|
||||
status: :unprocessable_entity
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -39,20 +39,20 @@ class Admin::WebHooksController < Admin::AdminController
|
||||
admin_web_hooks_path(limit: limit, offset: offset + limit, format: :json),
|
||||
}
|
||||
|
||||
render json: MultiJson.dump(json), status: 200
|
||||
render json: MultiJson.dump(json), status: :ok
|
||||
end
|
||||
|
||||
def show
|
||||
data = serialize_data(@web_hook, AdminWebHookSerializer, root: "web_hook")
|
||||
web_hook = data.delete("web_hook")
|
||||
data = { "extras" => data, "web_hook" => web_hook }
|
||||
render json: MultiJson.dump(data), status: 200
|
||||
render json: MultiJson.dump(data), status: :ok
|
||||
end
|
||||
|
||||
def edit
|
||||
data = serialize_data(@web_hook, AdminWebHookSerializer, root: "web_hook")
|
||||
data["extras"] = { "categories" => data.delete(:categories) }
|
||||
render json: MultiJson.dump(data), status: 200
|
||||
render json: MultiJson.dump(data), status: :ok
|
||||
end
|
||||
|
||||
def create
|
||||
@@ -120,7 +120,7 @@ class Admin::WebHooksController < Admin::AdminController
|
||||
},
|
||||
}
|
||||
|
||||
render json: MultiJson.dump(json), status: 200
|
||||
render json: MultiJson.dump(json), status: :ok
|
||||
end
|
||||
|
||||
def bulk_events
|
||||
|
||||
@@ -29,7 +29,7 @@ class ApplicationController < ActionController::Base
|
||||
unless is_api? || is_user_api?
|
||||
super
|
||||
clear_current_user
|
||||
render plain: "[\"BAD CSRF\"]", status: 403
|
||||
render plain: "[\"BAD CSRF\"]", status: :forbidden
|
||||
end
|
||||
end
|
||||
|
||||
@@ -255,14 +255,16 @@ class ApplicationController < ActionController::Base
|
||||
format.json do
|
||||
render_json_error I18n.t("read_only_mode_enabled"), type: :read_only, status: 503
|
||||
end
|
||||
format.html { render status: 503, layout: "no_ember", template: "exceptions/read_only" }
|
||||
format.html do
|
||||
render status: :service_unavailable, layout: "no_ember", template: "exceptions/read_only"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
rescue_from SecondFactor::AuthManager::SecondFactorRequired do |e|
|
||||
if request.xhr?
|
||||
render json: { second_factor_challenge_nonce: e.nonce }, status: 403
|
||||
render json: { second_factor_challenge_nonce: e.nonce }, status: :forbidden
|
||||
else
|
||||
redirect_to session_2fa_path(nonce: e.nonce)
|
||||
end
|
||||
|
||||
@@ -35,7 +35,8 @@ class BookmarksController < ApplicationController
|
||||
|
||||
return render json: success_json.merge(id: bookmark.id) if bookmark_manager.errors.empty?
|
||||
|
||||
render json: failed_json.merge(errors: bookmark_manager.errors.full_messages), status: 400
|
||||
render json: failed_json.merge(errors: bookmark_manager.errors.full_messages),
|
||||
status: :bad_request
|
||||
end
|
||||
|
||||
def destroy
|
||||
@@ -61,7 +62,8 @@ class BookmarksController < ApplicationController
|
||||
|
||||
return render json: success_json if bookmark_manager.errors.empty?
|
||||
|
||||
render json: failed_json.merge(errors: bookmark_manager.errors.full_messages), status: 400
|
||||
render json: failed_json.merge(errors: bookmark_manager.errors.full_messages),
|
||||
status: :bad_request
|
||||
end
|
||||
|
||||
def toggle_pin
|
||||
@@ -72,7 +74,8 @@ class BookmarksController < ApplicationController
|
||||
|
||||
return render json: success_json if bookmark_manager.errors.empty?
|
||||
|
||||
render json: failed_json.merge(errors: bookmark_manager.errors.full_messages), status: 400
|
||||
render json: failed_json.merge(errors: bookmark_manager.errors.full_messages),
|
||||
status: :bad_request
|
||||
end
|
||||
|
||||
def bulk
|
||||
|
||||
@@ -100,7 +100,7 @@ class CategoriesController < ApplicationController
|
||||
category.move_to(params["position"].to_i)
|
||||
render json: success_json
|
||||
else
|
||||
render status: 500, json: failed_json
|
||||
render status: :internal_server_error, json: failed_json
|
||||
end
|
||||
end
|
||||
|
||||
@@ -143,7 +143,7 @@ class CategoriesController < ApplicationController
|
||||
begin
|
||||
Category.new(required_create_params.merge(user: current_user))
|
||||
rescue ArgumentError => e
|
||||
return render json: { errors: [e.message] }, status: 422
|
||||
return render json: { errors: [e.message] }, status: :unprocessable_entity
|
||||
end
|
||||
|
||||
if @category.save
|
||||
|
||||
@@ -148,7 +148,7 @@ class DraftsController < ApplicationController
|
||||
# nothing really we can do here, if try clearing a draft that is not ours, just skip it.
|
||||
# rendering an error causes issues in the composer
|
||||
rescue StandardError => e
|
||||
return render json: failed_json.merge(errors: e), status: 401
|
||||
return render json: failed_json.merge(errors: e), status: :unauthorized
|
||||
end
|
||||
|
||||
render json: success_json
|
||||
@@ -191,7 +191,7 @@ class DraftsController < ApplicationController
|
||||
failed_json.merge(
|
||||
errors: "Draft sequence conflict for keys: #{sequence_errors.join(", ")}",
|
||||
),
|
||||
status: 409
|
||||
status: :conflict
|
||||
return
|
||||
end
|
||||
|
||||
@@ -205,7 +205,7 @@ class DraftsController < ApplicationController
|
||||
UserStat.update_draft_count(user.id)
|
||||
end
|
||||
rescue StandardError => e
|
||||
return render json: failed_json.merge(errors: e.message), status: 500
|
||||
return render json: failed_json.merge(errors: e.message), status: :internal_server_error
|
||||
end
|
||||
|
||||
render json: success_json.merge(deleted_count: deleted_count)
|
||||
|
||||
@@ -16,14 +16,14 @@ class EmbedController < ApplicationController
|
||||
@show_reason = true
|
||||
@hosts = EmbeddableHost.all
|
||||
end
|
||||
render "embed_error", status: 400
|
||||
render "embed_error", status: :bad_request
|
||||
end
|
||||
|
||||
def topics
|
||||
discourse_expires_in 1.minute
|
||||
|
||||
unless SiteSetting.embed_topics_list?
|
||||
render "embed_topics_error", status: 400
|
||||
render "embed_topics_error", status: :bad_request
|
||||
return
|
||||
end
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ class ExportCsvController < ApplicationController
|
||||
unless current_user.admin ||
|
||||
UserExport.where(
|
||||
user_id: entity_id || current_user.id,
|
||||
created_at: (Time.zone.now.beginning_of_day..Time.zone.now.end_of_day),
|
||||
created_at: (Time.zone.now.all_day),
|
||||
).count == 0
|
||||
render_json_error I18n.t("csv_export.rate_limit_error")
|
||||
return
|
||||
|
||||
@@ -11,9 +11,9 @@ class ForumsController < ActionController::Base
|
||||
def status
|
||||
if params[:cluster]
|
||||
if GlobalSetting.cluster_name.nil?
|
||||
return render plain: "cluster name not configured", status: 500
|
||||
return render plain: "cluster name not configured", status: :internal_server_error
|
||||
elsif GlobalSetting.cluster_name != params[:cluster]
|
||||
return render plain: "cluster name does not match", status: 500
|
||||
return render plain: "cluster name does not match", status: :internal_server_error
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -162,7 +162,7 @@ class GroupsController < ApplicationController
|
||||
user_count = count_existing_users(group.group_users, notification_level, categories, tags)
|
||||
if user_count > 0
|
||||
return(
|
||||
render status: 422,
|
||||
render status: :unprocessable_entity,
|
||||
json: {
|
||||
user_count: user_count,
|
||||
errors: [I18n.t("invalid_params", message: :update_existing_users)],
|
||||
@@ -612,7 +612,7 @@ class GroupsController < ApplicationController
|
||||
rescue ActiveRecord::RecordNotUnique
|
||||
return(
|
||||
render json: failed_json.merge(error: I18n.t("groups.errors.already_requested_membership")),
|
||||
status: 409
|
||||
status: :conflict
|
||||
)
|
||||
end
|
||||
|
||||
|
||||
@@ -9,7 +9,8 @@ class InlineOneboxController < ApplicationController
|
||||
urls = params[:urls] || []
|
||||
|
||||
if urls.size > MAX_URLS_LIMIT
|
||||
render json: failed_json.merge(errors: [I18n.t("inline_oneboxer.too_many_urls")]), status: 413
|
||||
render json: failed_json.merge(errors: [I18n.t("inline_oneboxer.too_many_urls")]),
|
||||
status: :payload_too_large
|
||||
return
|
||||
end
|
||||
|
||||
@@ -18,7 +19,7 @@ class InlineOneboxController < ApplicationController
|
||||
if InlineOneboxer.is_previewing?(current_user_id)
|
||||
response.headers["Retry-After"] = "60"
|
||||
render json: failed_json.merge(errors: [I18n.t("inline_oneboxer.concurrency_not_allowed")]),
|
||||
status: 429
|
||||
status: :too_many_requests
|
||||
return
|
||||
end
|
||||
|
||||
|
||||
@@ -169,7 +169,7 @@ class InvitesController < ApplicationController
|
||||
show_warnings: true,
|
||||
)
|
||||
else
|
||||
render json: failed_json, status: 422
|
||||
render json: failed_json, status: :unprocessable_entity
|
||||
end
|
||||
rescue Invite::UserExists => e
|
||||
render_json_error(e.message)
|
||||
@@ -378,11 +378,14 @@ class InvitesController < ApplicationController
|
||||
ActiveRecord::RecordNotSaved,
|
||||
ActiveRecord::LockWaitTimeout,
|
||||
Invite::UserExists => e
|
||||
return render json: failed_json.merge(message: e.message), status: 412
|
||||
return render json: failed_json.merge(message: e.message), status: :precondition_failed
|
||||
end
|
||||
|
||||
if user.blank?
|
||||
return render json: failed_json.merge(message: I18n.t("invite.not_found_json")), status: 404
|
||||
return(
|
||||
render json: failed_json.merge(message: I18n.t("invite.not_found_json")),
|
||||
status: :not_found
|
||||
)
|
||||
end
|
||||
|
||||
log_on_user(user) if !redeeming_user && user.active? && user.guardian.can_access_forum?
|
||||
@@ -416,7 +419,7 @@ class InvitesController < ApplicationController
|
||||
|
||||
render json: success_json.merge(response)
|
||||
else
|
||||
render json: failed_json.merge(message: I18n.t("invite.not_found_json")), status: 404
|
||||
render json: failed_json.merge(message: I18n.t("invite.not_found_json")), status: :not_found
|
||||
end
|
||||
end
|
||||
|
||||
@@ -495,7 +498,9 @@ class InvitesController < ApplicationController
|
||||
DiscoursePluginRegistry.apply_modifier(:invite_bulk_csv_custom_error, nil, invites)
|
||||
|
||||
if custom_error.present?
|
||||
return render json: failed_json.merge(errors: [custom_error]), status: 422
|
||||
return(
|
||||
render json: failed_json.merge(errors: [custom_error]), status: :unprocessable_entity
|
||||
)
|
||||
end
|
||||
|
||||
Jobs.enqueue(:bulk_invite, invites: invites, current_user_id: current_user.id)
|
||||
@@ -510,12 +515,13 @@ class InvitesController < ApplicationController
|
||||
),
|
||||
],
|
||||
),
|
||||
status: 422
|
||||
status: :unprocessable_entity
|
||||
else
|
||||
render json: success_json
|
||||
end
|
||||
else
|
||||
render json: failed_json.merge(errors: [I18n.t("bulk_invite.error")]), status: 422
|
||||
render json: failed_json.merge(errors: [I18n.t("bulk_invite.error")]),
|
||||
status: :unprocessable_entity
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -430,7 +430,7 @@ class ListController < ApplicationController
|
||||
url = url.sub(ActionController::Base.config.relative_url_root, "")
|
||||
end
|
||||
|
||||
return redirect_to path(url), status: 301
|
||||
return redirect_to path(url), status: :moved_permanently
|
||||
end
|
||||
|
||||
@description_meta =
|
||||
|
||||
@@ -8,24 +8,24 @@ class MetadataController < ApplicationController
|
||||
:redirect_to_profile_if_required
|
||||
|
||||
def manifest
|
||||
expires_in 1.minutes
|
||||
expires_in 1.minute
|
||||
render json: default_manifest.to_json, content_type: "application/manifest+json"
|
||||
end
|
||||
|
||||
def opensearch
|
||||
expires_in 1.minutes
|
||||
expires_in 1.minute
|
||||
render template: "metadata/opensearch", formats: [:xml]
|
||||
end
|
||||
|
||||
def app_association_android
|
||||
raise Discourse::NotFound if SiteSetting.app_association_android.blank?
|
||||
expires_in 1.minutes
|
||||
expires_in 1.minute
|
||||
render plain: SiteSetting.app_association_android, content_type: "application/json"
|
||||
end
|
||||
|
||||
def app_association_ios
|
||||
raise Discourse::NotFound if SiteSetting.app_association_ios.blank?
|
||||
expires_in 1.minutes
|
||||
expires_in 1.minute
|
||||
render plain: SiteSetting.app_association_ios, content_type: "application/json"
|
||||
end
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ class OneboxController < ApplicationController
|
||||
end
|
||||
|
||||
# only 1 outgoing preview per user
|
||||
return render(body: nil, status: 429) if Oneboxer.is_previewing?(current_user.id)
|
||||
return render(body: nil, status: :too_many_requests) if Oneboxer.is_previewing?(current_user.id)
|
||||
|
||||
user_id = current_user.id
|
||||
category_id = params[:category_id].to_i
|
||||
@@ -19,7 +19,7 @@ class OneboxController < ApplicationController
|
||||
invalidate = params[:refresh] == "true"
|
||||
url = params[:url]
|
||||
|
||||
return render(body: nil, status: 404) if Oneboxer.recently_failed?(url)
|
||||
return render(body: nil, status: :not_found) if Oneboxer.recently_failed?(url)
|
||||
|
||||
hijack(info: "#{url} topic_id: #{topic_id} user_id: #{user_id}") do
|
||||
Oneboxer.preview_onebox!(user_id)
|
||||
@@ -39,7 +39,7 @@ class OneboxController < ApplicationController
|
||||
|
||||
if preview.blank?
|
||||
Oneboxer.cache_failed!(url)
|
||||
render body: nil, status: 404
|
||||
render body: nil, status: :not_found
|
||||
else
|
||||
render plain: preview
|
||||
end
|
||||
|
||||
@@ -13,7 +13,7 @@ class ReviewableNotesController < ApplicationController
|
||||
note.reload
|
||||
render json: ReviewableNoteSerializer.new(note, scope: guardian, root: false)
|
||||
else
|
||||
render json: { errors: note.errors.full_messages }, status: 422
|
||||
render json: { errors: note.errors.full_messages }, status: :unprocessable_entity
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -91,14 +91,15 @@ class SessionController < ApplicationController
|
||||
render json: success_json.merge(redirect_url: redirect_url)
|
||||
end
|
||||
rescue DiscourseConnectProvider::BlankSecret
|
||||
render plain: I18n.t("discourse_connect.missing_secret"), status: 400
|
||||
render plain: I18n.t("discourse_connect.missing_secret"), status: :bad_request
|
||||
rescue DiscourseConnectProvider::ParseError
|
||||
# Do NOT pass the error text to the client, it would give them the correct signature
|
||||
render plain: I18n.t("discourse_connect.login_error"), status: 422
|
||||
render plain: I18n.t("discourse_connect.login_error"), status: :unprocessable_entity
|
||||
rescue DiscourseConnectProvider::BlankReturnUrl
|
||||
render plain: "return_sso_url is blank, it must be provided", status: 400
|
||||
render plain: "return_sso_url is blank, it must be provided", status: :bad_request
|
||||
rescue DiscourseConnectProvider::InvalidParameterValueError => e
|
||||
render plain: I18n.t("discourse_connect.invalid_parameter_value", param: e.param), status: 400
|
||||
render plain: I18n.t("discourse_connect.invalid_parameter_value", param: e.param),
|
||||
status: :bad_request
|
||||
end
|
||||
|
||||
# For use in development mode only when login options could be limited or disabled.
|
||||
@@ -110,7 +111,7 @@ class SessionController < ApplicationController
|
||||
raise Discourse::InvalidAccess if Rails.env.production?
|
||||
|
||||
if ENV["DISCOURSE_DEV_ALLOW_ANON_TO_IMPERSONATE"] != "1"
|
||||
return render plain: <<~TEXT, status: 403
|
||||
return render plain: <<~TEXT, status: :forbidden
|
||||
To enable impersonating any user without typing passwords set the following ENV var
|
||||
|
||||
export DISCOURSE_DEV_ALLOW_ANON_TO_IMPERSONATE=1
|
||||
@@ -122,9 +123,9 @@ class SessionController < ApplicationController
|
||||
user = User.find_by_username(params[:session_id])
|
||||
|
||||
if user.blank?
|
||||
return render plain: "User #{params[:session_id]} not found", status: 403
|
||||
return render plain: "User #{params[:session_id]} not found", status: :forbidden
|
||||
elsif !user.active?
|
||||
return render plain: "User #{params[:session_id]} is not active", status: 403
|
||||
return render plain: "User #{params[:session_id]} is not active", status: :forbidden
|
||||
end
|
||||
|
||||
log_on_user(user)
|
||||
@@ -157,7 +158,7 @@ class SessionController < ApplicationController
|
||||
# but since this is a test route, we allow passing a bad value into the API, catch the error
|
||||
# and return a JSON response to assert against.
|
||||
if e.message == "running 2fa against another user is not allowed"
|
||||
render json: { result: "wrong user" }, status: 400
|
||||
render json: { result: "wrong user" }, status: :bad_request
|
||||
else
|
||||
raise e
|
||||
end
|
||||
@@ -605,7 +606,7 @@ class SessionController < ApplicationController
|
||||
.deep_symbolize_keys
|
||||
.slice(:ok, :error, :reason)
|
||||
.merge(failed_json)
|
||||
render json: error_json, status: 400
|
||||
render json: error_json, status: :bad_request
|
||||
return
|
||||
end
|
||||
end
|
||||
@@ -615,7 +616,7 @@ class SessionController < ApplicationController
|
||||
callback_path: challenge[:callback_path],
|
||||
redirect_url: challenge[:redirect_url],
|
||||
},
|
||||
status: 200
|
||||
status: :ok
|
||||
end
|
||||
|
||||
def forgot_password
|
||||
@@ -661,7 +662,7 @@ class SessionController < ApplicationController
|
||||
if current_user.present?
|
||||
render_serialized(current_user, CurrentUserSerializer, { login_method: login_method })
|
||||
else
|
||||
render body: nil, status: 404
|
||||
render body: nil, status: :not_found
|
||||
end
|
||||
end
|
||||
|
||||
@@ -716,7 +717,7 @@ class SessionController < ApplicationController
|
||||
api_key = ApiKey.active.with_key(key).first
|
||||
render_serialized(api_key.api_key_scopes, ApiKeyScopeSerializer, root: "scopes")
|
||||
else
|
||||
render body: nil, status: 404
|
||||
render body: nil, status: :not_found
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -74,7 +74,7 @@ class SidebarSectionsController < ApplicationController
|
||||
rescue ActiveRecord::NestedAttributes::TooManyRecords => e
|
||||
render_json_error(e.message)
|
||||
rescue Discourse::InvalidAccess
|
||||
render json: failed_json, status: 403
|
||||
render json: failed_json, status: :forbidden
|
||||
end
|
||||
|
||||
def reset
|
||||
@@ -102,7 +102,7 @@ class SidebarSectionsController < ApplicationController
|
||||
|
||||
render json: success_json
|
||||
rescue Discourse::InvalidAccess
|
||||
render json: failed_json, status: 403
|
||||
render json: failed_json, status: :forbidden
|
||||
end
|
||||
|
||||
def section_params
|
||||
|
||||
@@ -108,7 +108,7 @@ class StaticController < ApplicationController
|
||||
end
|
||||
@title = "#{title_prefix} - #{SiteSetting.title}"
|
||||
@body = @topic.posts.first.cooked
|
||||
@faq_overridden = !SiteSetting.faq_url.blank?
|
||||
@faq_overridden = SiteSetting.faq_url.present?
|
||||
@experimental_rename_faq_to_guidelines = rename_faq
|
||||
|
||||
render :show, layout: !request.xhr?, formats: [:html]
|
||||
@@ -203,7 +203,7 @@ class StaticController < ApplicationController
|
||||
file&.unlink
|
||||
end
|
||||
else
|
||||
File.read(Rails.root.join("public", favicon.url[1..-1]))
|
||||
File.read(Rails.public_path.join(favicon.url[1..-1]))
|
||||
end
|
||||
end
|
||||
|
||||
@@ -265,7 +265,7 @@ class StaticController < ApplicationController
|
||||
rescue Errno::ENOENT
|
||||
expires_in 1.second, public: true, must_revalidate: false
|
||||
|
||||
render plain: "can not find #{params[:path]}", status: 404
|
||||
render plain: "can not find #{params[:path]}", status: :not_found
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
@@ -20,7 +20,7 @@ class StepsController < ApplicationController
|
||||
updater.errors.messages.each do |field, msg|
|
||||
errors << { field: field, description: msg.join }
|
||||
end
|
||||
render json: { errors: errors }, status: 422
|
||||
render json: { errors: errors }, status: :unprocessable_entity
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -78,7 +78,7 @@ class StylesheetsController < ApplicationController
|
||||
end
|
||||
end
|
||||
|
||||
if Rails.env == "development"
|
||||
if Rails.env.development?
|
||||
response.headers["Last-Modified"] = Time.zone.now.httpdate
|
||||
immutable_for(1.second)
|
||||
else
|
||||
|
||||
@@ -37,7 +37,7 @@ class SvgSpriteController < ApplicationController
|
||||
data = SvgSprite.search(keyword)
|
||||
|
||||
if data.blank?
|
||||
render body: nil, status: 404
|
||||
render body: nil, status: :not_found
|
||||
else
|
||||
render plain: data.inspect, disposition: nil, content_type: "text/plain"
|
||||
end
|
||||
@@ -62,14 +62,14 @@ class SvgSpriteController < ApplicationController
|
||||
icon = SvgSprite.search(name)
|
||||
|
||||
if icon.blank?
|
||||
render body: nil, status: 404
|
||||
render body: nil, status: :not_found
|
||||
else
|
||||
doc = Nokogiri.XML(icon)
|
||||
doc.at_xpath("symbol").name = "svg"
|
||||
doc.at_xpath("svg")["xmlns"] = "http://www.w3.org/2000/svg"
|
||||
doc.at_xpath("svg")["fill"] = adjust_hex(params[:color]) if params[:color]
|
||||
|
||||
response.headers["Last-Modified"] = 1.years.ago.httpdate
|
||||
response.headers["Last-Modified"] = 1.year.ago.httpdate
|
||||
response.headers["Content-Length"] = doc.to_s.bytesize.to_s
|
||||
immutable_for 1.day
|
||||
|
||||
|
||||
@@ -267,7 +267,7 @@ class TagsController < ::ApplicationController
|
||||
end
|
||||
render json: success_json
|
||||
rescue Discourse::InvalidParameters => e
|
||||
render json: failed_json.merge(errors: [e.message]), status: 422
|
||||
render json: failed_json.merge(errors: [e.message]), status: :unprocessable_entity
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -328,7 +328,7 @@ class TagsController < ::ApplicationController
|
||||
|
||||
filter_params[:category] = Category.find_by_id(params[:categoryId]) if params[:categoryId]
|
||||
|
||||
if !params[:q].blank?
|
||||
if params[:q].present?
|
||||
clean_name = DiscourseTagging.clean_tag(params[:q])
|
||||
filter_params[:term] = clean_name
|
||||
filter_params[:order_search_results] = true
|
||||
@@ -444,7 +444,7 @@ class TagsController < ::ApplicationController
|
||||
synonym.update!(target_tag: nil)
|
||||
render json: success_json
|
||||
else
|
||||
render json: failed_json, status: 400
|
||||
render json: failed_json, status: :bad_request
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -571,7 +571,7 @@ class TopicsController < ApplicationController
|
||||
|
||||
options = { by_user: current_user, based_on_last_post: based_on_last_post }
|
||||
|
||||
options.merge!(category_id: params[:category_id]) if !params[:category_id].blank?
|
||||
options.merge!(category_id: params[:category_id]) if params[:category_id].present?
|
||||
if params[:duration_minutes].present?
|
||||
options.merge!(duration_minutes: params[:duration_minutes].to_i)
|
||||
end
|
||||
@@ -729,7 +729,7 @@ class TopicsController < ApplicationController
|
||||
if topic.remove_allowed_user(current_user, user)
|
||||
render json: success_json
|
||||
else
|
||||
render json: failed_json, status: 422
|
||||
render json: failed_json, status: :unprocessable_entity
|
||||
end
|
||||
end
|
||||
|
||||
@@ -741,7 +741,7 @@ class TopicsController < ApplicationController
|
||||
if topic.remove_allowed_group(current_user, params[:name])
|
||||
render json: success_json
|
||||
else
|
||||
render json: failed_json, status: 422
|
||||
render json: failed_json, status: :unprocessable_entity
|
||||
end
|
||||
end
|
||||
|
||||
@@ -774,7 +774,7 @@ class TopicsController < ApplicationController
|
||||
topic.invite_group(current_user, group, should_notify: should_notify)
|
||||
render_json_dump BasicGroupSerializer.new(group, scope: guardian, root: "group")
|
||||
else
|
||||
render json: failed_json, status: 422
|
||||
render json: failed_json, status: :unprocessable_entity
|
||||
end
|
||||
end
|
||||
|
||||
@@ -827,10 +827,10 @@ class TopicsController < ApplicationController
|
||||
end
|
||||
end
|
||||
|
||||
render json: json, status: 422
|
||||
render json: json, status: :unprocessable_entity
|
||||
end
|
||||
rescue Topic::UserExists, Topic::NotAllowed => e
|
||||
render json: { errors: [e.message] }, status: 422
|
||||
render json: { errors: [e.message] }, status: :unprocessable_entity
|
||||
end
|
||||
end
|
||||
|
||||
@@ -935,7 +935,7 @@ class TopicsController < ApplicationController
|
||||
).change_owner!
|
||||
render json: success_json
|
||||
rescue ArgumentError
|
||||
render json: failed_json, status: 422
|
||||
render json: failed_json, status: :unprocessable_entity
|
||||
end
|
||||
end
|
||||
|
||||
@@ -959,7 +959,7 @@ class TopicsController < ApplicationController
|
||||
|
||||
render json: success_json
|
||||
rescue ActiveRecord::RecordInvalid, TopicTimestampChanger::InvalidTimestampError
|
||||
render json: failed_json, status: 422
|
||||
render json: failed_json, status: :unprocessable_entity
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1293,7 +1293,7 @@ class TopicsController < ApplicationController
|
||||
url << "#{s}#{k}=#{v}"
|
||||
end
|
||||
|
||||
redirect_to url, status: 301
|
||||
redirect_to url, status: :moved_permanently
|
||||
end
|
||||
|
||||
def track_visit_to_topic
|
||||
@@ -1377,8 +1377,7 @@ class TopicsController < ApplicationController
|
||||
|
||||
helpers.localize_topic_view_content(@topic_view) if SiteSetting.content_localization_enabled
|
||||
@breadcrumbs = helpers.categories_breadcrumb(@topic_view.topic) || []
|
||||
@description_meta =
|
||||
@topic_view.topic.excerpt.present? ? @topic_view.topic.excerpt : @topic_view.summary
|
||||
@description_meta = (@topic_view.topic.excerpt.presence || @topic_view.summary)
|
||||
store_preloaded("topic_#{@topic_view.topic.id}", MultiJson.dump(topic_view_serializer))
|
||||
render :show
|
||||
end
|
||||
|
||||
@@ -53,7 +53,7 @@ class UploadsController < ApplicationController
|
||||
SiteSetting.discourse_connect_overrides_avatar || SiteSetting.auth_overrides_avatar ||
|
||||
!me.in_any_groups?(SiteSetting.uploaded_avatars_allowed_groups_map)
|
||||
)
|
||||
return render json: failed_json, status: 422
|
||||
return render json: failed_json, status: :unprocessable_entity
|
||||
end
|
||||
|
||||
url = params[:url]
|
||||
@@ -81,7 +81,8 @@ class UploadsController < ApplicationController
|
||||
retain_hours: retain_hours,
|
||||
)
|
||||
rescue => e
|
||||
render json: failed_json.merge(message: e.message&.split("\n")&.first), status: 422
|
||||
render json: failed_json.merge(message: e.message&.split("\n")&.first),
|
||||
status: :unprocessable_entity
|
||||
else
|
||||
render json: UploadsController.serialize_upload(info), status: Upload === info ? 200 : 422
|
||||
end
|
||||
|
||||
@@ -87,7 +87,7 @@ class UserApiKeysController < ApplicationController
|
||||
api: AUTH_API_VERSION,
|
||||
}.to_json
|
||||
|
||||
public_key_str = @client.public_key.present? ? @client.public_key : params[:public_key]
|
||||
public_key_str = (@client.public_key.presence || params[:public_key])
|
||||
public_key = OpenSSL::PKey::RSA.new(public_key_str)
|
||||
|
||||
# by default, Ruby uses `PKCS1_PADDING` here
|
||||
|
||||
@@ -81,7 +81,7 @@ class UserBadgesController < ApplicationController
|
||||
params.require(:username)
|
||||
user = fetch_user_from_params
|
||||
|
||||
return render json: failed_json, status: 403 unless can_assign_badge_to_user?(user)
|
||||
return render json: failed_json, status: :forbidden unless can_assign_badge_to_user?(user)
|
||||
|
||||
badge = fetch_badge_from_params
|
||||
post_id = nil
|
||||
@@ -90,7 +90,7 @@ class UserBadgesController < ApplicationController
|
||||
unless is_badge_reason_valid? params[:reason]
|
||||
return(
|
||||
render json: failed_json.merge(message: I18n.t("invalid_grant_badge_reason_link")),
|
||||
status: 400
|
||||
status: :bad_request
|
||||
)
|
||||
end
|
||||
|
||||
@@ -120,7 +120,7 @@ class UserBadgesController < ApplicationController
|
||||
user_badge = UserBadge.find(params[:id])
|
||||
|
||||
unless can_assign_badge_to_user?(user_badge.user)
|
||||
render json: failed_json, status: 403
|
||||
render json: failed_json, status: :forbidden
|
||||
return
|
||||
end
|
||||
|
||||
@@ -133,14 +133,14 @@ class UserBadgesController < ApplicationController
|
||||
user_badge = UserBadge.find(params[:user_badge_id])
|
||||
user_badges = user_badge.user.user_badges
|
||||
|
||||
return render json: failed_json, status: 403 unless can_favorite_badge?(user_badge)
|
||||
return render json: failed_json, status: :forbidden unless can_favorite_badge?(user_badge)
|
||||
|
||||
is_favorite = user_badges.where(badge: user_badge.badge, is_favorite: true).exists?
|
||||
|
||||
if !is_favorite &&
|
||||
user_badges.select(:badge_id).distinct.where(is_favorite: true).count >=
|
||||
SiteSetting.max_favorite_badges
|
||||
return render json: failed_json, status: 400
|
||||
return render json: failed_json, status: :bad_request
|
||||
end
|
||||
|
||||
UserBadge.where(user_id: user_badge.user_id, badge_id: user_badge.badge_id).update_all(
|
||||
|
||||
@@ -10,11 +10,11 @@ class Users::DiscourseIdController < ApplicationController
|
||||
on_success { render json: { success: true } }
|
||||
on_failed_contract do |contract|
|
||||
logger.warn(result.inspect_steps) if SiteSetting.discourse_id_verbose_logging
|
||||
render json: { error: contract.errors.full_messages.join(", ") }, status: 400
|
||||
render json: { error: contract.errors.full_messages.join(", ") }, status: :bad_request
|
||||
end
|
||||
on_failure do
|
||||
logger.warn(result.inspect_steps) if SiteSetting.discourse_id_verbose_logging
|
||||
render json: { error: "Invalid request" }, status: 400
|
||||
render json: { error: "Invalid request" }, status: :bad_request
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -104,7 +104,7 @@ class Users::OmniauthCallbacksController < ApplicationController
|
||||
true
|
||||
end
|
||||
|
||||
ALLOWED_FAILURE_ERRORS = %w[csrf_detected request_error invalid_iat].to_h { [_1, _1] }
|
||||
ALLOWED_FAILURE_ERRORS = %w[csrf_detected request_error invalid_iat].index_by { _1 }
|
||||
|
||||
def failure
|
||||
error_name = params[:message].to_s.gsub(/[^\w-]/, "").presence
|
||||
|
||||
@@ -288,7 +288,7 @@ class UsersController < ApplicationController
|
||||
if current_user&.staff?
|
||||
render_json_error(I18n.t("errors.messages.auth_overrides_username"))
|
||||
else
|
||||
render json: failed_json, status: 403
|
||||
render json: failed_json, status: :forbidden
|
||||
end
|
||||
end
|
||||
|
||||
@@ -310,7 +310,7 @@ class UsersController < ApplicationController
|
||||
associated_accounts: user.associated_accounts,
|
||||
}
|
||||
rescue Discourse::InvalidAccess
|
||||
render json: failed_json, status: 403
|
||||
render json: failed_json, status: :forbidden
|
||||
end
|
||||
|
||||
def check_sso_email
|
||||
@@ -326,7 +326,7 @@ class UsersController < ApplicationController
|
||||
|
||||
render json: { email: email }
|
||||
rescue Discourse::InvalidAccess
|
||||
render json: failed_json, status: 403
|
||||
render json: failed_json, status: :forbidden
|
||||
end
|
||||
|
||||
def check_sso_payload
|
||||
@@ -342,11 +342,11 @@ class UsersController < ApplicationController
|
||||
|
||||
render json: { payload: payload }
|
||||
rescue Discourse::InvalidAccess
|
||||
render json: failed_json, status: 403
|
||||
render json: failed_json, status: :forbidden
|
||||
end
|
||||
|
||||
def update_primary_email
|
||||
return render json: failed_json, status: 410 if !SiteSetting.enable_secondary_emails
|
||||
return render json: failed_json, status: :gone if !SiteSetting.enable_secondary_emails
|
||||
|
||||
params.require(:email)
|
||||
|
||||
@@ -359,7 +359,8 @@ class UsersController < ApplicationController
|
||||
new_primary = user.user_emails.find_by(email: params[:email])
|
||||
if new_primary.blank?
|
||||
return(
|
||||
render json: failed_json.merge(errors: [I18n.t("change_email.doesnt_exist")]), status: 428
|
||||
render json: failed_json.merge(errors: [I18n.t("change_email.doesnt_exist")]),
|
||||
status: :precondition_required
|
||||
)
|
||||
end
|
||||
|
||||
@@ -379,7 +380,7 @@ class UsersController < ApplicationController
|
||||
end
|
||||
|
||||
def destroy_email
|
||||
return render json: failed_json, status: 410 if !SiteSetting.enable_secondary_emails
|
||||
return render json: failed_json, status: :gone if !SiteSetting.enable_secondary_emails
|
||||
|
||||
params.require(:email)
|
||||
|
||||
@@ -392,7 +393,7 @@ class UsersController < ApplicationController
|
||||
elsif user.user_emails.where(email: params[:email], primary: false).destroy_all.present?
|
||||
DiscourseEvent.trigger(:user_updated, user)
|
||||
else
|
||||
return render json: failed_json, status: 428
|
||||
return render json: failed_json, status: :precondition_required
|
||||
end
|
||||
|
||||
if current_user.staff? && current_user != user
|
||||
@@ -1075,7 +1076,7 @@ class UsersController < ApplicationController
|
||||
log_on_user(user)
|
||||
render json: success_json
|
||||
else
|
||||
render json: failed_json, status: 403
|
||||
render json: failed_json, status: :forbidden
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1324,23 +1325,23 @@ class UsersController < ApplicationController
|
||||
guardian.ensure_can_edit!(user)
|
||||
|
||||
if SiteSetting.discourse_connect_overrides_avatar || SiteSetting.auth_overrides_avatar
|
||||
return render json: failed_json, status: 422
|
||||
return render json: failed_json, status: :unprocessable_entity
|
||||
end
|
||||
|
||||
type = params[:type]
|
||||
|
||||
if type == "gravatar" && !SiteSetting.gravatar_enabled?
|
||||
return render json: failed_json, status: 422
|
||||
return render json: failed_json, status: :unprocessable_entity
|
||||
end
|
||||
|
||||
invalid_type = type.present? && !AVATAR_TYPES_WITH_UPLOAD.include?(type) && type != "system"
|
||||
return render json: failed_json, status: 422 if invalid_type
|
||||
return render json: failed_json, status: :unprocessable_entity if invalid_type
|
||||
|
||||
if type.blank? || type == "system"
|
||||
upload_id = nil
|
||||
elsif !user.in_any_groups?(SiteSetting.uploaded_avatars_allowed_groups_map) &&
|
||||
!user.is_system_user?
|
||||
return render json: failed_json, status: 422
|
||||
return render json: failed_json, status: :unprocessable_entity
|
||||
else
|
||||
upload_id = params[:upload_id]
|
||||
upload = Upload.find_by(id: upload_id)
|
||||
@@ -1374,19 +1375,23 @@ class UsersController < ApplicationController
|
||||
|
||||
url = params[:url]
|
||||
|
||||
return render json: failed_json, status: 422 if url.blank?
|
||||
return render json: failed_json, status: :unprocessable_entity if url.blank?
|
||||
|
||||
if SiteSetting.selectable_avatars_mode == "disabled"
|
||||
return render json: failed_json, status: 422
|
||||
return render json: failed_json, status: :unprocessable_entity
|
||||
end
|
||||
|
||||
return render json: failed_json, status: 422 if SiteSetting.selectable_avatars.blank?
|
||||
if SiteSetting.selectable_avatars.blank?
|
||||
return render json: failed_json, status: :unprocessable_entity
|
||||
end
|
||||
|
||||
unless upload = Upload.get_from_url(url)
|
||||
return render json: failed_json, status: 422
|
||||
return render json: failed_json, status: :unprocessable_entity
|
||||
end
|
||||
|
||||
return render json: failed_json, status: 422 if SiteSetting.selectable_avatars.exclude?(upload)
|
||||
if SiteSetting.selectable_avatars.exclude?(upload)
|
||||
return render json: failed_json, status: :unprocessable_entity
|
||||
end
|
||||
|
||||
user.uploaded_avatar_id = upload.id
|
||||
|
||||
@@ -1494,7 +1499,7 @@ class UsersController < ApplicationController
|
||||
if !SiteSetting.log_search_queries
|
||||
return(
|
||||
render json: failed_json.merge(error: I18n.t("user_activity.no_log_search_queries")),
|
||||
status: 403
|
||||
status: :forbidden
|
||||
)
|
||||
end
|
||||
|
||||
@@ -1722,7 +1727,7 @@ class UsersController < ApplicationController
|
||||
user_security_key = current_user.security_keys.find_by(id: params[:id].to_i)
|
||||
raise Discourse::InvalidParameters unless user_security_key
|
||||
|
||||
user_security_key.update!(name: params[:name]) if params[:name] && !params[:name].blank?
|
||||
user_security_key.update!(name: params[:name]) if params[:name] && params[:name].present?
|
||||
user_security_key.update!(enabled: false) if params[:disable] == "true"
|
||||
|
||||
render json: success_json
|
||||
@@ -1743,7 +1748,7 @@ class UsersController < ApplicationController
|
||||
rate_limit_second_factor!(current_user)
|
||||
|
||||
authenticated =
|
||||
!auth_token.blank? &&
|
||||
auth_token.present? &&
|
||||
totp_object.verify(
|
||||
auth_token,
|
||||
drift_ahead: SecondFactorManager::TOTP_ALLOWED_DRIFT_SECONDS,
|
||||
@@ -1784,7 +1789,7 @@ class UsersController < ApplicationController
|
||||
|
||||
raise Discourse::InvalidParameters unless user_second_factor
|
||||
|
||||
user_second_factor.update!(name: params[:name]) if params[:name] && !params[:name].blank?
|
||||
user_second_factor.update!(name: params[:name]) if params[:name] && params[:name].present?
|
||||
if params[:disable] == "true"
|
||||
# Disabling backup codes deletes *all* backup codes
|
||||
if update_second_factor_method == UserSecondFactor.methods[:backup_codes]
|
||||
|
||||
@@ -18,7 +18,7 @@ class UsersEmailController < ApplicationController
|
||||
end
|
||||
|
||||
def create
|
||||
return render json: failed_json, status: 410 if !SiteSetting.enable_secondary_emails
|
||||
return render json: failed_json, status: :gone if !SiteSetting.enable_secondary_emails
|
||||
|
||||
params.require(:email)
|
||||
user = fetch_user_from_params
|
||||
@@ -65,7 +65,7 @@ class UsersEmailController < ApplicationController
|
||||
updater.user.user_stat.reset_bounce_score!
|
||||
render json: success_json
|
||||
else
|
||||
render json: { error: I18n.t("change_email.already_done") }, status: 400
|
||||
render json: { error: I18n.t("change_email.already_done") }, status: :bad_request
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -89,7 +89,7 @@ class UsersEmailController < ApplicationController
|
||||
if updater.confirm(params[:token]) == :authorizing_new
|
||||
render json: success_json
|
||||
else
|
||||
render json: { error: I18n.t("change_email.already_done") }, status: 400
|
||||
render json: { error: I18n.t("change_email.already_done") }, status: :bad_request
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -202,11 +202,11 @@ class WebhooksController < ActionController::Base
|
||||
private
|
||||
|
||||
def signature_failure
|
||||
render body: nil, status: 406
|
||||
render body: nil, status: :not_acceptable
|
||||
end
|
||||
|
||||
def success
|
||||
render body: nil, status: 200
|
||||
render body: nil, status: :ok
|
||||
end
|
||||
|
||||
def valid_mailgun_signature?(token, timestamp, signature)
|
||||
|
||||
@@ -360,14 +360,7 @@ module ApplicationHelper
|
||||
end
|
||||
|
||||
private def generate_twitter_card_metadata(result, opts)
|
||||
img_url =
|
||||
(
|
||||
if opts[:x_summary_large_image].present?
|
||||
opts[:x_summary_large_image]
|
||||
else
|
||||
opts[:image]
|
||||
end
|
||||
)
|
||||
img_url = (opts[:x_summary_large_image].presence || opts[:image])
|
||||
|
||||
# Twitter does not allow SVGs, see https://developer.twitter.com/en/docs/twitter-for-websites/cards/overview/markup
|
||||
if img_url.ends_with?(".svg")
|
||||
|
||||
@@ -17,7 +17,7 @@ module EmbedHelper
|
||||
|
||||
def get_html(post)
|
||||
key = "js.action_codes.#{post.action_code}"
|
||||
cooked = post.cooked.blank? ? I18n.t(key, when: nil).humanize : post.cooked
|
||||
cooked = (post.cooked.presence || I18n.t(key, when: nil).humanize)
|
||||
|
||||
raw PrettyText.format_for_email(cooked, post)
|
||||
end
|
||||
|
||||
+1
-1
@@ -423,7 +423,7 @@ module Jobs
|
||||
|
||||
DB.after_commit { klass.client_push(hash) }
|
||||
else
|
||||
if Rails.env == "development"
|
||||
if Rails.env.development?
|
||||
Scheduler::Defer.later("job") { klass.new.perform(opts) }
|
||||
else
|
||||
# Run the job synchronously
|
||||
|
||||
@@ -15,9 +15,7 @@ module Skippable
|
||||
if reason_type == SkippedEmailLog.reason_types[:exceeded_emails_limit]
|
||||
exists =
|
||||
SkippedEmailLog.exists?(
|
||||
{ created_at: (Time.zone.now.beginning_of_day..Time.zone.now.end_of_day) }.merge!(
|
||||
attributes.except(:post_id),
|
||||
),
|
||||
{ created_at: (Time.zone.now.all_day) }.merge!(attributes.except(:post_id)),
|
||||
)
|
||||
|
||||
return if exists
|
||||
|
||||
@@ -11,7 +11,7 @@ module Jobs
|
||||
attr_accessor :entity
|
||||
|
||||
HEADER_ATTRS_FOR =
|
||||
HashWithIndifferentAccess.new(
|
||||
ActiveSupport::HashWithIndifferentAccess.new(
|
||||
user_list: %w[
|
||||
id
|
||||
name
|
||||
@@ -60,7 +60,7 @@ module Jobs
|
||||
|
||||
def execute(args)
|
||||
@entity = args[:entity]
|
||||
@extra = HashWithIndifferentAccess.new(args[:args]) if args[:args]
|
||||
@extra = ActiveSupport::HashWithIndifferentAccess.new(args[:args]) if args[:args]
|
||||
@current_user = User.find_by(id: args[:user_id])
|
||||
|
||||
entity = { name: @entity }
|
||||
|
||||
@@ -26,7 +26,7 @@ module Jobs
|
||||
]
|
||||
|
||||
HEADER_ATTRS_FOR =
|
||||
HashWithIndifferentAccess.new(
|
||||
ActiveSupport::HashWithIndifferentAccess.new(
|
||||
user_archive: %w[
|
||||
topic_title
|
||||
categories
|
||||
@@ -130,7 +130,7 @@ module Jobs
|
||||
@requesting_user = @archive_for_user
|
||||
end
|
||||
|
||||
@extra = HashWithIndifferentAccess.new(args[:args]) if args[:args]
|
||||
@extra = ActiveSupport::HashWithIndifferentAccess.new(args[:args]) if args[:args]
|
||||
@timestamp ||= Time.now.strftime("%y%m%d-%H%M%S")
|
||||
|
||||
components = []
|
||||
|
||||
@@ -4,7 +4,15 @@ module Jobs
|
||||
class NotifyMailingListSubscribers < ::Jobs::Base
|
||||
include Skippable
|
||||
|
||||
RETRY_TIMES = [5.minute, 15.minute, 30.minute, 45.minute, 90.minute, 180.minute, 300.minute]
|
||||
RETRY_TIMES = [
|
||||
5.minutes,
|
||||
15.minutes,
|
||||
30.minutes,
|
||||
45.minutes,
|
||||
90.minutes,
|
||||
180.minutes,
|
||||
300.minutes,
|
||||
]
|
||||
|
||||
sidekiq_options queue: "low"
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ module Jobs
|
||||
post = Post.find_by(id: @post_id)
|
||||
return if post.nil? || post.topic.nil?
|
||||
|
||||
hotlinked_map = post.post_hotlinked_media.map { |r| [r.url, r] }.to_h
|
||||
hotlinked_map = post.post_hotlinked_media.index_by { |r| r.url }
|
||||
|
||||
changed_hotlink_records = false
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ module Jobs
|
||||
return if post.cook_method == Post.cook_methods[:raw_html]
|
||||
return if post.topic.nil?
|
||||
|
||||
hotlinked_map = post.post_hotlinked_media.preload(:upload).map { |r| [r.url, r] }.to_h
|
||||
hotlinked_map = post.post_hotlinked_media.preload(:upload).index_by { |r| r.url }
|
||||
|
||||
raw =
|
||||
InlineUploads.replace_hotlinked_image_urls(raw: post.raw) do |match_src|
|
||||
|
||||
@@ -5,7 +5,7 @@ module Jobs
|
||||
every 1.day
|
||||
|
||||
def execute(args = {})
|
||||
date = args[:date].present? ? args[:date] : Time.zone.now.to_date
|
||||
date = (args[:date].presence || Time.zone.now.to_date)
|
||||
WebHook
|
||||
.joins(
|
||||
"LEFT JOIN web_hook_events_daily_aggregates ON web_hooks.id = web_hook_events_daily_aggregates.web_hook_id AND web_hook_events_daily_aggregates.date = '#{date}'",
|
||||
|
||||
@@ -9,7 +9,7 @@ module Jobs
|
||||
def execute(args)
|
||||
RedeliveringWebhookEvent
|
||||
.includes(web_hook_event: :web_hook)
|
||||
.where("created_at < ?", 8.hour.ago)
|
||||
.where("created_at < ?", 8.hours.ago)
|
||||
.delete_all
|
||||
end
|
||||
end
|
||||
|
||||
@@ -67,9 +67,11 @@ module Jobs
|
||||
|
||||
def keys_list
|
||||
messages =
|
||||
old_site_settings_keys.map { |key| "#{key.name} - #{key.updated_at.to_date.to_fs(:db)}" }
|
||||
old_site_settings_keys.map do |key|
|
||||
"#{key.name} - #{key.updated_at.to_date.to_formatted_s(:db)}"
|
||||
end
|
||||
old_api_keys.each_with_object(messages) do |key, array|
|
||||
array << "#{[key.description, key.user&.username, key.created_at.to_date.to_fs(:db)].compact.join(" - ")}"
|
||||
array << "#{[key.description, key.user&.username, key.created_at.to_date.to_formatted_s(:db)].compact.join(" - ")}"
|
||||
end
|
||||
messages.join("\n")
|
||||
end
|
||||
|
||||
@@ -8,7 +8,7 @@ module Jobs
|
||||
|
||||
def execute(args)
|
||||
if SiteSetting.top_menu_map.include?("hot") ||
|
||||
Discourse.redis.set(HOT_SCORE_UPDATE_REDIS_KEY, 1, ex: 6.hour, nx: true)
|
||||
Discourse.redis.set(HOT_SCORE_UPDATE_REDIS_KEY, 1, ex: 6.hours, nx: true)
|
||||
TopicHotScore.update_scores
|
||||
end
|
||||
end
|
||||
|
||||
@@ -75,7 +75,7 @@ class UserNotifications < ActionMailer::Base
|
||||
template: "user_notifications.suspicious_login",
|
||||
locale: user_locale(user),
|
||||
client_ip: opts[:client_ip],
|
||||
location: location.present? ? location : I18n.t("staff_action_logs.unknown"),
|
||||
location: (location.presence || I18n.t("staff_action_logs.unknown")),
|
||||
browser: I18n.t("user_auth_tokens.browser.#{browser}"),
|
||||
device: I18n.t("user_auth_tokens.device.#{device}"),
|
||||
os: I18n.t("user_auth_tokens.os.#{os}"),
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class ApiKeyScope < ActiveRecord::Base
|
||||
validates_presence_of :resource
|
||||
validates_presence_of :action
|
||||
validates :resource, presence: true
|
||||
validates :action, presence: true
|
||||
|
||||
class << self
|
||||
def list_actions
|
||||
|
||||
@@ -48,7 +48,7 @@ class ApplicationRequest < ActiveRecord::Base
|
||||
end
|
||||
|
||||
def self.stats
|
||||
s = HashWithIndifferentAccess.new({})
|
||||
s = ActiveSupport::HashWithIndifferentAccess.new({})
|
||||
|
||||
self.req_types.each do |key, i|
|
||||
query = self.where(req_type: i)
|
||||
|
||||
+1
-1
@@ -121,8 +121,8 @@ class Badge < ActiveRecord::Base
|
||||
|
||||
scope :enabled, -> { where(enabled: true) }
|
||||
|
||||
before_create :ensure_not_system
|
||||
before_save :sanitize_description
|
||||
before_create :ensure_not_system
|
||||
|
||||
after_save do
|
||||
if saved_change_to_image_upload_id?
|
||||
|
||||
+12
-16
@@ -107,15 +107,22 @@ class Category < ActiveRecord::Base
|
||||
validates :color, format: { with: /\A(\h{6}|\h{3})\z/ }
|
||||
validates :text_color, format: { with: /\A(\h{6}|\h{3})\z/ }
|
||||
|
||||
after_create :create_category_definition
|
||||
after_destroy :trash_category_definition
|
||||
after_destroy :clear_related_site_settings
|
||||
|
||||
before_save :apply_permissions
|
||||
before_save :downcase_email
|
||||
before_save :downcase_name
|
||||
before_save :ensure_category_setting
|
||||
after_create :create_category_definition
|
||||
after_create :delete_category_permalink
|
||||
after_update :rename_category_definition, if: :saved_change_to_name?
|
||||
after_update :create_category_permalink, if: :saved_change_to_slug?
|
||||
after_update :run_plugin_category_update_param_callbacks
|
||||
after_destroy :trash_category_definition
|
||||
after_destroy :clear_related_site_settings
|
||||
|
||||
after_destroy :reset_topic_ids_cache
|
||||
after_destroy :clear_subcategory_ids
|
||||
after_destroy :publish_category_deletion
|
||||
after_destroy :remove_site_settings
|
||||
after_save :reset_topic_ids_cache
|
||||
after_save :clear_subcategory_ids
|
||||
after_save :clear_url_cache
|
||||
@@ -135,17 +142,6 @@ class Category < ActiveRecord::Base
|
||||
end
|
||||
end
|
||||
|
||||
after_destroy :reset_topic_ids_cache
|
||||
after_destroy :clear_subcategory_ids
|
||||
after_destroy :publish_category_deletion
|
||||
after_destroy :remove_site_settings
|
||||
|
||||
after_create :delete_category_permalink
|
||||
|
||||
after_update :rename_category_definition, if: :saved_change_to_name?
|
||||
after_update :create_category_permalink, if: :saved_change_to_slug?
|
||||
after_update :run_plugin_category_update_param_callbacks
|
||||
|
||||
after_commit :trigger_category_created_event, on: :create
|
||||
after_commit :trigger_category_updated_event, on: :update
|
||||
after_commit :trigger_category_destroyed_event, on: :destroy
|
||||
@@ -638,7 +634,7 @@ class Category < ActiveRecord::Base
|
||||
|
||||
def topic_url
|
||||
if has_attribute?("topic_slug")
|
||||
Topic.relative_url(topic_id, read_attribute(:topic_slug))
|
||||
Topic.relative_url(topic_id, self[:topic_slug])
|
||||
else
|
||||
topic_only_relative_url.try(:relative_url)
|
||||
end
|
||||
|
||||
@@ -228,9 +228,7 @@ class CategoryUser < ActiveRecord::Base
|
||||
end
|
||||
|
||||
def self.create_lookup(category_users)
|
||||
category_users.each_with_object({}) do |category_user, acc|
|
||||
acc[category_user.category_id] = category_user
|
||||
end
|
||||
category_users.index_by(&:category_id)
|
||||
end
|
||||
|
||||
def self.muted_category_ids_query(user, include_direct: false)
|
||||
|
||||
@@ -346,7 +346,7 @@ module HasCustomFields
|
||||
protected
|
||||
|
||||
def refresh_custom_fields_from_db
|
||||
target = HashWithIndifferentAccess.new
|
||||
target = ActiveSupport::HashWithIndifferentAccess.new
|
||||
_custom_fields
|
||||
.order(:id)
|
||||
.pluck(:name, :value)
|
||||
|
||||
@@ -7,6 +7,6 @@ module HasSearchData
|
||||
_associated_record_name = self.name.sub("SearchData", "").underscore
|
||||
self.primary_key = "#{_associated_record_name}_id"
|
||||
belongs_to _associated_record_name.to_sym
|
||||
validates_presence_of :search_data
|
||||
validates :search_data, presence: true
|
||||
end
|
||||
end
|
||||
|
||||
@@ -46,7 +46,7 @@ module SecondFactorManager
|
||||
last_used = totp.last_used.to_i if totp.last_used
|
||||
|
||||
authenticated =
|
||||
!token.blank? &&
|
||||
token.present? &&
|
||||
totp.totp_object.verify(
|
||||
token,
|
||||
drift_ahead: TOTP_ALLOWED_DRIFT_SECONDS,
|
||||
@@ -243,7 +243,7 @@ module SecondFactorManager
|
||||
end
|
||||
|
||||
def authenticate_backup_code(backup_code)
|
||||
if !backup_code.blank?
|
||||
if backup_code.present?
|
||||
codes = self.user_second_factors&.backup_codes
|
||||
|
||||
codes.each do |code|
|
||||
|
||||
@@ -3,8 +3,8 @@
|
||||
class Developer < ActiveRecord::Base
|
||||
belongs_to :user
|
||||
|
||||
after_save :rebuild_cache
|
||||
after_destroy :rebuild_cache
|
||||
after_save :rebuild_cache
|
||||
|
||||
def self.id_cache
|
||||
@id_cache ||= DistributedCache.new("developer_ids")
|
||||
|
||||
@@ -349,7 +349,7 @@ class DiscourseConnect < DiscourseConnectBase
|
||||
end
|
||||
|
||||
if SiteSetting.auth_overrides_name && user.name != name && name.present?
|
||||
user.name = name || User.suggest_name(username.blank? ? email : username)
|
||||
user.name = name || User.suggest_name(username.presence || email)
|
||||
end
|
||||
|
||||
if locale_force_update && SiteSetting.allow_user_locale && locale.present? &&
|
||||
|
||||
@@ -45,7 +45,7 @@ class GlobalSetting
|
||||
end
|
||||
end
|
||||
end
|
||||
if !secret_key_base.blank? && token != secret_key_base
|
||||
if secret_key_base.present? && token != secret_key_base
|
||||
STDERR.puts "WARNING: DISCOURSE_SECRET_KEY_BASE is invalid, it was re-generated"
|
||||
end
|
||||
token
|
||||
@@ -219,7 +219,7 @@ class GlobalSetting
|
||||
c[:username] = redis_username if redis_username.present?
|
||||
c[:password] = redis_password if redis_password.present?
|
||||
c[:db] = redis_db if redis_db != 0
|
||||
c[:db] = 1 if Rails.env == "test"
|
||||
c[:db] = 1 if Rails.env.test?
|
||||
c[:id] = nil if redis_skip_client_commands
|
||||
c[:ssl] = true if redis_use_ssl
|
||||
|
||||
@@ -246,7 +246,7 @@ class GlobalSetting
|
||||
c[:username] = message_bus_redis_username if message_bus_redis_username.present?
|
||||
c[:password] = message_bus_redis_password if message_bus_redis_password.present?
|
||||
c[:db] = message_bus_redis_db if message_bus_redis_db != 0
|
||||
c[:db] = 1 if Rails.env == "test"
|
||||
c[:db] = 1 if Rails.env.test?
|
||||
c[:id] = nil if message_bus_redis_skip_client_commands
|
||||
c[:ssl] = true if redis_use_ssl
|
||||
|
||||
@@ -293,13 +293,7 @@ class GlobalSetting
|
||||
end
|
||||
|
||||
def resolve(current, default)
|
||||
BaseProvider.coerce(
|
||||
if current.present?
|
||||
current
|
||||
else
|
||||
default.present? ? default : nil
|
||||
end,
|
||||
)
|
||||
BaseProvider.coerce(current.presence || default.presence)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -373,7 +367,7 @@ class GlobalSetting
|
||||
end
|
||||
|
||||
def self.configure!
|
||||
if Rails.env == "test"
|
||||
if Rails.env.test?
|
||||
@provider = BlankProvider.new
|
||||
else
|
||||
@provider =
|
||||
|
||||
+3
-3
@@ -50,6 +50,8 @@ class Group < ActiveRecord::Base
|
||||
before_save :downcase_incoming_email
|
||||
before_save :cook_bio
|
||||
|
||||
before_destroy :cache_group_users_for_destroyed_event, prepend: true
|
||||
after_destroy :expire_cache
|
||||
after_save :destroy_deletions
|
||||
after_save :update_primary_group
|
||||
after_save :update_title
|
||||
@@ -64,12 +66,10 @@ class Group < ActiveRecord::Base
|
||||
end
|
||||
|
||||
after_save :expire_cache
|
||||
after_destroy :expire_cache
|
||||
|
||||
after_commit :automatic_group_membership, on: %i[create update]
|
||||
after_commit :trigger_group_created_event, on: :create
|
||||
after_commit :trigger_group_updated_event, on: :update
|
||||
before_destroy :cache_group_users_for_destroyed_event, prepend: true
|
||||
after_commit :trigger_group_destroyed_event, on: :destroy
|
||||
after_commit :set_default_notifications, on: %i[create update]
|
||||
|
||||
@@ -348,7 +348,7 @@ class Group < ActiveRecord::Base
|
||||
end
|
||||
|
||||
def smtp_from_address
|
||||
self.email_from_alias.present? ? self.email_from_alias : self.email_username
|
||||
email_from_alias.presence || email_username
|
||||
end
|
||||
|
||||
def downcase_incoming_email
|
||||
|
||||
@@ -3,8 +3,8 @@ class GroupAssociatedGroup < ActiveRecord::Base
|
||||
belongs_to :group
|
||||
belongs_to :associated_group
|
||||
|
||||
after_commit :add_associated_users, on: %i[create update]
|
||||
before_destroy :remove_associated_users
|
||||
after_commit :add_associated_users, on: %i[create update]
|
||||
|
||||
def add_associated_users
|
||||
with_mutex do
|
||||
|
||||
@@ -31,7 +31,7 @@ class GroupHistory < ActiveRecord::Base
|
||||
.where(group_id: group.id)
|
||||
.order("group_histories.created_at DESC")
|
||||
|
||||
if !params.blank?
|
||||
if params.present?
|
||||
params = params.slice(*filters)
|
||||
records = records.where(action: self.actions[params[:action].to_sym]) if params[
|
||||
:action
|
||||
|
||||
@@ -4,13 +4,13 @@ class GroupUser < ActiveRecord::Base
|
||||
belongs_to :group
|
||||
belongs_to :user
|
||||
|
||||
after_save :update_title
|
||||
before_create :set_notification_level
|
||||
after_destroy :grant_other_available_title
|
||||
after_destroy :remove_primary_and_flair_group, :recalculate_trust_level
|
||||
after_save :update_title
|
||||
|
||||
after_save :set_primary_group
|
||||
after_destroy :remove_primary_and_flair_group, :recalculate_trust_level
|
||||
|
||||
before_create :set_notification_level
|
||||
after_save :grant_trust_level
|
||||
after_save :set_category_notifications
|
||||
after_save :set_tag_notifications
|
||||
|
||||
@@ -31,7 +31,7 @@ class Invite < ActiveRecord::Base
|
||||
has_many :topic_invites
|
||||
has_many :topics, through: :topic_invites, source: :topic
|
||||
|
||||
validates_presence_of :invited_by_id
|
||||
validates :invited_by_id, presence: true
|
||||
validates :email, email: true, allow_blank: true
|
||||
validates :custom_message, length: { maximum: 1000 }
|
||||
validates :domain, length: { maximum: 500 }
|
||||
|
||||
@@ -4,8 +4,8 @@ class InvitedUser < ActiveRecord::Base
|
||||
belongs_to :user
|
||||
belongs_to :invite, -> { unscope(where: :deleted_at) }
|
||||
|
||||
validates_presence_of :invite_id
|
||||
validates_uniqueness_of :invite_id, scope: :user_id, conditions: -> { where.not(user_id: nil) }
|
||||
validates :invite_id, presence: true
|
||||
validates :invite_id, uniqueness: { scope: :user_id, conditions: -> { where.not(user_id: nil) } }
|
||||
end
|
||||
|
||||
# == Schema Information
|
||||
|
||||
@@ -11,8 +11,8 @@ class Notification < ActiveRecord::Base
|
||||
|
||||
MEMBERSHIP_REQUEST_CONSOLIDATION_WINDOW_HOURS = 24
|
||||
|
||||
validates_presence_of :data
|
||||
validates_presence_of :notification_type
|
||||
validates :data, presence: true
|
||||
validates :notification_type, presence: true
|
||||
|
||||
scope :unread, lambda { where(read: false) }
|
||||
scope :recent,
|
||||
|
||||
@@ -178,7 +178,7 @@ class OptimizedImage < ActiveRecord::Base
|
||||
else
|
||||
size = calculate_filesize
|
||||
|
||||
write_attribute(:filesize, size)
|
||||
self[:filesize] = size
|
||||
update_columns(filesize: size) if !new_record?
|
||||
size
|
||||
end
|
||||
|
||||
+2
-2
@@ -1051,7 +1051,7 @@ class Post < ActiveRecord::Base
|
||||
post_revision = PostRevision.find_by(post_id: id, number: (number + 1))
|
||||
post_revision.modifications.each do |attribute, change|
|
||||
attribute = "version" if attribute == "cached_version"
|
||||
write_attribute(attribute, change[0])
|
||||
self[attribute] = change[0]
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1342,7 +1342,7 @@ class Post < ActiveRecord::Base
|
||||
|
||||
def parse_quote_into_arguments(quote)
|
||||
return {} if quote.blank?
|
||||
args = HashWithIndifferentAccess.new
|
||||
args = ActiveSupport::HashWithIndifferentAccess.new
|
||||
quote.first.scan(/([a-z]+)\:(\d+)/).each { |arg| args[arg[0]] = arg[1].to_i }
|
||||
args
|
||||
end
|
||||
|
||||
@@ -3,8 +3,8 @@
|
||||
class PostDetail < ActiveRecord::Base
|
||||
belongs_to :post
|
||||
|
||||
validates_presence_of :key, :value
|
||||
validates_uniqueness_of :key, scope: :post_id
|
||||
validates :key, :value, presence: true
|
||||
validates :key, uniqueness: { scope: :post_id }
|
||||
end
|
||||
|
||||
# == Schema Information
|
||||
|
||||
@@ -4,7 +4,7 @@ class PostReply < ActiveRecord::Base
|
||||
belongs_to :post
|
||||
belongs_to :reply, foreign_key: :reply_post_id, class_name: "Post"
|
||||
|
||||
validates_uniqueness_of :reply_post_id, scope: :post_id
|
||||
validates :reply_post_id, uniqueness: { scope: :post_id }
|
||||
validate :ensure_same_topic
|
||||
|
||||
private
|
||||
|
||||
@@ -4,8 +4,8 @@ class PostTiming < ActiveRecord::Base
|
||||
belongs_to :topic
|
||||
belongs_to :user
|
||||
|
||||
validates_presence_of :post_number
|
||||
validates_presence_of :msecs
|
||||
validates :post_number, presence: true
|
||||
validates :msecs, presence: true
|
||||
|
||||
def self.pretend_read(topic_id, actual_read_post_number, pretend_read_post_number, user_ids = nil)
|
||||
# This is done in SQL cause the logic is quite tricky and we want to do this in one db hit
|
||||
|
||||
@@ -3,8 +3,8 @@
|
||||
class PublishedPage < ActiveRecord::Base
|
||||
belongs_to :topic
|
||||
|
||||
validates_presence_of :slug
|
||||
validates_uniqueness_of :slug, :topic_id
|
||||
validates :slug, presence: true
|
||||
validates :slug, :topic_id, uniqueness: true
|
||||
|
||||
validate :slug_format
|
||||
def slug_format
|
||||
|
||||
@@ -40,10 +40,12 @@ class RemoteTheme < ActiveRecord::Base
|
||||
)
|
||||
end
|
||||
|
||||
validates_format_of :minimum_discourse_version,
|
||||
:maximum_discourse_version,
|
||||
with: Discourse::VERSION_REGEXP,
|
||||
allow_nil: true
|
||||
validates :minimum_discourse_version,
|
||||
:maximum_discourse_version,
|
||||
format: {
|
||||
with: Discourse::VERSION_REGEXP,
|
||||
allow_nil: true,
|
||||
}
|
||||
|
||||
def self.extract_theme_info(importer)
|
||||
if importer.file_size("about.json") > MAX_METADATA_FILE_SIZE
|
||||
|
||||
@@ -22,7 +22,7 @@ class Reviewable < ActiveRecord::Base
|
||||
end
|
||||
|
||||
attr_accessor :created_new
|
||||
validates_presence_of :type, :status, :created_by_id
|
||||
validates :type, :status, :created_by_id, presence: true
|
||||
belongs_to :target, polymorphic: true
|
||||
belongs_to :created_by, class_name: "User"
|
||||
belongs_to :target_created_by, class_name: "User"
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
class ReviewableClaimedTopic < ActiveRecord::Base
|
||||
belongs_to :topic
|
||||
belongs_to :user
|
||||
validates_uniqueness_of :topic
|
||||
validates :topic, uniqueness: true
|
||||
|
||||
def self.claimed_hash(topic_ids)
|
||||
result = {}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
class SearchLog < ActiveRecord::Base
|
||||
MAXIMUM_USER_AGENT_LENGTH = 2000
|
||||
|
||||
validates_presence_of :term
|
||||
validates :term, presence: true
|
||||
validates :user_agent, length: { maximum: MAXIMUM_USER_AGENT_LENGTH }
|
||||
|
||||
belongs_to :user
|
||||
|
||||
@@ -75,8 +75,8 @@ class SiteSetting < ActiveRecord::Base
|
||||
|
||||
has_many :upload_references, as: :target, dependent: :destroy
|
||||
|
||||
validates_presence_of :name
|
||||
validates_presence_of :data_type
|
||||
validates :name, presence: true
|
||||
validates :data_type, presence: true
|
||||
|
||||
after_save do
|
||||
if saved_change_to_value?
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
class TagGroup < ActiveRecord::Base
|
||||
validates :name, length: { maximum: 100 }
|
||||
validates_uniqueness_of :name, case_sensitive: false
|
||||
validates :name, uniqueness: { case_sensitive: false }
|
||||
|
||||
has_many :tag_group_memberships, dependent: :destroy
|
||||
has_many :tags, through: :tag_group_memberships
|
||||
@@ -17,9 +17,9 @@ class TagGroup < ActiveRecord::Base
|
||||
|
||||
belongs_to :parent_tag, class_name: "Tag"
|
||||
|
||||
before_create :init_permissions
|
||||
before_save :apply_permissions
|
||||
before_save :remove_parent_from_group
|
||||
before_create :init_permissions
|
||||
|
||||
after_commit { DiscourseTagging.clear_cache! }
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ class ThemeModifierSet < ActiveRecord::Base
|
||||
|
||||
def type_validator
|
||||
ThemeModifierSet.modifiers.each do |k, config|
|
||||
value = read_attribute(k)
|
||||
value = self[k]
|
||||
next if value.nil?
|
||||
|
||||
case config[:type]
|
||||
@@ -92,8 +92,8 @@ class ThemeModifierSet < ActiveRecord::Base
|
||||
value =
|
||||
target_setting_name.present? ? target_setting_value : theme.settings[setting_name]&.value
|
||||
value = coerce_setting_value(modifier_name, value)
|
||||
if read_attribute(modifier_name) != value
|
||||
write_attribute(modifier_name, value)
|
||||
if self[modifier_name] != value
|
||||
self[modifier_name] = value
|
||||
changed = true
|
||||
end
|
||||
end
|
||||
|
||||
@@ -10,13 +10,13 @@ class ThemeSetting < ActiveRecord::Base
|
||||
|
||||
MAXIMUM_JSON_VALUE_SIZE_BYTES = 0.5 * 1024 * 1024 # 0.5 MB
|
||||
|
||||
validates_presence_of :name, :theme
|
||||
validates :name, :theme, presence: true
|
||||
validates :data_type, inclusion: { in: TYPES_ENUM.values }
|
||||
validate :json_value_size, if: -> { self.data_type == TYPES_ENUM[:objects] }
|
||||
validates :name, length: { maximum: 255 }
|
||||
|
||||
after_save :clear_settings_cache
|
||||
after_destroy :clear_settings_cache
|
||||
after_save :clear_settings_cache
|
||||
|
||||
after_save do
|
||||
if self.data_type == ThemeSetting.types[:upload] && saved_change_to_value?
|
||||
|
||||
+6
-6
@@ -408,7 +408,7 @@ class Topic < ActiveRecord::Base
|
||||
before_save do
|
||||
ensure_topic_has_a_category unless skip_callbacks
|
||||
|
||||
write_attribute(:fancy_title, Topic.fancy_title(title)) if title_changed?
|
||||
self[:fancy_title] = Topic.fancy_title(title) if title_changed?
|
||||
|
||||
if category_id_changed? || new_record?
|
||||
inherit_auto_close_from_category
|
||||
@@ -537,7 +537,7 @@ class Topic < ActiveRecord::Base
|
||||
|
||||
unless fancy_title = read_attribute(:fancy_title)
|
||||
fancy_title = Topic.fancy_title(title)
|
||||
write_attribute(:fancy_title, fancy_title)
|
||||
self[:fancy_title] = fancy_title
|
||||
|
||||
if !new_record? && !Discourse.readonly_mode?
|
||||
# make sure data is set in table, this also allows us to change algorithm
|
||||
@@ -1461,7 +1461,7 @@ class Topic < ActiveRecord::Base
|
||||
return "" if title.blank?
|
||||
slug = slug_for_topic(title)
|
||||
if new_record?
|
||||
write_attribute(:slug, slug)
|
||||
self[:slug] = slug
|
||||
else
|
||||
update_column(:slug, slug)
|
||||
end
|
||||
@@ -1481,8 +1481,8 @@ class Topic < ActiveRecord::Base
|
||||
|
||||
def title=(t)
|
||||
slug = slug_for_topic(t.to_s)
|
||||
write_attribute(:slug, slug)
|
||||
write_attribute(:fancy_title, nil)
|
||||
self[:slug] = slug
|
||||
self[:fancy_title] = nil
|
||||
write_attribute(:title, t)
|
||||
end
|
||||
|
||||
@@ -1664,7 +1664,7 @@ class Topic < ActiveRecord::Base
|
||||
topic_timer.status_type = status_type
|
||||
|
||||
time_now = Time.zone.now
|
||||
topic_timer.based_on_last_post = !based_on_last_post.blank?
|
||||
topic_timer.based_on_last_post = based_on_last_post.present?
|
||||
|
||||
if status_type == TopicTimer.types[:publish_to_category]
|
||||
topic_timer.category = Category.find_by(id: category_id)
|
||||
|
||||
@@ -4,7 +4,7 @@ class TopicAllowedGroup < ActiveRecord::Base
|
||||
belongs_to :topic
|
||||
belongs_to :group
|
||||
|
||||
validates_uniqueness_of :topic_id, scope: :group_id
|
||||
validates :topic_id, uniqueness: { scope: :group_id }
|
||||
end
|
||||
|
||||
# == Schema Information
|
||||
|
||||
@@ -4,7 +4,7 @@ class TopicAllowedUser < ActiveRecord::Base
|
||||
belongs_to :topic
|
||||
belongs_to :user
|
||||
|
||||
validates_uniqueness_of :topic_id, scope: :user_id
|
||||
validates :topic_id, uniqueness: { scope: :user_id }
|
||||
end
|
||||
|
||||
# == Schema Information
|
||||
|
||||
@@ -7,8 +7,8 @@ class TopicEmbed < ActiveRecord::Base
|
||||
|
||||
belongs_to :topic
|
||||
belongs_to :post
|
||||
validates_presence_of :embed_url
|
||||
validates_uniqueness_of :embed_url
|
||||
validates :embed_url, presence: true
|
||||
validates :embed_url, uniqueness: true
|
||||
validates :embed_content_cache, length: { maximum: EMBED_CONTENT_CACHE_MAX_LENGTH }
|
||||
|
||||
before_validation(on: :create) do
|
||||
|
||||
@@ -4,10 +4,10 @@ class TopicInvite < ActiveRecord::Base
|
||||
belongs_to :topic
|
||||
belongs_to :invite
|
||||
|
||||
validates_presence_of :topic_id
|
||||
validates_presence_of :invite_id
|
||||
validates :topic_id, presence: true
|
||||
validates :invite_id, presence: true
|
||||
|
||||
validates_uniqueness_of :topic_id, scope: :invite_id
|
||||
validates :topic_id, uniqueness: { scope: :invite_id }
|
||||
end
|
||||
|
||||
# == Schema Information
|
||||
|
||||
@@ -17,11 +17,11 @@ class TopicLink < ActiveRecord::Base
|
||||
belongs_to :link_topic, class_name: "Topic"
|
||||
belongs_to :link_post, class_name: "Post"
|
||||
|
||||
validates_presence_of :url
|
||||
validates :url, presence: true
|
||||
|
||||
validates_length_of :url, maximum: 500
|
||||
validates :url, length: { maximum: 500 }
|
||||
|
||||
validates_uniqueness_of :url, scope: %i[topic_id post_id]
|
||||
validates :url, uniqueness: { scope: %i[topic_id post_id] }
|
||||
|
||||
has_many :topic_link_clicks, dependent: :destroy
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ class TopicLinkClick < ActiveRecord::Base
|
||||
belongs_to :topic_link, counter_cache: :clicks
|
||||
belongs_to :user
|
||||
|
||||
validates_presence_of :topic_link_id
|
||||
validates :topic_link_id, presence: true
|
||||
|
||||
ALLOWED_REDIRECT_HOSTNAMES = Set.new(%W[www.youtube.com youtu.be])
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ class TopicViewItem < ActiveRecord::Base
|
||||
self.table_name = "topic_views"
|
||||
belongs_to :user
|
||||
belongs_to :topic
|
||||
validates_presence_of :topic_id, :ip_address, :viewed_at
|
||||
validates :topic_id, :ip_address, :viewed_at, presence: true
|
||||
|
||||
def self.add(topic_id, ip, user_id = nil, at = nil, skip_redis = false)
|
||||
# Only store a view once per day per thing per (user || ip)
|
||||
|
||||
@@ -45,8 +45,8 @@ class TranslationOverride < ActiveRecord::Base
|
||||
|
||||
include HasSanitizableFields
|
||||
|
||||
validates_uniqueness_of :translation_key, scope: :locale
|
||||
validates_presence_of :locale, :translation_key, :value
|
||||
validates :translation_key, uniqueness: { scope: :locale }
|
||||
validates :locale, :translation_key, :value, presence: true
|
||||
|
||||
validate :check_interpolation_keys
|
||||
validate :check_MF_string, if: :message_format?
|
||||
|
||||
@@ -41,9 +41,9 @@ class Upload < ActiveRecord::Base
|
||||
attr_accessor :validate_file_size
|
||||
attr_accessor :skip_video_conversion
|
||||
|
||||
validates_presence_of :filesize
|
||||
validates_presence_of :original_filename
|
||||
validates :dominant_color, length: { is: 6 }, allow_blank: true, allow_nil: true
|
||||
validates :filesize, presence: true
|
||||
validates :original_filename, presence: true
|
||||
validates :dominant_color, length: { is: 6 }, allow_blank: true
|
||||
|
||||
validates_with UploadValidator
|
||||
|
||||
@@ -339,11 +339,11 @@ class Upload < ActiveRecord::Base
|
||||
# on demand image size calculation, this allows us to null out image sizes
|
||||
# and still handle as needed
|
||||
def get_dimension(key)
|
||||
if v = read_attribute(key)
|
||||
if v = self[key]
|
||||
return v
|
||||
end
|
||||
fix_dimensions!
|
||||
read_attribute(key)
|
||||
self[key]
|
||||
end
|
||||
|
||||
def width
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user