From 5012d46cbd3bcf79b7351f7d2d41003496a796c5 Mon Sep 17 00:00:00 2001 From: Guo Xiang Tan Date: Fri, 28 Jul 2017 10:20:09 +0900 Subject: [PATCH] Add rubocop to our build. (#5004) --- .rubocop.yml | 110 ++++- .travis.yml | 3 +- Gemfile | 1 - Rakefile | 1 - app/controllers/admin/badges_controller.rb | 14 +- .../admin/color_schemes_controller.rb | 1 - app/controllers/admin/dashboard_controller.rb | 4 +- .../admin/diagnostics_controller.rb | 4 +- app/controllers/admin/email_controller.rb | 30 +- app/controllers/admin/emojis_controller.rb | 5 +- app/controllers/admin/flags_controller.rb | 4 +- app/controllers/admin/groups_controller.rb | 4 +- .../admin/screened_ip_addresses_controller.rb | 2 +- .../admin/site_settings_controller.rb | 2 +- .../admin/site_texts_controller.rb | 6 +- .../admin/staff_action_logs_controller.rb | 14 +- app/controllers/admin/themes_controller.rb | 25 +- .../admin/user_fields_controller.rb | 3 +- app/controllers/admin/users_controller.rb | 13 +- .../admin/watched_words_controller.rb | 2 +- app/controllers/admin/web_hooks_controller.rb | 8 +- app/controllers/application_controller.rb | 50 +- app/controllers/badges_controller.rb | 2 +- app/controllers/categories_controller.rb | 12 +- app/controllers/clicks_controller.rb | 2 +- .../composer_messages_controller.rb | 2 +- app/controllers/directory_items_controller.rb | 2 +- app/controllers/draft_controller.rb | 2 +- app/controllers/email_controller.rb | 28 +- app/controllers/embed_controller.rb | 7 +- app/controllers/groups_controller.rb | 8 +- app/controllers/highlight_js_controller.rb | 1 - app/controllers/invites_controller.rb | 13 +- app/controllers/list_controller.rb | 20 +- app/controllers/metadata_controller.rb | 4 +- app/controllers/notifications_controller.rb | 6 +- .../post_action_users_controller.rb | 5 +- app/controllers/posts_controller.rb | 67 ++- app/controllers/queued_posts_controller.rb | 5 +- app/controllers/search_controller.rb | 4 +- app/controllers/session_controller.rb | 19 +- app/controllers/similar_topics_controller.rb | 2 +- app/controllers/static_controller.rb | 12 +- app/controllers/steps_controller.rb | 2 +- app/controllers/stylesheets_controller.rb | 7 +- app/controllers/tag_groups_controller.rb | 2 +- app/controllers/tags_controller.rb | 40 +- app/controllers/topics_controller.rb | 64 ++- app/controllers/user_api_keys_controller.rb | 10 +- app/controllers/user_avatars_controller.rb | 2 +- app/controllers/user_badges_controller.rb | 8 +- .../users/omniauth_callbacks_controller.rb | 3 +- app/controllers/users_controller.rb | 65 ++- app/helpers/application_helper.rb | 16 +- app/helpers/list_helper.rb | 2 +- app/helpers/topics_helper.rb | 2 +- app/helpers/user_notifications_helper.rb | 6 +- app/jobs/base.rb | 21 +- app/jobs/onceoff/grant_emoji.rb | 10 +- .../onceoff/grant_first_reply_by_email.rb | 12 +- app/jobs/onceoff/grant_onebox.rb | 10 +- app/jobs/onceoff/migrate_tagging_plugin.rb | 2 +- app/jobs/onceoff/retro_grant_anniversary.rb | 1 - .../regular/automatic_group_membership.rb | 10 +- app/jobs/regular/delete_topic.rb | 2 +- app/jobs/regular/emit_web_hook_event.rb | 13 +- app/jobs/regular/export_csv_file.rb | 48 +- .../notify_mailing_list_subscribers.rb | 12 +- app/jobs/regular/notify_moved_posts.rb | 4 +- app/jobs/regular/push_notification.rb | 6 +- app/jobs/regular/retrieve_topic.rb | 2 - app/jobs/regular/user_email.rb | 8 +- app/jobs/scheduled/badge_grant.rb | 2 +- app/jobs/scheduled/clean_up_email_logs.rb | 4 +- .../scheduled/clean_up_unmatched_emails.rb | 4 +- app/jobs/scheduled/clean_up_unmatched_ips.rb | 4 +- .../scheduled/clean_up_unsubscribe_keys.rb | 1 - app/jobs/scheduled/create_missing_avatars.rb | 10 +- app/jobs/scheduled/dashboard_stats.rb | 2 +- app/jobs/scheduled/directory_refresh_older.rb | 2 +- app/jobs/scheduled/enqueue_digest_emails.rb | 18 +- .../grant_new_user_of_the_month_badges.rb | 12 +- app/jobs/scheduled/migrate_upload_scheme.rb | 4 +- app/jobs/scheduled/pending_flags_reminder.rb | 12 +- app/jobs/scheduled/pending_users_reminder.rb | 14 +- app/jobs/scheduled/periodical_updates.rb | 2 +- app/jobs/scheduled/purge_inactive.rb | 1 - app/jobs/scheduled/tl3_promotions.rb | 2 +- app/jobs/scheduled/version_check.rb | 10 +- app/mailers/admin_confirmation_mailer.rb | 1 - app/mailers/pending_flags_mailer.rb | 4 +- app/mailers/pending_queued_posts_mailer.rb | 2 +- app/mailers/subscription_mailer.rb | 2 +- app/mailers/user_notifications.rb | 62 ++- app/mailers/version_mailer.rb | 10 +- app/models/about.rb | 4 +- app/models/admin_dashboard_data.rb | 4 +- app/models/application_request.rb | 22 +- app/models/backup.rb | 6 +- app/models/badge.rb | 5 +- app/models/badge_type.rb | 1 - app/models/category.rb | 54 ++- app/models/category_featured_topic.rb | 4 +- app/models/category_featured_user.rb | 2 +- app/models/category_list.rb | 8 +- app/models/category_user.rb | 5 +- app/models/color_scheme.rb | 20 +- app/models/concerns/has_custom_fields.rb | 22 +- app/models/concerns/positionable.rb | 8 +- app/models/concerns/trashable.rb | 4 +- app/models/directory_item.rb | 21 +- app/models/discourse_single_sign_on.rb | 14 +- app/models/draft.rb | 6 +- app/models/draft_sequence.rb | 2 +- app/models/email_log.rb | 18 +- app/models/email_token.rb | 14 +- app/models/embedding.rb | 2 +- app/models/emoji.rb | 6 +- app/models/given_daily_like.rb | 8 +- app/models/global_setting.rb | 17 +- app/models/group.rb | 124 ++--- app/models/group_archived_message.rb | 7 +- app/models/group_user.rb | 39 +- app/models/incoming_link.rb | 5 +- app/models/incoming_links_report.rb | 60 ++- app/models/invite.rb | 41 +- app/models/invite_redeemer.rb | 9 +- app/models/locale_site_setting.rb | 4 +- app/models/notification.rb | 34 +- app/models/optimized_image.rb | 26 +- app/models/permalink.rb | 14 +- app/models/plugin_store.rb | 4 +- app/models/post.rb | 89 ++-- app/models/post_action.rb | 122 ++--- app/models/post_analyzer.rb | 12 +- app/models/post_mover.rb | 2 +- app/models/post_timing.rb | 27 +- app/models/queued_post.rb | 4 +- app/models/quoted_post.rb | 4 +- app/models/remote_theme.rb | 10 +- app/models/report.rb | 22 +- app/models/screened_email.rb | 18 +- app/models/screened_ip_address.rb | 16 +- app/models/screened_url.rb | 2 +- app/models/search_log.rb | 2 +- app/models/site.rb | 2 +- app/models/site_setting.rb | 6 +- app/models/slug_setting.rb | 2 +- app/models/stylesheet_cache.rb | 12 +- app/models/tag.rb | 16 +- app/models/theme.rb | 31 +- app/models/theme_field.rb | 5 +- app/models/top_topic.rb | 13 +- app/models/topic.rb | 147 +++--- app/models/topic_embed.rb | 6 +- app/models/topic_featured_users.rb | 4 +- app/models/topic_link.rb | 40 +- app/models/topic_link_click.rb | 4 +- app/models/topic_list.rb | 10 +- app/models/topic_notifier.rb | 12 +- app/models/topic_posters_summary.rb | 2 +- app/models/topic_tracking_state.rb | 14 +- app/models/topic_user.rb | 46 +- app/models/topic_view_item.rb | 3 +- app/models/translation_override.rb | 2 +- app/models/trust_level3_requirements.rb | 28 +- app/models/upload.rb | 4 +- app/models/user.rb | 97 ++-- app/models/user_action.rb | 20 +- app/models/user_api_key.rb | 2 +- app/models/user_archived_message.rb | 6 +- app/models/user_auth_token.rb | 4 +- app/models/user_avatar.rb | 2 +- app/models/user_badge.rb | 2 +- app/models/user_badges.rb | 2 +- app/models/user_email.rb | 2 +- app/models/user_history.rb | 9 +- app/models/user_option.rb | 11 +- app/models/user_profile.rb | 6 +- app/models/user_profile_view.rb | 4 +- app/models/user_search.rb | 34 +- app/models/user_stat.rb | 8 +- app/models/user_summary.rb | 44 +- app/models/user_visit.rb | 6 +- app/models/watched_word.rb | 1 - app/models/web_hook.rb | 8 +- app/models/web_hook_event.rb | 14 +- app/serializers/admin_badge_serializer.rb | 2 +- .../admin_user_action_serializer.rb | 4 +- .../category_and_topic_lists_serializer.rb | 2 +- app/serializers/category_serializer.rb | 6 +- app/serializers/current_user_serializer.rb | 2 +- .../detailed_user_badge_serializer.rb | 1 - .../post_action_type_serializer.rb | 8 +- app/serializers/post_item_excerpt.rb | 1 - app/serializers/post_revision_serializer.rb | 9 +- app/serializers/site_serializer.rb | 10 +- app/serializers/site_text_serializer.rb | 1 - app/serializers/topic_flag_type_serializer.rb | 4 +- app/serializers/topic_view_serializer.rb | 4 +- app/serializers/user_action_serializer.rb | 1 - app/serializers/user_option_serializer.rb | 1 - app/serializers/user_serializer.rb | 11 +- app/services/badge_granter.rb | 57 +-- app/services/color_scheme_revisor.rb | 4 +- app/services/group_message.rb | 10 +- app/services/handle_chunk_upload.rb | 2 +- app/services/notification_emailer.rb | 4 +- app/services/post_alerter.rb | 82 ++-- app/services/random_topic_selector.rb | 21 +- app/services/search_indexer.rb | 3 +- app/services/spam_rule/auto_block.rb | 22 +- app/services/staff_action_logger.rb | 362 ++++++--------- app/services/topic_status_updater.rb | 8 +- app/services/tracked_topics_updater.rb | 3 +- app/services/user_action_creator.rb | 18 +- app/services/user_anonymizer.rb | 14 +- app/services/user_blocker.rb | 8 +- app/services/user_destroyer.rb | 6 +- app/services/username_changer.rb | 4 +- app/services/username_checker_service.rb | 3 +- app/services/word_watcher.rb | 2 +- bin/puma | 2 +- config.ru | 1 - config/application.rb | 7 +- config/boot.rb | 1 - config/cloud/cloud66/files/production.rb | 14 +- config/environments/development.rb | 2 - config/environments/production.rb | 4 +- config/environments/test.rb | 2 +- config/initializers/001-redis.rb | 13 +- config/initializers/004-message_bus.rb | 2 +- config/initializers/006-ensure_login_hint.rb | 2 +- config/initializers/006-mini_profiler.rb | 8 +- config/initializers/008-rack-cors.rb | 4 +- config/initializers/050-force_https.rb | 3 +- config/initializers/099-anon-cache.rb | 12 +- config/initializers/100-logster.rb | 8 +- config/initializers/100-quiet_logger.rb | 2 +- config/initializers/100-sidekiq.rb | 2 +- config/initializers/100-verify_config.rb | 4 +- .../200-message_bus_request_tracker.rb | 1 - config/locales/plurals.rb | 220 ++++----- config/puma.rb | 8 +- config/routes.rb | 222 +++++---- config/unicorn.conf.rb | 13 +- db/fixtures/001_categories.rb | 2 +- db/fixtures/002_groups.rb | 2 +- db/fixtures/006_badges.rb | 9 +- db/fixtures/009_users.rb | 3 +- db/fixtures/501_meta_category.rb | 2 +- db/fixtures/502_staff_category.rb | 2 +- db/fixtures/600_themes.rb | 12 +- db/fixtures/999_delayed.rb | 2 +- db/fixtures/999_topics.rb | 26 +- ..._add_last_post_user_id_to_forum_threads.rb | 1 - .../20120629150253_denormalize_expressions.rb | 1 - ...mail_hashed_password_name_salt_to_users.rb | 4 +- ...20720013733_add_username_lower_to_users.rb | 2 +- db/migrate/20120807223020_create_actions.rb | 1 - db/migrate/20120809020415_remove_site_id.rb | 2 +- ...0120809053414_correct_indexing_on_posts.rb | 8 +- .../20120809154750_remove_index_for_now.rb | 8 +- .../20120809174649_create_post_actions.rb | 2 +- ...6_add_unique_constraint_to_user_actions.rb | 2 +- ...21191616_add_bumped_at_to_forum_threads.rb | 2 +- .../20121011155904_create_email_logs.rb | 4 +- ...121018103721_rename_forum_thread_tables.rb | 2 - ...ter_seconds_and_banning_and_dob_to_user.rb | 2 +- ...0319122248_add_reply_to_user_id_to_post.rb | 4 +- ...00_add_user_indexes_to_posts_and_topics.rb | 6 +- db/migrate/20130404232558_add_user_extras.rb | 1 - ...426044914_allow_nulls_in_incoming_links.rb | 4 +- .../20130527152648_add_like_score_to_posts.rb | 2 - ...612200846_create_post_upload_join_table.rb | 14 +- .../20130613211700_drop_posts_uploads.rb | 2 +- ...130621042855_change_supress_to_suppress.rb | 4 +- ..._change_ip_to_inet_in_topic_link_clicks.rb | 2 +- ...130625022454_change_ip_to_inet_in_views.rb | 2 +- .../20130625170842_remove_access_password.rb | 2 +- .../20130911182437_create_user_stats.rb | 2 +- db/migrate/20130912185218_acting_user_null.rb | 4 +- ..._add_user_id_parent_type_index_on_views.rb | 2 +- ...131022045114_add_uncategorized_category.rb | 1 - ...09_add_parent_category_id_to_categories.rb | 1 - .../20131210181901_migrate_word_counts.rb | 8 +- .../20140211230222_move_cas_settings.rb | 14 +- ...04930_add_custom_email_in_to_categories.rb | 12 +- .../20140318150412_add_excerpt_to_topics.rb | 2 +- ...140402201432_make_content_sha1_nullable.rb | 2 +- ...remove_system_avatars_from_user_avatars.rb | 8 +- db/migrate/20140715055242_add_quoted_posts.rb | 6 +- ...40804010803_incoming_link_normalization.rb | 2 - ...613_normalize_topic_view_data_and_index.rb | 1 - ...0815215618_add_name_lower_to_categories.rb | 2 +- ...913192733_add_trust_level_locked_column.rb | 2 +- .../20140929204155_migrate_tos_setting.rb | 1 - ...216112341_resolve_duplicate_group_names.rb | 2 +- ..._add_liked_and_bookmarked_to_topic_user.rb | 2 +- ...0150713203955_enlarge_users_email_field.rb | 4 +- ...20150729150523_migrate_auto_close_posts.rb | 2 +- ...160108051129_fix_incorrect_user_history.rb | 1 - .../20161205001727_add_topic_columns_back.rb | 4 +- ...01352_add_all_topics_wiki_to_categories.rb | 2 +- ...add_show_subcategory_list_to_categories.rb | 2 +- db/migrate/20170313192741_add_themes.rb | 9 +- .../postgresql_fallback_adapter.rb | 4 +- lib/admin_constraint.rb | 2 +- lib/admin_user_index_query.rb | 28 +- lib/archetype.rb | 2 +- lib/auth/current_user_provider.rb | 5 +- lib/auth/default_current_user_provider.rb | 7 +- lib/auth/facebook_authenticator.rb | 6 +- lib/auth/github_authenticator.rb | 13 +- lib/auth/google_oauth2_authenticator.rb | 8 +- lib/auth/instagram_authenticator.rb | 4 +- lib/auth/oauth2_authenticator.rb | 2 +- lib/auth/open_id_authenticator.rb | 11 +- lib/auth/result.rb | 4 +- lib/auth/twitter_authenticator.rb | 4 +- lib/autospec/formatter.rb | 2 +- lib/autospec/manager.rb | 20 +- lib/autospec/qunit_runner.rb | 2 +- lib/autospec/rspec_runner.rb | 4 +- lib/autospec/simple_runner.rb | 4 +- lib/autospec/spork_runner.rb | 6 +- lib/avatar_lookup.rb | 8 +- lib/backup_restore/backup_restore.rb | 4 +- lib/backup_restore/backuper.rb | 2 +- lib/backup_restore/restorer.rb | 2 +- lib/badge_queries.rb | 54 +-- lib/cache.rb | 2 +- lib/category_badge.rb | 71 +-- lib/composer_messages_finder.rb | 18 +- lib/content_buffer.rb | 2 +- lib/cooked_post_processor.rb | 18 +- lib/current_user.rb | 7 +- lib/demon/base.rb | 16 +- lib/demon/rails_autospec.rb | 6 +- lib/demon/sidekiq.rb | 2 +- lib/directory_helper.rb | 2 +- lib/discourse.rb | 16 +- lib/discourse_cookie_store.rb | 4 +- lib/discourse_hub.rb | 14 +- lib/discourse_plugin.rb | 7 +- lib/discourse_plugin_registry.rb | 12 +- lib/discourse_redis.rb | 12 +- lib/discourse_tagging.rb | 33 +- lib/discourse_updates.rb | 11 +- lib/distributed_cache.rb | 18 +- lib/distributed_memoizer.rb | 3 +- lib/distributed_mutex.rb | 4 +- lib/email/message_builder.rb | 15 +- lib/email/processor.rb | 38 +- lib/email/receiver.rb | 14 +- lib/email/renderer.rb | 2 +- lib/email/sender.rb | 14 +- lib/email/styles.rb | 8 +- lib/email_updater.rb | 8 +- .../tilt/es6_module_transpiler_template.rb | 10 +- lib/excerpt_parser.rb | 48 +- lib/file_store/s3_store.rb | 4 +- lib/filter_best_posts.rb | 47 +- lib/final_destination.rb | 6 +- lib/flag_query.rb | 28 +- lib/freedom_patches/active_record_base.rb | 3 +- .../ams_include_without_root.rb | 2 +- .../better_handlebars_errors.rb | 1 - lib/freedom_patches/fast_pluck.rb | 2 +- lib/freedom_patches/inflector_backport.rb | 7 +- lib/freedom_patches/pool_drainer.rb | 2 +- lib/freedom_patches/rack_patches.rb | 22 +- lib/freedom_patches/rails4.rb | 50 +- lib/freedom_patches/raw_handlebars.rb | 4 +- lib/freedom_patches/safe_buffer.rb | 8 +- .../schema_migration_details.rb | 2 +- lib/freedom_patches/scrub.rb | 6 +- lib/freedom_patches/sprockets_patches.rb | 6 +- lib/freedom_patches/translate_accelerator.rb | 6 +- lib/gaps.rb | 4 +- lib/guardian.rb | 11 +- lib/guardian/category_guardian.rb | 6 +- lib/guardian/post_guardian.rb | 8 +- lib/guardian/topic_guardian.rb | 4 +- lib/html_normalize.rb | 13 +- lib/html_prettify.rb | 21 +- lib/html_to_markdown.rb | 7 +- lib/i18n/backend/discourse_i18n.rb | 2 +- lib/import/normalize.rb | 4 +- lib/import_export/category_exporter.rb | 10 +- lib/import_export/category_importer.rb | 6 +- lib/import_export/import_export.rb | 2 +- lib/import_export/topic_exporter.rb | 14 +- lib/import_export/topic_importer.rb | 10 +- lib/inline_oneboxer.rb | 9 +- lib/js_locale_helper.rb | 4 +- lib/json_error.rb | 2 +- lib/letter_avatar.rb | 436 +++++++++--------- lib/markdown_linker.rb | 2 +- lib/memory_diagnostics.rb | 24 +- lib/message_bus_diags.rb | 2 +- lib/middleware/anonymous_cache.rb | 20 +- lib/middleware/missing_avatars.rb | 6 +- lib/middleware/request_tracker.rb | 20 +- lib/middleware/turbo_dev.rb | 4 +- lib/new_post_manager.rb | 12 +- lib/new_post_result.rb | 2 +- lib/oneboxer.rb | 12 +- lib/pbkdf2.rb | 8 +- lib/pinned_check.rb | 6 +- lib/plugin/auth_provider.rb | 2 +- lib/plugin/instance.rb | 24 +- lib/plugin/theme.rb | 1 - lib/plugin_gem.rb | 2 +- lib/post_creator.rb | 27 +- lib/post_destroyer.rb | 18 +- lib/post_jobs_enqueuer.rb | 2 +- lib/post_revisor.rb | 28 +- lib/pretty_text.rb | 13 +- lib/pretty_text/helpers.rb | 2 +- lib/primary_group_lookup.rb | 8 +- lib/promotion.rb | 13 +- lib/rate_limiter.rb | 2 +- lib/rate_limiter/limit_exceeded.rb | 2 +- lib/rate_limiter/on_create_record.rb | 4 +- lib/s3_helper.rb | 14 +- lib/scheduler/defer.rb | 10 +- lib/scheduler/manager.rb | 19 +- lib/scheduler/schedule.rb | 4 +- lib/scheduler/web.rb | 10 +- lib/score_calculator.rb | 7 +- lib/screening_model.rb | 2 +- lib/search.rb | 121 +++-- lib/search/grouped_search_results.rb | 3 +- lib/secure_session.rb | 2 +- lib/single_sign_on.rb | 6 +- lib/site_setting_extension.rb | 26 +- lib/site_settings/db_provider.rb | 4 +- lib/slug.rb | 23 +- lib/source_url.rb | 2 +- lib/spam_handler.rb | 14 +- lib/sql_builder.rb | 23 +- lib/stats_socket.rb | 2 +- lib/stylesheet/compiler.rb | 9 +- lib/stylesheet/manager.rb | 12 +- lib/stylesheet/watcher.rb | 7 +- lib/suggested_topics_builder.rb | 13 +- lib/table_migration_helper.rb | 2 +- lib/tasks/add_topic_to_quotes.rake | 1 - lib/tasks/admin.rake | 14 +- lib/tasks/api.rake | 2 +- lib/tasks/assets.rake | 22 +- lib/tasks/auto_annotate_models.rake | 52 +-- lib/tasks/autospec.rake | 2 +- lib/tasks/avatars.rake | 2 +- lib/tasks/backfill.thor | 2 - lib/tasks/build_test_topic.rake | 3 +- lib/tasks/cdn.rake | 4 +- lib/tasks/docker.rake | 4 +- lib/tasks/emoji.rake | 30 +- lib/tasks/highlight.rake | 2 +- lib/tasks/i18n_stats.rake | 14 +- lib/tasks/images.rake | 2 +- lib/tasks/import.rake | 1 - lib/tasks/integration.rake | 1 - lib/tasks/plugin.rake | 2 +- lib/tasks/posts.rake | 14 +- lib/tasks/qunit.rake | 8 +- lib/tasks/release_note.rake | 10 +- lib/tasks/scheduler.rake | 10 +- lib/tasks/search.rake | 2 +- lib/tasks/typepad.thor | 6 +- lib/tasks/uploads.rake | 12 +- lib/tasks/user_actions.rake | 7 +- lib/tasks/users.rake | 2 +- lib/text_sentinel.rb | 7 +- lib/timeline_lookup.rb | 4 +- lib/topic_creator.rb | 23 +- lib/topic_list_responder.rb | 1 - lib/topic_query.rb | 86 ++-- lib/topic_retriever.rb | 3 +- lib/topic_subtype.rb | 4 +- lib/topic_view.rb | 76 +-- lib/topics_bulk_action.rb | 6 +- lib/twitter_api.rb | 3 +- lib/unread.rb | 5 +- .../allow_user_locale_enabled_validator.rb | 4 +- ...tive_reply_by_email_addresses_validator.rb | 2 +- lib/validators/email_setting_validator.rb | 2 +- lib/validators/integer_setting_validator.rb | 12 +- .../pop3_polling_enabled_setting_validator.rb | 2 +- lib/validators/post_validator.rb | 2 +- lib/validators/regex_setting_validator.rb | 2 +- .../reply_by_email_address_validator.rb | 2 +- .../reply_by_email_enabled_validator.rb | 2 +- .../sso_overrides_email_validator.rb | 2 +- lib/validators/string_setting_validator.rb | 12 +- .../topic_title_length_validator.rb | 17 +- lib/validators/username_setting_validator.rb | 2 +- lib/wizard.rb | 8 +- lib/wizard/builder.rb | 22 +- lib/wizard/field.rb | 2 +- lib/wizard/step_updater.rb | 2 +- .../db/fixtures/001_discobot.rb | 4 +- .../advanced_user_narrative.rb | 22 +- .../lib/discourse_narrative_bot/base.rb | 6 +- .../new_user_narrative.rb | 4 +- plugins/discourse-narrative-bot/plugin.rb | 2 +- .../advanced_user_narrative_spec.rb | 38 +- .../new_user_narrative_spec.rb | 30 +- .../track_selector_spec.rb | 3 +- .../scheduled/daily_performance_report.rb | 1 - .../lib/log_analyzer.rb | 15 +- .../script/nginx_analyze.rb | 12 +- .../20151016163051_merge_polls_votes.rb | 4 +- ...0321164925_close_polls_in_closed_topics.rb | 6 +- plugins/poll/lib/polls_updater.rb | 2 +- plugins/poll/lib/tasks/migrate_old_polls.rake | 12 +- plugins/poll/plugin.rb | 11 +- .../spec/controllers/polls_controller_spec.rb | 30 +- .../spec/controllers/posts_controller_spec.rb | 52 +-- .../spec/integration/poll_endpoints_spec.rb | 30 +- plugins/poll/spec/lib/polls_validator_spec.rb | 1 - script/bench.rb | 43 +- script/benchmarks/markdown/bench.rb | 6 +- script/bulk_import/base.rb | 4 +- script/diff_heaps.rb | 11 +- script/discourse | 13 +- script/import_scripts/askbot.rb | 99 ++-- script/import_scripts/base.rb | 26 +- script/import_scripts/base/csv_helper.rb | 4 +- script/import_scripts/bbpress.rb | 6 +- script/import_scripts/bespoke_1.rb | 63 ++- script/import_scripts/discuz_x.rb | 47 +- script/import_scripts/disqus.rb | 8 +- script/import_scripts/drupal-6.rb | 28 +- script/import_scripts/drupal.rb | 14 +- script/import_scripts/drupal_json.rb | 4 +- script/import_scripts/drupal_qa.rb | 10 +- script/import_scripts/fluxbb.rb | 6 +- script/import_scripts/getsatisfaction.rb | 72 ++- script/import_scripts/jive.rb | 112 ++--- script/import_scripts/jive_api.rb | 2 +- script/import_scripts/json_generic.rb | 5 +- script/import_scripts/kunena.rb | 12 +- script/import_scripts/kunena3.rb | 10 +- script/import_scripts/lithium.rb | 50 +- script/import_scripts/mbox-experimental.rb | 1 - script/import_scripts/mbox.rb | 30 +- script/import_scripts/muut.rb | 7 +- script/import_scripts/mybb.rb | 18 +- script/import_scripts/mylittleforum.rb | 79 ++-- script/import_scripts/nabble.rb | 16 +- script/import_scripts/ning.rb | 6 +- .../phpbb3/importers/avatar_importer.rb | 28 +- .../phpbb3/importers/category_importer.rb | 4 +- .../phpbb3/importers/message_importer.rb | 5 +- .../phpbb3/importers/poll_importer.rb | 4 +- .../import_scripts/phpbb3/support/settings.rb | 2 +- script/import_scripts/punbb.rb | 4 +- script/import_scripts/quandora/export.rb | 5 +- script/import_scripts/quandora/import.rb | 14 +- .../import_scripts/quandora/quandora_api.rb | 14 +- .../quandora/quandora_question.rb | 26 +- .../quandora/test/test_quandora_api.rb | 8 +- .../quandora/test/test_quandora_question.rb | 22 +- script/import_scripts/sfn.rb | 6 +- script/import_scripts/simplepress.rb | 4 +- script/import_scripts/smf2.rb | 58 ++- .../import_scripts/socialcast/create_title.rb | 2 +- script/import_scripts/socialcast/export.rb | 12 +- script/import_scripts/socialcast/import.rb | 14 +- .../socialcast/socialcast_api.rb | 16 +- .../socialcast/socialcast_message.rb | 5 +- .../socialcast/socialcast_user.rb | 6 +- .../socialcast/test/test_socialcast_api.rb | 16 +- script/import_scripts/socialcast/title.rb | 4 +- script/import_scripts/sourceforge.rb | 6 +- .../support/convert_mysql_xml_to_mysql.rb | 6 +- script/import_scripts/vanilla.rb | 20 +- script/import_scripts/vanilla_mysql.rb | 39 +- script/import_scripts/vbulletin.rb | 9 +- script/import_scripts/vbulletin5.rb | 22 +- script/import_scripts/xenforo.rb | 4 +- script/import_scripts/zoho.rb | 17 +- script/measure.rb | 50 +- script/memstats.rb | 40 +- script/micro_bench.rb | 3 +- script/profile_db_generator.rb | 2 - script/pull_translations.rb | 6 +- script/redis_memory.rb | 2 +- script/require_profiler.rb | 8 +- script/test_email_settings.rb | 16 +- script/test_mem.rb | 4 +- script/test_pretty_text.rb | 3 +- script/user_simulator.rb | 2 - script/version_bump.rb | 6 +- .../postgresql_fallback_adapter_spec.rb | 24 +- spec/components/admin_confirmation_spec.rb | 1 - .../components/admin_user_index_query_spec.rb | 48 +- spec/components/archetype_spec.rb | 3 +- .../default_current_user_provider_spec.rb | 23 +- .../auth/facebook_authenticator_spec.rb | 2 +- .../auth/github_authenticator_spec.rb | 134 +++--- .../auth/google_oauth2_authenticator_spec.rb | 60 +-- .../auth/open_id_authenticator_spec.rb | 2 +- spec/components/avatar_lookup_spec.rb | 2 +- spec/components/cache_spec.rb | 4 +- spec/components/column_dropper_spec.rb | 8 +- .../common_passwords/common_passwords_spec.rb | 4 +- .../composer_messages_finder_spec.rb | 13 +- .../concern/has_custom_fields_spec.rb | 35 +- spec/components/concern/positionable_spec.rb | 12 +- spec/components/content_buffer_spec.rb | 8 +- spec/components/cooked_post_processor_spec.rb | 32 +- spec/components/discourse_diff_spec.rb | 2 +- spec/components/discourse_event_spec.rb | 2 +- spec/components/discourse_hub_spec.rb | 2 +- spec/components/discourse_i18n_spec.rb | 26 +- spec/components/discourse_redis_spec.rb | 4 +- spec/components/discourse_spec.rb | 4 +- spec/components/distributed_mutex_spec.rb | 3 +- spec/components/email/message_builder_spec.rb | 2 +- spec/components/email/receiver_spec.rb | 4 +- spec/components/email/renderer_spec.rb | 3 - spec/components/email/sender_spec.rb | 3 +- spec/components/email_updater_spec.rb | 1 - spec/components/enum_spec.rb | 8 +- spec/components/file_store/s3_store_spec.rb | 2 +- spec/components/filter_best_posts_spec.rb | 8 +- spec/components/flag_query_spec.rb | 2 +- .../freedom_patches/pool_drainer_spec.rb | 7 +- .../schema_migration_details_spec.rb | 2 +- spec/components/gaps_spec.rb | 23 +- spec/components/guardian_spec.rb | 46 +- .../highlight_js/highlight_js_spec.rb | 1 - spec/components/html_normalize_spec.rb | 2 +- spec/components/html_to_markdown_spec.rb | 2 +- spec/components/import/normalize_spec.rb | 1 - spec/components/inline_oneboxer_spec.rb | 2 - spec/components/js_locale_helper_spec.rb | 28 +- spec/components/json_error_spec.rb | 3 +- .../middleware/anonymous_cache_spec.rb | 20 +- .../middleware/request_tracker_spec.rb | 10 +- spec/components/new_post_manager_spec.rb | 13 +- .../engine/discourse_local_onebox_spec.rb | 4 +- spec/components/onpdiff_spec.rb | 1 - spec/components/pbkdf2_spec.rb | 4 +- spec/components/pinned_check_spec.rb | 2 - spec/components/plugin/filter_manager_spec.rb | 6 +- spec/components/plugin/instance_spec.rb | 6 +- spec/components/post_action_creator_spec.rb | 1 - spec/components/post_creator_spec.rb | 62 ++- spec/components/post_destroyer_spec.rb | 16 +- spec/components/post_merger_spec.rb | 5 +- spec/components/post_revisor_spec.rb | 53 ++- spec/components/pretty_text_spec.rb | 46 +- spec/components/promotion_spec.rb | 6 +- spec/components/retrieve_title_spec.rb | 2 - spec/components/scheduler/defer_spec.rb | 1 - spec/components/scheduler/manager_spec.rb | 8 +- .../scheduler/schedule_info_spec.rb | 2 +- spec/components/search_spec.rb | 38 +- .../components/site_setting_extension_spec.rb | 23 +- .../site_settings/db_provider_spec.rb | 3 +- .../local_process_provider_spec.rb | 17 +- .../site_settings/yaml_loader_spec.rb | 6 +- spec/components/slug_spec.rb | 1 - spec/components/sql_builder_spec.rb | 4 +- spec/components/stats_socket_spec.rb | 2 +- spec/components/stylesheet/compiler_spec.rb | 4 +- spec/components/stylesheet/manager_spec.rb | 3 - .../suggested_topics_builder_spec.rb | 27 +- spec/components/system_message_spec.rb | 2 - .../components/table_migration_helper_spec.rb | 10 +- spec/components/timeline_lookup_spec.rb | 4 +- spec/components/topic_creator_spec.rb | 2 +- spec/components/topic_query_spec.rb | 87 ++-- spec/components/topic_retriever_spec.rb | 6 +- spec/components/topic_view_spec.rb | 46 +- spec/components/trashable_spec.rb | 3 +- spec/components/unread_spec.rb | 1 - .../allowed_ip_address_validator_spec.rb | 2 +- .../validators/email_validator_spec.rb | 6 +- .../ip_address_format_validator_spec.rb | 2 +- .../validators/password_validator_spec.rb | 4 +- .../quality_title_validator_spec.rb | 17 +- .../topic_title_length_validator_spec.rb | 4 +- .../user_full_name_validator_spec.rb | 4 +- spec/components/version_spec.rb | 1 - spec/components/wizard/step_updater_spec.rb | 4 +- spec/components/wizard/wizard_spec.rb | 4 +- spec/components/wizard/wizard_step_spec.rb | 3 +- .../admin/admin_controller_spec.rb | 1 - .../admin/backups_controller_spec.rb | 1 - .../admin/badges_controller_spec.rb | 9 +- .../admin/color_schemes_controller_spec.rb | 4 +- .../admin/dashboard_controller_spec.rb | 2 +- .../admin/email_controller_spec.rb | 6 +- .../admin/flags_controller_spec.rb | 1 - .../admin/groups_controller_spec.rb | 12 +- .../admin/plugins_controller_spec.rb | 1 - .../admin/reports_controller_spec.rb | 1 - .../staff_action_logs_controller_spec.rb | 2 +- .../admin/themes_controller_spec.rb | 22 +- .../admin/user_fields_controller_spec.rb | 35 +- .../admin/users_controller_spec.rb | 4 +- .../admin/web_hooks_controller_spec.rb | 2 +- .../application_controller_spec.rb | 26 +- .../controllers/categories_controller_spec.rb | 41 +- .../category_hashtags_controller_spec.rb | 6 +- .../composer_messages_controller_spec.rb | 2 +- .../directory_items_controller_spec.rb | 4 +- spec/controllers/email_controller_spec.rb | 24 +- spec/controllers/embed_controller_spec.rb | 4 +- .../controllers/export_csv_controller_spec.rb | 1 - .../extra_locales_controller_spec.rb | 8 +- spec/controllers/groups_controller_spec.rb | 2 +- .../inline_onebox_controller_spec.rb | 1 - spec/controllers/invites_controller_spec.rb | 3 +- spec/controllers/list_controller_spec.rb | 1 - spec/controllers/onebox_controller_spec.rb | 2 +- .../post_actions_controller_spec.rb | 12 +- spec/controllers/posts_controller_spec.rb | 119 +++-- .../queued_posts_controller_spec.rb | 2 - spec/controllers/search_controller_spec.rb | 40 +- spec/controllers/session_controller_spec.rb | 9 +- spec/controllers/site_controller_spec.rb | 2 +- spec/controllers/static_controller_spec.rb | 2 +- spec/controllers/steps_controller_spec.rb | 1 - .../stylesheets_controller_spec.rb | 2 +- spec/controllers/tags_controller_spec.rb | 10 +- spec/controllers/topics_controller_spec.rb | 129 +++--- spec/controllers/uploads_controller_spec.rb | 18 +- .../user_api_keys_controller_spec.rb | 3 +- .../user_avatars_controller_spec.rb | 3 +- spec/controllers/users_controller_spec.rb | 94 ++-- .../users_email_controller_spec.rb | 2 +- spec/controllers/webhooks_controller_spec.rb | 10 +- spec/fabricators/badge_fabricator.rb | 4 +- .../color_scheme_color_fabricator.rb | 2 +- spec/fabricators/color_scheme_fabricator.rb | 2 +- spec/fabricators/incoming_link_fabricator.rb | 2 +- spec/fabricators/notification_fabricator.rb | 6 +- spec/fabricators/permalink_fabricator.rb | 2 +- spec/fabricators/post_fabricator.rb | 8 +- spec/fabricators/queued_post_fabricator.rb | 3 +- .../screened_ip_address_fabricator.rb | 2 +- .../single_sign_on_record_fabricator.rb | 2 - spec/fabricators/tag_fabricator.rb | 2 +- spec/fabricators/topic_embed_fabricator.rb | 2 +- spec/fabricators/topic_fabricator.rb | 2 +- spec/fabricators/upload_fabricator.rb | 2 +- spec/fabricators/user_fabricator.rb | 12 +- spec/fabricators/user_field_fabricator.rb | 2 +- spec/fabricators/watched_word_fabricator.rb | 2 +- spec/fixtures/plugins/my_plugin/plugin.rb | 10 +- spec/integration/admin/emojis_spec.rb | 26 +- spec/integration/category_tag_spec.rb | 48 +- spec/integration/groups_spec.rb | 12 +- spec/integration/spam_rules_spec.rb | 6 +- spec/integration/tags_spec.rb | 2 +- spec/integration/users_spec.rb | 4 +- spec/integrity/common_mark_spec.rb | 5 +- spec/integrity/i18n_spec.rb | 1 - spec/jobs/bulk_grant_trust_level_spec.rb | 4 +- spec/jobs/clean_up_digest_keys.rb | 1 - spec/jobs/emit_web_hook_event_spec.rb | 2 +- spec/jobs/enqueue_digest_emails_spec.rb | 3 +- spec/jobs/export_csv_file_spec.rb | 4 +- spec/jobs/feature_topic_users_spec.rb | 5 +- spec/jobs/grant_anniversary_badges_spec.rb | 1 - ...grant_new_user_of_the_month_badges_spec.rb | 1 - spec/jobs/invite_email_spec.rb | 1 - spec/jobs/jobs_base_spec.rb | 5 +- .../notify_mailing_list_subscribers_spec.rb | 2 +- spec/jobs/notify_moved_posts_spec.rb | 4 +- .../pending_queued_posts_reminder_spec.rb | 2 +- spec/jobs/periodical_updates_spec.rb | 2 - spec/jobs/publish_topic_to_category_spec.rb | 1 - spec/jobs/test_email_spec.rb | 2 - spec/jobs/topic_reminder_spec.rb | 4 +- spec/jobs/user_email_spec.rb | 19 +- spec/mailers/invite_mailer_spec.rb | 1 - spec/mailers/rejection_mailer_spec.rb | 2 +- spec/mailers/user_notifications_spec.rb | 28 +- spec/models/admin_dashboard_data_spec.rb | 2 +- spec/models/application_request_spec.rb | 4 +- spec/models/badge_spec.rb | 1 - spec/models/category_featured_topic_spec.rb | 4 +- spec/models/category_list_spec.rb | 8 +- spec/models/category_spec.rb | 15 +- spec/models/category_user_spec.rb | 1 - spec/models/color_scheme_spec.rb | 18 +- spec/models/developer_spec.rb | 1 - spec/models/discourse_single_sign_on_spec.rb | 1 - spec/models/draft_spec.rb | 15 +- spec/models/email_log_spec.rb | 1 - spec/models/email_token_spec.rb | 1 - spec/models/global_setting_spec.rb | 16 +- spec/models/group_history_spec.rb | 4 +- spec/models/group_spec.rb | 31 +- spec/models/incoming_links_report_spec.rb | 30 +- spec/models/invite_redeemer_spec.rb | 4 +- spec/models/invite_spec.rb | 1 - spec/models/locale_site_setting_spec.rb | 2 +- spec/models/notification_spec.rb | 25 +- spec/models/plugin_store_spec.rb | 9 +- spec/models/post_action_spec.rb | 20 +- spec/models/post_analyzer_spec.rb | 9 +- spec/models/post_mover_spec.rb | 6 +- spec/models/post_spec.rb | 47 +- spec/models/post_timing_spec.rb | 20 +- spec/models/queued_post_spec.rb | 5 +- spec/models/remote_theme_spec.rb | 6 +- spec/models/report_spec.rb | 18 +- spec/models/screened_ip_address_spec.rb | 2 +- spec/models/screened_url_spec.rb | 2 +- spec/models/site_setting_spec.rb | 1 - spec/models/site_spec.rb | 14 +- spec/models/tag_spec.rb | 4 +- spec/models/tag_user_spec.rb | 2 - spec/models/theme_spec.rb | 9 +- spec/models/top_topic_spec.rb | 2 +- spec/models/topic_converter_spec.rb | 2 +- spec/models/topic_link_click_spec.rb | 4 - spec/models/topic_link_spec.rb | 15 +- spec/models/topic_list_spec.rb | 4 +- spec/models/topic_spec.rb | 89 ++-- spec/models/topic_tracking_state_spec.rb | 1 - spec/models/topic_user_spec.rb | 14 +- spec/models/topic_view_item_spec.rb | 2 +- spec/models/trust_level3_requirements_spec.rb | 8 +- spec/models/twitter_user_info_spec.rb | 2 +- spec/models/user_action_spec.rb | 13 +- spec/models/user_api_key_spec.rb | 5 +- spec/models/user_archived_message_spec.rb | 3 +- spec/models/user_auth_token_spec.rb | 18 +- spec/models/user_avatar_spec.rb | 1 - spec/models/user_history_spec.rb | 4 +- spec/models/user_option_spec.rb | 14 +- spec/models/user_profile_view_spec.rb | 6 +- spec/models/user_spec.rb | 19 +- spec/models/user_stat_spec.rb | 1 - spec/models/user_visit_spec.rb | 4 +- spec/models/web_hook_spec.rb | 2 +- spec/rails_helper.rb | 14 +- spec/serializers/post_serializer_spec.rb | 17 +- spec/serializers/user_serializer_spec.rb | 7 +- .../services/anonymous_shadow_creator_spec.rb | 1 - spec/services/auto_block_spec.rb | 6 +- spec/services/badge_granter_spec.rb | 6 +- spec/services/color_scheme_revisor_spec.rb | 6 +- spec/services/group_message_spec.rb | 28 +- spec/services/notification_emailer_spec.rb | 8 +- spec/services/post_action_notifier_spec.rb | 11 +- spec/services/post_alerter_spec.rb | 59 ++- spec/services/post_owner_changer_spec.rb | 9 +- spec/services/random_topic_selector_spec.rb | 8 +- spec/services/staff_action_logger_spec.rb | 18 +- spec/services/user_anonymizer_spec.rb | 18 +- spec/services/user_blocker_spec.rb | 2 +- spec/services/user_destroyer_spec.rb | 22 +- spec/services/user_updater_spec.rb | 27 +- spec/support/diagnostics_helper.rb | 2 +- spec/support/helpers.rb | 12 +- spec/support/integration_helpers.rb | 2 +- .../shared_examples_for_stats_cacheable.rb | 2 +- spec/tasks/posts_spec.rb | 2 +- .../complete.html.erb_spec.rb | 2 - .../failure.html.erb_spec.rb | 10 +- 871 files changed, 5480 insertions(+), 6056 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 792d6e22e1b..088f59f4d3c 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,14 +1,104 @@ AllCops: - TargetRubyVersion: 2.3 + TargetRubyVersion: 2.4 + DisabledByDefault: true -Metrics/LineLength: - Max: 120 +# Prefer &&/|| over and/or. +Style/AndOr: + Enabled: true -Metrics/MethodLength: +# Do not use braces for hash literals when they are the last argument of a +# method call. +Style/BracesAroundHashParameters: + Enabled: true + +# Align `when` with `case`. +Layout/CaseIndentation: + Enabled: true + +# Align comments with method definitions. +Layout/CommentIndentation: + Enabled: true + +# No extra empty lines. +Layout/EmptyLines: + Enabled: true + +# Use Ruby >= 1.9 syntax for hashes. Prefer { a: :b } over { :a => :b }. +Style/HashSyntax: + Enabled: true + +# Two spaces, no tabs (for indentation). +Layout/IndentationWidth: + Enabled: true + +Layout/SpaceAfterColon: + Enabled: true + +Layout/SpaceAfterComma: + Enabled: true + +Layout/SpaceAroundEqualsInParameterDefault: + Enabled: true + +Layout/SpaceAroundKeyword: + Enabled: true + +Layout/SpaceAroundOperators: + Enabled: true + +Layout/SpaceBeforeFirstArg: + Enabled: true + +# Defining a method with parameters needs parentheses. +Style/MethodDefParentheses: + Enabled: true + +# Use `foo {}` not `foo{}`. +Layout/SpaceBeforeBlockBraces: + Enabled: true + +# Use `foo { bar }` not `foo {bar}`. +Layout/SpaceInsideBlockBraces: + Enabled: true + +# Use `{ a: 1 }` not `{a:1}`. +Layout/SpaceInsideHashLiteralBraces: + Enabled: true + +Layout/SpaceInsideParens: + Enabled: true + +# Detect hard tabs, no hard tabs. +Layout/Tab: + Enabled: true + +# Blank lines should not have any spaces. +Layout/TrailingBlankLines: + Enabled: true + +# No trailing whitespace. +Layout/TrailingWhitespace: + Enabled: true + +Lint/BlockAlignment: + Enabled: true + +# Align `end` with the matching keyword or starting expression except for +# assignments, where it should be aligned with the LHS. +Lint/EndAlignment: + Enabled: true + EnforcedStyleAlignWith: variable + +# Use my_method(my_arg) not my_method( my_arg ) or my_method my_arg. +Lint/RequireParentheses: + Enabled: true + +Layout/MultilineMethodCallIndentation: + Enabled: true + EnforcedStyle: indented + +Layout/AlignHash: + Enabled: true + +Bundler/OrderedGems: Enabled: false - -Style/Documentation: - Enabled: false - -Style/FrozenStringLiteralComment: - Enabled: False diff --git a/.travis.yml b/.travis.yml index 25827245817..dc66517428e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -36,7 +36,7 @@ cache: - vendor/bundle before_install: - - gem install bundler + - gem install bundler rubocop - git clone --depth=1 https://github.com/discourse/discourse-backup-uploads-to-s3.git plugins/discourse-backup-uploads-to-s3 - git clone --depth=1 https://github.com/discourse/discourse-spoiler-alert.git plugins/discourse-spoiler-alert - git clone --depth=1 https://github.com/discourse/discourse-cakeday.git plugins/discourse-cakeday @@ -48,6 +48,7 @@ before_install: - eslint --ext .es6 test/javascripts - eslint --ext .es6 plugins/**/assets/javascripts - eslint test/javascripts + - rubocop --parallel before_script: - bundle exec rake db:create db:migrate diff --git a/Gemfile b/Gemfile index 091bf3fd1eb..42e358e8e67 100644 --- a/Gemfile +++ b/Gemfile @@ -189,7 +189,6 @@ gem 'logster' gem 'sassc', require: false - if ENV["IMPORT"] == "1" gem 'mysql2' gem 'redcarpet' diff --git a/Rakefile b/Rakefile index 179ba560eb2..7a7f9ee44b3 100755 --- a/Rakefile +++ b/Rakefile @@ -9,4 +9,3 @@ Discourse::Application.load_tasks # this prevents crashes when migrating a database in production in certain # PostgreSQL configuations when trying to create structure.sql Rake::Task["db:structure:dump"].clear if Rails.env.production? - diff --git a/app/controllers/admin/badges_controller.rb b/app/controllers/admin/badges_controller.rb index e33a4765862..6fcdc7e7df4 100644 --- a/app/controllers/admin/badges_controller.rb +++ b/app/controllers/admin/badges_controller.rb @@ -5,9 +5,9 @@ class Admin::BadgesController < Admin::AdminController badge_types: BadgeType.all.order(:id).to_a, badge_groupings: BadgeGrouping.all.order(:position).to_a, badges: Badge.includes(:badge_grouping) - .includes(:badge_type) - .references(:badge_grouping) - .order('badge_groupings.position, badge_type_id, badges.name').to_a, + .includes(:badge_type) + .references(:badge_grouping) + .order('badge_groupings.position, badge_type_id, badges.name').to_a, protected_system_fields: Badge.protected_system_fields, triggers: Badge.trigger_hash } @@ -43,9 +43,9 @@ class Admin::BadgesController < Admin::AdminController badge_groupings = BadgeGrouping.all.order(:position).to_a ids = params[:ids].map(&:to_i) - params[:names].each_with_index do |name,index| + params[:names].each_with_index do |name, index| id = ids[index].to_i - group = badge_groupings.find{|b| b.id == id} || BadgeGrouping.new() + group = badge_groupings.find { |b| b.id == id } || BadgeGrouping.new() group.name = name group.position = index group.save @@ -95,7 +95,7 @@ class Admin::BadgesController < Admin::AdminController # Options: # :new - reset the badge id to nil before saving - def update_badge_from_params(badge, opts={}) + def update_badge_from_params(badge, opts = {}) errors = [] Badge.transaction do allowed = Badge.column_names.map(&:to_sym) @@ -112,7 +112,7 @@ class Admin::BadgesController < Admin::AdminController # Badge query contract checks begin if SiteSetting.enable_badge_sql - BadgeGranter.contract_checks!(badge.query, { target_posts: badge.target_posts, trigger: badge.trigger }) + BadgeGranter.contract_checks!(badge.query, target_posts: badge.target_posts, trigger: badge.trigger) end rescue => e errors << e.message diff --git a/app/controllers/admin/color_schemes_controller.rb b/app/controllers/admin/color_schemes_controller.rb index dda6c9f07ce..a070f2324d4 100644 --- a/app/controllers/admin/color_schemes_controller.rb +++ b/app/controllers/admin/color_schemes_controller.rb @@ -29,7 +29,6 @@ class Admin::ColorSchemesController < Admin::AdminController render json: success_json end - private def fetch_color_scheme diff --git a/app/controllers/admin/dashboard_controller.rb b/app/controllers/admin/dashboard_controller.rb index d7250ca8262..ed021d9158d 100644 --- a/app/controllers/admin/dashboard_controller.rb +++ b/app/controllers/admin/dashboard_controller.rb @@ -2,13 +2,13 @@ require 'disk_space' class Admin::DashboardController < Admin::AdminController def index dashboard_data = AdminDashboardData.fetch_cached_stats || Jobs::DashboardStats.new.execute({}) - dashboard_data.merge!({version_check: DiscourseUpdates.check_version.as_json}) if SiteSetting.version_checks? + dashboard_data.merge!(version_check: DiscourseUpdates.check_version.as_json) if SiteSetting.version_checks? dashboard_data[:disk_space] = DiskSpace.cached_stats render json: dashboard_data end def problems - render_json_dump({problems: AdminDashboardData.fetch_problems}) + render_json_dump(problems: AdminDashboardData.fetch_problems) end end diff --git a/app/controllers/admin/diagnostics_controller.rb b/app/controllers/admin/diagnostics_controller.rb index ba889837a34..8411e854845 100644 --- a/app/controllers/admin/diagnostics_controller.rb +++ b/app/controllers/admin/diagnostics_controller.rb @@ -42,8 +42,8 @@ class Admin::DiagnosticsController < Admin::AdminController GC.start(full_mark: true) require 'objspace' - io = File.open("discourse-heap-#{SecureRandom.hex(3)}.json",'w') - ObjectSpace.dump_all(:output => io) + io = File.open("discourse-heap-#{SecureRandom.hex(3)}.json", 'w') + ObjectSpace.dump_all(output: io) io.close render plain: "HEAP DUMP:\n#{io.path}" diff --git a/app/controllers/admin/email_controller.rb b/app/controllers/admin/email_controller.rb index 75e07bb22b6..a5030d06dd8 100644 --- a/app/controllers/admin/email_controller.rb +++ b/app/controllers/admin/email_controller.rb @@ -13,7 +13,7 @@ class Admin::EmailController < Admin::AdminController Jobs::TestEmail.new.execute(to_address: params[:email_address]) render nothing: true rescue => e - render json: {errors: [e.message]}, status: 422 + render json: { errors: [e.message] }, status: 422 end end @@ -55,17 +55,17 @@ class Admin::EmailController < Admin::AdminController params.require(:username) params.require(:email) user = User.find_by_username(params[:username]) - message, skip_reason = UserNotifications.send(:digest, user, {since: params[:last_seen_at]}) + message, skip_reason = UserNotifications.send(:digest, user, since: params[:last_seen_at]) if message message.to = params[:email] begin 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: 422 end else - render json: {errors: skip_reason} + render json: { errors: skip_reason } end end @@ -131,18 +131,18 @@ class Admin::EmailController < 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: 404 end end private def filter_email_logs(email_logs, params) - email_logs = email_logs.includes(:user, { post: :topic }) - .references(:user) - .order(created_at: :desc) - .offset(params[:offset] || 0) - .limit(50) + email_logs = email_logs.includes(:user, post: :topic) + .references(:user) + .order(created_at: :desc) + .offset(params[:offset] || 0) + .limit(50) email_logs = email_logs.where("users.username ILIKE ?", "%#{params[:user]}%") if params[:user].present? email_logs = email_logs.where("email_logs.to_address ILIKE ?", "%#{params[:address]}%") if params[:address].present? @@ -154,10 +154,10 @@ class Admin::EmailController < Admin::AdminController end def filter_incoming_emails(incoming_emails, params) - incoming_emails = incoming_emails.includes(:user, { post: :topic }) - .order(created_at: :desc) - .offset(params[:offset] || 0) - .limit(50) + incoming_emails = incoming_emails.includes(:user, post: :topic) + .order(created_at: :desc) + .offset(params[:offset] || 0) + .limit(50) incoming_emails = incoming_emails.where("from_address ILIKE ?", "%#{params[:from]}%") if params[:from].present? incoming_emails = incoming_emails.where("to_addresses ILIKE :to OR cc_addresses ILIKE :to", to: "%#{params[:to]}%") if params[:to].present? @@ -170,7 +170,7 @@ class Admin::EmailController < Admin::AdminController def delivery_settings action_mailer_settings .reject { |k, _| k == :password } - .map { |k, v| { name: k, value: v }} + .map { |k, v| { name: k, value: v } } end def delivery_method diff --git a/app/controllers/admin/emojis_controller.rb b/app/controllers/admin/emojis_controller.rb index 8bd3f36edec..47b78e83b4d 100644 --- a/app/controllers/admin/emojis_controller.rb +++ b/app/controllers/admin/emojis_controller.rb @@ -13,8 +13,8 @@ class Admin::EmojisController < Admin::AdminController Scheduler::Defer.later("Upload Emoji") do # fix the name name = name.gsub(/[^a-z0-9]+/i, '_') - .gsub(/_{2,}/, '_') - .downcase + .gsub(/_{2,}/, '_') + .downcase upload = UploadCreator.new( file.tempfile, @@ -61,4 +61,3 @@ class Admin::EmojisController < Admin::AdminController end end - diff --git a/app/controllers/admin/flags_controller.rb b/app/controllers/admin/flags_controller.rb index 1385f958d50..f986ecd43e7 100644 --- a/app/controllers/admin/flags_controller.rb +++ b/app/controllers/admin/flags_controller.rb @@ -10,11 +10,11 @@ class Admin::FlagsController < Admin::AdminController if posts.blank? render json: { posts: [], topics: [], users: [] } else - render json: MultiJson.dump({ + render json: MultiJson.dump( posts: posts, topics: serialize_data(topics, FlaggedTopicSerializer), users: serialize_data(users, FlaggedUserSerializer) - }) + ) end end diff --git a/app/controllers/admin/groups_controller.rb b/app/controllers/admin/groups_controller.rb index 3da78834fd4..7d54bb12634 100644 --- a/app/controllers/admin/groups_controller.rb +++ b/app/controllers/admin/groups_controller.rb @@ -11,7 +11,7 @@ class Admin::GroupsController < Admin::AdminController group = Group.find(params[:group_id].to_i) users_added = 0 if group.present? - users = (params[:users] || []).map {|u| u.downcase} + users = (params[:users] || []).map { |u| u.downcase } valid_emails = {} valid_usernames = {} @@ -162,7 +162,7 @@ class Admin::GroupsController < Admin::AdminController protected def can_not_modify_automatic - render json: {errors: I18n.t('groups.errors.can_not_modify_automatic')}, status: 422 + render json: { errors: I18n.t('groups.errors.can_not_modify_automatic') }, status: 422 end private diff --git a/app/controllers/admin/screened_ip_addresses_controller.rb b/app/controllers/admin/screened_ip_addresses_controller.rb index 31df2a6b8eb..1f4bc315657 100644 --- a/app/controllers/admin/screened_ip_addresses_controller.rb +++ b/app/controllers/admin/screened_ip_addresses_controller.rb @@ -46,7 +46,7 @@ class Admin::ScreenedIpAddressesController < Admin::AdminController def roll_up subnets = ScreenedIpAddress.roll_up(current_user) - render json: success_json.merge!({ subnets: subnets }) + render json: success_json.merge!(subnets: subnets) end private diff --git a/app/controllers/admin/site_settings_controller.rb b/app/controllers/admin/site_settings_controller.rb index 7f20c5d88e5..87478597a17 100644 --- a/app/controllers/admin/site_settings_controller.rb +++ b/app/controllers/admin/site_settings_controller.rb @@ -17,7 +17,7 @@ class Admin::SiteSettingsController < Admin::AdminController SiteSetting.set_and_log(id, value, current_user) render nothing: true rescue Discourse::InvalidParameters => e - render json: {errors: [e.message]}, status: 422 + render json: { errors: [e.message] }, status: 422 end end diff --git a/app/controllers/admin/site_texts_controller.rb b/app/controllers/admin/site_texts_controller.rb index 33c7b716fc3..8cdb0d9b196 100644 --- a/app/controllers/admin/site_texts_controller.rb +++ b/app/controllers/admin/site_texts_controller.rb @@ -14,7 +14,7 @@ class Admin::SiteTextsController < Admin::AdminController query = params[:q] || "" if query.blank? && !overridden extras[:recommended] = true - results = self.class.preferred_keys.map {|k| record_for(k) } + results = self.class.preferred_keys.map { |k| record_for(k) } else results = [] translations = I18n.search(query, overridden: overridden) @@ -69,14 +69,14 @@ class Admin::SiteTextsController < Admin::AdminController protected - def record_for(k, value=nil) + def record_for(k, value = nil) if k.ends_with?("_MF") ovr = TranslationOverride.where(translation_key: k).pluck(:value) value = ovr[0] if ovr.present? end value ||= I18n.t(k) - {id: k, value: value} + { id: k, value: value } end def find_site_text diff --git a/app/controllers/admin/staff_action_logs_controller.rb b/app/controllers/admin/staff_action_logs_controller.rb index 242cc4f4027..2e72e2b86f4 100644 --- a/app/controllers/admin/staff_action_logs_controller.rb +++ b/app/controllers/admin/staff_action_logs_controller.rb @@ -6,7 +6,7 @@ class Admin::StaffActionLogsController < Admin::AdminController staff_action_logs = UserHistory.staff_action_records(current_user, filters).to_a render json: StaffActionLogsSerializer.new({ staff_action_logs: staff_action_logs, - user_history_actions: UserHistory.staff_actions.sort.map{|name| {id: UserHistory.actions[name], name: name}} + user_history_actions: UserHistory.staff_actions.sort.map { |name| { id: UserHistory.actions[name], name: name } } }, root: false) end @@ -46,20 +46,18 @@ class Admin::StaffActionLogsController < Admin::AdminController cur: child_themes(cur) } - load_diff(diff_fields, :cur, cur) load_diff(diff_fields, :prev, prev) - diff_fields.delete_if{|k,v| v[:cur] == v[:prev]} + diff_fields.delete_if { |k, v| v[:cur] == v[:prev] } - - diff_fields.each do |k,v| + diff_fields.each do |k, v| output << "

#{k}

" diff = DiscourseDiff.new(v[:prev] || "", v[:cur] || "") output << diff.side_by_side_markdown end - render json: {side_by_side: output} + render json: { side_by_side: output } end protected @@ -67,11 +65,11 @@ class Admin::StaffActionLogsController < Admin::AdminController def child_themes(theme) return "" unless children = theme["child_themes"] - children.map{|row| row["name"]}.join(" ").to_s + children.map { |row| row["name"] }.join(" ").to_s end def load_diff(hash, key, val) - if f=val["theme_fields"] + if f = val["theme_fields"] f.each do |row| entry = hash[row["target"] + " " + row["name"]] ||= {} entry[key] = row["value"] diff --git a/app/controllers/admin/themes_controller.rb b/app/controllers/admin/themes_controller.rb index d6adf207411..4b8a8c58359 100644 --- a/app/controllers/admin/themes_controller.rb +++ b/app/controllers/admin/themes_controller.rb @@ -62,7 +62,7 @@ class Admin::ThemesController < Admin::AdminController } respond_to do |format| - format.json { render json: payload} + format.json { render json: payload } end end @@ -77,7 +77,7 @@ class Admin::ThemesController < Admin::AdminController if @theme.save update_default_theme log_theme_change(nil, @theme) - format.json { render json: @theme, status: :created} + format.json { render json: @theme, status: :created } else format.json { render json: @theme.errors, status: :unprocessable_entity } end @@ -100,7 +100,7 @@ class Admin::ThemesController < Admin::AdminController @theme.child_theme_relation.to_a.each do |child| if expected.include?(child.child_theme_id) - expected.reject!{|id| id == child.child_theme_id} + expected.reject! { |id| id == child.child_theme_id } else child.destroy end @@ -133,12 +133,12 @@ class Admin::ThemesController < Admin::AdminController update_default_theme log_theme_change(original_json, @theme) - format.json { render json: @theme, status: :created} + format.json { render json: @theme, status: :created } else format.json { error = @theme.errors[:color_scheme] ? I18n.t("themes.bad_color_scheme") : I18n.t("themes.other_error") - render json: {errors: [ error ]}, status: :unprocessable_entity + render json: { errors: [ error ] }, status: :unprocessable_entity } end end @@ -192,13 +192,14 @@ class Admin::ThemesController < Admin::AdminController begin # deep munge is a train wreck, work around it for now params[:theme][:child_theme_ids] ||= [] if params[:theme].key?(:child_theme_ids) - params.require(:theme) - .permit(:name, - :color_scheme_id, - :default, - :user_selectable, - theme_fields: [:name, :target, :value, :upload_id, :type_id], - child_theme_ids: []) + params.require(:theme).permit( + :name, + :color_scheme_id, + :default, + :user_selectable, + theme_fields: [:name, :target, :value, :upload_id, :type_id], + child_theme_ids: [] + ) end end diff --git a/app/controllers/admin/user_fields_controller.rb b/app/controllers/admin/user_fields_controller.rb index 596b53e4ee1..2af8832e333 100644 --- a/app/controllers/admin/user_fields_controller.rb +++ b/app/controllers/admin/user_fields_controller.rb @@ -51,8 +51,7 @@ class Admin::UserFieldsController < Admin::AdminController options = params[:user_field][:options] if options.present? UserFieldOption.where(user_field_id: field.id).delete_all - field.user_field_options_attributes = options.map {|o| {value: o} }.uniq + field.user_field_options_attributes = options.map { |o| { value: o } }.uniq end end end - diff --git a/app/controllers/admin/users_controller.rb b/app/controllers/admin/users_controller.rb index 5db8236745c..f1f85fe82a2 100644 --- a/app/controllers/admin/users_controller.rb +++ b/app/controllers/admin/users_controller.rb @@ -77,7 +77,7 @@ class Admin::UsersController < Admin::AdminController @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: 404 end end @@ -154,8 +154,7 @@ class Admin::UsersController < Admin::AdminController guardian.ensure_can_change_trust_level!(@user) level = params[:level].to_i - - if !@user.trust_level_locked && [0,1,2].include?(level) && Promotion.send("tl#{level+1}_met?", @user) + if !@user.trust_level_locked && [0, 1, 2].include?(level) && Promotion.send("tl#{level + 1}_met?", @user) @user.trust_level_locked = true @user.save end @@ -187,7 +186,7 @@ class Admin::UsersController < Admin::AdminController unless @user.trust_level_locked p = Promotion.new(@user) - 2.times{ p.review } + 2.times { p.review } p.review_tl2 if @user.trust_level == 3 && Promotion.tl3_lost?(@user) @user.change_trust_level!(2, log_action_for: current_user) @@ -242,7 +241,7 @@ class Admin::UsersController < Admin::AdminController d = UserDestroyer.new(current_user) User.where(id: params[:users]).each do |u| - success_count += 1 if guardian.can_delete_user?(u) and d.destroy(u, params.slice(:context)) rescue UserDestroyer::PostsExistError + success_count += 1 if guardian.can_delete_user?(u) && d.destroy(u, params.slice(:context)) rescue UserDestroyer::PostsExistError end render json: { @@ -339,12 +338,12 @@ class Admin::UsersController < Admin::AdminController user.save! user.grant_admin! user.change_trust_level!(4) - user.email_tokens.update_all confirmed: true + user.email_tokens.update_all confirmed: true email_token = user.email_tokens.create(email: user.email) unless params[:send_email] == '0' || params[:send_email] == 'false' - Jobs.enqueue( :critical_user_email, + Jobs.enqueue(:critical_user_email, type: :account_created, user_id: user.id, email_token: email_token.token) diff --git a/app/controllers/admin/watched_words_controller.rb b/app/controllers/admin/watched_words_controller.rb index a2f777d8f55..119562dc4e0 100644 --- a/app/controllers/admin/watched_words_controller.rb +++ b/app/controllers/admin/watched_words_controller.rb @@ -28,7 +28,7 @@ class Admin::WatchedWordsController < Admin::AdminController File.open(file.tempfile, encoding: "ISO-8859-1").each_line do |line| WatchedWord.create_or_update_word(word: line, action_key: action_key) unless line.empty? end - data = {url: '/ok'} + data = { url: '/ok' } rescue => e data = failed_json.merge(errors: [e.message]) end diff --git a/app/controllers/admin/web_hooks_controller.rb b/app/controllers/admin/web_hooks_controller.rb index 4deb554c8b7..c3b2cfe9ef0 100644 --- a/app/controllers/admin/web_hooks_controller.rb +++ b/app/controllers/admin/web_hooks_controller.rb @@ -6,10 +6,10 @@ class Admin::WebHooksController < Admin::AdminController offset = params[:offset].to_i web_hooks = WebHook.limit(limit) - .offset(offset) - .includes(:web_hook_event_types) - .includes(:categories) - .includes(:groups) + .offset(offset) + .includes(:web_hook_event_types) + .includes(:categories) + .includes(:groups) json = { web_hooks: serialize_data(web_hooks, AdminWebHookSerializer), diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 7527f4a9ba0..1484df2603b 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -147,7 +147,7 @@ class ApplicationController < ActionController::Base render_json_error I18n.t('read_only_mode_enabled'), type: :read_only, status: 503 end - def rescue_discourse_actions(type, status_code, include_ember=false) + def rescue_discourse_actions(type, status_code, include_ember = false) show_json_errors = (request.format && request.format.json?) || (request.xhr?) || @@ -175,7 +175,7 @@ class ApplicationController < ActionController::Base def set_current_user_for_logs if current_user - Logster.add_to_env(request.env,"username",current_user.username) + Logster.add_to_env(request.env, "username", current_user.username) response.headers["X-Discourse-Username"] = current_user.username end response.headers["X-Discourse-Route"] = "#{controller_name}/#{action_name}" @@ -298,9 +298,9 @@ class ApplicationController < ActionController::Base current_user ? SiteSetting.homepage : SiteSetting.anonymous_homepage end - def serialize_data(obj, serializer, opts=nil) + def serialize_data(obj, serializer, opts = nil) # If it's an array, apply the serializer as an each_serializer to the elements - serializer_opts = {scope: guardian}.merge!(opts || {}) + serializer_opts = { scope: guardian }.merge!(opts || {}) if obj.respond_to?(:to_ary) serializer_opts[:each_serializer] = serializer ActiveModel::ArraySerializer.new(obj.to_ary, serializer_opts).as_json @@ -313,11 +313,11 @@ class ApplicationController < ActionController::Base # 20% slower than calling MultiJSON.dump ourselves. I'm not sure why # Rails doesn't call MultiJson.dump when you pass it json: obj but # it seems we don't need whatever Rails is doing. - def render_serialized(obj, serializer, opts=nil) + def render_serialized(obj, serializer, opts = nil) render_json_dump(serialize_data(obj, serializer, opts), opts) end - def render_json_dump(obj, opts=nil) + def render_json_dump(obj, opts = nil) opts ||= {} if opts[:rest_serializer] obj['__rest_serializer'] = "1" @@ -341,7 +341,7 @@ class ApplicationController < ActionController::Base Middleware::AnonymousCache.anon_cache(request.env, time_length) end - def fetch_user_from_params(opts=nil, eager_load = []) + def fetch_user_from_params(opts = nil, eager_load = []) opts ||= {} user = if params[:username] username_lower = params[:username].downcase.chomp('.json') @@ -361,9 +361,9 @@ class ApplicationController < ActionController::Base end def post_ids_including_replies - post_ids = params[:post_ids].map {|p| p.to_i} + post_ids = params[:post_ids].map { |p| p.to_i } if params[:reply_post_ids] - post_ids |= PostReply.where(post_id: params[:reply_post_ids].map {|p| p.to_i}).pluck(:reply_id) + post_ids |= PostReply.where(post_id: params[:reply_post_ids].map { |p| p.to_i }).pluck(:reply_id) end post_ids end @@ -394,7 +394,6 @@ class ApplicationController < ActionController::Base end end - def secure_session SecureSession.new(session["secure_session_id"] ||= SecureRandom.hex) end @@ -433,14 +432,16 @@ class ApplicationController < ActionController::Base def custom_html_json target = view_context.mobile_view? ? :mobile : :desktop - data = if @theme_key - { - top: Theme.lookup_field(@theme_key, target, "after_header"), - footer: Theme.lookup_field(@theme_key, target, "footer") - } - else - {} - end + + data = + if @theme_key + { + top: Theme.lookup_field(@theme_key, target, "after_header"), + footer: Theme.lookup_field(@theme_key, target, "footer") + } + else + {} + end if DiscoursePluginRegistry.custom_html data.merge! DiscoursePluginRegistry.custom_html @@ -480,7 +481,7 @@ class ApplicationController < ActionController::Base # opts: # type - a machine-readable description of the error # status - HTTP status code to return - def render_json_error(obj, opts={}) + def render_json_error(obj, opts = {}) opts = { status: opts } if opts.is_a?(Integer) render json: MultiJson.dump(create_errors_json(obj, opts[:type])), status: opts[:status] || 422 end @@ -493,7 +494,7 @@ class ApplicationController < ActionController::Base { failed: 'FAILED' } end - def json_result(obj, opts={}) + def json_result(obj, opts = {}) if yield(obj) json = success_json @@ -574,21 +575,20 @@ class ApplicationController < ActionController::Base raise Discourse::ReadOnly.new if !(request.get? || request.head?) && Discourse.readonly_mode? end - def build_not_found_page(status=404, layout=false) + def build_not_found_page(status = 404, layout = false) category_topic_ids = Category.pluck(:topic_id).compact @container_class = "wrap not-found-container" - @top_viewed = TopicQuery.new(nil, {except_topic_ids: category_topic_ids}).list_top_for("monthly").topics.first(10) + @top_viewed = TopicQuery.new(nil, except_topic_ids: category_topic_ids).list_top_for("monthly").topics.first(10) @recent = Topic.where.not(id: category_topic_ids).recent(10) @slug = params[:slug].class == String ? params[:slug] : '' @slug = (params[:id].class == String ? params[:id] : '') if @slug.blank? - @slug.tr!('-',' ') + @slug.tr!('-', ' ') render_to_string status: status, layout: layout, formats: [:html], template: '/exceptions/not_found' end - protected - def render_post_json(post, add_raw=true) + def render_post_json(post, add_raw = true) post_serializer = PostSerializer.new(post, scope: guardian, root: false) post_serializer.add_raw = add_raw diff --git a/app/controllers/badges_controller.rb b/app/controllers/badges_controller.rb index 432489a3d43..6447558befe 100644 --- a/app/controllers/badges_controller.rb +++ b/app/controllers/badges_controller.rb @@ -14,7 +14,7 @@ class BadgesController < ApplicationController if (params[:only_listable] == "true") || !request.xhr? # NOTE: this is sorted client side if needed badges = badges.includes(:badge_grouping) - .where(enabled: true, listable: true) + .where(enabled: true, listable: true) end diff --git a/app/controllers/categories_controller.rb b/app/controllers/categories_controller.rb index c2da87bac4a..51e8e088528 100644 --- a/app/controllers/categories_controller.rb +++ b/app/controllers/categories_controller.rb @@ -218,7 +218,7 @@ class CategoriesController < ApplicationController end if p = params[:permissions] - p.each do |k,v| + p.each do |k, v| p[k] = v.to_i end end @@ -250,10 +250,10 @@ class CategoriesController < ApplicationController :default_view, :subcategory_list_style, :default_top_period, - :custom_fields => [params[:custom_fields].try(:keys)], - :permissions => [*p.try(:keys)], - :allowed_tags => [], - :allowed_tag_groups => []) + custom_fields: [params[:custom_fields].try(:keys)], + permissions: [*p.try(:keys)], + allowed_tags: [], + allowed_tag_groups: []) end end @@ -265,7 +265,7 @@ class CategoriesController < ApplicationController @staff_action_logger = StaffActionLogger.new(current_user) end - def include_topics(parent_category=nil) + def include_topics(parent_category = nil) view_context.mobile_view? || params[:include_topics] || (parent_category && parent_category.subcategory_list_includes_topics?) || diff --git a/app/controllers/clicks_controller.rb b/app/controllers/clicks_controller.rb index 4d7e186b0eb..23b1684f2b5 100644 --- a/app/controllers/clicks_controller.rb +++ b/app/controllers/clicks_controller.rb @@ -8,7 +8,7 @@ class ClicksController < ApplicationController params = track_params.merge(ip: request.remote_ip) if params[:topic_id].present? || params[:post_id].present? - params.merge!({ user_id: current_user.id }) if current_user.present? + params.merge!(user_id: current_user.id) if current_user.present? @redirect_url = TopicLinkClick.create_from(params) end diff --git a/app/controllers/composer_messages_controller.rb b/app/controllers/composer_messages_controller.rb index ff1a51d2bd2..62f86b05835 100644 --- a/app/controllers/composer_messages_controller.rb +++ b/app/controllers/composer_messages_controller.rb @@ -11,7 +11,7 @@ class ComposerMessagesController < ApplicationController if params[:topic_id].present? topic = Topic.where(id: params[:topic_id]).first if guardian.can_see?(topic) - json[:extras] = {duplicate_lookup: TopicLink.duplicate_lookup(topic)} + json[:extras] = { duplicate_lookup: TopicLink.duplicate_lookup(topic) } end end diff --git a/app/controllers/directory_items_controller.rb b/app/controllers/directory_items_controller.rb index 6158534b400..22c723c1e7a 100644 --- a/app/controllers/directory_items_controller.rb +++ b/app/controllers/directory_items_controller.rb @@ -53,7 +53,7 @@ class DirectoryItemsController < ApplicationController # Put yourself at the top of the first page if result.present? && current_user.present? && page == 0 - position = result.index {|r| r.user_id == current_user.id } + position = result.index { |r| r.user_id == current_user.id } # Don't show the record unless you're not in the top positions already if (position || 10) >= 10 diff --git a/app/controllers/draft_controller.rb b/app/controllers/draft_controller.rb index 7af211db564..4e7a0437479 100644 --- a/app/controllers/draft_controller.rb +++ b/app/controllers/draft_controller.rb @@ -5,7 +5,7 @@ class DraftController < ApplicationController def show seq = params[:sequence] || DraftSequence.current(current_user, params[:draft_key]) - render json: {draft: Draft.get(current_user, params[:draft_key], seq), draft_sequence: seq} + render json: { draft: Draft.get(current_user, params[:draft_key], seq), draft_sequence: seq } end def update diff --git a/app/controllers/email_controller.rb b/app/controllers/email_controller.rb index c7eace9c02f..771e6e1b37a 100644 --- a/app/controllers/email_controller.rb +++ b/app/controllers/email_controller.rb @@ -31,8 +31,8 @@ class EmailController < ApplicationController if @topic.category_id if CategoryUser.exists?(user_id: @user.id, notification_level: CategoryUser.watching_levels, category_id: @topic.category_id) @watched_count = TopicUser.joins(:topic) - .where(user: @user, notification_level: watching, "topics.category_id" => @topic.category_id) - .count + .where(user: @user, notification_level: watching, "topics.category_id" => @topic.category_id) + .count end end end @@ -52,28 +52,28 @@ class EmailController < ApplicationController if topic if params["unwatch_topic"] TopicUser.where(topic_id: topic.id, user_id: user.id) - .update_all(notification_level: TopicUser.notification_levels[:tracking]) + .update_all(notification_level: TopicUser.notification_levels[:tracking]) updated = true end if params["unwatch_category"] && topic.category_id TopicUser.joins(:topic) - .where(:user => user, - :notification_level => TopicUser.notification_levels[:watching], - "topics.category_id" => topic.category_id) - .update_all(notification_level: TopicUser.notification_levels[:tracking]) + .where(:user => user, + :notification_level => TopicUser.notification_levels[:watching], + "topics.category_id" => topic.category_id) + .update_all(notification_level: TopicUser.notification_levels[:tracking]) CategoryUser.where(user_id: user.id, - category_id: topic.category_id, - notification_level: CategoryUser.watching_levels + category_id: topic.category_id, + notification_level: CategoryUser.watching_levels ) - .destroy_all + .destroy_all updated = true end if params["mute_topic"] TopicUser.where(topic_id: topic.id, user_id: user.id) - .update_all(notification_level: TopicUser.notification_levels[:muted]) + .update_all(notification_level: TopicUser.notification_levels[:muted]) updated = true end end @@ -90,9 +90,9 @@ class EmailController < ApplicationController if params["unsubscribe_all"] user.user_option.update_columns(email_always: false, - email_digests: false, - email_direct: false, - email_private_messages: false) + email_digests: false, + email_direct: false, + email_private_messages: false) updated = true end diff --git a/app/controllers/embed_controller.rb b/app/controllers/embed_controller.rb index f64cc8035c7..d7da707d98d 100644 --- a/app/controllers/embed_controller.rb +++ b/app/controllers/embed_controller.rb @@ -74,7 +74,7 @@ class EmbedController < ApplicationController by_url = {} if embed_urls.present? - urls = embed_urls.map {|u| u.sub(/#discourse-comments$/, '').sub(/\/$/, '') } + urls = embed_urls.map { |u| u.sub(/#discourse-comments$/, '').sub(/\/$/, '') } topic_embeds = TopicEmbed.where(embed_url: urls).includes(:topic).references(:topic) topic_embeds.each do |te| @@ -88,7 +88,7 @@ class EmbedController < ApplicationController end end - render json: {counts: by_url}, callback: params[:callback] + render json: { counts: by_url }, callback: params[:callback] end private @@ -96,7 +96,7 @@ class EmbedController < ApplicationController def get_embeddable_css_class @embeddable_css_class = "" embeddable_host = EmbeddableHost.record_for_url(request.referer) - @embeddable_css_class = " class=\"#{embeddable_host.class_name}\"" if embeddable_host.present? and embeddable_host.class_name.present? + @embeddable_css_class = " class=\"#{embeddable_host.class_name}\"" if embeddable_host.present? && embeddable_host.class_name.present? end def ensure_api_request @@ -114,5 +114,4 @@ class EmbedController < ApplicationController raise Discourse::InvalidAccess.new('invalid referer host') end - end diff --git a/app/controllers/groups_controller.rb b/app/controllers/groups_controller.rb index 46a69b6be4f..504dc251371 100644 --- a/app/controllers/groups_controller.rb +++ b/app/controllers/groups_controller.rb @@ -124,13 +124,13 @@ class GroupsController < ApplicationController members = group.users .order('NOT group_users.owner') .order(order) - .order(:username_lower => dir) + .order(username_lower: dir) .limit(limit) .offset(offset) owners = group.users .order(order) - .order(:username_lower => dir) + .order(username_lower: dir) .where('group_users.owner') render json: { @@ -274,8 +274,8 @@ class GroupsController < ApplicationController end GroupUser.where(group_id: group.id) - .where(user_id: user_id) - .update_all(notification_level: notification_level) + .where(user_id: user_id) + .update_all(notification_level: notification_level) render json: success_json end diff --git a/app/controllers/highlight_js_controller.rb b/app/controllers/highlight_js_controller.rb index 86137be56ea..19a83c4a766 100644 --- a/app/controllers/highlight_js_controller.rb +++ b/app/controllers/highlight_js_controller.rb @@ -26,4 +26,3 @@ class HighlightJsController < ApplicationController end end end - diff --git a/app/controllers/invites_controller.rb b/app/controllers/invites_controller.rb index 42ab4ca712e..a892c50cfc4 100644 --- a/app/controllers/invites_controller.rb +++ b/app/controllers/invites_controller.rb @@ -16,11 +16,12 @@ class InvitesController < ApplicationController invite = Invite.find_by(invite_key: params[:id]) if invite.present? - store_preloaded("invite_info", MultiJson.dump({ + store_preloaded("invite_info", MultiJson.dump( invited_by: UserNameSerializer.new(invite.invited_by, scope: guardian, root: false), email: invite.email, - username: UserNameSuggester.suggest(invite.email) - })) + username: UserNameSuggester.suggest(invite.email)) + ) + render layout: 'application' else flash.now[:error] = I18n.t('invite.not_found') @@ -81,7 +82,7 @@ class InvitesController < ApplicationController render json: failed_json, status: 422 end rescue Invite::UserExists, ActiveRecord::RecordInvalid => e - render json: {errors: [e.message]}, status: 422 + render json: { errors: [e.message] }, status: 422 end end @@ -110,7 +111,7 @@ class InvitesController < ApplicationController render json: failed_json, status: 422 end rescue => e - render json: {errors: [e.message]}, status: 422 + render json: { errors: [e.message] }, status: 422 end end @@ -163,7 +164,7 @@ class InvitesController < ApplicationController data = if extension.downcase == ".csv" path = Invite.create_csv(file, name) Jobs.enqueue(:bulk_invite, filename: "#{name}#{extension}", current_user_id: current_user.id) - {url: path} + { url: path } else failed_json.merge(errors: [I18n.t("bulk_invite.file_should_be_csv")]) end diff --git a/app/controllers/list_controller.rb b/app/controllers/list_controller.rb index 66e59247f93..65635e54293 100644 --- a/app/controllers/list_controller.rb +++ b/app/controllers/list_controller.rb @@ -205,7 +205,7 @@ class ListController < ApplicationController render 'list', formats: [:rss] end - def top(options=nil) + def top(options = nil) options ||= {} period = ListController.best_period_for(current_user.try(:previous_visit_at), options[:category]) send("top_#{period}", options) @@ -308,7 +308,7 @@ class ListController < ApplicationController parent_category_id = nil if parent_slug_or_id.present? parent_category_id = Category.query_parent_category(parent_slug_or_id) - permalink_redirect_or_not_found and return if parent_category_id.blank? && !id + permalink_redirect_or_not_found && (return) if parent_category_id.blank? && !id end @category = Category.query_category(slug_or_id, parent_category_id) @@ -319,7 +319,7 @@ class ListController < ApplicationController (redirect_to category.url, status: 301) && return if category end - permalink_redirect_or_not_found and return if !@category + permalink_redirect_or_not_found && (return) if !@category @description_meta = @category.description_text raise Discourse::NotFound unless guardian.can_see?(@category) @@ -362,23 +362,23 @@ class ListController < ApplicationController else # :next public_send(method, opts.merge(next_page_params(opts))) end - url.sub('.json?','?') + url.sub('.json?', '?') end - def get_excluded_category_ids(current_category=nil) + def get_excluded_category_ids(current_category = nil) exclude_category_ids = Category.where(suppress_from_homepage: true) exclude_category_ids = exclude_category_ids.where.not(id: current_category) if current_category exclude_category_ids.pluck(:id) end - def self.best_period_for(previous_visit_at, category_id=nil) + def self.best_period_for(previous_visit_at, category_id = nil) default_period = ((category_id && Category.where(id: category_id).pluck(:default_top_period).first) || SiteSetting.top_page_default_timeframe).to_sym best_period_with_topics_for(previous_visit_at, category_id, default_period) || default_period end - def self.best_period_with_topics_for(previous_visit_at, category_id=nil, default_period=SiteSetting.top_page_default_timeframe) + def self.best_period_with_topics_for(previous_visit_at, category_id = nil, default_period = SiteSetting.top_page_default_timeframe) best_periods_for(previous_visit_at, default_period.to_sym).each do |period| top_topics = TopTopic.where("#{period}_score > 0") top_topics = top_topics.joins(:topic).where("topics.category_id = ?", category_id) if category_id @@ -389,12 +389,12 @@ class ListController < ApplicationController false end - def self.best_periods_for(date, default_period=:all) + def self.best_periods_for(date, default_period = :all) date ||= 1.year.ago periods = [] periods << default_period if :all != default_period - periods << :daily if :daily != default_period && date > 8.days.ago - periods << :weekly if :weekly != default_period && date > 35.days.ago + periods << :daily if :daily != default_period && date > 8.days.ago + periods << :weekly if :weekly != default_period && date > 35.days.ago periods << :monthly if :monthly != default_period && date > 180.days.ago periods << :yearly if :yearly != default_period periods diff --git a/app/controllers/metadata_controller.rb b/app/controllers/metadata_controller.rb index 04a5eaafd49..c297ed18bd7 100644 --- a/app/controllers/metadata_controller.rb +++ b/app/controllers/metadata_controller.rb @@ -31,7 +31,7 @@ class MetadataController < ApplicationController } if SiteSetting.native_app_install_banner - manifest = manifest.merge({ + manifest = manifest.merge( prefer_related_applications: true, related_applications: [ { @@ -39,7 +39,7 @@ class MetadataController < ApplicationController id: "com.discourse" } ] - }) + ) end manifest diff --git a/app/controllers/notifications_controller.rb b/app/controllers/notifications_controller.rb index 1415f78f573..7f6b95ca535 100644 --- a/app/controllers/notifications_controller.rb +++ b/app/controllers/notifications_controller.rb @@ -37,9 +37,9 @@ class NotificationsController < ApplicationController offset = params[:offset].to_i notifications = Notification.where(user_id: user.id) - .visible - .includes(:topic) - .order(created_at: :desc) + .visible + .includes(:topic) + .order(created_at: :desc) total_rows = notifications.dup.count notifications = notifications.offset(offset).limit(60) diff --git a/app/controllers/post_action_users_controller.rb b/app/controllers/post_action_users_controller.rb index e9e6c054805..46b6328d612 100644 --- a/app/controllers/post_action_users_controller.rb +++ b/app/controllers/post_action_users_controller.rb @@ -12,10 +12,9 @@ class PostActionUsersController < ApplicationController post = finder.first guardian.ensure_can_see!(post) - post_actions = post.post_actions.where(post_action_type_id: post_action_type_id) - .includes(:user) - .order('post_actions.created_at asc') + .includes(:user) + .order('post_actions.created_at asc') if !guardian.can_see_post_actors?(post.topic, post_action_type_id) if !current_user diff --git a/app/controllers/posts_controller.rb b/app/controllers/posts_controller.rb index 5e18b575203..1794ddded0b 100644 --- a/app/controllers/posts_controller.rb +++ b/app/controllers/posts_controller.rb @@ -41,23 +41,23 @@ class PostsController < ApplicationController if params[:id] == "private_posts" raise Discourse::NotFound if current_user.nil? posts = Post.private_posts - .order(created_at: :desc) - .where('posts.id <= ?', last_post_id) - .where('posts.id > ?', last_post_id - 50) - .includes(topic: :category) - .includes(user: :primary_group) - .includes(:reply_to_user) - .limit(50) + .order(created_at: :desc) + .where('posts.id <= ?', last_post_id) + .where('posts.id > ?', last_post_id - 50) + .includes(topic: :category) + .includes(user: :primary_group) + .includes(:reply_to_user) + .limit(50) rss_description = I18n.t("rss_description.private_posts") else posts = Post.public_posts - .order(created_at: :desc) - .where('posts.id <= ?', last_post_id) - .where('posts.id > ?', last_post_id - 50) - .includes(topic: :category) - .includes(user: :primary_group) - .includes(:reply_to_user) - .limit(50) + .order(created_at: :desc) + .where('posts.id <= ?', last_post_id) + .where('posts.id > ?', last_post_id - 50) + .includes(topic: :category) + .includes(user: :primary_group) + .includes(:reply_to_user) + .limit(50) rss_description = I18n.t("rss_description.posts") end @@ -92,12 +92,12 @@ class PostsController < ApplicationController user = fetch_user_from_params posts = Post.public_posts - .where(user_id: user.id) - .where(post_type: Post.types[:regular]) - .order(created_at: :desc) - .includes(:user) - .includes(topic: :category) - .limit(50) + .where(user_id: user.id) + .where(post_type: Post.types[:regular]) + .order(created_at: :desc) + .includes(:user) + .includes(topic: :category) + .limit(50) posts = posts.reject { |post| !guardian.can_see?(post) || post.topic.blank? } @@ -230,20 +230,20 @@ class PostsController < ApplicationController RateLimiter.new(current_user, "delete_post", 3, 1.minute).performed! unless current_user.staff? if too_late_to(:delete_post, post) - render json: {errors: [I18n.t('too_late_to_edit')]}, status: 422 + render json: { errors: [I18n.t('too_late_to_edit')] }, status: 422 return end guardian.ensure_can_delete!(post) - destroyer = PostDestroyer.new(current_user, post, { context: params[:context] }) + destroyer = PostDestroyer.new(current_user, post, context: params[:context]) destroyer.destroy render nothing: true end def expand_embed - render json: {cooked: TopicEmbed.expanded_for(find_post_from_params) } + render json: { cooked: TopicEmbed.expanded_for(find_post_from_params) } rescue render_json_error I18n.t('errors.embed.load_from_remote') end @@ -266,10 +266,10 @@ class PostsController < ApplicationController raise Discourse::InvalidParameters.new(:post_ids) if posts.blank? # Make sure we can delete the posts - posts.each {|p| guardian.ensure_can_delete!(p) } + posts.each { |p| guardian.ensure_can_delete!(p) } Post.transaction do - posts.each {|p| PostDestroyer.new(current_user, p).destroy } + posts.each { |p| PostDestroyer.new(current_user, p).destroy } end render nothing: true @@ -399,7 +399,7 @@ class PostsController < ApplicationController post = find_post_from_params guardian.ensure_can_wiki!(post) - post.revise(current_user, { wiki: params[:wiki] }) + post.revise(current_user, wiki: params[:wiki]) render nothing: true end @@ -408,7 +408,7 @@ class PostsController < ApplicationController guardian.ensure_can_change_post_type! post = find_post_from_params - post.revise(current_user, { post_type: params[:post_type].to_i }) + post.revise(current_user, post_type: params[:post_type].to_i) render nothing: true end @@ -441,7 +441,7 @@ class PostsController < ApplicationController limit = [(params[:limit] || 60).to_i, 100].min posts = user_posts(guardian, user.id, offset: offset, limit: limit) - .where(id: PostAction.where(post_action_type_id: PostActionType.notify_flag_type_ids) + .where(id: PostAction.where(post_action_type_id: PostActionType.notify_flag_type_ids) .where(disagreed_at: nil) .select(:post_id)) @@ -479,7 +479,6 @@ class PostsController < ApplicationController render json: json_obj, status: (!!success) ? 200 : 422 end - def find_post_revision_from_params post_id = params[:id] || params[:post_id] revision = params[:revision].to_i @@ -529,9 +528,9 @@ class PostsController < ApplicationController def user_posts(guardian, user_id, opts) posts = Post.includes(:user, :topic, :deleted_by, :user_actions) - .where(user_id: user_id) - .with_deleted - .order(created_at: :desc) + .where(user_id: user_id) + .with_deleted + .order(created_at: :desc) if guardian.user.moderator? @@ -545,7 +544,7 @@ class PostsController < ApplicationController end posts.offset(opts[:offset]) - .limit(opts[:limit]) + .limit(opts[:limit]) end def create_params @@ -622,7 +621,7 @@ class PostsController < ApplicationController "post##" << Digest::SHA1.hexdigest(args .to_a .concat([["user", current_user.id]]) - .sort{|x,y| x[0] <=> y[0]}.join do |x,y| + .sort { |x, y| x[0] <=> y[0] }.join do |x, y| "#{x}:#{y}" end) end diff --git a/app/controllers/queued_posts_controller.rb b/app/controllers/queued_posts_controller.rb index 6b225b5e65c..888ef0ddc2a 100644 --- a/app/controllers/queued_posts_controller.rb +++ b/app/controllers/queued_posts_controller.rb @@ -41,18 +41,17 @@ class QueuedPostsController < ApplicationController render_serialized(qp, QueuedPostSerializer, root: :queued_posts) end - private def user_deletion_opts base = { - context: I18n.t('queue.delete_reason', {performed_by: current_user.username}), + context: I18n.t('queue.delete_reason', performed_by: current_user.username), delete_posts: true, delete_as_spammer: true } if Rails.env.production? && ENV["Staging"].nil? - base.merge!({block_email: true, block_ip: true}) + base.merge!(block_email: true, block_ip: true) end base diff --git a/app/controllers/search_controller.rb b/app/controllers/search_controller.rb index 60d63488aa0..a348ac7505b 100644 --- a/app/controllers/search_controller.rb +++ b/app/controllers/search_controller.rb @@ -98,7 +98,7 @@ class SearchController < ApplicationController search_context = params[:search_context] unless search_context if (context = params[:context]) && (id = params[:context_id]) - search_context = {type: context, id: id} + search_context = { type: context, id: id } end end @@ -108,7 +108,7 @@ class SearchController < ApplicationController # A user is found by username context_obj = nil - if ['user','private_messages'].include? search_context[:type] + if ['user', 'private_messages'].include? search_context[:type] context_obj = User.find_by(username_lower: search_context[:id].downcase) elsif 'category' == search_context[:type] context_obj = Category.find_by(id: search_context[:id].to_i) diff --git a/app/controllers/session_controller.rb b/app/controllers/session_controller.rb index 96259d430d4..60d30691512 100644 --- a/app/controllers/session_controller.rb +++ b/app/controllers/session_controller.rb @@ -9,7 +9,7 @@ class SessionController < ApplicationController ACTIVATE_USER_KEY = "activate_user" def csrf - render json: {csrf: form_authenticity_token } + render json: { csrf: form_authenticity_token } end def sso @@ -35,7 +35,7 @@ class SessionController < ApplicationController end end - def sso_provider(payload=nil) + def sso_provider(payload = nil) payload ||= request.query_string if SiteSetting.enable_sso_provider sso = SingleSignOn.parse(payload, SiteSetting.sso_secret) @@ -112,7 +112,7 @@ class SessionController < ApplicationController activation = UserActivator.new(user, request, session, cookies) activation.finish session["user_created_message"] = activation.message - redirect_to users_account_created_path and return + redirect_to(users_account_created_path) && (return) else if SiteSetting.verbose_sso_logging Rails.logger.warn("Verbose SSO log: User was logged on #{user.username}\n\n#{sso.diagnostics}") @@ -292,11 +292,11 @@ class SessionController < ApplicationController end def invalid_credentials - render json: {error: I18n.t("login.incorrect_username_email_or_password")} + render json: { error: I18n.t("login.incorrect_username_email_or_password") } end def login_not_approved - render json: {error: I18n.t("login.not_approved")} + render json: { error: I18n.t("login.not_approved") } end def not_activated(user) @@ -310,19 +310,19 @@ class SessionController < ApplicationController end def not_allowed_from_ip_address(user) - render json: {error: I18n.t("login.not_allowed_from_ip_address", username: user.username)} + render json: { error: I18n.t("login.not_allowed_from_ip_address", username: user.username) } end def admin_not_allowed_from_ip_address(user) - render json: {error: I18n.t("login.admin_not_allowed_from_ip_address", username: user.username)} + render json: { error: I18n.t("login.admin_not_allowed_from_ip_address", username: user.username) } end def failed_to_login(user) message = user.suspend_reason ? "login.suspended_with_reason" : "login.suspended" render json: { - error: I18n.t(message, { date: I18n.l(user.suspended_till, format: :date_only), - reason: Rack::Utils.escape_html(user.suspend_reason) }), + error: I18n.t(message, date: I18n.l(user.suspended_till, format: :date_only), + reason: Rack::Utils.escape_html(user.suspend_reason)), reason: 'suspended' } end @@ -337,7 +337,6 @@ class SessionController < ApplicationController render_serialized(user, UserSerializer) end - def render_sso_error(status:, text:) @sso_error = text render status: status, layout: 'no_ember' diff --git a/app/controllers/similar_topics_controller.rb b/app/controllers/similar_topics_controller.rb index 1f0a84d84f8..8070697e57c 100644 --- a/app/controllers/similar_topics_controller.rb +++ b/app/controllers/similar_topics_controller.rb @@ -26,7 +26,7 @@ class SimilarTopicsController < ApplicationController return render json: [] if invalid_length || !Topic.count_exceeds_minimum? topics = Topic.similar_to(title, raw, current_user).to_a - topics.map! {|t| SimilarTopic.new(t) } + topics.map! { |t| SimilarTopic.new(t) } render_serialized(topics, SimilarTopicSerializer, root: :similar_topics, rest_serializer: true) end diff --git a/app/controllers/static_controller.rb b/app/controllers/static_controller.rb index 30c140304ee..b524b0dd8e7 100644 --- a/app/controllers/static_controller.rb +++ b/app/controllers/static_controller.rb @@ -13,9 +13,9 @@ class StaticController < ApplicationController return redirect_to path('/login') if SiteSetting.login_required? && current_user.nil? && (params[:id] == 'faq' || params[:id] == 'guidelines') map = { - "faq" => {redirect: "faq_url", topic_id: "guidelines_topic_id"}, - "tos" => {redirect: "tos_url", topic_id: "tos_topic_id"}, - "privacy" => {redirect: "privacy_policy_url", topic_id: "privacy_topic_id"} + "faq" => { redirect: "faq_url", topic_id: "guidelines_topic_id" }, + "tos" => { redirect: "tos_url", topic_id: "tos_topic_id" }, + "privacy" => { redirect: "privacy_policy_url", topic_id: "privacy_topic_id" } } @page = params[:id] @@ -100,7 +100,7 @@ class StaticController < ApplicationController # a huge expiry, we also cache these assets in nginx so it bypassed if needed def favicon - data = DistributedMemoizer.memoize('favicon' + SiteSetting.favicon_url, 60*30) do + data = DistributedMemoizer.memoize('favicon' + SiteSetting.favicon_url, 60 * 30) do begin file = FileHelper.download( SiteSetting.favicon_url, @@ -137,21 +137,19 @@ class StaticController < ApplicationController end end - def cdn_asset serve_asset end protected - def serve_asset(suffix=nil) + def serve_asset(suffix = nil) path = File.expand_path(Rails.root + "public/assets/#{params[:path]}#{suffix}") # SECURITY what if path has /../ raise Discourse::NotFound unless path.start_with?(Rails.root.to_s + "/public/assets") - response.headers["Expires"] = 1.year.from_now.httpdate response.headers["Access-Control-Allow-Origin"] = params[:origin] if params[:origin] diff --git a/app/controllers/steps_controller.rb b/app/controllers/steps_controller.rb index 005d2d7d781..c80bdffd2f9 100644 --- a/app/controllers/steps_controller.rb +++ b/app/controllers/steps_controller.rb @@ -20,7 +20,7 @@ class StepsController < ApplicationController else errors = [] updater.errors.messages.each do |field, msg| - errors << {field: field, description: msg.join } + errors << { field: field, description: msg.join } end render json: { errors: errors }, status: 422 end diff --git a/app/controllers/stylesheets_controller.rb b/app/controllers/stylesheets_controller.rb index 8d1328e0f2b..d174f28faa6 100644 --- a/app/controllers/stylesheets_controller.rb +++ b/app/controllers/stylesheets_controller.rb @@ -19,17 +19,17 @@ class StylesheetsController < ApplicationController no_cookies - target,digest = params[:name].split(/_([a-f0-9]{40})/) + target, digest = params[:name].split(/_([a-f0-9]{40})/) if !Rails.env.production? # TODO add theme # calling this method ensures we have a cache for said target # we hold of re-compilation till someone asks for asset if target.include?("theme") - split_target,theme_id = target.split(/_(-?[0-9]+)/) + split_target, theme_id = target.split(/_(-?[0-9]+)/) theme = Theme.find(theme_id) if theme_id else - split_target,color_scheme_id = target.split(/_(-?[0-9]+)/) + split_target, color_scheme_id = target.split(/_(-?[0-9]+)/) theme = Theme.find_by(color_scheme_id: color_scheme_id) end Stylesheet::Manager.stylesheet_link_tag(split_target, nil, theme&.key) @@ -59,7 +59,6 @@ class StylesheetsController < ApplicationController return render nothing: true, status: 304 end - unless File.exist?(location) if current = query.limit(1).pluck(source_map ? :source_map : :content).first File.write(location, current) diff --git a/app/controllers/tag_groups_controller.rb b/app/controllers/tag_groups_controller.rb index 783839fd4d6..d29d3ba8d7b 100644 --- a/app/controllers/tag_groups_controller.rb +++ b/app/controllers/tag_groups_controller.rb @@ -69,7 +69,7 @@ class TagGroupsController < ApplicationController end def tag_groups_params - result = params.permit(:id, :name, :one_per_topic, :tag_names => [], :parent_tag_name => []) + result = params.permit(:id, :name, :one_per_topic, tag_names: [], parent_tag_name: []) result[:tag_names] ||= [] result[:parent_tag_name] ||= [] result[:one_per_topic] = (params[:one_per_topic] == "true") diff --git a/app/controllers/tags_controller.rb b/app/controllers/tags_controller.rb index 0af8be70a63..21dd16c8188 100644 --- a/app/controllers/tags_controller.rb +++ b/app/controllers/tags_controller.rb @@ -14,18 +14,18 @@ class TagsController < ::ApplicationController :tag_feed, :search, :check_hashtag, - Discourse.anonymous_filters.map { |f| :"show_#{f}"} + Discourse.anonymous_filters.map { |f| :"show_#{f}" } ].flatten before_filter :set_category_from_params, except: [:index, :update, :destroy, :tag_feed, :search, :notifications, :update_notifications] def index categories = Category.where("id in (select category_id from category_tags)") - .where("id in (?)", guardian.allowed_category_ids) - .preload(:tags) + .where("id in (?)", guardian.allowed_category_ids) + .preload(:tags) category_tag_counts = categories.map do |c| h = Tag.category_tags_by_count_query(c, limit: 300).count(Tag::COUNT_ARG) - h.merge!(c.tags.where.not(name: h.keys).inject({}) { |sum,t| sum[t.name] = 0; sum }) # unused tags - {id: c.id, tags: self.class.tag_counts_json(h)} + h.merge!(c.tags.where.not(name: h.keys).inject({}) { |sum, t| sum[t.name] = 0; sum }) # unused tags + { id: c.id, tags: self.class.tag_counts_json(h) } end tag_counts = self.class.tags_by_count(guardian, limit: 300).count(Tag::COUNT_ARG) @@ -91,7 +91,7 @@ class TagsController < ::ApplicationController tag.name = new_tag_name if tag.save StaffActionLogger.new(current_user).log_custom('renamed_tag', previous_value: params[:tag_id], new_value: new_tag_name) - render json: { tag: { id: new_tag_name }} + render json: { tag: { id: new_tag_name } } else render_json_error tag.errors.full_messages end @@ -116,7 +116,7 @@ class TagsController < ::ApplicationController @title = "#{SiteSetting.title} - #{@description}" @atom_link = "#{Discourse.base_url}/tags/#{tag_id}.rss" - query = TopicQuery.new(current_user, {tags: [tag_id]}) + query = TopicQuery.new(current_user, tags: [tag_id]) latest_results = query.latest_results @topic_list = query.create_list(:by_tag, {}, latest_results) @@ -129,15 +129,13 @@ class TagsController < ::ApplicationController tags_with_counts = DiscourseTagging.filter_allowed_tags( Tag.tags_by_count_query(params.slice(:limit)), guardian, - { - for_input: params[:filterForInput], - term: params[:q], - category: category, - selected_tags: params[:selected_tags] - } + for_input: params[:filterForInput], + term: params[:q], + category: category, + selected_tags: params[:selected_tags] ) - tags = tags_with_counts.count(Tag::COUNT_ARG).map {|t, c| { id: t, text: t, count: c } } + tags = tags_with_counts.count(Tag::COUNT_ARG).map { |t, c| { id: t, text: t, count: c } } json_response = { results: tags } @@ -161,7 +159,7 @@ class TagsController < ::ApplicationController raise Discourse::NotFound unless tag level = params[:tag_notification][:notification_level].to_i TagUser.change(current_user.id, tag.id, level) - render json: {notification_level: level} + render json: { notification_level: level } end def check_hashtag @@ -180,12 +178,12 @@ class TagsController < ::ApplicationController raise Discourse::NotFound unless SiteSetting.tagging_enabled? end - def self.tags_by_count(guardian, opts={}) + def self.tags_by_count(guardian, opts = {}) guardian.filter_allowed_categories(Tag.tags_by_count_query(opts)) end def self.tag_counts_json(tag_counts) - tag_counts.map {|t, c| { id: t, text: t, count: c } } + tag_counts.map { |t, c| { id: t, text: t, count: c } } end def set_category_from_params @@ -201,13 +199,13 @@ class TagsController < ::ApplicationController parent_category_id = nil if parent_slug_or_id.present? parent_category_id = Category.query_parent_category(parent_slug_or_id) - category_redirect_or_not_found and return if parent_category_id.blank? + category_redirect_or_not_found && (return) if parent_category_id.blank? end @filter_on_category = Category.query_category(slug_or_id, parent_category_id) end - category_redirect_or_not_found and return if !@filter_on_category + category_redirect_or_not_found && (return) if !@filter_on_category guardian.ensure_can_see!(@filter_on_category) end @@ -236,7 +234,7 @@ class TagsController < ::ApplicationController end end - def url_method(opts={}) + def url_method(opts = {}) if opts[:parent_category] && opts[:category] "tag_parent_category_category_#{action_name}_path" elsif opts[:category] @@ -254,7 +252,7 @@ class TagsController < ::ApplicationController else # :next public_send(method, opts.merge(next_page_params(opts))) end - url.sub('.json?','?') + url.sub('.json?', '?') end def build_topic_list_options diff --git a/app/controllers/topics_controller.rb b/app/controllers/topics_controller.rb index e35ca7391c4..27279d2dc3a 100644 --- a/app/controllers/topics_controller.rb +++ b/app/controllers/topics_controller.rb @@ -40,7 +40,7 @@ class TopicsController < ApplicationController topic = Topic.find_by(slug: params[:slug].downcase) guardian.ensure_can_see!(topic) raise Discourse::NotFound unless topic - render json: {slug: topic.slug, topic_id: topic.id, url: topic.url} + render json: { slug: topic.slug, topic_id: topic.id, url: topic.url } end def show @@ -155,7 +155,6 @@ class TopicsController < ApplicationController TopicUser.change(current_user.id, params[:topic_id].to_i, notification_level: TopicUser.notification_levels[:muted]) end - perform_show_response end @@ -164,7 +163,8 @@ class TopicsController < ApplicationController params.require(:topic_id) params.permit(:min_trust_level, :min_score, :min_replies, :bypass_trust_level_score, :only_moderator_liked) - opts = { best: params[:best].to_i, + opts = { + best: params[:best].to_i, min_trust_level: params[:min_trust_level] ? params[:min_trust_level].to_i : 1, min_score: params[:min_score].to_i, min_replies: params[:min_replies].to_i, @@ -206,17 +206,16 @@ class TopicsController < ApplicationController guardian.ensure_can_see!(@topic) @posts = Post.where(hidden: false, deleted_at: nil, topic_id: @topic.id) - .where('posts.id in (?)', post_ids) - .joins("LEFT JOIN users u on u.id = posts.user_id") - .pluck(:id, :cooked, :username) - .map do |post_id, cooked, username| - { - post_id: post_id, - username: username, - excerpt: PrettyText.excerpt(cooked, 800, keep_emoji_images: true) - } - end - + .where('posts.id in (?)', post_ids) + .joins("LEFT JOIN users u on u.id = posts.user_id") + .pluck(:id, :cooked, :username) + .map do |post_id, cooked, username| + { + post_id: post_id, + username: username, + excerpt: PrettyText.excerpt(cooked, 800, keep_emoji_images: true) + } + end render json: @posts.to_json end @@ -266,7 +265,7 @@ class TopicsController < ApplicationController params.require(:enabled) params.permit(:until) - status = params[:status] + status = params[:status] topic_id = params[:topic_id].to_i enabled = params[:enabled] == 'true' @@ -319,13 +318,13 @@ class TopicsController < ApplicationController ) if topic.save - render json: success_json.merge!({ + render json: success_json.merge!( execute_at: topic_status_update&.execute_at, duration: topic_status_update&.duration, based_on_last_post: topic_status_update&.based_on_last_post, closed: topic.closed, category_id: topic_status_update&.category_id - }) + ) else render_json_error(topic) end @@ -353,8 +352,8 @@ class TopicsController < ApplicationController topic = Topic.find(params[:topic_id].to_i) PostAction.joins(:post) - .where(user_id: current_user.id) - .where('topic_id = ?', topic.id).each do |pa| + .where(user_id: current_user.id) + .where('topic_id = ?', topic.id).each do |pa| PostAction.remove_act(current_user, pa.post, PostActionType.types[:bookmark]) end @@ -378,7 +377,7 @@ class TopicsController < ApplicationController group_ids = current_user.groups.pluck(:id) if group_ids.present? allowed_groups = topic.allowed_groups - .where('topic_allowed_groups.group_id IN (?)', group_ids).pluck(:id) + .where('topic_allowed_groups.group_id IN (?)', group_ids).pluck(:id) allowed_groups.each do |id| if archive GroupArchivedMessage.archive!(id, topic.id) @@ -421,7 +420,7 @@ class TopicsController < ApplicationController guardian.ensure_can_delete!(topic) first_post = topic.ordered_posts.first - PostDestroyer.new(current_user, first_post, { context: params[:context] }).destroy + PostDestroyer.new(current_user, first_post, context: params[:context]).destroy render nothing: true end @@ -484,7 +483,6 @@ class TopicsController < ApplicationController topic = Topic.find_by(id: params[:topic_id]) - groups = Group.lookup_groups( group_ids: params[:group_ids], group_names: params[:group_names] @@ -505,7 +503,7 @@ class TopicsController < ApplicationController render json: failed_json, status: 422 end rescue Topic::UserExists => e - render json: {errors: [e.message]}, status: 422 + render json: { errors: [e.message] }, status: 422 end end @@ -547,10 +545,10 @@ class TopicsController < ApplicationController guardian.ensure_can_change_post_owner! begin - PostOwnerChanger.new( post_ids: params[:post_ids].to_a, - topic_id: params[:topic_id].to_i, - new_owner: User.find_by(username: params[:username]), - acting_user: current_user ).change_owner! + PostOwnerChanger.new(post_ids: params[:post_ids].to_a, + topic_id: params[:topic_id].to_i, + new_owner: User.find_by(username: params[:username]), + acting_user: current_user).change_owner! render json: success_json rescue ArgumentError render json: failed_json, status: 422 @@ -594,8 +592,8 @@ class TopicsController < ApplicationController current_user, params[:topic_id].to_i, params[:topic_time].to_i, - (params[:timings] || []).map{|post_number, t| [post_number.to_i, t.to_i]}, - {mobile: view_context.mobile_view?} + (params[:timings] || []).map { |post_number, t| [post_number.to_i, t.to_i] }, + mobile: view_context.mobile_view? ) render nothing: true end @@ -608,7 +606,7 @@ class TopicsController < ApplicationController def bulk if params[:topic_ids].present? - topic_ids = params[:topic_ids].map {|t| t.to_i} + topic_ids = params[:topic_ids].map { |t| t.to_i } elsif params[:filter] == 'unread' tq = TopicQuery.new(current_user) topics = TopicQuery.unread_filter(tq.joined_topic_user, current_user.id, staff: guardian.is_staff?).listable_topics @@ -664,7 +662,7 @@ class TopicsController < ApplicationController params[:slug] && @topic_view.topic.slug != params[:slug] end - def redirect_to_correct_topic(topic, post_number=nil) + def redirect_to_correct_topic(topic, post_number = nil) url = topic.relative_url url << "/#{post_number}" if post_number.to_i > 0 url << ".json" if request.format.json? @@ -728,9 +726,9 @@ class TopicsController < ApplicationController def render_topic_changes(dest_topic) if dest_topic.present? - render json: {success: true, url: dest_topic.relative_url} + render json: { success: true, url: dest_topic.relative_url } else - render json: {success: false} + render json: { success: false } end end diff --git a/app/controllers/user_api_keys_controller.rb b/app/controllers/user_api_keys_controller.rb index 8d11d46c1e7..6fff6655c82 100644 --- a/app/controllers/user_api_keys_controller.rb +++ b/app/controllers/user_api_keys_controller.rb @@ -40,7 +40,7 @@ class UserApiKeysController < ApplicationController @client_id = params[:client_id] @auth_redirect = params[:auth_redirect] @push_url = params[:push_url] - @localized_scopes = params[:scopes].split(",").map{|s| I18n.t("user_api_key.scopes.#{s}")} + @localized_scopes = params[:scopes].split(",").map { |s| I18n.t("user_api_key.scopes.#{s}") } @scopes = params[:scopes] rescue Discourse::InvalidAccess @@ -52,10 +52,10 @@ class UserApiKeysController < ApplicationController require_params unless SiteSetting.allowed_user_api_auth_redirects - .split('|') - .any?{|u| params[:auth_redirect] == u} + .split('|') + .any? { |u| params[:auth_redirect] == u } - raise Discourse::InvalidAccess + raise Discourse::InvalidAccess end raise Discourse::InvalidAccess unless meets_tl? @@ -126,7 +126,7 @@ class UserApiKeysController < ApplicationController :client_id, :auth_redirect, :application_name - ].each{|p| params.require(p)} + ].each { |p| params.require(p) } end def validate_params diff --git a/app/controllers/user_avatars_controller.rb b/app/controllers/user_avatars_controller.rb index 30a3709c60a..119266fd357 100644 --- a/app/controllers/user_avatars_controller.rb +++ b/app/controllers/user_avatars_controller.rb @@ -89,7 +89,7 @@ class UserAvatarsController < ApplicationController return render_blank if size < 8 || size > 1000 if !Discourse.avatar_sizes.include?(size) && Discourse.store.external? - closest = Discourse.avatar_sizes.to_a.min { |a,b| (size-a).abs <=> (size-b).abs } + closest = Discourse.avatar_sizes.to_a.min { |a, b| (size - a).abs <=> (size - b).abs } avatar_url = UserAvatar.local_avatar_url(hostname, user.username_lower, upload_id, closest) return redirect_to cdn_path(avatar_url) end diff --git a/app/controllers/user_badges_controller.rb b/app/controllers/user_badges_controller.rb index 7c9cfb0bee7..d8f44a41ea2 100644 --- a/app/controllers/user_badges_controller.rb +++ b/app/controllers/user_badges_controller.rb @@ -33,12 +33,12 @@ class UserBadgesController < ApplicationController if params[:grouped] user_badges = user_badges.group(:badge_id) - .select(UserBadge.attribute_names.map {|x| "MAX(#{x}) AS #{x}" }, 'COUNT(*) AS "count"') + .select(UserBadge.attribute_names.map { |x| "MAX(#{x}) AS #{x}" }, 'COUNT(*) AS "count"') end user_badges = user_badges.includes(badge: [:badge_grouping, :badge_type]) - .includes(post: :topic) - .includes(:granted_by) + .includes(post: :topic) + .includes(:granted_by) render_serialized(user_badges, DetailedUserBadgeSerializer, root: :user_badges) end @@ -104,6 +104,6 @@ class UserBadgesController < ApplicationController def can_assign_badge_to_user?(user) master_api_call = current_user.nil? && is_api? - master_api_call or guardian.can_grant_badges?(user) + master_api_call || guardian.can_grant_badges?(user) end end diff --git a/app/controllers/users/omniauth_callbacks_controller.rb b/app/controllers/users/omniauth_callbacks_controller.rb index 6b0409e2a49..4908b527bb2 100644 --- a/app/controllers/users/omniauth_callbacks_controller.rb +++ b/app/controllers/users/omniauth_callbacks_controller.rb @@ -36,7 +36,7 @@ class Users::OmniauthCallbacksController < ApplicationController auth[:session] = session authenticator = self.class.find_authenticator(params[:provider]) - provider = Discourse.auth_providers && Discourse.auth_providers.find{|p| p.name == params[:provider]} + provider = Discourse.auth_providers && Discourse.auth_providers.find { |p| p.name == params[:provider] } @auth_result = authenticator.after_authenticate(auth) @@ -83,7 +83,6 @@ class Users::OmniauthCallbacksController < ApplicationController render layout: 'no_ember' end - def self.find_authenticator(name) BUILTIN_AUTH.each do |authenticator| if authenticator.name == name diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 69ad6520785..953353916e9 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -50,7 +50,7 @@ class UsersController < ApplicationController topic_id = params[:include_post_count_for].to_i if topic_id != 0 - user_serializer.topic_post_count = {topic_id => Post.where(topic_id: topic_id, user_id: @user.id).count } + user_serializer.topic_post_count = { topic_id => Post.where(topic_id: topic_id, user_id: @user.id).count } end if !params[:skip_track_visit] && (@user != current_user) @@ -59,7 +59,7 @@ class UsersController < ApplicationController # This is a hack to get around a Rails issue where values with periods aren't handled correctly # when used as part of a route. - if params[:external_id] and params[:external_id].ends_with? '.json' + if params[:external_id] && params[:external_id].ends_with?('.json') return render_json_dump(user_serializer) end @@ -224,8 +224,8 @@ class UsersController < ApplicationController pending_count = Invite.find_pending_invites_count(inviter) redeemed_count = Invite.find_redeemed_invites_count(inviter) - render json: {counts: { pending: pending_count, redeemed: redeemed_count, - total: (pending_count.to_i + redeemed_count.to_i) } } + render json: { counts: { pending: pending_count, redeemed: redeemed_count, + total: (pending_count.to_i + redeemed_count.to_i) } } end def is_local_username @@ -238,7 +238,7 @@ class UsersController < ApplicationController Group.mentionable(current_user) .where(name: usernames) .pluck(:name, :user_count) - .map{ |name,user_count| {name: name, user_count: user_count} } + .map { |name, user_count| { name: name, user_count: user_count } } end usernames -= groups @@ -250,14 +250,14 @@ class UsersController < ApplicationController topic_id = params[:topic_id] unless topic_id.blank? topic = Topic.find_by(id: topic_id) - usernames.each{ |username| cannot_see.push(username) unless Guardian.new(User.find_by_username(username)).can_see?(topic) } + usernames.each { |username| cannot_see.push(username) unless Guardian.new(User.find_by_username(username)).can_see?(topic) } end result = User.where(staged: false) - .where(username_lower: usernames) - .pluck(:username_lower) + .where(username_lower: usernames) + .pluck(:username_lower) - render json: {valid: result, valid_groups: groups, mentionable_groups: mentionable_groups, cannot_see: cannot_see} + render json: { valid: result, valid_groups: groups, mentionable_groups: mentionable_groups, cannot_see: cannot_see } end def render_available_true @@ -265,7 +265,7 @@ class UsersController < ApplicationController end def changing_case_of_own_username(target_user, username) - target_user and username.downcase == target_user.username.downcase + target_user && username.downcase == (target_user.username.downcase) end # Used for checking availability of a username and will return suggestions @@ -385,7 +385,7 @@ class UsersController < ApplicationController end def get_honeypot_value - render json: {value: honeypot_value, challenge: challenge_value} + render json: { value: honeypot_value, challenge: challenge_value } end def password_reset @@ -433,7 +433,7 @@ class UsersController < ApplicationController if @error render layout: 'no_ember' else - store_preloaded("password_reset", MultiJson.dump({ is_developer: UsernameCheckerService.is_developer?(@user.email) })) + store_preloaded("password_reset", MultiJson.dump(is_developer: UsernameCheckerService.is_developer?(@user.email))) end return redirect_to(wizard_path) if request.put? && Wizard.user_requires_completion?(@user) end @@ -456,7 +456,7 @@ class UsersController < ApplicationController } end else - render json: {is_developer: UsernameCheckerService.is_developer?(@user.email)} + render json: { is_developer: UsernameCheckerService.is_developer?(@user.email) } end end end @@ -469,14 +469,15 @@ class UsersController < ApplicationController end def logon_after_password_reset - message = if Guardian.new(@user).can_access_forum? - # Log in the user - log_on_user(@user) - 'password_reset.success' - else - @requires_approval = true - 'password_reset.success_unapproved' - end + message = + if Guardian.new(@user).can_access_forum? + # Log in the user + log_on_user(@user) + 'password_reset.success' + else + @requires_approval = true + 'password_reset.success_unapproved' + end @success = I18n.t(message) end @@ -606,7 +607,7 @@ class UsersController < ApplicationController User.transaction do @user.email = params[:email] - + if @user.save @user.email_tokens.create(email: @user.email) enqueue_activation_email @@ -662,7 +663,6 @@ class UsersController < ApplicationController @group = Group.find_by(name: params[:group]) end - results = UserSearch.new(term, topic_id: topic_id, topic_allowed_users: topic_allowed_users, @@ -683,8 +683,8 @@ class UsersController < ApplicationController if params[:include_mentionable_groups] == "true" && current_user to_render[:groups] = Group.mentionable(current_user) - .where("name ILIKE :term_like", term_like: "#{term}%") - .map do |m| + .where("name ILIKE :term_like", term_like: "#{term}%") + .map do |m| { name: m.name, full_name: m.full_name } end end @@ -752,7 +752,7 @@ class UsersController < ApplicationController @user = fetch_user_from_params guardian.ensure_can_delete_user!(@user) - UserDestroyer.new(current_user).destroy(@user, { delete_posts: true, context: params[:context] }) + UserDestroyer.new(current_user).destroy(@user, delete_posts: true, context: params[:context]) render json: success_json end @@ -797,14 +797,14 @@ class UsersController < ApplicationController private def honeypot_value - Digest::SHA1::hexdigest("#{Discourse.current_hostname}:#{GlobalSetting.safe_secret_key_base}")[0,15] + Digest::SHA1::hexdigest("#{Discourse.current_hostname}:#{GlobalSetting.safe_secret_key_base}")[0, 15] end def challenge_value challenge = $redis.get('SECRET_CHALLENGE') - unless challenge && challenge.length == 16*2 + unless challenge && challenge.length == 16 * 2 challenge = SecureRandom.hex(16) - $redis.set('SECRET_CHALLENGE',challenge) + $redis.set('SECRET_CHALLENGE', challenge) end challenge @@ -833,9 +833,9 @@ class UsersController < ApplicationController def user_params result = params.permit(:name, :email, :password, :username, :date_of_birth) - .merge(ip_address: request.remote_ip, - registration_ip_address: request.remote_ip, - locale: user_locale) + .merge(ip_address: request.remote_ip, + registration_ip_address: request.remote_ip, + locale: user_locale) if !UsernameCheckerService.is_developer?(result['email']) && is_api? && @@ -845,7 +845,6 @@ class UsersController < ApplicationController result.merge!(params.permit(:active, :staged)) end - result end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 944ab7f8ef2..1d837bbf0b0 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -15,7 +15,7 @@ module ApplicationHelper include ConfigurableUrls include GlobalPath - def google_universal_analytics_json(ua_domain_name=nil) + def google_universal_analytics_json(ua_domain_name = nil) result = {} if ua_domain_name result[:cookieDomain] = ua_domain_name.gsub(/^http(s)?:\/\//, '') @@ -55,7 +55,7 @@ module ApplicationHelper GlobalSetting.cdn_url.start_with?("https") && ENV["COMPRESS_BROTLI"] == "1" && request.env["HTTP_ACCEPT_ENCODING"] =~ /br/ - path.gsub!("#{GlobalSetting.cdn_url}/assets/", "#{GlobalSetting.cdn_url}/brotli_asset/") + path.gsub!("#{GlobalSetting.cdn_url}/assets/", "#{GlobalSetting.cdn_url}/brotli_asset/") end " ".html_safe @@ -158,7 +158,7 @@ module ApplicationHelper end # Creates open graph and twitter card meta data - def crawlable_meta_data(opts=nil) + def crawlable_meta_data(opts = nil) opts ||= {} opts[:url] ||= "#{Discourse.base_url_no_prefix}#{request.fullpath}" @@ -242,7 +242,7 @@ module ApplicationHelper end def mobile_view? - MobileDetection.resolve_mobile_view!(request.user_agent,params,session) + MobileDetection.resolve_mobile_view!(request.user_agent, params, session) end def crawler_layout? @@ -283,7 +283,7 @@ module ApplicationHelper controller.class.name.split("::").first == "Admin" end - def category_badge(category, opts=nil) + def category_badge(category, opts = nil) CategoryBadge.html_for(category, opts).html_safe end @@ -297,11 +297,11 @@ module ApplicationHelper return "" if Rails.env.test? matcher = Regexp.new("/connectors/#{name}/.*\.html\.erb$") - erbs = ApplicationHelper.all_connectors.select {|c| c =~ matcher } + erbs = ApplicationHelper.all_connectors.select { |c| c =~ matcher } return "" if erbs.blank? result = "" - erbs.each {|erb| result << render(file: erb) } + erbs.each { |erb| result << render(file: erb) } result.html_safe end @@ -335,7 +335,7 @@ module ApplicationHelper lookup.html_safe if lookup end - def discourse_stylesheet_link_tag(name, opts={}) + def discourse_stylesheet_link_tag(name, opts = {}) if opts.key?(:theme_key) key = opts[:theme_key] unless customization_disabled? else diff --git a/app/helpers/list_helper.rb b/app/helpers/list_helper.rb index a7cf7766acb..9839401f9ec 100644 --- a/app/helpers/list_helper.rb +++ b/app/helpers/list_helper.rb @@ -6,7 +6,7 @@ module ListHelper return if total_pages < 2 - page = [total_pages - (max_pages+1), 2].max + page = [total_pages - (max_pages + 1), 2].max result = "(" while page <= total_pages diff --git a/app/helpers/topics_helper.rb b/app/helpers/topics_helper.rb index c3f0cb96459..b50b923bb87 100644 --- a/app/helpers/topics_helper.rb +++ b/app/helpers/topics_helper.rb @@ -2,7 +2,7 @@ module TopicsHelper include ApplicationHelper def render_topic_title(topic) - link_to(Emoji.gsub_emoji_to_unicode(topic.title),topic.relative_url) + link_to(Emoji.gsub_emoji_to_unicode(topic.title), topic.relative_url) end def categories_breadcrumb(topic) diff --git a/app/helpers/user_notifications_helper.rb b/app/helpers/user_notifications_helper.rb index 044b4eb3128..2e18c702ee3 100644 --- a/app/helpers/user_notifications_helper.rb +++ b/app/helpers/user_notifications_helper.rb @@ -1,6 +1,6 @@ module UserNotificationsHelper - def indent(text, by=2) + def indent(text, by = 2) spacer = " " * by result = "" text.each_line do |line| @@ -48,9 +48,9 @@ module UserNotificationsHelper doc.css('div').first end - def email_excerpt(html_arg, posts_count=nil) + def email_excerpt(html_arg, posts_count = nil) # only include 1st paragraph when more than 1 posts - html = (posts_count.nil? || posts_count > 1) ? (first_paragraph_from(html_arg)||html_arg).to_s : html_arg + html = (posts_count.nil? || posts_count > 1) ? (first_paragraph_from(html_arg) || html_arg).to_s : html_arg PrettyText.format_for_email(html).html_safe end diff --git a/app/jobs/base.rb b/app/jobs/base.rb index 4445c78aa9d..9ce3b6e0766 100644 --- a/app/jobs/base.rb +++ b/app/jobs/base.rb @@ -71,11 +71,11 @@ module Jobs ctx end - def self.delayed_perform(opts={}) + def self.delayed_perform(opts = {}) self.new.perform(opts) end - def execute(opts={}) + def execute(opts = {}) raise "Overwrite me!" end @@ -114,7 +114,6 @@ module Jobs end end - dbs = if opts[:current_site_id] [opts[:current_site_id]] @@ -203,7 +202,7 @@ module Jobs end end - def self.enqueue(job_name, opts={}) + def self.enqueue(job_name, opts = {}) klass = "Jobs::#{job_name.to_s.camelcase}".constantize # Unless we want to work on all sites @@ -227,20 +226,20 @@ module Jobs end - def self.enqueue_in(secs, job_name, opts={}) + def self.enqueue_in(secs, job_name, opts = {}) enqueue(job_name, opts.merge!(delay_for: secs)) end - def self.enqueue_at(datetime, job_name, opts={}) + def self.enqueue_at(datetime, job_name, opts = {}) secs = [(datetime - Time.zone.now).to_i, 0].max enqueue_in(secs, job_name, opts) end - def self.cancel_scheduled_job(job_name, opts={}) + def self.cancel_scheduled_job(job_name, opts = {}) scheduled_for(job_name, opts).each(&:delete) end - def self.scheduled_for(job_name, opts={}) + def self.scheduled_for(job_name, opts = {}) opts = opts.with_indifferent_access unless opts.delete(:all_sites) opts[:current_site_id] ||= RailsMultisite::ConnectionManagement.current_db @@ -265,6 +264,6 @@ module Jobs end end -Dir["#{Rails.root}/app/jobs/onceoff/*.rb"].each {|file| require_dependency file } -Dir["#{Rails.root}/app/jobs/regular/*.rb"].each {|file| require_dependency file } -Dir["#{Rails.root}/app/jobs/scheduled/*.rb"].each {|file| require_dependency file } +Dir["#{Rails.root}/app/jobs/onceoff/*.rb"].each { |file| require_dependency file } +Dir["#{Rails.root}/app/jobs/regular/*.rb"].each { |file| require_dependency file } +Dir["#{Rails.root}/app/jobs/scheduled/*.rb"].each { |file| require_dependency file } diff --git a/app/jobs/onceoff/grant_emoji.rb b/app/jobs/onceoff/grant_emoji.rb index 696fd1f9528..39d9ececf8d 100644 --- a/app/jobs/onceoff/grant_emoji.rb +++ b/app/jobs/onceoff/grant_emoji.rb @@ -6,11 +6,11 @@ module Jobs to_award = {} Post.secured(Guardian.new) - .select(:id, :created_at, :cooked, :user_id) - .visible - .public_posts - .where("cooked LIKE '%emoji%'") - .find_in_batches do |group| + .select(:id, :created_at, :cooked, :user_id) + .visible + .public_posts + .where("cooked LIKE '%emoji%'") + .find_in_batches do |group| group.each do |p| doc = Nokogiri::HTML::fragment(p.cooked) if (doc.css("img.emoji") - doc.css(".quote img")).size > 0 diff --git a/app/jobs/onceoff/grant_first_reply_by_email.rb b/app/jobs/onceoff/grant_first_reply_by_email.rb index ae769f681c3..ef8bcc6469d 100644 --- a/app/jobs/onceoff/grant_first_reply_by_email.rb +++ b/app/jobs/onceoff/grant_first_reply_by_email.rb @@ -7,12 +7,12 @@ module Jobs to_award = {} Post.select(:id, :created_at, :user_id) - .secured(Guardian.new) - .visible - .public_posts - .where(via_email: true) - .where("post_number > 1") - .find_in_batches do |group| + .secured(Guardian.new) + .visible + .public_posts + .where(via_email: true) + .where("post_number > 1") + .find_in_batches do |group| group.each do |p| to_award[p.user_id] ||= { post_id: p.id, created_at: p.created_at } end diff --git a/app/jobs/onceoff/grant_onebox.rb b/app/jobs/onceoff/grant_onebox.rb index 0c63e6b7b85..259dfe97021 100644 --- a/app/jobs/onceoff/grant_onebox.rb +++ b/app/jobs/onceoff/grant_onebox.rb @@ -8,11 +8,11 @@ module Jobs to_award = {} Post.secured(Guardian.new) - .select(:id, :created_at, :raw, :user_id) - .visible - .public_posts - .where("raw LIKE '%http%'") - .find_in_batches do |group| + .select(:id, :created_at, :raw, :user_id) + .visible + .public_posts + .where("raw LIKE '%http%'") + .find_in_batches do |group| group.each do |p| begin # Note we can't use `p.cooked` here because oneboxes have been cooked out diff --git a/app/jobs/onceoff/migrate_tagging_plugin.rb b/app/jobs/onceoff/migrate_tagging_plugin.rb index f0bb91e7e49..9d94b8e88f4 100644 --- a/app/jobs/onceoff/migrate_tagging_plugin.rb +++ b/app/jobs/onceoff/migrate_tagging_plugin.rb @@ -4,7 +4,7 @@ module Jobs def execute_onceoff(args) all_tags = TopicCustomField.where(name: "tags").select('DISTINCT value').all.map(&:value) - tag_id_lookup = Tag.create(all_tags.map { |tag_name| {name: tag_name} }).inject({}) { |h,v| h[v.name] = v.id; h } + tag_id_lookup = Tag.create(all_tags.map { |tag_name| { name: tag_name } }).inject({}) { |h, v| h[v.name] = v.id; h } TopicCustomField.where(name: "tags").find_each do |tcf| TopicTag.create(topic_id: tcf.topic_id, tag_id: tag_id_lookup[tcf.value] || Tag.find_by_name(tcf.value).try(:id)) diff --git a/app/jobs/onceoff/retro_grant_anniversary.rb b/app/jobs/onceoff/retro_grant_anniversary.rb index 2b338e6dcdc..9cbdddd8109 100644 --- a/app/jobs/onceoff/retro_grant_anniversary.rb +++ b/app/jobs/onceoff/retro_grant_anniversary.rb @@ -14,4 +14,3 @@ module Jobs end end - diff --git a/app/jobs/regular/automatic_group_membership.rb b/app/jobs/regular/automatic_group_membership.rb index b2f12d15022..4e688d84000 100644 --- a/app/jobs/regular/automatic_group_membership.rb +++ b/app/jobs/regular/automatic_group_membership.rb @@ -14,11 +14,11 @@ module Jobs domains = group.automatic_membership_email_domains.gsub('.', '\.') User.joins(:user_emails) - .where("user_emails.email ~* '@(#{domains})$'") - .where("users.id NOT IN (SELECT user_id FROM group_users WHERE group_users.group_id = ?)", group_id) - .activated - .where(staged: false) - .find_each do |user| + .where("user_emails.email ~* '@(#{domains})$'") + .where("users.id NOT IN (SELECT user_id FROM group_users WHERE group_users.group_id = ?)", group_id) + .activated + .where(staged: false) + .find_each do |user| next unless user.email_confirmed? group.add(user) GroupActionLogger.new(Discourse.system_user, group).log_add_user_to_group(user) diff --git a/app/jobs/regular/delete_topic.rb b/app/jobs/regular/delete_topic.rb index e50cd9c2dae..bfb23f568cf 100644 --- a/app/jobs/regular/delete_topic.rb +++ b/app/jobs/regular/delete_topic.rb @@ -12,7 +12,7 @@ module Jobs if Guardian.new(topic_timer.user).can_delete?(topic) first_post = topic.ordered_posts.first - PostDestroyer.new(topic_timer.user, first_post, { context: I18n.t("topic_statuses.auto_deleted_by_timer") }).destroy + PostDestroyer.new(topic_timer.user, first_post, context: I18n.t("topic_statuses.auto_deleted_by_timer")).destroy topic_timer.trash!(Discourse.system_user) end end diff --git a/app/jobs/regular/emit_web_hook_event.rb b/app/jobs/regular/emit_web_hook_event.rb index 46ce3f43bd1..341702904a8 100644 --- a/app/jobs/regular/emit_web_hook_event.rb +++ b/app/jobs/regular/emit_web_hook_event.rb @@ -83,12 +83,13 @@ module Jobs web_hook_event = WebHookEvent.create!(web_hook_id: web_hook.id) begin - content_type = case web_hook.content_type - when WebHook.content_types['application/x-www-form-urlencoded'] - 'application/x-www-form-urlencoded' - else - 'application/json' - end + content_type = + case web_hook.content_type + when WebHook.content_types['application/x-www-form-urlencoded'] + 'application/x-www-form-urlencoded' + else + 'application/json' + end headers = { 'Accept' => '*/*', diff --git a/app/jobs/regular/export_csv_file.rb b/app/jobs/regular/export_csv_file.rb index 336c0bfdcc6..69eeec72d49 100644 --- a/app/jobs/regular/export_csv_file.rb +++ b/app/jobs/regular/export_csv_file.rb @@ -8,18 +8,18 @@ module Jobs sidekiq_options retry: false - HEADER_ATTRS_FOR ||= HashWithIndifferentAccess.new({ - user_archive: ['topic_title','category','sub_category','is_pm','post','like_count','reply_count','url','created_at'], - user_list: ['id','name','username','email','title','created_at','last_seen_at','last_posted_at','last_emailed_at','trust_level','approved','suspended_at','suspended_till','blocked','active','admin','moderator','ip_address'], - user_stats: ['topics_entered','posts_read_count','time_read','topic_count','post_count','likes_given','likes_received'], - user_profile: ['location','website','views'], - user_sso: ['external_id','external_email', 'external_username', 'external_name', 'external_avatar_url'], - staff_action: ['staff_user','action','subject','created_at','details', 'context'], - screened_email: ['email','action','match_count','last_match_at','created_at','ip_address'], - screened_ip: ['ip_address','action','match_count','last_match_at','created_at'], - screened_url: ['domain','action','match_count','last_match_at','created_at'], - report: ['date', 'value'], - }) + HEADER_ATTRS_FOR ||= HashWithIndifferentAccess.new( + user_archive: ['topic_title', 'category', 'sub_category', 'is_pm', 'post', 'like_count', 'reply_count', 'url', 'created_at'], + user_list: ['id', 'name', 'username', 'email', 'title', 'created_at', 'last_seen_at', 'last_posted_at', 'last_emailed_at', 'trust_level', 'approved', 'suspended_at', 'suspended_till', 'blocked', 'active', 'admin', 'moderator', 'ip_address'], + user_stats: ['topics_entered', 'posts_read_count', 'time_read', 'topic_count', 'post_count', 'likes_given', 'likes_received'], + user_profile: ['location', 'website', 'views'], + user_sso: ['external_id', 'external_email', 'external_username', 'external_name', 'external_avatar_url'], + staff_action: ['staff_user', 'action', 'subject', 'created_at', 'details', 'context'], + screened_email: ['email', 'action', 'match_count', 'last_match_at', 'created_at', 'ip_address'], + screened_ip: ['ip_address', 'action', 'match_count', 'last_match_at', 'created_at'], + screened_url: ['domain', 'action', 'match_count', 'last_match_at', 'created_at'], + report: ['date', 'value'] + ) def execute(args) @entity = args[:entity] @@ -58,11 +58,11 @@ module Jobs return enum_for(:user_archive_export) unless block_given? Post.includes(topic: :category) - .where(user_id: @current_user.id) - .select(:topic_id, :post_number, :raw, :like_count, :reply_count, :created_at) - .order(:created_at) - .with_deleted - .each do |user_archive| + .where(user_id: @current_user.id) + .select(:topic_id, :post_number, :raw, :like_count, :reply_count, :created_at) + .order(:created_at) + .with_deleted + .each do |user_archive| yield get_user_archive_fields(user_archive) end end @@ -132,9 +132,9 @@ module Jobs return enum_for(:screened_url_export) unless block_given? ScreenedUrl.select("domain, sum(match_count) as match_count, max(last_match_at) as last_match_at, min(created_at) as created_at") - .group(:domain) - .order('last_match_at DESC') - .each do |screened_url| + .group(:domain) + .order('last_match_at DESC') + .each do |screened_url| yield get_screened_url_fields(screened_url) end end @@ -181,14 +181,14 @@ module Jobs def get_base_user_array(user) user_array = [] - user_array.push(user.id,escape_comma(user.name),user.username,user.email,escape_comma(user.title),user.created_at,user.last_seen_at,user.last_posted_at,user.last_emailed_at,user.trust_level,user.approved,user.suspended_at,user.suspended_till,user.blocked,user.active,user.admin,user.moderator,user.ip_address,user.user_stat.topics_entered,user.user_stat.posts_read_count,user.user_stat.time_read,user.user_stat.topic_count,user.user_stat.post_count,user.user_stat.likes_given,user.user_stat.likes_received,escape_comma(user.user_profile.location),user.user_profile.website,user.user_profile.views) + user_array.push(user.id, escape_comma(user.name), user.username, user.email, escape_comma(user.title), user.created_at, user.last_seen_at, user.last_posted_at, user.last_emailed_at, user.trust_level, user.approved, user.suspended_at, user.suspended_till, user.blocked, user.active, user.admin, user.moderator, user.ip_address, user.user_stat.topics_entered, user.user_stat.posts_read_count, user.user_stat.time_read, user.user_stat.topic_count, user.user_stat.post_count, user.user_stat.likes_given, user.user_stat.likes_received, escape_comma(user.user_profile.location), user.user_profile.website, user.user_profile.views) end def add_single_sign_on(user, user_info_array) if user.single_sign_on_record - user_info_array.push(user.single_sign_on_record.external_id,user.single_sign_on_record.external_email,user.single_sign_on_record.external_username,escape_comma(user.single_sign_on_record.external_name),user.single_sign_on_record.external_avatar_url) + user_info_array.push(user.single_sign_on_record.external_id, user.single_sign_on_record.external_email, user.single_sign_on_record.external_username, escape_comma(user.single_sign_on_record.external_name), user.single_sign_on_record.external_avatar_url) else - user_info_array.push(nil,nil,nil,nil,nil) + user_info_array.push(nil, nil, nil, nil, nil) end user_info_array end @@ -233,7 +233,7 @@ module Jobs is_pm = topic_data.archetype == "private_message" ? I18n.t("csv_export.boolean_yes") : I18n.t("csv_export.boolean_no") url = "#{Discourse.base_url}/t/#{topic_data.slug}/#{topic_data.id}/#{user_archive['post_number']}" - topic_hash = {"post" => user_archive['raw'], "topic_title" => topic_data.title, "category" => category_name, "sub_category" => sub_category, "is_pm" => is_pm, "url" => url} + topic_hash = { "post" => user_archive['raw'], "topic_title" => topic_data.title, "category" => category_name, "sub_category" => sub_category, "is_pm" => is_pm, "url" => url } user_archive.merge!(topic_hash) HEADER_ATTRS_FOR['user_archive'].each do |attr| diff --git a/app/jobs/regular/notify_mailing_list_subscribers.rb b/app/jobs/regular/notify_mailing_list_subscribers.rb index 41773141824..6b8647a36bc 100644 --- a/app/jobs/regular/notify_mailing_list_subscribers.rb +++ b/app/jobs/regular/notify_mailing_list_subscribers.rb @@ -14,19 +14,19 @@ module Jobs users = User.activated.not_blocked.not_suspended.real - .joins(:user_option) - .where('user_options.mailing_list_mode AND user_options.mailing_list_mode_frequency > 0') - .where('NOT EXISTS ( + .joins(:user_option) + .where('user_options.mailing_list_mode AND user_options.mailing_list_mode_frequency > 0') + .where('NOT EXISTS ( SELECT 1 FROM muted_users mu WHERE mu.muted_user_id = ? AND mu.user_id = users.id )', post.user_id) - .where('NOT EXISTS ( + .where('NOT EXISTS ( SELECT 1 FROM topic_users tu WHERE tu.topic_id = ? AND tu.user_id = users.id AND tu.notification_level = ? )', post.topic_id, TopicUser.notification_levels[:muted]) - .where('NOT EXISTS ( + .where('NOT EXISTS ( SELECT 1 FROM category_users cu WHERE cu.category_id = ? AND cu.user_id = users.id AND cu.notification_level = ? @@ -57,7 +57,7 @@ module Jobs end end rescue => e - Discourse.handle_job_exception(e, error_context(args, "Sending post to mailing list subscribers", { user_id: user.id, user_email: user.email })) + Discourse.handle_job_exception(e, error_context(args, "Sending post to mailing list subscribers", user_id: user.id, user_email: user.email)) end end end diff --git a/app/jobs/regular/notify_moved_posts.rb b/app/jobs/regular/notify_moved_posts.rb index da1300e86c1..9916bab8e77 100644 --- a/app/jobs/regular/notify_moved_posts.rb +++ b/app/jobs/regular/notify_moved_posts.rb @@ -17,8 +17,8 @@ module Jobs p.user.notifications.create(notification_type: Notification.types[:moved_post], topic_id: p.topic_id, post_number: p.post_number, - data: {topic_title: p.topic.title, - display_username: moved_by.username}.to_json) + data: { topic_title: p.topic.title, + display_username: moved_by.username }.to_json) users_notified << p.user_id end end diff --git a/app/jobs/regular/push_notification.rb b/app/jobs/regular/push_notification.rb index e07e5d59208..965acb963b3 100644 --- a/app/jobs/regular/push_notification.rb +++ b/app/jobs/regular/push_notification.rb @@ -13,11 +13,9 @@ module Jobs } clients = args["clients"] - clients.group_by{|r| r[1]}.each do |push_url, group| + clients.group_by { |r| r[1] }.each do |push_url, group| notifications = group.map do |client_id, _| - notification.merge({ - client_id: client_id - }) + notification.merge(client_id: client_id) end result = Excon.post(push_url, diff --git a/app/jobs/regular/retrieve_topic.rb b/app/jobs/regular/retrieve_topic.rb index 2820f05e310..9d5d4e248cf 100644 --- a/app/jobs/regular/retrieve_topic.rb +++ b/app/jobs/regular/retrieve_topic.rb @@ -19,5 +19,3 @@ module Jobs end end - - diff --git a/app/jobs/regular/user_email.rb b/app/jobs/regular/user_email.rb index f9def1f4510..f28019b74c6 100644 --- a/app/jobs/regular/user_email.rb +++ b/app/jobs/regular/user_email.rb @@ -56,7 +56,7 @@ module Jobs quoted } - def message_for_email(user, post, type, notification, notification_type=nil, notification_data_hash=nil, email_token=nil, to_address=nil) + def message_for_email(user, post, type, notification, notification_type = nil, notification_data_hash = nil, email_token = nil, to_address = nil) set_skip_context(type, user.id, to_address || user.email, post.try(:id)) return skip_message(I18n.t("email_log.anonymous_user")) if user.anonymous? @@ -90,8 +90,8 @@ module Jobs user.user_option.mailing_list_mode_frequency > 0 && # don't catch notifications for users on daily mailing list mode (!post.try(:topic).try(:private_message?)) && NOTIFICATIONS_SENT_BY_MAILING_LIST.include?(email_args[:notification_type]) - # no need to log a reason when the mail was already sent via the mailing list job - return [nil, nil] + # no need to log a reason when the mail was already sent via the mailing list job + return [nil, nil] end unless user.user_option.email_always? @@ -141,7 +141,7 @@ module Jobs # extracted from sidekiq def self.seconds_to_delay(count) - (count ** 4) + 15 + (rand(30) * (count + 1)) + (count**4) + 15 + (rand(30) * (count + 1)) end private diff --git a/app/jobs/scheduled/badge_grant.rb b/app/jobs/scheduled/badge_grant.rb index dc5def06840..a9d9b915a78 100644 --- a/app/jobs/scheduled/badge_grant.rb +++ b/app/jobs/scheduled/badge_grant.rb @@ -15,7 +15,7 @@ module Jobs BadgeGranter.backfill(b) rescue => ex # TODO - expose errors in UI - Discourse.handle_job_exception(ex, error_context({}, code_desc: 'Exception granting badges', extra: {badge_id: b.id})) + Discourse.handle_job_exception(ex, error_context({}, code_desc: 'Exception granting badges', extra: { badge_id: b.id })) end end diff --git a/app/jobs/scheduled/clean_up_email_logs.rb b/app/jobs/scheduled/clean_up_email_logs.rb index 30305c4d9ac..48421c1cfa2 100644 --- a/app/jobs/scheduled/clean_up_email_logs.rb +++ b/app/jobs/scheduled/clean_up_email_logs.rb @@ -9,8 +9,8 @@ module Jobs threshold = SiteSetting.delete_email_logs_after_days.days.ago EmailLog.where(reply_key: nil) - .where("created_at < ?", threshold) - .delete_all + .where("created_at < ?", threshold) + .delete_all end end diff --git a/app/jobs/scheduled/clean_up_unmatched_emails.rb b/app/jobs/scheduled/clean_up_unmatched_emails.rb index 6ce62f3f235..4fff997ef81 100644 --- a/app/jobs/scheduled/clean_up_unmatched_emails.rb +++ b/app/jobs/scheduled/clean_up_unmatched_emails.rb @@ -7,8 +7,8 @@ module Jobs last_match_threshold = SiteSetting.max_age_unmatched_emails.days.ago ScreenedEmail.where(action_type: ScreenedEmail.actions[:block]) - .where("last_match_at < ?", last_match_threshold) - .destroy_all + .where("last_match_at < ?", last_match_threshold) + .destroy_all end end diff --git a/app/jobs/scheduled/clean_up_unmatched_ips.rb b/app/jobs/scheduled/clean_up_unmatched_ips.rb index abd3cdc4421..a9b4e4d5d33 100644 --- a/app/jobs/scheduled/clean_up_unmatched_ips.rb +++ b/app/jobs/scheduled/clean_up_unmatched_ips.rb @@ -11,8 +11,8 @@ module Jobs # remove old unmatched IP addresses ScreenedIpAddress.where(action_type: ScreenedIpAddress.actions[:block]) - .where("last_match_at < ? OR (last_match_at IS NULL AND created_at < ?)", last_match_threshold, last_match_threshold) - .destroy_all + .where("last_match_at < ? OR (last_match_at IS NULL AND created_at < ?)", last_match_threshold, last_match_threshold) + .destroy_all end end diff --git a/app/jobs/scheduled/clean_up_unsubscribe_keys.rb b/app/jobs/scheduled/clean_up_unsubscribe_keys.rb index 05358666712..606a13390ba 100644 --- a/app/jobs/scheduled/clean_up_unsubscribe_keys.rb +++ b/app/jobs/scheduled/clean_up_unsubscribe_keys.rb @@ -10,4 +10,3 @@ module Jobs end end - diff --git a/app/jobs/scheduled/create_missing_avatars.rb b/app/jobs/scheduled/create_missing_avatars.rb index 2d4befe245f..d973e9a0be0 100644 --- a/app/jobs/scheduled/create_missing_avatars.rb +++ b/app/jobs/scheduled/create_missing_avatars.rb @@ -5,11 +5,11 @@ module Jobs def execute(args) # backfill in batches of 5000 an hour UserAvatar.includes(:user) - .joins(:user) - .where(last_gravatar_download_attempt: nil) - .order("users.last_posted_at DESC") - .limit(5000) - .each do |u| + .joins(:user) + .where(last_gravatar_download_attempt: nil) + .order("users.last_posted_at DESC") + .limit(5000) + .each do |u| u.user.refresh_avatar end end diff --git a/app/jobs/scheduled/dashboard_stats.rb b/app/jobs/scheduled/dashboard_stats.rb index 2b35fc43809..75977e7acbd 100644 --- a/app/jobs/scheduled/dashboard_stats.rb +++ b/app/jobs/scheduled/dashboard_stats.rb @@ -7,7 +7,7 @@ module Jobs if problems_started_at && problems_started_at < 2.days.ago # If there have been problems reported on the dashboard for a while, # send a message to admins no more often than once per week. - GroupMessage.create(Group[:admins].name, :dashboard_problems, {limit_once_per: 7.days.to_i}) + GroupMessage.create(Group[:admins].name, :dashboard_problems, limit_once_per: 7.days.to_i) end AdminDashboardData.refresh_stats diff --git a/app/jobs/scheduled/directory_refresh_older.rb b/app/jobs/scheduled/directory_refresh_older.rb index 3c25c8151fc..93147d6c88a 100644 --- a/app/jobs/scheduled/directory_refresh_older.rb +++ b/app/jobs/scheduled/directory_refresh_older.rb @@ -4,7 +4,7 @@ module Jobs def execute(args) periods = DirectoryItem.period_types.keys - [:daily] - periods.each {|p| DirectoryItem.refresh_period!(p)} + periods.each { |p| DirectoryItem.refresh_period!(p) } end end end diff --git a/app/jobs/scheduled/enqueue_digest_emails.rb b/app/jobs/scheduled/enqueue_digest_emails.rb index 1bd4ed4fdfb..23db70d4e52 100644 --- a/app/jobs/scheduled/enqueue_digest_emails.rb +++ b/app/jobs/scheduled/enqueue_digest_emails.rb @@ -14,15 +14,15 @@ module Jobs def target_user_ids # Users who want to receive digest email within their chosen digest email frequency query = User.real - .not_suspended - .activated - .where(staged: false) - .joins(:user_option, :user_stat) - .where("user_options.email_digests") - .where("user_stats.bounce_score < #{SiteSetting.bounce_score_threshold}") - .where("COALESCE(last_emailed_at, '2010-01-01') <= CURRENT_TIMESTAMP - ('1 MINUTE'::INTERVAL * user_options.digest_after_minutes)") - .where("COALESCE(last_seen_at, '2010-01-01') <= CURRENT_TIMESTAMP - ('1 MINUTE'::INTERVAL * user_options.digest_after_minutes)") - .where("COALESCE(last_seen_at, '2010-01-01') >= CURRENT_TIMESTAMP - ('1 DAY'::INTERVAL * #{SiteSetting.suppress_digest_email_after_days})") + .not_suspended + .activated + .where(staged: false) + .joins(:user_option, :user_stat) + .where("user_options.email_digests") + .where("user_stats.bounce_score < #{SiteSetting.bounce_score_threshold}") + .where("COALESCE(last_emailed_at, '2010-01-01') <= CURRENT_TIMESTAMP - ('1 MINUTE'::INTERVAL * user_options.digest_after_minutes)") + .where("COALESCE(last_seen_at, '2010-01-01') <= CURRENT_TIMESTAMP - ('1 MINUTE'::INTERVAL * user_options.digest_after_minutes)") + .where("COALESCE(last_seen_at, '2010-01-01') >= CURRENT_TIMESTAMP - ('1 DAY'::INTERVAL * #{SiteSetting.suppress_digest_email_after_days})") # If the site requires approval, make sure the user is approved query = query.where("approved OR moderator OR admin") if SiteSetting.must_approve_users? diff --git a/app/jobs/scheduled/grant_new_user_of_the_month_badges.rb b/app/jobs/scheduled/grant_new_user_of_the_month_badges.rb index c2190d16056..83e5b5cc728 100644 --- a/app/jobs/scheduled/grant_new_user_of_the_month_badges.rb +++ b/app/jobs/scheduled/grant_new_user_of_the_month_badges.rb @@ -8,7 +8,7 @@ module Jobs def execute(args) badge = Badge.find(Badge::NewUserOfTheMonth) - return unless SiteSetting.enable_badges? and badge.enabled? + return unless SiteSetting.enable_badges? && badge.enabled? # Don't award it if a month hasn't gone by return if UserBadge.where("badge_id = ? AND granted_at >= ?", @@ -22,9 +22,7 @@ module Jobs user = User.find(user_id) if user.badges.where(id: Badge::NewUserOfTheMonth).blank? BadgeGranter.grant(badge, user) - SystemMessage.new(user).create('new_user_of_the_month', { - month_year: Time.now.strftime("%B %Y") - }) + SystemMessage.new(user).create('new_user_of_the_month', month_year: Time.now.strftime("%B %Y")) end end end @@ -75,10 +73,8 @@ module Jobs LIMIT :max_awarded SQL - User.exec_sql(sql, { - like: PostActionType.types[:like], - max_awarded: MAX_AWARDED - }).each do |row| + User.exec_sql(sql, like: PostActionType.types[:like], + max_awarded: MAX_AWARDED).each do |row| scores[row['id'].to_i] = row['score'].to_f end scores diff --git a/app/jobs/scheduled/migrate_upload_scheme.rb b/app/jobs/scheduled/migrate_upload_scheme.rb index a5e21f3e0d4..6be51da6995 100644 --- a/app/jobs/scheduled/migrate_upload_scheme.rb +++ b/app/jobs/scheduled/migrate_upload_scheme.rb @@ -9,8 +9,8 @@ module Jobs # clean up failed uploads Upload.where("created_at < ?", 1.hour.ago) - .where("LENGTH(COALESCE(url, '')) = 0") - .destroy_all + .where("LENGTH(COALESCE(url, '')) = 0") + .destroy_all # migrate uploads to new scheme problems = Upload.migrate_to_new_scheme(50) diff --git a/app/jobs/scheduled/pending_flags_reminder.rb b/app/jobs/scheduled/pending_flags_reminder.rb index 2a33c517852..128a52187c6 100644 --- a/app/jobs/scheduled/pending_flags_reminder.rb +++ b/app/jobs/scheduled/pending_flags_reminder.rb @@ -25,8 +25,8 @@ module Jobs target_group_names: Group[:moderators].name, archetype: Archetype.private_message, subtype: TopicSubtype.system_message, - title: I18n.t('flags_reminder.subject_template', { count: flagged_posts_count }), - raw: mentions + I18n.t('flags_reminder.flags_were_submitted', { count: SiteSetting.notify_about_flags_after }) + title: I18n.t('flags_reminder.subject_template', count: flagged_posts_count), + raw: mentions + I18n.t('flags_reminder.flags_were_submitted', count: SiteSetting.notify_about_flags_after) ) self.last_notified_id = flag_ids.max @@ -54,10 +54,10 @@ module Jobs def active_moderator_usernames User.where(moderator: true) - .human_users - .order('last_seen_at DESC') - .limit(3) - .pluck(:username) + .human_users + .order('last_seen_at DESC') + .limit(3) + .pluck(:username) end end diff --git a/app/jobs/scheduled/pending_users_reminder.rb b/app/jobs/scheduled/pending_users_reminder.rb index c2e392d65a4..5c682bb4e35 100644 --- a/app/jobs/scheduled/pending_users_reminder.rb +++ b/app/jobs/scheduled/pending_users_reminder.rb @@ -7,7 +7,7 @@ module Jobs def execute(args) if SiteSetting.must_approve_users && SiteSetting.pending_users_reminder_delay >= 0 - query = AdminUserIndexQuery.new({query: 'pending', stats: false}).find_users_query # default order is: users.created_at DESC + query = AdminUserIndexQuery.new(query: 'pending', stats: false).find_users_query # default order is: users.created_at DESC if SiteSetting.pending_users_reminder_delay > 0 query = query.where('users.created_at < ?', SiteSetting.pending_users_reminder_delay.hours.ago) end @@ -21,10 +21,10 @@ module Jobs if count > 0 target_usernames = Group[:moderators].users.map do |u| u.id > 0 && u.notifications.joins(:topic) - .where("notifications.id > ?", u.seen_notification_id) - .where("notifications.read = false") - .where("topics.subtype = '#{TopicSubtype.pending_users_reminder}'") - .count == 0 ? u.username : nil + .where("notifications.id > ?", u.seen_notification_id) + .where("notifications.read = false") + .where("topics.subtype = '#{TopicSubtype.pending_users_reminder}'") + .count == 0 ? u.username : nil end.compact unless target_usernames.empty? @@ -33,8 +33,8 @@ module Jobs target_usernames: target_usernames, archetype: Archetype.private_message, subtype: TopicSubtype.pending_users_reminder, - title: I18n.t("system_messages.pending_users_reminder.subject_template", {count: count}), - raw: I18n.t("system_messages.pending_users_reminder.text_body_template", {count: count, base_url: Discourse.base_url}) + title: I18n.t("system_messages.pending_users_reminder.subject_template", count: count), + raw: I18n.t("system_messages.pending_users_reminder.text_body_template", count: count, base_url: Discourse.base_url) ) self.previous_newest_username = newest_username diff --git a/app/jobs/scheduled/periodical_updates.rb b/app/jobs/scheduled/periodical_updates.rb index 98751dffc38..a1223434825 100644 --- a/app/jobs/scheduled/periodical_updates.rb +++ b/app/jobs/scheduled/periodical_updates.rb @@ -20,7 +20,7 @@ module Jobs CategoryFeaturedTopic.feature_topics # Update the scores of posts - args = {min_topic_age: 1.day.ago} + args = { min_topic_age: 1.day.ago } args[:max_topic_length] = 500 unless self.class.should_update_long_topics? ScoreCalculator.new.calculate(args) diff --git a/app/jobs/scheduled/purge_inactive.rb b/app/jobs/scheduled/purge_inactive.rb index a6615f5fe25..21417bef216 100644 --- a/app/jobs/scheduled/purge_inactive.rb +++ b/app/jobs/scheduled/purge_inactive.rb @@ -7,4 +7,3 @@ module Jobs end end end - diff --git a/app/jobs/scheduled/tl3_promotions.rb b/app/jobs/scheduled/tl3_promotions.rb index 37acfcec154..a816d471c5a 100644 --- a/app/jobs/scheduled/tl3_promotions.rb +++ b/app/jobs/scheduled/tl3_promotions.rb @@ -19,7 +19,7 @@ module Jobs # Promotions User.real.where(trust_level: TrustLevel[2], trust_level_locked: false) - .where.not(id: demoted_user_ids).find_each do |u| + .where.not(id: demoted_user_ids).find_each do |u| Promotion.new(u).review_tl2 end end diff --git a/app/jobs/scheduled/version_check.rb b/app/jobs/scheduled/version_check.rb index 9fb39252ee4..51b08d379d9 100644 --- a/app/jobs/scheduled/version_check.rb +++ b/app/jobs/scheduled/version_check.rb @@ -6,7 +6,7 @@ module Jobs every 1.day def execute(args) - if SiteSetting.version_checks? and (DiscourseUpdates.updated_at.nil? or DiscourseUpdates.updated_at < 1.minute.ago) + if SiteSetting.version_checks? && (DiscourseUpdates.updated_at.nil? || DiscourseUpdates.updated_at < (1.minute.ago)) begin prev_missing_versions_count = DiscourseUpdates.missing_versions_count || 0 @@ -18,10 +18,10 @@ module Jobs DiscourseUpdates.updated_at = Time.zone.now DiscourseUpdates.missing_versions = json['versions'] - if GlobalSetting.new_version_emails and - SiteSetting.new_version_emails and - json['missingVersionsCount'] > 0 and - prev_missing_versions_count < json['missingVersionsCount'].to_i + if GlobalSetting.new_version_emails && + SiteSetting.new_version_emails && + json['missingVersionsCount'] > (0) && + prev_missing_versions_count < (json['missingVersionsCount'].to_i) message = VersionMailer.send_notice Email::Sender.new(message, :new_version).send diff --git a/app/mailers/admin_confirmation_mailer.rb b/app/mailers/admin_confirmation_mailer.rb index ea4d444ad8c..dc2d7df41de 100644 --- a/app/mailers/admin_confirmation_mailer.rb +++ b/app/mailers/admin_confirmation_mailer.rb @@ -12,4 +12,3 @@ class AdminConfirmationMailer < ActionMailer::Base ) end end - diff --git a/app/mailers/pending_flags_mailer.rb b/app/mailers/pending_flags_mailer.rb index c0f67d2bf29..39fbbb0fd16 100644 --- a/app/mailers/pending_flags_mailer.rb +++ b/app/mailers/pending_flags_mailer.rb @@ -23,14 +23,14 @@ class PendingFlagsMailer < ActionMailer::Base @hours = SiteSetting.notify_about_flags_after - subject = "[#{SiteSetting.title}] " + I18n.t('flags_reminder.subject_template', { count: PostAction.flagged_posts_count }) + subject = "[#{SiteSetting.title}] " + I18n.t('flags_reminder.subject_template', count: PostAction.flagged_posts_count) build_email(SiteSetting.contact_email, subject: subject) end private def flag_reason_counts(post) - post[:post_actions].inject({}) do |h,v| + post[:post_actions].inject({}) do |h, v| h[v[:name_key]] ||= 0 h[v[:name_key]] += 1 h diff --git a/app/mailers/pending_queued_posts_mailer.rb b/app/mailers/pending_queued_posts_mailer.rb index fec7c3ba729..525454b7d22 100644 --- a/app/mailers/pending_queued_posts_mailer.rb +++ b/app/mailers/pending_queued_posts_mailer.rb @@ -3,7 +3,7 @@ require_dependency 'email/message_builder' class PendingQueuedPostsMailer < ActionMailer::Base include Email::BuildEmailHelper - def notify(opts={}) + def notify(opts = {}) return unless SiteSetting.contact_email build_email(SiteSetting.contact_email, template: 'queued_posts_reminder', count: opts[:count]) end diff --git a/app/mailers/subscription_mailer.rb b/app/mailers/subscription_mailer.rb index 51a66797a65..d8ea40d2fb7 100644 --- a/app/mailers/subscription_mailer.rb +++ b/app/mailers/subscription_mailer.rb @@ -3,7 +3,7 @@ require_dependency 'email/message_builder' class SubscriptionMailer < ActionMailer::Base include Email::BuildEmailHelper - def confirm_unsubscribe(user, opts={}) + def confirm_unsubscribe(user, opts = {}) unsubscribe_key = UnsubscribeKey.create_key_for(user, "all") build_email user.email, template: "unsubscribe_mailer", diff --git a/app/mailers/user_notifications.rb b/app/mailers/user_notifications.rb index c209a940d16..049e6658275 100644 --- a/app/mailers/user_notifications.rb +++ b/app/mailers/user_notifications.rb @@ -11,14 +11,14 @@ class UserNotifications < ActionMailer::Base include Email::BuildEmailHelper - def signup(user, opts={}) + def signup(user, opts = {}) build_email(user.email, template: "user_notifications.signup", locale: user_locale(user), email_token: opts[:email_token]) end - def signup_after_approval(user, opts={}) + def signup_after_approval(user, opts = {}) build_email(user.email, template: 'user_notifications.signup_after_approval', locale: user_locale(user), @@ -26,42 +26,42 @@ class UserNotifications < ActionMailer::Base new_user_tips: I18n.t('system_messages.usage_tips.text_body_template', base_url: Discourse.base_url, locale: locale)) end - def notify_old_email(user, opts={}) + def notify_old_email(user, opts = {}) build_email(user.email, template: "user_notifications.notify_old_email", locale: user_locale(user), new_email: opts[:new_email]) end - def confirm_old_email(user, opts={}) + def confirm_old_email(user, opts = {}) build_email(user.email, template: "user_notifications.confirm_old_email", locale: user_locale(user), email_token: opts[:email_token]) end - def confirm_new_email(user, opts={}) + def confirm_new_email(user, opts = {}) build_email(user.email, template: "user_notifications.confirm_new_email", locale: user_locale(user), email_token: opts[:email_token]) end - def forgot_password(user, opts={}) + def forgot_password(user, opts = {}) build_email(user.email, template: user.has_password? ? "user_notifications.forgot_password" : "user_notifications.set_password", locale: user_locale(user), email_token: opts[:email_token]) end - def admin_login(user, opts={}) + def admin_login(user, opts = {}) build_email(user.email, template: "user_notifications.admin_login", locale: user_locale(user), email_token: opts[:email_token]) end - def account_created(user, opts={}) + def account_created(user, opts = {}) build_email(user.email, template: "user_notifications.account_created", locale: user_locale(user), @@ -76,30 +76,30 @@ class UserNotifications < ActionMailer::Base end end - def digest(user, opts={}) + def digest(user, opts = {}) build_summary_for(user) min_date = opts[:since] || user.last_emailed_at || user.last_seen_at || 1.month.ago # Fetch some topics and posts to show - digest_opts = {limit: SiteSetting.digest_topics + SiteSetting.digest_other_topics, top_order: true} + digest_opts = { limit: SiteSetting.digest_topics + SiteSetting.digest_other_topics, top_order: true } topics_for_digest = Topic.for_digest(user, min_date, digest_opts).to_a if topics_for_digest.empty? && !user.user_option.try(:include_tl0_in_digests) # Find some topics from new users that are at least 24 hours old topics_for_digest = Topic.for_digest(user, min_date, digest_opts.merge(include_tl0: true)).where('topics.created_at < ?', 24.hours.ago).to_a end - @popular_topics = topics_for_digest[0,SiteSetting.digest_topics] + @popular_topics = topics_for_digest[0, SiteSetting.digest_topics] if @popular_topics.present? @other_new_for_you = topics_for_digest.size > SiteSetting.digest_topics ? topics_for_digest[SiteSetting.digest_topics..-1] : [] @popular_posts = if SiteSetting.digest_posts > 0 Post.order("posts.score DESC") - .for_mailing_list(user, min_date) - .where('posts.post_type = ?', Post.types[:regular]) - .where('posts.deleted_at IS NULL AND posts.hidden = false AND posts.user_deleted = false') - .where("posts.post_number > ? AND posts.score > ?", 1, ScoreCalculator.default_score_weights[:like_score] * 5.0) - .limit(SiteSetting.digest_posts) + .for_mailing_list(user, min_date) + .where('posts.post_type = ?', Post.types[:regular]) + .where('posts.deleted_at IS NULL AND posts.hidden = false AND posts.user_deleted = false') + .where("posts.post_number > ? AND posts.score > ?", 1, ScoreCalculator.default_score_weights[:like_score] * 5.0) + .limit(SiteSetting.digest_posts) else [] end @@ -117,19 +117,19 @@ class UserNotifications < ActionMailer::Base # We used topics from new users instead, so count should match new_topics_count = topics_for_digest.size end - @counts = [{label_key: 'user_notifications.digest.new_topics', - value: new_topics_count, - href: "#{Discourse.base_url}/new"}] + @counts = [{ label_key: 'user_notifications.digest.new_topics', + value: new_topics_count, + href: "#{Discourse.base_url}/new" }] value = user.unread_notifications - @counts << {label_key: 'user_notifications.digest.unread_notifications', value: value, href: "#{Discourse.base_url}/my/notifications"} if value > 0 + @counts << { label_key: 'user_notifications.digest.unread_notifications', value: value, href: "#{Discourse.base_url}/my/notifications" } if value > 0 value = user.unread_private_messages - @counts << {label_key: 'user_notifications.digest.unread_messages', value: value, href: "#{Discourse.base_url}/my/messages"} if value > 0 + @counts << { label_key: 'user_notifications.digest.unread_messages', value: value, href: "#{Discourse.base_url}/my/messages" } if value > 0 if @counts.size < 3 value = user.unread_notifications_of_type(Notification.types[:liked]) - @counts << {label_key: 'user_notifications.digest.liked_received', value: value, href: "#{Discourse.base_url}/my/notifications"} if value > 0 + @counts << { label_key: 'user_notifications.digest.liked_received', value: value, href: "#{Discourse.base_url}/my/notifications" } if value > 0 end if @counts.size < 3 @@ -157,7 +157,6 @@ class UserNotifications < ActionMailer::Base end end - def user_replied(user, opts) opts[:allow_reply_by_email] = true opts[:use_site_subject] = true @@ -252,7 +251,7 @@ class UserNotifications < ActionMailer::Base (user.locale.present? && I18n.available_locales.include?(user.locale.to_sym)) ? user.locale : nil end - def email_post_markdown(post, add_posted_by=false) + def email_post_markdown(post, add_posted_by = false) result = "#{post.raw}\n\n" if add_posted_by result << "#{I18n.t('user_notifications.posted_by', username: post.username, post_date: post.created_at.strftime("%m/%d/%Y"))}\n\n" @@ -275,12 +274,12 @@ class UserNotifications < ActionMailer::Base allowed_post_types << Post.types[:whisper] if topic_user.try(:user).try(:staff?) context_posts = Post.where(topic_id: post.topic_id) - .where("post_number < ?", post.post_number) - .where(user_deleted: false) - .where(hidden: false) - .where(post_type: allowed_post_types) - .order('created_at desc') - .limit(SiteSetting.email_posts_context) + .where("post_number < ?", post.post_number) + .where(user_deleted: false) + .where(hidden: false) + .where(post_type: allowed_post_types) + .order('created_at desc') + .limit(SiteSetting.email_posts_context) if topic_user && topic_user.last_emailed_post_number && user.user_option.email_previous_replies == UserOption.previous_replies_type[:unless_emailed] context_posts = context_posts.where("post_number > ?", topic_user.last_emailed_post_number) @@ -429,7 +428,7 @@ class UserNotifications < ActionMailer::Base reached_limit = SiteSetting.max_emails_per_day_per_user > 0 reached_limit &&= (EmailLog.where(user_id: user.id, skipped: false) .where('created_at > ?', 1.day.ago) - .count) >= (SiteSetting.max_emails_per_day_per_user-1) + .count) >= (SiteSetting.max_emails_per_day_per_user - 1) in_reply_to_post = post.reply_to_post if user.user_option.email_in_reply_to if SiteSetting.private_email? @@ -438,7 +437,6 @@ class UserNotifications < ActionMailer::Base message = email_post_markdown(post) + (reached_limit ? "\n\n#{I18n.t "user_notifications.reached_limit", count: SiteSetting.max_emails_per_day_per_user}" : ""); end - unless translation_override_exists html = UserNotificationRenderer.new(Rails.configuration.paths["app/views"]).render( template: 'email/notification', diff --git a/app/mailers/version_mailer.rb b/app/mailers/version_mailer.rb index b39136933c6..dad4dbd448c 100644 --- a/app/mailers/version_mailer.rb +++ b/app/mailers/version_mailer.rb @@ -6,17 +6,17 @@ class VersionMailer < ActionMailer::Base def send_notice if SiteSetting.contact_email.present? missing_versions = DiscourseUpdates.missing_versions - if missing_versions.present? and missing_versions.first['notes'].present? - build_email( SiteSetting.contact_email, + if missing_versions.present? && missing_versions.first['notes'].present? + build_email(SiteSetting.contact_email, template: 'new_version_mailer_with_notes', notes: missing_versions.first['notes'], new_version: DiscourseUpdates.latest_version, - installed_version: Discourse::VERSION::STRING ) + installed_version: Discourse::VERSION::STRING) else - build_email( SiteSetting.contact_email, + build_email(SiteSetting.contact_email, template: 'new_version_mailer', new_version: DiscourseUpdates.latest_version, - installed_version: Discourse::VERSION::STRING ) + installed_version: Discourse::VERSION::STRING) end end end diff --git a/app/models/about.rb b/app/models/about.rb index 0d670183ba7..8392df3c483 100644 --- a/app/models/about.rb +++ b/app/models/about.rb @@ -35,8 +35,8 @@ class About def moderators @moderators ||= User.where(moderator: true, admin: false) - .human_users - .order(:username_lower) + .human_users + .order(:username_lower) end def admins diff --git a/app/models/admin_dashboard_data.rb b/app/models/admin_dashboard_data.rb index b4113d609ea..20550a9fd0a 100644 --- a/app/models/admin_dashboard_data.rb +++ b/app/models/admin_dashboard_data.rb @@ -31,7 +31,7 @@ class AdminDashboardData USER_REPORTS ||= ['users_by_trust_level'] - MOBILE_REPORTS ||= ['mobile_visits'] + ApplicationRequest.req_types.keys.select {|r| r =~ /mobile/}.map { |r| r + "_reqs" } + MOBILE_REPORTS ||= ['mobile_visits'] + ApplicationRequest.req_types.keys.select { |r| r =~ /mobile/ }.map { |r| r + "_reqs" } def self.add_problem_check(*syms, &blk) @problem_syms.push(*syms) if syms @@ -120,7 +120,7 @@ class AdminDashboardData $redis.get(problem_message_key(i18n_key)) ? I18n.t(i18n_key) : nil end - def self.add_problem_message(i18n_key, expire_seconds=nil) + def self.add_problem_message(i18n_key, expire_seconds = nil) if expire_seconds.to_i > 0 $redis.setex problem_message_key(i18n_key), expire_seconds.to_i, 1 else diff --git a/app/models/application_request.rb b/app/models/application_request.rb index 8f146f10fd7..1f1f758d956 100644 --- a/app/models/application_request.rb +++ b/app/models/application_request.rb @@ -19,7 +19,7 @@ class ApplicationRequest < ActiveRecord::Base self.autoflush_seconds = 5.minutes self.last_flush = Time.now.utc - def self.increment!(type, opts=nil) + def self.increment!(type, opts = nil) key = redis_key(type) val = $redis.incr(key).to_i # 3.days, see: https://github.com/rails/rails/issues/21296 @@ -36,7 +36,7 @@ class ApplicationRequest < ActiveRecord::Base end end - def self.write_cache!(date=nil) + def self.write_cache!(date = nil) if date.nil? write_cache!(Time.now.utc) write_cache!(Time.now.utc.yesterday) @@ -49,8 +49,8 @@ class ApplicationRequest < ActiveRecord::Base # this may seem a bit fancy but in so it allows # for concurrent calls without double counting - req_types.each do |req_type,_| - key = redis_key(req_type,date) + req_types.each do |req_type, _| + key = redis_key(req_type, date) val = $redis.get(key).to_i next if val == 0 @@ -63,28 +63,28 @@ class ApplicationRequest < ActiveRecord::Base next end - id = req_id(date,req_type) + id = req_id(date, req_type) where(id: id).update_all(["count = count + ?", val]) end end - def self.clear_cache!(date=nil) + def self.clear_cache!(date = nil) if date.nil? clear_cache!(Time.now.utc) clear_cache!(Time.now.utc.yesterday) return end - req_types.each do |req_type,_| - key = redis_key(req_type,date) + req_types.each do |req_type, _| + key = redis_key(req_type, date) $redis.del key end end protected - def self.req_id(date,req_type,retries=0) + def self.req_id(date, req_type, retries = 0) req_type_id = req_types[req_type] @@ -94,13 +94,13 @@ class ApplicationRequest < ActiveRecord::Base rescue # primary key violation if retries == 0 - req_id(date,req_type,1) + req_id(date, req_type, 1) else raise end end - def self.redis_key(req_type, time=Time.now.utc) + def self.redis_key(req_type, time = Time.now.utc) "app_req_#{req_type}#{time.strftime('%Y%m%d')}" end diff --git a/app/models/backup.rb b/app/models/backup.rb index d23d459d008..72a619a06c8 100644 --- a/app/models/backup.rb +++ b/app/models/backup.rb @@ -10,9 +10,9 @@ class Backup def self.all Dir.glob(File.join(Backup.base_directory, "*.{gz,tgz}")) - .sort_by { |file| File.mtime(file) } - .reverse - .map { |backup| Backup.create_from_filename(File.basename(backup)) } + .sort_by { |file| File.mtime(file) } + .reverse + .map { |backup| Backup.create_from_filename(File.basename(backup)) } end def self.[](filename) diff --git a/app/models/badge.rb b/app/models/badge.rb index ac1b3a4d493..46502613f58 100644 --- a/app/models/badge.rb +++ b/app/models/badge.rb @@ -63,7 +63,7 @@ class Badge < ActiveRecord::Base def self.trigger_hash Hash[*( - Badge::Trigger.constants.map{|k| + Badge::Trigger.constants.map { |k| [k.to_s.underscore, Badge::Trigger.const_get(k)] }.flatten )] @@ -100,7 +100,7 @@ class Badge < ActiveRecord::Base validates :allow_title, inclusion: [true, false] validates :multiple_grant, inclusion: [true, false] - scope :enabled, ->{ where(enabled: true) } + scope :enabled, -> { where(enabled: true) } before_create :ensure_not_system @@ -208,7 +208,6 @@ class Badge < ActiveRecord::Base val end - def slug Slug.for(self.display_name, '-') end diff --git a/app/models/badge_type.rb b/app/models/badge_type.rb index 11d4a4b655b..b1d6e91edd9 100644 --- a/app/models/badge_type.rb +++ b/app/models/badge_type.rb @@ -3,7 +3,6 @@ class BadgeType < ActiveRecord::Base Silver = 2 Bronze = 3 - has_many :badges validates :name, presence: true, uniqueness: true end diff --git a/app/models/category.rb b/app/models/category.rb index 02956b4eef2..7939103cd0c 100644 --- a/app/models/category.rb +++ b/app/models/category.rb @@ -72,7 +72,6 @@ class Category < ActiveRecord::Base has_many :category_tag_groups, dependent: :destroy has_many :tag_groups, through: :category_tag_groups - scope :latest, -> { order('topic_count DESC') } scope :secured, -> (guardian = nil) { @@ -141,10 +140,10 @@ class Category < ActiveRecord::Base def self.update_stats topics_with_post_count = Topic - .select("topics.category_id, COUNT(*) topic_count, SUM(topics.posts_count) post_count") - .where("topics.id NOT IN (select cc.topic_id from categories cc WHERE topic_id IS NOT NULL)") - .group("topics.category_id") - .visible.to_sql + .select("topics.category_id, COUNT(*) topic_count, SUM(topics.posts_count) post_count") + .where("topics.id NOT IN (select cc.topic_id from categories cc WHERE topic_id IS NOT NULL)") + .group("topics.category_id") + .visible.to_sql Category.exec_sql <<-SQL UPDATE categories c @@ -183,13 +182,12 @@ SQL end end - def visible_posts query = Post.joins(:topic) - .where(['topics.category_id = ?', self.id]) - .where('topics.visible = true') - .where('posts.deleted_at IS NULL') - .where('posts.user_deleted = false') + .where(['topics.category_id = ?', self.id]) + .where('topics.visible = true') + .where('posts.deleted_at IS NULL') + .where('posts.user_deleted = false') self.topic_id ? query.where(['topics.id <> ?', self.topic_id]) : query end @@ -256,11 +254,11 @@ SQL def publish_category group_ids = self.groups.pluck(:id) if self.read_restricted - MessageBus.publish('/categories', {categories: ActiveModel::ArraySerializer.new([self]).as_json}, group_ids: group_ids) + MessageBus.publish('/categories', { categories: ActiveModel::ArraySerializer.new([self]).as_json }, group_ids: group_ids) end def publish_category_deletion - MessageBus.publish('/categories', {deleted_categories: [self.id]}) + MessageBus.publish('/categories', deleted_categories: [self.id]) end def parent_category_validator @@ -321,7 +319,7 @@ SQL end def allowed_tags=(tag_names_arg) - DiscourseTagging.add_or_create_tags_by_name(self, tag_names_arg, {unlimited: true}) + DiscourseTagging.add_or_create_tags_by_name(self, tag_names_arg, unlimited: true) end def allowed_tag_groups=(group_names) @@ -359,21 +357,21 @@ SQL def update_latest latest_post_id = Post - .order("posts.created_at desc") - .where("NOT hidden") - .joins("join topics on topics.id = topic_id") - .where("topics.category_id = :id", id: self.id) - .limit(1) - .pluck("posts.id") - .first + .order("posts.created_at desc") + .where("NOT hidden") + .joins("join topics on topics.id = topic_id") + .where("topics.category_id = :id", id: self.id) + .limit(1) + .pluck("posts.id") + .first latest_topic_id = Topic - .order("topics.created_at desc") - .where("visible") - .where("topics.category_id = :id", id: self.id) - .limit(1) - .pluck("topics.id") - .first + .order("topics.created_at desc") + .where("visible") + .where("topics.category_id = :id", id: self.id) + .limit(1) + .pluck("topics.id") + .first self.update_attributes(latest_topic_id: latest_topic_id, latest_post_id: latest_post_id) end @@ -384,7 +382,7 @@ SQL everyone = Group::AUTO_GROUPS[:everyone] full = CategoryGroup.permission_types[:full] - mapped = permissions.map do |group,permission| + mapped = permissions.map do |group, permission| group = group.id if group.is_a?(Group) # subtle, using Group[] ensures the group exists in the DB @@ -498,7 +496,7 @@ SQL SearchIndexer.index(self) end - def self.find_by_slug(category_slug, parent_category_slug=nil) + def self.find_by_slug(category_slug, parent_category_slug = nil) if parent_category_slug parent_category_id = self.where(slug: parent_category_slug, parent_category_id: nil).pluck(:id).first self.where(slug: category_slug, parent_category_id: parent_category_id).first diff --git a/app/models/category_featured_topic.rb b/app/models/category_featured_topic.rb index 78331574db3..22d948dd598 100644 --- a/app/models/category_featured_topic.rb +++ b/app/models/category_featured_topic.rb @@ -13,7 +13,7 @@ class CategoryFeaturedTopic < ActiveRecord::Base end end - def self.feature_topics_for(c, existing=nil) + def self.feature_topics_for(c, existing = nil) return if c.blank? query_opts = { @@ -28,7 +28,7 @@ class CategoryFeaturedTopic < ActiveRecord::Base results = query.list_category_topic_ids(c).uniq # Add some topics that are visible to everyone: - anon_query = TopicQuery.new(nil, query_opts.merge({except_topic_ids: [c.topic_id] + results})) + anon_query = TopicQuery.new(nil, query_opts.merge(except_topic_ids: [c.topic_id] + results)) results += anon_query.list_category_topic_ids(c).uniq return if results == existing diff --git a/app/models/category_featured_user.rb b/app/models/category_featured_user.rb index fb75cca87b5..73ac6b1516f 100644 --- a/app/models/category_featured_user.rb +++ b/app/models/category_featured_user.rb @@ -30,7 +30,7 @@ class CategoryFeaturedUser < ActiveRecord::Base LIMIT :max_featured_users; ", category_id: category_id, max_featured_users: max_featured_users - user_ids = most_recent_user_ids.map{|uc| uc['user_id'].to_i} + user_ids = most_recent_user_ids.map { |uc| uc['user_id'].to_i } current = CategoryFeaturedUser.where(category_id: category_id).order(:id).pluck(:user_id) return if current == user_ids diff --git a/app/models/category_list.rb b/app/models/category_list.rb index 39507a2a8aa..ddf9ab5880b 100644 --- a/app/models/category_list.rb +++ b/app/models/category_list.rb @@ -9,7 +9,7 @@ class CategoryList :draft_key, :draft_sequence - def initialize(guardian=nil, options={}) + def initialize(guardian = nil, options = {}) @guardian = guardian || Guardian.new @options = options @@ -63,9 +63,9 @@ class CategoryList @categories = @categories.order(:position, :id) else @categories = @categories.order('COALESCE(categories.posts_week, 0) DESC') - .order('COALESCE(categories.posts_month, 0) DESC') - .order('COALESCE(categories.posts_year, 0) DESC') - .order('id ASC') + .order('COALESCE(categories.posts_month, 0) DESC') + .order('COALESCE(categories.posts_year, 0) DESC') + .order('id ASC') end @categories = @categories.to_a diff --git a/app/models/category_user.rb b/app/models/category_user.rb index 1cb6f502b3e..8d0cf159127 100644 --- a/app/models/category_user.rb +++ b/app/models/category_user.rb @@ -62,7 +62,7 @@ class CategoryUser < ActiveRecord::Base auto_track(user_id: user.id) end - def self.auto_track(opts={}) + def self.auto_track(opts = {}) builder = SqlBuilder.new < "#{name}CustomField" + has_many :_custom_fields, dependent: :destroy, class_name: "#{name}CustomField" after_save :save_custom_fields attr_accessor :preloaded_custom_fields @@ -58,7 +58,7 @@ module HasCustomFields return result if whitelisted_fields.blank? klass.where(foreign_key => ids, :name => whitelisted_fields) - .pluck(foreign_key, :name, :value).each do |cf| + .pluck(foreign_key, :name, :value).each do |cf| result[cf[0]] ||= {} append_custom_field(result[cf[0]], cf[1], cf[2]) end @@ -96,7 +96,7 @@ module HasCustomFields .where("name in (?)", fields) .pluck(fk, :name, :value).each do |id, name, value| - preloaded = map[id].preloaded_custom_fields + preloaded = map[id].preloaded_custom_fields if preloaded[name].nil? preloaded.delete(name) @@ -156,7 +156,7 @@ module HasCustomFields !@custom_fields || @custom_fields_orig == @custom_fields end - def save_custom_fields(force=false) + def save_custom_fields(force = false) if force || !custom_fields_clean? dup = @custom_fields.dup @@ -194,7 +194,7 @@ module HasCustomFields end end - dup.each do |k,v| + dup.each do |k, v| if v.is_a? Array v.each { |subv| _custom_fields.create(name: k, value: subv) } elsif v.is_a? Hash @@ -212,7 +212,7 @@ module HasCustomFields def refresh_custom_fields_from_db target = Hash.new - _custom_fields.pluck(:name,:value).each do |key, value| + _custom_fields.pluck(:name, :value).each do |key, value| self.class.append_custom_field(target, key, value) end @custom_fields_orig = target diff --git a/app/models/concerns/positionable.rb b/app/models/concerns/positionable.rb index 335b8ce0acb..68e71f1b145 100644 --- a/app/models/concerns/positionable.rb +++ b/app/models/concerns/positionable.rb @@ -11,18 +11,18 @@ module Positionable position = [[position_arg, 0].max, self.class.count - 1].min - if self.position.nil? or position > self.position + if self.position.nil? || position > (self.position) self.exec_sql " UPDATE #{self.class.table_name} SET position = position - 1 WHERE position > :current_position and position <= :new_position", - {current_position: self.position, new_position: position} + current_position: self.position, new_position: position elsif position < self.position self.exec_sql " UPDATE #{self.class.table_name} SET position = position + 1 WHERE position >= :new_position and position < :current_position", - {current_position: self.position, new_position: position} + current_position: self.position, new_position: position else # Not moving to a new position return @@ -31,6 +31,6 @@ module Positionable self.exec_sql " UPDATE #{self.class.table_name} SET position = :position - WHERE id = :id", {id: id, position: position} + WHERE id = :id", id: id, position: position end end diff --git a/app/models/concerns/trashable.rb b/app/models/concerns/trashable.rb index 9325f6849e1..b758df0027e 100644 --- a/app/models/concerns/trashable.rb +++ b/app/models/concerns/trashable.rb @@ -8,7 +8,6 @@ module Trashable belongs_to :deleted_by, class_name: 'User' end - module ClassMethods def with_deleted # lifted from acts_as_paranoid, works around https://github.com/rails/rails/issues/4306 @@ -30,7 +29,7 @@ module Trashable deleted_at.present? end - def trash!(trashed_by=nil) + def trash!(trashed_by = nil) # note, an argument could be made that the column should probably called trashed_at # however, deleted_at is the terminology used in the UI # @@ -44,7 +43,6 @@ module Trashable trash_update(nil, nil) end - private def trash_update(deleted_at, deleted_by_id) diff --git a/app/models/directory_item.rb b/app/models/directory_item.rb index 9bdcdf50acb..b877705d70b 100644 --- a/app/models/directory_item.rb +++ b/app/models/directory_item.rb @@ -22,7 +22,7 @@ class DirectoryItem < ActiveRecord::Base end def self.refresh! - period_types.each_key {|p| refresh_period!(p)} + period_types.each_key { |p| refresh_period!(p) } end def self.refresh_period!(period_type) @@ -30,14 +30,15 @@ class DirectoryItem < ActiveRecord::Base # Don't calculate it if the user directory is disabled return unless SiteSetting.enable_user_directory? - since = case period_type - when :daily then 1.day.ago - when :weekly then 1.week.ago - when :monthly then 1.month.ago - when :quarterly then 3.months.ago - when :yearly then 1.year.ago - else 1000.years.ago - end + since = + case period_type + when :daily then 1.day.ago + when :weekly then 1.week.ago + when :monthly then 1.month.ago + when :quarterly then 3.months.ago + when :yearly then 1.year.ago + else 1000.years.ago + end ActiveRecord::Base.transaction do exec_sql "DELETE FROM directory_items @@ -47,7 +48,6 @@ class DirectoryItem < ActiveRecord::Base u.id IS NULL AND di.period_type = :period_type", period_type: period_types[period_type] - exec_sql "INSERT INTO directory_items(period_type, user_id, likes_received, likes_given, topics_entered, days_visited, posts_read, topic_count, post_count) SELECT :period_type, @@ -117,7 +117,6 @@ class DirectoryItem < ActiveRecord::Base reply_type: UserAction::REPLY, regular_post_type: Post.types[:regular] - if period_type == :all exec_sql < 0 GroupUser - .where(user_id: user.id) - .where('group_id IN (SELECT id FROM groups WHERE name in (?))',split) - .destroy_all + .where(user_id: user.id) + .where('group_id IN (SELECT id FROM groups WHERE name in (?))', split) + .destroy_all end end end diff --git a/app/models/draft.rb b/app/models/draft.rb index 437ad298fe3..be412cc72a3 100644 --- a/app/models/draft.rb +++ b/app/models/draft.rb @@ -4,7 +4,7 @@ class Draft < ActiveRecord::Base EXISTING_TOPIC = 'topic_' def self.set(user, key, sequence, data) - d = find_draft(user,key) + d = find_draft(user, key) if d return if d.sequence > sequence exec_sql("UPDATE drafts @@ -18,14 +18,14 @@ class Draft < ActiveRecord::Base end def self.get(user, key, sequence) - d = find_draft(user,key) + d = find_draft(user, key) if d && d.sequence == sequence d.data end end def self.clear(user, key, sequence) - d = find_draft(user,key) + d = find_draft(user, key) if d && d.sequence <= sequence d.destroy end diff --git a/app/models/draft_sequence.rb b/app/models/draft_sequence.rb index af4eb647c93..2e8eeb98c82 100644 --- a/app/models/draft_sequence.rb +++ b/app/models/draft_sequence.rb @@ -1,5 +1,5 @@ class DraftSequence < ActiveRecord::Base - def self.next!(user,key) + def self.next!(user, key) user_id = user user_id = user.id unless user.is_a?(Integer) diff --git a/app/models/email_log.rb b/app/models/email_log.rb index d17ec8c3a69..3add7e1c355 100644 --- a/app/models/email_log.rb +++ b/app/models/email_log.rb @@ -39,21 +39,21 @@ class EmailLog < ActiveRecord::Base end end - def self.reached_max_emails?(user, email_type=nil) + def self.reached_max_emails?(user, email_type = nil) return false if SiteSetting.max_emails_per_day_per_user == 0 || CRITICAL_EMAIL_TYPES.include?(email_type) count = sent.where('created_at > ?', 1.day.ago) - .where(user_id: user.id) - .count + .where(user_id: user.id) + .count count >= SiteSetting.max_emails_per_day_per_user end def self.count_per_day(start_date, end_date) sent.where("created_at BETWEEN ? AND ?", start_date, end_date) - .group("DATE(created_at)") - .order("DATE(created_at)") - .count + .group("DATE(created_at)") + .order("DATE(created_at)") + .count end def self.for(reply_key) @@ -62,9 +62,9 @@ class EmailLog < ActiveRecord::Base def self.last_sent_email_address self.where(email_type: "signup") - .order(created_at: :desc) - .first - .try(:to_address) + .order(created_at: :desc) + .first + .try(:to_address) end end diff --git a/app/models/email_token.rb b/app/models/email_token.rb index cff339a08eb..2a10dd4e234 100644 --- a/app/models/email_token.rb +++ b/app/models/email_token.rb @@ -11,8 +11,8 @@ class EmailToken < ActiveRecord::Base after_create do # Expire the previous tokens EmailToken.where(user_id: self.user_id) - .where("id != ?", self.id) - .update_all(expired: true) + .where("id != ?", self.id) + .update_all(expired: true) end def self.token_length @@ -36,7 +36,7 @@ class EmailToken < ActiveRecord::Base end def self.valid_token_format?(token) - token.present? && token =~ /\h{#{token.length/2}}/i + token.present? && token =~ /\h{#{token.length / 2}}/i end def self.atomic_confirm(token) @@ -81,10 +81,10 @@ class EmailToken < ActiveRecord::Base def self.confirmable(token) EmailToken.where(token: token) - .where(expired: false, confirmed: false) - .where("created_at >= ?", EmailToken.valid_after) - .includes(:user) - .first + .where(expired: false, confirmed: false) + .where("created_at >= ?", EmailToken.valid_after) + .includes(:user) + .first end end diff --git a/app/models/embedding.rb b/app/models/embedding.rb index f11de96f4f3..a0be5ceea80 100644 --- a/app/models/embedding.rb +++ b/app/models/embedding.rb @@ -38,7 +38,7 @@ class Embedding < OpenStruct def self.find embedding_args = { id: 'default' } - Embedding.settings.each {|s| embedding_args[s] = SiteSetting.send(s) } + Embedding.settings.each { |s| embedding_args[s] = SiteSetting.send(s) } Embedding.new(embedding_args) end end diff --git a/app/models/emoji.rb b/app/models/emoji.rb index 513ad8478ff..c6f2e490cfc 100644 --- a/app/models/emoji.rb +++ b/app/models/emoji.rb @@ -78,7 +78,7 @@ class Emoji end def self.load_standard - db['emojis'].map {|e| Emoji.create_from_db_item(e) } + db['emojis'].map { |e| Emoji.create_from_db_item(e) } end def self.load_custom @@ -135,7 +135,7 @@ class Emoji if is_tonable_emojis.include?(name) fitzpatrick_scales.each_with_index do |scale, index| toned_code = code.codepoints.insert(1, scale).pack("U*".freeze) - @unicode_replacements[toned_code] = "#{name}:t#{index+2}" + @unicode_replacements[toned_code] = "#{name}:t#{index + 2}" end end end @@ -180,7 +180,7 @@ class Emoji if is_tonable_emojis.include?(e['name']) FITZPATRICK_SCALE.each_with_index do |scale, index| toned_code = (code.codepoints.insert(1, scale.to_i(16))).pack("U*") - map["#{e['name']}:t#{index+2}"] = toned_code + map["#{e['name']}:t#{index + 2}"] = toned_code end end end diff --git a/app/models/given_daily_like.rb b/app/models/given_daily_like.rb index 87da4194537..ccc29742377 100644 --- a/app/models/given_daily_like.rb +++ b/app/models/given_daily_like.rb @@ -16,8 +16,8 @@ class GivenDailyLike < ActiveRecord::Base create(user_id: user_id, given_date: given_date, likes_given: 1) else find_for(user_id, given_date) - .where('limit_reached = false AND likes_given >= :limit', limit: SiteSetting.max_likes_per_day) - .update_all(limit_reached: true) + .where('limit_reached = false AND likes_given >= :limit', limit: SiteSetting.max_likes_per_day) + .update_all(limit_reached: true) end end @@ -28,8 +28,8 @@ class GivenDailyLike < ActiveRecord::Base find_for(user_id, given_date).update_all('likes_given = likes_given - 1') find_for(user_id, given_date) - .where('limit_reached = true AND likes_given < :limit', limit: SiteSetting.max_likes_per_day) - .update_all(limit_reached: false) + .where('limit_reached = true AND likes_given < :limit', limit: SiteSetting.max_likes_per_day) + .update_all(limit_reached: false) end end diff --git a/app/models/global_setting.rb b/app/models/global_setting.rb index 2ee90b7bc1f..84750ecc695 100644 --- a/app/models/global_setting.rb +++ b/app/models/global_setting.rb @@ -40,7 +40,7 @@ class GlobalSetting token = $redis.without_namespace.get(REDIS_SECRET_KEY) unless token && token =~ VALID_SECRET_KEY token = SecureRandom.hex(64) - $redis.without_namespace.set(REDIS_SECRET_KEY,token) + $redis.without_namespace.set(REDIS_SECRET_KEY, token) end end if !secret_key_base.blank? && token != secret_key_base @@ -74,7 +74,7 @@ class GlobalSetting end def self.database_config - hash = {"adapter" => "postgresql"} + hash = { "adapter" => "postgresql" } %w{pool timeout socket host port username password replica_host replica_port}.each do |s| if val = self.send("db_#{s}") hash[s] = val @@ -91,7 +91,7 @@ class GlobalSetting hash["prepared_statements"] = !!self.db_prepared_statements - {"production" => hash} + { "production" => hash } end # For testing purposes @@ -118,8 +118,8 @@ class GlobalSetting if redis_sentinels.present? c[:sentinels] = redis_sentinels.split(",").map do |address| - host,port = address.split(":") - {host: host, port: port} + host, port = address.split(":") + { host: host, port: port } end.to_a end @@ -134,7 +134,6 @@ class GlobalSetting setting end - def resolve(current, default) BaseProvider.coerce( if current.present? @@ -167,8 +166,7 @@ class GlobalSetting end end - - def lookup(key,default) + def lookup(key, default) var = @data[key] resolve(var, var.nil? ? default : "") end @@ -193,7 +191,7 @@ class GlobalSetting end def keys - ENV.keys.select{|k| k =~ /^DISCOURSE_/}.map{|k| k[10..-1].downcase.to_sym} + ENV.keys.select { |k| k =~ /^DISCOURSE_/ }.map { |k| k[10..-1].downcase.to_sym } end end @@ -207,7 +205,6 @@ class GlobalSetting end end - class << self attr_accessor :provider end diff --git a/app/models/group.rb b/app/models/group.rb index 517247beb6d..f7f37ab4105 100644 --- a/app/models/group.rb +++ b/app/models/group.rb @@ -41,29 +41,29 @@ class Group < ActiveRecord::Base validate :automatic_membership_email_domains_format_validator validate :incoming_email_validator validate :can_allow_membership_requests, if: :allow_membership_requests - validates :flair_url, url: true, if: Proc.new { |g| g.flair_url && g.flair_url[0,3] != 'fa-' } + validates :flair_url, url: true, if: Proc.new { |g| g.flair_url && g.flair_url[0, 3] != 'fa-' } AUTO_GROUPS = { - :everyone => 0, - :admins => 1, - :moderators => 2, - :staff => 3, - :trust_level_0 => 10, - :trust_level_1 => 11, - :trust_level_2 => 12, - :trust_level_3 => 13, - :trust_level_4 => 14 + everyone: 0, + admins: 1, + moderators: 2, + staff: 3, + trust_level_0: 10, + trust_level_1: 11, + trust_level_2: 12, + trust_level_3: 13, + trust_level_4: 14 } AUTO_GROUP_IDS = Hash[*AUTO_GROUPS.to_a.flatten.reverse] STAFF_GROUPS = [:admins, :moderators, :staff] ALIAS_LEVELS = { - :nobody => 0, - :only_admins => 1, - :mods_and_admins => 2, - :members_mods_and_admins => 3, - :everyone => 99 + nobody: 0, + only_admins: 1, + mods_and_admins: 2, + members_mods_and_admins: 3, + everyone: 99 } def self.visibility_levels @@ -75,13 +75,13 @@ class Group < ActiveRecord::Base ) end - validates :alias_level, inclusion: { in: ALIAS_LEVELS.values} + validates :alias_level, inclusion: { in: ALIAS_LEVELS.values } scope :visible_groups, ->(user) { groups = Group.order(name: :asc).where("groups.id > 0") unless user&.admin - sql = <<~SQL + sql = <<~SQL groups.id IN ( SELECT g.id FROM groups g WHERE g.visibility_level = :public @@ -121,7 +121,7 @@ class Group < ActiveRecord::Base groups } - scope :mentionable, lambda {|user| + scope :mentionable, lambda { |user| levels = [ALIAS_LEVELS[:everyone]] @@ -140,7 +140,7 @@ class Group < ActiveRecord::Base ( alias_level = #{ALIAS_LEVELS[:members_mods_and_admins]} AND id in ( SELECT group_id FROM group_users WHERE user_id = :user_id) - )", levels: levels, user_id: user && user.id ) + )", levels: levels, user_id: user && user.id) } def downcase_incoming_email @@ -168,38 +168,38 @@ class Group < ActiveRecord::Base end end - def posts_for(guardian, before_post_id=nil) + def posts_for(guardian, before_post_id = nil) user_ids = group_users.map { |gu| gu.user_id } result = Post.includes(:user, :topic, topic: :category) - .references(:posts, :topics, :category) - .where(user_id: user_ids) - .where('topics.archetype <> ?', Archetype.private_message) - .where(post_type: Post.types[:regular]) + .references(:posts, :topics, :category) + .where(user_id: user_ids) + .where('topics.archetype <> ?', Archetype.private_message) + .where(post_type: Post.types[:regular]) result = guardian.filter_allowed_categories(result) result = result.where('posts.id < ?', before_post_id) if before_post_id result.order('posts.created_at desc') end - def messages_for(guardian, before_post_id=nil) + def messages_for(guardian, before_post_id = nil) result = Post.includes(:user, :topic, topic: :category) - .references(:posts, :topics, :category) - .where('topics.archetype = ?', Archetype.private_message) - .where(post_type: Post.types[:regular]) - .where('topics.id IN (SELECT topic_id FROM topic_allowed_groups WHERE group_id = ?)', self.id) + .references(:posts, :topics, :category) + .where('topics.archetype = ?', Archetype.private_message) + .where(post_type: Post.types[:regular]) + .where('topics.id IN (SELECT topic_id FROM topic_allowed_groups WHERE group_id = ?)', self.id) result = guardian.filter_allowed_categories(result) result = result.where('posts.id < ?', before_post_id) if before_post_id result.order('posts.created_at desc') end - def mentioned_posts_for(guardian, before_post_id=nil) + def mentioned_posts_for(guardian, before_post_id = nil) result = Post.joins(:group_mentions) - .includes(:user, :topic, topic: :category) - .references(:posts, :topics, :category) - .where('topics.archetype <> ?', Archetype.private_message) - .where(post_type: Post.types[:regular]) - .where('group_mentions.group_id = ?', self.id) + .includes(:user, :topic, topic: :category) + .references(:posts, :topics, :category) + .where('topics.archetype <> ?', Archetype.private_message) + .where(post_type: Post.types[:regular]) + .where('group_mentions.group_id = ?', self.id) result = guardian.filter_allowed_categories(result) result = result.where('posts.id < ?', before_post_id) if before_post_id @@ -237,16 +237,17 @@ class Group < ActiveRecord::Base end # Remove people from groups they don't belong in. - remove_subquery = case name - when :admins - "SELECT id FROM users WHERE NOT admin" - when :moderators - "SELECT id FROM users WHERE NOT moderator" - when :staff - "SELECT id FROM users WHERE NOT admin AND NOT moderator" - when :trust_level_0, :trust_level_1, :trust_level_2, :trust_level_3, :trust_level_4 - "SELECT id FROM users WHERE trust_level < #{id - 10}" - end + remove_subquery = + case name + when :admins + "SELECT id FROM users WHERE NOT admin" + when :moderators + "SELECT id FROM users WHERE NOT moderator" + when :staff + "SELECT id FROM users WHERE NOT admin AND NOT moderator" + when :trust_level_0, :trust_level_1, :trust_level_2, :trust_level_3, :trust_level_4 + "SELECT id FROM users WHERE trust_level < #{id - 10}" + end exec_sql <<-SQL DELETE FROM group_users @@ -256,18 +257,19 @@ class Group < ActiveRecord::Base SQL # Add people to groups - insert_subquery = case name - when :admins - "SELECT id FROM users WHERE admin" - when :moderators - "SELECT id FROM users WHERE moderator" - when :staff - "SELECT id FROM users WHERE moderator OR admin" - when :trust_level_1, :trust_level_2, :trust_level_3, :trust_level_4 - "SELECT id FROM users WHERE trust_level >= #{id - 10}" - when :trust_level_0 - "SELECT id FROM users" - end + insert_subquery = + case name + when :admins + "SELECT id FROM users WHERE admin" + when :moderators + "SELECT id FROM users WHERE moderator" + when :staff + "SELECT id FROM users WHERE moderator OR admin" + when :trust_level_1, :trust_level_2, :trust_level_3, :trust_level_4 + "SELECT id FROM users WHERE trust_level >= #{id - 10}" + when :trust_level_0 + "SELECT id FROM users" + end exec_sql <<-SQL INSERT INTO group_users (group_id, user_id, created_at, updated_at) @@ -388,11 +390,11 @@ class Group < ActiveRecord::Base additions = expected - current deletions = current - expected - map = Hash[*User.where(username: additions+deletions) - .select('id,username') - .map{|u| [u.username,u.id]}.flatten] + map = Hash[*User.where(username: additions + deletions) + .select('id,username') + .map { |u| [u.username, u.id] }.flatten] - deletions = Set.new(deletions.map{|d| map[d]}) + deletions = Set.new(deletions.map { |d| map[d] }) @deletions = [] group_users.each do |gu| diff --git a/app/models/group_archived_message.rb b/app/models/group_archived_message.rb index 190dce298c7..91d2062cae5 100644 --- a/app/models/group_archived_message.rb +++ b/app/models/group_archived_message.rb @@ -5,22 +5,21 @@ class GroupArchivedMessage < ActiveRecord::Base def self.move_to_inbox!(group_id, topic_id) GroupArchivedMessage.where(group_id: group_id, topic_id: topic_id).destroy_all trigger(:move_to_inbox, group_id, topic_id) - MessageBus.publish("/topic/#{topic_id}", {type: "move_to_inbox"}, group_ids: [group_id]) + MessageBus.publish("/topic/#{topic_id}", { type: "move_to_inbox" }, group_ids: [group_id]) end def self.archive!(group_id, topic_id) GroupArchivedMessage.where(group_id: group_id, topic_id: topic_id).destroy_all GroupArchivedMessage.create!(group_id: group_id, topic_id: topic_id) trigger(:archive_message, group_id, topic_id) - MessageBus.publish("/topic/#{topic_id}", {type: "archived"}, group_ids: [group_id]) + MessageBus.publish("/topic/#{topic_id}", { type: "archived" }, group_ids: [group_id]) end - def self.trigger(event, group_id, topic_id) group = Group.find_by(id: group_id) topic = Topic.find_by(id: topic_id) if group && topic - DiscourseEvent.trigger(event, {group: group, topic: topic}) + DiscourseEvent.trigger(event, group: group, topic: topic) end end diff --git a/app/models/group_user.rb b/app/models/group_user.rb index b5595803901..3c40b079285 100644 --- a/app/models/group_user.rb +++ b/app/models/group_user.rb @@ -25,36 +25,41 @@ class GroupUser < ActiveRecord::Base def set_primary_group if group.primary_group - self.class.exec_sql("UPDATE users - SET primary_group_id = :id - WHERE id = :user_id", - id: group.id, user_id: user_id) + self.class.exec_sql(" + UPDATE users + SET primary_group_id = :id + WHERE id = :user_id", + id: group.id, user_id: user_id + ) end end def remove_primary_group - self.class.exec_sql("UPDATE users - SET primary_group_id = NULL - WHERE id = :user_id AND primary_group_id = :id", - id: group.id, user_id: user_id) - + self.class.exec_sql(" + UPDATE users + SET primary_group_id = NULL + WHERE id = :user_id AND primary_group_id = :id", + id: group.id, user_id: user_id + ) end def remove_title if group.title.present? - self.class.exec_sql("UPDATE users SET title = NULL - WHERE title = :title AND id = :id", - id: user_id, - title: group.title) + self.class.exec_sql(" + UPDATE users SET title = NULL + WHERE title = :title AND id = :id", + id: user_id, title: group.title + ) end end def update_title if group.title.present? - self.class.exec_sql("UPDATE users SET title = :title - WHERE (title IS NULL OR title = '') AND id = :id", - id: user_id, - title: group.title) + self.class.exec_sql(" + UPDATE users SET title = :title + WHERE (title IS NULL OR title = '') AND id = :id", + id: user_id, title: group.title + ) end end diff --git a/app/models/incoming_link.rb b/app/models/incoming_link.rb index fd3e9e8e8d9..e7992e2c729 100644 --- a/app/models/incoming_link.rb +++ b/app/models/incoming_link.rb @@ -35,11 +35,10 @@ class IncomingLink < ActiveRecord::Base post_id = opts[:post_id] post_id ||= Post.where(topic_id: opts[:topic_id], post_number: opts[:post_number] || 1) - .pluck(:id).first + .pluck(:id).first cid = current_user ? (current_user.id) : (nil) - unless cid && cid == user_id create(referer: referer, @@ -53,7 +52,6 @@ class IncomingLink < ActiveRecord::Base end - def referer=(referer) self.incoming_referer_id = nil @@ -87,7 +85,6 @@ class IncomingLink < ActiveRecord::Base end end - # Internal: Update appropriate link counts. def update_link_counts exec_sql("UPDATE topics diff --git a/app/models/incoming_links_report.rb b/app/models/incoming_links_report.rb index 388ea57cc9c..cf28011b8d4 100644 --- a/app/models/incoming_links_report.rb +++ b/app/models/incoming_links_report.rb @@ -30,24 +30,24 @@ class IncomingLinksReport # Return top 10 users who brought traffic to the site within the last 30 days def self.report_top_referrers(report) - report.y_titles[:num_clicks] = I18n.t("reports.#{report.type}.num_clicks") + report.y_titles[:num_clicks] = I18n.t("reports.#{report.type}.num_clicks") report.y_titles[:num_topics] = I18n.t("reports.#{report.type}.num_topics") - num_clicks = link_count_per_user + num_clicks = link_count_per_user num_topics = topic_count_per_user - user_id_lookup = User.where(username: num_clicks.keys).select(:id, :username).inject({}) {|sum,v| sum[v.username] = v.id; sum;} + user_id_lookup = User.where(username: num_clicks.keys).select(:id, :username).inject({}) { |sum, v| sum[v.username] = v.id; sum; } report.data = [] num_clicks.each_key do |username| - report.data << {username: username, user_id: user_id_lookup[username], num_clicks: num_clicks[username], num_topics: num_topics[username]} + report.data << { username: username, user_id: user_id_lookup[username], num_clicks: num_clicks[username], num_topics: num_topics[username] } end - report.data = report.data.sort_by {|x| x[:num_clicks]}.reverse[0,10] + report.data = report.data.sort_by { |x| x[:num_clicks] }.reverse[0, 10] end def self.per_user @per_user_query ||= IncomingLink - .where('incoming_links.created_at > ? AND incoming_links.user_id IS NOT NULL', 30.days.ago) - .joins(:user) - .group('users.username') + .where('incoming_links.created_at > ? AND incoming_links.user_id IS NOT NULL', 30.days.ago) + .joins(:user) + .group('users.username') end def self.link_count_per_user @@ -58,35 +58,34 @@ class IncomingLinksReport per_user.joins(:post).count("DISTINCT posts.topic_id") end - # Return top 10 domains that brought traffic to the site within the last 30 days def self.report_top_traffic_sources(report) - report.y_titles[:num_clicks] = I18n.t("reports.#{report.type}.num_clicks") + report.y_titles[:num_clicks] = I18n.t("reports.#{report.type}.num_clicks") report.y_titles[:num_topics] = I18n.t("reports.#{report.type}.num_topics") report.y_titles[:num_users] = I18n.t("reports.#{report.type}.num_users") - num_clicks = link_count_per_domain + num_clicks = link_count_per_domain num_topics = topic_count_per_domain(num_clicks.keys) report.data = [] num_clicks.each_key do |domain| - report.data << {domain: domain, num_clicks: num_clicks[domain], num_topics: num_topics[domain]} + report.data << { domain: domain, num_clicks: num_clicks[domain], num_topics: num_topics[domain] } end - report.data = report.data.sort_by {|x| x[:num_clicks]}.reverse[0,10] + report.data = report.data.sort_by { |x| x[:num_clicks] }.reverse[0, 10] end - def self.link_count_per_domain(limit=10) + def self.link_count_per_domain(limit = 10) IncomingLink.where('incoming_links.created_at > ?', 30.days.ago) - .joins(:incoming_referer => :incoming_domain) - .group('incoming_domains.name') - .order('count_all DESC') - .limit(limit).count + .joins(incoming_referer: :incoming_domain) + .group('incoming_domains.name') + .order('count_all DESC') + .limit(limit).count end def self.per_domain(domains) IncomingLink - .joins(:incoming_referer => :incoming_domain) - .where('incoming_links.created_at > ? AND incoming_domains.name IN (?)', 30.days.ago, domains) - .group('incoming_domains.name') + .joins(incoming_referer: :incoming_domain) + .where('incoming_links.created_at > ? AND incoming_domains.name IN (?)', 30.days.ago, domains) + .group('incoming_domains.name') end def self.topic_count_per_domain(domains) @@ -94,17 +93,16 @@ class IncomingLinksReport per_domain(domains).joins(:post).count("DISTINCT posts.topic_id") end - def self.report_top_referred_topics(report) - report.y_titles[:num_clicks] = I18n.t("reports.#{report.type}.num_clicks") - num_clicks = link_count_per_topic - num_clicks = num_clicks.to_a.sort_by {|x| x[1]}.last(10).reverse # take the top 10 + report.y_titles[:num_clicks] = I18n.t("reports.#{report.type}.num_clicks") + num_clicks = link_count_per_topic + num_clicks = num_clicks.to_a.sort_by { |x| x[1] }.last(10).reverse # take the top 10 report.data = [] - topics = Topic.select('id, slug, title').where('id in (?)', num_clicks.map {|z| z[0]}) + topics = Topic.select('id, slug, title').where('id in (?)', num_clicks.map { |z| z[0] }) num_clicks.each do |topic_id, num_clicks_element| - topic = topics.find {|t| t.id == topic_id} + topic = topics.find { |t| t.id == topic_id } if topic - report.data << {topic_id: topic_id, topic_title: topic.title, topic_slug: topic.slug, num_clicks: num_clicks_element} + report.data << { topic_id: topic_id, topic_title: topic.title, topic_slug: topic.slug, num_clicks: num_clicks_element } end end report.data @@ -112,8 +110,8 @@ class IncomingLinksReport def self.link_count_per_topic IncomingLink.joins(:post) - .where('incoming_links.created_at > ? AND topic_id IS NOT NULL', 30.days.ago) - .group('topic_id') - .count + .where('incoming_links.created_at > ? AND topic_id IS NOT NULL', 30.days.ago) + .group('topic_id') + .count end end diff --git a/app/models/invite.rb b/app/models/invite.rb index 01b6e970f1d..1955654c2dd 100644 --- a/app/models/invite.rb +++ b/app/models/invite.rb @@ -70,29 +70,30 @@ class Invite < ActiveRecord::Base end end - def self.invite_by_email(email, invited_by, topic=nil, group_ids=nil, custom_message=nil) - create_invite_by_email(email, invited_by, { + def self.invite_by_email(email, invited_by, topic = nil, group_ids = nil, custom_message = nil) + create_invite_by_email(email, invited_by, topic: topic, group_ids: group_ids, custom_message: custom_message, send_email: true - }) + ) end # generate invite link - def self.generate_invite_link(email, invited_by, topic=nil, group_ids=nil) - invite = create_invite_by_email(email, invited_by, { + def self.generate_invite_link(email, invited_by, topic = nil, group_ids = nil) + invite = create_invite_by_email(email, invited_by, topic: topic, group_ids: group_ids, send_email: false - }) - return "#{Discourse.base_url}/invites/#{invite.invite_key}" if invite + ) + + "#{Discourse.base_url}/invites/#{invite.invite_key}" if invite end # Create an invite for a user, supplying an optional topic # # Return the previously existing invite if already exists. Returns nil if the invite can't be created. - def self.create_invite_by_email(email, invited_by, opts=nil) + def self.create_invite_by_email(email, invited_by, opts = nil) opts ||= {} topic = opts[:topic] @@ -107,9 +108,9 @@ class Invite < ActiveRecord::Base end invite = Invite.with_deleted - .where(email: lower_email, invited_by_id: invited_by.id) - .order('created_at DESC') - .first + .where(email: lower_email, invited_by_id: invited_by.id) + .order('created_at DESC') + .first if invite && (invite.expired? || invite.deleted_at) invite.destroy @@ -161,23 +162,23 @@ class Invite < ActiveRecord::Base group_ids end - def self.find_all_invites_from(inviter, offset=0, limit=SiteSetting.invites_per_page) + def self.find_all_invites_from(inviter, offset = 0, limit = SiteSetting.invites_per_page) Invite.where(invited_by_id: inviter.id) - .where('invites.email IS NOT NULL') - .includes(:user => :user_stat) - .order('CASE WHEN invites.user_id IS NOT NULL THEN 0 ELSE 1 END', + .where('invites.email IS NOT NULL') + .includes(user: :user_stat) + .order('CASE WHEN invites.user_id IS NOT NULL THEN 0 ELSE 1 END', 'user_stats.time_read DESC', 'invites.redeemed_at DESC') - .limit(limit) - .offset(offset) - .references('user_stats') + .limit(limit) + .offset(offset) + .references('user_stats') end - def self.find_pending_invites_from(inviter, offset=0) + def self.find_pending_invites_from(inviter, offset = 0) find_all_invites_from(inviter, offset).where('invites.user_id IS NULL').order('invites.created_at DESC') end - def self.find_redeemed_invites_from(inviter, offset=0) + def self.find_redeemed_invites_from(inviter, offset = 0) find_all_invites_from(inviter, offset).where('invites.user_id IS NOT NULL').order('invites.redeemed_at DESC') end diff --git a/app/models/invite_redeemer.rb b/app/models/invite_redeemer.rb index 5de389af3b7..9b68b8b03ad 100644 --- a/app/models/invite_redeemer.rb +++ b/app/models/invite_redeemer.rb @@ -18,7 +18,7 @@ InviteRedeemer = Struct.new(:invite, :username, :name, :password, :user_custom_f end # extracted from User cause it is very specific to invites - def self.create_user_from_invite(invite, username, name, password=nil, user_custom_fields=nil) + def self.create_user_from_invite(invite, username, name, password = nil, user_custom_fields = nil) if username && UsernameValidator.new(username).valid_format? && User.username_available?(username) available_username = username else @@ -94,7 +94,6 @@ InviteRedeemer = Struct.new(:invite, :username, :name, :password, :user_custom_f User.where(admin: false).find_by_email(invite.email) end - def add_to_private_topics_if_invited invite.topics.private_messages.each do |t| t.topic_allowed_users.create(user_id: invited_user.id) @@ -102,7 +101,7 @@ InviteRedeemer = Struct.new(:invite, :username, :name, :password, :user_custom_f end def add_user_to_invited_topics - Invite.where('invites.email = ? and invites.id != ?', invite.email, invite.id).includes(:topics).where(topics: {archetype: Archetype::private_message}).each do |i| + Invite.where('invites.email = ? and invites.id != ?', invite.email, invite.id).includes(:topics).where(topics: { archetype: Archetype::private_message }).each do |i| i.topics.each do |t| t.topic_allowed_users.create(user_id: invited_user.id) end @@ -130,8 +129,8 @@ InviteRedeemer = Struct.new(:invite, :username, :name, :password, :user_custom_f def notify_invitee if inviter = invite.invited_by - inviter.notifications.create(notification_type: Notification.types[:invitee_accepted], - data: {display_username: invited_user.username}.to_json) + inviter.notifications.create(notification_type: Notification.types[:invitee_accepted], + data: { display_username: invited_user.username }.to_json) end end diff --git a/app/models/locale_site_setting.rb b/app/models/locale_site_setting.rb index 1cd9246418e..607a8e7cddd 100644 --- a/app/models/locale_site_setting.rb +++ b/app/models/locale_site_setting.rb @@ -9,7 +9,7 @@ class LocaleSiteSetting < EnumSiteSetting def self.values supported_locales.map do |l| lang = language_names[l] || language_names[l[0..1]] - {name: lang ? lang['nativeName'] : l, value: l} + { name: lang ? lang['nativeName'] : l, value: l } end end @@ -25,7 +25,7 @@ class LocaleSiteSetting < EnumSiteSetting def self.supported_locales @lock.synchronize do - @supported_locales ||= Dir.glob( File.join(Rails.root, 'config', 'locales', 'client.*.yml') ).map {|x| x.split('.')[-2]}.sort + @supported_locales ||= Dir.glob(File.join(Rails.root, 'config', 'locales', 'client.*.yml')).map { |x| x.split('.')[-2] }.sort end end diff --git a/app/models/notification.rb b/app/models/notification.rb index 7db7a5b8bd3..e238bd1f6ea 100644 --- a/app/models/notification.rb +++ b/app/models/notification.rb @@ -8,9 +8,9 @@ class Notification < ActiveRecord::Base validates_presence_of :notification_type scope :unread, lambda { where(read: false) } - scope :recent, lambda { |n=nil| n ||= 10; order('notifications.created_at desc').limit(n) } + scope :recent, lambda { |n = nil| n ||= 10; order('notifications.created_at desc').limit(n) } scope :visible , lambda { joins('LEFT JOIN topics ON notifications.topic_id = topics.id') - .where('topics.id IS NULL OR topics.deleted_at IS NULL') } + .where('topics.id IS NULL OR topics.deleted_at IS NULL') } attr_accessor :skip_send_email @@ -76,20 +76,20 @@ class Notification < ActiveRecord::Base def self.read(user, notification_ids) count = Notification.where(user_id: user.id) - .where(id: notification_ids) - .where(read: false) - .update_all(read: true) + .where(id: notification_ids) + .where(read: false) + .update_all(read: true) user.publish_notifications_state if count > 0 end def self.interesting_after(min_date) - result = where("created_at > ?", min_date) - .includes(:topic) - .visible - .unread - .limit(20) - .order("CASE WHEN notification_type = #{Notification.types[:replied]} THEN 1 + result = where("created_at > ?", min_date) + .includes(:topic) + .visible + .unread + .limit(20) + .order("CASE WHEN notification_type = #{Notification.types[:replied]} THEN 1 WHEN notification_type = #{Notification.types[:mentioned]} THEN 2 ELSE 3 END, created_at DESC").to_a @@ -107,7 +107,7 @@ class Notification < ActiveRecord::Base seen[r.notification_type] << r.topic_id end end - result.reject! {|r| to_remove.include?(r.id) } + result.reject! { |r| to_remove.include?(r.id) } end result @@ -145,9 +145,9 @@ class Notification < ActiveRecord::Base count ||= 10 notifications = user.notifications - .visible - .recent(count) - .includes(:topic) + .visible + .recent(count) + .includes(:topic) if user.user_option.like_notification_frequency == UserOption.like_notification_frequency_type[:never] notifications = notifications.where('notification_type <> ?', Notification.types[:liked]) @@ -165,7 +165,7 @@ class Notification < ActiveRecord::Base NOT read ORDER BY n.id ASC LIMIT #{count.to_i} - ").values.map do |x,_| + ").values.map do |x, _| x.to_i end @@ -178,7 +178,7 @@ class Notification < ActiveRecord::Base .limit(count) end - notifications.uniq(&:id).sort do |x,y| + notifications.uniq(&:id).sort do |x, y| if x.unread_pm? && !y.unread_pm? -1 elsif y.unread_pm? && !x.unread_pm? diff --git a/app/models/optimized_image.rb b/app/models/optimized_image.rb index e665a8f89d3..c290f93aca5 100644 --- a/app/models/optimized_image.rb +++ b/app/models/optimized_image.rb @@ -9,7 +9,7 @@ class OptimizedImage < ActiveRecord::Base # BUMP UP if optimized image algorithm changes VERSION = 1 - def self.create_for(upload, width, height, opts={}) + def self.create_for(upload, width, height, opts = {}) return unless width > 0 && height > 0 return if upload.try(:sha1).blank? @@ -90,7 +90,7 @@ class OptimizedImage < ActiveRecord::Base end def local? - !(url =~ /^(https?:)?\/\//) + !(url =~ /^(https?:)?\/\//) end def self.safe_path?(path) @@ -111,7 +111,7 @@ class OptimizedImage < ActiveRecord::Base SiteSetting.strip_image_metadata ? "thumbnail" : "resize" end - def self.resize_instructions(from, to, dimensions, opts={}) + def self.resize_instructions(from, to, dimensions, opts = {}) ensure_safe_paths!(from, to) # NOTE: ORDER is important! @@ -132,7 +132,7 @@ class OptimizedImage < ActiveRecord::Base } end - def self.resize_instructions_animated(from, to, dimensions, opts={}) + def self.resize_instructions_animated(from, to, dimensions, opts = {}) ensure_safe_paths!(from, to) %W{ @@ -145,7 +145,7 @@ class OptimizedImage < ActiveRecord::Base } end - def self.crop_instructions(from, to, dimensions, opts={}) + def self.crop_instructions(from, to, dimensions, opts = {}) ensure_safe_paths!(from, to) %W{ @@ -164,7 +164,7 @@ class OptimizedImage < ActiveRecord::Base } end - def self.crop_instructions_animated(from, to, dimensions, opts={}) + def self.crop_instructions_animated(from, to, dimensions, opts = {}) ensure_safe_paths!(from, to) %W{ @@ -177,7 +177,7 @@ class OptimizedImage < ActiveRecord::Base } end - def self.downsize_instructions(from, to, dimensions, opts={}) + def self.downsize_instructions(from, to, dimensions, opts = {}) ensure_safe_paths!(from, to) %W{ @@ -193,24 +193,24 @@ class OptimizedImage < ActiveRecord::Base } end - def self.downsize_instructions_animated(from, to, dimensions, opts={}) + def self.downsize_instructions_animated(from, to, dimensions, opts = {}) resize_instructions_animated(from, to, dimensions, opts) end - def self.resize(from, to, width, height, opts={}) + def self.resize(from, to, width, height, opts = {}) optimize("resize", from, to, "#{width}x#{height}", opts) end - def self.crop(from, to, width, height, opts={}) + def self.crop(from, to, width, height, opts = {}) opts[:width] = width optimize("crop", from, to, "#{width}x#{height}", opts) end - def self.downsize(from, to, dimensions, opts={}) + def self.downsize(from, to, dimensions, opts = {}) optimize("downsize", from, to, dimensions, opts) end - def self.optimize(operation, from, to, dimensions, opts={}) + def self.optimize(operation, from, to, dimensions, opts = {}) method_name = "#{operation}_instructions" if !!opts[:allow_animation] && (from =~ /\.GIF$/i || opts[:filename] =~ /\.GIF$/i) method_name += "_animated" @@ -233,7 +233,7 @@ class OptimizedImage < ActiveRecord::Base false end - def self.migrate_to_new_scheme(limit=nil) + def self.migrate_to_new_scheme(limit = nil) problems = [] if SiteSetting.migrate_to_new_scheme diff --git a/app/models/permalink.rb b/app/models/permalink.rb index e7427d20bad..4bfaa5a9cd5 100644 --- a/app/models/permalink.rb +++ b/app/models/permalink.rb @@ -44,8 +44,8 @@ class Permalink < ActiveRecord::Base def normalize(url) return url unless @rules - @rules.each do |(regex,sub)| - url = url.sub(regex,sub) + @rules.each do |(regex, sub)| + url = url.sub(regex, sub) end url @@ -56,10 +56,10 @@ class Permalink < ActiveRecord::Base def self.normalize_url(url) if url url = url.strip - url = url[1..-1] if url[0,1] == '/' + url = url[1..-1] if url[0, 1] == '/' end - normalizations = SiteSetting.permalink_normalizations + normalizations = SiteSetting.permalink_normalizations @normalizer = Normalizer.new(normalizations) unless @normalizer && @normalizer.source == normalizations @normalizer.normalize(url) @@ -81,10 +81,10 @@ class Permalink < ActiveRecord::Base nil end - def self.filter_by(url=nil) + def self.filter_by(url = nil) permalinks = Permalink - .includes(:topic, :post, :category) - .order('permalinks.created_at desc') + .includes(:topic, :post, :category) + .order('permalinks.created_at desc') permalinks.where!('url ILIKE :url OR external_url ILIKE :url', url: "%#{url}%") if url.present? permalinks.limit!(100) diff --git a/app/models/plugin_store.rb b/app/models/plugin_store.rb index 5a7675344ec..aebf7f3217e 100644 --- a/app/models/plugin_store.rb +++ b/app/models/plugin_store.rb @@ -7,7 +7,7 @@ class PluginStore end def self.set(plugin_name, key, value) - hash = {plugin_name: plugin_name, key: key} + hash = { plugin_name: plugin_name, key: key } row = PluginStoreRow.find_by(hash) || PluginStoreRow.new(hash) row.type_name = determine_type(value) @@ -34,7 +34,7 @@ class PluginStore if item.is_a? Hash ActiveSupport::HashWithIndifferentAccess.new item elsif item.is_a? Array - item.map { |subitem| map_json subitem} + item.map { |subitem| map_json subitem } else item end diff --git a/app/models/post.rb b/app/models/post.rb index ad2b98e2f45..a4df5df7787 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -79,7 +79,7 @@ class Post < ActiveRecord::Base scope :private_posts, -> { joins(:topic).where('topics.archetype = ?', Archetype.private_message) } scope :with_topic_subtype, ->(subtype) { joins(:topic).where('topics.subtype = ?', subtype) } scope :visible, -> { joins(:topic).where('topics.visible = true').where(hidden: false) } - scope :secured, lambda { |guardian| where('posts.post_type in (?)', Topic.visible_post_types(guardian && guardian.user))} + scope :secured, lambda { |guardian| where('posts.post_type in (?)', Topic.visible_post_types(guardian && guardian.user)) } scope :for_mailing_list, ->(user, since) { q = created_since(since) .joins(:topic) @@ -154,7 +154,7 @@ class Post < ActiveRecord::Base end end - def trash!(trashed_by=nil) + def trash!(trashed_by = nil) self.topic_links.each(&:destroy) super(trashed_by) end @@ -182,7 +182,7 @@ class Post < ActiveRecord::Base def matches_recent_post? post_id = $redis.get(unique_post_key) - post_id != nil and post_id.to_i != id + post_id != (nil) && post_id.to_i != (id) end def raw_hash @@ -218,24 +218,24 @@ class Post < ActiveRecord::Base # case we can skip the rendering pipeline. return raw if cook_method == Post.cook_methods[:raw_html] - cooked = nil - if cook_method == Post.cook_methods[:email] - cooked = EmailCook.new(raw).cook - else - cloned = args.dup - cloned[1] ||= {} + cooked = + if cook_method == Post.cook_methods[:email] + EmailCook.new(raw).cook + else + cloned = args.dup + cloned[1] ||= {} - post_user = self.user - cloned[1][:user_id] = post_user.id if post_user + post_user = self.user + cloned[1][:user_id] = post_user.id if post_user - cooked = if add_nofollow? - post_analyzer.cook(*args) - else - # At trust level 3, we don't apply nofollow to links - cloned[1][:omit_nofollow] = true - post_analyzer.cook(*cloned) - end - end + if add_nofollow? + post_analyzer.cook(*args) + else + # At trust level 3, we don't apply nofollow to links + cloned[1][:omit_nofollow] = true + post_analyzer.cook(*cloned) + end + end new_cooked = Plugin::Filter.apply(:after_post_cook, self, cooked) @@ -267,10 +267,10 @@ class Post < ActiveRecord::Base def whitelisted_spam_hosts hosts = SiteSetting - .white_listed_spam_host_domains - .split('|') - .map{|h| h.strip} - .reject{|h| !h.include?('.')} + .white_listed_spam_host_domains + .split('|') + .map { |h| h.strip } + .reject { |h| !h.include?('.') } hosts << GlobalSetting.hostname hosts << RailsMultisite::ConnectionManagement.current_hostname @@ -290,9 +290,9 @@ class Post < ActiveRecord::Base return hosts if hosts.length == 0 TopicLink.where(domain: hosts.keys, user_id: acting_user.id) - .group(:domain, :post_id) - .count - .each_key do |tuple| + .group(:domain, :post_id) + .count + .each_key do |tuple| domain = tuple[0] hosts[domain] = (hosts[domain] || 0) + 1 end @@ -319,7 +319,7 @@ class Post < ActiveRecord::Base order('sort_order desc, post_number desc') end - def self.summary(topic_id=nil) + def self.summary(topic_id = nil) # PERF: if you pass in nil it is WAY slower # pg chokes getting a reasonable plan topic_id = topic_id ? topic_id.to_i : "posts.topic_id" @@ -410,7 +410,7 @@ class Post < ActiveRecord::Base "#{Discourse.base_url}#{url}" end - def url(opts=nil) + def url(opts = nil) opts ||= {} if topic @@ -424,7 +424,7 @@ class Post < ActiveRecord::Base "#{Discourse.base_url}/email/unsubscribe/#{UnsubscribeKey.create_key_for(user, self)}" end - def self.url(slug, topic_id, post_number, opts=nil) + def self.url(slug, topic_id, post_number, opts = nil) opts ||= {} result = "/t/" @@ -434,12 +434,12 @@ class Post < ActiveRecord::Base end def self.urls(post_ids) - ids = post_ids.map{|u| u} + ids = post_ids.map { |u| u } if ids.length > 0 urls = {} Topic.joins(:posts).where('posts.id' => ids). - select(['posts.id as post_id','post_number', 'topics.slug', 'topics.title', 'topics.id']). - each do |t| + select(['posts.id as post_id', 'post_number', 'topics.slug', 'topics.title', 'topics.id']). + each do |t| urls[t.post_id.to_i] = url(t.slug, t.id, t.post_number) end urls @@ -448,24 +448,24 @@ class Post < ActiveRecord::Base end end - def revise(updated_by, changes={}, opts={}) + def revise(updated_by, changes = {}, opts = {}) PostRevisor.new(self).revise!(updated_by, changes, opts) end def self.rebake_old(limit) problems = [] Post.where('baked_version IS NULL OR baked_version < ?', BAKED_VERSION) - .limit(limit).each do |p| + .limit(limit).each do |p| begin p.rebake! rescue => e - problems << {post: p, ex: e} + problems << { post: p, ex: e } end end problems end - def rebake!(opts=nil) + def rebake!(opts = nil) opts ||= {} new_cooked = cook(raw, topic_id: topic_id, invalidate_oneboxes: opts.fetch(:invalidate_oneboxes, false)) @@ -485,14 +485,14 @@ class Post < ActiveRecord::Base new_cooked != old_cooked end - def set_owner(new_user, actor, skip_revision=false) + def set_owner(new_user, actor, skip_revision = false) return if user_id == new_user.id edit_reason = I18n.t('change_owner.post_revision_text', old_user: (self.user.username_lower rescue nil) || I18n.t('change_owner.deleted_user'), new_user: new_user.username_lower ) - revise(actor, {raw: self.raw, user_id: new_user.id, edit_reason: edit_reason}, {bypass_bump: true, skip_revision: skip_revision}) + revise(actor, { raw: self.raw, user_id: new_user.id, edit_reason: edit_reason }, bypass_bump: true, skip_revision: skip_revision) if post_number == topic.highest_post_number topic.update_columns(last_post_user_id: new_user.id) @@ -516,7 +516,7 @@ class Post < ActiveRecord::Base # This calculates the geometric mean of the post timings and stores it along with # each post. - def self.calculate_avg_time(min_topic_age=nil) + def self.calculate_avg_time(min_topic_age = nil) retry_lock_error do builder = SqlBuilder.new("UPDATE posts SET avg_time = (x.gmean / 1000) @@ -577,7 +577,6 @@ class Post < ActiveRecord::Base self.quote_count = temp_collector.size end - def save_reply_relationships add_to_quoted_post_numbers(reply_to_post_number) return if self.quoted_post_numbers.blank? @@ -602,7 +601,7 @@ class Post < ActiveRecord::Base DiscourseEvent.trigger(:after_trigger_post_process, self) end - def self.public_posts_count_per_day(start_date, end_date, category_id=nil) + def self.public_posts_count_per_day(start_date, end_date, category_id = nil) result = public_posts.where('posts.created_at >= ? AND posts.created_at <= ?', start_date, end_date) result = result.where('topics.category_id = ?', category_id) if category_id result.group('date(posts.created_at)').order('date(posts.created_at)').count @@ -612,7 +611,7 @@ class Post < ActiveRecord::Base private_posts.with_topic_subtype(topic_subtype).where('posts.created_at >= ? AND posts.created_at <= ?', start_date, end_date).group('date(posts.created_at)').order('date(posts.created_at)').count end - def reply_history(max_replies=100, guardian=nil) + def reply_history(max_replies = 100, guardian = nil) post_ids = Post.exec_sql("WITH RECURSIVE breadcrumb(id, reply_to_post_number) AS ( SELECT p.id, p.reply_to_post_number FROM posts AS p WHERE p.id = :post_id @@ -622,11 +621,11 @@ class Post < ActiveRecord::Base AND p.topic_id = :topic_id ) SELECT id from breadcrumb ORDER by id", post_id: id, topic_id: topic_id).to_a - post_ids.map! {|r| r['id'].to_i } - .reject! {|post_id| post_id == id} + post_ids.map! { |r| r['id'].to_i } + .reject! { |post_id| post_id == id } # [1,2,3][-10,-1] => nil - post_ids = (post_ids[(0-max_replies)..-1] || post_ids) + post_ids = (post_ids[(0 - max_replies)..-1] || post_ids) Post.secured(guardian).where(id: post_ids).includes(:user, :topic).order(:id).to_a end diff --git a/app/models/post_action.rb b/app/models/post_action.rb index 73fcf5ed37c..73a7e583ff8 100644 --- a/app/models/post_action.rb +++ b/app/models/post_action.rb @@ -42,27 +42,27 @@ class PostAction < ActiveRecord::Base nil end - def self.flag_count_by_date(start_date, end_date, category_id=nil) + def self.flag_count_by_date(start_date, end_date, category_id = nil) result = where('post_actions.created_at >= ? AND post_actions.created_at <= ?', start_date, end_date) result = result.where(post_action_type_id: PostActionType.flag_types.values) result = result.joins(post: :topic).where("topics.category_id = ?", category_id) if category_id result.group('date(post_actions.created_at)') - .order('date(post_actions.created_at)') - .count + .order('date(post_actions.created_at)') + .count end def self.update_flagged_posts_count posts_flagged_count = PostAction.active - .flags - .joins(post: :topic) - .where('posts.deleted_at' => nil) - .where('topics.deleted_at' => nil) - .where('posts.user_id > 0') - .count('DISTINCT posts.id') + .flags + .joins(post: :topic) + .where('posts.deleted_at' => nil) + .where('topics.deleted_at' => nil) + .where('posts.user_id > 0') + .count('DISTINCT posts.id') $redis.set('posts_flagged_count', posts_flagged_count) user_ids = User.staff.pluck(:id) - MessageBus.publish('/flagged_counts', { total: posts_flagged_count }, { user_ids: user_ids }) + MessageBus.publish('/flagged_counts', { total: posts_flagged_count }, user_ids: user_ids) end def self.flagged_posts_count @@ -107,7 +107,6 @@ SQL (map[row.topic_id] ||= []) << row.post_number end - map end @@ -128,21 +127,21 @@ SQL user_actions end - def self.count_per_day_for_type(post_action_type, opts=nil) + def self.count_per_day_for_type(post_action_type, opts = nil) opts ||= {} result = unscoped.where(post_action_type_id: post_action_type) result = result.where('post_actions.created_at >= ?', opts[:start_date] || (opts[:since_days_ago] || 30).days.ago) result = result.where('post_actions.created_at <= ?', opts[:end_date]) if opts[:end_date] result = result.joins(post: :topic).where('topics.category_id = ?', opts[:category_id]) if opts[:category_id] result.group('date(post_actions.created_at)') - .order('date(post_actions.created_at)') - .count + .order('date(post_actions.created_at)') + .count end - def self.agree_flags!(post, moderator, delete_post=false) + def self.agree_flags!(post, moderator, delete_post = false) actions = PostAction.active - .where(post_id: post.id) - .where(post_action_type_id: PostActionType.flag_types.values) + .where(post_id: post.id) + .where(post_action_type_id: PostActionType.flag_types.values) trigger_spam = false actions.each do |action| @@ -169,7 +168,7 @@ SQL end actions = PostAction.where(post_id: post.id) - .where(post_action_type_id: action_type_ids) + .where(post_action_type_id: action_type_ids) actions.each do |action| action.disagreed_at = Time.zone.now @@ -186,10 +185,10 @@ SQL update_flagged_posts_count end - def self.defer_flags!(post, moderator, delete_post=false) + def self.defer_flags!(post, moderator, delete_post = false) actions = PostAction.active - .where(post_id: post.id) - .where(post_action_type_id: PostActionType.flag_types.values) + .where(post_id: post.id) + .where(post_action_type_id: PostActionType.flag_types.values) actions.each do |action| action.deferred_at = Time.zone.now @@ -202,7 +201,7 @@ SQL update_flagged_posts_count end - def add_moderator_post_if_needed(moderator, disposition, delete_post=false) + def add_moderator_post_if_needed(moderator, disposition, delete_post = false) return if !SiteSetting.auto_respond_to_flag_actions return if related_post.nil? || related_post.topic.nil? return if staff_already_replied?(related_post.topic) @@ -237,33 +236,35 @@ SQL opts[:target_group_names] = target_moderators else opts[:subtype] = TopicSubtype.notify_user - opts[:target_usernames] = if post_action_type == :notify_user - post.user.username - elsif post_action_type != :notify_moderators - # this is a hack to allow a PM with no recipients, we should think through - # a cleaner technique, a PM with myself is valid for flagging - 'x' - end + + opts[:target_usernames] = + if post_action_type == :notify_user + post.user.username + elsif post_action_type != :notify_moderators + # this is a hack to allow a PM with no recipients, we should think through + # a cleaner technique, a PM with myself is valid for flagging + 'x' + end end PostCreator.new(user, opts).create.try(:id) end - def self.limit_action!(user,post,post_action_type_id) + def self.limit_action!(user, post, post_action_type_id) RateLimiter.new(user, "post_action-#{post.id}_#{post_action_type_id}", 4, 1.minute).performed! end def self.act(user, post, post_action_type_id, opts = {}) - limit_action!(user,post,post_action_type_id) + limit_action!(user, post, post_action_type_id) related_post_id = create_message_for_post_action(user, post, post_action_type_id, opts) staff_took_action = opts[:take_action] || false - targets_topic = if opts[:flag_topic] && post.topic - post.topic.reload - post.topic.posts_count != 1 - end + targets_topic = + if opts[:flag_topic] && post.topic + post.topic.reload.posts_count != 1 + end where_attrs = { post_id: post.id, @@ -279,9 +280,9 @@ SQL # First try to revive a trashed record post_action = PostAction.where(where_attrs) - .with_deleted - .where("deleted_at IS NOT NULL") - .first + .with_deleted + .where("deleted_at IS NOT NULL") + .first if post_action post_action.recover! @@ -324,7 +325,7 @@ SQL def self.remove_act(user, post, post_action_type_id) - limit_action!(user,post,post_action_type_id) + limit_action!(user, post, post_action_type_id) finder = PostAction.where(post_id: post.id, user_id: user.id, post_action_type_id: post_action_type_id) finder = finder.with_deleted.includes(:post) if user.try(:staff?) @@ -374,10 +375,10 @@ SQL multiplier = SiteSetting.send("tl#{user.trust_level}_additional_likes_per_day_multiplier").to_f multiplier = 1.0 if multiplier < 1.0 - limit = (limit * multiplier ).to_i + limit = (limit * multiplier).to_i end - @rate_limiter = RateLimiter.new(user, "create_#{type}",limit, 1.day.to_i) + @rate_limiter = RateLimiter.new(user, "create_#{type}", limit, 1.day.to_i) return @rate_limiter end end @@ -386,12 +387,12 @@ SQL before_create do post_action_type_ids = is_flag? ? PostActionType.flag_types.values : post_action_type_id raise AlreadyActed if PostAction.where(user_id: user_id) - .where(post_id: post_id) - .where(post_action_type_id: post_action_type_ids) - .where(deleted_at: nil) - .where(disagreed_at: nil) - .where(targets_topic: targets_topic) - .exists? + .where(post_id: post_id) + .where(post_action_type_id: post_action_type_ids) + .where(deleted_at: nil) + .where(disagreed_at: nil) + .where(targets_topic: targets_topic) + .exists? end # Returns the flag counts for a post, taking into account that some users @@ -427,8 +428,8 @@ SQL # Update denormalized counts column = "#{post_action_type_key}_count" count = PostAction.where(post_id: post_id) - .where(post_action_type_id: post_action_type_id) - .count + .where(post_action_type_id: post_action_type_id) + .count # We probably want to refactor this method to something cleaner. case post_action_type_key @@ -438,18 +439,17 @@ SQL when :like # 'like_score' is weighted higher for staff accounts score = PostAction.joins(:user) - .where(post_id: post_id) - .sum("CASE WHEN users.moderator OR users.admin THEN #{SiteSetting.staff_like_weight} ELSE 1 END") + .where(post_id: post_id) + .sum("CASE WHEN users.moderator OR users.admin THEN #{SiteSetting.staff_like_weight} ELSE 1 END") Post.where(id: post_id).update_all ["like_count = :count, like_score = :score", count: count, score: score] else Post.where(id: post_id).update_all ["#{column} = ?", count] end - topic_id = Post.with_deleted.where(id: post_id).pluck(:topic_id).first # topic_user - if [:like,:bookmark].include? post_action_type_key + if [:like, :bookmark].include? post_action_type_key TopicUser.update_post_action_cache(user_id: user_id, topic_id: topic_id, post_action_type: post_action_type_key) @@ -501,12 +501,12 @@ SQL return if topic.nil? || topic.closed? flags = PostAction.active - .flags - .joins(:post) - .where("posts.topic_id = ?", topic.id) - .where("post_actions.user_id > 0") - .group("post_actions.user_id") - .pluck("post_actions.user_id, COUNT(post_id)") + .flags + .joins(:post) + .where("posts.topic_id = ?", topic.id) + .where("post_actions.user_id > 0") + .group("post_actions.user_id") + .pluck("post_actions.user_id, COUNT(post_id)") # we need a minimum number of unique flaggers return if flags.count < SiteSetting.num_flaggers_to_close_topic @@ -535,7 +535,7 @@ SQL acting_user.has_trust_level?(TrustLevel[3]) && post.user.trust_level == TrustLevel[0] - hide_post!(post, post_action_type, Post.hidden_reasons[:flagged_by_tl3_user]) + hide_post!(post, post_action_type, Post.hidden_reasons[:flagged_by_tl3_user]) elsif PostActionType.auto_action_flag_types.include?(post_action_type) && SiteSetting.flags_required_to_hide_post > 0 @@ -548,7 +548,7 @@ SQL end end - def self.hide_post!(post, post_action_type, reason=nil) + def self.hide_post!(post, post_action_type, reason = nil) return if post.hidden unless reason diff --git a/app/models/post_analyzer.rb b/app/models/post_analyzer.rb index 53296c8e596..e0105cce4eb 100644 --- a/app/models/post_analyzer.rb +++ b/app/models/post_analyzer.rb @@ -3,7 +3,7 @@ require_dependency 'oneboxer' class PostAnalyzer def initialize(raw, topic_id) - @raw = raw + @raw = raw @topic_id = topic_id @found_oneboxes = false end @@ -51,11 +51,11 @@ class PostAnalyzer return @raw_mentions if @raw_mentions.present? raw_mentions = cooked_stripped.css('.mention, .mention-group').map do |e| - if name = e.inner_text - name = name[1..-1] - name.downcase! if name - name - end + if name = e.inner_text + name = name[1..-1] + name.downcase! if name + name + end end raw_mentions.compact! diff --git a/app/models/post_mover.rb b/app/models/post_mover.rb index 1d70519eaf6..06ac7b5ebcf 100644 --- a/app/models/post_mover.rb +++ b/app/models/post_mover.rb @@ -19,7 +19,7 @@ class PostMover end end - def to_new_topic(title, category_id=nil) + def to_new_topic(title, category_id = nil) @move_type = PostMover.move_types[:new_topic] post = Post.find_by(id: post_ids.first) diff --git a/app/models/post_timing.rb b/app/models/post_timing.rb index 8f682090204..c006d29508e 100644 --- a/app/models/post_timing.rb +++ b/app/models/post_timing.rb @@ -5,7 +5,6 @@ class PostTiming < ActiveRecord::Base validates_presence_of :post_number validates_presence_of :msecs - def self.pretend_read(topic_id, actual_read_post_number, pretend_read_post_number) # This is done in SQL cause the logic is quite tricky and we want to do this in one db hit # @@ -39,9 +38,9 @@ class PostTiming < ActiveRecord::Base AND post_number = :post_number)", args) rescue PG::UniqueViolation - # concurrency is hard, we are not running serialized so this can possibly - # still happen, if it happens we just don't care, its an invalid record anyway - return + # concurrency is hard, we are not running serialized so this can possibly + # still happen, if it happens we just don't care, its an invalid record anyway + return end Post.where(['topic_id = :topic_id and post_number = :post_number', args]).update_all 'reads = reads + 1' @@ -60,7 +59,6 @@ class PostTiming < ActiveRecord::Base record_new_timing(args) if rows == 0 end - def self.destroy_for(user_id, topic_ids) PostTiming.transaction do PostTiming.delete_all(['user_id = ? and topic_id in (?)', user_id, topic_ids]) @@ -68,9 +66,9 @@ class PostTiming < ActiveRecord::Base end end - MAX_READ_TIME_PER_BATCH = 60*1000.0 + MAX_READ_TIME_PER_BATCH = 60 * 1000.0 - def self.process_timings(current_user, topic_id, topic_time, timings, opts={}) + def self.process_timings(current_user, topic_id, topic_time, timings, opts = {}) current_user.user_stat.update_time_read! max_time_per_post = ((Time.now - current_user.created_at) * 1000.0) @@ -89,9 +87,8 @@ class PostTiming < ActiveRecord::Base timings.each_with_index do |(post_number, time), index| - join_table << "SELECT #{topic_id.to_i} topic_id, #{post_number.to_i} post_number, - #{current_user.id.to_i} user_id, #{time.to_i} msecs, #{index} idx" - + join_table << "SELECT #{topic_id.to_i} topic_id, #{post_number.to_i} post_number, + #{current_user.id.to_i} user_id, #{time.to_i} msecs, #{index} idx" highest_seen = post_number.to_i > highest_seen ? post_number.to_i : highest_seen @@ -113,19 +110,19 @@ SQL result.type_map = SqlBuilder.pg_type_map existing = Set.new(result.column_values(0)) - timings.each_with_index do |(post_number, time),index| + timings.each_with_index do |(post_number, time), index| unless existing.include?(index) PostTiming.record_new_timing(topic_id: topic_id, - post_number: post_number, - user_id: current_user.id, - msecs: time) + post_number: post_number, + user_id: current_user.id, + msecs: time) end end end total_changed = 0 if timings.length > 0 - total_changed = Notification.mark_posts_read(current_user, topic_id, timings.map{|t| t[0]}) + total_changed = Notification.mark_posts_read(current_user, topic_id, timings.map { |t| t[0] }) end topic_time = max_time_per_post if topic_time > max_time_per_post diff --git a/app/models/queued_post.rb b/app/models/queued_post.rb index e1736c85488..f7b3147e8be 100644 --- a/app/models/queued_post.rb +++ b/app/models/queued_post.rb @@ -51,7 +51,7 @@ class QueuedPost < ActiveRecord::Base end def create_options - opts = {raw: raw} + opts = { raw: raw } opts.merge!(post_options.symbolize_keys) opts[:cooking_options].symbolize_keys! if opts[:cooking_options] @@ -102,7 +102,7 @@ class QueuedPost < ActiveRecord::Base end # Update the record in memory too, and clear the dirty flag - updates.each {|k, v| send("#{k}=", v) } + updates.each { |k, v| send("#{k}=", v) } changes_applied QueuedPost.broadcast_new! if visible? diff --git a/app/models/quoted_post.rb b/app/models/quoted_post.rb index 2bd06fce81c..ecfe19e73d3 100644 --- a/app/models/quoted_post.rb +++ b/app/models/quoted_post.rb @@ -17,8 +17,8 @@ class QuotedPost < ActiveRecord::Base post_number = a['data-post'].to_i next if topic_id == 0 || post_number == 0 - next if uniq[[topic_id,post_number]] - uniq[[topic_id,post_number]] = true + next if uniq[[topic_id, post_number]] + uniq[[topic_id, post_number]] = true begin # It would be so much nicer if we used post_id in quotes diff --git a/app/models/remote_theme.rb b/app/models/remote_theme.rb index b426030dbea..3030b4aa22d 100644 --- a/app/models/remote_theme.rb +++ b/app/models/remote_theme.rb @@ -7,7 +7,7 @@ class RemoteTheme < ActiveRecord::Base has_one :theme - def self.import_theme(url, user=Discourse.system_user) + def self.import_theme(url, user = Discourse.system_user) importer = GitImporter.new(url) importer.import! @@ -37,7 +37,7 @@ class RemoteTheme < ActiveRecord::Base self.remote_version, self.commits_behind = importer.commits_since(remote_version) end - def update_from_remote(importer=nil) + def update_from_remote(importer = nil) return unless remote_url cleanup = false @@ -70,9 +70,9 @@ class RemoteTheme < ActiveRecord::Base end theme.set_field(target: info["target"] || :common, - name: name, - value: info["value"], - type: info["type"] || :theme_var) + name: name, + value: info["value"], + type: info["type"] || :theme_var) end Theme.targets.keys.each do |target| diff --git a/app/models/report.rb b/app/models/report.rb index 76c162ffb17..8144df648b9 100644 --- a/app/models/report.rb +++ b/app/models/report.rb @@ -14,7 +14,7 @@ class Report @end_date ||= Time.zone.now.end_of_day end - def as_json(options=nil) + def as_json(options = nil) { type: type, title: I18n.t("reports.#{type}.title"), @@ -34,7 +34,7 @@ class Report singleton_class.instance_eval { define_method("report_#{name}", &block) } end - def self.find(type, opts=nil) + def self.find(type, opts = nil) opts ||= {} # Load the report @@ -56,11 +56,11 @@ class Report report end - def self.req_report(report, filter=nil) + def self.req_report(report, filter = nil) data = if filter == :page_view_total ApplicationRequest.where(req_type: [ - ApplicationRequest.req_types.reject{|k,v| k =~ /mobile/}.map{|k,v| v if k =~ /page_view/}.compact + ApplicationRequest.req_types.reject { |k, v| k =~ /mobile/ }.map { |k, v| v if k =~ /page_view/ }.compact ].flatten) else ApplicationRequest.where(req_type: ApplicationRequest.req_types[filter]) @@ -68,18 +68,18 @@ class Report report.data = [] data.where('date >= ? AND date <= ?', report.start_date.to_date, report.end_date.to_date) - .order(date: :asc) - .group(:date) - .sum(:count) - .each do |date, count| + .order(date: :asc) + .group(:date) + .sum(:count) + .each do |date, count| report.data << { x: date, y: count } end report.total = data.sum(:count) report.prev30Days = data.where('date >= ? AND date <= ?', (report.start_date - 31.days).to_date, - (report.end_date - 31.days).to_date ) - .sum(:count) + (report.end_date - 31.days).to_date) + .sum(:count) end def self.report_visits(report) @@ -128,7 +128,7 @@ class Report def self.report_time_to_first_response(report) report.data = [] - Topic.time_to_first_response_per_day(report.start_date, report.end_date, {category_id: report.category_id}).each do |r| + Topic.time_to_first_response_per_day(report.start_date, report.end_date, category_id: report.category_id).each do |r| report.data << { x: Date.parse(r["date"]), y: r["hours"].to_f.round(2) } end report.total = Topic.time_to_first_response_total(category_id: report.category_id) diff --git a/app/models/screened_email.rb b/app/models/screened_email.rb index ee8b005728e..a0dec7f12f1 100644 --- a/app/models/screened_email.rb +++ b/app/models/screened_email.rb @@ -18,8 +18,8 @@ class ScreenedEmail < ActiveRecord::Base self.email = email.downcase end - def self.block(email, opts={}) - find_by_email(Email.downcase(email)) || create(opts.slice(:action_type, :ip_address).merge({email: email})) + def self.block(email, opts = {}) + find_by_email(Email.downcase(email)) || create(opts.slice(:action_type, :ip_address).merge(email: email)) end def self.should_block?(email) @@ -30,8 +30,8 @@ class ScreenedEmail < ActiveRecord::Base max_distance = SiteSetting.levenshtein_distance_spammer_emails screened_email = screened_emails.select { |se| distances[se.email] <= max_distance } - .sort { |se| distances[se.email] } - .first + .sort { |se| distances[se.email] } + .first screened_email.record_match! if screened_email @@ -46,13 +46,13 @@ class ScreenedEmail < ActiveRecord::Base (1..second.length).each do |i| (1..first.length).each do |j| - if first[j-1] == second[i-1] - matrix[i][j] = matrix[i-1][j-1] + if first[j - 1] == second[i - 1] + matrix[i][j] = matrix[i - 1][j - 1] else matrix[i][j] = [ - matrix[i-1][j], - matrix[i][j-1], - matrix[i-1][j-1], + matrix[i - 1][j], + matrix[i][j - 1], + matrix[i - 1][j - 1], ].min + 1 end end diff --git a/app/models/screened_ip_address.rb b/app/models/screened_ip_address.rb index 248ad97703c..f0e51ab0456 100644 --- a/app/models/screened_ip_address.rb +++ b/app/models/screened_ip_address.rb @@ -11,7 +11,7 @@ class ScreenedIpAddress < ActiveRecord::Base validates :ip_address, ip_address_format: true, presence: true - def self.watch(ip_address, opts={}) + def self.watch(ip_address, opts = {}) match_for_ip_address(ip_address) || create(opts.slice(:action_type).merge(ip_address: ip_address)) end @@ -67,10 +67,10 @@ class ScreenedIpAddress < ActiveRecord::Base exists_for_ip_address_and_action?(ip_address, actions[:do_nothing]) end - def self.exists_for_ip_address_and_action?(ip_address, action_type, opts={}) + def self.exists_for_ip_address_and_action?(ip_address, action_type, opts = {}) b = match_for_ip_address(ip_address) - found = (!!b and b.action_type == action_type) - b.record_match! if found and opts[:record_match] != false + found = (!!b && b.action_type == (action_type)) + b.record_match! if found && opts[:record_match] != (false) found end @@ -125,7 +125,7 @@ class ScreenedIpAddress < ActiveRecord::Base ScreenedIpAddress.exec_sql(star_star_subnets_query, min_count: 10, roll_up_weight: weight).values.flatten end - def self.roll_up(current_user=Discourse.system_user) + def self.roll_up(current_user = Discourse.system_user) # 1 - retrieve all subnets that needs roll up subnets = [star_subnets, star_star_subnets].flatten @@ -158,9 +158,9 @@ class ScreenedIpAddress < ActiveRecord::Base # 5 - remove old matches ScreenedIpAddress.where(action_type: ScreenedIpAddress.actions[:block]) - .where("family(ip_address) = 4") - .where("ip_address << ?", subnet) - .delete_all + .where("family(ip_address) = 4") + .where("ip_address << ?", subnet) + .delete_all end # return the subnets diff --git a/app/models/screened_url.rb b/app/models/screened_url.rb index 3bd7cc1b897..47e6e949db6 100644 --- a/app/models/screened_url.rb +++ b/app/models/screened_url.rb @@ -21,7 +21,7 @@ class ScreenedUrl < ActiveRecord::Base self.domain = self.domain.downcase.sub(/^www\./, '') if self.domain end - def self.watch(url, domain, opts={}) + def self.watch(url, domain, opts = {}) find_match(url) || create(opts.slice(:action_type, :ip_address).merge(url: url, domain: domain)) end diff --git a/app/models/search_log.rb b/app/models/search_log.rb index 35a427d7185..acaf269c563 100644 --- a/app/models/search_log.rb +++ b/app/models/search_log.rb @@ -10,7 +10,7 @@ class SearchLog < ActiveRecord::Base ) end - def self.log(term:, search_type:, ip_address:, user_id:nil) + def self.log(term:, search_type:, ip_address:, user_id: nil) search_type = search_types[search_type] return [:error] unless search_type.present? && ip_address.present? diff --git a/app/models/site.rb b/app/models/site.rb index 37312625ba2..9d90b2c1bc3 100644 --- a/app/models/site.rb +++ b/app/models/site.rb @@ -121,7 +121,7 @@ class Site def self.clear_anon_cache! # publishing forces the sequence up # the cache is validated based on the sequence - MessageBus.publish('/site_json','') + MessageBus.publish('/site_json', '') end end diff --git a/app/models/site_setting.rb b/app/models/site_setting.rb index ef88e14516d..2e4fa838f34 100644 --- a/app/models/site_setting.rb +++ b/app/models/site_setting.rb @@ -34,7 +34,7 @@ class SiteSetting < ActiveRecord::Base client_settings << :available_locales def self.available_locales - LocaleSiteSetting.values.map{ |e| e[:value] }.join('|') + LocaleSiteSetting.values.map { |e| e[:value] }.join('|') end def self.topic_title_length @@ -71,8 +71,8 @@ class SiteSetting < ActiveRecord::Base def self.anonymous_homepage top_menu_items.map { |item| item.name } - .select { |item| anonymous_menu_items.include?(item) } - .first + .select { |item| anonymous_menu_items.include?(item) } + .first end def self.should_download_images?(src) diff --git a/app/models/slug_setting.rb b/app/models/slug_setting.rb index b2be27fcbd3..86dc666d918 100644 --- a/app/models/slug_setting.rb +++ b/app/models/slug_setting.rb @@ -10,7 +10,7 @@ class SlugSetting < EnumSiteSetting def self.values VALUES.map do |l| - {name: l, value: l} + { name: l, value: l } end end diff --git a/app/models/stylesheet_cache.rb b/app/models/stylesheet_cache.rb index 2c568072cbf..b421c0df7ad 100644 --- a/app/models/stylesheet_cache.rb +++ b/app/models/stylesheet_cache.rb @@ -3,7 +3,7 @@ class StylesheetCache < ActiveRecord::Base MAX_TO_KEEP = 50 - def self.add(target,digest,content,source_map) + def self.add(target, digest, content, source_map) return false if where(target: target, digest: digest).exists? @@ -13,11 +13,11 @@ class StylesheetCache < ActiveRecord::Base if count > MAX_TO_KEEP remove_lower = StylesheetCache - .where(target: target) - .limit(MAX_TO_KEEP) - .order('id desc') - .pluck(:id) - .last + .where(target: target) + .limit(MAX_TO_KEEP) + .order('id desc') + .pluck(:id) + .last exec_sql("DELETE FROM stylesheet_cache where id < :id", id: remove_lower) end diff --git a/app/models/tag.rb b/app/models/tag.rb index 95a944776c4..a9223b670ac 100644 --- a/app/models/tag.rb +++ b/app/models/tag.rb @@ -18,23 +18,23 @@ class Tag < ActiveRecord::Base # fetch the result with .count(Tag::COUNT_ARG). # # e.g., Tag.tags_by_count_query.where("topics.category_id = ?", category.id).count(Tag::COUNT_ARG) - def self.tags_by_count_query(opts={}) + def self.tags_by_count_query(opts = {}) q = Tag.joins("LEFT JOIN topic_tags ON tags.id = topic_tags.tag_id") - .joins("LEFT JOIN topics ON topics.id = topic_tags.topic_id") - .group("tags.id, tags.name") - .order('count_topic_tags_id DESC') + .joins("LEFT JOIN topics ON topics.id = topic_tags.topic_id") + .group("tags.id, tags.name") + .order('count_topic_tags_id DESC') q = q.limit(opts[:limit]) if opts[:limit] q end - def self.category_tags_by_count_query(category, opts={}) + def self.category_tags_by_count_query(category, opts = {}) tags_by_count_query(opts).where("tags.id in (select tag_id from category_tags where category_id = ?)", category.id) - .where("topics.category_id = ?", category.id) + .where("topics.category_id = ?", category.id) end def self.top_tags(limit_arg: nil, category: nil, guardian: nil) limit = limit_arg || SiteSetting.max_tags_in_filter_list - scope_category_ids = (guardian||Guardian.new).allowed_category_ids + scope_category_ids = (guardian || Guardian.new).allowed_category_ids if category scope_category_ids &= ([category.id] + category.subcategories.pluck(:id)) @@ -46,7 +46,7 @@ class Tag < ActiveRecord::Base category: category ) - tags.count(COUNT_ARG).map {|name, _| name} + tags.count(COUNT_ARG).map { |name, _| name } end def self.include_tags? diff --git a/app/models/theme.rb b/app/models/theme.rb index ab1fceb91f2..f38668e1fa6 100644 --- a/app/models/theme.rb +++ b/app/models/theme.rb @@ -50,7 +50,7 @@ class Theme < ActiveRecord::Base ColorScheme .where(theme_id: self.id) .where("id NOT IN (SELECT color_scheme_id FROM themes where color_scheme_id IS NOT NULL)") - .destroy_all + .destroy_all ColorScheme .where(theme_id: self.id) @@ -114,7 +114,7 @@ class Theme < ActiveRecord::Base (@cache[cache_key] = val || "").html_safe end - def self.remove_from_cache!(themes=nil) + def self.remove_from_cache!(themes = nil) clear_cache! end @@ -122,13 +122,11 @@ class Theme < ActiveRecord::Base @cache.clear end - def self.targets @targets ||= Enum.new(common: 0, desktop: 1, mobile: 2) end - - def notify_scheme_change(clear_manager_cache=true) + def notify_scheme_change(clear_manager_cache = true) Stylesheet::Manager.cache.clear if clear_manager_cache message = refresh_message_for_targets(["desktop", "mobile", "admin"], self) MessageBus.publish('/file-change', message) @@ -140,7 +138,7 @@ class Theme < ActiveRecord::Base themes = [self] + dependant_themes message = themes.map do |theme| - refresh_message_for_targets([:mobile_theme,:desktop_theme], theme) + refresh_message_for_targets([:mobile_theme, :desktop_theme], theme) end.compact.flatten MessageBus.publish('/file-change', message) end @@ -168,7 +166,7 @@ class Theme < ActiveRecord::Base def resolve_dependant_themes(direction) - select_field,where_field=nil + select_field, where_field = nil if direction == :up select_field = "parent_theme_id" @@ -212,7 +210,7 @@ class Theme < ActiveRecord::Base end def resolve_baked_field(target, name) - list_baked_fields(target,name).map{|f| f.value_baked || f.value}.join("\n") + list_baked_fields(target, name).map { |f| f.value_baked || f.value }.join("\n") end def list_baked_fields(target, name) @@ -221,12 +219,15 @@ class Theme < ActiveRecord::Base theme_ids = [self.id] + (included_themes.map(&:id) || []) fields = ThemeField.where(target_id: [Theme.targets[target], Theme.targets[:common]]) - .where(name: name.to_s) - .includes(:theme) - .joins("JOIN ( - SELECT #{theme_ids.map.with_index{|id,idx| "#{id} AS theme_id, #{idx} AS sort_column"}.join(" UNION ALL SELECT ")} - ) as X ON X.theme_id = theme_fields.theme_id") - .order('sort_column, target_id') + .where(name: name.to_s) + .includes(:theme) + .joins(" + JOIN ( + SELECT #{theme_ids.map.with_index { |id, idx| "#{id} AS theme_id, #{idx} AS sort_column" }.join(" UNION ALL SELECT ")} + ) as X ON X.theme_id = theme_fields.theme_id" + ) + .order('sort_column, target_id') + fields.each(&:ensure_baked!) fields end @@ -254,7 +255,7 @@ class Theme < ActiveRecord::Base value ||= "" - field = theme_fields.find{|f| f.name==name && f.target_id == target_id && f.type_id == type_id} + field = theme_fields.find { |f| f.name == name && f.target_id == target_id && f.type_id == type_id } if field if value.blank? && !upload_id theme_fields.delete field.destroy diff --git a/app/models/theme_field.rb b/app/models/theme_field.rb index 34d09eb1898..26e67329ee0 100644 --- a/app/models/theme_field.rb +++ b/app/models/theme_field.rb @@ -11,7 +11,7 @@ class ThemeField < ActiveRecord::Base end def self.theme_var_type_ids - @theme_var_type_ids ||= [2,3,4] + @theme_var_type_ids ||= [2, 3, 4] end COMPILER_VERSION = 5 @@ -19,7 +19,7 @@ class ThemeField < ActiveRecord::Base belongs_to :theme def transpile(es6_source, version) - template = Tilt::ES6ModuleTranspilerTemplate.new {} + template = Tilt::ES6ModuleTranspilerTemplate.new {} wrapped = < { #{es6_source} @@ -90,7 +90,6 @@ COMPILED @scss_fields ||= %w(scss embedded_scss) end - def ensure_baked! if ThemeField.html_fields.include?(self.name) if !self.value_baked || compiler_version != COMPILER_VERSION diff --git a/app/models/top_topic.rb b/app/models/top_topic.rb index 6172f7cf0a0..709148167c4 100644 --- a/app/models/top_topic.rb +++ b/app/models/top_topic.rb @@ -16,7 +16,7 @@ class TopTopic < ActiveRecord::Base # We don't have to refresh these as often def self.refresh_older! - older_periods = periods - [:daily,:all] + older_periods = periods - [:daily, :all] transaction do older_periods.each do |period| @@ -32,7 +32,6 @@ class TopTopic < ActiveRecord::Base refresh_older! end - def self.periods @@periods ||= [:all, :yearly, :quarterly, :monthly, :weekly, :daily].freeze end @@ -203,11 +202,11 @@ class TopTopic < ActiveRecord::Base def self.start_of(period) case period - when :yearly then 1.year.ago - when :monthly then 1.month.ago - when :quarterly then 3.months.ago - when :weekly then 1.week.ago - when :daily then 1.day.ago + when :yearly then 1.year.ago + when :monthly then 1.month.ago + when :quarterly then 3.months.ago + when :weekly then 1.week.ago + when :daily then 1.day.ago end end diff --git a/app/models/topic.rb b/app/models/topic.rb index 9b3e0b0f2fa..b076191a8d3 100644 --- a/app/models/topic.rb +++ b/app/models/topic.rb @@ -30,14 +30,14 @@ class Topic < ActiveRecord::Base attr_accessor :allowed_user_ids, :tags_changed def self.max_sort_order - @max_sort_order ||= (2 ** 31) - 1 + @max_sort_order ||= (2**31) - 1 end def featured_users @featured_users ||= TopicFeaturedUsers.new(self) end - def trash!(trashed_by=nil) + def trash!(trashed_by = nil) update_category_topic_count_by(-1) if deleted_at.nil? super(trashed_by) update_flagged_posts_count @@ -57,27 +57,27 @@ class Topic < ActiveRecord::Base rate_limit :limit_topics_per_day rate_limit :limit_private_messages_per_day - validates :title, :if => Proc.new { |t| t.new_record? || t.title_changed? }, - :presence => true, - :topic_title_length => true, - :censored_words => true, - :quality_title => { :unless => :private_message? }, - :unique_among => { :unless => Proc.new { |t| (SiteSetting.allow_duplicate_topic_titles? || t.private_message?) }, - :message => :has_already_been_used, - :allow_blank => true, - :case_sensitive => false, - :collection => Proc.new{ Topic.listable_topics } } + validates :title, if: Proc.new { |t| t.new_record? || t.title_changed? }, + presence: true, + topic_title_length: true, + censored_words: true, + quality_title: { unless: :private_message? }, + unique_among: { unless: Proc.new { |t| (SiteSetting.allow_duplicate_topic_titles? || t.private_message?) }, + message: :has_already_been_used, + allow_blank: true, + case_sensitive: false, + collection: Proc.new { Topic.listable_topics } } validates :category_id, - :presence => true, - :exclusion => { - :in => Proc.new{[SiteSetting.uncategorized_category_id]} + presence: true, + exclusion: { + in: Proc.new { [SiteSetting.uncategorized_category_id] } }, - :if => Proc.new { |t| - (t.new_record? || t.category_id_changed?) && - !SiteSetting.allow_uncategorized_topics && - (t.archetype.nil? || t.archetype == Archetype.default) && - (!t.user_id || !t.user.staff?) + if: Proc.new { |t| + (t.new_record? || t.category_id_changed?) && + !SiteSetting.allow_uncategorized_topics && + (t.archetype.nil? || t.archetype == Archetype.default) && + (!t.user_id || !t.user.staff?) } validates :featured_link, allow_nil: true, format: URI::regexp(%w(http https)) @@ -124,7 +124,7 @@ class Topic < ActiveRecord::Base has_many :topic_timers, dependent: :destroy has_one :user_warning - has_one :first_post, -> {where post_number: 1}, class_name: Post + has_one :first_post, -> { where post_number: 1 }, class_name: Post has_one :topic_embed, dependent: :destroy @@ -152,7 +152,7 @@ class Topic < ActiveRecord::Base scope :created_since, lambda { |time_ago| where('topics.created_at > ?', time_ago) } - scope :secured, lambda { |guardian=nil| + scope :secured, lambda { |guardian = nil| ids = guardian.secure_category_ids if guardian # Query conditions @@ -242,7 +242,7 @@ class Topic < ActiveRecord::Base end end - def self.visible_post_types(viewed_by=nil) + def self.visible_post_types(viewed_by = nil) types = Post.types result = [types[:regular], types[:moderator_action], types[:small_action]] result << types[:whisper] if viewed_by.try(:staff?) @@ -267,8 +267,8 @@ class Topic < ActiveRecord::Base def has_flags? FlagQuery.flagged_post_actions("active") - .where("topics.id" => id) - .exists? + .where("topics.id" => id) + .exists? end def is_official_warning? @@ -324,21 +324,21 @@ class Topic < ActiveRecord::Base end # Returns hot topics since a date for display in email digest. - def self.for_digest(user, since, opts=nil) + def self.for_digest(user, since, opts = nil) opts = opts || {} score = "#{ListController.best_period_for(since)}_score" topics = Topic - .visible - .secured(Guardian.new(user)) - .joins("LEFT OUTER JOIN topic_users ON topic_users.topic_id = topics.id AND topic_users.user_id = #{user.id.to_i}") - .joins("LEFT OUTER JOIN category_users ON category_users.category_id = topics.category_id AND category_users.user_id = #{user.id.to_i}") - .joins("LEFT OUTER JOIN users ON users.id = topics.user_id") - .where(closed: false, archived: false) - .where("COALESCE(topic_users.notification_level, 1) <> ?", TopicUser.notification_levels[:muted]) - .created_since(since) - .listable_topics - .includes(:category) + .visible + .secured(Guardian.new(user)) + .joins("LEFT OUTER JOIN topic_users ON topic_users.topic_id = topics.id AND topic_users.user_id = #{user.id.to_i}") + .joins("LEFT OUTER JOIN category_users ON category_users.category_id = topics.category_id AND category_users.user_id = #{user.id.to_i}") + .joins("LEFT OUTER JOIN users ON users.id = topics.user_id") + .where(closed: false, archived: false) + .where("COALESCE(topic_users.notification_level, 1) <> ?", TopicUser.notification_levels[:muted]) + .created_since(since) + .listable_topics + .includes(:category) unless opts[:include_tl0] || user.user_option.try(:include_tl0_in_digests) topics = topics.where("COALESCE(users.trust_level, 0) > 0") @@ -346,7 +346,7 @@ class Topic < ActiveRecord::Base if !!opts[:top_order] topics = topics.joins("LEFT OUTER JOIN top_topics ON top_topics.topic_id = topics.id") - .order(TopicQuerySQL.order_top_with_notification_levels(score)) + .order(TopicQuerySQL.order_top_with_notification_levels(score)) end if opts[:limit] @@ -383,7 +383,7 @@ class Topic < ActiveRecord::Base end # Using the digest query, figure out what's new for a user since last seen - def self.new_since_last_seen(user, since, featured_topic_ids=nil) + def self.new_since_last_seen(user, since, featured_topic_ids = nil) topics = Topic.for_digest(user, since) featured_topic_ids ? topics.where("topics.id NOT IN (?)", featured_topic_ids) : topics end @@ -401,7 +401,7 @@ class Topic < ActiveRecord::Base save end - def reload(options=nil) + def reload(options = nil) @post_numbers = nil @public_topic_timer = nil super(options) @@ -423,7 +423,7 @@ class Topic < ActiveRecord::Base custom_fields[key.to_s] end - def self.listable_count_per_day(start_date, end_date, category_id=nil) + def self.listable_count_per_day(start_date, end_date, category_id = nil) result = listable_topics.where('created_at >= ? and created_at <= ?', start_date, end_date) result = result.where(category_id: category_id) if category_id result.group('date(created_at)').order('date(created_at)').count @@ -435,7 +435,7 @@ class Topic < ActiveRecord::Base MAX_SIMILAR_BODY_LENGTH = 200 # Search for similar topics - def self.similar_to(title, raw, user=nil) + def self.similar_to(title, raw, user = nil) return [] unless title.present? return [] unless raw.present? @@ -445,12 +445,12 @@ class Topic < ActiveRecord::Base # Exclude category definitions from similar topic suggestions candidates = Topic.visible - .secured(Guardian.new(user)) - .listable_topics - .joins('JOIN topic_search_data s ON topics.id = s.topic_id') - .where("search_data @@ #{ts_query}") - .order("ts_rank(search_data, #{ts_query}) DESC") - .limit(SiteSetting.max_similar_results * 3) + .secured(Guardian.new(user)) + .listable_topics + .joins('JOIN topic_search_data s ON topics.id = s.topic_id') + .where("search_data @@ #{ts_query}") + .order("ts_rank(search_data, #{ts_query}) DESC") + .limit(SiteSetting.max_similar_results * 3) exclude_topic_ids = Category.pluck(:topic_id).compact! if exclude_topic_ids.present? @@ -462,16 +462,16 @@ class Topic < ActiveRecord::Base return [] unless candidate_ids.present? similar = Topic.select(sanitize_sql_array(["topics.*, similarity(topics.title, :title) + similarity(topics.title, :raw) AS similarity, p.cooked as blurb", title: title, raw: raw])) - .joins("JOIN posts AS p ON p.topic_id = topics.id AND p.post_number = 1") - .limit(SiteSetting.max_similar_results) - .where("topics.id IN (?)", candidate_ids) - .where("similarity(topics.title, :title) + similarity(topics.title, :raw) > 0.2", raw: raw, title: title) - .order('similarity desc') + .joins("JOIN posts AS p ON p.topic_id = topics.id AND p.post_number = 1") + .limit(SiteSetting.max_similar_results) + .where("topics.id IN (?)", candidate_ids) + .where("similarity(topics.title, :title) + similarity(topics.title, :raw) > 0.2", raw: raw, title: title) + .order('similarity desc') similar end - def update_status(status, enabled, user, opts={}) + def update_status(status, enabled, user, opts = {}) TopicStatusUpdater.new(self, user).update!(status, enabled, opts) DiscourseEvent.trigger(:topic_status_updated, self.id, status, enabled) end @@ -504,7 +504,6 @@ class Topic < ActiveRecord::Base end end - def self.reset_all_highest! exec_sql < 1 url @@ -927,7 +925,7 @@ SQL self.class.url id, slug, post_number end - def self.relative_url(id, slug, post_number=nil) + def self.relative_url(id, slug, post_number = nil) url = "#{Discourse.base_uri}/t/" url << "#{slug}/" if slug.present? url << id.to_s @@ -935,11 +933,11 @@ SQL url end - def slugless_url(post_number=nil) + def slugless_url(post_number = nil) Topic.relative_url(id, nil, post_number) end - def relative_url(post_number=nil) + def relative_url(post_number = nil) Topic.relative_url(id, slug, post_number) end @@ -957,7 +955,7 @@ SQL TopicUser.change(user.id, id, cleared_pinned_at: nil) end - def update_pinned(status, global=false, pinned_until=nil) + def update_pinned(status, global = false, pinned_until = nil) pinned_until = Time.parse(pinned_until) rescue nil update_columns( @@ -1136,7 +1134,7 @@ SQL ) t SQL - def self.time_to_first_response(sql, opts=nil) + def self.time_to_first_response(sql, opts = nil) opts ||= {} builder = SqlBuilder.new(sql) builder.where("t.created_at >= :start_date", start_date: opts[:start_date]) if opts[:start_date] @@ -1147,17 +1145,17 @@ SQL builder.where("p.deleted_at IS NULL") builder.where("p.post_number > 1") builder.where("p.user_id != t.user_id") - builder.where("p.user_id in (:user_ids)", {user_ids: opts[:user_ids]}) if opts[:user_ids] + builder.where("p.user_id in (:user_ids)", user_ids: opts[:user_ids]) if opts[:user_ids] builder.where("p.post_type = :post_type", post_type: Post.types[:regular]) builder.where("EXTRACT(EPOCH FROM p.created_at - t.created_at) > 0") builder.exec end - def self.time_to_first_response_per_day(start_date, end_date, opts={}) - time_to_first_response(TIME_TO_FIRST_RESPONSE_SQL, opts.merge({start_date: start_date, end_date: end_date})) + def self.time_to_first_response_per_day(start_date, end_date, opts = {}) + time_to_first_response(TIME_TO_FIRST_RESPONSE_SQL, opts.merge(start_date: start_date, end_date: end_date)) end - def self.time_to_first_response_total(opts=nil) + def self.time_to_first_response_total(opts = nil) total = time_to_first_response(TIME_TO_FIRST_RESPONSE_TOTAL_SQL, opts) total.first["hours"].to_f.round(2) end @@ -1176,7 +1174,7 @@ SQL ORDER BY tt.created_at SQL - def self.with_no_response_per_day(start_date, end_date, category_id=nil) + def self.with_no_response_per_day(start_date, end_date, category_id = nil) builder = SqlBuilder.new(WITH_NO_RESPONSE_SQL) builder.where("t.created_at >= :start_date", start_date: start_date) if start_date builder.where("t.created_at < :end_date", end_date: end_date) if end_date @@ -1198,7 +1196,7 @@ SQL WHERE tt.first_reply IS NULL OR tt.first_reply < 2 SQL - def self.with_no_response_total(opts={}) + def self.with_no_response_total(opts = {}) builder = SqlBuilder.new(WITH_NO_RESPONSE_TOTAL_SQL) builder.where("t.category_id = :category_id", category_id: opts[:category_id]) if opts[:category_id] builder.where("t.archetype <> '#{Archetype.private_message}'") @@ -1245,7 +1243,6 @@ SQL end - # == Schema Information # # Table name: topics diff --git a/app/models/topic_embed.rb b/app/models/topic_embed.rb index 0f1cc78f7d1..9904b05c989 100644 --- a/app/models/topic_embed.rb +++ b/app/models/topic_embed.rb @@ -113,7 +113,7 @@ class TopicEmbed < ActiveRecord::Base response.title = title doc = Nokogiri::HTML(read_doc.content) - tags = {'img' => 'src', 'script' => 'src', 'a' => 'href'} + tags = { 'img' => 'src', 'script' => 'src', 'a' => 'href' } doc.search(tags.keys.join(',')).each do |node| url_param = tags[node.name] src = node[url_param] @@ -132,7 +132,7 @@ class TopicEmbed < ActiveRecord::Base # only allow classes in the whitelist allowed_classes = if embed_classname_whitelist.blank? then [] else embed_classname_whitelist.split(/[ ,]+/i) end doc.search('[class]:not([class=""])').each do |classnode| - classes = classnode[:class].split(' ').select{ |classname| allowed_classes.include?(classname) } + classes = classnode[:class].split(' ').select { |classname| allowed_classes.include?(classname) } if classes.length === 0 classnode.delete('class') else @@ -145,7 +145,7 @@ class TopicEmbed < ActiveRecord::Base response end - def self.import_remote(import_user, url, opts=nil) + def self.import_remote(import_user, url, opts = nil) opts = opts || {} response = find_remote(url) response.title = opts[:title] if opts[:title].present? diff --git a/app/models/topic_featured_users.rb b/app/models/topic_featured_users.rb index f28c555b4ce..d3f705149be 100644 --- a/app/models/topic_featured_users.rb +++ b/app/models/topic_featured_users.rb @@ -10,7 +10,7 @@ class TopicFeaturedUsers end # Chooses which topic users to feature - def choose(args={}) + def choose(args = {}) self.class.ensure_consistency!(topic.id.to_i) update_participant_count end @@ -22,7 +22,7 @@ class TopicFeaturedUsers topic.featured_user4_id].uniq.compact end - def self.ensure_consistency!(topic_id=nil) + def self.ensure_consistency!(topic_id = nil) filter = "#{"AND t.id = #{topic_id.to_i}" if topic_id}" filter2 = "#{"AND tt.id = #{topic_id.to_i}" if topic_id}" diff --git a/app/models/topic_link.rb b/app/models/topic_link.rb index d7691db82d2..f5925960a27 100644 --- a/app/models/topic_link.rb +++ b/app/models/topic_link.rb @@ -67,7 +67,7 @@ SQL end - def self.counts_for(guardian,topic, posts) + def self.counts_for(guardian, topic, posts) return {} if posts.blank? # Sam: I don't know how to write this cleanly in AR, @@ -93,13 +93,13 @@ SQL builder.where('l.post_id IN (:post_ids)', post_ids: posts.map(&:id)) builder.secure_category(guardian.secure_category_ids) - builder.map_exec(OpenStruct).each_with_object({}) do |l,result| + builder.map_exec(OpenStruct).each_with_object({}) do |l, result| result[l.post_id] ||= [] - result[l.post_id] << {url: l.url, - clicks: l.clicks, - title: l.title, - internal: l.internal, - reflection: l.reflection} + result[l.post_id] << { url: l.url, + clicks: l.clicks, + title: l.title, + internal: l.internal, + reflection: l.reflection } end end @@ -189,14 +189,14 @@ SQL unless tl tl = TopicLink.create(user_id: post.user_id, - topic_id: topic_id, - post_id: reflected_post.try(:id), - url: reflected_url, - domain: Discourse.current_hostname, - reflection: true, - internal: true, - link_topic_id: post.topic_id, - link_post_id: post.id) + topic_id: topic_id, + post_id: reflected_post.try(:id), + url: reflected_url, + domain: Discourse.current_hostname, + reflection: true, + internal: true, + link_topic_id: post.topic_id, + link_post_id: post.id) end @@ -235,11 +235,11 @@ SQL def self.duplicate_lookup(topic) results = TopicLink - .includes(:post, :user) - .joins(:post, :user) - .where("posts.id IS NOT NULL AND users.id IS NOT NULL") - .where(topic_id: topic.id, reflection: false) - .last(200) + .includes(:post, :user) + .joins(:post, :user) + .where("posts.id IS NOT NULL AND users.id IS NOT NULL") + .where(topic_id: topic.id, reflection: false) + .last(200) lookup = {} results.each do |tl| diff --git a/app/models/topic_link_click.rb b/app/models/topic_link_click.rb index 6bd932c796f..825067384fa 100644 --- a/app/models/topic_link_click.rb +++ b/app/models/topic_link_click.rb @@ -12,7 +12,7 @@ class TopicLinkClick < ActiveRecord::Base WHITELISTED_REDIRECT_HOSTNAMES = Set.new(%W{www.youtube.com youtu.be}) # Create a click from a URL and post_id - def self.create_from(args={}) + def self.create_from(args = {}) url = args[:url][0...TopicLink.max_url_length] return nil if url.blank? @@ -31,7 +31,7 @@ class TopicLinkClick < ActiveRecord::Base query = url.index('?') unless query.nil? endpos = url.index('#') || url.size - urls << url[0..query-1] + url[endpos..-1] + urls << url[0..query - 1] + url[endpos..-1] end # add a cdn link diff --git a/app/models/topic_list.rb b/app/models/topic_list.rb index efa8089202b..375659dc5c8 100644 --- a/app/models/topic_list.rb +++ b/app/models/topic_list.rb @@ -22,7 +22,7 @@ class TopicList def self.preload(topics, object) if @preload - @preload.each{|preload| preload.call(topics, object)} + @preload.each { |preload| preload.call(topics, object) } end end @@ -37,7 +37,7 @@ class TopicList :tags, :current_user - def initialize(filter, current_user, topics, opts=nil) + def initialize(filter, current_user, topics, opts = nil) @filter = filter @current_user = current_user @topics_input = topics @@ -86,7 +86,7 @@ class TopicList # Include bookmarks if you have bookmarked topics if @current_user && !post_action_type - post_action_type = PostActionType.types[:bookmark] if @topic_lookup.any?{|_,tu| tu && tu.bookmarked} + post_action_type = PostActionType.types[:bookmark] if @topic_lookup.any? { |_, tu| tu && tu.bookmarked } end # Data for bookmarks or likes @@ -105,7 +105,7 @@ class TopicList ft.user_data = @topic_lookup[ft.id] if @topic_lookup.present? if ft.user_data && post_action_lookup && actions = post_action_lookup[ft.id] - ft.user_data.post_action_data = {post_action_type => actions} + ft.user_data.post_action_data = { post_action_type => actions } end ft.posters = ft.posters_summary( @@ -127,6 +127,6 @@ class TopicList end def attributes - {'more_topics_url' => page} + { 'more_topics_url' => page } end end diff --git a/app/models/topic_notifier.rb b/app/models/topic_notifier.rb index db30a8e471b..46d43c3755b 100644 --- a/app/models/topic_notifier.rb +++ b/app/models/topic_notifier.rb @@ -3,10 +3,10 @@ class TopicNotifier @topic = topic end - { :watch! => :watching, - :track! => :tracking, - :regular! => :regular, - :mute! => :muted }.each_pair do |method_name, level| + { watch!: :watching, + track!: :tracking, + regular!: :regular, + mute!: :muted }.each_pair do |method_name, level| define_method method_name do |user_id| change_level user_id, level @@ -34,8 +34,8 @@ class TopicNotifier @notification_levels ||= TopicUser.notification_levels end - def change_level(user_id, level, reason=nil) - attrs = {notification_level: levels[level]} + def change_level(user_id, level, reason = nil) + attrs = { notification_level: levels[level] } attrs.merge!(notifications_reason_id: TopicUser.notification_reasons[reason]) if reason TopicUser.change(user_id, @topic.id, attrs) end diff --git a/app/models/topic_posters_summary.rb b/app/models/topic_posters_summary.rb index 7723bf338cd..c6cf8255d57 100644 --- a/app/models/topic_posters_summary.rb +++ b/app/models/topic_posters_summary.rb @@ -40,7 +40,7 @@ class TopicPostersSummary def shuffle_last_poster_to_back_in(summary) unless last_poster_is_topic_creator? - summary.reject!{ |u| u.id == topic.last_post_user_id } + summary.reject! { |u| u.id == topic.last_post_user_id } summary << avatar_lookup[topic.last_post_user_id] end summary diff --git a/app/models/topic_tracking_state.rb b/app/models/topic_tracking_state.rb index ff30630353b..3c104f4fdb7 100644 --- a/app/models/topic_tracking_state.rb +++ b/app/models/topic_tracking_state.rb @@ -38,7 +38,7 @@ class TopicTrackingState publish_read(topic.id, 1, topic.user_id) end - def self.publish_latest(topic, staff_only=false) + def self.publish_latest(topic, staff_only = false) return unless topic.archetype == "regular" message = { @@ -73,9 +73,9 @@ class TopicTrackingState end TopicUser - .tracking(post.topic_id) - .select([:user_id,:last_read_post_number, :notification_level]) - .each do |tu| + .tracking(post.topic_id) + .select([:user_id, :last_read_post_number, :notification_level]) + .each do |tu| message = { topic_id: post.topic_id, @@ -125,7 +125,7 @@ class TopicTrackingState MessageBus.publish("/delete", message.as_json, group_ids: group_ids) end - def self.publish_read(topic_id, last_read_post_number, user_id, notification_level=nil) + def self.publish_read(topic_id, last_read_post_number, user_id, notification_level = nil) highest_post_number = Topic.where(id: topic_id).pluck(:highest_post_number).first @@ -179,8 +179,7 @@ class TopicTrackingState end - - def self.report_raw_sql(opts=nil) + def self.report_raw_sql(opts = nil) unread = if opts && opts[:skip_unread] @@ -205,7 +204,6 @@ class TopicTrackingState c.id AS category_id, tu.notification_level" - sql = <= :tracking", + .where("COALESCE(topic_users.notification_level, :regular) >= :tracking", regular: TopicUser.notification_levels[:regular], tracking: TopicUser.notification_levels[:tracking]) } @@ -159,22 +159,22 @@ SQL unless attrs[:notification_level] category_notification_level = CategoryUser.where(user_id: user_id) - .where("category_id IN (SELECT category_id FROM topics WHERE id = :id)", id: topic_id) - .where("notification_level IN (:levels)", levels: [CategoryUser.notification_levels[:watching], + .where("category_id IN (SELECT category_id FROM topics WHERE id = :id)", id: topic_id) + .where("notification_level IN (:levels)", levels: [CategoryUser.notification_levels[:watching], CategoryUser.notification_levels[:tracking]]) - .order("notification_level DESC") - .limit(1) - .pluck(:notification_level) - .first + .order("notification_level DESC") + .limit(1) + .pluck(:notification_level) + .first tag_notification_level = TagUser.where(user_id: user_id) - .where("tag_id IN (SELECT tag_id FROM topic_tags WHERE topic_id = :id)", id: topic_id) - .where("notification_level IN (:levels)", levels: [CategoryUser.notification_levels[:watching], + .where("tag_id IN (SELECT tag_id FROM topic_tags WHERE topic_id = :id)", id: topic_id) + .where("notification_level IN (:levels)", levels: [CategoryUser.notification_levels[:watching], CategoryUser.notification_levels[:tracking]]) - .order("notification_level DESC") - .limit(1) - .pluck(:notification_level) - .first + .order("notification_level DESC") + .limit(1) + .pluck(:notification_level) + .first if category_notification_level && !(tag_notification_level && (tag_notification_level > category_notification_level)) attrs[:notification_level] = category_notification_level @@ -191,7 +191,6 @@ SQL TopicUser.notification_reasons[:auto_track_tag] end - end unless attrs[:notification_level] @@ -203,7 +202,7 @@ SQL end end - TopicUser.create(attrs.merge!(user_id: user_id, topic_id: topic_id, first_visited_at: now ,last_visited_at: now)) + TopicUser.create(attrs.merge!(user_id: user_id, topic_id: topic_id, first_visited_at: now , last_visited_at: now)) end def track_visit!(topic_id, user_id) @@ -256,7 +255,7 @@ SQL INSERT_TOPIC_USER_SQL_STAFF = INSERT_TOPIC_USER_SQL.gsub("highest_post_number", "highest_staff_post_number") - def update_last_read(user, topic_id, post_number, msecs, opts={}) + def update_last_read(user, topic_id, post_number, msecs, opts = {}) return if post_number.blank? msecs = 0 if msecs.to_i < 0 @@ -276,11 +275,12 @@ SQL # ... user visited the topic but did not read the posts # # 86400000 = 1 day - rows = if user.staff? - exec_sql(UPDATE_TOPIC_USER_SQL_STAFF,args).values - else - exec_sql(UPDATE_TOPIC_USER_SQL,args).values - end + rows = + if user.staff? + exec_sql(UPDATE_TOPIC_USER_SQL_STAFF, args).values + else + exec_sql(UPDATE_TOPIC_USER_SQL, args).values + end if rows.length == 1 before = rows[0][1].to_i @@ -332,7 +332,7 @@ SQL end - def self.update_post_action_cache(opts={}) + def self.update_post_action_cache(opts = {}) user_id = opts[:user_id] post_id = opts[:post_id] topic_id = opts[:topic_id] @@ -412,7 +412,7 @@ SQL TopicUser.exec_sql(sql, user_id: user_id, count: count) end - def self.ensure_consistency!(topic_id=nil) + def self.ensure_consistency!(topic_id = nil) update_post_action_cache(topic_id: topic_id) # TODO this needs some reworking, when we mark stuff skipped diff --git a/app/models/topic_view_item.rb b/app/models/topic_view_item.rb index 2b6fa6b49ce..04b231fa9bf 100644 --- a/app/models/topic_view_item.rb +++ b/app/models/topic_view_item.rb @@ -6,7 +6,7 @@ class TopicViewItem < ActiveRecord::Base belongs_to :user validates_presence_of :topic_id, :ip_address, :viewed_at - def self.add(topic_id, ip, user_id=nil, at=nil, skip_redis=false) + 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 per ip at ||= Date.today redis_key = "view:#{topic_id}:#{at}" @@ -28,7 +28,6 @@ class TopicViewItem < ActiveRecord::Base /*where*/ )" - builder = SqlBuilder.new(sql) if !user_id diff --git a/app/models/translation_override.rb b/app/models/translation_override.rb index 6e73686f9b9..3cdff253b53 100644 --- a/app/models/translation_override.rb +++ b/app/models/translation_override.rb @@ -30,7 +30,7 @@ class TranslationOverride < ActiveRecord::Base def self.i18n_changed I18n.reload! - MessageBus.publish('/i18n-flush', { refresh: true }) + MessageBus.publish('/i18n-flush', refresh: true) end def check_interpolation_keys diff --git a/app/models/trust_level3_requirements.rb b/app/models/trust_level3_requirements.rb index 2579216f867..448f94e6729 100644 --- a/app/models/trust_level3_requirements.rb +++ b/app/models/trust_level3_requirements.rb @@ -130,11 +130,11 @@ class TrustLevel3Requirements def num_flagged_posts PostAction.with_deleted - .where(post_id: flagged_post_ids) - .where.not(user_id: @user.id) - .where.not(agreed_at: nil) - .pluck(:post_id) - .uniq.count + .where(post_id: flagged_post_ids) + .where.not(user_id: @user.id) + .where.not(agreed_at: nil) + .pluck(:post_id) + .uniq.count end def max_flagged_posts @@ -143,11 +143,11 @@ class TrustLevel3Requirements def num_flagged_by_users @_num_flagged_by_users ||= PostAction.with_deleted - .where(post_id: flagged_post_ids) - .where.not(user_id: @user.id) - .where.not(agreed_at: nil) - .pluck(:user_id) - .uniq.count + .where(post_id: flagged_post_ids) + .where.not(user_id: @user.id) + .where.not(agreed_at: nil) + .pluck(:user_id) + .uniq.count end def max_flagged_by_users @@ -194,13 +194,11 @@ class TrustLevel3Requirements (min_likes_received.to_f / 4.0).ceil end - def self.clear_cache $redis.del NUM_TOPICS_KEY $redis.del NUM_POSTS_KEY end - CACHE_DURATION = 1.day.seconds - 60 NUM_TOPICS_KEY = "tl3_num_topics" NUM_POSTS_KEY = "tl3_num_posts" @@ -223,8 +221,8 @@ class TrustLevel3Requirements def flagged_post_ids @_flagged_post_ids ||= @user.posts - .with_deleted - .where('created_at > ? AND (spam_count > 0 OR inappropriate_count > 0)', time_period.days.ago) - .pluck(:id) + .with_deleted + .where('created_at > ? AND (spam_count > 0 OR inappropriate_count > 0)', time_period.days.ago) + .pluck(:id) end end diff --git a/app/models/upload.rb b/app/models/upload.rb index 5e272846402..514748f2d7e 100644 --- a/app/models/upload.rb +++ b/app/models/upload.rb @@ -30,7 +30,7 @@ class Upload < ActiveRecord::Base thumbnail(width, height).present? end - def create_thumbnail!(width, height, crop=false) + def create_thumbnail!(width, height, crop = false) return unless SiteSetting.create_thumbnails? opts = { @@ -75,7 +75,7 @@ class Upload < ActiveRecord::Base Upload.find_by(url: url) end - def self.migrate_to_new_scheme(limit=nil) + def self.migrate_to_new_scheme(limit = nil) problems = [] if SiteSetting.migrate_to_new_scheme diff --git a/app/models/user.rb b/app/models/user.rb index f6af5defef8..61c7799127b 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -74,13 +74,13 @@ class User < ActiveRecord::Base has_many :acting_group_histories, dependent: :destroy, foreign_key: :acting_user_id, class_name: GroupHistory has_many :targeted_group_histories, dependent: :destroy, foreign_key: :target_user_id, class_name: GroupHistory - delegate :last_sent_email_address, :to => :email_logs + delegate :last_sent_email_address, to: :email_logs validates_presence_of :username validate :username_validator, if: :username_changed? validate :password_validator validates :name, user_full_name: true, if: :name_changed?, length: { maximum: 255 } - validates :ip_address, allowed_ip_address: {on: :create, message: :signup_not_allowed} + validates :ip_address, allowed_ip_address: { on: :create, message: :signup_not_allowed } validates :primary_email, presence: true, if: :should_validate_primary_email? validates_associated :primary_email, if: :should_validate_primary_email? @@ -240,13 +240,12 @@ class User < ActiveRecord::Base find_by(username_lower: username.downcase) end - def enqueue_welcome_message(message_type) return unless SiteSetting.send_welcome_message? Jobs.enqueue(:send_system_message, user_id: id, message_type: message_type) end - def change_username(new_username, actor=nil) + def change_username(new_username, actor = nil) UsernameChanger.change(self, new_username, actor) end @@ -273,7 +272,7 @@ class User < ActiveRecord::Base end # Approve this user - def approve(approved_by, send_mail=true) + def approve(approved_by, send_mail = true) self.approved = true if approved_by.is_a?(Integer) @@ -318,7 +317,7 @@ class User < ActiveRecord::Base n.user_id = :user_id AND NOT read" - User.exec_sql(sql, user_id: id, type: notification_type).getvalue(0,0).to_i + User.exec_sql(sql, user_id: id, type: notification_type).getvalue(0, 0).to_i end def unread_private_messages @@ -342,7 +341,7 @@ class User < ActiveRecord::Base User.exec_sql(sql, user_id: id, seen_notification_id: seen_notification_id, pm: Notification.types[:private_message]) - .getvalue(0,0).to_i + .getvalue(0, 0).to_i end end @@ -377,7 +376,6 @@ class User < ActiveRecord::Base notification = notifications.visible.order('notifications.id desc').first json = NotificationSerializer.new(notification).as_json if notification - sql = " SELECT * FROM ( SELECT n.id, n.read FROM notifications n @@ -404,18 +402,18 @@ class User < ActiveRecord::Base " recent = User.exec_sql(sql, user_id: id, - type: Notification.types[:private_message]).values.map do |id, read| + type: Notification.types[:private_message]).values.map do |id, read| [id.to_i, read == 't'.freeze] end MessageBus.publish("/notification/#{id}", - {unread_notifications: unread_notifications, - unread_private_messages: unread_private_messages, - total_unread_notifications: total_unread_notifications, - read_first_notification: read_first_notification?, - last_notification: json, - recent: recent, - seen_notification_id: seen_notification_id + { unread_notifications: unread_notifications, + unread_private_messages: unread_private_messages, + total_unread_notifications: total_unread_notifications, + read_first_notification: read_first_notification?, + last_notification: json, + recent: recent, + seen_notification_id: seen_notification_id }, user_ids: [id] # only publish the notification to this user ) @@ -475,7 +473,7 @@ class User < ActiveRecord::Base last_seen_at.present? end - def create_visit_record!(date, opts={}) + def create_visit_record!(date, opts = {}) user_stat.update_column(:days_visited, user_stat.days_visited + 1) user_visits.create!(visited_at: date, posts_read: opts[:posts_read] || 0, mobile: opts[:mobile] || false) end @@ -488,7 +486,7 @@ class User < ActiveRecord::Base create_visit_record!(date) unless visit_record_for(date) end - def update_posts_read!(num_posts, opts={}) + def update_posts_read!(num_posts, opts = {}) now = opts[:at] || Time.zone.now _retry = opts[:retry] || false @@ -502,7 +500,7 @@ class User < ActiveRecord::Base create_visit_record!(now.to_date, posts_read: num_posts, mobile: opts.fetch(:mobile, false)) rescue ActiveRecord::RecordNotUnique if !_retry - update_posts_read!(num_posts, opts.merge( retry: true )) + update_posts_read!(num_posts, opts.merge(retry: true)) else raise end @@ -516,7 +514,7 @@ class User < ActiveRecord::Base end end - def update_last_seen!(now=Time.zone.now) + def update_last_seen!(now = Time.zone.now) now_date = now.to_date # Only update last seen once every minute redis_key = "user:#{id}:#{now_date}" @@ -703,7 +701,7 @@ class User < ActiveRecord::Base save end - def change_trust_level!(level, opts=nil) + def change_trust_level!(level, opts = nil) Promotion.new(self).change_trust_level!(level, opts) end @@ -716,26 +714,26 @@ class User < ActiveRecord::Base user_badges.select('distinct badge_id').count end - def featured_user_badges(limit=3) + def featured_user_badges(limit = 3) tl_badge_ids = Badge.trust_level_badge_ids query = user_badges - .group(:badge_id) - .select(UserBadge.attribute_names.map { |x| "MAX(user_badges.#{x}) AS #{x}" }, + .group(:badge_id) + .select(UserBadge.attribute_names.map { |x| "MAX(user_badges.#{x}) AS #{x}" }, 'COUNT(*) AS "count"', 'MAX(badges.badge_type_id) AS badges_badge_type_id', 'MAX(badges.grant_count) AS badges_grant_count') - .joins(:badge) - .order('badges_badge_type_id ASC, badges_grant_count ASC, badge_id DESC') - .includes(:user, :granted_by, { badge: :badge_type }, { post: :topic }) + .joins(:badge) + .order('badges_badge_type_id ASC, badges_grant_count ASC, badge_id DESC') + .includes(:user, :granted_by, { badge: :badge_type }, post: :topic) tl_badge = query.where("user_badges.badge_id IN (:tl_badge_ids)", tl_badge_ids: tl_badge_ids) - .limit(1) + .limit(1) other_badges = query.where("user_badges.badge_id NOT IN (:tl_badge_ids)", tl_badge_ids: tl_badge_ids) - .limit(limit) + .limit(limit) (tl_badge + other_badges).take(limit) end @@ -750,7 +748,6 @@ class User < ActiveRecord::Base result.group('date(users.created_at)').order('date(users.created_at)').count end - def secure_category_ids cats = self.admin? ? Category.where(read_restricted: true) : secure_categories.references(:categories) cats.pluck('categories.id').sort @@ -760,16 +757,15 @@ class User < ActiveRecord::Base Category.topic_create_allowed(self.id).select(:id) end - # Flag all posts from a user as spam def flag_linked_posts_as_spam disagreed_flag_post_ids = PostAction.where(post_action_type_id: PostActionType.types[:spam]) - .where.not(disagreed_at: nil) - .pluck(:post_id) + .where.not(disagreed_at: nil) + .pluck(:post_id) topic_links.includes(:post) - .where.not(post_id: disagreed_flag_post_ids) - .each do |tl| + .where.not(post_id: disagreed_flag_post_ids) + .each do |tl| begin message = I18n.t('flag_reason.spam_hosts', domain: tl.domain) PostAction.act(Discourse.system_user, tl.post, PostActionType.types[:spam], message: message) @@ -812,7 +808,6 @@ class User < ActiveRecord::Base .exists? end - def refresh_avatar return if @import_mode @@ -868,25 +863,25 @@ class User < ActiveRecord::Base def number_of_deleted_posts Post.with_deleted - .where(user_id: self.id) - .where.not(deleted_at: nil) - .count + .where(user_id: self.id) + .where.not(deleted_at: nil) + .count end def number_of_flagged_posts Post.with_deleted - .where(user_id: self.id) - .where(id: PostAction.where(post_action_type_id: PostActionType.notify_flag_type_ids) + .where(user_id: self.id) + .where(id: PostAction.where(post_action_type_id: PostActionType.notify_flag_type_ids) .where(disagreed_at: nil) .select(:post_id)) - .count + .count end def number_of_flags_given PostAction.where(user_id: self.id) - .where(disagreed_at: nil) - .where(post_action_type_id: PostActionType.notify_flag_type_ids) - .count + .where(disagreed_at: nil) + .where(post_action_type_id: PostActionType.notify_flag_type_ids) + .count end def number_of_suspensions @@ -924,8 +919,8 @@ class User < ActiveRecord::Base return unless active && email_confirmed? && !staged Group.where(automatic: false) - .where("LENGTH(COALESCE(automatic_membership_email_domains, '')) > 0") - .each do |group| + .where("LENGTH(COALESCE(automatic_membership_email_domains, '')) > 0") + .each do |group| domains = group.automatic_membership_email_domains.gsub('.', '\.') @@ -1064,10 +1059,10 @@ class User < ActiveRecord::Base # Delete unactivated accounts (without verified email) that are over a week old def self.purge_unactivated to_destroy = User.where(active: false) - .joins('INNER JOIN user_stats AS us ON us.user_id = users.id') - .where("created_at < ?", SiteSetting.purge_unactivated_users_grace_period_days.days.ago) - .where('NOT admin AND NOT moderator') - .limit(200) + .joins('INNER JOIN user_stats AS us ON us.user_id = users.id') + .where("created_at < ?", SiteSetting.purge_unactivated_users_grace_period_days.days.ago) + .where('NOT admin AND NOT moderator') + .limit(200) destroyer = UserDestroyer.new(Discourse.system_user) to_destroy.each do |u| diff --git a/app/models/user_action.rb b/app/models/user_action.rb index 5e3599a381b..b65f207af36 100644 --- a/app/models/user_action.rb +++ b/app/models/user_action.rb @@ -11,7 +11,7 @@ class UserAction < ActiveRecord::Base BOOKMARK = 3 NEW_TOPIC = 4 REPLY = 5 - RESPONSE= 6 + RESPONSE = 6 MENTION = 7 QUOTE = 9 EDIT = 11 @@ -75,7 +75,7 @@ SQL apply_common_filters(builder, user_id, guardian) results = builder.exec.to_a - results.sort! { |a,b| ORDER[a.action_type] <=> ORDER[b.action_type] } + results.sort! { |a, b| ORDER[a.action_type] <=> ORDER[b.action_type] } results end @@ -109,10 +109,10 @@ SQL GROUP BY g.name SQL - result = { all: all, mine: mine, unread: unread} + result = { all: all, mine: mine, unread: unread } exec_sql(sql, user_id: user_id).each do |row| - (result[:groups] ||= []) << {name: row["name"], count: row["count"].to_i} + (result[:groups] ||= []) << { name: row["name"], count: row["count"].to_i } end result @@ -123,7 +123,7 @@ SQL stream(action_id: action_id, guardian: guardian).first end - def self.stream_queued(opts=nil) + def self.stream_queued(opts = nil) opts ||= {} offset = opts[:offset] || 0 @@ -156,7 +156,7 @@ SQL .map_exec(UserActionRow) end - def self.stream(opts=nil) + def self.stream(opts = nil) opts ||= {} action_types = opts[:action_types] @@ -276,7 +276,7 @@ SQL require_parameters(hash, :action_type, :user_id, :acting_user_id, :target_topic_id, :target_post_id) if action = UserAction.find_by(hash.except(:created_at)) action.destroy - MessageBus.publish("/user/#{hash[:user_id]}", {user_action_id: action.id, remove: true}) + MessageBus.publish("/user/#{hash[:user_id]}", user_action_id: action.id, remove: true) end if !Topic.where(id: hash[:target_topic_id], archetype: Archetype.private_message).exists? @@ -331,7 +331,7 @@ SQL end end - def self.apply_common_filters(builder,user_id,guardian,ignore_private_messages=false) + def self.apply_common_filters(builder, user_id, guardian, ignore_private_messages = false) # We never return deleted topics in activity builder.where("t.deleted_at is null") @@ -341,7 +341,7 @@ SQL current_user_id = -2 current_user_id = guardian.user.id if guardian.user - builder.where("NOT COALESCE(p.hidden, false) OR p.user_id = :current_user_id", current_user_id: current_user_id ) + builder.where("NOT COALESCE(p.hidden, false) OR p.user_id = :current_user_id", current_user_id: current_user_id) end visible_post_types = Topic.visible_post_types(guardian.user) @@ -381,7 +381,7 @@ SQL if allowed.present? builder.where("( c.read_restricted IS NULL OR NOT c.read_restricted OR - (c.read_restricted and c.id in (:cats)) )", cats: guardian.secure_category_ids ) + (c.read_restricted and c.id in (:cats)) )", cats: guardian.secure_category_ids) else builder.where("(c.read_restricted IS NULL OR NOT c.read_restricted)") end diff --git a/app/models/user_api_key.rb b/app/models/user_api_key.rb index be0e85b7f8a..39f8d4a80f9 100644 --- a/app/models/user_api_key.rb +++ b/app/models/user_api_key.rb @@ -30,7 +30,7 @@ class UserApiKey < ActiveRecord::Base # not a rails route, special handling return true if action == "message_bus" && env["PATH_INFO"] =~ /^\/message-bus\/.*\/poll/ - params = env['action_dispatch.request.path_parameters'] + params = env['action_dispatch.request.path_parameters'] return false unless params diff --git a/app/models/user_archived_message.rb b/app/models/user_archived_message.rb index 1cb45c81654..36c3ccd1ac4 100644 --- a/app/models/user_archived_message.rb +++ b/app/models/user_archived_message.rb @@ -11,21 +11,21 @@ class UserArchivedMessage < ActiveRecord::Base UserArchivedMessage.where(user_id: user_id, topic_id: topic_id).destroy_all trigger(:move_to_inbox, user_id, topic_id) - MessageBus.publish("/topic/#{topic_id}", {type: "move_to_inbox"}, user_ids: [user_id]) + MessageBus.publish("/topic/#{topic_id}", { type: "move_to_inbox" }, user_ids: [user_id]) end def self.archive!(user_id, topic_id) UserArchivedMessage.where(user_id: user_id, topic_id: topic_id).destroy_all UserArchivedMessage.create!(user_id: user_id, topic_id: topic_id) trigger(:archive_message, user_id, topic_id) - MessageBus.publish("/topic/#{topic_id}", {type: "archived"}, user_ids: [user_id]) + MessageBus.publish("/topic/#{topic_id}", { type: "archived" }, user_ids: [user_id]) end def self.trigger(event, user_id, topic_id) user = User.find_by(id: user_id) topic = Topic.find_by(id: topic_id) if user && topic - DiscourseEvent.trigger(event, {user: user, topic: topic}) + DiscourseEvent.trigger(event, user: user, topic: topic) end end end diff --git a/app/models/user_auth_token.rb b/app/models/user_auth_token.rb index 7a22ea5931c..5597d523679 100644 --- a/app/models/user_auth_token.rb +++ b/app/models/user_auth_token.rb @@ -40,7 +40,7 @@ class UserAuthToken < ActiveRecord::Base user_auth_token end - def self.lookup(unhashed_token, opts=nil) + def self.lookup(unhashed_token, opts = nil) mark_seen = opts && opts[:seen] @@ -123,7 +123,7 @@ class UserAuthToken < ActiveRecord::Base end - def rotate!(info=nil) + def rotate!(info = nil) user_agent = (info && info[:user_agent] || self.user_agent) client_ip = (info && info[:client_ip] || self.client_ip) diff --git a/app/models/user_avatar.rb b/app/models/user_avatar.rb index 0c49693ddbf..8e9de17baf1 100644 --- a/app/models/user_avatar.rb +++ b/app/models/user_avatar.rb @@ -67,7 +67,7 @@ class UserAvatar < ActiveRecord::Base "#{upload_id}_#{OptimizedImage::VERSION}" end - def self.import_url_for_user(avatar_url, user, options=nil) + def self.import_url_for_user(avatar_url, user, options = nil) tempfile = FileHelper.download( avatar_url, max_file_size: SiteSetting.max_image_size_kb.kilobytes, diff --git a/app/models/user_badge.rb b/app/models/user_badge.rb index a50bf1be726..f7b8b55569c 100644 --- a/app/models/user_badge.rb +++ b/app/models/user_badge.rb @@ -5,7 +5,7 @@ class UserBadge < ActiveRecord::Base belongs_to :notification, dependent: :destroy belongs_to :post - validates :badge_id, presence: true, uniqueness: {scope: :user_id}, if: 'badge.single_grant?' + validates :badge_id, presence: true, uniqueness: { scope: :user_id }, if: 'badge.single_grant?' validates :user_id, presence: true validates :granted_at, presence: true validates :granted_by, presence: true diff --git a/app/models/user_badges.rb b/app/models/user_badges.rb index 187ee1bc9f8..bd68c4c037b 100644 --- a/app/models/user_badges.rb +++ b/app/models/user_badges.rb @@ -4,7 +4,7 @@ class UserBadges attr_accessor :user_badges, :username, :grant_count - def initialize(opts={}) + def initialize(opts = {}) @user_badges = opts[:user_badges] @username = opts[:username] @grant_count = opts[:grant_count] diff --git a/app/models/user_email.rb b/app/models/user_email.rb index d97077c20a9..b67a6cd3ca9 100644 --- a/app/models/user_email.rb +++ b/app/models/user_email.rb @@ -8,7 +8,7 @@ class UserEmail < ActiveRecord::Base validates :email, presence: true, uniqueness: true validates :email, email: true, format: { with: EmailValidator.email_regex }, - if: :skip_email_validation? + if: :skip_email_validation? validates :primary, uniqueness: { scope: [:user_id] } diff --git a/app/models/user_history.rb b/app/models/user_history.rb index e177cd8de4a..c1665874684 100644 --- a/app/models/user_history.rb +++ b/app/models/user_history.rb @@ -11,7 +11,7 @@ class UserHistory < ActiveRecord::Base validates_presence_of :action - scope :only_staff_actions, ->{ where("action IN (?)", UserHistory.staff_action_ids) } + scope :only_staff_actions, -> { where("action IN (?)", UserHistory.staff_action_ids) } before_save :set_admin_only @@ -121,7 +121,7 @@ class UserHistory < ActiveRecord::Base query = query.where(custom_type: filters[:custom_type]) if filters[:custom_type].present? [:acting_user, :target_user].each do |key| - if filters[key] and obj_id = User.where(username_lower: filters[key].downcase).pluck(:id) + if filters[key] && (obj_id = User.where(username_lower: filters[key].downcase).pluck(:id)) query = query.where("#{key}_id = ?", obj_id) end end @@ -133,7 +133,7 @@ class UserHistory < ActiveRecord::Base self.where(target_user_id: user.id, action: UserHistory.actions[action_type]) end - def self.exists_for_user?(user, action_type, opts=nil) + def self.exists_for_user?(user, action_type, opts = nil) opts = opts || {} result = self.where(target_user_id: user.id, action: UserHistory.actions[action_type]) result = result.where(topic_id: opts[:topic_id]) if opts[:topic_id] @@ -144,14 +144,13 @@ class UserHistory < ActiveRecord::Base [:action_id, :custom_type, :acting_user, :target_user, :subject] end - def self.staff_action_records(viewer, opts=nil) + def self.staff_action_records(viewer, opts = nil) opts ||= {} query = self.with_filters(opts.slice(*staff_filters)).only_staff_actions.limit(200).order('id DESC').includes(:acting_user, :target_user) query = query.where(admin_only: false) unless viewer && viewer.admin? query end - def set_admin_only self.admin_only = UserHistory.admin_only_action_ids.include?(self.action) self diff --git a/app/models/user_option.rb b/app/models/user_option.rb index 551380335dd..ee46d5b77e1 100644 --- a/app/models/user_option.rb +++ b/app/models/user_option.rb @@ -8,7 +8,7 @@ class UserOption < ActiveRecord::Base def self.ensure_consistency! exec_sql("SELECT u.id FROM users u LEFT JOIN user_options o ON o.user_id = u.id - WHERE o.user_id IS NULL").values.each do |id,_| + WHERE o.user_id IS NULL").values.each do |id, _| UserOption.create(user_id: id.to_i) end end @@ -94,7 +94,6 @@ class UserOption < ActiveRecord::Base # top must be in the top_menu return unless SiteSetting.top_menu =~ /(^|\|)top(\||$)/i - # not enough topics return unless period = SiteSetting.min_redirected_to_top_period(1.days.ago) @@ -118,14 +117,18 @@ class UserOption < ActiveRecord::Base def treat_as_new_topic_start_date duration = new_topic_duration_minutes || SiteSetting.default_other_new_topic_duration_minutes.to_i - times = [case duration + times = [ + case duration when User::NewTopicDuration::ALWAYS user.created_at when User::NewTopicDuration::LAST_VISIT user.previous_visit_at || user.user_stat.new_since else duration.minutes.ago - end, user.user_stat.new_since, Time.at(SiteSetting.min_new_topics_time).to_datetime] + end, + user.user_stat.new_since, + Time.at(SiteSetting.min_new_topics_time).to_datetime + ] times.max end diff --git a/app/models/user_profile.rb b/app/models/user_profile.rb index a6ceec48584..8ce2d186d4a 100644 --- a/app/models/user_profile.rb +++ b/app/models/user_profile.rb @@ -19,7 +19,7 @@ class UserProfile < ActiveRecord::Base BAKED_VERSION = 1 - def bio_excerpt(length=350, opts={}) + def bio_excerpt(length = 350, opts = {}) excerpt = PrettyText.excerpt(bio_cooked, length, opts).sub(/
$/, '') return excerpt if excerpt.blank? || (user.has_trust_level?(TrustLevel[1]) && !user.suspended?) PrettyText.strip_links(excerpt) @@ -63,11 +63,11 @@ class UserProfile < ActiveRecord::Base def self.rebake_old(limit) problems = [] UserProfile.where('bio_cooked_version IS NULL OR bio_cooked_version < ?', BAKED_VERSION) - .limit(limit).each do |p| + .limit(limit).each do |p| begin p.rebake! rescue => e - problems << {profile: p, ex: e} + problems << { profile: p, ex: e } end end problems diff --git a/app/models/user_profile_view.rb b/app/models/user_profile_view.rb index efe43cd42e1..716b26c07c3 100644 --- a/app/models/user_profile_view.rb +++ b/app/models/user_profile_view.rb @@ -3,7 +3,7 @@ class UserProfileView < ActiveRecord::Base belongs_to :user_profile - def self.add(user_profile_id, ip, user_id=nil, at=nil, skip_redis=false) + def self.add(user_profile_id, ip, user_id = nil, at = nil, skip_redis = false) at ||= Time.zone.now redis_key = "user-profile-view:#{user_profile_id}:#{at.to_date}" if user_id @@ -41,7 +41,7 @@ class UserProfileView < ActiveRecord::Base end end - def self.profile_views_by_day(start_date, end_date, group_id=nil) + def self.profile_views_by_day(start_date, end_date, group_id = nil) profile_views = self.where("viewed_at >= ? AND viewed_at < ?", start_date, end_date + 1.day) if group_id profile_views = profile_views.joins("INNER JOIN users ON users.id = user_profile_views.user_id") diff --git a/app/models/user_search.rb b/app/models/user_search.rb index 9b6c02c6ac8..6fe2db9b22c 100644 --- a/app/models/user_search.rb +++ b/app/models/user_search.rb @@ -3,7 +3,7 @@ require_dependency 'search' class UserSearch - def initialize(term, opts={}) + def initialize(term, opts = {}) @term = term @term_like = "#{term.downcase.gsub("_", "\\_")}%" @topic_id = opts[:topic_id] @@ -34,8 +34,8 @@ class UserSearch if topic.category && topic.category.read_restricted users = users.includes(:secure_categories) - .where("users.admin = TRUE OR categories.id = ?", topic.category.id) - .references(:categories) + .where("users.admin = TRUE OR categories.id = ?", topic.category.id) + .references(:categories) end end @@ -50,9 +50,9 @@ class UserSearch query = Search.ts_query(@term, "simple") users = users.includes(:user_search_data) - .references(:user_search_data) - .where("user_search_data.search_data @@ #{query}") - .order(User.sql_fragment("CASE WHEN username_lower LIKE ? THEN 0 ELSE 1 END ASC", @term_like)) + .references(:user_search_data) + .where("user_search_data.search_data @@ #{query}") + .order(User.sql_fragment("CASE WHEN username_lower LIKE ? THEN 0 ELSE 1 END ASC", @term_like)) else users = users.where("username_lower LIKE :term_like", term_like: @term_like) @@ -68,9 +68,9 @@ class UserSearch # 1. exact username matches if @term.present? scoped_users.where(username_lower: @term.downcase) - .limit(@limit) - .pluck(:id) - .each { |id| users << id } + .limit(@limit) + .pluck(:id) + .each { |id| users << id } end @@ -79,19 +79,19 @@ class UserSearch # 2. in topic if @topic_id filtered_by_term_users.where('users.id IN (SELECT p.user_id FROM posts p WHERE topic_id = ?)', @topic_id) - .order('last_seen_at DESC') - .limit(@limit - users.length) - .pluck(:id) - .each { |id| users << id } + .order('last_seen_at DESC') + .limit(@limit - users.length) + .pluck(:id) + .each { |id| users << id } end return users.to_a if users.length >= @limit # 3. global matches filtered_by_term_users.order('last_seen_at DESC') - .limit(@limit - users.length) - .pluck(:id) - .each { |id| users << id } + .limit(@limit - users.length) + .pluck(:id) + .each { |id| users << id } users.to_a end @@ -103,7 +103,7 @@ class UserSearch User.joins("JOIN (SELECT unnest uid, row_number() OVER () AS rn FROM unnest('{#{ids.join(",")}}'::int[]) ) x on uid = users.id") - .order("rn") + .order("rn") end end diff --git a/app/models/user_stat.rb b/app/models/user_stat.rb index 50761737e3f..51ca626c3ae 100644 --- a/app/models/user_stat.rb +++ b/app/models/user_stat.rb @@ -10,8 +10,8 @@ class UserStat < ActiveRecord::Base def self.reset_bounce_scores UserStat.where("reset_bounce_score_after < now()") - .where("bounce_score > 0") - .update_all(bounce_score: 0) + .where("bounce_score > 0") + .update_all(bounce_score: 0) end # Updates the denormalized view counts for all users @@ -55,14 +55,14 @@ class UserStat < ActiveRecord::Base def update_topic_reply_count self.topic_reply_count = Topic - .where(['id in ( + .where(['id in ( SELECT topic_id FROM posts p JOIN topics t2 ON t2.id = p.topic_id WHERE p.deleted_at IS NULL AND t2.user_id <> p.user_id AND p.user_id = ? )', self.user_id]) - .count + .count end MAX_TIME_READ_DIFF = 100 diff --git a/app/models/user_summary.rb b/app/models/user_summary.rb index abfc9b8f514..0cf714cfac0 100644 --- a/app/models/user_summary.rb +++ b/app/models/user_summary.rb @@ -53,18 +53,18 @@ class UserSummary def most_liked_by_users likers = {} UserAction.joins(:target_topic, :target_post) - .merge(Topic.listable_topics.visible.secured(@guardian)) - .where(user: @user) - .where(action_type: UserAction::WAS_LIKED) - .group(:acting_user_id) - .order('COUNT(*) DESC') - .limit(MAX_SUMMARY_RESULTS) - .pluck('acting_user_id, COUNT(*)') - .each { |l| likers[l[0].to_s] = l[1] } + .merge(Topic.listable_topics.visible.secured(@guardian)) + .where(user: @user) + .where(action_type: UserAction::WAS_LIKED) + .group(:acting_user_id) + .order('COUNT(*) DESC') + .limit(MAX_SUMMARY_RESULTS) + .pluck('acting_user_id, COUNT(*)') + .each { |l| likers[l[0].to_s] = l[1] } User.where(id: likers.keys) - .pluck(:id, :username, :name, :uploaded_avatar_id) - .map do |u| + .pluck(:id, :username, :name, :uploaded_avatar_id) + .map do |u| UserWithCount.new( id: u[0], username: u[1], @@ -78,18 +78,18 @@ class UserSummary def most_liked_users liked_users = {} UserAction.joins(:target_topic, :target_post) - .merge(Topic.listable_topics.visible.secured(@guardian)) - .where(action_type: UserAction::WAS_LIKED) - .where(acting_user_id: @user.id) - .group(:user_id) - .order('COUNT(*) DESC') - .limit(MAX_SUMMARY_RESULTS) - .pluck('user_actions.user_id, COUNT(*)') - .each { |l| liked_users[l[0].to_s] = l[1] } + .merge(Topic.listable_topics.visible.secured(@guardian)) + .where(action_type: UserAction::WAS_LIKED) + .where(acting_user_id: @user.id) + .group(:user_id) + .order('COUNT(*) DESC') + .limit(MAX_SUMMARY_RESULTS) + .pluck('user_actions.user_id, COUNT(*)') + .each { |l| liked_users[l[0].to_s] = l[1] } User.where(id: liked_users.keys) - .pluck(:id, :username, :name, :uploaded_avatar_id) - .map do |u| + .pluck(:id, :username, :name, :uploaded_avatar_id) + .map do |u| UserWithCount.new( id: u[0], username: u[1], @@ -120,8 +120,8 @@ class UserSummary .each { |r| replied_users[r[0].to_s] = r[1] } User.where(id: replied_users.keys) - .pluck(:id, :username, :name, :uploaded_avatar_id) - .map do |u| + .pluck(:id, :username, :name, :uploaded_avatar_id) + .map do |u| UserWithCount.new( id: u[0], username: u[1], diff --git a/app/models/user_visit.rb b/app/models/user_visit.rb index 5ebe059167b..63734ef207b 100644 --- a/app/models/user_visit.rb +++ b/app/models/user_visit.rb @@ -1,6 +1,6 @@ class UserVisit < ActiveRecord::Base - def self.counts_by_day_query(start_date, end_date, group_id=nil) + def self.counts_by_day_query(start_date, end_date, group_id = nil) result = where('visited_at >= ? and visited_at <= ?', start_date.to_date, end_date.to_date) if group_id @@ -12,11 +12,11 @@ class UserVisit < ActiveRecord::Base end # A count of visits in a date range by day - def self.by_day(start_date, end_date, group_id=nil) + def self.by_day(start_date, end_date, group_id = nil) counts_by_day_query(start_date, end_date, group_id).count end - def self.mobile_by_day(start_date, end_date, group_id=nil) + def self.mobile_by_day(start_date, end_date, group_id = nil) counts_by_day_query(start_date, end_date, group_id).where(mobile: true).count end diff --git a/app/models/watched_word.rb b/app/models/watched_word.rb index d9cbd4edc19..a0cc43e867a 100644 --- a/app/models/watched_word.rb +++ b/app/models/watched_word.rb @@ -30,7 +30,6 @@ class WatchedWord < ActiveRecord::Base scope :by_action, -> { order("action ASC, word ASC") } - def self.normalize_word(w) w.strip.downcase.squeeze('*') end diff --git a/app/models/web_hook.rb b/app/models/web_hook.rb index 40fed09de63..e3335e02043 100644 --- a/app/models/web_hook.rb +++ b/app/models/web_hook.rb @@ -30,8 +30,8 @@ class WebHook < ActiveRecord::Base def self.find_by_type(type) WebHook.where(active: true) - .joins(:web_hook_event_types) - .where("web_hooks.wildcard_web_hook = ? OR web_hook_event_types.name = ?", true, type.to_s) + .joins(:web_hook_event_types) + .where("web_hooks.wildcard_web_hook = ? OR web_hook_event_types.name = ?", true, type.to_s) end def self.enqueue_hooks(type, opts = {}) @@ -40,11 +40,11 @@ class WebHook < ActiveRecord::Base end end - def self.enqueue_topic_hooks(event, topic, user=nil) + def self.enqueue_topic_hooks(event, topic, user = nil) WebHook.enqueue_hooks(:topic, topic_id: topic.id, category_id: topic&.category_id, event_name: event.to_s) end - def self.enqueue_post_hooks(event, post, user=nil) + def self.enqueue_post_hooks(event, post, user = nil) WebHook.enqueue_hooks(:post, post_id: post.id, category_id: post&.topic&.category_id, event_name: event.to_s) end end diff --git a/app/models/web_hook_event.rb b/app/models/web_hook_event.rb index f10b5cde316..0626c7fecc5 100644 --- a/app/models/web_hook_event.rb +++ b/app/models/web_hook_event.rb @@ -6,12 +6,14 @@ class WebHookEvent < ActiveRecord::Base default_scope { order('created_at DESC') } def update_web_hook_delivery_status - web_hook.last_delivery_status = case status - when 200..299 - WebHook.last_delivery_statuses[:successful] - else - WebHook.last_delivery_statuses[:failed] - end + web_hook.last_delivery_status = + case status + when 200..299 + WebHook.last_delivery_statuses[:successful] + else + WebHook.last_delivery_statuses[:failed] + end + web_hook.save! end end diff --git a/app/serializers/admin_badge_serializer.rb b/app/serializers/admin_badge_serializer.rb index 535d27d1bdf..4f57896d90e 100644 --- a/app/serializers/admin_badge_serializer.rb +++ b/app/serializers/admin_badge_serializer.rb @@ -2,6 +2,6 @@ class AdminBadgeSerializer < BadgeSerializer attributes :query, :trigger, :target_posts, :auto_revoke, :show_posts def include_long_description? - true + true end end diff --git a/app/serializers/admin_user_action_serializer.rb b/app/serializers/admin_user_action_serializer.rb index 0cc58aa27a6..dfe2cbc6314 100644 --- a/app/serializers/admin_user_action_serializer.rb +++ b/app/serializers/admin_user_action_serializer.rb @@ -75,8 +75,8 @@ class AdminUserActionSerializer < ApplicationSerializer def action_type object.user_actions.select { |ua| ua.user_id = object.user_id } - .select { |ua| [UserAction::REPLY, UserAction::RESPONSE].include? ua.action_type } - .first.try(:action_type) + .select { |ua| [UserAction::REPLY, UserAction::RESPONSE].include? ua.action_type } + .first.try(:action_type) end private diff --git a/app/serializers/category_and_topic_lists_serializer.rb b/app/serializers/category_and_topic_lists_serializer.rb index 239bc079819..173b417d463 100644 --- a/app/serializers/category_and_topic_lists_serializer.rb +++ b/app/serializers/category_and_topic_lists_serializer.rb @@ -5,7 +5,7 @@ class CategoryAndTopicListsSerializer < ApplicationSerializer def users users = object.topic_list.topics.map do |t| - t.posters.map{|poster| poster.try(:user)} + t.posters.map { |poster| poster.try(:user) } end users.flatten! users.compact! diff --git a/app/serializers/category_serializer.rb b/app/serializers/category_serializer.rb index f482dd7e13d..dae914fc6dc 100644 --- a/app/serializers/category_serializer.rb +++ b/app/serializers/category_serializer.rb @@ -35,7 +35,7 @@ class CategorySerializer < BasicCategorySerializer end def available_groups - Group.order(:name).pluck(:name) - group_permissions.map{|g| g[:group_name]} + Group.order(:name).pluck(:name) - group_permissions.map { |g| g[:group_name] } end def can_delete @@ -44,7 +44,7 @@ class CategorySerializer < BasicCategorySerializer def include_is_special? [SiteSetting.meta_category_id, SiteSetting.staff_category_id, SiteSetting.uncategorized_category_id] - .include? object.id + .include? object.id end def is_special @@ -76,7 +76,7 @@ class CategorySerializer < BasicCategorySerializer end def notification_level - user = scope && scope.user + user = scope && scope.user object.notification_level || (user && CategoryUser.where(user: user, category: object).first.try(:notification_level)) end diff --git a/app/serializers/current_user_serializer.rb b/app/serializers/current_user_serializer.rb index 80de2e205c7..a02c99d02b5 100644 --- a/app/serializers/current_user_serializer.rb +++ b/app/serializers/current_user_serializer.rb @@ -137,7 +137,7 @@ class CurrentUserSerializer < BasicUserSerializer def muted_category_ids @muted_category_ids ||= CategoryUser.where(user_id: object.id, notification_level: TopicUser.notification_levels[:muted]) - .pluck(:category_id) + .pluck(:category_id) end def dismissed_banner_key diff --git a/app/serializers/detailed_user_badge_serializer.rb b/app/serializers/detailed_user_badge_serializer.rb index 1fa408844df..b32f72b6b85 100644 --- a/app/serializers/detailed_user_badge_serializer.rb +++ b/app/serializers/detailed_user_badge_serializer.rb @@ -10,7 +10,6 @@ class DetailedUserBadgeSerializer < BasicUserBadgeSerializer alias :include_topic_id? :include_post_number? alias :include_topic_title? :include_post_number? - def post_number object.post.post_number if object.post end diff --git a/app/serializers/post_action_type_serializer.rb b/app/serializers/post_action_type_serializer.rb index 4e66641105d..e0bf6f7c971 100644 --- a/app/serializers/post_action_type_serializer.rb +++ b/app/serializers/post_action_type_serializer.rb @@ -8,7 +8,7 @@ class PostActionTypeSerializer < ApplicationSerializer def is_custom_flag object.id == PostActionType.types[:notify_user] || - object.id == PostActionType.types[:notify_moderators] + object.id == PostActionType.types[:notify_moderators] end def name @@ -20,16 +20,16 @@ class PostActionTypeSerializer < ApplicationSerializer end def description - i18n('description', {tos_url: tos_path}) + i18n('description', tos_url: tos_path) end def short_description - i18n('short_description', {tos_url: tos_path}) + i18n('short_description', tos_url: tos_path) end protected - def i18n(field, vars=nil) + def i18n(field, vars = nil) key = "post_action_types.#{object.name_key}.#{field}" vars ? I18n.t(key, vars) : I18n.t(key) end diff --git a/app/serializers/post_item_excerpt.rb b/app/serializers/post_item_excerpt.rb index be74db9bdf9..7f0cc6322b2 100644 --- a/app/serializers/post_item_excerpt.rb +++ b/app/serializers/post_item_excerpt.rb @@ -22,4 +22,3 @@ module PostItemExcerpt end end - diff --git a/app/serializers/post_revision_serializer.rb b/app/serializers/post_revision_serializer.rb index 5c1a05f603e..11b13677f4e 100644 --- a/app/serializers/post_revision_serializer.rb +++ b/app/serializers/post_revision_serializer.rb @@ -27,7 +27,6 @@ class PostRevisionSerializer < ApplicationSerializer :wiki, :can_edit - # Creates a field called field_name_changes with previous and # current members if a field has changed in this revision def self.add_compared_field(field) @@ -59,8 +58,8 @@ class PostRevisionSerializer < ApplicationSerializer def previous_revision @previous_revision ||= revisions.select { |r| r["revision"] >= first_revision } - .select { |r| r["revision"] < current_revision } - .last.try(:[], "revision") + .select { |r| r["revision"] < current_revision } + .last.try(:[], "revision") end def current_revision @@ -69,8 +68,8 @@ class PostRevisionSerializer < ApplicationSerializer def next_revision @next_revision ||= revisions.select { |r| r["revision"] <= last_revision } - .select { |r| r["revision"] > current_revision } - .first.try(:[], "revision") + .select { |r| r["revision"] > current_revision } + .first.try(:[], "revision") end def last_revision diff --git a/app/serializers/site_serializer.rb b/app/serializers/site_serializer.rb index 1b474185336..ecd93e02ae9 100644 --- a/app/serializers/site_serializer.rb +++ b/app/serializers/site_serializer.rb @@ -37,16 +37,16 @@ class SiteSerializer < ApplicationSerializer cache_fragment("user_themes") do Theme.where('key = :default OR user_selectable', default: SiteSetting.default_theme_key) - .order(:name) - .pluck(:key, :name) - .map{|k,n| {theme_key: k, name: n, default: k == SiteSetting.default_theme_key}} - .as_json + .order(:name) + .pluck(:key, :name) + .map { |k, n| { theme_key: k, name: n, default: k == SiteSetting.default_theme_key } } + .as_json end end def groups cache_fragment("group_names") do - Group.order(:name).pluck(:id,:name).map { |id,name| { id: id, name: name } }.as_json + Group.order(:name).pluck(:id, :name).map { |id, name| { id: id, name: name } }.as_json end end diff --git a/app/serializers/site_text_serializer.rb b/app/serializers/site_text_serializer.rb index c686a080087..f0e3c1e4c3e 100644 --- a/app/serializers/site_text_serializer.rb +++ b/app/serializers/site_text_serializer.rb @@ -19,4 +19,3 @@ class SiteTextSerializer < ApplicationSerializer alias_method :can_revert?, :overridden? end - diff --git a/app/serializers/topic_flag_type_serializer.rb b/app/serializers/topic_flag_type_serializer.rb index a764d1a8209..ee81618448b 100644 --- a/app/serializers/topic_flag_type_serializer.rb +++ b/app/serializers/topic_flag_type_serializer.rb @@ -2,9 +2,9 @@ class TopicFlagTypeSerializer < PostActionTypeSerializer protected - def i18n(field, vars=nil) + def i18n(field, vars = nil) key = "topic_flag_types.#{object.name_key}.#{field}" - vars ? I18n.t(key,vars) : I18n.t(key) + vars ? I18n.t(key, vars) : I18n.t(key) end end diff --git a/app/serializers/topic_view_serializer.rb b/app/serializers/topic_view_serializer.rb index 23682bd629c..49be96b8c7e 100644 --- a/app/serializers/topic_view_serializer.rb +++ b/app/serializers/topic_view_serializer.rb @@ -90,7 +90,7 @@ class TopicViewSerializer < ApplicationSerializer if object.post_counts_by_user.present? result[:participants] = object.post_counts_by_user.map do |pc| - TopicPostCountSerializer.new({user: object.participants[pc[0]], post_count: pc[1]}, scope: scope, root: false) + TopicPostCountSerializer.new({ user: object.participants[pc[0]], post_count: pc[1] }, scope: scope, root: false) end end @@ -220,7 +220,7 @@ class TopicViewSerializer < ApplicationSerializer result << { id: id, count: 0, hidden: false, - can_act: scope.post_can_act?(post, sym)} + can_act: scope.post_can_act?(post, sym) } # TODO: other keys? :can_defer_flags, :acted, :can_undo end result diff --git a/app/serializers/user_action_serializer.rb b/app/serializers/user_action_serializer.rb index 81b2cb2fe60..c6abea6a5ce 100644 --- a/app/serializers/user_action_serializer.rb +++ b/app/serializers/user_action_serializer.rb @@ -31,7 +31,6 @@ class UserActionSerializer < ApplicationSerializer :closed, :archived - def avatar_template User.avatar_template(object.username, object.uploaded_avatar_id) end diff --git a/app/serializers/user_option_serializer.rb b/app/serializers/user_option_serializer.rb index a6a7caeb236..b8253b40d78 100644 --- a/app/serializers/user_option_serializer.rb +++ b/app/serializers/user_option_serializer.rb @@ -22,7 +22,6 @@ class UserOptionSerializer < ApplicationSerializer :theme_key, :theme_key_seq - def auto_track_topics_after_msecs object.auto_track_topics_after_msecs || SiteSetting.default_other_auto_track_topics_after_msecs end diff --git a/app/serializers/user_serializer.rb b/app/serializers/user_serializer.rb index 0e75983daf4..f41f7629488 100644 --- a/app/serializers/user_serializer.rb +++ b/app/serializers/user_serializer.rb @@ -125,12 +125,12 @@ class UserSerializer < BasicUserSerializer def mailing_list_posts_per_day val = Post.estimate_posts_per_day - [val,SiteSetting.max_emails_per_day_per_user].min + [val, SiteSetting.max_emails_per_day_per_user].min end def groups object.groups.order(:id) - .visible_groups(scope.user) + .visible_groups(scope.user) end def group_users @@ -145,13 +145,12 @@ class UserSerializer < BasicUserSerializer !(SiteSetting.enable_sso && SiteSetting.sso_overrides_bio) end - def user_api_keys keys = object.user_api_keys.where(revoked_at: nil).map do |k| { id: k.id, application_name: k.application_name, - scopes: k.scopes.map{|s| I18n.t("user_api_key.scopes.#{s}")}, + scopes: k.scopes.map { |s| I18n.t("user_api_key.scopes.#{s}") }, created_at: k.created_at } end @@ -178,7 +177,7 @@ class UserSerializer < BasicUserSerializer def website_name uri = URI(website.to_s) rescue nil return if uri.nil? || uri.host.nil? - uri.host.sub(/^www\./,'') + uri.path + uri.host.sub(/^www\./, '') + uri.path end def include_website_name @@ -248,7 +247,7 @@ class UserSerializer < BasicUserSerializer end def bio_excerpt - object.user_profile.bio_excerpt(350 , { keep_newlines: true, keep_emoji_images: true }) + object.user_profile.bio_excerpt(350 , keep_newlines: true, keep_emoji_images: true) end def include_suspend_reason? diff --git a/app/services/badge_granter.rb b/app/services/badge_granter.rb index cfde16aa135..f76ab063e8e 100644 --- a/app/services/badge_granter.rb +++ b/app/services/badge_granter.rb @@ -1,17 +1,17 @@ class BadgeGranter - def initialize(badge, user, opts={}) + def initialize(badge, user, opts = {}) @badge, @user, @opts = badge, user, opts @granted_by = opts[:granted_by] || Discourse.system_user @post_id = opts[:post_id] end - def self.grant(badge, user, opts={}) + def self.grant(badge, user, opts = {}) BadgeGranter.new(badge, user, opts).grant end def grant - return if @granted_by and !Guardian.new(@granted_by).can_grant_badges?(@user) + return if @granted_by && !Guardian.new(@granted_by).can_grant_badges?(@user) return unless @badge.enabled? find_by = { badge_id: @badge.id, user_id: @user.id } @@ -51,7 +51,7 @@ class BadgeGranter data: { badge_id: @badge.id, badge_name: @badge.display_name, badge_slug: @badge.slug, - username: @user.username}.to_json + username: @user.username }.to_json ) user_badge.update_attributes notification_id: notification.id end @@ -63,7 +63,7 @@ class BadgeGranter user_badge end - def self.revoke(user_badge, options={}) + def self.revoke(user_badge, options = {}) UserBadge.transaction do user_badge.destroy! if options[:revoked_by] @@ -178,7 +178,7 @@ class BadgeGranter # :trigger - the Badge::Trigger id # :explain - return the EXPLAIN query def self.preview(sql, opts = {}) - params = {user_ids: [], post_ids: [], backfill: true} + params = { user_ids: [], post_ids: [], backfill: true } BadgeGranter.contract_checks!(sql, opts) @@ -188,19 +188,19 @@ class BadgeGranter grants_sql = if opts[:target_posts] - "SELECT u.id, u.username, q.post_id, t.title, q.granted_at - FROM(#{sql}) q - JOIN users u on u.id = q.user_id - LEFT JOIN badge_posts p on p.id = q.post_id - LEFT JOIN topics t on t.id = p.topic_id - WHERE :backfill = :backfill - LIMIT 10" + "SELECT u.id, u.username, q.post_id, t.title, q.granted_at + FROM(#{sql}) q + JOIN users u on u.id = q.user_id + LEFT JOIN badge_posts p on p.id = q.post_id + LEFT JOIN topics t on t.id = p.topic_id + WHERE :backfill = :backfill + LIMIT 10" else - "SELECT u.id, u.username, q.granted_at - FROM(#{sql}) q - JOIN users u on u.id = q.user_id - WHERE :backfill = :backfill - LIMIT 10" + "SELECT u.id, u.username, q.granted_at + FROM(#{sql}) q + JOIN users u on u.id = q.user_id + WHERE :backfill = :backfill + LIMIT 10" end query_plan = nil @@ -218,13 +218,13 @@ class BadgeGranter end end - {grant_count: grant_count, sample: sample, query_plan: query_plan} + { grant_count: grant_count, sample: sample, query_plan: query_plan } rescue => e - {errors: e.message} + { errors: e.message } end MAX_ITEMS_FOR_DELTA ||= 200 - def self.backfill(badge, opts=nil) + def self.backfill(badge, opts = nil) return unless SiteSetting.enable_badges return unless badge.enabled return unless badge.query.present? @@ -304,14 +304,15 @@ class BadgeGranter user_ids: user_ids || [-2]).each do |row| # old bronze badges do not matter - next if badge.badge_type_id == BadgeType::Bronze and row.granted_at < 2.days.ago + next if badge.badge_type_id == (BadgeType::Bronze) && row.granted_at < (2.days.ago) # Try to use user locale in the badge notification if possible without too much resources - notification_locale = if SiteSetting.allow_user_locale && row.locale.present? - row.locale - else - SiteSetting.default_locale - end + notification_locale = + if SiteSetting.allow_user_locale && row.locale.present? + row.locale + else + SiteSetting.default_locale + end # Make this variable in this scope notification = nil @@ -327,7 +328,7 @@ class BadgeGranter badge_name: badge.display_name, badge_slug: badge.slug, username: row.username - }.to_json ) + }.to_json) end Badge.exec_sql("UPDATE user_badges SET notification_id = :notification_id WHERE id = :id", diff --git a/app/services/color_scheme_revisor.rb b/app/services/color_scheme_revisor.rb index ce66c37332d..1fec2875f50 100644 --- a/app/services/color_scheme_revisor.rb +++ b/app/services/color_scheme_revisor.rb @@ -1,6 +1,6 @@ class ColorSchemeRevisor - def initialize(color_scheme, params={}) + def initialize(color_scheme, params = {}) @color_scheme = color_scheme @params = params end @@ -12,7 +12,7 @@ class ColorSchemeRevisor def revise ColorScheme.transaction do - @color_scheme.name = @params[:name] if @params.has_key?(:name) + @color_scheme.name = @params[:name] if @params.has_key?(:name) @color_scheme.base_scheme_id = @params[:base_scheme_id] if @params.has_key?(:base_scheme_id) has_colors = @params[:colors] diff --git a/app/services/group_message.rb b/app/services/group_message.rb index 16e18ddbb87..4e5a55f99a4 100644 --- a/app/services/group_message.rb +++ b/app/services/group_message.rb @@ -16,11 +16,11 @@ class GroupMessage include Rails.application.routes.url_helpers - def self.create(group_name, message_type, opts={}) + def self.create(group_name, message_type, opts = {}) GroupMessage.new(group_name, message_type, opts).create end - def initialize(group_name, message_type, opts={}) + def initialize(group_name, message_type, opts = {}) @group_name = group_name @message_type = message_type @opts = opts @@ -47,10 +47,8 @@ class GroupMessage @message_params ||= begin h = { base_url: Discourse.base_url }.merge(@opts[:message_params] || {}) if @opts[:user] - h.merge!({ - username: @opts[:user].username, - user_url: user_path(@opts[:user].username) - }) + h.merge!(username: @opts[:user].username, + user_url: user_path(@opts[:user].username)) end h end diff --git a/app/services/handle_chunk_upload.rb b/app/services/handle_chunk_upload.rb index c71a656dad8..de5bf7837de 100644 --- a/app/services/handle_chunk_upload.rb +++ b/app/services/handle_chunk_upload.rb @@ -1,6 +1,6 @@ class HandleChunkUpload - def initialize(chunk, params={}) + def initialize(chunk, params = {}) @chunk = chunk @params = params end diff --git a/app/services/notification_emailer.rb b/app/services/notification_emailer.rb index 534d4037a13..bdbc5d7d35e 100644 --- a/app/services/notification_emailer.rb +++ b/app/services/notification_emailer.rb @@ -66,12 +66,12 @@ class NotificationEmailer EMAILABLE_POST_TYPES ||= Set.new [Post.types[:regular], Post.types[:whisper]] - def enqueue(type, delay=default_delay) + def enqueue(type, delay = default_delay) return unless notification.user.user_option.email_direct? perform_enqueue(type, delay) end - def enqueue_private(type, delay=private_delay) + def enqueue_private(type, delay = private_delay) return unless notification.user.user_option.email_private_messages? perform_enqueue(type, delay) end diff --git a/app/services/post_alerter.rb b/app/services/post_alerter.rb index e43ea3ed9d1..130eec12850 100644 --- a/app/services/post_alerter.rb +++ b/app/services/post_alerter.rb @@ -48,11 +48,11 @@ class PostAlerter if post.last_editor_id != post.user_id # Mention comes from an edit by someone else, so notification should say who added the mention. editor = post.last_editor - mentioned_opts = {user_id: editor.id, original_username: editor.username, display_username: editor.username} + mentioned_opts = { user_id: editor.id, original_username: editor.username, display_username: editor.username } end expand_group_mentions(mentioned_groups, post) do |group, users| - notify_non_pm_users(users - notified, :group_mentioned, post, mentioned_opts.merge({group: group})) + notify_non_pm_users(users - notified, :group_mentioned, post, mentioned_opts.merge(group: group)) notified += users end @@ -122,17 +122,17 @@ class PostAlerter if topic.present? cat_watchers = topic.category_users - .where(notification_level: CategoryUser.notification_levels[:watching_first_post]) - .pluck(:user_id) + .where(notification_level: CategoryUser.notification_levels[:watching_first_post]) + .pluck(:user_id) tag_watchers = topic.tag_users - .where(notification_level: TagUser.notification_levels[:watching_first_post]) - .pluck(:user_id) + .where(notification_level: TagUser.notification_levels[:watching_first_post]) + .pluck(:user_id) group_ids = topic.allowed_groups.pluck(:group_id) group_watchers = GroupUser.where(group_id: group_ids, notification_level: GroupUser.notification_levels[:watching_first_post]) - .pluck(:user_id) + .pluck(:user_id) watchers = [cat_watchers, tag_watchers, group_watchers].flatten @@ -167,17 +167,17 @@ class PostAlerter def unread_posts(user, topic) Post.secured(Guardian.new(user)) - .where('post_number > COALESCE(( + .where('post_number > COALESCE(( SELECT last_read_post_number FROM topic_users tu WHERE tu.user_id = ? AND tu.topic_id = ? ),0)', user.id, topic.id) - .where('reply_to_user_id = ? OR exists( + .where('reply_to_user_id = ? OR exists( SELECT 1 from topic_users tu WHERE tu.user_id = ? AND tu.topic_id = ? AND notification_level = ? )', user.id, user.id, topic.id, TopicUser.notification_levels[:watching]) - .where(topic_id: topic.id) + .where(topic_id: topic.id) end def first_unread_post(user, topic) @@ -198,7 +198,7 @@ class PostAlerter user.reload end - NOTIFIABLE_TYPES = [:mentioned, :replied, :quoted, :posted, :linked, :private_message, :group_mentioned].map{ |t| + NOTIFIABLE_TYPES = [:mentioned, :replied, :quoted, :posted, :linked, :private_message, :group_mentioned].map { |t| Notification.types[t] } @@ -217,18 +217,18 @@ class PostAlerter end end - def notify_group_summary(user,post) + def notify_group_summary(user, post) @group_stats ||= {} stats = (@group_stats[post.topic_id] ||= group_stats(post.topic)) return unless stats group_id = post.topic - .topic_allowed_groups - .where(group_id: user.groups.pluck(:id)) - .pluck(:group_id).first + .topic_allowed_groups + .where(group_id: user.groups.pluck(:id)) + .pluck(:group_id).first - stat = stats.find{|s| s[:group_id] == group_id} + stat = stats.find { |s| s[:group_id] == group_id } return unless stat && stat[:inbox_count] > 0 notification_type = Notification.types[:group_message_summary] @@ -297,9 +297,9 @@ class PostAlerter # apply muting here return if notifier_id && MutedUser.where(user_id: user.id, muted_user_id: notifier_id) - .joins(:muted_user) - .where('NOT admin AND NOT moderator') - .exists? + .joins(:muted_user) + .where('NOT admin AND NOT moderator') + .exists? # skip if muted on the topic return if TopicUser.where( @@ -319,10 +319,10 @@ class PostAlerter # Don't notify the same user about the same notification on the same post existing_notification = user.notifications - .order("notifications.id DESC") - .find_by(topic_id: post.topic_id, - post_number: post.post_number, - notification_type: type) + .order("notifications.id DESC") + .find_by(topic_id: post.topic_id, + post_number: post.post_number, + notification_type: type) return if existing_notification && !should_notify_previous?(user, existing_notification, opts) @@ -376,13 +376,11 @@ class PostAlerter end end - notification_data.merge!({ - topic_title: topic_title, - original_post_id: original_post.id, - original_post_type: original_post.post_type, - original_username: original_username, - display_username: opts[:display_username] || post.user.username - }) + notification_data.merge!(topic_title: topic_title, + original_post_id: original_post.id, + original_post_type: original_post.post_type, + original_username: original_username, + display_username: opts[:display_username] || post.user.username) if group = opts[:group] notification_data[:group_id] = group.id @@ -401,15 +399,15 @@ class PostAlerter # we may have an invalid post somehow, dont blow up post_url = original_post.url rescue nil if post_url - payload = { - notification_type: type, - post_number: original_post.post_number, - topic_title: original_post.topic.title, - topic_id: original_post.topic.id, - excerpt: original_post.excerpt(400, text_entities: true, strip_links: true, remap_emoji: true), - username: original_username, - post_url: post_url - } + payload = { + notification_type: type, + post_number: original_post.post_number, + topic_title: original_post.topic.title, + topic_id: original_post.topic.id, + excerpt: original_post.excerpt(400, text_entities: true, strip_links: true, remap_emoji: true), + username: original_username, + post_url: post_url + } MessageBus.publish("/notification-alert/#{user.id}", payload, user_ids: [user.id]) push_notification(user, payload) @@ -422,9 +420,9 @@ class PostAlerter def push_notification(user, payload) if SiteSetting.allow_user_api_key_scopes.split("|").include?("push") && SiteSetting.allowed_user_api_push_urls.present? clients = user.user_api_keys - .where("('push' = ANY(scopes) OR 'notifications' = ANY(scopes)) AND push_url IS NOT NULL AND position(push_url in ?) > 0 AND revoked_at IS NULL", + .where("('push' = ANY(scopes) OR 'notifications' = ANY(scopes)) AND push_url IS NOT NULL AND position(push_url in ?) > 0 AND revoked_at IS NULL", SiteSetting.allowed_user_api_push_urls) - .pluck(:client_id, :push_url) + .pluck(:client_id, :push_url) if clients.length > 0 Jobs.enqueue(:push_notification, clients: clients, payload: payload, user_id: user.id) @@ -458,7 +456,6 @@ class PostAlerter [groups, users] end - # TODO: Move to post-analyzer? # Returns a list of users who were quoted in the post def extract_quoted_users(post) @@ -530,7 +527,6 @@ SQL exclude_user_ids = notified.map(&:id) notify = notify.where("id NOT IN (?)", exclude_user_ids) if exclude_user_ids.present? - DiscourseEvent.trigger(:before_create_notifications_for_users, notify, post) notify.each do |user| create_notification(user, Notification.types[:posted], post) diff --git a/app/services/random_topic_selector.rb b/app/services/random_topic_selector.rb index 9446c4fcbb3..f19b1a17187 100644 --- a/app/services/random_topic_selector.rb +++ b/app/services/random_topic_selector.rb @@ -3,7 +3,7 @@ class RandomTopicSelector BACKFILL_SIZE = 3000 BACKFILL_LOW_WATER_MARK = 500 - def self.backfill(category=nil) + def self.backfill(category = nil) exclude = category.try(:topic_id) # don't leak private categories into the "everything" group @@ -20,13 +20,12 @@ class RandomTopicSelector query = TopicQuery.new(user, options) - results = query.latest_results.order('RANDOM()') - .where(closed: false, archived: false) - .where("topics.created_at > ?", SiteSetting.suggested_topics_max_days_old.days.ago) - .limit(BACKFILL_SIZE) - .reorder('RANDOM()') - .pluck(:id) + .where(closed: false, archived: false) + .where("topics.created_at > ?", SiteSetting.suggested_topics_max_days_old.days.ago) + .limit(BACKFILL_SIZE) + .reorder('RANDOM()') + .pluck(:id) key = cache_key(category) results.each do |id| @@ -37,7 +36,7 @@ class RandomTopicSelector results end - def self.next(count, category=nil) + def self.next(count, category = nil) key = cache_key(category) results = [] @@ -45,12 +44,12 @@ class RandomTopicSelector return results if count < 1 results = $redis.multi do - $redis.lrange(key, 0, count-1) + $redis.lrange(key, 0, count - 1) $redis.ltrim(key, count, -1) end if !results.is_a?(Array) # Redis is in readonly mode - results = $redis.lrange(key, 0, count-1) + results = $redis.lrange(key, 0, count - 1) else results = results[0] end @@ -77,7 +76,7 @@ class RandomTopicSelector results end - def self.cache_key(category=nil) + def self.cache_key(category = nil) "random_topic_cache_#{category.try(:id)}" end diff --git a/app/services/search_indexer.rb b/app/services/search_indexer.rb index 72e526a301e..6eb92412863 100644 --- a/app/services/search_indexer.rb +++ b/app/services/search_indexer.rb @@ -110,7 +110,6 @@ class SearchIndexer end end - class HtmlScrubber < Nokogiri::XML::SAX::Document attr_reader :scrubbed @@ -130,7 +129,7 @@ class SearchIndexer me.scrubbed end - def start_element(name, attributes=[]) + def start_element(name, attributes = []) attributes = Hash[*attributes.flatten] if attributes["alt"] scrubbed << " " diff --git a/app/services/spam_rule/auto_block.rb b/app/services/spam_rule/auto_block.rb index a44ac9a115a..03bb1bf67c3 100644 --- a/app/services/spam_rule/auto_block.rb +++ b/app/services/spam_rule/auto_block.rb @@ -21,17 +21,17 @@ class SpamRule::AutoBlock return false if @user.staged? return false if @user.has_trust_level?(TrustLevel[1]) - if SiteSetting.num_spam_flags_to_block_new_user > 0 and - SiteSetting.num_users_to_block_new_user > 0 and - num_spam_flags_against_user >= SiteSetting.num_spam_flags_to_block_new_user and - num_users_who_flagged_spam_against_user >= SiteSetting.num_users_to_block_new_user + if SiteSetting.num_spam_flags_to_block_new_user > (0) && + SiteSetting.num_users_to_block_new_user > (0) && + num_spam_flags_against_user >= (SiteSetting.num_spam_flags_to_block_new_user) && + num_users_who_flagged_spam_against_user >= (SiteSetting.num_users_to_block_new_user) return true end - if SiteSetting.num_tl3_flags_to_block_new_user > 0 and - SiteSetting.num_tl3_users_to_block_new_user > 0 and - num_tl3_flags_against_user >= SiteSetting.num_tl3_flags_to_block_new_user and - num_tl3_users_who_flagged >= SiteSetting.num_tl3_users_to_block_new_user + if SiteSetting.num_tl3_flags_to_block_new_user > (0) && + SiteSetting.num_tl3_users_to_block_new_user > (0) && + num_tl3_flags_against_user >= (SiteSetting.num_tl3_flags_to_block_new_user) && + num_tl3_users_who_flagged >= (SiteSetting.num_tl3_users_to_block_new_user) return true end @@ -66,14 +66,14 @@ class SpamRule::AutoBlock def flagged_post_ids Post.where(user_id: @user.id) - .where('spam_count > ? OR off_topic_count > ? OR inappropriate_count > ?', 0, 0, 0) - .pluck(:id) + .where('spam_count > ? OR off_topic_count > ? OR inappropriate_count > ?', 0, 0, 0) + .pluck(:id) end def block_user Post.transaction do if UserBlocker.block(@user, Discourse.system_user, message: :too_many_spam_flags) && SiteSetting.notify_mods_when_user_blocked - GroupMessage.create(Group[:moderators].name, :user_automatically_blocked, {user: @user, limit_once_per: false}) + GroupMessage.create(Group[:moderators].name, :user_automatically_blocked, user: @user, limit_once_per: false) end end end diff --git a/app/services/staff_action_logger.rb b/app/services/staff_action_logger.rb index 1cd09176af4..b58ff9093ed 100644 --- a/app/services/staff_action_logger.rb +++ b/app/services/staff_action_logger.rb @@ -10,16 +10,14 @@ class StaffActionLogger raise Discourse::InvalidParameters.new(:admin) unless @admin && @admin.is_a?(User) end - def log_user_deletion(deleted_user, opts={}) + def log_user_deletion(deleted_user, opts = {}) raise Discourse::InvalidParameters.new(:deleted_user) unless deleted_user && deleted_user.is_a?(User) - UserHistory.create( params(opts).merge({ - action: UserHistory.actions[:delete_user], - ip_address: deleted_user.ip_address.to_s, - details: [:id, :username, :name, :created_at, :trust_level, :last_seen_at, :last_emailed_at].map { |x| "#{x}: #{deleted_user.send(x)}" }.join("\n") - })) + UserHistory.create(params(opts).merge(action: UserHistory.actions[:delete_user], + ip_address: deleted_user.ip_address.to_s, + details: [:id, :username, :name, :created_at, :trust_level, :last_seen_at, :last_emailed_at].map { |x| "#{x}: #{deleted_user.send(x)}" }.join("\n"))) end - def log_custom(custom_type, details=nil) + def log_custom(custom_type, details = nil) raise Discourse::InvalidParameters.new(:custom_type) unless custom_type details ||= {} @@ -28,7 +26,7 @@ class StaffActionLogger StaffActionLogger.base_attrs.each do |attr| attrs[attr] = details.delete(attr) if details.has_key?(attr) end - attrs[:details] = details.map {|r| "#{r[0]}: #{r[1]}"}.join("\n") + attrs[:details] = details.map { |r| "#{r[0]}: #{r[1]}" }.join("\n") attrs[:acting_user_id] = @admin.id attrs[:action] = UserHistory.actions[:custom_staff] attrs[:custom_type] = custom_type @@ -36,7 +34,7 @@ class StaffActionLogger UserHistory.create(attrs) end - def log_post_deletion(deleted_post, opts={}) + def log_post_deletion(deleted_post, opts = {}) raise Discourse::InvalidParameters.new(:deleted_post) unless deleted_post && deleted_post.is_a?(Post) topic = deleted_post.topic || Topic.with_deleted.find_by(id: deleted_post.topic_id) @@ -54,14 +52,12 @@ class StaffActionLogger "raw: #{deleted_post.raw}" ] - UserHistory.create(params(opts).merge({ - action: UserHistory.actions[:delete_post], - post_id: deleted_post.id, - details: details.join("\n") - })) + UserHistory.create(params(opts).merge(action: UserHistory.actions[:delete_post], + post_id: deleted_post.id, + details: details.join("\n"))) end - def log_topic_deletion(deleted_topic, opts={}) + def log_topic_deletion(deleted_topic, opts = {}) raise Discourse::InvalidParameters.new(:deleted_topic) unless deleted_topic && deleted_topic.is_a?(Topic) user = deleted_topic.user ? "#{deleted_topic.user.username} (#{deleted_topic.user.name})" : "(deleted user)" @@ -77,48 +73,40 @@ class StaffActionLogger details << "raw: #{first_post.raw}" end - UserHistory.create(params(opts).merge({ - action: UserHistory.actions[:delete_topic], - topic_id: deleted_topic.id, - details: details.join("\n") - })) + UserHistory.create(params(opts).merge(action: UserHistory.actions[:delete_topic], + topic_id: deleted_topic.id, + details: details.join("\n"))) end - def log_trust_level_change(user, old_trust_level, new_trust_level, opts={}) + def log_trust_level_change(user, old_trust_level, new_trust_level, opts = {}) raise Discourse::InvalidParameters.new(:user) unless user && user.is_a?(User) raise Discourse::InvalidParameters.new(:old_trust_level) unless TrustLevel.valid? old_trust_level raise Discourse::InvalidParameters.new(:new_trust_level) unless TrustLevel.valid? new_trust_level - UserHistory.create!( params(opts).merge({ - action: UserHistory.actions[:change_trust_level], - target_user_id: user.id, - details: "old trust level: #{old_trust_level}\nnew trust level: #{new_trust_level}" - })) + UserHistory.create!(params(opts).merge(action: UserHistory.actions[:change_trust_level], + target_user_id: user.id, + details: "old trust level: #{old_trust_level}\nnew trust level: #{new_trust_level}")) end - def log_lock_trust_level(user, opts={}) + def log_lock_trust_level(user, opts = {}) raise Discourse::InvalidParameters.new(:user) unless user && user.is_a?(User) - UserHistory.create!( params(opts).merge({ - action: UserHistory.actions[user.trust_level_locked ? :lock_trust_level : :unlock_trust_level], - target_user_id: user.id - })) + UserHistory.create!(params(opts).merge(action: UserHistory.actions[user.trust_level_locked ? :lock_trust_level : :unlock_trust_level], + target_user_id: user.id)) end - def log_site_setting_change(setting_name, previous_value, new_value, opts={}) + def log_site_setting_change(setting_name, previous_value, new_value, opts = {}) raise Discourse::InvalidParameters.new(:setting_name) unless setting_name.present? && SiteSetting.respond_to?(setting_name) - UserHistory.create( params(opts).merge({ - action: UserHistory.actions[:change_site_setting], - subject: setting_name, - previous_value: previous_value, - new_value: new_value - })) + UserHistory.create(params(opts).merge(action: UserHistory.actions[:change_site_setting], + subject: setting_name, + previous_value: previous_value, + new_value: new_value)) end def theme_json(theme) - ThemeSerializer.new(theme, root:false).to_json + ThemeSerializer.new(theme, root: false).to_json end - def strip_duplicates(old,cur) - return [old,cur] unless old && cur + def strip_duplicates(old, cur) + return [old, cur] unless old && cur old = JSON.parse(old) cur = JSON.parse(cur) @@ -135,144 +123,116 @@ class StaffActionLogger [old.to_json, cur.to_json] end - def log_theme_change(old_json, new_theme, opts={}) + def log_theme_change(old_json, new_theme, opts = {}) raise Discourse::InvalidParameters.new(:new_theme) unless new_theme new_json = theme_json(new_theme) - old_json,new_json = strip_duplicates(old_json,new_json) + old_json, new_json = strip_duplicates(old_json, new_json) - UserHistory.create( params(opts).merge({ - action: UserHistory.actions[:change_theme], - subject: new_theme.name, - previous_value: old_json, - new_value: new_json - })) + UserHistory.create(params(opts).merge(action: UserHistory.actions[:change_theme], + subject: new_theme.name, + previous_value: old_json, + new_value: new_json)) end - def log_theme_destroy(theme, opts={}) + def log_theme_destroy(theme, opts = {}) raise Discourse::InvalidParameters.new(:theme) unless theme - UserHistory.create( params(opts).merge({ - action: UserHistory.actions[:delete_theme], - subject: theme.name, - previous_value: theme_json(theme) - })) + UserHistory.create(params(opts).merge(action: UserHistory.actions[:delete_theme], + subject: theme.name, + previous_value: theme_json(theme))) end - def log_site_text_change(subject, new_text=nil, old_text=nil, opts={}) + def log_site_text_change(subject, new_text = nil, old_text = nil, opts = {}) raise Discourse::InvalidParameters.new(:subject) unless subject.present? - UserHistory.create!( params(opts).merge({ - action: UserHistory.actions[:change_site_text], - subject: subject, - previous_value: old_text, - new_value: new_text - })) + UserHistory.create!(params(opts).merge(action: UserHistory.actions[:change_site_text], + subject: subject, + previous_value: old_text, + new_value: new_text)) end - def log_username_change(user, old_username, new_username, opts={}) + def log_username_change(user, old_username, new_username, opts = {}) raise Discourse::InvalidParameters.new(:user) unless user - UserHistory.create( params(opts).merge({ - action: UserHistory.actions[:change_username], - target_user_id: user.id, - previous_value: old_username, - new_value: new_username - })) + UserHistory.create(params(opts).merge(action: UserHistory.actions[:change_username], + target_user_id: user.id, + previous_value: old_username, + new_value: new_username)) end - def log_name_change(user_id, old_name, new_name, opts={}) + def log_name_change(user_id, old_name, new_name, opts = {}) raise Discourse::InvalidParameters.new(:user) unless user_id - UserHistory.create( params(opts).merge({ - action: UserHistory.actions[:change_name], - target_user_id: user_id, - previous_value: old_name, - new_value: new_name - })) + UserHistory.create(params(opts).merge(action: UserHistory.actions[:change_name], + target_user_id: user_id, + previous_value: old_name, + new_value: new_name)) end - def log_user_suspend(user, reason, opts={}) + def log_user_suspend(user, reason, opts = {}) raise Discourse::InvalidParameters.new(:user) unless user - UserHistory.create( params(opts).merge({ - action: UserHistory.actions[:suspend_user], - target_user_id: user.id, - details: reason - })) + UserHistory.create(params(opts).merge(action: UserHistory.actions[:suspend_user], + target_user_id: user.id, + details: reason)) end - def log_user_unsuspend(user, opts={}) + def log_user_unsuspend(user, opts = {}) raise Discourse::InvalidParameters.new(:user) unless user - UserHistory.create( params(opts).merge({ - action: UserHistory.actions[:unsuspend_user], - target_user_id: user.id - })) + UserHistory.create(params(opts).merge(action: UserHistory.actions[:unsuspend_user], + target_user_id: user.id)) end - def log_badge_grant(user_badge, opts={}) + def log_badge_grant(user_badge, opts = {}) raise Discourse::InvalidParameters.new(:user_badge) unless user_badge - UserHistory.create( params(opts).merge({ - action: UserHistory.actions[:grant_badge], - target_user_id: user_badge.user_id, - details: user_badge.badge.name - })) + UserHistory.create(params(opts).merge(action: UserHistory.actions[:grant_badge], + target_user_id: user_badge.user_id, + details: user_badge.badge.name)) end - def log_badge_revoke(user_badge, opts={}) + def log_badge_revoke(user_badge, opts = {}) raise Discourse::InvalidParameters.new(:user_badge) unless user_badge - UserHistory.create( params(opts).merge({ - action: UserHistory.actions[:revoke_badge], - target_user_id: user_badge.user_id, - details: user_badge.badge.name - })) + UserHistory.create(params(opts).merge(action: UserHistory.actions[:revoke_badge], + target_user_id: user_badge.user_id, + details: user_badge.badge.name)) end - def log_check_email(user, opts={}) + def log_check_email(user, opts = {}) raise Discourse::InvalidParameters.new(:user) unless user - UserHistory.create(params(opts).merge({ - action: UserHistory.actions[:check_email], - target_user_id: user.id - })) + UserHistory.create(params(opts).merge(action: UserHistory.actions[:check_email], + target_user_id: user.id)) end - def log_show_emails(users, opts={}) + def log_show_emails(users, opts = {}) return if users.blank? - UserHistory.create(params(opts).merge({ - action: UserHistory.actions[:check_email], - details: users.map { |u| "[#{u.id}] #{u.username}"}.join("\n") - })) + UserHistory.create(params(opts).merge(action: UserHistory.actions[:check_email], + details: users.map { |u| "[#{u.id}] #{u.username}" }.join("\n"))) end - def log_impersonate(user, opts={}) + def log_impersonate(user, opts = {}) raise Discourse::InvalidParameters.new(:user) unless user - UserHistory.create(params(opts).merge({ - action: UserHistory.actions[:impersonate], - target_user_id: user.id - })) + UserHistory.create(params(opts).merge(action: UserHistory.actions[:impersonate], + target_user_id: user.id)) end - def log_roll_up(subnets, opts={}) - UserHistory.create(params(opts).merge({ - action: UserHistory.actions[:roll_up], - details: subnets.join(", ") - })) + def log_roll_up(subnets, opts = {}) + UserHistory.create(params(opts).merge(action: UserHistory.actions[:roll_up], + details: subnets.join(", "))) end - def log_category_settings_change(category, category_params, old_permissions=nil) + def log_category_settings_change(category, category_params, old_permissions = nil) validate_category(category) changed_attributes = category.previous_changes.slice(*category_params.keys) if !old_permissions.empty? && (old_permissions != category_params[:permissions]) - changed_attributes.merge!({ permissions: [old_permissions.to_json, category_params[:permissions].to_json] }) + changed_attributes.merge!(permissions: [old_permissions.to_json, category_params[:permissions].to_json]) end changed_attributes.each do |key, value| - UserHistory.create(params.merge({ - action: UserHistory.actions[:change_category_settings], - category_id: category.id, - context: category.url, - subject: key, - previous_value: value[0], - new_value: value[1] - })) + UserHistory.create(params.merge(action: UserHistory.actions[:change_category_settings], + category_id: category.id, + context: category.url, + subject: key, + previous_value: value[0], + new_value: value[1])) end end @@ -289,12 +249,10 @@ class StaffActionLogger details << "parent_category: #{parent_category.name}" end - UserHistory.create(params.merge({ - action: UserHistory.actions[:delete_category], - category_id: category.id, - details: details.join("\n"), - context: category.url - })) + UserHistory.create(params.merge(action: UserHistory.actions[:delete_category], + category_id: category.id, + details: details.join("\n"), + context: category.url)) end def log_category_creation(category) @@ -305,132 +263,102 @@ class StaffActionLogger "name: #{category.name}" ] - UserHistory.create(params.merge({ - action: UserHistory.actions[:create_category], - details: details.join("\n"), - category_id: category.id, - context: category.url - })) + UserHistory.create(params.merge(action: UserHistory.actions[:create_category], + details: details.join("\n"), + category_id: category.id, + context: category.url)) end - def log_block_user(user, opts={}) + def log_block_user(user, opts = {}) raise Discourse::InvalidParameters.new(:user) unless user - UserHistory.create( params(opts).merge({ - action: UserHistory.actions[:block_user], - target_user_id: user.id - })) + UserHistory.create(params(opts).merge(action: UserHistory.actions[:block_user], + target_user_id: user.id)) end - def log_unblock_user(user, opts={}) + def log_unblock_user(user, opts = {}) raise Discourse::InvalidParameters.new(:user) unless user - UserHistory.create( params(opts).merge({ - action: UserHistory.actions[:unblock_user], - target_user_id: user.id - })) + UserHistory.create(params(opts).merge(action: UserHistory.actions[:unblock_user], + target_user_id: user.id)) end - def log_grant_admin(user, opts={}) + def log_grant_admin(user, opts = {}) raise Discourse::InvalidParameters.new(:user) unless user - UserHistory.create( params(opts).merge({ - action: UserHistory.actions[:grant_admin], - target_user_id: user.id - })) + UserHistory.create(params(opts).merge(action: UserHistory.actions[:grant_admin], + target_user_id: user.id)) end - def log_revoke_admin(user, opts={}) + def log_revoke_admin(user, opts = {}) raise Discourse::InvalidParameters.new(:user) unless user - UserHistory.create( params(opts).merge({ - action: UserHistory.actions[:revoke_admin], - target_user_id: user.id - })) + UserHistory.create(params(opts).merge(action: UserHistory.actions[:revoke_admin], + target_user_id: user.id)) end - def log_grant_moderation(user, opts={}) + def log_grant_moderation(user, opts = {}) raise Discourse::InvalidParameters.new(:user) unless user - UserHistory.create( params(opts).merge({ - action: UserHistory.actions[:grant_moderation], - target_user_id: user.id - })) + UserHistory.create(params(opts).merge(action: UserHistory.actions[:grant_moderation], + target_user_id: user.id)) end - def log_revoke_moderation(user, opts={}) + def log_revoke_moderation(user, opts = {}) raise Discourse::InvalidParameters.new(:user) unless user - UserHistory.create( params(opts).merge({ - action: UserHistory.actions[:revoke_moderation], - target_user_id: user.id - })) + UserHistory.create(params(opts).merge(action: UserHistory.actions[:revoke_moderation], + target_user_id: user.id)) end - def log_backup_create(opts={}) - UserHistory.create(params(opts).merge({ - action: UserHistory.actions[:backup_create], - ip_address: @admin.ip_address.to_s - })) + def log_backup_create(opts = {}) + UserHistory.create(params(opts).merge(action: UserHistory.actions[:backup_create], + ip_address: @admin.ip_address.to_s)) end - def log_backup_download(backup, opts={}) + def log_backup_download(backup, opts = {}) raise Discourse::InvalidParameters.new(:backup) unless backup - UserHistory.create(params(opts).merge({ - action: UserHistory.actions[:backup_download], - ip_address: @admin.ip_address.to_s, - details: backup.filename - })) + UserHistory.create(params(opts).merge(action: UserHistory.actions[:backup_download], + ip_address: @admin.ip_address.to_s, + details: backup.filename)) end - def log_backup_destroy(backup, opts={}) + def log_backup_destroy(backup, opts = {}) raise Discourse::InvalidParameters.new(:backup) unless backup - UserHistory.create(params(opts).merge({ - action: UserHistory.actions[:backup_destroy], - ip_address: @admin.ip_address.to_s, - details: backup.filename - })) + UserHistory.create(params(opts).merge(action: UserHistory.actions[:backup_destroy], + ip_address: @admin.ip_address.to_s, + details: backup.filename)) end - def log_revoke_email(user, reason, opts={}) - UserHistory.create(params(opts).merge({ - action: UserHistory.actions[:revoke_email], - target_user_id: user.id, - details: reason - })) + def log_revoke_email(user, reason, opts = {}) + UserHistory.create(params(opts).merge(action: UserHistory.actions[:revoke_email], + target_user_id: user.id, + details: reason)) end - def log_user_deactivate(user, reason, opts={}) + def log_user_deactivate(user, reason, opts = {}) raise Discourse::InvalidParameters.new(:user) unless user - UserHistory.create(params(opts).merge({ - action: UserHistory.actions[:deactivate_user], - target_user_id: user.id, - details: reason - })) + UserHistory.create(params(opts).merge(action: UserHistory.actions[:deactivate_user], + target_user_id: user.id, + details: reason)) end - def log_user_activate(user, reason, opts={}) + def log_user_activate(user, reason, opts = {}) raise Discourse::InvalidParameters.new(:user) unless user - UserHistory.create(params(opts).merge({ - action: UserHistory.actions[:activate_user], - target_user_id: user.id, - details: reason - })) + UserHistory.create(params(opts).merge(action: UserHistory.actions[:activate_user], + target_user_id: user.id, + details: reason)) end - def log_wizard_step(step, opts={}) + def log_wizard_step(step, opts = {}) raise Discourse::InvalidParameters.new(:step) unless step - UserHistory.create(params(opts).merge({ - action: UserHistory.actions[:wizard_step], - context: step.id - })) + UserHistory.create(params(opts).merge(action: UserHistory.actions[:wizard_step], + context: step.id)) end def log_change_readonly_mode(state) - UserHistory.create(params.merge({ - action: UserHistory.actions[:change_readonly_mode], - previous_value: !state, - new_value: state - })) + UserHistory.create(params.merge(action: UserHistory.actions[:change_readonly_mode], + previous_value: !state, + new_value: state)) end private - def params(opts=nil) + def params(opts = nil) opts ||= {} { acting_user_id: @admin.id, context: opts[:context] } end diff --git a/app/services/topic_status_updater.rb b/app/services/topic_status_updater.rb index a2fc8f4dd63..80b5781ea73 100644 --- a/app/services/topic_status_updater.rb +++ b/app/services/topic_status_updater.rb @@ -1,5 +1,5 @@ TopicStatusUpdater = Struct.new(:topic, :user) do - def update!(status, enabled, opts={}) + def update!(status, enabled, opts = {}) status = Status.new(status, enabled) @topic_status_update = topic.public_topic_timer @@ -19,7 +19,7 @@ TopicStatusUpdater = Struct.new(:topic, :user) do private - def change(status, opts={}) + def change(status, opts = {}) result = true if status.pinned? || status.pinned_globally? @@ -30,7 +30,7 @@ TopicStatusUpdater = Struct.new(:topic, :user) do result = false if rc == 0 else rc = Topic.where(:id => topic.id, status.name => !status.enabled) - .update_all(status.name => status.enabled?) + .update_all(status.name => status.enabled?) topic.send("#{status.name}=", status.enabled?) result = false if rc == 0 @@ -55,7 +55,7 @@ TopicStatusUpdater = Struct.new(:topic, :user) do result end - def create_moderator_post_for(status, message=nil) + def create_moderator_post_for(status, message = nil) topic.add_moderator_post(user, message || message_for(status), options_for(status)) topic.reload end diff --git a/app/services/tracked_topics_updater.rb b/app/services/tracked_topics_updater.rb index 2222fc4c637..0ffb32e7e79 100644 --- a/app/services/tracked_topics_updater.rb +++ b/app/services/tracked_topics_updater.rb @@ -8,11 +8,10 @@ class TrackedTopicsUpdater def call topic_users = TopicUser.where(notifications_reason_id: nil, user_id: @id) if @threshold < 0 - topic_users.update_all({notification_level: TopicUser.notification_levels[:regular]}) + topic_users.update_all(notification_level: TopicUser.notification_levels[:regular]) else topic_users.update_all(["notification_level = CASE WHEN total_msecs_viewed < ? THEN ? ELSE ? END", @threshold, TopicUser.notification_levels[:regular], TopicUser.notification_levels[:tracking]]) end end end - diff --git a/app/services/user_action_creator.rb b/app/services/user_action_creator.rb index bbf21f9fb9d..68a5d0847d2 100644 --- a/app/services/user_action_creator.rb +++ b/app/services/user_action_creator.rb @@ -7,19 +7,19 @@ class UserActionCreator @disabled = false end - def self.log_notification(post, user, notification_type, acting_user_id=nil) + def self.log_notification(post, user, notification_type, acting_user_id = nil) return if @disabled action = case notification_type - when Notification.types[:quoted] - UserAction::QUOTE - when Notification.types[:replied] - UserAction::RESPONSE - when Notification.types[:mentioned] - UserAction::MENTION - when Notification.types[:edited] - UserAction::EDIT + when Notification.types[:quoted] + UserAction::QUOTE + when Notification.types[:replied] + UserAction::RESPONSE + when Notification.types[:mentioned] + UserAction::MENTION + when Notification.types[:edited] + UserAction::EDIT end # skip any invalid items, eg failed to save post and so on diff --git a/app/services/user_anonymizer.rb b/app/services/user_anonymizer.rb index ac692d28d76..dbd58624bff 100644 --- a/app/services/user_anonymizer.rb +++ b/app/services/user_anonymizer.rb @@ -1,10 +1,10 @@ class UserAnonymizer - def initialize(user, actor=nil) + def initialize(user, actor = nil) @user = user @actor = actor end - def self.make_anonymous(user, actor=nil) + def self.make_anonymous(user, actor = nil) self.new(user, actor).make_anonymous end @@ -48,11 +48,11 @@ class UserAnonymizer @user.user_open_ids.find_each { |x| x.destroy } @user.api_key.try(:destroy) - UserHistory.create( action: UserHistory.actions[:anonymize_user], - target_user_id: @user.id, - acting_user_id: @actor ? @actor.id : @user.id, - email: prev_email, - details: "username: #{prev_username}" ) + UserHistory.create(action: UserHistory.actions[:anonymize_user], + target_user_id: @user.id, + acting_user_id: @actor ? @actor.id : @user.id, + email: prev_email, + details: "username: #{prev_username}") end @user end diff --git a/app/services/user_blocker.rb b/app/services/user_blocker.rb index fe0091425e9..8a35c5f2390 100644 --- a/app/services/user_blocker.rb +++ b/app/services/user_blocker.rb @@ -1,14 +1,14 @@ class UserBlocker - def initialize(user, by_user=nil, opts={}) + def initialize(user, by_user = nil, opts = {}) @user, @by_user, @opts = user, by_user, opts end - def self.block(user, by_user=nil, opts={}) + def self.block(user, by_user = nil, opts = {}) UserBlocker.new(user, by_user, opts).block end - def self.unblock(user, by_user=nil, opts={}) + def self.unblock(user, by_user = nil, opts = {}) UserBlocker.new(user, by_user, opts).unblock end @@ -20,7 +20,7 @@ class UserBlocker message_type = @opts[:message] || :blocked_by_staff post = SystemMessage.create(@user, message_type) if post && @by_user - StaffActionLogger.new(@by_user).log_block_user(@user, {context: "#{message_type}: '#{post.topic&.title rescue ''}' #{@opts[:reason]}"}) + StaffActionLogger.new(@by_user).log_block_user(@user, context: "#{message_type}: '#{post.topic&.title rescue ''}' #{@opts[:reason]}") end end else diff --git a/app/services/user_destroyer.rb b/app/services/user_destroyer.rb index 838c2ba59e4..e95d4ca60dd 100644 --- a/app/services/user_destroyer.rb +++ b/app/services/user_destroyer.rb @@ -7,14 +7,14 @@ class UserDestroyer def initialize(actor) @actor = actor - raise Discourse::InvalidParameters.new('acting user is nil') unless @actor and @actor.is_a?(User) + raise Discourse::InvalidParameters.new('acting user is nil') unless @actor && @actor.is_a?(User) @guardian = Guardian.new(actor) end # Returns false if the user failed to be deleted. # Returns a frozen instance of the User if the delete succeeded. - def destroy(user, opts={}) - raise Discourse::InvalidParameters.new('user is nil') unless user and user.is_a?(User) + def destroy(user, opts = {}) + raise Discourse::InvalidParameters.new('user is nil') unless user && user.is_a?(User) raise PostsExistError if !opts[:delete_posts] && user.posts.count != 0 @guardian.ensure_can_delete_user!(user) diff --git a/app/services/username_changer.rb b/app/services/username_changer.rb index 990534e2822..a81f089415c 100644 --- a/app/services/username_changer.rb +++ b/app/services/username_changer.rb @@ -1,12 +1,12 @@ class UsernameChanger - def initialize(user, new_username, actor=nil) + def initialize(user, new_username, actor = nil) @user = user @new_username = new_username @actor = actor end - def self.change(user, new_username, actor=nil) + def self.change(user, new_username, actor = nil) self.new(user, new_username, actor).change end diff --git a/app/services/username_checker_service.rb b/app/services/username_checker_service.rb index 91bfe42de93..0f8d7a62510 100644 --- a/app/services/username_checker_service.rb +++ b/app/services/username_checker_service.rb @@ -4,7 +4,7 @@ class UsernameCheckerService if username && username.length > 0 validator = UsernameValidator.new(username) if !validator.valid_format? - {errors: validator.errors} + { errors: validator.errors } else check_username_availability(username, email) end @@ -23,7 +23,6 @@ class UsernameCheckerService Rails.configuration.respond_to?(:developer_emails) && Rails.configuration.developer_emails.include?(value) end - def self.is_developer?(email) UsernameCheckerService.new.is_developer?(email) end diff --git a/app/services/word_watcher.rb b/app/services/word_watcher.rb index 625e51e999d..11d61f0f522 100644 --- a/app/services/word_watcher.rb +++ b/app/services/word_watcher.rb @@ -26,7 +26,7 @@ class WordWatcher end def self.clear_cache! - WatchedWord.actions.sum do |a,i| + WatchedWord.actions.sum do |a, i| Discourse.cache.delete word_matcher_regexp_key(a) end end diff --git a/bin/puma b/bin/puma index 26523fced37..3249ddee001 100755 --- a/bin/puma +++ b/bin/puma @@ -12,7 +12,7 @@ if ARGV[0] == '--kill-existing' pids = `ps aux | grep puma | grep discourse | grep -v grep | awk '{print $2;}'`.strip .split("\n") .map(&:to_i) - .reject{|pid| pid == Process.pid} + .reject { |pid| pid == Process.pid } if pids.length > 0 STDERR.puts "Terminating old version of puma at pid #{pids[0]}" diff --git a/config.ru b/config.ru index c74954f4f4b..9a0cd31d678 100644 --- a/config.ru +++ b/config.ru @@ -3,4 +3,3 @@ require ::File.expand_path('../config/environment', __FILE__) map ActionController::Base.config.try(:relative_url_root) || "/" do run Discourse::Application end - diff --git a/config/application.rb b/config/application.rb index 153ef545cd7..a0a9920d48f 100644 --- a/config/application.rb +++ b/config/application.rb @@ -22,7 +22,6 @@ if defined?(Bundler) Bundler.require(*Rails.groups(assets: %w(development test profile))) end - module Discourse class Application < Rails::Application @@ -169,7 +168,7 @@ module Discourse # we configure rack cache on demand in an initializer # our setup does not use rack cache and instead defers to nginx - config.action_dispatch.rack_cache = nil + config.action_dispatch.rack_cache = nil # ember stuff only used for asset precompliation, production variant plays up config.ember.variant = :development @@ -177,7 +176,7 @@ module Discourse config.ember.handlebars_location = "#{Rails.root}/vendor/assets/javascripts/handlebars.js" require 'auth' - Discourse.activate_plugins! unless Rails.env.test? and ENV['LOAD_PLUGINS'] != "1" + Discourse.activate_plugins! unless Rails.env.test? && ENV['LOAD_PLUGINS'] != ("1") if GlobalSetting.relative_url_root.present? config.relative_url_root = GlobalSetting.relative_url_root @@ -207,7 +206,7 @@ module Discourse # So open id logs somewhere sane OpenID::Util.logger = Rails.logger if plugins = Discourse.plugins - plugins.each{|plugin| plugin.notify_after_initialize} + plugins.each { |plugin| plugin.notify_after_initialize } end # This nasty hack is required for not precompiling QUnit assets diff --git a/config/boot.rb b/config/boot.rb index 7180eb1fbbc..929f1a62fe0 100644 --- a/config/boot.rb +++ b/config/boot.rb @@ -10,7 +10,6 @@ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__) require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE']) - if ENV['RAILS_ENV'] != 'production' require 'bootsnap' diff --git a/config/cloud/cloud66/files/production.rb b/config/cloud/cloud66/files/production.rb index db662574bee..42d9caa9fc2 100644 --- a/config/cloud/cloud66/files/production.rb +++ b/config/cloud/cloud66/files/production.rb @@ -27,13 +27,13 @@ Discourse::Application.configure do config.action_mailer.delivery_method = :smtp config.action_mailer.smtp_settings = { - :address => ENV['SMTP_ADDRESS'], - :port => ENV['SMTP_PORT'], - :domain => ENV['SMTP_DOMAIN'], - :user_name => ENV['SMTP_USERNAME'], - :password => ENV['SMTP_PASSWORD'], - :authentication => 'plain', - :enable_starttls_auto => true } + address: ENV['SMTP_ADDRESS'], + port: ENV['SMTP_PORT'], + domain: ENV['SMTP_DOMAIN'], + user_name: ENV['SMTP_USERNAME'], + password: ENV['SMTP_PASSWORD'], + authentication: 'plain', + enable_starttls_auto: true } #config.action_mailer.delivery_method = :sendmail #config.action_mailer.sendmail_settings = {arguments: '-i'} diff --git a/config/environments/development.rb b/config/environments/development.rb index 560d5601301..d9c10db2e8a 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -48,8 +48,6 @@ Discourse::Application.configure do config.enable_anon_caching = false require 'rbtrace' - - if emails = GlobalSetting.developer_emails config.developer_emails = emails.split(",").map(&:downcase).map(&:strip) end diff --git a/config/environments/production.rb b/config/environments/production.rb index b4331f15ac6..6489a1777e2 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -35,10 +35,10 @@ Discourse::Application.configure do settings[:openssl_verify_mode] = GlobalSetting.smtp_openssl_verify_mode if GlobalSetting.smtp_openssl_verify_mode - config.action_mailer.smtp_settings = settings.reject{|_, y| y.nil?} + config.action_mailer.smtp_settings = settings.reject { |_, y| y.nil? } else config.action_mailer.delivery_method = :sendmail - config.action_mailer.sendmail_settings = {arguments: '-i'} + config.action_mailer.sendmail_settings = { arguments: '-i' } end # Send deprecation notices to registered listeners diff --git a/config/environments/test.rb b/config/environments/test.rb index af2eedae623..5cd785ce22c 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -18,7 +18,7 @@ Discourse::Application.configure do config.action_dispatch.show_exceptions = false # Disable request forgery protection in test environment - config.action_controller.allow_forgery_protection = false + config.action_controller.allow_forgery_protection = false # Tell Action Mailer not to deliver emails to the real world. # The :test delivery method accumulates sent emails in the diff --git a/config/initializers/001-redis.rb b/config/initializers/001-redis.rb index 73340cc49da..af3e829842c 100644 --- a/config/initializers/001-redis.rb +++ b/config/initializers/001-redis.rb @@ -4,12 +4,11 @@ if Rails.env.development? && ENV['DISCOURSE_FLUSH_REDIS'] end if defined?(PhusionPassenger) - PhusionPassenger.on_event(:starting_worker_process) do |forked| - if forked - Discourse.after_fork - else - # We're in conservative spawning mode. We don't need to do anything. - end + PhusionPassenger.on_event(:starting_worker_process) do |forked| + if forked + Discourse.after_fork + else + # We're in conservative spawning mode. We don't need to do anything. end + end end - diff --git a/config/initializers/004-message_bus.rb b/config/initializers/004-message_bus.rb index 5faf89f9e8b..fabada48a02 100644 --- a/config/initializers/004-message_bus.rb +++ b/config/initializers/004-message_bus.rb @@ -1,4 +1,4 @@ -MessageBus.site_id_lookup do |env=nil| +MessageBus.site_id_lookup do |env = nil| if env setup_message_bus_env(env) env["__mb"][:site_id] diff --git a/config/initializers/006-ensure_login_hint.rb b/config/initializers/006-ensure_login_hint.rb index e177601737b..1cc7b514291 100644 --- a/config/initializers/006-ensure_login_hint.rb +++ b/config/initializers/006-ensure_login_hint.rb @@ -18,5 +18,5 @@ if User.limit(20).count < 20 && User.where(admin: true).human_users.count == 0 SiteSetting.has_login_hint = true end -# we may be booting with no User table eg: first migration, just skip + # we may be booting with no User table eg: first migration, just skip end rescue nil diff --git a/config/initializers/006-mini_profiler.rb b/config/initializers/006-mini_profiler.rb index e39b1a33dee..a04c888fceb 100644 --- a/config/initializers/006-mini_profiler.rb +++ b/config/initializers/006-mini_profiler.rb @@ -6,7 +6,7 @@ if Rails.configuration.respond_to?(:load_mini_profiler) && Rails.configuration.l begin require 'memory_profiler' rescue => e - STDERR.put "#{e} failed to require mini profiler" + STDERR.put "#{e} failed to require mini profiler" end # initialization is skipped so trigger it @@ -48,7 +48,7 @@ if defined?(Rack::MiniProfiler) path = env['PATH_INFO'] (env['HTTP_USER_AGENT'] !~ /iPad|iPhone|Android/) && - !skip.any?{|re| re =~ path} + !skip.any? { |re| re =~ path } end # without a user provider our results will use the ip address for namespacing @@ -68,7 +68,6 @@ if defined?(Rack::MiniProfiler) Rack::MiniProfiler.config.backtrace_ignores << /config\/initializers\/silence_logger/ Rack::MiniProfiler.config.backtrace_ignores << /config\/initializers\/quiet_logger/ - # Rack::MiniProfiler.counter_method(ActiveRecord::QueryMethods, 'build_arel') # Rack::MiniProfiler.counter_method(Array, 'uniq') # require "#{Rails.root}/vendor/backports/notification" @@ -97,9 +96,8 @@ if defined?(Rack::MiniProfiler) # Rack::MiniProfiler.profile_method ActionView::PathResolver, 'find_templates' end - if ENV["PRINT_EXCEPTIONS"] - trace = TracePoint.new(:raise) do |tp| + trace = TracePoint.new(:raise) do |tp| puts tp.raised_exception puts tp.raised_exception.backtrace.join("\n") puts diff --git a/config/initializers/008-rack-cors.rb b/config/initializers/008-rack-cors.rb index 4864b961f67..2ba7b01fb3f 100644 --- a/config/initializers/008-rack-cors.rb +++ b/config/initializers/008-rack-cors.rb @@ -8,7 +8,7 @@ if GlobalSetting.enable_cors end def call(env) - if env['REQUEST_METHOD'] == 'OPTIONS' and env['HTTP_ACCESS_CONTROL_REQUEST_METHOD'] + if env['REQUEST_METHOD'] == ('OPTIONS') && env['HTTP_ACCESS_CONTROL_REQUEST_METHOD'] return [200, apply_headers(env), []] end @@ -16,7 +16,7 @@ if GlobalSetting.enable_cors [status, apply_headers(env, headers), body] end - def apply_headers(env, headers=nil) + def apply_headers(env, headers = nil) headers ||= {} origin = nil diff --git a/config/initializers/050-force_https.rb b/config/initializers/050-force_https.rb index 7ac71e11351..0185fbd7426 100644 --- a/config/initializers/050-force_https.rb +++ b/config/initializers/050-force_https.rb @@ -1,7 +1,7 @@ # tiny middleware to force https if needed class Discourse::ForceHttpsMiddleware - def initialize(app, config={}) + def initialize(app, config = {}) @app = app end @@ -11,4 +11,3 @@ class Discourse::ForceHttpsMiddleware end end - diff --git a/config/initializers/099-anon-cache.rb b/config/initializers/099-anon-cache.rb index d2c90beee87..e0a90c71f17 100644 --- a/config/initializers/099-anon-cache.rb +++ b/config/initializers/099-anon-cache.rb @@ -1,13 +1,13 @@ require_dependency "middleware/anonymous_cache" -enabled = if Rails.configuration.respond_to?(:enable_anon_caching) - Rails.configuration.enable_anon_caching - else - Rails.env.production? - end +enabled = + if Rails.configuration.respond_to?(:enable_anon_caching) + Rails.configuration.enable_anon_caching + else + Rails.env.production? + end if !ENV['DISCOURSE_DISABLE_ANON_CACHE'] && enabled # in an ideal world this is position 0, but mobile detection uses ... session and request and params Rails.configuration.middleware.insert_after ActionDispatch::ParamsParser, Middleware::AnonymousCache end - diff --git a/config/initializers/100-logster.rb b/config/initializers/100-logster.rb index d913051336c..c7277684c69 100644 --- a/config/initializers/100-logster.rb +++ b/config/initializers/100-logster.rb @@ -44,12 +44,12 @@ end # middleware that logs errors sits before multisite # we need to establish a connection so redis connection is good # and db connection is good -Logster.config.current_context = lambda{|env,&blk| +Logster.config.current_context = lambda { |env, &blk| begin if Rails.configuration.multisite request = Rack::Request.new(env) ActiveRecord::Base.connection_handler.clear_active_connections! - RailsMultisite::ConnectionManagement.establish_connection(:host => request['__ws'] || request.host) + RailsMultisite::ConnectionManagement.establish_connection(host: request['__ws'] || request.host) end blk.call ensure @@ -73,7 +73,7 @@ RailsMultisite::ConnectionManagement.each_connection do if (error_rate_per_minute || 0) > 0 store.register_rate_limit_per_minute(severities, error_rate_per_minute) do |rate| - MessageBus.publish("/logs_error_rate_exceeded", { rate: rate, duration: 'minute', publish_at: Time.current.to_i }) + MessageBus.publish("/logs_error_rate_exceeded", rate: rate, duration: 'minute', publish_at: Time.current.to_i) end end @@ -81,7 +81,7 @@ RailsMultisite::ConnectionManagement.each_connection do if (error_rate_per_hour || 0) > 0 store.register_rate_limit_per_hour(severities, error_rate_per_hour) do |rate| - MessageBus.publish("/logs_error_rate_exceeded", { rate: rate, duration: 'hour', publish_at: Time.current.to_i }) + MessageBus.publish("/logs_error_rate_exceeded", rate: rate, duration: 'hour', publish_at: Time.current.to_i) end end end diff --git a/config/initializers/100-quiet_logger.rb b/config/initializers/100-quiet_logger.rb index 55c0dfcb4ce..908b0c2cfdd 100644 --- a/config/initializers/100-quiet_logger.rb +++ b/config/initializers/100-quiet_logger.rb @@ -6,7 +6,7 @@ Rails::Rack::Logger.class_eval do def call_with_quiet_assets(env) override = false - if (env['PATH_INFO'].index("/assets/") == 0) or + if (env['PATH_INFO'].index("/assets/") == 0) || (env['PATH_INFO'].index("mini-profiler-resources") == 0) if ::Logster::Logger === Rails.logger override = true diff --git a/config/initializers/100-sidekiq.rb b/config/initializers/100-sidekiq.rb index a155c113cb3..efde7360128 100644 --- a/config/initializers/100-sidekiq.rb +++ b/config/initializers/100-sidekiq.rb @@ -35,7 +35,7 @@ if Sidekiq.server? manager.tick rescue => e # the show must go on - Discourse.handle_job_exception(e, {message: "While ticking scheduling manager"}) + Discourse.handle_job_exception(e, message: "While ticking scheduling manager") end sleep 1 end diff --git a/config/initializers/100-verify_config.rb b/config/initializers/100-verify_config.rb index c0c0a8965a5..2d91431db64 100644 --- a/config/initializers/100-verify_config.rb +++ b/config/initializers/100-verify_config.rb @@ -1,6 +1,6 @@ # Check that the app is configured correctly. Raise some helpful errors if something is wrong. -if defined?(Rails::Server) and Rails.env.production? # Only run these checks when starting up a production server +if defined?(Rails::Server) && Rails.env.production? # Only run these checks when starting up a production server if ['localhost', 'production.localhost'].include?(Discourse.current_hostname) puts < { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| n == 1 ? :one : :other } } } }, - :am => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| [0, 1].include?(n) ? :one : :other } } } }, - :ar => { :i18n => { :plural => { :keys => [:zero, :one, :two, :few, :many, :other], :rule => lambda { |n| n == 0 ? :zero : n == 1 ? :one : n == 2 ? :two : [3, 4, 5, 6, 7, 8, 9, 10].include?(n % 100) ? :few : [11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99].include?(n % 100) ? :many : :other } } } }, - :az => { :i18n => { :plural => { :keys => [:other], :rule => lambda { |n| :other } } } }, - :be => { :i18n => { :plural => { :keys => [:one, :few, :many, :other], :rule => lambda { |n| n % 10 == 1 && n % 100 != 11 ? :one : [2, 3, 4].include?(n % 10) && ![12, 13, 14].include?(n % 100) ? :few : n % 10 == 0 || [5, 6, 7, 8, 9].include?(n % 10) || [11, 12, 13, 14].include?(n % 100) ? :many : :other } } } }, - :bg => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| n == 1 ? :one : :other } } } }, - :bh => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| [0, 1].include?(n) ? :one : :other } } } }, - :bn => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| n == 1 ? :one : :other } } } }, - :bo => { :i18n => { :plural => { :keys => [:other], :rule => lambda { |n| :other } } } }, - :bs => { :i18n => { :plural => { :keys => [:one, :few, :many, :other], :rule => lambda { |n| n % 10 == 1 && n % 100 != 11 ? :one : [2, 3, 4].include?(n % 10) && ![12, 13, 14].include?(n % 100) ? :few : n % 10 == 0 || [5, 6, 7, 8, 9].include?(n % 10) || [11, 12, 13, 14].include?(n % 100) ? :many : :other } } } }, - :ca => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| n == 1 ? :one : :other } } } }, - :cs => { :i18n => { :plural => { :keys => [:one, :few, :other], :rule => lambda { |n| n == 1 ? :one : [2, 3, 4].include?(n) ? :few : :other } } } }, - :cy => { :i18n => { :plural => { :keys => [:one, :two, :many, :other], :rule => lambda { |n| n == 1 ? :one : n == 2 ? :two : n == 8 || n == 11 ? :many : :other } } } }, - :da => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| n == 1 ? :one : :other } } } }, - :de => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| n == 1 ? :one : :other } } } }, - :dz => { :i18n => { :plural => { :keys => [:other], :rule => lambda { |n| :other } } } }, - :el => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| n == 1 ? :one : :other } } } }, - :en => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| n == 1 ? :one : :other } } } }, - :eo => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| n == 1 ? :one : :other } } } }, - :es => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| n == 1 ? :one : :other } } } }, - :et => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| n == 1 ? :one : :other } } } }, - :eu => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| n == 1 ? :one : :other } } } }, - :fa_IR => { :i18n => { :plural => { :keys => [:other], :rule => lambda { |n| :other } } } }, - :fi => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| n == 1 ? :one : :other } } } }, - :fil => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| [0, 1].include?(n) ? :one : :other } } } }, - :fo => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| n == 1 ? :one : :other } } } }, - :fr => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| n.between?(0, 2) && n != 2 ? :one : :other } } } }, - :fur => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| n == 1 ? :one : :other } } } }, - :fy => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| n == 1 ? :one : :other } } } }, - :ga => { :i18n => { :plural => { :keys => [:one, :two, :other], :rule => lambda { |n| n == 1 ? :one : n == 2 ? :two : :other } } } }, - :gl => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| n == 1 ? :one : :other } } } }, - :gu => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| n == 1 ? :one : :other } } } }, - :guw => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| [0, 1].include?(n) ? :one : :other } } } }, - :ha => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| n == 1 ? :one : :other } } } }, - :he => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| n == 1 ? :one : :other } } } }, - :hi => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| [0, 1].include?(n) ? :one : :other } } } }, - :hr => { :i18n => { :plural => { :keys => [:one, :few, :many, :other], :rule => lambda { |n| n % 10 == 1 && n % 100 != 11 ? :one : [2, 3, 4].include?(n % 10) && ![12, 13, 14].include?(n % 100) ? :few : n % 10 == 0 || [5, 6, 7, 8, 9].include?(n % 10) || [11, 12, 13, 14].include?(n % 100) ? :many : :other } } } }, - :hu => { :i18n => { :plural => { :keys => [:other], :rule => lambda { |n| :other } } } }, - :id => { :i18n => { :plural => { :keys => [:other], :rule => lambda { |n| :other } } } }, - :is => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| n == 1 ? :one : :other } } } }, - :it => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| n == 1 ? :one : :other } } } }, - :iw => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| n == 1 ? :one : :other } } } }, - :ja => { :i18n => { :plural => { :keys => [:other], :rule => lambda { |n| :other } } } }, - :jv => { :i18n => { :plural => { :keys => [:other], :rule => lambda { |n| :other } } } }, - :ka => { :i18n => { :plural => { :keys => [:other], :rule => lambda { |n| :other } } } }, - :km => { :i18n => { :plural => { :keys => [:other], :rule => lambda { |n| :other } } } }, - :kn => { :i18n => { :plural => { :keys => [:other], :rule => lambda { |n| :other } } } }, - :ko => { :i18n => { :plural => { :keys => [:other], :rule => lambda { |n| :other } } } }, - :ku => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| n == 1 ? :one : :other } } } }, - :lb => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| n == 1 ? :one : :other } } } }, - :ln => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| [0, 1].include?(n) ? :one : :other } } } }, - :lt => { :i18n => { :plural => { :keys => [:one, :few, :other], :rule => lambda { |n| n % 10 == 1 && ![11, 12, 13, 14, 15, 16, 17, 18, 19].include?(n % 100) ? :one : [2, 3, 4, 5, 6, 7, 8, 9].include?(n % 10) && ![11, 12, 13, 14, 15, 16, 17, 18, 19].include?(n % 100) ? :few : :other } } } }, - :lv => { :i18n => { :plural => { :keys => [:zero, :one, :other], :rule => lambda { |n| n == 0 ? :zero : n % 10 == 1 && n % 100 != 11 ? :one : :other } } } }, - :mg => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| [0, 1].include?(n) ? :one : :other } } } }, - :mk => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| n % 10 == 1 ? :one : :other } } } }, - :ml => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| n == 1 ? :one : :other } } } }, - :mn => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| n == 1 ? :one : :other } } } }, - :mo => { :i18n => { :plural => { :keys => [:one, :few, :other], :rule => lambda { |n| n == 1 ? :one : n == 0 ? :few : :other } } } }, - :mr => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| n == 1 ? :one : :other } } } }, - :ms => { :i18n => { :plural => { :keys => [:other], :rule => lambda { |n| :other } } } }, - :mt => { :i18n => { :plural => { :keys => [:one, :few, :many, :other], :rule => lambda { |n| n == 1 ? :one : n == 0 || [2, 3, 4, 5, 6, 7, 8, 9, 10].include?(n % 100) ? :few : [11, 12, 13, 14, 15, 16, 17, 18, 19].include?(n % 100) ? :many : :other } } } }, - :my => { :i18n => { :plural => { :keys => [:other], :rule => lambda { |n| :other } } } }, - :nah => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| n == 1 ? :one : :other } } } }, - :nb_NO => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| n == 1 ? :one : :other } } } }, - :ne => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| n == 1 ? :one : :other } } } }, - :nl => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| n == 1 ? :one : :other } } } }, - :nn => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| n == 1 ? :one : :other } } } }, - :no => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| n == 1 ? :one : :other } } } }, - :nso => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| [0, 1].include?(n) ? :one : :other } } } }, - :om => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| n == 1 ? :one : :other } } } }, - :or => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| n == 1 ? :one : :other } } } }, - :pa => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| n == 1 ? :one : :other } } } }, - :pap => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| n == 1 ? :one : :other } } } }, - :pl_PL => { :i18n => { :plural => { :keys => [:one, :few, :other], :rule => lambda { |n| n == 1 ? :one : [2, 3, 4].include?(n % 10) && ![12, 13, 14].include?(n % 100) ? :few : :other } } } }, - :ps => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| n == 1 ? :one : :other } } } }, - :pt => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| [0, 1].include?(n) ? :one : :other } } } }, - :pt_BR => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| n == 1 ? :one : :other } } } }, - :ro => { :i18n => { :plural => { :keys => [:one, :few, :other], :rule => lambda { |n| n == 1 ? :one : n == 0 || ((n % 100) >= 1 && (n % 100) <= 19) ? :few : :other } } } }, - :ru => { :i18n => { :plural => { :keys => [:one, :few, :other], :rule => lambda { |n| n % 10 == 1 && n % 100 != 11 ? :one : [2, 3, 4].include?(n % 10) && ![12, 13, 14].include?(n % 100) ? :few : :other } } } }, - :se => { :i18n => { :plural => { :keys => [:one, :two, :other], :rule => lambda { |n| n == 1 ? :one : n == 2 ? :two : :other } } } }, - :sh => { :i18n => { :plural => { :keys => [:one, :few, :many, :other], :rule => lambda { |n| n % 10 == 1 && n % 100 != 11 ? :one : [2, 3, 4].include?(n % 10) && ![12, 13, 14].include?(n % 100) ? :few : n % 10 == 0 || [5, 6, 7, 8, 9].include?(n % 10) || [11, 12, 13, 14].include?(n % 100) ? :many : :other } } } }, - :sk => { :i18n => { :plural => { :keys => [:one, :few, :other], :rule => lambda { |n| n == 1 ? :one : [2, 3, 4].include?(n) ? :few : :other } } } }, - :sl => { :i18n => { :plural => { :keys => [:one, :two, :few, :other], :rule => lambda { |n| n % 100 == 1 ? :one : n % 100 == 2 ? :two : [3, 4].include?(n % 100) ? :few : :other } } } }, - :sma => { :i18n => { :plural => { :keys => [:one, :two, :other], :rule => lambda { |n| n == 1 ? :one : n == 2 ? :two : :other } } } }, - :smi => { :i18n => { :plural => { :keys => [:one, :two, :other], :rule => lambda { |n| n == 1 ? :one : n == 2 ? :two : :other } } } }, - :smj => { :i18n => { :plural => { :keys => [:one, :two, :other], :rule => lambda { |n| n == 1 ? :one : n == 2 ? :two : :other } } } }, - :smn => { :i18n => { :plural => { :keys => [:one, :two, :other], :rule => lambda { |n| n == 1 ? :one : n == 2 ? :two : :other } } } }, - :sms => { :i18n => { :plural => { :keys => [:one, :two, :other], :rule => lambda { |n| n == 1 ? :one : n == 2 ? :two : :other } } } }, - :so => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| n == 1 ? :one : :other } } } }, - :sq => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| n == 1 ? :one : :other } } } }, - :sr => { :i18n => { :plural => { :keys => [:one, :few, :many, :other], :rule => lambda { |n| n % 10 == 1 && n % 100 != 11 ? :one : [2, 3, 4].include?(n % 10) && ![12, 13, 14].include?(n % 100) ? :few : n % 10 == 0 || [5, 6, 7, 8, 9].include?(n % 10) || [11, 12, 13, 14].include?(n % 100) ? :many : :other } } } }, - :sv => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| n == 1 ? :one : :other } } } }, - :sw => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| n == 1 ? :one : :other } } } }, - :ta => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| n == 1 ? :one : :other } } } }, - :te => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| n == 1 ? :one : :other } } } }, - :th => { :i18n => { :plural => { :keys => [:other], :rule => lambda { |n| :other } } } }, - :ti => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| [0, 1].include?(n) ? :one : :other } } } }, - :tk => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| n == 1 ? :one : :other } } } }, - :tl => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| [0, 1].include?(n) ? :one : :other } } } }, - :to => { :i18n => { :plural => { :keys => [:other], :rule => lambda { |n| :other } } } }, - :tr_TR => { :i18n => { :plural => { :keys => [:other], :rule => lambda { |n| :other } } } }, + af: { i18n: { plural: { keys: [:one, :other], rule: lambda { |n| n == 1 ? :one : :other } } } }, + am: { i18n: { plural: { keys: [:one, :other], rule: lambda { |n| [0, 1].include?(n) ? :one : :other } } } }, + ar: { i18n: { plural: { keys: [:zero, :one, :two, :few, :many, :other], rule: lambda { |n| n == 0 ? :zero : n == 1 ? :one : n == 2 ? :two : [3, 4, 5, 6, 7, 8, 9, 10].include?(n % 100) ? :few : [11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99].include?(n % 100) ? :many : :other } } } }, + az: { i18n: { plural: { keys: [:other], rule: lambda { |n| :other } } } }, + be: { i18n: { plural: { keys: [:one, :few, :many, :other], rule: lambda { |n| n % 10 == 1 && n % 100 != 11 ? :one : [2, 3, 4].include?(n % 10) && ![12, 13, 14].include?(n % 100) ? :few : n % 10 == 0 || [5, 6, 7, 8, 9].include?(n % 10) || [11, 12, 13, 14].include?(n % 100) ? :many : :other } } } }, + bg: { i18n: { plural: { keys: [:one, :other], rule: lambda { |n| n == 1 ? :one : :other } } } }, + bh: { i18n: { plural: { keys: [:one, :other], rule: lambda { |n| [0, 1].include?(n) ? :one : :other } } } }, + bn: { i18n: { plural: { keys: [:one, :other], rule: lambda { |n| n == 1 ? :one : :other } } } }, + bo: { i18n: { plural: { keys: [:other], rule: lambda { |n| :other } } } }, + bs: { i18n: { plural: { keys: [:one, :few, :many, :other], rule: lambda { |n| n % 10 == 1 && n % 100 != 11 ? :one : [2, 3, 4].include?(n % 10) && ![12, 13, 14].include?(n % 100) ? :few : n % 10 == 0 || [5, 6, 7, 8, 9].include?(n % 10) || [11, 12, 13, 14].include?(n % 100) ? :many : :other } } } }, + ca: { i18n: { plural: { keys: [:one, :other], rule: lambda { |n| n == 1 ? :one : :other } } } }, + cs: { i18n: { plural: { keys: [:one, :few, :other], rule: lambda { |n| n == 1 ? :one : [2, 3, 4].include?(n) ? :few : :other } } } }, + cy: { i18n: { plural: { keys: [:one, :two, :many, :other], rule: lambda { |n| n == 1 ? :one : n == 2 ? :two : n == 8 || n == 11 ? :many : :other } } } }, + da: { i18n: { plural: { keys: [:one, :other], rule: lambda { |n| n == 1 ? :one : :other } } } }, + de: { i18n: { plural: { keys: [:one, :other], rule: lambda { |n| n == 1 ? :one : :other } } } }, + dz: { i18n: { plural: { keys: [:other], rule: lambda { |n| :other } } } }, + el: { i18n: { plural: { keys: [:one, :other], rule: lambda { |n| n == 1 ? :one : :other } } } }, + en: { i18n: { plural: { keys: [:one, :other], rule: lambda { |n| n == 1 ? :one : :other } } } }, + eo: { i18n: { plural: { keys: [:one, :other], rule: lambda { |n| n == 1 ? :one : :other } } } }, + es: { i18n: { plural: { keys: [:one, :other], rule: lambda { |n| n == 1 ? :one : :other } } } }, + et: { i18n: { plural: { keys: [:one, :other], rule: lambda { |n| n == 1 ? :one : :other } } } }, + eu: { i18n: { plural: { keys: [:one, :other], rule: lambda { |n| n == 1 ? :one : :other } } } }, + fa_IR: { i18n: { plural: { keys: [:other], rule: lambda { |n| :other } } } }, + fi: { i18n: { plural: { keys: [:one, :other], rule: lambda { |n| n == 1 ? :one : :other } } } }, + fil: { i18n: { plural: { keys: [:one, :other], rule: lambda { |n| [0, 1].include?(n) ? :one : :other } } } }, + fo: { i18n: { plural: { keys: [:one, :other], rule: lambda { |n| n == 1 ? :one : :other } } } }, + fr: { i18n: { plural: { keys: [:one, :other], rule: lambda { |n| n.between?(0, 2) && n != 2 ? :one : :other } } } }, + fur: { i18n: { plural: { keys: [:one, :other], rule: lambda { |n| n == 1 ? :one : :other } } } }, + fy: { i18n: { plural: { keys: [:one, :other], rule: lambda { |n| n == 1 ? :one : :other } } } }, + ga: { i18n: { plural: { keys: [:one, :two, :other], rule: lambda { |n| n == 1 ? :one : n == 2 ? :two : :other } } } }, + gl: { i18n: { plural: { keys: [:one, :other], rule: lambda { |n| n == 1 ? :one : :other } } } }, + gu: { i18n: { plural: { keys: [:one, :other], rule: lambda { |n| n == 1 ? :one : :other } } } }, + guw: { i18n: { plural: { keys: [:one, :other], rule: lambda { |n| [0, 1].include?(n) ? :one : :other } } } }, + ha: { i18n: { plural: { keys: [:one, :other], rule: lambda { |n| n == 1 ? :one : :other } } } }, + he: { i18n: { plural: { keys: [:one, :other], rule: lambda { |n| n == 1 ? :one : :other } } } }, + hi: { i18n: { plural: { keys: [:one, :other], rule: lambda { |n| [0, 1].include?(n) ? :one : :other } } } }, + hr: { i18n: { plural: { keys: [:one, :few, :many, :other], rule: lambda { |n| n % 10 == 1 && n % 100 != 11 ? :one : [2, 3, 4].include?(n % 10) && ![12, 13, 14].include?(n % 100) ? :few : n % 10 == 0 || [5, 6, 7, 8, 9].include?(n % 10) || [11, 12, 13, 14].include?(n % 100) ? :many : :other } } } }, + hu: { i18n: { plural: { keys: [:other], rule: lambda { |n| :other } } } }, + id: { i18n: { plural: { keys: [:other], rule: lambda { |n| :other } } } }, + is: { i18n: { plural: { keys: [:one, :other], rule: lambda { |n| n == 1 ? :one : :other } } } }, + it: { i18n: { plural: { keys: [:one, :other], rule: lambda { |n| n == 1 ? :one : :other } } } }, + iw: { i18n: { plural: { keys: [:one, :other], rule: lambda { |n| n == 1 ? :one : :other } } } }, + ja: { i18n: { plural: { keys: [:other], rule: lambda { |n| :other } } } }, + jv: { i18n: { plural: { keys: [:other], rule: lambda { |n| :other } } } }, + ka: { i18n: { plural: { keys: [:other], rule: lambda { |n| :other } } } }, + km: { i18n: { plural: { keys: [:other], rule: lambda { |n| :other } } } }, + kn: { i18n: { plural: { keys: [:other], rule: lambda { |n| :other } } } }, + ko: { i18n: { plural: { keys: [:other], rule: lambda { |n| :other } } } }, + ku: { i18n: { plural: { keys: [:one, :other], rule: lambda { |n| n == 1 ? :one : :other } } } }, + lb: { i18n: { plural: { keys: [:one, :other], rule: lambda { |n| n == 1 ? :one : :other } } } }, + ln: { i18n: { plural: { keys: [:one, :other], rule: lambda { |n| [0, 1].include?(n) ? :one : :other } } } }, + lt: { i18n: { plural: { keys: [:one, :few, :other], rule: lambda { |n| n % 10 == 1 && ![11, 12, 13, 14, 15, 16, 17, 18, 19].include?(n % 100) ? :one : [2, 3, 4, 5, 6, 7, 8, 9].include?(n % 10) && ![11, 12, 13, 14, 15, 16, 17, 18, 19].include?(n % 100) ? :few : :other } } } }, + lv: { i18n: { plural: { keys: [:zero, :one, :other], rule: lambda { |n| n == 0 ? :zero : n % 10 == 1 && n % 100 != 11 ? :one : :other } } } }, + mg: { i18n: { plural: { keys: [:one, :other], rule: lambda { |n| [0, 1].include?(n) ? :one : :other } } } }, + mk: { i18n: { plural: { keys: [:one, :other], rule: lambda { |n| n % 10 == 1 ? :one : :other } } } }, + ml: { i18n: { plural: { keys: [:one, :other], rule: lambda { |n| n == 1 ? :one : :other } } } }, + mn: { i18n: { plural: { keys: [:one, :other], rule: lambda { |n| n == 1 ? :one : :other } } } }, + mo: { i18n: { plural: { keys: [:one, :few, :other], rule: lambda { |n| n == 1 ? :one : n == 0 ? :few : :other } } } }, + mr: { i18n: { plural: { keys: [:one, :other], rule: lambda { |n| n == 1 ? :one : :other } } } }, + ms: { i18n: { plural: { keys: [:other], rule: lambda { |n| :other } } } }, + mt: { i18n: { plural: { keys: [:one, :few, :many, :other], rule: lambda { |n| n == 1 ? :one : n == 0 || [2, 3, 4, 5, 6, 7, 8, 9, 10].include?(n % 100) ? :few : [11, 12, 13, 14, 15, 16, 17, 18, 19].include?(n % 100) ? :many : :other } } } }, + my: { i18n: { plural: { keys: [:other], rule: lambda { |n| :other } } } }, + nah: { i18n: { plural: { keys: [:one, :other], rule: lambda { |n| n == 1 ? :one : :other } } } }, + nb_NO: { i18n: { plural: { keys: [:one, :other], rule: lambda { |n| n == 1 ? :one : :other } } } }, + ne: { i18n: { plural: { keys: [:one, :other], rule: lambda { |n| n == 1 ? :one : :other } } } }, + nl: { i18n: { plural: { keys: [:one, :other], rule: lambda { |n| n == 1 ? :one : :other } } } }, + nn: { i18n: { plural: { keys: [:one, :other], rule: lambda { |n| n == 1 ? :one : :other } } } }, + no: { i18n: { plural: { keys: [:one, :other], rule: lambda { |n| n == 1 ? :one : :other } } } }, + nso: { i18n: { plural: { keys: [:one, :other], rule: lambda { |n| [0, 1].include?(n) ? :one : :other } } } }, + om: { i18n: { plural: { keys: [:one, :other], rule: lambda { |n| n == 1 ? :one : :other } } } }, + or: { i18n: { plural: { keys: [:one, :other], rule: lambda { |n| n == 1 ? :one : :other } } } }, + pa: { i18n: { plural: { keys: [:one, :other], rule: lambda { |n| n == 1 ? :one : :other } } } }, + pap: { i18n: { plural: { keys: [:one, :other], rule: lambda { |n| n == 1 ? :one : :other } } } }, + pl_PL: { i18n: { plural: { keys: [:one, :few, :other], rule: lambda { |n| n == 1 ? :one : [2, 3, 4].include?(n % 10) && ![12, 13, 14].include?(n % 100) ? :few : :other } } } }, + ps: { i18n: { plural: { keys: [:one, :other], rule: lambda { |n| n == 1 ? :one : :other } } } }, + pt: { i18n: { plural: { keys: [:one, :other], rule: lambda { |n| [0, 1].include?(n) ? :one : :other } } } }, + pt_BR: { i18n: { plural: { keys: [:one, :other], rule: lambda { |n| n == 1 ? :one : :other } } } }, + ro: { i18n: { plural: { keys: [:one, :few, :other], rule: lambda { |n| n == 1 ? :one : n == 0 || ((n % 100) >= 1 && (n % 100) <= 19) ? :few : :other } } } }, + ru: { i18n: { plural: { keys: [:one, :few, :other], rule: lambda { |n| n % 10 == 1 && n % 100 != 11 ? :one : [2, 3, 4].include?(n % 10) && ![12, 13, 14].include?(n % 100) ? :few : :other } } } }, + se: { i18n: { plural: { keys: [:one, :two, :other], rule: lambda { |n| n == 1 ? :one : n == 2 ? :two : :other } } } }, + sh: { i18n: { plural: { keys: [:one, :few, :many, :other], rule: lambda { |n| n % 10 == 1 && n % 100 != 11 ? :one : [2, 3, 4].include?(n % 10) && ![12, 13, 14].include?(n % 100) ? :few : n % 10 == 0 || [5, 6, 7, 8, 9].include?(n % 10) || [11, 12, 13, 14].include?(n % 100) ? :many : :other } } } }, + sk: { i18n: { plural: { keys: [:one, :few, :other], rule: lambda { |n| n == 1 ? :one : [2, 3, 4].include?(n) ? :few : :other } } } }, + sl: { i18n: { plural: { keys: [:one, :two, :few, :other], rule: lambda { |n| n % 100 == 1 ? :one : n % 100 == 2 ? :two : [3, 4].include?(n % 100) ? :few : :other } } } }, + sma: { i18n: { plural: { keys: [:one, :two, :other], rule: lambda { |n| n == 1 ? :one : n == 2 ? :two : :other } } } }, + smi: { i18n: { plural: { keys: [:one, :two, :other], rule: lambda { |n| n == 1 ? :one : n == 2 ? :two : :other } } } }, + smj: { i18n: { plural: { keys: [:one, :two, :other], rule: lambda { |n| n == 1 ? :one : n == 2 ? :two : :other } } } }, + smn: { i18n: { plural: { keys: [:one, :two, :other], rule: lambda { |n| n == 1 ? :one : n == 2 ? :two : :other } } } }, + sms: { i18n: { plural: { keys: [:one, :two, :other], rule: lambda { |n| n == 1 ? :one : n == 2 ? :two : :other } } } }, + so: { i18n: { plural: { keys: [:one, :other], rule: lambda { |n| n == 1 ? :one : :other } } } }, + sq: { i18n: { plural: { keys: [:one, :other], rule: lambda { |n| n == 1 ? :one : :other } } } }, + sr: { i18n: { plural: { keys: [:one, :few, :many, :other], rule: lambda { |n| n % 10 == 1 && n % 100 != 11 ? :one : [2, 3, 4].include?(n % 10) && ![12, 13, 14].include?(n % 100) ? :few : n % 10 == 0 || [5, 6, 7, 8, 9].include?(n % 10) || [11, 12, 13, 14].include?(n % 100) ? :many : :other } } } }, + sv: { i18n: { plural: { keys: [:one, :other], rule: lambda { |n| n == 1 ? :one : :other } } } }, + sw: { i18n: { plural: { keys: [:one, :other], rule: lambda { |n| n == 1 ? :one : :other } } } }, + ta: { i18n: { plural: { keys: [:one, :other], rule: lambda { |n| n == 1 ? :one : :other } } } }, + te: { i18n: { plural: { keys: [:one, :other], rule: lambda { |n| n == 1 ? :one : :other } } } }, + th: { i18n: { plural: { keys: [:other], rule: lambda { |n| :other } } } }, + ti: { i18n: { plural: { keys: [:one, :other], rule: lambda { |n| [0, 1].include?(n) ? :one : :other } } } }, + tk: { i18n: { plural: { keys: [:one, :other], rule: lambda { |n| n == 1 ? :one : :other } } } }, + tl: { i18n: { plural: { keys: [:one, :other], rule: lambda { |n| [0, 1].include?(n) ? :one : :other } } } }, + to: { i18n: { plural: { keys: [:other], rule: lambda { |n| :other } } } }, + tr_TR: { i18n: { plural: { keys: [:other], rule: lambda { |n| :other } } } }, # TODO put this back when translations are correct: :uk => { :i18n => { :plural => { :keys => [:one, :few, :many, :other], :rule => lambda { |n| n % 10 == 1 && n % 100 != 11 ? :one : [2, 3, 4].include?(n % 10) && ![12, 13, 14].include?(n % 100) ? :few : n % 10 == 0 || [5, 6, 7, 8, 9].include?(n % 10) || [11, 12, 13, 14].include?(n % 100) ? :many : :other } } } }, - :uk => { :i18n => { :plural => { :keys => [:one, :few, :other], :rule => lambda { |n| n % 10 == 1 && n % 100 != 11 ? :one : [2, 3, 4].include?(n % 10) && ![12, 13, 14].include?(n % 100) ? :few : n % 10 == 0 || [5, 6, 7, 8, 9].include?(n % 10) || [11, 12, 13, 14].include?(n % 100) ? :other : :other } } } }, - :ur => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| n == 1 ? :one : :other } } } }, - :vi => { :i18n => { :plural => { :keys => [:other], :rule => lambda { |n| :other } } } }, - :wa => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| [0, 1].include?(n) ? :one : :other } } } }, - :yo => { :i18n => { :plural => { :keys => [:other], :rule => lambda { |n| :other } } } }, - :zh => { :i18n => { :plural => { :keys => [:other], :rule => lambda { |n| :other } } } }, - :zh_CN => { :i18n => { :plural => { :keys => [:other], :rule => lambda { |n| :other } } } }, - :zh_TW => { :i18n => { :plural => { :keys => [:other], :rule => lambda { |n| :other } } } }, - :zu => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| n == 1 ? :one : :other } } } } + uk: { i18n: { plural: { keys: [:one, :few, :other], rule: lambda { |n| n % 10 == 1 && n % 100 != 11 ? :one : [2, 3, 4].include?(n % 10) && ![12, 13, 14].include?(n % 100) ? :few : n % 10 == 0 || [5, 6, 7, 8, 9].include?(n % 10) || [11, 12, 13, 14].include?(n % 100) ? :other : :other } } } }, + ur: { i18n: { plural: { keys: [:one, :other], rule: lambda { |n| n == 1 ? :one : :other } } } }, + vi: { i18n: { plural: { keys: [:other], rule: lambda { |n| :other } } } }, + wa: { i18n: { plural: { keys: [:one, :other], rule: lambda { |n| [0, 1].include?(n) ? :one : :other } } } }, + yo: { i18n: { plural: { keys: [:other], rule: lambda { |n| :other } } } }, + zh: { i18n: { plural: { keys: [:other], rule: lambda { |n| :other } } } }, + zh_CN: { i18n: { plural: { keys: [:other], rule: lambda { |n| :other } } } }, + zh_TW: { i18n: { plural: { keys: [:other], rule: lambda { |n| :other } } } }, + zu: { i18n: { plural: { keys: [:one, :other], rule: lambda { |n| n == 1 ? :one : :other } } } } } diff --git a/config/puma.rb b/config/puma.rb index d472c7278f9..85f38250eca 100644 --- a/config/puma.rb +++ b/config/puma.rb @@ -1,4 +1,4 @@ -if ENV['RAILS_ENV']=='production' +if ENV['RAILS_ENV'] == 'production' # First, you need to change these below to your situation. APP_ROOT = '/home/discourse/discourse' @@ -6,11 +6,11 @@ if ENV['RAILS_ENV']=='production' # Second, you can choose how many threads that you are going to run at same time. workers "#{num_workers}" - threads 8,32 + threads 8, 32 # Unless you know what you are changing, do not change them. - bind "unix://#{APP_ROOT}/tmp/sockets/puma.sock" - stdout_redirect "#{APP_ROOT}/log/puma.log","#{APP_ROOT}/log/puma.err.log" + bind "unix://#{APP_ROOT}/tmp/sockets/puma.sock" + stdout_redirect "#{APP_ROOT}/log/puma.log", "#{APP_ROOT}/log/puma.err.log" pidfile "#{APP_ROOT}/tmp/pids/puma.pid" state_path "#{APP_ROOT}/tmp/pids/puma.state" daemonize true diff --git a/config/routes.rb b/config/routes.rb index b95fff1a39d..1aa2b5fd075 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -130,12 +130,11 @@ Discourse::Application.routes.draw do put "anonymize" post "reset_bounce_score" end - get "users/:id.json" => 'users#show', defaults: {format: 'json'} - get 'users/:id/:username' => 'users#show', constraints: {username: USERNAME_ROUTE_FORMAT} + get "users/:id.json" => 'users#show', defaults: { format: 'json' } + get 'users/:id/:username' => 'users#show', constraints: { username: USERNAME_ROUTE_FORMAT } get 'users/:id/:username/badges' => 'users#show' get 'users/:id/:username/tl3_requirements' => 'users#show' - post "users/sync_sso" => "users#sync_sso", constraints: AdminConstraint.new post "users/invite_admin" => "users#invite_admin", constraints: AdminConstraint.new @@ -266,9 +265,9 @@ Discourse::Application.routes.draw do end end - get "memory_stats"=> "diagnostics#memory_stats", constraints: AdminConstraint.new - get "dump_heap"=> "diagnostics#dump_heap", constraints: AdminConstraint.new - get "dump_statement_cache"=> "diagnostics#dump_statement_cache", constraints: AdminConstraint.new + get "memory_stats" => "diagnostics#memory_stats", constraints: AdminConstraint.new + get "dump_heap" => "diagnostics#dump_heap", constraints: AdminConstraint.new + get "dump_statement_cache" => "diagnostics#dump_statement_cache", constraints: AdminConstraint.new resources :watched_words, only: [:index, :create, :update, :destroy], constraints: AdminConstraint.new do collection do @@ -333,7 +332,7 @@ Discourse::Application.routes.draw do post "#{root_path}/read-faq" => "users#read_faq" get "#{root_path}/search/users" => "users#search_users" - get({ "#{root_path}/account-created/" => "users#account_created" }.merge(index == 1 ? { as: :users_account_created } : {as: :old_account_created})) + get({ "#{root_path}/account-created/" => "users#account_created" }.merge(index == 1 ? { as: :users_account_created } : { as: :old_account_created })) get "#{root_path}/account-created/resent" => "users#account_created" get "#{root_path}/account-created/edit-email" => "users#account_created" @@ -348,63 +347,63 @@ Discourse::Application.routes.draw do constraints: { token: /[0-9a-f]+/ } }.merge(index == 1 ? { as: 'confirm_admin' } : {})) post "#{root_path}/confirm-admin/:token" => "users#confirm_admin", constraints: { token: /[0-9a-f]+/ } - get "#{root_path}/:username/private-messages" => "user_actions#private_messages", constraints: {username: USERNAME_ROUTE_FORMAT} - get "#{root_path}/:username/private-messages/:filter" => "user_actions#private_messages", constraints: {username: USERNAME_ROUTE_FORMAT} - get "#{root_path}/:username/messages" => "user_actions#private_messages", constraints: {username: USERNAME_ROUTE_FORMAT} - get "#{root_path}/:username/messages/:filter" => "user_actions#private_messages", constraints: {username: USERNAME_ROUTE_FORMAT} - get "#{root_path}/:username/messages/group/:group_name" => "user_actions#private_messages", constraints: {username: USERNAME_ROUTE_FORMAT, group_name: USERNAME_ROUTE_FORMAT} - get "#{root_path}/:username/messages/group/:group_name/archive" => "user_actions#private_messages", constraints: {username: USERNAME_ROUTE_FORMAT, group_name: USERNAME_ROUTE_FORMAT} - get "#{root_path}/:username.json" => "users#show", constraints: {username: USERNAME_ROUTE_FORMAT}, defaults: {format: :json} + get "#{root_path}/:username/private-messages" => "user_actions#private_messages", constraints: { username: USERNAME_ROUTE_FORMAT } + get "#{root_path}/:username/private-messages/:filter" => "user_actions#private_messages", constraints: { username: USERNAME_ROUTE_FORMAT } + get "#{root_path}/:username/messages" => "user_actions#private_messages", constraints: { username: USERNAME_ROUTE_FORMAT } + get "#{root_path}/:username/messages/:filter" => "user_actions#private_messages", constraints: { username: USERNAME_ROUTE_FORMAT } + get "#{root_path}/:username/messages/group/:group_name" => "user_actions#private_messages", constraints: { username: USERNAME_ROUTE_FORMAT, group_name: USERNAME_ROUTE_FORMAT } + get "#{root_path}/:username/messages/group/:group_name/archive" => "user_actions#private_messages", constraints: { username: USERNAME_ROUTE_FORMAT, group_name: USERNAME_ROUTE_FORMAT } + get "#{root_path}/:username.json" => "users#show", constraints: { username: USERNAME_ROUTE_FORMAT }, defaults: { format: :json } get({ "#{root_path}/:username" => "users#show", constraints: { username: USERNAME_ROUTE_FORMAT, format: /(json|html)/ } }.merge(index == 1 ? { as: 'user' } : {})) - put "#{root_path}/:username" => "users#update", constraints: {username: USERNAME_ROUTE_FORMAT}, defaults: { format: :json } - get "#{root_path}/:username/emails" => "users#check_emails", constraints: {username: USERNAME_ROUTE_FORMAT} + put "#{root_path}/:username" => "users#update", constraints: { username: USERNAME_ROUTE_FORMAT }, defaults: { format: :json } + get "#{root_path}/:username/emails" => "users#check_emails", constraints: { username: USERNAME_ROUTE_FORMAT } get({ "#{root_path}/:username/preferences" => "users#preferences", constraints: { username: USERNAME_ROUTE_FORMAT } }.merge(index == 1 ? { as: :email_preferences } : {})) - get "#{root_path}/:username/preferences/email" => "users_email#index", constraints: {username: USERNAME_ROUTE_FORMAT} - get "#{root_path}/:username/preferences/account" => "users#preferences", constraints: {username: USERNAME_ROUTE_FORMAT} - get "#{root_path}/:username/preferences/profile" => "users#preferences", constraints: {username: USERNAME_ROUTE_FORMAT} - get "#{root_path}/:username/preferences/emails" => "users#preferences", constraints: {username: USERNAME_ROUTE_FORMAT} - get "#{root_path}/:username/preferences/notifications" => "users#preferences", constraints: {username: USERNAME_ROUTE_FORMAT} - get "#{root_path}/:username/preferences/categories" => "users#preferences", constraints: {username: USERNAME_ROUTE_FORMAT} - get "#{root_path}/:username/preferences/tags" => "users#preferences", constraints: {username: USERNAME_ROUTE_FORMAT} - get "#{root_path}/:username/preferences/interface" => "users#preferences", constraints: {username: USERNAME_ROUTE_FORMAT} - get "#{root_path}/:username/preferences/apps" => "users#preferences", constraints: {username: USERNAME_ROUTE_FORMAT} - put "#{root_path}/:username/preferences/email" => "users_email#update", constraints: {username: USERNAME_ROUTE_FORMAT} - get "#{root_path}/:username/preferences/about-me" => "users#preferences", constraints: {username: USERNAME_ROUTE_FORMAT} - get "#{root_path}/:username/preferences/badge_title" => "users#preferences", constraints: {username: USERNAME_ROUTE_FORMAT} - put "#{root_path}/:username/preferences/badge_title" => "users#badge_title", constraints: {username: USERNAME_ROUTE_FORMAT} - get "#{root_path}/:username/preferences/username" => "users#preferences", constraints: {username: USERNAME_ROUTE_FORMAT} - put "#{root_path}/:username/preferences/username" => "users#username", constraints: {username: USERNAME_ROUTE_FORMAT} - delete "#{root_path}/:username/preferences/user_image" => "users#destroy_user_image", constraints: {username: USERNAME_ROUTE_FORMAT} - put "#{root_path}/:username/preferences/avatar/pick" => "users#pick_avatar", constraints: {username: USERNAME_ROUTE_FORMAT} - get "#{root_path}/:username/preferences/card-badge" => "users#card_badge", constraints: {username: USERNAME_ROUTE_FORMAT} - put "#{root_path}/:username/preferences/card-badge" => "users#update_card_badge", constraints: {username: USERNAME_ROUTE_FORMAT} - get "#{root_path}/:username/staff-info" => "users#staff_info", constraints: {username: USERNAME_ROUTE_FORMAT} - get "#{root_path}/:username/summary" => "users#summary", constraints: {username: USERNAME_ROUTE_FORMAT} - get "#{root_path}/:username/invited" => "users#invited", constraints: {username: USERNAME_ROUTE_FORMAT} - get "#{root_path}/:username/invited_count" => "users#invited_count", constraints: {username: USERNAME_ROUTE_FORMAT} - get "#{root_path}/:username/invited/:filter" => "users#invited", constraints: {username: USERNAME_ROUTE_FORMAT} + get "#{root_path}/:username/preferences/email" => "users_email#index", constraints: { username: USERNAME_ROUTE_FORMAT } + get "#{root_path}/:username/preferences/account" => "users#preferences", constraints: { username: USERNAME_ROUTE_FORMAT } + get "#{root_path}/:username/preferences/profile" => "users#preferences", constraints: { username: USERNAME_ROUTE_FORMAT } + get "#{root_path}/:username/preferences/emails" => "users#preferences", constraints: { username: USERNAME_ROUTE_FORMAT } + get "#{root_path}/:username/preferences/notifications" => "users#preferences", constraints: { username: USERNAME_ROUTE_FORMAT } + get "#{root_path}/:username/preferences/categories" => "users#preferences", constraints: { username: USERNAME_ROUTE_FORMAT } + get "#{root_path}/:username/preferences/tags" => "users#preferences", constraints: { username: USERNAME_ROUTE_FORMAT } + get "#{root_path}/:username/preferences/interface" => "users#preferences", constraints: { username: USERNAME_ROUTE_FORMAT } + get "#{root_path}/:username/preferences/apps" => "users#preferences", constraints: { username: USERNAME_ROUTE_FORMAT } + put "#{root_path}/:username/preferences/email" => "users_email#update", constraints: { username: USERNAME_ROUTE_FORMAT } + get "#{root_path}/:username/preferences/about-me" => "users#preferences", constraints: { username: USERNAME_ROUTE_FORMAT } + get "#{root_path}/:username/preferences/badge_title" => "users#preferences", constraints: { username: USERNAME_ROUTE_FORMAT } + put "#{root_path}/:username/preferences/badge_title" => "users#badge_title", constraints: { username: USERNAME_ROUTE_FORMAT } + get "#{root_path}/:username/preferences/username" => "users#preferences", constraints: { username: USERNAME_ROUTE_FORMAT } + put "#{root_path}/:username/preferences/username" => "users#username", constraints: { username: USERNAME_ROUTE_FORMAT } + delete "#{root_path}/:username/preferences/user_image" => "users#destroy_user_image", constraints: { username: USERNAME_ROUTE_FORMAT } + put "#{root_path}/:username/preferences/avatar/pick" => "users#pick_avatar", constraints: { username: USERNAME_ROUTE_FORMAT } + get "#{root_path}/:username/preferences/card-badge" => "users#card_badge", constraints: { username: USERNAME_ROUTE_FORMAT } + put "#{root_path}/:username/preferences/card-badge" => "users#update_card_badge", constraints: { username: USERNAME_ROUTE_FORMAT } + get "#{root_path}/:username/staff-info" => "users#staff_info", constraints: { username: USERNAME_ROUTE_FORMAT } + get "#{root_path}/:username/summary" => "users#summary", constraints: { username: USERNAME_ROUTE_FORMAT } + get "#{root_path}/:username/invited" => "users#invited", constraints: { username: USERNAME_ROUTE_FORMAT } + get "#{root_path}/:username/invited_count" => "users#invited_count", constraints: { username: USERNAME_ROUTE_FORMAT } + get "#{root_path}/:username/invited/:filter" => "users#invited", constraints: { username: USERNAME_ROUTE_FORMAT } post "#{root_path}/action/send_activation_email" => "users#send_activation_email" - get "#{root_path}/:username/summary" => "users#show", constraints: {username: USERNAME_ROUTE_FORMAT} - get "#{root_path}/:username/activity/topics.rss" => "list#user_topics_feed", format: :rss, constraints: {username: USERNAME_ROUTE_FORMAT} - get "#{root_path}/:username/activity.rss" => "posts#user_posts_feed", format: :rss, constraints: {username: USERNAME_ROUTE_FORMAT} - get "#{root_path}/:username/activity" => "users#show", constraints: {username: USERNAME_ROUTE_FORMAT} - get "#{root_path}/:username/activity/:filter" => "users#show", constraints: {username: USERNAME_ROUTE_FORMAT} - get "#{root_path}/:username/badges" => "users#show", constraints: {username: USERNAME_ROUTE_FORMAT} - get "#{root_path}/:username/notifications" => "users#show", constraints: {username: USERNAME_ROUTE_FORMAT} - get "#{root_path}/:username/notifications/:filter" => "users#show", constraints: {username: USERNAME_ROUTE_FORMAT} - get "#{root_path}/:username/activity/pending" => "users#show", constraints: {username: USERNAME_ROUTE_FORMAT} - delete "#{root_path}/:username" => "users#destroy", constraints: {username: USERNAME_ROUTE_FORMAT} - get "#{root_path}/by-external/:external_id" => "users#show", constraints: {external_id: /[^\/]+/} - get "#{root_path}/:username/flagged-posts" => "users#show", constraints: {username: USERNAME_ROUTE_FORMAT} - get "#{root_path}/:username/deleted-posts" => "users#show", constraints: {username: USERNAME_ROUTE_FORMAT} - get "#{root_path}/:username/topic-tracking-state" => "users#topic_tracking_state", constraints: {username: USERNAME_ROUTE_FORMAT} + get "#{root_path}/:username/summary" => "users#show", constraints: { username: USERNAME_ROUTE_FORMAT } + get "#{root_path}/:username/activity/topics.rss" => "list#user_topics_feed", format: :rss, constraints: { username: USERNAME_ROUTE_FORMAT } + get "#{root_path}/:username/activity.rss" => "posts#user_posts_feed", format: :rss, constraints: { username: USERNAME_ROUTE_FORMAT } + get "#{root_path}/:username/activity" => "users#show", constraints: { username: USERNAME_ROUTE_FORMAT } + get "#{root_path}/:username/activity/:filter" => "users#show", constraints: { username: USERNAME_ROUTE_FORMAT } + get "#{root_path}/:username/badges" => "users#show", constraints: { username: USERNAME_ROUTE_FORMAT } + get "#{root_path}/:username/notifications" => "users#show", constraints: { username: USERNAME_ROUTE_FORMAT } + get "#{root_path}/:username/notifications/:filter" => "users#show", constraints: { username: USERNAME_ROUTE_FORMAT } + get "#{root_path}/:username/activity/pending" => "users#show", constraints: { username: USERNAME_ROUTE_FORMAT } + delete "#{root_path}/:username" => "users#destroy", constraints: { username: USERNAME_ROUTE_FORMAT } + get "#{root_path}/by-external/:external_id" => "users#show", constraints: { external_id: /[^\/]+/ } + get "#{root_path}/:username/flagged-posts" => "users#show", constraints: { username: USERNAME_ROUTE_FORMAT } + get "#{root_path}/:username/deleted-posts" => "users#show", constraints: { username: USERNAME_ROUTE_FORMAT } + get "#{root_path}/:username/topic-tracking-state" => "users#topic_tracking_state", constraints: { username: USERNAME_ROUTE_FORMAT } end - get "user-badges/:username.json" => "user_badges#username", constraints: {username: USERNAME_ROUTE_FORMAT}, defaults: {format: :json} - get "user-badges/:username" => "user_badges#username", constraints: {username: USERNAME_ROUTE_FORMAT} + get "user-badges/:username.json" => "user_badges#username", constraints: { username: USERNAME_ROUTE_FORMAT }, defaults: { format: :json } + get "user-badges/:username" => "user_badges#username", constraints: { username: USERNAME_ROUTE_FORMAT } - post "user_avatar/:username/refresh_gravatar" => "user_avatars#refresh_gravatar", constraints: {username: USERNAME_ROUTE_FORMAT} - get "letter_avatar/:username/:size/:version.png" => "user_avatars#show_letter", format: false, constraints: { hostname: /[\w\.-]+/, size: /\d+/, username: USERNAME_ROUTE_FORMAT} + post "user_avatar/:username/refresh_gravatar" => "user_avatars#refresh_gravatar", constraints: { username: USERNAME_ROUTE_FORMAT } + get "letter_avatar/:username/:size/:version.png" => "user_avatars#show_letter", format: false, constraints: { hostname: /[\w\.-]+/, size: /\d+/, username: USERNAME_ROUTE_FORMAT } get "user_avatar/:hostname/:username/:size/:version.png" => "user_avatars#show", format: false, constraints: { hostname: /[\w\.-]+/, size: /\d+/, username: USERNAME_ROUTE_FORMAT } # in most production settings this is bypassed @@ -428,8 +427,8 @@ Discourse::Application.routes.draw do get "private-posts" => "posts#latest", id: "private_posts" get "posts/by_number/:topic_id/:post_number" => "posts#by_number" get "posts/:id/reply-history" => "posts#reply_history" - get "posts/:username/deleted" => "posts#deleted_posts", constraints: {username: USERNAME_ROUTE_FORMAT} - get "posts/:username/flagged" => "posts#flagged_posts", constraints: {username: USERNAME_ROUTE_FORMAT} + get "posts/:username/deleted" => "posts#deleted_posts", constraints: { username: USERNAME_ROUTE_FORMAT } + get "posts/:username/flagged" => "posts#flagged_posts", constraints: { username: USERNAME_ROUTE_FORMAT } resources :groups, id: USERNAME_ROUTE_FORMAT do get "posts.rss" => "groups#posts_feed", format: :rss @@ -511,10 +510,9 @@ Discourse::Application.routes.draw do get "/badges/:id(/:slug)" => "badges#show" resources :user_badges, only: [:index, :create, :destroy] - get '/c', to: redirect('/categories') - resources :categories, :except => :show + resources :categories, except: :show post "category/:category_id/move" => "categories#move" post "categories/reorder" => "categories#reorder" post "category/:category_id/notifications" => "categories#set_notifications" @@ -577,11 +575,11 @@ Discourse::Application.routes.draw do resources :similar_topics get "topics/feature_stats" - get "topics/created-by/:username" => "list#topics_by", as: "topics_by", constraints: {username: USERNAME_ROUTE_FORMAT} - get "topics/private-messages/:username" => "list#private_messages", as: "topics_private_messages", constraints: {username: USERNAME_ROUTE_FORMAT} - get "topics/private-messages-sent/:username" => "list#private_messages_sent", as: "topics_private_messages_sent", constraints: {username: USERNAME_ROUTE_FORMAT} - get "topics/private-messages-archive/:username" => "list#private_messages_archive", as: "topics_private_messages_archive", constraints: {username: USERNAME_ROUTE_FORMAT} - get "topics/private-messages-unread/:username" => "list#private_messages_unread", as: "topics_private_messages_unread", constraints: {username: USERNAME_ROUTE_FORMAT} + get "topics/created-by/:username" => "list#topics_by", as: "topics_by", constraints: { username: USERNAME_ROUTE_FORMAT } + get "topics/private-messages/:username" => "list#private_messages", as: "topics_private_messages", constraints: { username: USERNAME_ROUTE_FORMAT } + get "topics/private-messages-sent/:username" => "list#private_messages_sent", as: "topics_private_messages_sent", constraints: { username: USERNAME_ROUTE_FORMAT } + get "topics/private-messages-archive/:username" => "list#private_messages_archive", as: "topics_private_messages_archive", constraints: { username: USERNAME_ROUTE_FORMAT } + get "topics/private-messages-unread/:username" => "list#private_messages_unread", as: "topics_private_messages_unread", constraints: { username: USERNAME_ROUTE_FORMAT } get "topics/private-messages-group/:username/:group_name.json" => "list#private_messages_group", as: "topics_private_messages_group", constraints: { username: USERNAME_ROUTE_FORMAT, group_name: USERNAME_ROUTE_FORMAT @@ -601,49 +599,49 @@ Discourse::Application.routes.draw do # Topic routes get "t/id_for/:slug" => "topics#id_for_slug" - get "t/:slug/:topic_id/print" => "topics#show", format: :html, print: true, constraints: {topic_id: /\d+/} - get "t/:slug/:topic_id/wordpress" => "topics#wordpress", constraints: {topic_id: /\d+/} - get "t/:topic_id/wordpress" => "topics#wordpress", constraints: {topic_id: /\d+/} - get "t/:slug/:topic_id/moderator-liked" => "topics#moderator_liked", constraints: {topic_id: /\d+/} - get "t/:slug/:topic_id/summary" => "topics#show", defaults: {summary: true}, constraints: {topic_id: /\d+/} - get "t/:slug/:topic_id/unsubscribe" => "topics#unsubscribe", constraints: {topic_id: /\d+/} - get "t/:topic_id/unsubscribe" => "topics#unsubscribe", constraints: {topic_id: /\d+/} - get "t/:topic_id/summary" => "topics#show", constraints: {topic_id: /\d+/} - put "t/:slug/:topic_id" => "topics#update", constraints: {topic_id: /\d+/} - put "t/:slug/:topic_id/star" => "topics#star", constraints: {topic_id: /\d+/} - put "t/:topic_id/star" => "topics#star", constraints: {topic_id: /\d+/} - put "t/:slug/:topic_id/status" => "topics#status", constraints: {topic_id: /\d+/} - put "t/:topic_id/status" => "topics#status", constraints: {topic_id: /\d+/} - put "t/:topic_id/clear-pin" => "topics#clear_pin", constraints: {topic_id: /\d+/} - put "t/:topic_id/re-pin" => "topics#re_pin", constraints: {topic_id: /\d+/} - put "t/:topic_id/mute" => "topics#mute", constraints: {topic_id: /\d+/} - put "t/:topic_id/unmute" => "topics#unmute", constraints: {topic_id: /\d+/} - post "t/:topic_id/timer" => "topics#timer", constraints: {topic_id: /\d+/} - put "t/:topic_id/make-banner" => "topics#make_banner", constraints: {topic_id: /\d+/} - put "t/:topic_id/remove-banner" => "topics#remove_banner", constraints: {topic_id: /\d+/} - put "t/:topic_id/remove-allowed-user" => "topics#remove_allowed_user", constraints: {topic_id: /\d+/} - put "t/:topic_id/remove-allowed-group" => "topics#remove_allowed_group", constraints: {topic_id: /\d+/} - put "t/:topic_id/recover" => "topics#recover", constraints: {topic_id: /\d+/} - get "t/:topic_id/:post_number" => "topics#show", constraints: {topic_id: /\d+/, post_number: /\d+/} - get "t/:topic_id/last" => "topics#show", post_number: 99999999, constraints: {topic_id: /\d+/} - get "t/:slug/:topic_id.rss" => "topics#feed", format: :rss, constraints: {topic_id: /\d+/} - get "t/:slug/:topic_id" => "topics#show", constraints: {topic_id: /\d+/} - get "t/:slug/:topic_id/:post_number" => "topics#show", constraints: {topic_id: /\d+/, post_number: /\d+/} - get "t/:slug/:topic_id/last" => "topics#show", post_number: 99999999, constraints: {topic_id: /\d+/} - get "t/:topic_id/posts" => "topics#posts", constraints: {topic_id: /\d+/}, format: :json - get "t/:topic_id/excerpts" => "topics#excerpts", constraints: {topic_id: /\d+/}, format: :json - post "t/:topic_id/timings" => "topics#timings", constraints: {topic_id: /\d+/} - post "t/:topic_id/invite" => "topics#invite", constraints: {topic_id: /\d+/} - post "t/:topic_id/invite-group" => "topics#invite_group", constraints: {topic_id: /\d+/} - post "t/:topic_id/move-posts" => "topics#move_posts", constraints: {topic_id: /\d+/} - post "t/:topic_id/merge-topic" => "topics#merge_topic", constraints: {topic_id: /\d+/} - post "t/:topic_id/change-owner" => "topics#change_post_owners", constraints: {topic_id: /\d+/} - put "t/:topic_id/change-timestamp" => "topics#change_timestamps", constraints: {topic_id: /\d+/} - delete "t/:topic_id/timings" => "topics#destroy_timings", constraints: {topic_id: /\d+/} - put "t/:topic_id/bookmark" => "topics#bookmark", constraints: {topic_id: /\d+/} - put "t/:topic_id/remove_bookmarks" => "topics#remove_bookmarks", constraints: {topic_id: /\d+/} + get "t/:slug/:topic_id/print" => "topics#show", format: :html, print: true, constraints: { topic_id: /\d+/ } + get "t/:slug/:topic_id/wordpress" => "topics#wordpress", constraints: { topic_id: /\d+/ } + get "t/:topic_id/wordpress" => "topics#wordpress", constraints: { topic_id: /\d+/ } + get "t/:slug/:topic_id/moderator-liked" => "topics#moderator_liked", constraints: { topic_id: /\d+/ } + get "t/:slug/:topic_id/summary" => "topics#show", defaults: { summary: true }, constraints: { topic_id: /\d+/ } + get "t/:slug/:topic_id/unsubscribe" => "topics#unsubscribe", constraints: { topic_id: /\d+/ } + get "t/:topic_id/unsubscribe" => "topics#unsubscribe", constraints: { topic_id: /\d+/ } + get "t/:topic_id/summary" => "topics#show", constraints: { topic_id: /\d+/ } + put "t/:slug/:topic_id" => "topics#update", constraints: { topic_id: /\d+/ } + put "t/:slug/:topic_id/star" => "topics#star", constraints: { topic_id: /\d+/ } + put "t/:topic_id/star" => "topics#star", constraints: { topic_id: /\d+/ } + put "t/:slug/:topic_id/status" => "topics#status", constraints: { topic_id: /\d+/ } + put "t/:topic_id/status" => "topics#status", constraints: { topic_id: /\d+/ } + put "t/:topic_id/clear-pin" => "topics#clear_pin", constraints: { topic_id: /\d+/ } + put "t/:topic_id/re-pin" => "topics#re_pin", constraints: { topic_id: /\d+/ } + put "t/:topic_id/mute" => "topics#mute", constraints: { topic_id: /\d+/ } + put "t/:topic_id/unmute" => "topics#unmute", constraints: { topic_id: /\d+/ } + post "t/:topic_id/timer" => "topics#timer", constraints: { topic_id: /\d+/ } + put "t/:topic_id/make-banner" => "topics#make_banner", constraints: { topic_id: /\d+/ } + put "t/:topic_id/remove-banner" => "topics#remove_banner", constraints: { topic_id: /\d+/ } + put "t/:topic_id/remove-allowed-user" => "topics#remove_allowed_user", constraints: { topic_id: /\d+/ } + put "t/:topic_id/remove-allowed-group" => "topics#remove_allowed_group", constraints: { topic_id: /\d+/ } + put "t/:topic_id/recover" => "topics#recover", constraints: { topic_id: /\d+/ } + get "t/:topic_id/:post_number" => "topics#show", constraints: { topic_id: /\d+/, post_number: /\d+/ } + get "t/:topic_id/last" => "topics#show", post_number: 99999999, constraints: { topic_id: /\d+/ } + get "t/:slug/:topic_id.rss" => "topics#feed", format: :rss, constraints: { topic_id: /\d+/ } + get "t/:slug/:topic_id" => "topics#show", constraints: { topic_id: /\d+/ } + get "t/:slug/:topic_id/:post_number" => "topics#show", constraints: { topic_id: /\d+/, post_number: /\d+/ } + get "t/:slug/:topic_id/last" => "topics#show", post_number: 99999999, constraints: { topic_id: /\d+/ } + get "t/:topic_id/posts" => "topics#posts", constraints: { topic_id: /\d+/ }, format: :json + get "t/:topic_id/excerpts" => "topics#excerpts", constraints: { topic_id: /\d+/ }, format: :json + post "t/:topic_id/timings" => "topics#timings", constraints: { topic_id: /\d+/ } + post "t/:topic_id/invite" => "topics#invite", constraints: { topic_id: /\d+/ } + post "t/:topic_id/invite-group" => "topics#invite_group", constraints: { topic_id: /\d+/ } + post "t/:topic_id/move-posts" => "topics#move_posts", constraints: { topic_id: /\d+/ } + post "t/:topic_id/merge-topic" => "topics#merge_topic", constraints: { topic_id: /\d+/ } + post "t/:topic_id/change-owner" => "topics#change_post_owners", constraints: { topic_id: /\d+/ } + put "t/:topic_id/change-timestamp" => "topics#change_timestamps", constraints: { topic_id: /\d+/ } + delete "t/:topic_id/timings" => "topics#destroy_timings", constraints: { topic_id: /\d+/ } + put "t/:topic_id/bookmark" => "topics#bookmark", constraints: { topic_id: /\d+/ } + put "t/:topic_id/remove_bookmarks" => "topics#remove_bookmarks", constraints: { topic_id: /\d+/ } - post "t/:topic_id/notifications" => "topics#set_notifications" , constraints: {topic_id: /\d+/} + post "t/:topic_id/notifications" => "topics#set_notifications" , constraints: { topic_id: /\d+/ } get "p/:post_id(/:user_id)" => "posts#short_link" get "/posts/:id/cooked" => "posts#cooked" @@ -724,12 +722,12 @@ Discourse::Application.routes.draw do end Discourse.filters.each do |filter| - root to: "list##{filter}", constraints: HomePageConstraint.new("#{filter}"), :as => "list_#{filter}" + root to: "list##{filter}", constraints: HomePageConstraint.new("#{filter}"), as: "list_#{filter}" end # special case for categories - root to: "categories#index", constraints: HomePageConstraint.new("categories"), :as => "categories_index" + root to: "categories#index", constraints: HomePageConstraint.new("categories"), as: "categories_index" # special case for top - root to: "list#top", constraints: HomePageConstraint.new("top"), :as => "top_lists" + root to: "list#top", constraints: HomePageConstraint.new("top"), as: "top_lists" root to: 'finish_installation#index', constraints: HomePageConstraint.new("finish_installation"), as: 'installation_redirect' diff --git a/config/unicorn.conf.rb b/config/unicorn.conf.rb index 716c96cc984..e0d0894cec6 100644 --- a/config/unicorn.conf.rb +++ b/config/unicorn.conf.rb @@ -126,9 +126,9 @@ before_fork do |server, worker| def max_rss rss = `ps -eo rss,args | grep sidekiq | grep -v grep | awk '{print $1}'` - .split("\n") - .map(&:to_i) - .max + .split("\n") + .map(&:to_i) + .max rss ||= 0 @@ -146,9 +146,9 @@ before_fork do |server, worker| def force_kill_rogue_sidekiq info = `ps -eo pid,rss,args | grep sidekiq | grep -v grep | awk '{print $1,$2}'` info.split("\n").each do |row| - pid,mem = row.split(" ").map(&:to_i) - if pid > 0 && (mem*1024) > max_allowed_size - Rails.logger.warn "Detected rogue Sidekiq pid #{pid} mem #{mem*1024}, killing" + pid, mem = row.split(" ").map(&:to_i) + if pid > 0 && (mem * 1024) > max_allowed_size + Rails.logger.warn "Detected rogue Sidekiq pid #{pid} mem #{mem * 1024}, killing" Process.kill("KILL", pid) rescue nil end end @@ -199,7 +199,6 @@ before_fork do |server, worker| ActiveRecord::Base.connection.disconnect! $redis.client.disconnect - # Throttle the master from forking too quickly by sleeping. Due # to the implementation of standard Unix signal handlers, this # helps (but does not completely) prevent identical, repeated signals diff --git a/db/fixtures/001_categories.rb b/db/fixtures/001_categories.rb index 1a0282b84e9..4dc13268ac5 100644 --- a/db/fixtures/001_categories.rb +++ b/db/fixtures/001_categories.rb @@ -30,7 +30,7 @@ ColumnDropper.drop( table: 'categories', after_migration: 'AddUploadsToCategories', columns: ['logo_url', 'background_url'], - on_drop: ->(){ + on_drop: ->() { STDERR.puts 'Removing superflous categories columns!' } ) diff --git a/db/fixtures/002_groups.rb b/db/fixtures/002_groups.rb index 68912df848c..487263f6abe 100644 --- a/db/fixtures/002_groups.rb +++ b/db/fixtures/002_groups.rb @@ -9,7 +9,7 @@ ColumnDropper.drop( table: 'groups', after_migration: 'AddVisibleBackToGroups', columns: %w[visible], - on_drop: ->(){ + on_drop: ->() { STDERR.puts 'Removing superflous visible group column!' } ) diff --git a/db/fixtures/006_badges.rb b/db/fixtures/006_badges.rb index a8f55dd6f83..22cf2c77147 100644 --- a/db/fixtures/006_badges.rb +++ b/db/fixtures/006_badges.rb @@ -142,9 +142,9 @@ Badge.seed do |b| end [ - [Badge::Promoter,"Promoter",BadgeType::Bronze,1,0], - [Badge::Campaigner,"Campaigner",BadgeType::Silver,3,1], - [Badge::Champion,"Champion",BadgeType::Gold,5,2], + [Badge::Promoter, "Promoter", BadgeType::Bronze, 1, 0], + [Badge::Campaigner, "Campaigner", BadgeType::Silver, 3, 1], + [Badge::Champion, "Champion", BadgeType::Gold, 5, 2], ].each do |id, name, type, count, trust_level| Badge.seed do |b| b.id = id @@ -154,7 +154,7 @@ end b.multiple_grant = false b.target_posts = false b.show_posts = false - b.query = BadgeQueries.invite_badge(count,trust_level) + b.query = BadgeQueries.invite_badge(count, trust_level) b.default_badge_grouping_id = BadgeGrouping::Community # daily is good enough b.trigger = Badge::Trigger::None @@ -307,7 +307,6 @@ end end end - [ [Badge::ThankYou, "Thank You", BadgeType::Bronze, 20, 10], [Badge::GivesBack, "Gives Back", BadgeType::Silver, 100, 100], diff --git a/db/fixtures/009_users.rb b/db/fixtures/009_users.rb index 8d84fad2dad..937faa20cf7 100644 --- a/db/fixtures/009_users.rb +++ b/db/fixtures/009_users.rb @@ -33,7 +33,6 @@ UserOption.where(user_id: -1).update_all( Group.user_trust_level_change!(-1, TrustLevel[4]) - ColumnDropper.drop( table: 'users', after_migration: 'AddUserAuthTokens', @@ -55,7 +54,7 @@ ColumnDropper.drop( last_redirected_to_top_at auth_token auth_token_updated_at ], - on_drop: ->(){ + on_drop: ->() { STDERR.puts 'Removing superflous users columns!' } ) diff --git a/db/fixtures/501_meta_category.rb b/db/fixtures/501_meta_category.rb index 9996b2abc81..38ed96aaea0 100644 --- a/db/fixtures/501_meta_category.rb +++ b/db/fixtures/501_meta_category.rb @@ -17,7 +17,7 @@ unless Rails.env.test? raise "Failed meta topic" end - meta.set_permissions(:everyone => :full) + meta.set_permissions(everyone: :full) meta.topic_id = post.topic.id unless meta.save puts meta.errors.full_messages diff --git a/db/fixtures/502_staff_category.rb b/db/fixtures/502_staff_category.rb index f1b62c1bf2c..54faa6385bf 100644 --- a/db/fixtures/502_staff_category.rb +++ b/db/fixtures/502_staff_category.rb @@ -1,6 +1,6 @@ unless Rails.env.test? staff = Category.find_by(id: SiteSetting.staff_category_id) - if staff and !staff.group_ids.include?(Group[:staff].id) + if staff && !staff.group_ids.include?(Group[:staff].id) # Add permissions and a description to the Staff category. diff --git a/db/fixtures/600_themes.rb b/db/fixtures/600_themes.rb index 0ec6e274d28..5b141c57ad7 100644 --- a/db/fixtures/600_themes.rb +++ b/db/fixtures/600_themes.rb @@ -7,13 +7,13 @@ if !Theme.exists? dark_scheme ||= ColorScheme.create_from_base(name: name, via_wizard: true, base_scheme_id: "dark") name = I18n.t('color_schemes.dark_theme_name') - _dark_theme = Theme.create(name: name, user_id: -1, - color_scheme_id: dark_scheme.id, - user_selectable: true) + _dark_theme = Theme.create(name: name, user_id: -1, + color_scheme_id: dark_scheme.id, + user_selectable: true) name = I18n.t('color_schemes.default_theme_name') - default_theme = Theme.create(name: name, user_id: -1, - user_selectable: true) + default_theme = Theme.create(name: name, user_id: -1, + user_selectable: true) default_theme.set_default! end @@ -22,7 +22,7 @@ ColumnDropper.drop( table: 'theme_fields', after_migration: 'AddUploadIdToThemeFields', columns: ['target'], - on_drop: ->(){ + on_drop: ->() { STDERR.puts 'Removing superflous theme_fields target column!' } ) diff --git a/db/fixtures/999_delayed.rb b/db/fixtures/999_delayed.rb index 1141e13e64a..4d69a58267d 100644 --- a/db/fixtures/999_delayed.rb +++ b/db/fixtures/999_delayed.rb @@ -6,7 +6,7 @@ TableMigrationHelper.delayed_drop( old_name: 'topic_status_updates', new_name: 'topic_timers', after_migration: 'RenameTopicStatusUpdatesToTopicTimers', - on_drop: ->(){ + on_drop: ->() { STDERR.puts "Dropping topic_status_updates. It was moved to topic_timers." } ) diff --git a/db/fixtures/999_topics.rb b/db/fixtures/999_topics.rb index 541cacad12c..25958a8c694 100644 --- a/db/fixtures/999_topics.rb +++ b/db/fixtures/999_topics.rb @@ -6,9 +6,9 @@ staff = Category.find_by(id: SiteSetting.staff_category_id) seed_welcome_topics = (Topic.where('id NOT IN (SELECT topic_id from categories where topic_id is not null)').count == 0 && !Rails.env.test?) unless Rails.env.test? - def create_static_page_topic(site_setting_key, title_key, body_key, body_override, category, description, params={}) + def create_static_page_topic(site_setting_key, title_key, body_key, body_override, category, description, params = {}) unless SiteSetting.send(site_setting_key) > 0 - creator = PostCreator.new( Discourse.system_user, + creator = PostCreator.new(Discourse.system_user, title: I18n.t(title_key, default: I18n.t(title_key, locale: :en)), raw: body_override.present? ? body_override : I18n.t(body_key, params.merge(default: I18n.t(body_key, params.merge(locale: :en)))), skip_validations: true, @@ -19,18 +19,16 @@ unless Rails.env.test? SiteSetting.send("#{site_setting_key}=", post.topic_id) - _reply = PostCreator.create( Discourse.system_user, + _reply = PostCreator.create(Discourse.system_user, raw: I18n.t('static_topic_first_reply', page_name: I18n.t(title_key, default: I18n.t(title_key, locale: :en))), skip_validations: true, - topic_id: post.topic_id ) + topic_id: post.topic_id) end end - create_static_page_topic('tos_topic_id', 'tos_topic.title', "tos_topic.body", nil, staff, "terms of service", { - company_domain: "company_domain", - company_full_name: "company_full_name", - company_name: "company_short_name" - }) + create_static_page_topic('tos_topic_id', 'tos_topic.title', "tos_topic.body", nil, staff, "terms of service", company_domain: "company_domain", + company_full_name: "company_full_name", + company_name: "company_short_name") create_static_page_topic('guidelines_topic_id', 'guidelines_topic.title', "guidelines_topic.body", nil, staff, "guidelines") @@ -57,15 +55,13 @@ if seed_welcome_topics end welcome = File.read(filename) - PostCreator.create( Discourse.system_user, + PostCreator.create(Discourse.system_user, raw: welcome, title: DiscoursePluginRegistry.seed_data["admin_quick_start_title"] || "READ ME FIRST: Admin Quick Start Guide", skip_validations: true, category: staff ? staff.name : nil) end - - # run this later, cause we need to make sure new application controller resilience is in place first ColumnDropper.drop( @@ -74,7 +70,7 @@ ColumnDropper.drop( columns: %w{ first_topic_unread_at }, - on_drop: ->(){ + on_drop: ->() { STDERR.puts "Removing superflous user stats columns!" ActiveRecord::Base.exec_sql "DROP FUNCTION IF EXISTS first_unread_topic_for(int)" } @@ -91,7 +87,7 @@ ColumnDropper.drop( notify_user_count last_unread_at }, - on_drop: ->(){ + on_drop: ->() { STDERR.puts "Removing superflous topic columns!" } ) @@ -106,7 +102,7 @@ ColumnDropper.drop( auto_close_based_on_last_post auto_close_hours }, - on_drop: ->(){ + on_drop: ->() { STDERR.puts "Removing superflous topic columns!" }, delay: 3600 diff --git a/db/migrate/20120502192121_add_last_post_user_id_to_forum_threads.rb b/db/migrate/20120502192121_add_last_post_user_id_to_forum_threads.rb index 9f7daa2742e..28e3371745c 100644 --- a/db/migrate/20120502192121_add_last_post_user_id_to_forum_threads.rb +++ b/db/migrate/20120502192121_add_last_post_user_id_to_forum_threads.rb @@ -3,7 +3,6 @@ class AddLastPostUserIdToForumThreads < ActiveRecord::Migration def up add_column :forum_threads, :last_post_user_id, :integer - execute "update forum_threads t set last_post_user_id = (select user_id from posts where forum_thread_id = t.Id order by post_number desc limit 1)" diff --git a/db/migrate/20120629150253_denormalize_expressions.rb b/db/migrate/20120629150253_denormalize_expressions.rb index 1b8a659db4c..8a386648852 100644 --- a/db/migrate/20120629150253_denormalize_expressions.rb +++ b/db/migrate/20120629150253_denormalize_expressions.rb @@ -15,7 +15,6 @@ class DenormalizeExpressions < ActiveRecord::Migration add_column :forum_threads, :expression4_count, :integer, null: false, default: 0 add_column :forum_threads, :expression5_count, :integer, null: false, default: 0 - (1..5).each do |i| execute "update posts set expression#{i}_count = (select count(*) from expressions where parent_id = posts.id and expression_type_id = #{i})" execute "update forum_threads set expression#{i}_count = (select sum(expression#{i}_count) from posts where forum_thread_id = forum_threads.id)" diff --git a/db/migrate/20120719004636_add_email_hashed_password_name_salt_to_users.rb b/db/migrate/20120719004636_add_email_hashed_password_name_salt_to_users.rb index bd1e05bea2d..4bd5e9b733b 100644 --- a/db/migrate/20120719004636_add_email_hashed_password_name_salt_to_users.rb +++ b/db/migrate/20120719004636_add_email_hashed_password_name_salt_to_users.rb @@ -4,7 +4,7 @@ class AddEmailHashedPasswordNameSaltToUsers < ActiveRecord::Migration execute "update users set email= md5(random()::text) || 'domain.com'" - change_column :users, :email, :string, limit:256, null: false + change_column :users, :email, :string, limit: 256, null: false add_index :users, [:email], unique: true rename_column :users, :display_username, :name @@ -12,7 +12,7 @@ class AddEmailHashedPasswordNameSaltToUsers < ActiveRecord::Migration add_column :users, :password_hash, :string, limit: 64 add_column :users, :salt, :string, limit: 32 add_column :users, :active, :boolean - add_column :users, :activation_key,:string, limit: 32 + add_column :users, :activation_key, :string, limit: 32 add_column :user_open_ids, :active, :boolean, null: false diff --git a/db/migrate/20120720013733_add_username_lower_to_users.rb b/db/migrate/20120720013733_add_username_lower_to_users.rb index 764fae375d4..38602aa2aa7 100644 --- a/db/migrate/20120720013733_add_username_lower_to_users.rb +++ b/db/migrate/20120720013733_add_username_lower_to_users.rb @@ -3,7 +3,7 @@ class AddUsernameLowerToUsers < ActiveRecord::Migration add_column :users, :username_lower, :string, limit: 20 execute "update users set username_lower = lower(username)" add_index :users, [:username_lower], unique: true - change_column :users, :username_lower, :string, limit: 20, null:false + change_column :users, :username_lower, :string, limit: 20, null: false end def down remove_column :users, :username_lower diff --git a/db/migrate/20120807223020_create_actions.rb b/db/migrate/20120807223020_create_actions.rb index 623bda5929a..ace59397854 100644 --- a/db/migrate/20120807223020_create_actions.rb +++ b/db/migrate/20120807223020_create_actions.rb @@ -8,7 +8,6 @@ class CreateActions < ActiveRecord::Migration # There is a notificiation table as well that covers much of this, # but this table is wider and is intended for non-notifying actions as well - t.integer :action_type, null: false t.integer :user_id, null: false t.integer :target_forum_thread_id diff --git a/db/migrate/20120809020415_remove_site_id.rb b/db/migrate/20120809020415_remove_site_id.rb index 86727e86fd7..c9904d4a705 100644 --- a/db/migrate/20120809020415_remove_site_id.rb +++ b/db/migrate/20120809020415_remove_site_id.rb @@ -9,7 +9,7 @@ class RemoveSiteId < ActiveRecord::Migration remove_index 'expression_types', name: 'index_expression_types_on_site_id_and_expression_index' remove_index 'expression_types', name: 'index_expression_types_on_site_id_and_name' - remove_column 'expression_types','site_id' + remove_column 'expression_types', 'site_id' add_index "expression_types", ["expression_index"], unique: true add_index "expression_types", ["name"], unique: true diff --git a/db/migrate/20120809053414_correct_indexing_on_posts.rb b/db/migrate/20120809053414_correct_indexing_on_posts.rb index b3777e093ae..13ff4507d66 100644 --- a/db/migrate/20120809053414_correct_indexing_on_posts.rb +++ b/db/migrate/20120809053414_correct_indexing_on_posts.rb @@ -1,20 +1,20 @@ class CorrectIndexingOnPosts < ActiveRecord::Migration def up - execute "update posts pp + execute "update posts pp set post_number = c.real_number from ( select p1.id, count(*) real_number from posts p1 join posts p2 on p1.forum_thread_id = p2.forum_thread_id where p2.id <= p1.id and p1.forum_thread_id = p2.forum_thread_id - group by p1.id + group by p1.id ) as c where pp.id = c.id and pp.post_number <> c.real_number" - remove_index "posts", ["forum_thread_id","post_number"] + remove_index "posts", ["forum_thread_id", "post_number"] # this needs to be unique if it is not we can not use post_number to identify a post - add_index "posts", ["forum_thread_id","post_number"], unique: true + add_index "posts", ["forum_thread_id", "post_number"], unique: true end diff --git a/db/migrate/20120809154750_remove_index_for_now.rb b/db/migrate/20120809154750_remove_index_for_now.rb index 148cbe70a07..ea20ceb152e 100644 --- a/db/migrate/20120809154750_remove_index_for_now.rb +++ b/db/migrate/20120809154750_remove_index_for_now.rb @@ -1,11 +1,11 @@ class RemoveIndexForNow < ActiveRecord::Migration def up - remove_index "posts", ["forum_thread_id","post_number"] - add_index "posts", ["forum_thread_id","post_number"], unique: false + remove_index "posts", ["forum_thread_id", "post_number"] + add_index "posts", ["forum_thread_id", "post_number"], unique: false end def down - remove_index "posts", ["forum_thread_id","post_number"] - add_index "posts", ["forum_thread_id","post_number"], unique: true + remove_index "posts", ["forum_thread_id", "post_number"] + add_index "posts", ["forum_thread_id", "post_number"], unique: true end end diff --git a/db/migrate/20120809174649_create_post_actions.rb b/db/migrate/20120809174649_create_post_actions.rb index ddcf4d4632a..7a8e5d9f440 100644 --- a/db/migrate/20120809174649_create_post_actions.rb +++ b/db/migrate/20120809174649_create_post_actions.rb @@ -3,7 +3,7 @@ class CreatePostActions < ActiveRecord::Migration create_table :post_actions do |t| t.integer :post_id, null: false t.integer :user_id, null: false - t.integer :post_action_type_id, null:false + t.integer :post_action_type_id, null: false t.datetime :deleted_at t.timestamps end diff --git a/db/migrate/20120816050526_add_unique_constraint_to_user_actions.rb b/db/migrate/20120816050526_add_unique_constraint_to_user_actions.rb index 5a8ea4af878..6d79402d346 100644 --- a/db/migrate/20120816050526_add_unique_constraint_to_user_actions.rb +++ b/db/migrate/20120816050526_add_unique_constraint_to_user_actions.rb @@ -1,5 +1,5 @@ class AddUniqueConstraintToUserActions < ActiveRecord::Migration def change - add_index :user_actions, ['action_type','user_id', 'target_forum_thread_id', 'target_post_id', 'acting_user_id'], name: "idx_unique_rows", unique: true + add_index :user_actions, ['action_type', 'user_id', 'target_forum_thread_id', 'target_post_id', 'acting_user_id'], name: "idx_unique_rows", unique: true end end diff --git a/db/migrate/20120821191616_add_bumped_at_to_forum_threads.rb b/db/migrate/20120821191616_add_bumped_at_to_forum_threads.rb index 584c62c9fbf..9420f79a8d3 100644 --- a/db/migrate/20120821191616_add_bumped_at_to_forum_threads.rb +++ b/db/migrate/20120821191616_add_bumped_at_to_forum_threads.rb @@ -5,6 +5,6 @@ class AddBumpedAtToForumThreads < ActiveRecord::Migration change_column :forum_threads, :bumped_at, :datetime, null: false remove_index :forum_threads, :last_posted_at - add_index :forum_threads, :bumped_at, order: {bumped_at: :desc} + add_index :forum_threads, :bumped_at, order: { bumped_at: :desc } end end diff --git a/db/migrate/20121011155904_create_email_logs.rb b/db/migrate/20121011155904_create_email_logs.rb index 2d92e00db64..abfea55e767 100644 --- a/db/migrate/20121011155904_create_email_logs.rb +++ b/db/migrate/20121011155904_create_email_logs.rb @@ -7,7 +7,7 @@ class CreateEmailLogs < ActiveRecord::Migration t.timestamps end - add_index :email_logs, :created_at, order: {created_at: :desc} - add_index :email_logs, [:user_id, :created_at], order: {created_at: :desc} + add_index :email_logs, :created_at, order: { created_at: :desc } + add_index :email_logs, [:user_id, :created_at], order: { created_at: :desc } end end diff --git a/db/migrate/20121018103721_rename_forum_thread_tables.rb b/db/migrate/20121018103721_rename_forum_thread_tables.rb index d513d1b0e2f..84980494dae 100644 --- a/db/migrate/20121018103721_rename_forum_thread_tables.rb +++ b/db/migrate/20121018103721_rename_forum_thread_tables.rb @@ -14,7 +14,6 @@ class RenameForumThreadTables < ActiveRecord::Migration rename_column 'categories', 'threads_month', 'topics_month' rename_column 'categories', 'threads_week', 'topics_week' - rename_column 'category_featured_topics', 'forum_thread_id', 'topic_id' rename_column 'topic_link_clicks', 'forum_thread_link_id', 'topic_link_id' @@ -22,7 +21,6 @@ class RenameForumThreadTables < ActiveRecord::Migration rename_column 'topic_links', 'forum_thread_id', 'topic_id' rename_column 'topic_links', 'link_forum_thread_id', 'link_topic_id' - rename_column 'topic_users', 'forum_thread_id', 'topic_id' rename_column 'incoming_links', 'forum_thread_id', 'topic_id' diff --git a/db/migrate/20130122232825_add_auto_track_after_seconds_and_banning_and_dob_to_user.rb b/db/migrate/20130122232825_add_auto_track_after_seconds_and_banning_and_dob_to_user.rb index 1432d8ba70b..34ee5edbced 100644 --- a/db/migrate/20130122232825_add_auto_track_after_seconds_and_banning_and_dob_to_user.rb +++ b/db/migrate/20130122232825_add_auto_track_after_seconds_and_banning_and_dob_to_user.rb @@ -6,7 +6,7 @@ class AddAutoTrackAfterSecondsAndBanningAndDobToUser < ActiveRecord::Migration add_column :users, :auto_track_topics_after_msecs, :integer add_column :users, :views, :integer, null: false, default: 0 - remove_column :users, :auto_track_topics + remove_column :users, :auto_track_topics add_column :topic_users, :total_msecs_viewed, :integer, null: false, default: 0 diff --git a/db/migrate/20130319122248_add_reply_to_user_id_to_post.rb b/db/migrate/20130319122248_add_reply_to_user_id_to_post.rb index 3f537dfdc92..1eb09763de7 100644 --- a/db/migrate/20130319122248_add_reply_to_user_id_to_post.rb +++ b/db/migrate/20130319122248_add_reply_to_user_id_to_post.rb @@ -3,8 +3,8 @@ class AddReplyToUserIdToPost < ActiveRecord::Migration # caching this column makes the topic page WAY faster add_column :posts, :reply_to_user_id, :integer execute 'UPDATE posts p SET reply_to_user_id = ( - SELECT u.id from users u - JOIN posts p2 ON p2.user_id = u.id AND + SELECT u.id from users u + JOIN posts p2 ON p2.user_id = u.id AND p2.post_number = p.reply_to_post_number AND p2.topic_id = p.topic_id )' diff --git a/db/migrate/20130320012100_add_user_indexes_to_posts_and_topics.rb b/db/migrate/20130320012100_add_user_indexes_to_posts_and_topics.rb index 3fffe74303b..89bdb3aee4b 100644 --- a/db/migrate/20130320012100_add_user_indexes_to_posts_and_topics.rb +++ b/db/migrate/20130320012100_add_user_indexes_to_posts_and_topics.rb @@ -1,9 +1,9 @@ class AddUserIndexesToPostsAndTopics < ActiveRecord::Migration def up - execute "CREATE INDEX idx_posts_user_id_deleted_at + execute "CREATE INDEX idx_posts_user_id_deleted_at ON posts(user_id) WHERE deleted_at IS NULL" - - execute "CREATE INDEX idx_topics_user_id_deleted_at + + execute "CREATE INDEX idx_topics_user_id_deleted_at ON topics(user_id) WHERE deleted_at IS NULL" end diff --git a/db/migrate/20130404232558_add_user_extras.rb b/db/migrate/20130404232558_add_user_extras.rb index 73d1add55dd..70c75482e56 100644 --- a/db/migrate/20130404232558_add_user_extras.rb +++ b/db/migrate/20130404232558_add_user_extras.rb @@ -7,7 +7,6 @@ class AddUserExtras < ActiveRecord::Migration add_column :users, :likes_received, :integer, null: false, default: 0 add_column :users, :topic_reply_count, :integer, null: false, default: 0 - # NOTE: to keep migrations working through refactorings we avoid externalizing this stuff. # even though a helper method may make sense execute <> 0 & 255) );" - change_column :topic_link_clicks, :ip_address, :inet, { :null => false } + change_column :topic_link_clicks, :ip_address, :inet, null: false remove_column :topic_link_clicks, :ip end diff --git a/db/migrate/20130625022454_change_ip_to_inet_in_views.rb b/db/migrate/20130625022454_change_ip_to_inet_in_views.rb index 30a0e8390bc..e4e01f56295 100644 --- a/db/migrate/20130625022454_change_ip_to_inet_in_views.rb +++ b/db/migrate/20130625022454_change_ip_to_inet_in_views.rb @@ -12,7 +12,7 @@ class ChangeIpToInetInViews < ActiveRecord::Migration (ip >> 0 & 255) );" - change_column table, :ip_address, :inet, { :null => false } + change_column table, :ip_address, :inet, null: false remove_column table, :ip end diff --git a/db/migrate/20130625170842_remove_access_password.rb b/db/migrate/20130625170842_remove_access_password.rb index 31c5a83d4a5..d2b87bc71bd 100644 --- a/db/migrate/20130625170842_remove_access_password.rb +++ b/db/migrate/20130625170842_remove_access_password.rb @@ -1,7 +1,7 @@ class RemoveAccessPassword < ActiveRecord::Migration def up result = execute("SELECT count(*) FROM site_settings where name='access_password' and char_length(value) > 0") - if result[0] and result[0]["count"].to_i > 0 + if result[0] && result[0]["count"].to_i > (0) execute "DELETE FROM site_settings where name='access_password'" SiteSetting.login_required = true SiteSetting.must_approve_users = true diff --git a/db/migrate/20130911182437_create_user_stats.rb b/db/migrate/20130911182437_create_user_stats.rb index 66f5370743c..ff3f78ab185 100644 --- a/db/migrate/20130911182437_create_user_stats.rb +++ b/db/migrate/20130911182437_create_user_stats.rb @@ -1,6 +1,6 @@ class CreateUserStats < ActiveRecord::Migration def up - create_table :user_stats, :id => false do |t| + create_table :user_stats, id: false do |t| t.references :user, null: false t.boolean :has_custom_avatar, default: false, null: false end diff --git a/db/migrate/20130912185218_acting_user_null.rb b/db/migrate/20130912185218_acting_user_null.rb index fe99e3783cc..d03eabe527f 100644 --- a/db/migrate/20130912185218_acting_user_null.rb +++ b/db/migrate/20130912185218_acting_user_null.rb @@ -1,10 +1,10 @@ class ActingUserNull < ActiveRecord::Migration def up - change_column :user_histories, :acting_user_id, :integer, :null => true + change_column :user_histories, :acting_user_id, :integer, null: true end def down execute "DELETE FROM user_histories WHERE acting_user_id IS NULL" - change_column :user_histories, :acting_user_id, :integer, :null => false + change_column :user_histories, :acting_user_id, :integer, null: false end end diff --git a/db/migrate/20131002070347_add_user_id_parent_type_index_on_views.rb b/db/migrate/20131002070347_add_user_id_parent_type_index_on_views.rb index b1a20098d66..3055c712a84 100644 --- a/db/migrate/20131002070347_add_user_id_parent_type_index_on_views.rb +++ b/db/migrate/20131002070347_add_user_id_parent_type_index_on_views.rb @@ -1,5 +1,5 @@ class AddUserIdParentTypeIndexOnViews < ActiveRecord::Migration def change - add_index :views, [:user_id,:parent_type,:parent_id] + add_index :views, [:user_id, :parent_type, :parent_id] end end diff --git a/db/migrate/20131022045114_add_uncategorized_category.rb b/db/migrate/20131022045114_add_uncategorized_category.rb index 953960fd661..347bc2320c8 100644 --- a/db/migrate/20131022045114_add_uncategorized_category.rb +++ b/db/migrate/20131022045114_add_uncategorized_category.rb @@ -17,7 +17,6 @@ class AddUncategorizedCategory < ActiveRecord::Migration execute "INSERT INTO site_settings(name, data_type, value, created_at, updated_at) VALUES ('uncategorized_category_id', 3, #{category_id}, now(), now())" - execute "DELETE from site_settings where name in ('uncategorized_name', 'uncategorized_text_color', 'uncategorized_color')" execute "UPDATE topics SET category_id = #{category_id} WHERE archetype = 'regular' AND category_id IS NULL" diff --git a/db/migrate/20131023163509_add_parent_category_id_to_categories.rb b/db/migrate/20131023163509_add_parent_category_id_to_categories.rb index f4b86f50414..759895f5fe8 100644 --- a/db/migrate/20131023163509_add_parent_category_id_to_categories.rb +++ b/db/migrate/20131023163509_add_parent_category_id_to_categories.rb @@ -3,4 +3,3 @@ class AddParentCategoryIdToCategories < ActiveRecord::Migration add_column :categories, :parent_category_id, :integer end end - diff --git a/db/migrate/20131210181901_migrate_word_counts.rb b/db/migrate/20131210181901_migrate_word_counts.rb index 64e05aae99b..e783725bb80 100644 --- a/db/migrate/20131210181901_migrate_word_counts.rb +++ b/db/migrate/20131210181901_migrate_word_counts.rb @@ -2,7 +2,7 @@ class MigrateWordCounts < ActiveRecord::Migration disable_ddl_transaction! def up - post_ids = execute("SELECT id FROM posts WHERE word_count IS NULL LIMIT 500").map {|r| r['id'].to_i } + post_ids = execute("SELECT id FROM posts WHERE word_count IS NULL LIMIT 500").map { |r| r['id'].to_i } while post_ids.length > 0 3.times do begin @@ -12,10 +12,10 @@ class MigrateWordCounts < ActiveRecord::Migration # Deadlock. Try again, up to 3 times. end end - post_ids = execute("SELECT id FROM posts WHERE word_count IS NULL LIMIT 500").map {|r| r['id'].to_i } + post_ids = execute("SELECT id FROM posts WHERE word_count IS NULL LIMIT 500").map { |r| r['id'].to_i } end - topic_ids = execute("SELECT id FROM topics WHERE word_count IS NULL LIMIT 500").map {|r| r['id'].to_i } + topic_ids = execute("SELECT id FROM topics WHERE word_count IS NULL LIMIT 500").map { |r| r['id'].to_i } while topic_ids.length > 0 3.times do begin @@ -25,7 +25,7 @@ class MigrateWordCounts < ActiveRecord::Migration # Deadlock. Try again, up to 3 times. end end - topic_ids = execute("SELECT id FROM topics WHERE word_count IS NULL LIMIT 500").map {|r| r['id'].to_i } + topic_ids = execute("SELECT id FROM topics WHERE word_count IS NULL LIMIT 500").map { |r| r['id'].to_i } end end diff --git a/db/migrate/20140211230222_move_cas_settings.rb b/db/migrate/20140211230222_move_cas_settings.rb index 0de988fbfad..b832385a3b9 100644 --- a/db/migrate/20140211230222_move_cas_settings.rb +++ b/db/migrate/20140211230222_move_cas_settings.rb @@ -4,23 +4,23 @@ class MoveCasSettings < ActiveRecord::Migration #convert the data over to be used by the plugin. cas_hostname = SiteSetting.find_by(name: "cas_hostname") cas_sso_hostname = SiteSetting.find_by(name: "cas_sso_hostname") - if cas_hostname && ! cas_sso_hostname + if cas_hostname && ! cas_sso_hostname #convert the setting over for use by the plugin cas_hostname.update_attribute(:name, 'cas_sso_hostname') - elsif cas_hostname && cas_sso_hostname + elsif cas_hostname && cas_sso_hostname #copy the setting over for use by the plugin and delete the original setting - cas_sso_hostname.update_attribute(:value,cas_hostname.value) + cas_sso_hostname.update_attribute(:value, cas_hostname.value) cas_hostname.destroy end cas_domainname = SiteSetting.find_by(name: "cas_domainname") cas_sso_email_domain = SiteSetting.find_by(name: "cas_sso_email_domain") - if cas_domainname && ! cas_sso_email_domain + if cas_domainname && ! cas_sso_email_domain #convert the setting over for use by the plugin cas_domainname.update_attribute(:name, 'cas_sso_email_domain') - elsif cas_domainname && cas_sso_email_domain + elsif cas_domainname && cas_sso_email_domain #copy the setting over for use by the plugin and delete the original setting - cas_sso_email_domain.update_attribute(:value,cas_domainname.value) + cas_sso_email_domain.update_attribute(:value, cas_domainname.value) cas_domainname.destroy end @@ -29,7 +29,7 @@ class MoveCasSettings < ActiveRecord::Migration cas_logins.destroy end - #remove the unused table + #remove the unused table drop_table :cas_user_infos end diff --git a/db/migrate/20140227104930_add_custom_email_in_to_categories.rb b/db/migrate/20140227104930_add_custom_email_in_to_categories.rb index 7d3cac2c5f2..fa31829cafe 100644 --- a/db/migrate/20140227104930_add_custom_email_in_to_categories.rb +++ b/db/migrate/20140227104930_add_custom_email_in_to_categories.rb @@ -1,12 +1,12 @@ class AddCustomEmailInToCategories < ActiveRecord::Migration def up - add_column :categories, :email_in, :string, null: true - add_column :categories, :email_in_allow_strangers, :boolean, default: false - add_index :categories, :email_in, unique: true + add_column :categories, :email_in, :string, null: true + add_column :categories, :email_in_allow_strangers, :boolean, default: false + add_index :categories, :email_in, unique: true end def down - remove_column :categories, :email_in - remove_column :categories, :email_in_allow_strangers - remove_index :categories, :email_in + remove_column :categories, :email_in + remove_column :categories, :email_in_allow_strangers + remove_index :categories, :email_in end end diff --git a/db/migrate/20140318150412_add_excerpt_to_topics.rb b/db/migrate/20140318150412_add_excerpt_to_topics.rb index 35283cb47b5..513906d9000 100644 --- a/db/migrate/20140318150412_add_excerpt_to_topics.rb +++ b/db/migrate/20140318150412_add_excerpt_to_topics.rb @@ -2,7 +2,7 @@ class AddExcerptToTopics < ActiveRecord::Migration def up add_column :topics, :excerpt, :string, limit: 1000 - topic_ids = execute("SELECT id FROM topics WHERE pinned_at IS NOT NULL").map {|r| r['id'].to_i } + topic_ids = execute("SELECT id FROM topics WHERE pinned_at IS NOT NULL").map { |r| r['id'].to_i } topic_ids.each do |topic_id| cooked = execute("SELECT cooked FROM posts WHERE topic_id = #{topic_id} ORDER BY post_number ASC LIMIT 1")[0]['cooked'] if cooked diff --git a/db/migrate/20140402201432_make_content_sha1_nullable.rb b/db/migrate/20140402201432_make_content_sha1_nullable.rb index 29b7572edcc..fd2a60ebd93 100644 --- a/db/migrate/20140402201432_make_content_sha1_nullable.rb +++ b/db/migrate/20140402201432_make_content_sha1_nullable.rb @@ -1,5 +1,5 @@ class MakeContentSha1Nullable < ActiveRecord::Migration def change - change_column :topic_embeds, :content_sha1, :string, :limit => 40, :null => true + change_column :topic_embeds, :content_sha1, :string, limit: 40, null: true end end diff --git a/db/migrate/20140530002535_remove_system_avatars_from_user_avatars.rb b/db/migrate/20140530002535_remove_system_avatars_from_user_avatars.rb index ae4a8f364af..82e90e71530 100644 --- a/db/migrate/20140530002535_remove_system_avatars_from_user_avatars.rb +++ b/db/migrate/20140530002535_remove_system_avatars_from_user_avatars.rb @@ -9,7 +9,7 @@ class RemoveSystemAvatarsFromUserAvatars < ActiveRecord::Migration # normally we dont reach into the object model, but we have to here. # otherwise we will wait a real long time for uploads to go away skip = -1 - while skip=destroy_system_avatar_batch(skip) do + while skip = destroy_system_avatar_batch(skip) do puts "Destroyed up to id: #{skip}" end @@ -21,9 +21,9 @@ class RemoveSystemAvatarsFromUserAvatars < ActiveRecord::Migration initial = skip Upload.where('id IN (SELECT system_upload_id FROM user_avatars) AND id > ?', skip) - .order(:id) - .limit(500) - .each do |upload| + .order(:id) + .limit(500) + .each do |upload| skip = upload.id begin upload.destroy diff --git a/db/migrate/20140715055242_add_quoted_posts.rb b/db/migrate/20140715055242_add_quoted_posts.rb index 587d894799e..5f6c79cd3ec 100644 --- a/db/migrate/20140715055242_add_quoted_posts.rb +++ b/db/migrate/20140715055242_add_quoted_posts.rb @@ -9,7 +9,6 @@ class AddQuotedPosts < ActiveRecord::Migration add_index :quoted_posts, [:post_id, :quoted_post_id], unique: true add_index :quoted_posts, [:quoted_post_id, :post_id], unique: true - # NOTE this can be done in pg but too much of a headache id = 0 while id = backfill_batch(id, 1000); end @@ -37,9 +36,8 @@ SQL topic_id = a['data-topic'].to_i post_number = a['data-post'].to_i - next if uniq[[topic_id,post_number]] - uniq[[topic_id,post_number]] = true - + next if uniq[[topic_id, post_number]] + uniq[[topic_id, post_number]] = true execute "INSERT INTO quoted_posts(post_id, quoted_post_id, created_at, updated_at) SELECT #{post_id}, id, created_at, updated_at diff --git a/db/migrate/20140804010803_incoming_link_normalization.rb b/db/migrate/20140804010803_incoming_link_normalization.rb index 2c3743541a8..171451dff51 100644 --- a/db/migrate/20140804010803_incoming_link_normalization.rb +++ b/db/migrate/20140804010803_incoming_link_normalization.rb @@ -36,7 +36,6 @@ class IncomingLinkNormalization < ActiveRecord::Migration ) X WHERE a[2] IS NOT NULL" - execute "UPDATE incoming_links l SET incoming_referer_id = r.id FROM incoming_referers r @@ -59,7 +58,6 @@ class IncomingLinkNormalization < ActiveRecord::Migration FROM incoming_domains d WHERE d.name = l.domain AND d.https = l.https AND d.port = l.port" - remove_column :incoming_referers, :domain remove_column :incoming_referers, :port remove_column :incoming_referers, :https diff --git a/db/migrate/20140804075613_normalize_topic_view_data_and_index.rb b/db/migrate/20140804075613_normalize_topic_view_data_and_index.rb index 4f6e6f1b2ee..67b9d784b5b 100644 --- a/db/migrate/20140804075613_normalize_topic_view_data_and_index.rb +++ b/db/migrate/20140804075613_normalize_topic_view_data_and_index.rb @@ -29,7 +29,6 @@ class NormalizeTopicViewDataAndIndex < ActiveRecord::Migration SELECT NULL, topic_id, ip_address, viewed_at FROM tmp_views_ip ' - execute 'CREATE UNIQUE INDEX user_id_topic_id_topic_views ON topic_views(user_id, topic_id) WHERE user_id IS NOT NULL' execute 'CREATE UNIQUE INDEX ip_address_topic_id_topic_views ON topic_views(ip_address, topic_id) WHERE user_id IS NULL' diff --git a/db/migrate/20140815215618_add_name_lower_to_categories.rb b/db/migrate/20140815215618_add_name_lower_to_categories.rb index 97c1685337d..20f6ef8c374 100644 --- a/db/migrate/20140815215618_add_name_lower_to_categories.rb +++ b/db/migrate/20140815215618_add_name_lower_to_categories.rb @@ -3,7 +3,7 @@ class AddNameLowerToCategories < ActiveRecord::Migration def up add_column :categories, :name_lower, :string, limit: 50 execute "update categories set name_lower = lower(name)" - change_column :categories, :name_lower, :string, limit: 50, null:false + change_column :categories, :name_lower, :string, limit: 50, null: false end def down diff --git a/db/migrate/20140913192733_add_trust_level_locked_column.rb b/db/migrate/20140913192733_add_trust_level_locked_column.rb index 8ac5b0b9893..c086f4a2fde 100644 --- a/db/migrate/20140913192733_add_trust_level_locked_column.rb +++ b/db/migrate/20140913192733_add_trust_level_locked_column.rb @@ -1,6 +1,6 @@ class AddTrustLevelLockedColumn < ActiveRecord::Migration def change - add_column :users, :trust_level_locked, :boolean, { default: false, null: false} + add_column :users, :trust_level_locked, :boolean, default: false, null: false reversible do |dir| dir.up do diff --git a/db/migrate/20140929204155_migrate_tos_setting.rb b/db/migrate/20140929204155_migrate_tos_setting.rb index 4e313c0373b..6ecac45bb81 100644 --- a/db/migrate/20140929204155_migrate_tos_setting.rb +++ b/db/migrate/20140929204155_migrate_tos_setting.rb @@ -13,7 +13,6 @@ class MigrateTosSetting < ActiveRecord::Migration label = res[0]['value'] end - label = PG::Connection.escape_string(label) execute("INSERT INTO user_fields (name, field_type, editable) VALUES ('#{label}', 'confirm', false)") end diff --git a/db/migrate/20141216112341_resolve_duplicate_group_names.rb b/db/migrate/20141216112341_resolve_duplicate_group_names.rb index 63a49e4b603..dc8fa1fdb02 100644 --- a/db/migrate/20141216112341_resolve_duplicate_group_names.rb +++ b/db/migrate/20141216112341_resolve_duplicate_group_names.rb @@ -11,7 +11,7 @@ class ResolveDuplicateGroupNames < ActiveRecord::Migration groups = Group.where id: results.map { |r| r['id'] } groups.group_by { |g| g.name.downcase }.each do |key, value| value.each_with_index do |dup, index| - dup.update! name: "#{dup.name[0..18]}_#{index+1}" if index > 0 + dup.update! name: "#{dup.name[0..18]}_#{index + 1}" if index > 0 end end end diff --git a/db/migrate/20150108002354_add_liked_and_bookmarked_to_topic_user.rb b/db/migrate/20150108002354_add_liked_and_bookmarked_to_topic_user.rb index 2dcdd47314c..58b5f37831c 100644 --- a/db/migrate/20150108002354_add_liked_and_bookmarked_to_topic_user.rb +++ b/db/migrate/20150108002354_add_liked_and_bookmarked_to_topic_user.rb @@ -4,7 +4,7 @@ class AddLikedAndBookmarkedToTopicUser < ActiveRecord::Migration add_column :topic_users, :bookmarked, :boolean, default: false # likes and bookmarks PostActionType.types[:like] and :bookmark which should not be used in a migration - {liked: 2, bookmarked: 1}.each do |name, type| + { liked: 2, bookmarked: 1 }.each do |name, type| execute "UPDATE topic_users SET #{name} = true WHERE EXISTS (SELECT 1 FROM post_actions pa diff --git a/db/migrate/20150713203955_enlarge_users_email_field.rb b/db/migrate/20150713203955_enlarge_users_email_field.rb index 15856c0f04c..9b4238f4b50 100644 --- a/db/migrate/20150713203955_enlarge_users_email_field.rb +++ b/db/migrate/20150713203955_enlarge_users_email_field.rb @@ -1,8 +1,8 @@ class EnlargeUsersEmailField < ActiveRecord::Migration def up - change_column :users, :email, :string, :limit => 513 + change_column :users, :email, :string, limit: 513 end def down - change_column :users, :email, :string, :limit => 128 + change_column :users, :email, :string, limit: 128 end end diff --git a/db/migrate/20150729150523_migrate_auto_close_posts.rb b/db/migrate/20150729150523_migrate_auto_close_posts.rb index d00ec9623ad..1a4d6bc0e70 100644 --- a/db/migrate/20150729150523_migrate_auto_close_posts.rb +++ b/db/migrate/20150729150523_migrate_auto_close_posts.rb @@ -9,7 +9,7 @@ class MigrateAutoClosePosts < ActiveRecord::Migration sql = "UPDATE posts SET action_code = 'autoclosed.enabled', post_type = 3 " sql << "WHERE post_type = 2 AND (" - sql << strings.map {|s| "raw ~* #{ActiveRecord::Base.connection.quote(s)}" }.join(' OR ') + sql << strings.map { |s| "raw ~* #{ActiveRecord::Base.connection.quote(s)}" }.join(' OR ') sql << ")" execute sql diff --git a/db/migrate/20160108051129_fix_incorrect_user_history.rb b/db/migrate/20160108051129_fix_incorrect_user_history.rb index 2a9cbdf0fbc..e7b44a9e761 100644 --- a/db/migrate/20160108051129_fix_incorrect_user_history.rb +++ b/db/migrate/20160108051129_fix_incorrect_user_history.rb @@ -7,7 +7,6 @@ class FixIncorrectUserHistory < ActiveRecord::Migration # # This migration hunts for date stuff started going wrong and date it started being good and corrects the data - # this is a :auto_trust_level_change mislabled as :check_email # impersonate that was actually delete topic condition = < 0 + if result[0] && result[0]["count"].to_i > (0) execute "UPDATE categories SET show_subcategory_list = true WHERE parent_category_id IS NULL" end end diff --git a/db/migrate/20170313192741_add_themes.rb b/db/migrate/20170313192741_add_themes.rb index ab2e3abc3b4..52905c86b76 100644 --- a/db/migrate/20170313192741_add_themes.rb +++ b/db/migrate/20170313192741_add_themes.rb @@ -20,16 +20,15 @@ class AddThemes < ActiveRecord::Migration remove_column :color_schemes, :versioned_id enabled_theme_count = execute("SELECT count(*) FROM themes WHERE enabled") - .to_a[0]["count"].to_i - + .to_a[0]["count"].to_i enabled_scheme_id = execute("SELECT id FROM color_schemes WHERE enabled") - .to_a[0]&.fetch("id") + .to_a[0]&.fetch("id") theme_key, theme_id = execute("SELECT key, id FROM themes WHERE enabled").to_a[0]&.values - if (enabled_theme_count == 0 && enabled_scheme_id) || enabled_theme_count > 1 + if (enabled_theme_count == 0 && enabled_scheme_id) || enabled_theme_count > 1 puts "Creating a new default theme!" @@ -67,8 +66,6 @@ SQL execute(sql) end - - remove_column :themes, :enabled remove_column :color_schemes, :enabled end diff --git a/lib/active_record/connection_adapters/postgresql_fallback_adapter.rb b/lib/active_record/connection_adapters/postgresql_fallback_adapter.rb index 84500b50f77..ce2dfbb3e27 100644 --- a/lib/active_record/connection_adapters/postgresql_fallback_adapter.rb +++ b/lib/active_record/connection_adapters/postgresql_fallback_adapter.rb @@ -98,9 +98,7 @@ module ActiveRecord if fallback_handler.master_down? fallback_handler.verify_master - connection = postgresql_connection(config.dup.merge({ - host: config[:replica_host], port: config[:replica_port] - })) + connection = postgresql_connection(config.dup.merge(host: config[:replica_host], port: config[:replica_port])) verify_replica(connection) Discourse.enable_readonly_mode(Discourse::PG_READONLY_MODE_KEY) diff --git a/lib/admin_constraint.rb b/lib/admin_constraint.rb index 0ee711c2bca..db5c0e73b64 100644 --- a/lib/admin_constraint.rb +++ b/lib/admin_constraint.rb @@ -2,7 +2,7 @@ require_dependency 'current_user' class AdminConstraint - def initialize(options={}) + def initialize(options = {}) @require_master = options[:require_master] end diff --git a/lib/admin_user_index_query.rb b/lib/admin_user_index_query.rb index 3a52f75661f..0f216c606bc 100644 --- a/lib/admin_user_index_query.rb +++ b/lib/admin_user_index_query.rb @@ -24,10 +24,10 @@ class AdminUserIndexQuery 'read_time' => 'user_stats.time_read' } - def find_users(limit=100) + def find_users(limit = 100) page = params[:page].to_i - 1 if page < 0 - page = 0 + page = 0 end find_users_query.limit(limit).offset(page * limit) end @@ -81,22 +81,22 @@ class AdminUserIndexQuery where_conds << "user_stats.posts_read_count <= 1 AND user_stats.topics_entered <= 1" @query.activated - .references(:user_stats) - .includes(:user_profile) - .where("COALESCE(user_profiles.bio_raw, '') != ''") - .where('users.created_at <= ?', 1.day.ago) - .where(where_conds.map {|c| "(#{c})"}.join(" OR ")) + .references(:user_stats) + .includes(:user_profile) + .where("COALESCE(user_profiles.bio_raw, '') != ''") + .where('users.created_at <= ?', 1.day.ago) + .where(where_conds.map { |c| "(#{c})" }.join(" OR ")) end def filter_by_query_classification case params[:query] - when 'staff' then @query.where("admin or moderator") - when 'admins' then @query.where(admin: true) - when 'moderators' then @query.where(moderator: true) - when 'blocked' then @query.blocked - when 'suspended' then @query.suspended - when 'pending' then @query.not_suspended.where(approved: false) - when 'suspect' then suspect_users + when 'staff' then @query.where("admin or moderator") + when 'admins' then @query.where(admin: true) + when 'moderators' then @query.where(moderator: true) + when 'blocked' then @query.blocked + when 'suspended' then @query.suspended + when 'pending' then @query.not_suspended.where(approved: false) + when 'suspect' then suspect_users end end diff --git a/lib/archetype.rb b/lib/archetype.rb index 7213c8b26f0..8c8f3591ae6 100644 --- a/lib/archetype.rb +++ b/lib/archetype.rb @@ -32,7 +32,7 @@ class Archetype @archetypes.values end - def self.register(name, options={}) + def self.register(name, options = {}) @archetypes ||= {} @archetypes[name] = Archetype.new(name, options) end diff --git a/lib/auth/current_user_provider.rb b/lib/auth/current_user_provider.rb index cdd4d495fcc..1affbc8d870 100644 --- a/lib/auth/current_user_provider.rb +++ b/lib/auth/current_user_provider.rb @@ -12,12 +12,12 @@ class Auth::CurrentUserProvider end # log on a user and set cookies and session etc. - def log_on_user(user,session,cookies) + def log_on_user(user, session, cookies) raise NotImplementedError end # optional interface to be called to refresh cookies etc if needed - def refresh_session(user,session,cookies) + def refresh_session(user, session, cookies) end # api has special rights return true if api was detected @@ -35,7 +35,6 @@ class Auth::CurrentUserProvider raise NotImplementedError end - def log_off_user(session, cookies) raise NotImplementedError end diff --git a/lib/auth/default_current_user_provider.rb b/lib/auth/default_current_user_provider.rb index 4be651472ba..e94340c0de0 100644 --- a/lib/auth/default_current_user_provider.rb +++ b/lib/auth/default_current_user_provider.rb @@ -44,7 +44,7 @@ class Auth::DefaultCurrentUserProvider current_user = nil if auth_token && auth_token.length == 32 - limiter = RateLimiter.new(nil, "cookie_auth_#{request.ip}", COOKIE_ATTEMPTS_PER_MIN ,60) + limiter = RateLimiter.new(nil, "cookie_auth_#{request.ip}", COOKIE_ATTEMPTS_PER_MIN , 60) if limiter.can_perform? @user_token = UserAuthToken.lookup(auth_token, @@ -127,8 +127,8 @@ class Auth::DefaultCurrentUserProvider if !@user_token.legacy && needs_rotation if @user_token.rotate!(user_agent: @env['HTTP_USER_AGENT'], - client_ip: @request.ip, - path: @env['REQUEST_PATH']) + client_ip: @request.ip, + path: @env['REQUEST_PATH']) cookies[TOKEN_COOKIE] = cookie_hash(@user_token.unhashed_auth_token) end elsif @user_token.legacy @@ -200,7 +200,6 @@ class Auth::DefaultCurrentUserProvider cookies.delete(TOKEN_COOKIE) end - # api has special rights return true if api was detected def is_api? current_user diff --git a/lib/auth/facebook_authenticator.rb b/lib/auth/facebook_authenticator.rb index f7f90cb26bd..f969c8dabf0 100644 --- a/lib/auth/facebook_authenticator.rb +++ b/lib/auth/facebook_authenticator.rb @@ -52,8 +52,8 @@ class Auth::FacebookAuthenticator < Auth::Authenticator def register_middleware(omniauth) omniauth.provider :facebook, - :setup => lambda { |env| - strategy = env["omniauth.strategy"] + setup: lambda { |env| + strategy = env["omniauth.strategy"] strategy.options[:client_id] = SiteSetting.facebook_app_id strategy.options[:client_secret] = SiteSetting.facebook_app_secret strategy.options[:info_fields] = 'gender,email,name,about,first_name,link,last_name,website,location' @@ -61,7 +61,7 @@ class Auth::FacebookAuthenticator < Auth::Authenticator strategy.options[:scope] = 'email,user_about_me,user_location,user_website' end }, - :scope => "email" + scope: "email" end protected diff --git a/lib/auth/github_authenticator.rb b/lib/auth/github_authenticator.rb index e79414973ac..41874a04c1f 100644 --- a/lib/auth/github_authenticator.rb +++ b/lib/auth/github_authenticator.rb @@ -47,10 +47,8 @@ class Auth::GithubAuthenticator < Auth::Authenticator # Potentially use *any* of the emails from GitHub to find a match or # register a new user, with preference given to the primary email. all_emails = Array.new(auth_token[:extra][:all_emails]) - all_emails.unshift({ - :email => data[:email], - :verified => !!data[:email_verified] - }) + all_emails.unshift(email: data[:email], + verified: !!data[:email_verified]) # Only consider verified emails to match an existing user. We don't want # someone to be able to create a GitHub account with an unverified email @@ -106,14 +104,13 @@ class Auth::GithubAuthenticator < Auth::Authenticator ) end - def register_middleware(omniauth) omniauth.provider :github, - :setup => lambda { |env| - strategy = env["omniauth.strategy"] + setup: lambda { |env| + strategy = env["omniauth.strategy"] strategy.options[:client_id] = SiteSetting.github_client_id strategy.options[:client_secret] = SiteSetting.github_client_secret }, - :scope => "user:email" + scope: "user:email" end end diff --git a/lib/auth/google_oauth2_authenticator.rb b/lib/auth/google_oauth2_authenticator.rb index 31e44ea25dc..385aa921481 100644 --- a/lib/auth/google_oauth2_authenticator.rb +++ b/lib/auth/google_oauth2_authenticator.rb @@ -21,7 +21,7 @@ class Auth::GoogleOAuth2Authenticator < Auth::Authenticator if !result.user && !result.email.blank? && result.email_valid result.user = User.find_by_email(result.email) if result.user - ::GoogleUserInfo.create({user_id: result.user.id}.merge(google_hash)) + ::GoogleUserInfo.create({ user_id: result.user.id }.merge(google_hash)) end end @@ -30,7 +30,7 @@ class Auth::GoogleOAuth2Authenticator < Auth::Authenticator def after_create_account(user, auth) data = auth[:extra_data] - GoogleUserInfo.create({user_id: user.id}.merge(data)) + GoogleUserInfo.create({ user_id: user.id }.merge(data)) if auth[:email_valid].to_s == 'true' EmailToken.confirm(user.email_tokens.first.token) user.set_automatic_groups @@ -41,8 +41,8 @@ class Auth::GoogleOAuth2Authenticator < Auth::Authenticator # jwt encoding is causing auth to fail in quite a few conditions # skipping omniauth.provider :google_oauth2, - :setup => lambda { |env| - strategy = env["omniauth.strategy"] + setup: lambda { |env| + strategy = env["omniauth.strategy"] strategy.options[:client_id] = SiteSetting.google_oauth2_client_id strategy.options[:client_secret] = SiteSetting.google_oauth2_client_secret }, diff --git a/lib/auth/instagram_authenticator.rb b/lib/auth/instagram_authenticator.rb index ba2dd7f1bb0..507981ef2aa 100644 --- a/lib/auth/instagram_authenticator.rb +++ b/lib/auth/instagram_authenticator.rb @@ -39,8 +39,8 @@ class Auth::InstagramAuthenticator < Auth::Authenticator def register_middleware(omniauth) omniauth.provider :instagram, - :setup => lambda { |env| - strategy = env["omniauth.strategy"] + setup: lambda { |env| + strategy = env["omniauth.strategy"] strategy.options[:client_id] = SiteSetting.instagram_consumer_key strategy.options[:client_secret] = SiteSetting.instagram_consumer_secret } diff --git a/lib/auth/oauth2_authenticator.rb b/lib/auth/oauth2_authenticator.rb index 5484a19f5fb..cadd1022a7b 100644 --- a/lib/auth/oauth2_authenticator.rb +++ b/lib/auth/oauth2_authenticator.rb @@ -5,7 +5,7 @@ class Auth::OAuth2Authenticator < Auth::Authenticator end # only option at the moment is :trusted - def initialize(name, opts={}) + def initialize(name, opts = {}) @name = name @opts = opts end diff --git a/lib/auth/open_id_authenticator.rb b/lib/auth/open_id_authenticator.rb index 04f2764a9cd..1bb17447c7f 100644 --- a/lib/auth/open_id_authenticator.rb +++ b/lib/auth/open_id_authenticator.rb @@ -49,15 +49,14 @@ class Auth::OpenIdAuthenticator < Auth::Authenticator ) end - def register_middleware(omniauth) omniauth.provider :open_id, - :setup => lambda { |env| - strategy = env["omniauth.strategy"] + setup: lambda { |env| + strategy = env["omniauth.strategy"] strategy.options[:store] = OpenID::Store::Redis.new($redis) }, - :name => name, - :identifier => identifier, - :require => "omniauth-openid" + name: name, + identifier: identifier, + require: "omniauth-openid" end end diff --git a/lib/auth/result.rb b/lib/auth/result.rb index eabc6999995..0c18d3e1e5e 100644 --- a/lib/auth/result.rb +++ b/lib/auth/result.rb @@ -35,8 +35,8 @@ class Auth::Result if user.suspended? { suspended: true, - suspended_message: I18n.t( user.suspend_reason ? "login.suspended_with_reason" : "login.suspended", - {date: I18n.l(user.suspended_till, format: :date_only), reason: user.suspend_reason} ) + suspended_message: I18n.t(user.suspend_reason ? "login.suspended_with_reason" : "login.suspended", + date: I18n.l(user.suspended_till, format: :date_only), reason: user.suspend_reason) } else { diff --git a/lib/auth/twitter_authenticator.rb b/lib/auth/twitter_authenticator.rb index c5f91c04775..a88d2124c60 100644 --- a/lib/auth/twitter_authenticator.rb +++ b/lib/auth/twitter_authenticator.rb @@ -57,8 +57,8 @@ class Auth::TwitterAuthenticator < Auth::Authenticator def register_middleware(omniauth) omniauth.provider :twitter, - :setup => lambda { |env| - strategy = env["omniauth.strategy"] + setup: lambda { |env| + strategy = env["omniauth.strategy"] strategy.options[:consumer_key] = SiteSetting.twitter_consumer_key strategy.options[:consumer_secret] = SiteSetting.twitter_consumer_secret } diff --git a/lib/autospec/formatter.rb b/lib/autospec/formatter.rb index 98d872de8ef..a5fe09acbec 100644 --- a/lib/autospec/formatter.rb +++ b/lib/autospec/formatter.rb @@ -16,7 +16,7 @@ class Autospec::Formatter < RSpec::Core::Formatters::BaseTextFormatter def start(example_count) super File.delete(RSPEC_RESULT) if File.exists?(RSPEC_RESULT) - @fail_file = File.open(RSPEC_RESULT,"w") + @fail_file = File.open(RSPEC_RESULT, "w") end def example_passed(_notification) diff --git a/lib/autospec/manager.rb b/lib/autospec/manager.rb index 3cc52008e19..857967031cf 100644 --- a/lib/autospec/manager.rb +++ b/lib/autospec/manager.rb @@ -9,7 +9,7 @@ module Autospec; end class Autospec::Manager - def self.run(opts={}) + def self.run(opts = {}) self.new(opts).run end @@ -66,10 +66,10 @@ class Autospec::Manager Autospec::QunitRunner.new end - def ensure_all_specs_will_run(current_runner=nil) + def ensure_all_specs_will_run(current_runner = nil) puts "@@@@@@@@@@@@ ensure_all_specs_will_run" if @debug - @queue.reject!{|_,s,_| s == "spec"} + @queue.reject! { |_, s, _| s == "spec" } if current_runner @queue.concat [['spec', 'spec', current_runner]] @@ -151,14 +151,14 @@ class Autospec::Manager # try focus tag if failed_specs.length > 0 - filename,_ = failed_specs[0].split(":") + filename, _ = failed_specs[0].split(":") if filename && File.exist?(filename) && !File.directory?(filename) spec = File.read(filename) - start,_ = spec.split(/\S*#focus\S*$/) + start, _ = spec.split(/\S*#focus\S*$/) if start.length < spec.length line = start.scan(/\n/).length + 1 puts "Found #focus tag on line #{line}!" - failed_specs = ["#{filename}:#{line+1}"] + failed_specs = ["#{filename}:#{line + 1}"] end end end @@ -188,7 +188,7 @@ class Autospec::Manager FileUtils.rm_f(socket_path) server = SocketServer.new(socket_path) server.start do |line| - file,line = line.split(' ') + file, line = line.split(' ') file = file.sub(Rails.root.to_s << "/", "") # process_change can aquire a mutex and block # the acceptor @@ -196,7 +196,7 @@ class Autospec::Manager if file =~ /(es6|js)$/ process_change([[file]]) else - process_change([[file,line]]) + process_change([[file, line]]) end end "OK" @@ -213,7 +213,7 @@ class Autospec::Manager listener = Listen.to("#{path}/#{watch}", options) do |modified, added, _| paths = [modified, added].flatten paths.compact! - paths.map!{|long| long[(path.length+1)..-1]} + paths.map! { |long| long[(path.length + 1)..-1] } process_change(paths) end listener.start @@ -246,7 +246,7 @@ class Autospec::Manager end end # watchers - runner.watchers.each do |k,v| + runner.watchers.each do |k, v| if m = k.match(file) puts "@@@@@@@@@@@@ #{file} matched a watcher for #{runner}" if @debug hit = true diff --git a/lib/autospec/qunit_runner.rb b/lib/autospec/qunit_runner.rb index 577a7c824c0..5c570643704 100644 --- a/lib/autospec/qunit_runner.rb +++ b/lib/autospec/qunit_runner.rb @@ -144,7 +144,7 @@ module Autospec end def try_to_find_module_name(file) - file,_ = file.split(/:\d+$/) + file, _ = file.split(/:\d+$/) return unless File.exists?(file) File.open(file, "r").each_line do |line| if m = /module\(['"]([^'"]+)/i.match(line) diff --git a/lib/autospec/rspec_runner.rb b/lib/autospec/rspec_runner.rb index b6f5b90dd15..3fb9c093770 100644 --- a/lib/autospec/rspec_runner.rb +++ b/lib/autospec/rspec_runner.rb @@ -19,8 +19,8 @@ module Autospec watch(%r{^spec/fabricators/.+_fabricator\.rb$}) { "spec" } - watch(%r{^app/assets/javascripts/pretty-text/.*\.js\.es6$}) { "spec/components/pretty_text_spec.rb"} - watch(%r{^plugins/.*/discourse-markdown/.*\.js\.es6$}) { "spec/components/pretty_text_spec.rb"} + watch(%r{^app/assets/javascripts/pretty-text/.*\.js\.es6$}) { "spec/components/pretty_text_spec.rb" } + watch(%r{^plugins/.*/discourse-markdown/.*\.js\.es6$}) { "spec/components/pretty_text_spec.rb" } watch(%r{^plugins/.*/spec/.*\.rb}) diff --git a/lib/autospec/simple_runner.rb b/lib/autospec/simple_runner.rb index 01c0aada5ab..2c1fe8e656f 100644 --- a/lib/autospec/simple_runner.rb +++ b/lib/autospec/simple_runner.rb @@ -13,8 +13,8 @@ module Autospec "-f", "Autospec::Formatter", specs.split].flatten.join(" ") # launch rspec Dir.chdir(Rails.root) do - env = {"RAILS_ENV" => "test"} - if specs.split(' ').any?{|s| s =~ /^(.\/)?plugins/} + env = { "RAILS_ENV" => "test" } + if specs.split(' ').any? { |s| s =~ /^(.\/)?plugins/ } env["LOAD_PLUGINS"] = "1" puts "Loading plugins while running specs" end diff --git a/lib/autospec/spork_runner.rb b/lib/autospec/spork_runner.rb index fbd05d93ef5..b8ae2c8627e 100644 --- a/lib/autospec/spork_runner.rb +++ b/lib/autospec/spork_runner.rb @@ -30,7 +30,7 @@ module Autospec def run(specs) args = ["-r", "#{File.dirname(__FILE__)}/formatter.rb", "-f", "Autospec::Formatter", specs.split].flatten - spork_service.run(args,$stderr,$stdout) + spork_service.run(args, $stderr, $stdout) end def reload @@ -66,7 +66,7 @@ module Autospec def write_pid_file(file, pid) FileUtils.mkdir_p(Rails.root + "tmp/pids") - File.open(file,'w') do |f| + File.open(file, 'w') do |f| f.write(pid) end end @@ -95,7 +95,7 @@ module Autospec sleep 1 end - @spork_pid = Process.spawn({'RAILS_ENV' => 'test'}, "bundle exec spork") + @spork_pid = Process.spawn({ 'RAILS_ENV' => 'test' }, "bundle exec spork") write_pid_file(spork_pid_file, @spork_pid) running = false diff --git a/lib/avatar_lookup.rb b/lib/avatar_lookup.rb index d0b5877272b..d86871fee03 100644 --- a/lib/avatar_lookup.rb +++ b/lib/avatar_lookup.rb @@ -1,6 +1,6 @@ class AvatarLookup - def initialize(user_ids=[]) + def initialize(user_ids = []) @user_ids = user_ids.tap(&:compact!).tap(&:uniq!).tap(&:flatten!) end @@ -23,9 +23,9 @@ class AvatarLookup # adding tap here is a personal taste thing hash = {} User.joins(:user_emails) - .where(id: @user_ids) - .select(AvatarLookup.lookup_columns) - .each{ |user| hash[user.id] = user } + .where(id: @user_ids) + .select(AvatarLookup.lookup_columns) + .each { |user| hash[user.id] = user } hash end end diff --git a/lib/backup_restore/backup_restore.rb b/lib/backup_restore/backup_restore.rb index 12a9ecd21dd..c16314f98c0 100644 --- a/lib/backup_restore/backup_restore.rb +++ b/lib/backup_restore/backup_restore.rb @@ -11,11 +11,11 @@ module BackupRestore METADATA_FILE = "meta.json" LOGS_CHANNEL = "/admin/backups/logs" - def self.backup!(user_id, opts={}) + def self.backup!(user_id, opts = {}) start! BackupRestore::Backuper.new(user_id, opts) end - def self.restore!(user_id, opts={}) + def self.restore!(user_id, opts = {}) start! BackupRestore::Restorer.new(user_id, opts) end diff --git a/lib/backup_restore/backuper.rb b/lib/backup_restore/backuper.rb index c70a7a58506..9465457092d 100644 --- a/lib/backup_restore/backuper.rb +++ b/lib/backup_restore/backuper.rb @@ -3,7 +3,7 @@ module BackupRestore class Backuper attr_reader :success - def initialize(user_id, opts={}) + def initialize(user_id, opts = {}) @user_id = user_id @client_id = opts[:client_id] @publish_to_message_bus = opts[:publish_to_message_bus] || false diff --git a/lib/backup_restore/restorer.rb b/lib/backup_restore/restorer.rb index 2f4e7cdd46c..c0c2b413770 100644 --- a/lib/backup_restore/restorer.rb +++ b/lib/backup_restore/restorer.rb @@ -8,7 +8,7 @@ module BackupRestore class Restorer attr_reader :success - def initialize(user_id, opts={}) + def initialize(user_id, opts = {}) @user_id = user_id @client_id = opts[:client_id] @filename = opts[:filename] diff --git a/lib/badge_queries.rb b/lib/badge_queries.rb index 20a08d7daf0..cdb5ac8d6ab 100644 --- a/lib/badge_queries.rb +++ b/lib/badge_queries.rb @@ -133,44 +133,44 @@ SQL GROUP BY acting_user_id SQL - def self.invite_badge(count,trust_level) -" - SELECT u.id user_id, current_timestamp granted_at - FROM users u - WHERE u.id IN ( - SELECT invited_by_id - FROM invites i - JOIN users u2 ON u2.id = i.user_id - WHERE i.deleted_at IS NULL AND u2.active AND u2.trust_level >= #{trust_level.to_i} AND not u2.blocked - GROUP BY invited_by_id - HAVING COUNT(*) >= #{count.to_i} - ) AND u.active AND NOT u.blocked AND u.id > 0 AND - (:backfill OR u.id IN (:user_ids) ) -" + def self.invite_badge(count, trust_level) + " + SELECT u.id user_id, current_timestamp granted_at + FROM users u + WHERE u.id IN ( + SELECT invited_by_id + FROM invites i + JOIN users u2 ON u2.id = i.user_id + WHERE i.deleted_at IS NULL AND u2.active AND u2.trust_level >= #{trust_level.to_i} AND not u2.blocked + GROUP BY invited_by_id + HAVING COUNT(*) >= #{count.to_i} + ) AND u.active AND NOT u.blocked AND u.id > 0 AND + (:backfill OR u.id IN (:user_ids) ) + " end def self.like_badge(count, is_topic) # we can do better with dates, but its hard work -" - SELECT p.user_id, p.id post_id, p.updated_at granted_at - FROM badge_posts p - WHERE #{is_topic ? "p.post_number = 1" : "p.post_number > 1" } AND p.like_count >= #{count.to_i} AND - (:backfill OR p.id IN (:post_ids) ) -" + " + SELECT p.user_id, p.id post_id, p.updated_at granted_at + FROM badge_posts p + WHERE #{is_topic ? "p.post_number = 1" : "p.post_number > 1" } AND p.like_count >= #{count.to_i} AND + (:backfill OR p.id IN (:post_ids) ) + " end def self.trust_level(level) # we can do better with dates, but its hard work figuring this out historically -" - SELECT u.id user_id, current_timestamp granted_at FROM users u - WHERE trust_level >= #{level.to_i} AND ( - :backfill OR u.id IN (:user_ids) - ) -" + " + SELECT u.id user_id, current_timestamp granted_at FROM users u + WHERE trust_level >= #{level.to_i} AND ( + :backfill OR u.id IN (:user_ids) + ) + " end def self.sharing_badge(count) -< ?", 1.day.ago) - .order('created_at desc') - .limit(SiteSetting.sequential_replies_threshold) - .pluck(:user_id) + .where("created_at > ?", 1.day.ago) + .order('created_at desc') + .limit(SiteSetting.sequential_replies_threshold) + .pluck(:user_id) # Did we get back as many posts as we asked for, and are they all by the current user? return if recent_posts_user_ids.size != SiteSetting.sequential_replies_threshold || - recent_posts_user_ids.detect {|u| u != @user.id } + recent_posts_user_ids.detect { |u| u != @user.id } # If we got this far, log that we've nagged them about the sequential replies UserHistory.create!(action: UserHistory.actions[:notified_about_sequential_replies], target_user_id: @user.id, - topic_id: @details[:topic_id] ) + topic_id: @details[:topic_id]) { id: 'sequential_replies', @@ -149,7 +149,7 @@ class ComposerMessagesFinder order('created_at desc'). limit(SiteSetting.get_a_room_threshold). pluck(:reply_to_user_id). - find_all {|uid| uid != @user.id && uid == reply_to_user_id} + find_all { |uid| uid != @user.id && uid == reply_to_user_id } return unless last_x_replies.size == SiteSetting.get_a_room_threshold return unless @topic.posts.count('distinct user_id') >= min_users_posted diff --git a/lib/content_buffer.rb b/lib/content_buffer.rb index 99d176d4cb3..8db6146f0bb 100644 --- a/lib/content_buffer.rb +++ b/lib/content_buffer.rb @@ -35,7 +35,7 @@ class ContentBuffer end # fix last line - @lines[start_row] << @lines[finish_row][finish_col-1..-1] + @lines[start_row] << @lines[finish_row][finish_col - 1..-1] end if transform[:operation] == :insert diff --git a/lib/cooked_post_processor.rb b/lib/cooked_post_processor.rb index 9d950f4cf06..c3d4afc198d 100644 --- a/lib/cooked_post_processor.rb +++ b/lib/cooked_post_processor.rb @@ -9,7 +9,7 @@ class CookedPostProcessor attr_reader :cooking_options - def initialize(post, opts={}) + def initialize(post, opts = {}) @dirty = false @opts = opts @post = post @@ -63,7 +63,7 @@ class CookedPostProcessor upload_ids |= oneboxed_image_uploads.pluck(:id) - values = upload_ids.map{ |u| "(#{@post.id},#{u})" }.join(",") + values = upload_ids.map { |u| "(#{@post.id},#{u})" }.join(",") PostUpload.transaction do PostUpload.delete_all(post_id: @post.id) if upload_ids.length > 0 @@ -142,11 +142,11 @@ class CookedPostProcessor original_width, original_height = original_image_size.map(&:to_f) if w > 0 - ratio = w/original_width - [w.floor, (original_height*ratio).floor] + ratio = w / original_width + [w.floor, (original_height * ratio).floor] else - ratio = h/original_height - [(original_width*ratio).floor, h.floor] + ratio = h / original_height + [(original_width * ratio).floor, h.floor] end end end @@ -238,7 +238,7 @@ class CookedPostProcessor false end - def add_lightbox!(img, original_width, original_height, upload=nil) + def add_lightbox!(img, original_width, original_height, upload = nil) # first, create a div to hold our lightbox lightbox = Nokogiri::XML::Node.new("div", @doc) lightbox["class"] = "lightbox-wrapper" @@ -283,7 +283,7 @@ class CookedPostProcessor return I18n.t("upload.pasted_image_filename") end - def create_span_node(klass, content=nil) + def create_span_node(klass, content = nil) span = Nokogiri::XML::Node.new("span", @doc) span.content = content if content span["class"] = klass @@ -374,7 +374,7 @@ class CookedPostProcessor # log the site setting change reason = I18n.t("disable_remote_images_download_reason") staff_action_logger = StaffActionLogger.new(Discourse.system_user) - staff_action_logger.log_site_setting_change("download_remote_images_to_local", true, false, { details: reason }) + staff_action_logger.log_site_setting_change("download_remote_images_to_local", true, false, details: reason) # also send a private message to the site contact user notify_about_low_disk_space diff --git a/lib/current_user.rb b/lib/current_user.rb index 01c5570028b..a5035b97646 100644 --- a/lib/current_user.rb +++ b/lib/current_user.rb @@ -8,19 +8,18 @@ module CurrentUser Discourse.current_user_provider.new(env).current_user end - # can be used to pretend current user does no exist, for CSRF attacks def clear_current_user @current_user_provider = Discourse.current_user_provider.new({}) end def log_on_user(user) - current_user_provider.log_on_user(user,session,cookies) + current_user_provider.log_on_user(user, session, cookies) user.logged_in end def log_off_user - current_user_provider.log_off_user(session,cookies) + current_user_provider.log_off_user(session, cookies) end def is_api? @@ -36,7 +35,7 @@ module CurrentUser end def refresh_session(user) - current_user_provider.refresh_session(user,session,cookies) + current_user_provider.refresh_session(user, session, cookies) end private diff --git a/lib/demon/base.rb b/lib/demon/base.rb index 6fb162faad5..188a27e9fe6 100644 --- a/lib/demon/base.rb +++ b/lib/demon/base.rb @@ -7,7 +7,7 @@ class Demon::Base @demons end - def self.start(count=1) + def self.start(count = 1) @demons ||= {} count.times do |i| (@demons["#{prefix}_#{i}"] ||= new(i)).start @@ -50,7 +50,7 @@ class Demon::Base "#{Rails.root}/tmp/pids/#{self.class.prefix}_#{@index}.pid" end - def alive?(pid=nil) + def alive?(pid = nil) pid ||= @pid if pid Demon::Base.alive?(pid) @@ -63,14 +63,14 @@ class Demon::Base @started = false if @pid # TODO configurable stop signal - Process.kill("HUP",@pid) + Process.kill("HUP", @pid) wait_for_stop = lambda { timeout = @stop_timeout while alive? && timeout > 0 - timeout -= (@stop_timeout/10.0) - sleep(@stop_timeout/10.0) + timeout -= (@stop_timeout / 10.0) + sleep(@stop_timeout / 10.0) Process.waitpid(@pid, Process::WNOHANG) rescue -1 end @@ -86,7 +86,6 @@ class Demon::Base wait_for_stop.call - @pid = nil @started = false end @@ -116,7 +115,7 @@ class Demon::Base if existing = already_running? # should not happen ... so kill violently STDERR.puts "Attempting to kill pid #{existing}" - Process.kill("TERM",existing) + Process.kill("TERM", existing) end @started = true @@ -156,7 +155,7 @@ class Demon::Base def write_pid_file FileUtils.mkdir_p(Rails.root + "tmp/pids") - File.open(pid_file,'w') do |f| + File.open(pid_file, 'w') do |f| f.write(@pid) end end @@ -182,7 +181,6 @@ class Demon::Base end end - def suppress_stdout true end diff --git a/lib/demon/rails_autospec.rb b/lib/demon/rails_autospec.rb index 92d15a8fb25..702876c87e4 100644 --- a/lib/demon/rails_autospec.rb +++ b/lib/demon/rails_autospec.rb @@ -12,9 +12,9 @@ class Demon::RailsAutospec < Demon::Base require "rack" ENV["RAILS_ENV"] = "test" Rack::Server.start( - :config => "config.ru", - :AccessLog => [], - :Port => ENV["TEST_SERVER_PORT"] || 60099, + config: "config.ru", + AccessLog: [], + Port: ENV["TEST_SERVER_PORT"] || 60099, ) rescue => e STDERR.puts e.message diff --git a/lib/demon/sidekiq.rb b/lib/demon/sidekiq.rb index a6f01944152..85e343c9879 100644 --- a/lib/demon/sidekiq.rb +++ b/lib/demon/sidekiq.rb @@ -7,7 +7,7 @@ class Demon::Sidekiq < Demon::Base end def self.after_fork(&blk) - blk ? (@blk=blk) : @blk + blk ? (@blk = blk) : @blk end private diff --git a/lib/directory_helper.rb b/lib/directory_helper.rb index ec8eaccc5ae..7f8e6b86e31 100644 --- a/lib/directory_helper.rb +++ b/lib/directory_helper.rb @@ -2,7 +2,7 @@ module DirectoryHelper def tmp_directory(prefix) directory_cache[prefix] ||= begin - f = File.join( Rails.root, 'tmp', Time.now.strftime("#{prefix}%Y%m%d%H%M%S") ) + f = File.join(Rails.root, 'tmp', Time.now.strftime("#{prefix}%Y%m%d%H%M%S")) FileUtils.mkdir_p(f) unless Dir[f].present? f end diff --git a/lib/discourse.rb b/lib/discourse.rb index 3a29209a3b3..dd9d9d3fef9 100644 --- a/lib/discourse.rb +++ b/lib/discourse.rb @@ -63,7 +63,7 @@ module Discourse # When they don't have permission to do something class InvalidAccess < StandardError attr_reader :obj - def initialize(msg=nil, obj=nil) + def initialize(msg = nil, obj = nil) super(msg) @obj = obj end @@ -115,7 +115,6 @@ module Discourse set end - def self.activate_plugins! all_plugins = Plugin::Instance.find_all("#{Rails.root}/plugins") @@ -144,11 +143,11 @@ module Discourse end def self.official_plugins - plugins.find_all{|p| p.metadata.official?} + plugins.find_all { |p| p.metadata.official? } end def self.unofficial_plugins - plugins.find_all{|p| !p.metadata.official?} + plugins.find_all { |p| !p.metadata.official? } end def self.assets_digest @@ -378,7 +377,7 @@ module Discourse Rails.cache.reconnect Logster.store.redis.reconnect # shuts down all connections in the pool - Sidekiq.redis_pool.shutdown{|c| nil} + Sidekiq.redis_pool.shutdown { |c| nil } # re-establish Sidekiq.redis = sidekiq_redis_config start_connection_reaper @@ -402,7 +401,7 @@ module Discourse sleep GlobalSetting.connection_reaper_interval reap_connections(GlobalSetting.connection_reaper_age, GlobalSetting.connection_reaper_max_age) rescue => e - Discourse.handle_exception(e, {message: "Error reaping connections"}) + Discourse.handle_exception(e, message: "Error reaping connections") end end end @@ -410,7 +409,7 @@ module Discourse def self.reap_connections(idle, max_age) pools = [] - ObjectSpace.each_object(ActiveRecord::ConnectionAdapters::ConnectionPool){|pool| pools << pool} + ObjectSpace.each_object(ActiveRecord::ConnectionAdapters::ConnectionPool) { |pool| pools << pool } pools.each do |pool| pool.drain(idle.seconds, max_age.seconds) @@ -433,7 +432,7 @@ module Discourse def self.reset_active_record_cache_if_needed(e) last_cache_reset = Discourse.last_ar_cache_reset - if e && e.message =~ /UndefinedColumn/ && (last_cache_reset.nil? || last_cache_reset < 30.seconds.ago) + if e && e.message =~ /UndefinedColumn/ && (last_cache_reset.nil? || last_cache_reset < 30.seconds.ago) Rails.logger.warn "Clear Active Record cache cause schema appears to have changed!" Discourse.last_ar_cache_reset = Time.zone.now Discourse.reset_active_record_cache @@ -448,5 +447,4 @@ module Discourse nil end - end diff --git a/lib/discourse_cookie_store.rb b/lib/discourse_cookie_store.rb index f962ba3a0c9..2dbd56792f0 100644 --- a/lib/discourse_cookie_store.rb +++ b/lib/discourse_cookie_store.rb @@ -1,6 +1,6 @@ class ActionDispatch::Session::DiscourseCookieStore < ActionDispatch::Session::CookieStore - def initialize(app, options={}) - super(app,options) + def initialize(app, options = {}) + super(app, options) end private diff --git a/lib/discourse_hub.rb b/lib/discourse_hub.rb index 174ca23fb8a..940800be17c 100644 --- a/lib/discourse_hub.rb +++ b/lib/discourse_hub.rb @@ -5,7 +5,7 @@ module DiscourseHub STATS_FETCHED_AT_KEY = "stats_fetched_at" def self.version_check_payload - default_payload = { installed_version: Discourse::VERSION::STRING }.merge!(Discourse.git_branch == "unknown" ? {} : {branch: Discourse.git_branch}) + default_payload = { installed_version: Discourse::VERSION::STRING }.merge!(Discourse.git_branch == "unknown" ? {} : { branch: Discourse.git_branch }) default_payload.merge!(get_payload) end @@ -23,23 +23,23 @@ module DiscourseHub SiteSetting.share_anonymized_statistics && stats_fetched_at < 7.days.ago ? About.fetch_cached_stats.symbolize_keys : {} end - def self.get(rel_url, params={}) + def self.get(rel_url, params = {}) singular_action :get, rel_url, params end - def self.post(rel_url, params={}) + def self.post(rel_url, params = {}) collection_action :post, rel_url, params end - def self.put(rel_url, params={}) + def self.put(rel_url, params = {}) collection_action :put, rel_url, params end - def self.delete(rel_url, params={}) + def self.delete(rel_url, params = {}) singular_action :delete, rel_url, params end - def self.singular_action(action, rel_url, params={}) + def self.singular_action(action, rel_url, params = {}) JSON.parse(Excon.send(action, "#{hub_base_url}#{rel_url}", headers: { 'Referer' => referer, 'Accept' => accepts.join(', ') }, @@ -48,7 +48,7 @@ module DiscourseHub ).body) end - def self.collection_action(action, rel_url, params={}) + def self.collection_action(action, rel_url, params = {}) JSON.parse(Excon.send(action, "#{hub_base_url}#{rel_url}", body: JSON[params], diff --git a/lib/discourse_plugin.rb b/lib/discourse_plugin.rb index b39b676c024..a2f86705aec 100644 --- a/lib/discourse_plugin.rb +++ b/lib/discourse_plugin.rb @@ -27,10 +27,10 @@ class DiscoursePlugin # Find the modules defined in the plugin with "Mixin" in their name. def self.mixins constants.map { |const_name| const_get(const_name) } - .select { |const| const.class == Module && const.name["Mixin"] } + .select { |const| const.class == Module && const.name["Mixin"] } end - def register_js(file, opts={}) + def register_js(file, opts = {}) @registry.register_js(file, opts) end @@ -38,7 +38,7 @@ class DiscoursePlugin @registry.register_css(file) end - def register_archetype(name, options={}) + def register_archetype(name, options = {}) @registry.register_archetype(name, options) end @@ -48,4 +48,3 @@ class DiscoursePlugin end end - diff --git a/lib/discourse_plugin_registry.rb b/lib/discourse_plugin_registry.rb index 568c48932d0..9e404c16c52 100644 --- a/lib/discourse_plugin_registry.rb +++ b/lib/discourse_plugin_registry.rb @@ -70,7 +70,7 @@ class DiscoursePluginRegistry end - def register_js(filename, options={}) + def register_js(filename, options = {}) # If we have a server side option, add that too. self.class.javascripts << filename end @@ -79,15 +79,15 @@ class DiscoursePluginRegistry self.class.stylesheets << filename end - def register_archetype(name, options={}) + def register_archetype(name, options = {}) Archetype.register(name, options) end - def self.register_glob(root, extension, options=nil) + def self.register_glob(root, extension, options = nil) self.asset_globs << [root, extension, options || {}] end - def self.each_globbed_asset(each_options=nil) + def self.each_globbed_asset(each_options = nil) each_options ||= {} self.asset_globs.each do |g| @@ -108,7 +108,7 @@ class DiscoursePluginRegistry JS_REGEX = /\.js$|\.js\.erb$|\.js\.es6$/ HANDLEBARS_REGEX = /\.hbs$|\.js\.handlebars$/ - def self.register_asset(asset, opts=nil) + def self.register_asset(asset, opts = nil) if asset =~ JS_REGEX if opts == :admin self.admin_javascripts << asset @@ -140,7 +140,7 @@ class DiscoursePluginRegistry html_builders[name] = block end - def self.build_html(name, ctx=nil) + def self.build_html(name, ctx = nil) html_builders[name]&.call(ctx) end diff --git a/lib/discourse_redis.rb b/lib/discourse_redis.rb index 2277b751104..fccbb050e38 100644 --- a/lib/discourse_redis.rb +++ b/lib/discourse_redis.rb @@ -125,10 +125,10 @@ class DiscourseRedis end def self.slave_config(options = config) - options.dup.merge!({ host: options[:slave_host], port: options[:slave_port] }) + options.dup.merge!(host: options[:slave_host], port: options[:slave_port]) end - def initialize(config=nil) + def initialize(config = nil) @config = config || DiscourseRedis.config @redis = DiscourseRedis.raw_connection(@config) end @@ -182,7 +182,7 @@ class DiscourseRedis end def mget(*args) - args.map!{|a| "#{namespace}:#{a}"} + args.map! { |a| "#{namespace}:#{a}" } DiscourseRedis.ignore_readonly { @redis.mget(*args) } end @@ -193,10 +193,10 @@ class DiscourseRedis end end - def keys(pattern=nil) + def keys(pattern = nil) DiscourseRedis.ignore_readonly do len = namespace.length + 1 - @redis.keys("#{namespace}:#{pattern || '*'}").map{ + @redis.keys("#{namespace}:#{pattern || '*'}").map { |k| k[len..-1] } end @@ -210,7 +210,7 @@ class DiscourseRedis def flushdb DiscourseRedis.ignore_readonly do - keys.each{|k| del(k)} + keys.each { |k| del(k) } end end diff --git a/lib/discourse_tagging.rb b/lib/discourse_tagging.rb index 67e4d711712..0fcf8bda9b7 100644 --- a/lib/discourse_tagging.rb +++ b/lib/discourse_tagging.rb @@ -3,7 +3,6 @@ module DiscourseTagging TAGS_FIELD_NAME = "tags" TAGS_FILTER_REGEXP = /[\/\?#\[\]@!\$&'\(\)\*\+,;=\.%\\`^\s|\{\}"<>]+/ # /?#[]@!$&'()*+,;=.%\`^|{}"<> - def self.tag_topic_by_names(topic, guardian, tag_names_arg, append: false) if SiteSetting.tagging_enabled tag_names = DiscourseTagging.tags_for_saving(tag_names_arg, guardian) || [] @@ -33,11 +32,9 @@ module DiscourseTagging # guardian is explicitly nil cause we don't want to strip all # staff tags that already passed validation - tags = filter_allowed_tags(Tag.where(name: tag_names), nil, { - for_input: true, - category: category, - selected_tags: tag_names - }).to_a + tags = filter_allowed_tags(Tag.where(name: tag_names), nil, for_input: true, + category: category, + selected_tags: tag_names).to_a if tags.size < tag_names.size && (category.nil? || category.tags.count == 0) tag_names.each do |name| @@ -51,7 +48,7 @@ module DiscourseTagging else topic.tags = [] end - topic.tags_changed=true + topic.tags_changed = true end true end @@ -61,7 +58,7 @@ module DiscourseTagging # category: a Category to which the object being tagged belongs # for_input: result is for an input field, so only show permitted tags # selected_tags: an array of tag names that are in the current selection - def self.filter_allowed_tags(query, guardian, opts={}) + def self.filter_allowed_tags(query, guardian, opts = {}) term = opts[:term] if term.present? term.gsub!("_", "\\_") @@ -124,9 +121,9 @@ module DiscourseTagging else # One tag per group restriction exclude_group_ids = TagGroup.where(one_per_topic: true) - .joins(:tag_group_memberships) - .where('tag_group_memberships.tag_id in (?)', selected_tag_ids) - .pluck(:id) + .joins(:tag_group_memberships) + .where('tag_group_memberships.tag_id in (?)', selected_tag_ids) + .pluck(:id) if exclude_group_ids.empty? sql = "tags.id NOT IN (#{select_sql} WHERE tg.parent_tag_id NOT IN (?))" @@ -135,9 +132,9 @@ module DiscourseTagging # It's possible that the selected tags violate some one-tag-per-group restrictions, # so filter them out by picking one from each group. limit_tag_ids = TagGroupMembership.select('distinct on (tag_group_id) tag_id') - .where(tag_id: selected_tag_ids) - .where(tag_group_id: exclude_group_ids) - .map(&:tag_id) + .where(tag_id: selected_tag_ids) + .where(tag_group_id: exclude_group_ids) + .map(&:tag_id) sql = "(tags.id NOT IN (#{select_sql} WHERE (tg.parent_tag_id NOT IN (?) OR tg.id in (?))) OR tags.id IN (?))" query = query.where(sql, selected_tag_ids, exclude_group_ids, limit_tag_ids) end @@ -149,8 +146,8 @@ module DiscourseTagging def self.clean_tag(tag) tag.downcase.strip - .gsub(/\s+/, '-').squeeze('-') - .gsub(TAGS_FILTER_REGEXP, '')[0...SiteSetting.max_tag_length] + .gsub(/\s+/, '-').squeeze('-') + .gsub(TAGS_FILTER_REGEXP, '')[0...SiteSetting.max_tag_length] end def self.staff_only_tags(tags) @@ -164,7 +161,7 @@ module DiscourseTagging tag_diff.present? ? tag_diff : nil end - def self.tags_for_saving(tags_arg, guardian, opts={}) + def self.tags_for_saving(tags_arg, guardian, opts = {}) return [] unless guardian.can_tag_topics? && tags_arg.present? @@ -179,7 +176,7 @@ module DiscourseTagging return opts[:unlimited] ? tag_names : tag_names[0...SiteSetting.max_tags_per_topic] end - def self.add_or_create_tags_by_name(taggable, tag_names_arg, opts={}) + def self.add_or_create_tags_by_name(taggable, tag_names_arg, opts = {}) tag_names = DiscourseTagging.tags_for_saving(tag_names_arg, Guardian.new(Discourse.system_user), opts) || [] if taggable.tags.pluck(:name).sort != tag_names.sort taggable.tags = Tag.where(name: tag_names).all diff --git a/lib/discourse_updates.rb b/lib/discourse_updates.rb index 3e2f14c6823..dd568063608 100644 --- a/lib/discourse_updates.rb +++ b/lib/discourse_updates.rb @@ -33,10 +33,10 @@ module DiscourseUpdates # Handle cases when version check data is old so we report something that makes sense - if (version_info.updated_at.nil? or # never performed a version check - last_installed_version != Discourse::VERSION::STRING or # upgraded since the last version check - (version_info.missing_versions_count == 0 and version_info.latest_version != version_info.installed_version) or # old data - (version_info.missing_versions_count != 0 and version_info.latest_version == version_info.installed_version)) # old data + if (version_info.updated_at.nil? || # never performed a version check + last_installed_version != (Discourse::VERSION::STRING) || # upgraded since the last version check + (version_info.missing_versions_count == (0) && version_info.latest_version != (version_info.installed_version)) || # old data + (version_info.missing_versions_count != (0) && version_info.latest_version == (version_info.installed_version))) # old data Jobs.enqueue(:version_check, all_sites: true) version_info.version_check_pending = true unless version_info.updated_at.nil? @@ -92,7 +92,7 @@ module DiscourseUpdates if versions.present? # store the list in redis version_keys = [] - versions[0,5].each do |v| + versions[0, 5].each do |v| key = "#{missing_versions_key_prefix}:#{v['version']}" $redis.mapped_hmset key, v version_keys << key @@ -108,7 +108,6 @@ module DiscourseUpdates keys.present? ? keys.map { |k| $redis.hgetall(k) } : [] end - private def last_installed_version_key diff --git a/lib/distributed_cache.rb b/lib/distributed_cache.rb index 31753320364..2b08e642169 100644 --- a/lib/distributed_cache.rb +++ b/lib/distributed_cache.rb @@ -17,7 +17,7 @@ class DistributedCache end def self.process_message(message) - i = @subscribers.length-1 + i = @subscribers.length - 1 payload = message.data @@ -32,9 +32,9 @@ class DistributedCache hash = current.hash(message.site_id) case payload["op"] - when "set" then hash[payload["key"]] = payload["marshalled"] ? Marshal.load(Base64.decode64(payload["value"])) : payload["value"] - when "delete" then hash.delete(payload["key"]) - when "clear" then hash.clear + when "set" then hash[payload["key"]] = payload["marshalled"] ? Marshal.load(Base64.decode64(payload["value"])) : payload["value"] + when "delete" then hash.delete(payload["key"]) + when "clear" then hash.clear end rescue WeakRef::RefError @@ -66,22 +66,22 @@ class DistributedCache message[:origin] = hash.identity message[:hash_key] = hash.key message[:discourse_version] = Discourse.git_version - MessageBus.publish(channel_name, message, { user_ids: [-1] }) + MessageBus.publish(channel_name, message, user_ids: [-1]) end def self.set(hash, key, value) # special support for set marshal = (Set === value || Hash === value) value = Base64.encode64(Marshal.dump(value)) if marshal - publish(hash, { op: :set, key: key, value: value, marshalled: marshal }) + publish(hash, op: :set, key: key, value: value, marshalled: marshal) end def self.delete(hash, key) - publish(hash, { op: :delete, key: key }) + publish(hash, op: :delete, key: key) end def self.clear(hash) - publish(hash, { op: :clear }) + publish(hash, op: :clear) end def self.register(hash) @@ -103,7 +103,7 @@ class DistributedCache (@seed_id ||= SecureRandom.hex) + "#{Process.pid}" end - def []=(k,v) + def []=(k, v) k = k.to_s if Symbol === k DistributedCache.set(self, k, v) hash[k] = v diff --git a/lib/distributed_memoizer.rb b/lib/distributed_memoizer.rb index c5e7031d37e..e80b687923a 100644 --- a/lib/distributed_memoizer.rb +++ b/lib/distributed_memoizer.rb @@ -19,7 +19,7 @@ class DistributedMemoizer begin while Time.new < start + MAX_WAIT && !got_lock LOCK.synchronize do - got_lock = get_lock(redis,redis_lock_key) + got_lock = get_lock(redis, redis_lock_key) end sleep 0.001 end @@ -38,7 +38,6 @@ class DistributedMemoizer result end - def self.redis_lock_key(key) "memoize_lock_" << key end diff --git a/lib/distributed_mutex.rb b/lib/distributed_mutex.rb index 6a0e0af8cd7..b014a554a32 100644 --- a/lib/distributed_mutex.rb +++ b/lib/distributed_mutex.rb @@ -1,11 +1,11 @@ # Cross-process locking using Redis. class DistributedMutex - def self.synchronize(key, redis=nil, &blk) + def self.synchronize(key, redis = nil, &blk) self.new(key, redis).synchronize(&blk) end - def initialize(key, redis=nil) + def initialize(key, redis = nil) @key = key @redis = redis || $redis @mutex = Mutex.new diff --git a/lib/email/message_builder.rb b/lib/email/message_builder.rb index 7632a244843..c72d7bca9ea 100644 --- a/lib/email/message_builder.rb +++ b/lib/email/message_builder.rb @@ -17,7 +17,7 @@ module Email class MessageBuilder attr_reader :template_args - def initialize(to, opts=nil) + def initialize(to, opts = nil) @to = to @opts = opts || {} @@ -166,7 +166,6 @@ module Email result end - protected def reply_key @@ -195,11 +194,13 @@ module Email @reply_by_email_address = SiteSetting.reply_by_email_address.dup @reply_by_email_address.gsub!("%{reply_key}", reply_key) - @reply_by_email_address = if private_reply? - alias_email(@reply_by_email_address) - else - site_alias_email(@reply_by_email_address) - end + + @reply_by_email_address = + if private_reply? + alias_email(@reply_by_email_address) + else + site_alias_email(@reply_by_email_address) + end end def alias_email(source) diff --git a/lib/email/processor.rb b/lib/email/processor.rb index a477f58e490..a13d3814dff 100644 --- a/lib/email/processor.rb +++ b/lib/email/processor.rb @@ -2,12 +2,12 @@ module Email class Processor - def initialize(mail, retry_on_rate_limit=true) + def initialize(mail, retry_on_rate_limit = true) @mail = mail @retry_on_rate_limit = retry_on_rate_limit end - def self.process!(mail, retry_on_rate_limit=true) + def self.process!(mail, retry_on_rate_limit = true) Email::Processor.new(mail, retry_on_rate_limit).process! end @@ -35,23 +35,23 @@ module Email def handle_failure(mail_string, e, incoming_email) message_template = case e - when Email::Receiver::EmptyEmailError then :email_reject_empty - when Email::Receiver::NoBodyDetectedError then :email_reject_empty - when Email::Receiver::UserNotFoundError then :email_reject_user_not_found - when Email::Receiver::ScreenedEmailError then :email_reject_screened_email - when Email::Receiver::AutoGeneratedEmailError then :email_reject_auto_generated - when Email::Receiver::InactiveUserError then :email_reject_inactive_user - when Email::Receiver::BlockedUserError then :email_reject_blocked_user - when Email::Receiver::BadDestinationAddress then :email_reject_bad_destination_address - when Email::Receiver::StrangersNotAllowedError then :email_reject_strangers_not_allowed - when Email::Receiver::InsufficientTrustLevelError then :email_reject_insufficient_trust_level - when Email::Receiver::ReplyUserNotMatchingError then :email_reject_reply_user_not_matching - when Email::Receiver::TopicNotFoundError then :email_reject_topic_not_found - when Email::Receiver::TopicClosedError then :email_reject_topic_closed - when Email::Receiver::InvalidPost then :email_reject_invalid_post - when ActiveRecord::Rollback then :email_reject_invalid_post - when Email::Receiver::InvalidPostAction then :email_reject_invalid_post_action - when Discourse::InvalidAccess then :email_reject_invalid_access + when Email::Receiver::EmptyEmailError then :email_reject_empty + when Email::Receiver::NoBodyDetectedError then :email_reject_empty + when Email::Receiver::UserNotFoundError then :email_reject_user_not_found + when Email::Receiver::ScreenedEmailError then :email_reject_screened_email + when Email::Receiver::AutoGeneratedEmailError then :email_reject_auto_generated + when Email::Receiver::InactiveUserError then :email_reject_inactive_user + when Email::Receiver::BlockedUserError then :email_reject_blocked_user + when Email::Receiver::BadDestinationAddress then :email_reject_bad_destination_address + when Email::Receiver::StrangersNotAllowedError then :email_reject_strangers_not_allowed + when Email::Receiver::InsufficientTrustLevelError then :email_reject_insufficient_trust_level + when Email::Receiver::ReplyUserNotMatchingError then :email_reject_reply_user_not_matching + when Email::Receiver::TopicNotFoundError then :email_reject_topic_not_found + when Email::Receiver::TopicClosedError then :email_reject_topic_closed + when Email::Receiver::InvalidPost then :email_reject_invalid_post + when ActiveRecord::Rollback then :email_reject_invalid_post + when Email::Receiver::InvalidPostAction then :email_reject_invalid_post_action + when Discourse::InvalidAccess then :email_reject_invalid_access else :email_reject_unrecognized_error end diff --git a/lib/email/receiver.rb b/lib/email/receiver.rb index 6bb65bbded9..94a8dd77b38 100644 --- a/lib/email/receiver.rb +++ b/lib/email/receiver.rb @@ -166,7 +166,7 @@ module Email elsif bounce_score >= SiteSetting.bounce_score_threshold # NOTE: we check bounce_score before sending emails, nothing to do # here other than log it happened. - reason = I18n.t("user.email.revoked", { email: user.email, date: user.user_stat.reset_bounce_score_after }) + reason = I18n.t("user.email.revoked", email: user.email, date: user.user_stat.reset_bounce_score_after) StaffActionLogger.new(Discourse.system_user).log_revoke_email(user, reason) end end @@ -466,7 +466,7 @@ module Email true end - def self.reply_by_email_address_regex(extract_reply_key=true) + def self.reply_by_email_address_regex(extract_reply_key = true) reply_addresses = [SiteSetting.reply_by_email_address] reply_addresses << (SiteSetting.alternative_reply_by_email_addresses.presence || "").split("|") @@ -538,11 +538,11 @@ module Email PostActionType.types[:like] if likes.include?(body.strip.downcase) end - def create_topic(options={}) + def create_topic(options = {}) create_post_with_attachments(options) end - def create_reply(options={}) + def create_reply(options = {}) raise TopicNotFoundError if options[:topic].nil? || options[:topic].trashed? if post_action_type = post_action_for(options[:raw]) @@ -572,7 +572,7 @@ module Email end end - def create_post_with_attachments(options={}) + def create_post_with_attachments(options = {}) # deal with attachments attachments.each do |attachment| tmp = Tempfile.new(["discourse-email-attachment", File.extname(attachment.filename)]) @@ -612,7 +612,7 @@ module Email end end - def create_post(options={}) + def create_post(options = {}) options[:via_email] = true options[:raw_email] = @raw_email @@ -622,7 +622,7 @@ module Email raise InvalidPost, "No post creation date found. Is the e-mail missing a Date: header?" end - options[:created_at] = DateTime.now if options[:created_at] > DateTime.now + options[:created_at] = DateTime.now if options[:created_at] > DateTime.now is_private_message = options[:archetype] == Archetype.private_message || options[:topic].try(:private_message?) diff --git a/lib/email/renderer.rb b/lib/email/renderer.rb index 9b209781ff9..be802b7a991 100644 --- a/lib/email/renderer.rb +++ b/lib/email/renderer.rb @@ -3,7 +3,7 @@ require_dependency 'email/styles' module Email class Renderer - def initialize(message, opts=nil) + def initialize(message, opts = nil) @message = message @opts = opts || {} end diff --git a/lib/email/sender.rb b/lib/email/sender.rb index 61c5fc16854..08e141a923e 100644 --- a/lib/email/sender.rb +++ b/lib/email/sender.rb @@ -15,7 +15,7 @@ SMTP_CLIENT_ERRORS = [Net::SMTPFatalError, Net::SMTPSyntaxError] module Email class Sender - def initialize(message, email_type, user=nil) + def initialize(message, email_type, user = nil) @message = message @email_type = email_type @user = user @@ -55,8 +55,8 @@ module Email # These are the links we add when a user uploads a file or image. # Ideally we would parse general markdown into plain text, but that is almost an intractable problem. url_prefix = Discourse.base_url - @message.parts[0].body = @message.parts[0].body.to_s.gsub(/([^<]*)<\/a>/, '[\2]('+url_prefix+'\1)') - @message.parts[0].body = @message.parts[0].body.to_s.gsub(/]*)>/, '![]('+url_prefix+'\1)') + @message.parts[0].body = @message.parts[0].body.to_s.gsub(/([^<]*)<\/a>/, '[\2](' + url_prefix + '\1)') + @message.parts[0].body = @message.parts[0].body.to_s.gsub(/]*)>/, '![](' + url_prefix + '\1)') @message.text_part.content_type = 'text/plain; charset=UTF-8' @@ -88,8 +88,8 @@ module Email "" referenced_posts = Post.includes(:incoming_email) - .where(id: PostReply.where(reply_id: post_id).select(:post_id)) - .order(id: :desc) + .where(id: PostReply.where(reply_id: post_id).select(:post_id)) + .order(id: :desc) referenced_post_message_ids = referenced_posts.map do |post| if post.incoming_email&.message_id.present? @@ -165,9 +165,9 @@ module Email when /\.mailjet\.com/ @message.header['X-MJ-CustomID'] = @message.message_id when "smtp.mandrillapp.com" - merge_json_x_header('X-MC-Metadata', { message_id: @message.message_id }) + merge_json_x_header('X-MC-Metadata', message_id: @message.message_id) when "smtp.sparkpostmail.com" - merge_json_x_header('X-MSYS-API', { metadata: { message_id: @message.message_id } }) + merge_json_x_header('X-MSYS-API', metadata: { message_id: @message.message_id }) end # Suppress images from short emails diff --git a/lib/email/styles.rb b/lib/email/styles.rb index 4b51a023315..09a72731368 100644 --- a/lib/email/styles.rb +++ b/lib/email/styles.rb @@ -10,7 +10,7 @@ module Email delegate :css, to: :fragment - def initialize(html, opts=nil) + def initialize(html, opts = nil) @html = html @opts = opts || {} @fragment = Nokogiri::HTML.fragment(@html) @@ -41,7 +41,7 @@ module Email img['width'] = img['height'] = 20 else # use dimensions of original iPhone screen for 'too big, let device rescale' - if img['width'].to_i > 320 or img['height'].to_i > 480 + if img['width'].to_i > (320) || img['height'].to_i > (480) img['width'] = img['height'] = 'auto' end end @@ -246,7 +246,7 @@ module Email linknum = 0 element.css('a').each do |inner| # we want the first footer link to be specially highlighted as IMPORTANT - if footernum == 0 and linknum == 0 + if footernum == (0) && linknum == (0) inner['style'] = "background-color: #006699; color:#ffffff; border-top: 4px solid #006699; border-right: 6px solid #006699; border-bottom: 4px solid #006699; border-left: 6px solid #006699; display: inline-block;" else inner['style'] = "color:#666;" @@ -271,7 +271,7 @@ module Email def style(selector, style, attribs = {}) @fragment.css(selector).each do |element| add_styles(element, style) if style - attribs.each do |k,v| + attribs.each do |k, v| element[k] = v end end diff --git a/lib/email_updater.rb b/lib/email_updater.rb index d7acb357813..12a28781947 100644 --- a/lib/email_updater.rb +++ b/lib/email_updater.rb @@ -7,12 +7,12 @@ class EmailUpdater attr_reader :user - def initialize(guardian=nil, user=nil) + def initialize(guardian = nil, user = nil) @guardian = guardian @user = user end - def self.human_attribute_name(name, options={}) + def self.human_attribute_name(name, options = {}) User.human_attribute_name(name, options) end @@ -68,8 +68,8 @@ class EmailUpdater @user = token.user change_req = user.email_change_requests - .where('old_email_token_id = :token_id OR new_email_token_id = :token_id', { token_id: token.id}) - .first + .where('old_email_token_id = :token_id OR new_email_token_id = :token_id', token_id: token.id) + .first # Simple state machine case change_req.try(:change_state) diff --git a/lib/es6_module_transpiler/tilt/es6_module_transpiler_template.rb b/lib/es6_module_transpiler/tilt/es6_module_transpiler_template.rb index e64ce08380b..545f7522803 100644 --- a/lib/es6_module_transpiler/tilt/es6_module_transpiler_template.rb +++ b/lib/es6_module_transpiler/tilt/es6_module_transpiler_template.rb @@ -14,7 +14,7 @@ module Tilt source = input[:data] context = input[:environment].context_class.new(input) - result = new(filename){source}.render(context) + result = new(filename) { source }.render(context) context.metadata.merge(data: result) end @@ -28,8 +28,8 @@ module Tilt ctx = MiniRacer::Context.new(timeout: 15000) ctx.eval("var self = this; #{File.read("#{Rails.root}/vendor/assets/javascripts/babel.js")}") ctx.eval("module = {}; exports = {};"); - ctx.attach("rails.logger.info", proc{|err| Rails.logger.info(err.to_s)}) - ctx.attach("rails.logger.error", proc{|err| Rails.logger.error(err.to_s)}) + ctx.attach("rails.logger.info", proc { |err| Rails.logger.info(err.to_s) }) + ctx.attach("rails.logger.error", proc { |err| Rails.logger.error(err.to_s) }) ctx.eval <]*class\s*=\s*['|"]excerpt['|"][^>]*>/ - def initialize(length, options=nil) + def initialize(length, options = nil) @length = length @excerpt = "" @current_length = 0 @@ -45,13 +45,13 @@ class ExcerptParser < Nokogiri::XML::SAX::Document end def include_tag(name, attributes) - characters("<#{name} #{attributes.map{|k,v| "#{k}=\"#{escape_attribute(v)}\""}.join(' ')}>", false, false, false) + characters("<#{name} #{attributes.map { |k, v| "#{k}=\"#{escape_attribute(v)}\"" }.join(' ')}>", false, false, false) end - def start_element(name, attributes=[]) + def start_element(name, attributes = []) case name - when "img" - attributes = Hash[*attributes.flatten] + when "img" + attributes = Hash[*attributes.flatten] if attributes["class"] == 'emoji' if @remap_emoji @@ -78,28 +78,28 @@ class ExcerptParser < Nokogiri::XML::SAX::Document characters("(#{attributes['src']})") if @markdown_images - when "a" - unless @strip_links - include_tag(name, attributes) - @in_a = true - end + when "a" + unless @strip_links + include_tag(name, attributes) + @in_a = true + end - when "aside" - attributes = Hash[*attributes.flatten] + when "aside" + attributes = Hash[*attributes.flatten] unless @keep_onebox_source && attributes['class'].include?('onebox') @in_quote = true end - when 'article' - if @keep_onebox_source && attributes.include?(['class', 'onebox-body']) - @in_quote = true - end - when "div", "span" - if attributes.include?(["class", "excerpt"]) - @excerpt = "" - @current_length = 0 - @start_excerpt = true - end + when 'article' + if @keep_onebox_source && attributes.include?(['class', 'onebox-body']) + @in_quote = true + end + when "div", "span" + if attributes.include?(["class", "excerpt"]) + @excerpt = "" + @current_length = 0 + @start_excerpt = true + end # Preserve spoilers if attributes.include?(["class", "spoiler"]) include_tag("span", attributes) @@ -112,7 +112,7 @@ class ExcerptParser < Nokogiri::XML::SAX::Document case name when "a" unless @strip_links - characters("",false, false, false) + characters("", false, false, false) @in_a = false end when "p", "br" @@ -132,7 +132,7 @@ class ExcerptParser < Nokogiri::XML::SAX::Document def characters(string, truncate = true, count_it = true, encode = true) return if @in_quote - encode = encode ? lambda{|s| ERB::Util.html_escape(s)} : lambda {|s| s} + encode = encode ? lambda { |s| ERB::Util.html_escape(s) } : lambda { |s| s } if count_it && @current_length + string.length > @length length = [0, @length - @current_length - 1].max @excerpt << encode.call(string[0..length]) if truncate diff --git a/lib/file_store/s3_store.rb b/lib/file_store/s3_store.rb index 265c7d53a83..98f1c13f087 100644 --- a/lib/file_store/s3_store.rb +++ b/lib/file_store/s3_store.rb @@ -9,7 +9,7 @@ module FileStore class S3Store < BaseStore TOMBSTONE_PREFIX ||= "tombstone/" - def initialize(s3_helper=nil) + def initialize(s3_helper = nil) @s3_helper = s3_helper || S3Helper.new(s3_bucket, TOMBSTONE_PREFIX) end @@ -27,7 +27,7 @@ module FileStore # - filename # - content_type # - cache_locally - def store_file(file, path, opts={}) + def store_file(file, path, opts = {}) filename = opts[:filename].presence || File.basename(path) # cache file locally when needed cache_file(file, File.basename(path)) if opts[:cache_locally] diff --git a/lib/filter_best_posts.rb b/lib/filter_best_posts.rb index 88f97d4d1a0..e01e79e0e0d 100644 --- a/lib/filter_best_posts.rb +++ b/lib/filter_best_posts.rb @@ -2,26 +2,27 @@ class FilterBestPosts attr_accessor :filtered_posts, :posts - def initialize(topic, filtered_posts, limit, options={}) + def initialize(topic, filtered_posts, limit, options = {}) @filtered_posts = filtered_posts @topic = topic @limit = limit options.each do |key, value| - self.instance_variable_set("@#{key}".to_sym, value) + self.instance_variable_set("@#{key}".to_sym, value) end filter end def filter - @posts = if @min_replies && @topic.posts_count < @min_replies + 1 - [] - else - filter_posts_liked_by_moderators - setup_posts - filter_posts_based_on_trust_level - filter_posts_based_on_score - sort_posts - end + @posts = + if @min_replies && @topic.posts_count < @min_replies + 1 + [] + else + filter_posts_liked_by_moderators + setup_posts + filter_posts_based_on_trust_level + filter_posts_based_on_score + sort_posts + end end private @@ -39,24 +40,26 @@ class FilterBestPosts end def filter_posts_based_on_trust_level - return unless @min_trust_level.try('>',0) - @posts = if @bypass_trust_level_score.try('>',0) - @posts.where('COALESCE(users.trust_level,0) >= ? OR posts.score >= ?', - @min_trust_level, - @bypass_trust_level_score) - else - @posts.where('COALESCE(users.trust_level,0) >= ?', @min_trust_level) - end + return unless @min_trust_level.try('>', 0) + + @posts = + if @bypass_trust_level_score.try('>', 0) + @posts.where('COALESCE(users.trust_level,0) >= ? OR posts.score >= ?', + @min_trust_level, + @bypass_trust_level_score + ) + else + @posts.where('COALESCE(users.trust_level,0) >= ?', @min_trust_level) + end end def filter_posts_based_on_score - return unless @min_score.try('>',0) + return unless @min_score.try('>', 0) @posts = @posts.where('posts.score >= ?', @min_score) end def sort_posts - @posts.to_a.sort!{|a,b| a.post_number <=> b.post_number} + @posts.to_a.sort! { |a, b| a.post_number <=> b.post_number } end end - diff --git a/lib/final_destination.rb b/lib/final_destination.rb index b0aff9605bf..442f5b79a56 100644 --- a/lib/final_destination.rb +++ b/lib/final_destination.rb @@ -9,7 +9,7 @@ class FinalDestination attr_reader :status attr_reader :cookie - def initialize(url, opts=nil) + def initialize(url, opts = nil) @uri = begin URI(URI.escape(url)) if url @@ -161,7 +161,7 @@ class FinalDestination address = IPAddr.new(address_s) - if private_ranges.any? {|r| r === address } + if private_ranges.any? { |r| r === address } @status = :invalid_address return false end @@ -178,7 +178,7 @@ class FinalDestination def private_ranges FinalDestination.standard_private_ranges + - SiteSetting.blacklist_ip_blocks.split('|').map {|r| IPAddr.new(r) rescue nil }.compact + SiteSetting.blacklist_ip_blocks.split('|').map { |r| IPAddr.new(r) rescue nil }.compact end def self.standard_private_ranges diff --git a/lib/flag_query.rb b/lib/flag_query.rb index 11b21c8966f..53616e042f0 100644 --- a/lib/flag_query.rb +++ b/lib/flag_query.rb @@ -1,6 +1,6 @@ module FlagQuery - def self.flagged_posts_report(current_user, filter, offset=0, per_page=25) + def self.flagged_posts_report(current_user, filter, offset = 0, per_page = 25) actions = flagged_post_actions(filter) guardian = Guardian.new(current_user) @@ -12,11 +12,11 @@ module FlagQuery end post_ids = actions.limit(per_page) - .offset(offset) - .group(:post_id) - .order('MIN(post_actions.created_at) DESC') - .pluck(:post_id) - .uniq + .offset(offset) + .group(:post_id) + .order('MIN(post_actions.created_at) DESC') + .pluck(:post_id) + .uniq return nil if post_ids.blank? @@ -47,8 +47,8 @@ module FlagQuery end post_actions = actions.order('post_actions.created_at DESC') - .includes(related_post: { topic: { ordered_posts: :user }}) - .where(post_id: post_ids) + .includes(related_post: { topic: { ordered_posts: :user } }) + .where(post_id: post_ids) post_actions.each do |pa| post = post_lookup[pa.post_id] @@ -111,10 +111,10 @@ module FlagQuery def self.flagged_post_actions(filter) post_actions = PostAction.flags - .joins("INNER JOIN posts ON posts.id = post_actions.post_id") - .joins("INNER JOIN topics ON topics.id = posts.topic_id") - .joins("LEFT JOIN users ON users.id = posts.user_id") - .where("posts.user_id > 0") + .joins("INNER JOIN posts ON posts.id = post_actions.post_id") + .joins("INNER JOIN topics ON topics.id = posts.topic_id") + .joins("LEFT JOIN users ON users.id = posts.user_id") + .where("posts.user_id > 0") if filter == "old" post_actions.where("post_actions.disagreed_at IS NOT NULL OR @@ -122,8 +122,8 @@ module FlagQuery post_actions.agreed_at IS NOT NULL") else post_actions.active - .where("posts.deleted_at" => nil) - .where("topics.deleted_at" => nil) + .where("posts.deleted_at" => nil) + .where("topics.deleted_at" => nil) end end diff --git a/lib/freedom_patches/active_record_base.rb b/lib/freedom_patches/active_record_base.rb index 4f62d40647a..bd4eb2c1e82 100644 --- a/lib/freedom_patches/active_record_base.rb +++ b/lib/freedom_patches/active_record_base.rb @@ -19,13 +19,12 @@ class ActiveRecord::Base ActiveRecord::Base.exec_sql(*args) end - # Executes the given block +retries+ times (or forever, if explicitly given nil), # catching and retrying SQL Deadlock errors. # # Thanks to: http://stackoverflow.com/a/7427186/165668 # - def self.retry_lock_error(retries=5, &block) + def self.retry_lock_error(retries = 5, &block) begin yield rescue ActiveRecord::StatementInvalid => e diff --git a/lib/freedom_patches/ams_include_without_root.rb b/lib/freedom_patches/ams_include_without_root.rb index 424489b3f5c..67c4cf185b6 100644 --- a/lib/freedom_patches/ams_include_without_root.rb +++ b/lib/freedom_patches/ams_include_without_root.rb @@ -8,7 +8,7 @@ module ActiveModel # This method is copied over verbatim from the AMS version, except for silently # ignoring associations that cannot be embedded without a root instead of # raising an exception. - def include!(name, options={}) + def include!(name, options = {}) unique_values = if hash = options[:hash] if @options[:hash] == hash diff --git a/lib/freedom_patches/better_handlebars_errors.rb b/lib/freedom_patches/better_handlebars_errors.rb index 3cab31cc944..940afe71a20 100644 --- a/lib/freedom_patches/better_handlebars_errors.rb +++ b/lib/freedom_patches/better_handlebars_errors.rb @@ -13,4 +13,3 @@ module Ember end end end - diff --git a/lib/freedom_patches/fast_pluck.rb b/lib/freedom_patches/fast_pluck.rb index ac1203c66d0..9eacba972ff 100644 --- a/lib/freedom_patches/fast_pluck.rb +++ b/lib/freedom_patches/fast_pluck.rb @@ -64,7 +64,7 @@ class ActiveRecord::Relation columns_hash.key?(cn) ? arel_table[cn] : cn } - conn.select_raw(relation, nil, relation.arel.bind_values + bind_values) do |result,_| + conn.select_raw(relation, nil, relation.arel.bind_values + bind_values) do |result, _| result.type_map = SqlBuilder.pg_type_map result.nfields == 1 ? result.column_values(0) : result.values end diff --git a/lib/freedom_patches/inflector_backport.rb b/lib/freedom_patches/inflector_backport.rb index 299ee1107c7..1e192b0033e 100644 --- a/lib/freedom_patches/inflector_backport.rb +++ b/lib/freedom_patches/inflector_backport.rb @@ -23,7 +23,7 @@ module ActiveSupport define_method(method_name) do |*args| # this avoids recursive locks found = true - data = cache.fetch(args){found = false} + data = cache.fetch(args) { found = false } unless found cache[args] = data = send(uncached, *args) end @@ -56,8 +56,3 @@ module ActiveSupport end end end - - - - - diff --git a/lib/freedom_patches/pool_drainer.rb b/lib/freedom_patches/pool_drainer.rb index 6ded19de97d..bf1eb1e89c0 100644 --- a/lib/freedom_patches/pool_drainer.rb +++ b/lib/freedom_patches/pool_drainer.rb @@ -27,7 +27,7 @@ end class ActiveRecord::ConnectionAdapters::ConnectionPool # drain all idle connections # if idle_time is specified only connections idle for N seconds will be drained - def drain(idle_time=nil, max_age=nil) + def drain(idle_time = nil, max_age = nil) synchronize do @available.clear @connections.delete_if do |conn| diff --git a/lib/freedom_patches/rack_patches.rb b/lib/freedom_patches/rack_patches.rb index e02aca52cf5..890435d9b9c 100644 --- a/lib/freedom_patches/rack_patches.rb +++ b/lib/freedom_patches/rack_patches.rb @@ -4,7 +4,7 @@ class Rack::ETag private def digest_body(body) - parts = [] + parts = [] has_body = false body.each do |part| @@ -28,15 +28,15 @@ end class Rack::ConditionalGet private def to_rfc2822(since) - # shortest possible valid date is the obsolete: 1 Nov 97 09:55 A - # anything shorter is invalid, this avoids exceptions for common cases - # most common being the empty string - if since && since.length >= 16 - # NOTE: there is no trivial way to write this in a non execption way - # _rfc2822 returns a hash but is not that usable - Time.rfc2822(since) rescue nil - else - nil - end + # shortest possible valid date is the obsolete: 1 Nov 97 09:55 A + # anything shorter is invalid, this avoids exceptions for common cases + # most common being the empty string + if since && since.length >= 16 + # NOTE: there is no trivial way to write this in a non execption way + # _rfc2822 returns a hash but is not that usable + Time.rfc2822(since) rescue nil + else + nil + end end end diff --git a/lib/freedom_patches/rails4.rb b/lib/freedom_patches/rails4.rb index 82b4ed9fb9f..5052dd86542 100644 --- a/lib/freedom_patches/rails4.rb +++ b/lib/freedom_patches/rails4.rb @@ -1,4 +1,4 @@ -# Sam: This has now forked of rails. Trouble is we would never like to use "about 1 month" ever, we only want months for 2 or more months. +# Sam: This has now forked of rails. Trouble is we would never like to use "about 1 month" ever, we only want months for 2 or more months. # # Backporting a fix to rails itself may get too complex module FreedomPatches @@ -6,7 +6,7 @@ module FreedomPatches def self.distance_of_time_in_words(from_time, to_time = 0, include_seconds = false, options = {}) options = { - :scope => :'datetime.distance_in_words', + scope: :'datetime.distance_in_words', }.merge!(options) from_time = from_time.to_time if from_time.respond_to?(:to_time) @@ -15,36 +15,36 @@ module FreedomPatches distance_in_minutes = (distance / 60.0).round distance_in_seconds = distance.round - I18n.with_options :locale => options[:locale], :scope => options[:scope] do |locale| + I18n.with_options locale: options[:locale], scope: options[:scope] do |locale| case distance_in_minutes - when 0..1 - return distance_in_minutes == 0 ? - locale.t(:less_than_x_minutes, :count => 1) : - locale.t(:x_minutes, :count => distance_in_minutes) unless include_seconds + when 0..1 + return distance_in_minutes == 0 ? + locale.t(:less_than_x_minutes, count: 1) : + locale.t(:x_minutes, count: distance_in_minutes) unless include_seconds case distance_in_seconds - when 0..4 then locale.t :less_than_x_seconds, :count => 5 - when 5..9 then locale.t :less_than_x_seconds, :count => 10 - when 10..19 then locale.t :less_than_x_seconds, :count => 20 - when 20..39 then locale.t :half_a_minute - when 40..59 then locale.t :less_than_x_minutes, :count => 1 - else locale.t :x_minutes, :count => 1 + when 0..4 then locale.t :less_than_x_seconds, count: 5 + when 5..9 then locale.t :less_than_x_seconds, count: 10 + when 10..19 then locale.t :less_than_x_seconds, count: 20 + when 20..39 then locale.t :half_a_minute + when 40..59 then locale.t :less_than_x_minutes, count: 1 + else locale.t :x_minutes, count: 1 end - when 2..44 then locale.t :x_minutes, :count => distance_in_minutes - when 45..89 then locale.t :about_x_hours, :count => 1 - when 90..1439 then locale.t :about_x_hours, :count => (distance_in_minutes.to_f / 60.0).round - when 1440..2519 then locale.t :x_days, :count => 1 - + when 2..44 then locale.t :x_minutes, count: distance_in_minutes + when 45..89 then locale.t :about_x_hours, count: 1 + when 90..1439 then locale.t :about_x_hours, count: (distance_in_minutes.to_f / 60.0).round + when 1440..2519 then locale.t :x_days, count: 1 + # this is were we diverge from Rails - when 2520..129599 then locale.t :x_days, :count => (distance_in_minutes.to_f / 1440.0).round - when 129600..525599 then locale.t :x_months, :count => (distance_in_minutes.to_f / 43200.0).round + when 2520..129599 then locale.t :x_days, count: (distance_in_minutes.to_f / 1440.0).round + when 129600..525599 then locale.t :x_months, count: (distance_in_minutes.to_f / 43200.0).round else - fyear = from_time.year + fyear = from_time.year fyear += 1 if from_time.month >= 3 tyear = to_time.year tyear -= 1 if to_time.month < 3 - leap_years = (fyear > tyear) ? 0 : (fyear..tyear).count{|x| Date.leap?(x)} + leap_years = (fyear > tyear) ? 0 : (fyear..tyear).count { |x| Date.leap?(x) } minute_offset_for_leap_year = leap_years * 1440 # Discount the leap year days when calculating year distance. # e.g. if there are 20 leap year days between 2 dates having the same day @@ -55,11 +55,11 @@ module FreedomPatches remainder = (minutes_with_offset % 525600) distance_in_years = (minutes_with_offset / 525600) if remainder < 131400 - locale.t(:about_x_years, :count => distance_in_years) + locale.t(:about_x_years, count: distance_in_years) elsif remainder < 394200 - locale.t(:over_x_years, :count => distance_in_years) + locale.t(:over_x_years, count: distance_in_years) else - locale.t(:almost_x_years, :count => distance_in_years + 1) + locale.t(:almost_x_years, count: distance_in_years + 1) end end end diff --git a/lib/freedom_patches/raw_handlebars.rb b/lib/freedom_patches/raw_handlebars.rb index a3bd47c8a7f..3d3a8a84f2d 100644 --- a/lib/freedom_patches/raw_handlebars.rb +++ b/lib/freedom_patches/raw_handlebars.rb @@ -54,11 +54,11 @@ end class Ember::Handlebars::Template include Discourse::Ember::Handlebars::Helper - def precompile_handlebars(string, input=nil) + def precompile_handlebars(string, input = nil) "requirejs('discourse-common/lib/raw-handlebars').template(#{Barber::Precompiler.compile(string)});" end - def compile_handlebars(string, input=nil) + def compile_handlebars(string, input = nil) "requirejs('discourse-common/lib/raw-handlebars').compile(#{indent(string).inspect});" end diff --git a/lib/freedom_patches/safe_buffer.rb b/lib/freedom_patches/safe_buffer.rb index b39a96ebaae..8c8a294bfd0 100644 --- a/lib/freedom_patches/safe_buffer.rb +++ b/lib/freedom_patches/safe_buffer.rb @@ -4,7 +4,7 @@ # The alternative is a broken website when this happens class ActiveSupport::SafeBuffer - def concat(value, raise_encoding_err=false) + def concat(value, raise_encoding_err = false) if !html_safe? || value.html_safe? super(value) else @@ -22,8 +22,8 @@ class ActiveSupport::SafeBuffer self.force_encoding("UTF-8") unless valid_encoding? - encode!("utf-16","utf-8",:invalid => :replace) - encode!("utf-8","utf-16") + encode!("utf-16", "utf-8", invalid: :replace) + encode!("utf-8", "utf-16") end Rails.logger.warn("Encountered a non UTF-8 string in SafeBuffer - #{self} - #{encoding_diags}") end @@ -36,7 +36,7 @@ class ActiveSupport::SafeBuffer Rails.logger.warn("Attempted to concat a non UTF-8 string in SafeBuffer - #{value} - #{encoding_diags}") end - concat(value,_raise=true) + concat(value, _raise = true) end end diff --git a/lib/freedom_patches/schema_migration_details.rb b/lib/freedom_patches/schema_migration_details.rb index bbae956c11a..2c2722fdc77 100644 --- a/lib/freedom_patches/schema_migration_details.rb +++ b/lib/freedom_patches/schema_migration_details.rb @@ -4,7 +4,7 @@ module FreedomPatches rval = nil time = Benchmark.measure do - rval=super + rval = super end sql = < :replace) - str.encode!("utf-8","utf-16") + str.encode!("utf-16", "utf-8", invalid: :replace) + str.encode!("utf-8", "utf-16") end str diff --git a/lib/freedom_patches/sprockets_patches.rb b/lib/freedom_patches/sprockets_patches.rb index ca83e2aabbe..7cbf529aff2 100644 --- a/lib/freedom_patches/sprockets_patches.rb +++ b/lib/freedom_patches/sprockets_patches.rb @@ -21,9 +21,9 @@ if Rails.env == "development" end if source[0] != ?/ - # CODE REMOVED - # source = compute_asset_path(source, options) - source = "/assets/#{source}" + # CODE REMOVED + # source = compute_asset_path(source, options) + source = "/assets/#{source}" end relative_url_root = defined?(config.relative_url_root) && config.relative_url_root diff --git a/lib/freedom_patches/translate_accelerator.rb b/lib/freedom_patches/translate_accelerator.rb index ae6c1d48f55..92f0b80b311 100644 --- a/lib/freedom_patches/translate_accelerator.rb +++ b/lib/freedom_patches/translate_accelerator.rb @@ -49,10 +49,10 @@ module I18n end def ensure_all_loaded! - backend.fallbacks(locale).each {|l| ensure_loaded!(l) } + backend.fallbacks(locale).each { |l| ensure_loaded!(l) } end - def search(query, opts=nil) + def search(query, opts = nil) locale = opts[:locale] || config.locale load_locale(locale) unless @loaded_locales.include?(locale) @@ -167,7 +167,7 @@ module I18n alias_method :t, :translate - def exists?(key, locale=nil) + def exists?(key, locale = nil) locale ||= config.locale load_locale(locale) unless @loaded_locales.include?(locale) exists_no_cache?(key, locale) diff --git a/lib/gaps.rb b/lib/gaps.rb index c1f3f89602f..0bf52b14fc0 100644 --- a/lib/gaps.rb +++ b/lib/gaps.rb @@ -23,7 +23,7 @@ class Gaps end def find_gaps - return if @subset.nil? or @original.nil? + return if @subset.nil? || @original.nil? i = j = 0 gaps = {} @@ -48,7 +48,7 @@ class Gaps break if (i == @subset.size) || (j == @original.size) end - @after[@subset[i-1]] = @original[j..-1] if j < @original.size + @after[@subset[i - 1]] = @original[j..-1] if j < @original.size end end diff --git a/lib/guardian.rb b/lib/guardian.rb index 48c9ea4077e..dd75225f824 100644 --- a/lib/guardian.rb +++ b/lib/guardian.rb @@ -34,7 +34,7 @@ class Guardian attr_accessor :can_see_emails - def initialize(user=nil) + def initialize(user = nil) @user = user.presence || AnonymousUser.new end @@ -91,7 +91,7 @@ class Guardian end end - def can_create?(klass, parent=nil) + def can_create?(klass, parent = nil) return false unless authenticated? && klass # If no parent is provided, we look for a can_create_klass? @@ -155,8 +155,6 @@ class Guardian true end - - # Can we impersonate this user? def can_impersonate?(target) target && @@ -233,7 +231,7 @@ class Guardian is_me?(user) end - def can_invite_to_forum?(groups=nil) + def can_invite_to_forum?(groups = nil) authenticated? && (SiteSetting.max_invites_per_day.to_i > 0 || is_staff?) && !SiteSetting.enable_sso && @@ -245,7 +243,7 @@ class Guardian (groups.blank? || is_admin? || groups.all? { |g| can_edit_group?(g) }) end - def can_invite_to?(object, groups=nil) + def can_invite_to?(object, groups = nil) return false unless authenticated? return true if is_admin? return false unless SiteSetting.enable_private_messages? @@ -322,7 +320,6 @@ class Guardian end end - private def is_my_own?(obj) diff --git a/lib/guardian/category_guardian.rb b/lib/guardian/category_guardian.rb index 7e67066e892..567fbdbdd99 100644 --- a/lib/guardian/category_guardian.rb +++ b/lib/guardian/category_guardian.rb @@ -2,7 +2,7 @@ module CategoryGuardian # Creating Method - def can_create_category?(parent=nil) + def can_create_category?(parent = nil) is_admin? || ( SiteSetting.allow_moderators_to_create_categories && @@ -34,10 +34,10 @@ module CategoryGuardian if category.topic_count != 0 oldest_topic = category.topics.where.not(id: category.topic_id).order('created_at ASC').limit(1).first if oldest_topic - return I18n.t('category.cannot_delete.topic_exists', {count: category.topic_count, topic_link: "#{oldest_topic.title}"}) + return I18n.t('category.cannot_delete.topic_exists', count: category.topic_count, topic_link: "#{oldest_topic.title}") else # This is a weird case, probably indicating a bug. - return I18n.t('category.cannot_delete.topic_exists_no_oldest', {count: category.topic_count}) + return I18n.t('category.cannot_delete.topic_exists_no_oldest', count: category.topic_count) end end diff --git a/lib/guardian/post_guardian.rb b/lib/guardian/post_guardian.rb index 9b8f8ab0c16..da4275650c5 100644 --- a/lib/guardian/post_guardian.rb +++ b/lib/guardian/post_guardian.rb @@ -3,7 +3,7 @@ module PostGuardian # Can the user act on the post in a particular way. # taken_actions = the list of actions the user has already taken - def post_can_act?(post, action_key, opts={}) + def post_can_act?(post, action_key, opts = {}) return false unless can_see_post?(post) @@ -85,7 +85,7 @@ module PostGuardian (!SpamRule::AutoBlock.block?(@user) || (!!parent.try(:private_message?) && parent.allowed_users.include?(@user))) && ( !parent || !parent.category || - Category.post_create_allowed(self).where(:id => parent.category.id).count == 1 + Category.post_create_allowed(self).where(id: parent.category.id).count == 1 ) end @@ -186,8 +186,8 @@ module PostGuardian can_see_post?(post) end - def can_vote?(post, opts={}) - post_can_act?(post,:vote, opts) + def can_vote?(post, opts = {}) + post_can_act?(post, :vote, opts) end def can_change_post_owner? diff --git a/lib/guardian/topic_guardian.rb b/lib/guardian/topic_guardian.rb index add956351be..8b8f08a12d0 100644 --- a/lib/guardian/topic_guardian.rb +++ b/lib/guardian/topic_guardian.rb @@ -76,7 +76,7 @@ module TopicGuardian is_staff? end - def can_see_topic?(topic, hide_deleted=true) + def can_see_topic?(topic, hide_deleted = true) return false unless topic return true if is_admin? return false if hide_deleted && topic.deleted_at && !can_see_deleted_topics? @@ -107,6 +107,6 @@ module TopicGuardian def can_edit_featured_link?(category_id) return false unless SiteSetting.topic_featured_link_enabled - Category.where(id: category_id||SiteSetting.uncategorized_category_id, topic_featured_link_allowed: true).exists? + Category.where(id: category_id || SiteSetting.uncategorized_category_id, topic_featured_link_allowed: true).exists? end end diff --git a/lib/html_normalize.rb b/lib/html_normalize.rb index 072789c0cba..9b5ebb5d58a 100644 --- a/lib/html_normalize.rb +++ b/lib/html_normalize.rb @@ -51,7 +51,7 @@ class HtmlNormalize Oga::XML::Text === node || !BLOCK.include?(node.name.downcase) end - def dump_node(node, indent=0, buffer) + def dump_node(node, indent = 0, buffer) if Oga::XML::Text === node if node.parent&.name @@ -70,7 +70,7 @@ class HtmlNormalize attrs = node&.attributes if (attrs && attrs.length > 0) - attrs.sort!{|x,y| x.name <=> y.name} + attrs.sort! { |x, y| x.name <=> y.name } attrs.each do |a| buffer << " " buffer << a.name @@ -94,20 +94,20 @@ class HtmlNormalize children&.each do |child| if block && inline?(child) inline_buffer ||= String.new - dump_node(child, indent+1, inline_buffer) + dump_node(child, indent + 1, inline_buffer) else if inline_buffer - buffer << " " * (indent+1) * 2 + buffer << " " * (indent + 1) * 2 buffer << inline_buffer.strip inline_buffer = nil else - dump_node(child, indent+1, buffer) + dump_node(child, indent + 1, buffer) end end end if inline_buffer - buffer << " " * (indent+1) * 2 + buffer << " " * (indent + 1) * 2 buffer << inline_buffer.strip inline_buffer = nil end @@ -146,5 +146,4 @@ class HtmlNormalize nodes[start...finish] end - end diff --git a/lib/html_prettify.rb b/lib/html_prettify.rb index 39a8ca7d304..df91d767d32 100644 --- a/lib/html_prettify.rb +++ b/lib/html_prettify.rb @@ -12,7 +12,7 @@ class HtmlPrettify < String new(html).to_html end - # Create a new RubyPants instance with the text in +string+. + # Create a new RubyPants instance with the text in +string+. # # Allowed elements in the options array: # @@ -50,7 +50,7 @@ class HtmlPrettify < String # :ellipsis :: # :html_quote :: " # - def initialize(string, options=[2], entities = {}) + def initialize(string, options = [2], entities = {}) super string @options = [*options] @@ -173,7 +173,6 @@ class HtmlPrettify < String protected - # The string, with each instance of "--" translated to an # em-dash HTML entity. # @@ -319,14 +318,14 @@ class HtmlPrettify < String new_str = str.dup { - :en_dash => '-', - :em_dash => '--', - :single_left_quote => "'", - :single_right_quote => "'", - :double_left_quote => '"', - :double_right_quote => '"', - :ellipsis => '...' - }.each do |k,v| + en_dash: '-', + em_dash: '--', + single_left_quote: "'", + single_right_quote: "'", + double_left_quote: '"', + double_right_quote: '"', + ellipsis: '...' + }.each do |k, v| new_str.gsub!(/#{entity(k)}/, v) end diff --git a/lib/html_to_markdown.rb b/lib/html_to_markdown.rb index e5360477406..21a3cded140 100644 --- a/lib/html_to_markdown.rb +++ b/lib/html_to_markdown.rb @@ -3,24 +3,23 @@ require "nokogiri" class HtmlToMarkdown class Block < Struct.new(:name, :head, :body, :opened, :markdown) - def initialize(name, head="", body="", opened=false, markdown=""); super; end + def initialize(name, head = "", body = "", opened = false, markdown = ""); super; end end - def initialize(html, opts={}) + def initialize(html, opts = {}) @opts = opts || {} @doc = fix_span_elements(Nokogiri::HTML(html)) remove_whitespaces! end - # If a `
` is within a `` that's invalid, so let's hoist the `
` up def fix_span_elements(node) if node.name == 'span' && node.at('div') node.swap(node.children) end - node.children.each {|c| fix_span_elements(c)} + node.children.each { |c| fix_span_elements(c) } node end diff --git a/lib/i18n/backend/discourse_i18n.rb b/lib/i18n/backend/discourse_i18n.rb index f940bd8804d..65a090cd261 100644 --- a/lib/i18n/backend/discourse_i18n.rb +++ b/lib/i18n/backend/discourse_i18n.rb @@ -51,7 +51,7 @@ module I18n protected - def find_results(regexp, results, translations, path=nil) + def find_results(regexp, results, translations, path = nil) return results if translations.blank? translations.each do |k_sym, v| diff --git a/lib/import/normalize.rb b/lib/import/normalize.rb index 79dfb255f83..5279439dc4d 100644 --- a/lib/import/normalize.rb +++ b/lib/import/normalize.rb @@ -4,10 +4,10 @@ require 'htmlentities' module Import; end module Import::Normalize - def self.normalize_code_blocks(code, lang=nil) + def self.normalize_code_blocks(code, lang = nil) coder = HTMLEntities.new code.gsub(/
\s*\n?(.*?)\n?<\/code>\s*<\/pre>/m) {
-        "\n```#{lang}\n#{coder.decode($1)}\n```\n"
+      "\n```#{lang}\n#{coder.decode($1)}\n```\n"
     }
   end
 end
diff --git a/lib/import_export/category_exporter.rb b/lib/import_export/category_exporter.rb
index 9f182e72470..4e2a57e8208 100644
--- a/lib/import_export/category_exporter.rb
+++ b/lib/import_export/category_exporter.rb
@@ -22,15 +22,14 @@ module ImportExport
       self
     end
 
-
     CATEGORY_ATTRS = [:id, :name, :color, :created_at, :user_id, :slug, :description, :text_color,
                       :auto_close_hours, :auto_close_based_on_last_post,
                       :topic_template, :suppress_from_homepage, :all_topics_wiki, :permissions_params]
 
     def export_categories
-      @export_data[:category] = CATEGORY_ATTRS.inject({}) { |h,a| h[a] = @category.send(a); h }
+      @export_data[:category] = CATEGORY_ATTRS.inject({}) { |h, a| h[a] = @category.send(a); h }
       @subcategories.find_each do |subcat|
-        @export_data[:subcategories] << CATEGORY_ATTRS.inject({}) { |h,a| h[a] = subcat.send(a); h }
+        @export_data[:subcategories] << CATEGORY_ATTRS.inject({}) { |h, a| h[a] = subcat.send(a); h }
       end
 
       # export groups that are mentioned in category permissions
@@ -49,7 +48,6 @@ module ImportExport
       self
     end
 
-
     GROUP_ATTRS = [ :id, :name, :created_at, :alias_level, :visible,
                     :automatic_membership_email_domains, :automatic_membership_retroactive,
                     :primary_group, :title, :grant_trust_level, :incoming_email]
@@ -57,7 +55,7 @@ module ImportExport
     def export_groups(group_names)
       group_names.each do |name|
         group = Group.find_by_name(name)
-        group_attrs = GROUP_ATTRS.inject({}) { |h,a| h[a] = group.send(a); h }
+        group_attrs = GROUP_ATTRS.inject({}) { |h, a| h[a] = group.send(a); h }
         group_attrs[:user_ids] = group.users.pluck(:id)
         @export_data[:groups] << group_attrs
       end
@@ -75,7 +73,7 @@ module ImportExport
       self
     end
 
-    def save_to_file(filename=nil)
+    def save_to_file(filename = nil)
       require 'json'
       output_basename = filename || File.join("category-export-#{Time.now.strftime("%Y-%m-%d-%H%M%S")}.json")
       File.open(output_basename, "w:UTF-8") do |f|
diff --git a/lib/import_export/category_importer.rb b/lib/import_export/category_importer.rb
index 25b57acfcb9..8493b006a09 100644
--- a/lib/import_export/category_importer.rb
+++ b/lib/import_export/category_importer.rb
@@ -28,7 +28,7 @@ module ImportExport
         external_id = g.delete(:id)
         new_group = Group.find_by_name(g[:name]) || Group.create!(g)
         user_ids.each do |external_user_id|
-          new_group.add( User.find(@topic_importer.new_user_id(external_user_id)) ) rescue ActiveRecord::RecordNotUnique
+          new_group.add(User.find(@topic_importer.new_user_id(external_user_id))) rescue ActiveRecord::RecordNotUnique
         end
       end
     end
@@ -47,7 +47,7 @@ module ImportExport
         parent = Category.new(@export_data[:category])
         parent.user_id = @topic_importer.new_user_id(@export_data[:category][:user_id]) # imported user's new id
         parent.custom_fields["import_id"] = id
-        parent.permissions = permissions.present? ? permissions : {"everyone" => CategoryGroup.permission_types[:full]}
+        parent.permissions = permissions.present? ? permissions : { "everyone" => CategoryGroup.permission_types[:full] }
         parent.save!
         set_category_description(parent, @export_data[:category][:description])
       end
@@ -62,7 +62,7 @@ module ImportExport
           subcategory.parent_category_id = parent.id
           subcategory.user_id = @topic_importer.new_user_id(cat_attrs[:user_id])
           subcategory.custom_fields["import_id"] = id
-          subcategory.permissions = permissions.present? ? permissions : {"everyone" => CategoryGroup.permission_types[:full]}
+          subcategory.permissions = permissions.present? ? permissions : { "everyone" => CategoryGroup.permission_types[:full] }
           subcategory.save!
           set_category_description(subcategory, cat_attrs[:description])
         end
diff --git a/lib/import_export/import_export.rb b/lib/import_export/import_export.rb
index 4bb6fa9250d..fad560768f2 100644
--- a/lib/import_export/import_export.rb
+++ b/lib/import_export/import_export.rb
@@ -6,7 +6,7 @@ require "json"
 
 module ImportExport
 
-  def self.export_category(category_id, filename=nil)
+  def self.export_category(category_id, filename = nil)
     ImportExport::CategoryExporter.new(category_id).perform.save_to_file(filename)
   end
 
diff --git a/lib/import_export/topic_exporter.rb b/lib/import_export/topic_exporter.rb
index 78b4dc4d9eb..4c494003edd 100644
--- a/lib/import_export/topic_exporter.rb
+++ b/lib/import_export/topic_exporter.rb
@@ -20,7 +20,6 @@ module ImportExport
       self
     end
 
-
     USER_ATTRS = [:id, :email, :username, :name, :created_at, :trust_level, :active, :last_emailed_at]
 
     def export_users
@@ -33,11 +32,9 @@ module ImportExport
           u = post.user
           unless @exported_user_ids.include?(u.id)
             x = USER_ATTRS.inject({}) { |h, a| h[a] = u.send(a); h; }
-            @export_data[:users] << x.merge({
-              bio_raw: u.user_profile.bio_raw,
-              website: u.user_profile.website,
-              location: u.user_profile.location
-            })
+            @export_data[:users] << x.merge(bio_raw: u.user_profile.bio_raw,
+                                            website: u.user_profile.website,
+                                            location: u.user_profile.location)
             @exported_user_ids << u.id
           end
         end
@@ -46,7 +43,6 @@ module ImportExport
       self
     end
 
-
     def export_topics
       @topic_ids.each do |topic_id|
         t = Topic.find(topic_id)
@@ -56,7 +52,6 @@ module ImportExport
       puts ""
     end
 
-
     TOPIC_ATTRS = [:id, :title, :created_at, :views, :category_id, :closed, :archived, :archetype]
     POST_ATTRS = [:id, :user_id, :post_number, :raw, :created_at, :reply_to_post_number,
                   :hidden, :hidden_reason_id, :wiki]
@@ -81,8 +76,7 @@ module ImportExport
       self
     end
 
-
-    def save_to_file(filename=nil)
+    def save_to_file(filename = nil)
       require 'json'
       output_basename = filename || File.join("topic-export-#{Time.now.strftime("%Y-%m-%d-%H%M%S")}.json")
       File.open(output_basename, "w:UTF-8") do |f|
diff --git a/lib/import_export/topic_importer.rb b/lib/import_export/topic_importer.rb
index 57496c5dab3..c681d39c2f6 100644
--- a/lib/import_export/topic_importer.rb
+++ b/lib/import_export/topic_importer.rb
@@ -36,14 +36,14 @@ module ImportExport
         puts ""
         print t[:title]
 
-        first_post_attrs = t[:posts].first.merge( t.slice(*(TopicExporter::TOPIC_ATTRS - [:id, :category_id])) )
+        first_post_attrs = t[:posts].first.merge(t.slice(*(TopicExporter::TOPIC_ATTRS - [:id, :category_id])))
         first_post_attrs[:user_id] = new_user_id(first_post_attrs[:user_id])
         first_post_attrs[:category] = new_category_id(t[:category_id])
 
         first_post = PostCustomField.where(name: "import_id", value: first_post_attrs[:id]).first.try(:post)
 
         unless first_post
-          first_post = create_post( first_post_attrs, first_post_attrs[:id] )
+          first_post = create_post(first_post_attrs, first_post_attrs[:id])
         end
 
         topic_id = first_post.topic_id
@@ -53,10 +53,8 @@ module ImportExport
           print "."
           existing = PostCustomField.where(name: "import_id", value: post_data[:id]).first.try(:post)
           unless existing
-            create_post(post_data.merge({
-              topic_id: topic_id,
-              user_id: new_user_id(post_data[:user_id])
-            }), post_data[:id]) # see ImportScripts::Base
+            create_post(post_data.merge(topic_id: topic_id,
+                                        user_id: new_user_id(post_data[:user_id])), post_data[:id]) # see ImportScripts::Base
           end
         end
       end
diff --git a/lib/inline_oneboxer.rb b/lib/inline_oneboxer.rb
index b064794882a..f345bef4d38 100644
--- a/lib/inline_oneboxer.rb
+++ b/lib/inline_oneboxer.rb
@@ -2,13 +2,13 @@ require_dependency 'retrieve_title'
 
 class InlineOneboxer
 
-  def initialize(urls, opts=nil)
+  def initialize(urls, opts = nil)
     @urls = urls
     @opts = opts || {}
   end
 
   def process
-    @urls.map {|url| InlineOneboxer.lookup(url, @opts) }.compact
+    @urls.map { |url| InlineOneboxer.lookup(url, @opts) }.compact
   end
 
   def self.purge(url)
@@ -19,7 +19,7 @@ class InlineOneboxer
     Rails.cache.read(cache_key(url))
   end
 
-  def self.lookup(url, opts=nil)
+  def self.lookup(url, opts = nil)
     opts ||= {}
 
     unless opts[:skip_cache]
@@ -44,7 +44,7 @@ class InlineOneboxer
         uri.hostname.present? &&
         domains.include?(uri.hostname) &&
         title = RetrieveTitle.crawl(url)
-          return onebox_for(url, title, opts)
+        return onebox_for(url, title, opts)
       end
     end
 
@@ -70,4 +70,3 @@ class InlineOneboxer
     end
 
 end
-
diff --git a/lib/js_locale_helper.rb b/lib/js_locale_helper.rb
index 2aa8d65a0f1..c352ee42d74 100644
--- a/lib/js_locale_helper.rb
+++ b/lib/js_locale_helper.rb
@@ -16,7 +16,7 @@ module JsLocaleHelper
     end
   end
 
-  def self.load_translations(locale, opts=nil)
+  def self.load_translations(locale, opts = nil)
     opts ||= {}
 
     @loaded_translations = nil if opts[:force]
@@ -149,7 +149,7 @@ module JsLocaleHelper
   end
 
   def self.generate_message_format(message_formats, locale_str)
-    formats = message_formats.map { |k,v| k.inspect << " : " << compile_message_format(locale_str, v) }.join(", ")
+    formats = message_formats.map { |k, v| k.inspect << " : " << compile_message_format(locale_str, v) }.join(", ")
 
     filename = "#{Rails.root}/lib/javascripts/locale/#{locale_str}.js"
     filename = "#{Rails.root}/lib/javascripts/locale/en.js" unless File.exists?(filename)
diff --git a/lib/json_error.rb b/lib/json_error.rb
index e52f18edf4d..5dfc720506c 100644
--- a/lib/json_error.rb
+++ b/lib/json_error.rb
@@ -1,6 +1,6 @@
 module JsonError
 
-  def create_errors_json(obj, type=nil)
+  def create_errors_json(obj, type = nil)
     errors = create_errors_array obj
     errors[:error_type] = type if type
     errors
diff --git a/lib/letter_avatar.rb b/lib/letter_avatar.rb
index 62915edcaba..93766c4b2d1 100644
--- a/lib/letter_avatar.rb
+++ b/lib/letter_avatar.rb
@@ -89,7 +89,7 @@ class LetterAvatar
     end
 
     def to_rgb(color)
-      r,g,b = color
+      r, g, b = color
       "rgb(#{r},#{g},#{b})"
     end
 
@@ -108,7 +108,7 @@ class LetterAvatar
       skip = File.basename(cache_path)
       parent_path = File.dirname(cache_path)
       Dir.entries(parent_path).each do |path|
-        unless ['.','..'].include?(path) || path == skip
+        unless ['.', '..'].include?(path) || path == skip
           FileUtils.rm_rf(parent_path + "/" + path)
         end
       end
@@ -121,220 +121,220 @@ class LetterAvatar
   #   - H: 0 - 360
   #   - C: 0 - 2
   #   - L: 0.75 - 1.5
-  COLORS = [[198,125,40],
-      [61,155,243],
-      [74,243,75],
-      [238,89,166],
-      [52,240,224],
-      [177,156,155],
-      [240,120,145],
-      [111,154,78],
-      [237,179,245],
-      [237,101,95],
-      [89,239,155],
-      [43,254,70],
-      [163,212,245],
-      [65,152,142],
-      [165,135,246],
-      [181,166,38],
-      [187,229,206],
-      [77,164,25],
-      [179,246,101],
-      [234,93,37],
-      [225,155,115],
-      [142,140,188],
-      [223,120,140],
-      [249,174,27],
-      [244,117,225],
-      [137,141,102],
-      [75,191,146],
-      [188,239,142],
-      [164,199,145],
-      [173,120,149],
-      [59,195,89],
-      [222,198,220],
-      [68,145,187],
-      [236,204,179],
-      [159,195,72],
-      [188,121,189],
-      [166,160,85],
-      [181,233,37],
-      [236,177,85],
-      [121,147,160],
-      [234,218,110],
-      [241,157,191],
-      [62,200,234],
-      [133,243,34],
-      [88,149,110],
-      [59,228,248],
-      [183,119,118],
-      [251,195,45],
-      [113,196,122],
-      [197,115,70],
-      [80,175,187],
-      [103,231,238],
-      [240,72,133],
-      [228,149,241],
-      [180,188,159],
-      [172,132,85],
-      [180,135,251],
-      [236,194,58],
-      [217,176,109],
-      [88,244,199],
-      [186,157,239],
-      [113,230,96],
-      [206,115,165],
-      [244,178,163],
-      [230,139,26],
-      [241,125,89],
-      [83,160,66],
-      [107,190,166],
-      [197,161,210],
-      [198,203,245],
-      [238,117,19],
-      [228,119,116],
-      [131,156,41],
-      [145,178,168],
-      [139,170,220],
-      [233,95,125],
-      [87,178,230],
-      [157,200,119],
-      [237,140,76],
-      [229,185,186],
-      [144,206,212],
-      [236,209,158],
-      [185,189,79],
-      [34,208,66],
-      [84,238,129],
-      [133,140,134],
-      [67,157,94],
-      [168,179,25],
-      [140,145,240],
-      [151,241,125],
-      [67,162,107],
-      [200,156,21],
-      [169,173,189],
-      [226,116,189],
-      [133,231,191],
-      [194,161,63],
-      [241,77,99],
-      [241,217,53],
-      [123,204,105],
-      [210,201,119],
-      [229,108,155],
-      [240,91,72],
-      [187,115,210],
-      [240,163,100],
-      [178,217,57],
-      [179,135,116],
-      [204,211,24],
-      [186,135,57],
-      [223,176,135],
-      [204,148,151],
-      [116,223,50],
-      [95,195,46],
-      [123,160,236],
-      [181,172,131],
-      [142,220,202],
-      [240,140,112],
-      [172,145,164],
-      [228,124,45],
-      [135,151,243],
-      [42,205,125],
-      [192,233,116],
-      [119,170,114],
-      [158,138,26],
-      [73,190,183],
-      [185,229,243],
-      [227,107,55],
-      [196,205,202],
-      [132,143,60],
-      [233,192,237],
-      [62,150,220],
-      [205,201,141],
-      [106,140,190],
-      [161,131,205],
-      [135,134,158],
-      [198,139,81],
-      [115,171,32],
-      [101,181,67],
-      [149,137,119],
-      [37,142,183],
-      [183,130,175],
-      [168,125,133],
-      [124,142,87],
-      [236,156,171],
-      [232,194,91],
-      [219,200,69],
-      [144,219,34],
-      [219,95,187],
-      [145,154,217],
-      [165,185,100],
-      [127,238,163],
-      [224,178,198],
-      [119,153,120],
-      [124,212,92],
-      [172,161,105],
-      [231,155,135],
-      [157,132,101],
-      [122,185,146],
-      [53,166,51],
-      [70,163,90],
-      [150,190,213],
-      [210,107,60],
-      [166,152,185],
-      [159,194,159],
-      [39,141,222],
-      [202,176,161],
-      [95,140,229],
-      [168,142,87],
-      [93,170,203],
-      [159,142,54],
-      [14,168,39],
-      [94,150,149],
-      [187,206,136],
-      [157,224,166],
-      [235,158,208],
-      [109,232,216],
-      [141,201,87],
-      [208,124,118],
-      [142,125,214],
-      [19,237,174],
-      [72,219,41],
-      [234,102,111],
-      [168,142,79],
-      [188,135,35],
-      [95,155,143],
-      [148,173,116],
-      [223,112,95],
-      [228,128,236],
-      [206,114,54],
-      [195,119,88],
-      [235,140,94],
-      [235,202,125],
-      [233,155,153],
-      [214,214,238],
-      [246,200,35],
-      [151,125,171],
-      [132,145,172],
-      [131,142,118],
-      [199,126,150],
-      [61,162,123],
-      [58,176,151],
-      [215,141,69],
-      [225,154,220],
-      [220,77,167],
-      [233,161,64],
-      [130,221,137],
-      [81,191,129],
-      [169,162,140],
-      [174,177,222],
-      [236,174,47],
-      [233,188,180],
-      [69,222,172],
-      [71,232,93],
-      [118,211,238],
-      [157,224,83],
-      [218,105,73],
-      [126,169,36]]
+  COLORS = [[198, 125, 40],
+      [61, 155, 243],
+      [74, 243, 75],
+      [238, 89, 166],
+      [52, 240, 224],
+      [177, 156, 155],
+      [240, 120, 145],
+      [111, 154, 78],
+      [237, 179, 245],
+      [237, 101, 95],
+      [89, 239, 155],
+      [43, 254, 70],
+      [163, 212, 245],
+      [65, 152, 142],
+      [165, 135, 246],
+      [181, 166, 38],
+      [187, 229, 206],
+      [77, 164, 25],
+      [179, 246, 101],
+      [234, 93, 37],
+      [225, 155, 115],
+      [142, 140, 188],
+      [223, 120, 140],
+      [249, 174, 27],
+      [244, 117, 225],
+      [137, 141, 102],
+      [75, 191, 146],
+      [188, 239, 142],
+      [164, 199, 145],
+      [173, 120, 149],
+      [59, 195, 89],
+      [222, 198, 220],
+      [68, 145, 187],
+      [236, 204, 179],
+      [159, 195, 72],
+      [188, 121, 189],
+      [166, 160, 85],
+      [181, 233, 37],
+      [236, 177, 85],
+      [121, 147, 160],
+      [234, 218, 110],
+      [241, 157, 191],
+      [62, 200, 234],
+      [133, 243, 34],
+      [88, 149, 110],
+      [59, 228, 248],
+      [183, 119, 118],
+      [251, 195, 45],
+      [113, 196, 122],
+      [197, 115, 70],
+      [80, 175, 187],
+      [103, 231, 238],
+      [240, 72, 133],
+      [228, 149, 241],
+      [180, 188, 159],
+      [172, 132, 85],
+      [180, 135, 251],
+      [236, 194, 58],
+      [217, 176, 109],
+      [88, 244, 199],
+      [186, 157, 239],
+      [113, 230, 96],
+      [206, 115, 165],
+      [244, 178, 163],
+      [230, 139, 26],
+      [241, 125, 89],
+      [83, 160, 66],
+      [107, 190, 166],
+      [197, 161, 210],
+      [198, 203, 245],
+      [238, 117, 19],
+      [228, 119, 116],
+      [131, 156, 41],
+      [145, 178, 168],
+      [139, 170, 220],
+      [233, 95, 125],
+      [87, 178, 230],
+      [157, 200, 119],
+      [237, 140, 76],
+      [229, 185, 186],
+      [144, 206, 212],
+      [236, 209, 158],
+      [185, 189, 79],
+      [34, 208, 66],
+      [84, 238, 129],
+      [133, 140, 134],
+      [67, 157, 94],
+      [168, 179, 25],
+      [140, 145, 240],
+      [151, 241, 125],
+      [67, 162, 107],
+      [200, 156, 21],
+      [169, 173, 189],
+      [226, 116, 189],
+      [133, 231, 191],
+      [194, 161, 63],
+      [241, 77, 99],
+      [241, 217, 53],
+      [123, 204, 105],
+      [210, 201, 119],
+      [229, 108, 155],
+      [240, 91, 72],
+      [187, 115, 210],
+      [240, 163, 100],
+      [178, 217, 57],
+      [179, 135, 116],
+      [204, 211, 24],
+      [186, 135, 57],
+      [223, 176, 135],
+      [204, 148, 151],
+      [116, 223, 50],
+      [95, 195, 46],
+      [123, 160, 236],
+      [181, 172, 131],
+      [142, 220, 202],
+      [240, 140, 112],
+      [172, 145, 164],
+      [228, 124, 45],
+      [135, 151, 243],
+      [42, 205, 125],
+      [192, 233, 116],
+      [119, 170, 114],
+      [158, 138, 26],
+      [73, 190, 183],
+      [185, 229, 243],
+      [227, 107, 55],
+      [196, 205, 202],
+      [132, 143, 60],
+      [233, 192, 237],
+      [62, 150, 220],
+      [205, 201, 141],
+      [106, 140, 190],
+      [161, 131, 205],
+      [135, 134, 158],
+      [198, 139, 81],
+      [115, 171, 32],
+      [101, 181, 67],
+      [149, 137, 119],
+      [37, 142, 183],
+      [183, 130, 175],
+      [168, 125, 133],
+      [124, 142, 87],
+      [236, 156, 171],
+      [232, 194, 91],
+      [219, 200, 69],
+      [144, 219, 34],
+      [219, 95, 187],
+      [145, 154, 217],
+      [165, 185, 100],
+      [127, 238, 163],
+      [224, 178, 198],
+      [119, 153, 120],
+      [124, 212, 92],
+      [172, 161, 105],
+      [231, 155, 135],
+      [157, 132, 101],
+      [122, 185, 146],
+      [53, 166, 51],
+      [70, 163, 90],
+      [150, 190, 213],
+      [210, 107, 60],
+      [166, 152, 185],
+      [159, 194, 159],
+      [39, 141, 222],
+      [202, 176, 161],
+      [95, 140, 229],
+      [168, 142, 87],
+      [93, 170, 203],
+      [159, 142, 54],
+      [14, 168, 39],
+      [94, 150, 149],
+      [187, 206, 136],
+      [157, 224, 166],
+      [235, 158, 208],
+      [109, 232, 216],
+      [141, 201, 87],
+      [208, 124, 118],
+      [142, 125, 214],
+      [19, 237, 174],
+      [72, 219, 41],
+      [234, 102, 111],
+      [168, 142, 79],
+      [188, 135, 35],
+      [95, 155, 143],
+      [148, 173, 116],
+      [223, 112, 95],
+      [228, 128, 236],
+      [206, 114, 54],
+      [195, 119, 88],
+      [235, 140, 94],
+      [235, 202, 125],
+      [233, 155, 153],
+      [214, 214, 238],
+      [246, 200, 35],
+      [151, 125, 171],
+      [132, 145, 172],
+      [131, 142, 118],
+      [199, 126, 150],
+      [61, 162, 123],
+      [58, 176, 151],
+      [215, 141, 69],
+      [225, 154, 220],
+      [220, 77, 167],
+      [233, 161, 64],
+      [130, 221, 137],
+      [81, 191, 129],
+      [169, 162, 140],
+      [174, 177, 222],
+      [236, 174, 47],
+      [233, 188, 180],
+      [69, 222, 172],
+      [71, 232, 93],
+      [118, 211, 238],
+      [157, 224, 83],
+      [218, 105, 73],
+      [126, 169, 36]]
 end
diff --git a/lib/markdown_linker.rb b/lib/markdown_linker.rb
index b6bb1a2eb1e..fab7c5a6b60 100644
--- a/lib/markdown_linker.rb
+++ b/lib/markdown_linker.rb
@@ -17,7 +17,7 @@ class MarkdownLinker
 
   def references
     result = ""
-    (@rendered..@index-1).each do |i|
+    (@rendered..@index - 1).each do |i|
       result << "[#{i}]: #{@markdown_links[i]}\n"
     end
     @rendered = @index
diff --git a/lib/memory_diagnostics.rb b/lib/memory_diagnostics.rb
index a49480677a9..3a3fcd60f54 100644
--- a/lib/memory_diagnostics.rb
+++ b/lib/memory_diagnostics.rb
@@ -4,7 +4,7 @@ module MemoryDiagnostics
     File.exists?(snapshot_filename)
   end
 
-  def self.compare(from=nil, to=nil)
+  def self.compare(from = nil, to = nil)
 
     from ||= snapshot_filename
     if !to
@@ -38,7 +38,7 @@ module MemoryDiagnostics
       end
     end
 
-    report << summary.sort{|a,b| b[1] <=> a[1]}[0..50].map{|k,v|
+    report << summary.sort { |a, b| b[1] <=> a[1] }[0..50].map { |k, v|
       "#{k}: #{v}"
     }.join("\n")
 
@@ -59,9 +59,9 @@ module MemoryDiagnostics
     "#{snapshot_path}/#{Process.pid}.snapshot"
   end
 
-  def self.snapshot_current_process(filename=nil)
+  def self.snapshot_current_process(filename = nil)
     filename ||= snapshot_filename
-    pid=fork do
+    pid = fork do
       snapshot(filename)
     end
 
@@ -86,7 +86,7 @@ module MemoryDiagnostics
     IO.binwrite(filename, Marshal::dump(object_ids))
   end
 
-  def self.memory_report(opts={})
+  def self.memory_report(opts = {})
     begin
       # ruby 2.1
       GC.start(full_mark: true)
@@ -94,7 +94,6 @@ module MemoryDiagnostics
       GC.start
     end
 
-
     classes = {}
     large_objects = []
 
@@ -113,11 +112,11 @@ module MemoryDiagnostics
           classes[:unknown] += 1
         end
       end
-      classes = classes.sort{|a,b| b[1] <=> a[1]}[0..40].map{|klass, count| "#{klass}: #{count}"}
+      classes = classes.sort { |a, b| b[1] <=> a[1] }[0..40].map { |klass, count| "#{klass}: #{count}" }
 
-      classes << "\nLarge Objects (#{large_objects.length} larger than 200 bytes total size #{large_objects.map{|x,_| x}.sum}):\n"
+      classes << "\nLarge Objects (#{large_objects.length} larger than 200 bytes total size #{large_objects.map { |x, _| x }.sum}):\n"
 
-      classes += large_objects.sort{|a,b| b[0] <=> a[0]}[0..800].map do |size,object|
+      classes += large_objects.sort { |a, b| b[0] <=> a[0] }[0..800].map do |size, object|
         rval = "#{object.class}: size #{size}"
         rval << " " << object.to_s[0..500].gsub("\n", "") if (String === object) || (Regexp === object)
         rval << "\n"
@@ -125,10 +124,8 @@ module MemoryDiagnostics
       end
     end
 
-    stats = GC.stat.map{|k,v| "#{k}: #{v}"}
-    counts = ObjectSpace.count_objects.sort{|a,b| b[1] <=> a[1] }.map{|k,v| "#{k}: #{v}"}
-
-
+    stats = GC.stat.map { |k, v| "#{k}: #{v}" }
+    counts = ObjectSpace.count_objects.sort { |a, b| b[1] <=> a[1] }.map { |k, v| "#{k}: #{v}" }
 
     < 'image/png' }, [ File.read(default_image)] ]
         end
       end
-      
+
       status, headers, response = @app.call(env)
       [status, headers, response]
     end
diff --git a/lib/middleware/request_tracker.rb b/lib/middleware/request_tracker.rb
index 90b36890d0e..a2dae84e97f 100644
--- a/lib/middleware/request_tracker.rb
+++ b/lib/middleware/request_tracker.rb
@@ -2,11 +2,11 @@ require_dependency 'middleware/anonymous_cache'
 
 class Middleware::RequestTracker
 
-  def initialize(app, settings={})
+  def initialize(app, settings = {})
     @app = app
   end
 
-  def self.log_request_on_site(data,host)
+  def self.log_request_on_site(data, host)
     RailsMultisite::ConnectionManagement.with_hostname(host) do
       log_request(data)
     end
@@ -46,8 +46,8 @@ class Middleware::RequestTracker
 
   TRACK_VIEW = "HTTP_DISCOURSE_TRACK_VIEW".freeze
   CONTENT_TYPE = "Content-Type".freeze
-  def self.get_data(env,result)
-    status,headers = result
+  def self.get_data(env, result)
+    status, headers = result
     status = status.to_i
 
     helper = Middleware::AnonymousCache::Helper.new(env)
@@ -74,21 +74,21 @@ class Middleware::RequestTracker
   ensure
 
     # we got to skip this on error ... its just logging
-    data = self.class.get_data(env,result) rescue nil
+    data = self.class.get_data(env, result) rescue nil
     host = RailsMultisite::ConnectionManagement.host(env)
 
     if data
-      if result && (headers=result[1])
+      if result && (headers = result[1])
         headers["X-Discourse-TrackView"] = "1" if data[:track_view]
       end
-      log_later(data,host)
+      log_later(data, host)
     end
 
   end
 
-  def log_later(data,host)
-    Scheduler::Defer.later("Track view", _db=nil) do
-      self.class.log_request_on_site(data,host)
+  def log_later(data, host)
+    Scheduler::Defer.later("Track view", _db = nil) do
+      self.class.log_request_on_site(data, host)
     end
   end
 
diff --git a/lib/middleware/turbo_dev.rb b/lib/middleware/turbo_dev.rb
index beda1652243..53e81cb50df 100644
--- a/lib/middleware/turbo_dev.rb
+++ b/lib/middleware/turbo_dev.rb
@@ -13,7 +13,7 @@ module Middleware
   #  config.middleware.insert 0, Middleware::TurboDev
   #
   class TurboDev
-    def initialize(app, settings={})
+    def initialize(app, settings = {})
       @app = app
     end
 
@@ -27,7 +27,7 @@ module Middleware
         etag = etag.gsub "\"", ""
         asset = Rails.application.assets.find_asset(name)
         if asset && asset.digest == etag
-          return [304,{},[]]
+          return [304, {}, []]
         end
       end
 
diff --git a/lib/new_post_manager.rb b/lib/new_post_manager.rb
index 7d99a8b4ed6..8777f1b8ff7 100644
--- a/lib/new_post_manager.rb
+++ b/lib/new_post_manager.rb
@@ -17,16 +17,16 @@ class NewPostManager
   end
 
   def self.handlers
-    sorted_handlers.map {|h| h[:proc]}
+    sorted_handlers.map { |h| h[:proc] }
   end
 
   def self.clear_handlers!
     @sorted_handlers = [{ priority: 0, proc: method(:default_handler) }]
   end
 
-  def self.add_handler(priority=0, &block)
+  def self.add_handler(priority = 0, &block)
     sorted_handlers << { priority: priority, proc: block }
-    @sorted_handlers.sort_by! {|h| -h[:priority]}
+    @sorted_handlers.sort_by! { |h| -h[:priority] }
   end
 
   def self.is_first_post?(manager)
@@ -129,7 +129,7 @@ class NewPostManager
 
   def initialize(user, args)
     @user = user
-    @args = args.delete_if {|_, v| v.nil?}
+    @args = args.delete_if { |_, v| v.nil? }
   end
 
   def perform
@@ -158,11 +158,11 @@ class NewPostManager
   end
 
   # Enqueue this post in a queue
-  def enqueue(queue, reason=nil)
+  def enqueue(queue, reason = nil)
     result = NewPostResult.new(:enqueued)
     enqueuer = PostEnqueuer.new(@user, queue)
 
-    queued_args = {post_options: @args.dup}
+    queued_args = { post_options: @args.dup }
     queued_args[:raw] = queued_args[:post_options].delete(:raw)
     queued_args[:topic_id] = queued_args[:post_options].delete(:topic_id)
 
diff --git a/lib/new_post_result.rb b/lib/new_post_result.rb
index 63acab0b002..78725ea11f0 100644
--- a/lib/new_post_result.rb
+++ b/lib/new_post_result.rb
@@ -10,7 +10,7 @@ class NewPostResult
   attr_accessor :queued_post
   attr_accessor :pending_count
 
-  def initialize(action, success=false)
+  def initialize(action, success = false)
     @action = action
     @success = success
   end
diff --git a/lib/oneboxer.rb b/lib/oneboxer.rb
index 08d3ac4149b..42862abe325 100644
--- a/lib/oneboxer.rb
+++ b/lib/oneboxer.rb
@@ -18,16 +18,16 @@ module Oneboxer
   end
 
   def self.ignore_redirects
-    @ignore_redirects ||= ['http://www.dropbox.com','http://store.steampowered.com', Discourse.base_url]
+    @ignore_redirects ||= ['http://www.dropbox.com', 'http://store.steampowered.com', Discourse.base_url]
   end
 
-  def self.preview(url, options=nil)
+  def self.preview(url, options = nil)
     options ||= {}
     invalidate(url) if options[:invalidate_oneboxes]
     onebox_raw(url)[:preview]
   end
 
-  def self.onebox(url, options=nil)
+  def self.onebox(url, options = nil)
     options ||= {}
     invalidate(url) if options[:invalidate_oneboxes]
     onebox_raw(url)[:onebox]
@@ -74,7 +74,7 @@ module Oneboxer
 
   def self.append_source_topic_id(url, topic_id)
     # hack urls to create proper expansions
-    if url =~ Regexp.new("^#{Discourse.base_url.gsub(".","\\.")}.*$", true)
+    if url =~ Regexp.new("^#{Discourse.base_url.gsub(".", "\\.")}.*$", true)
       uri = URI.parse(url) rescue nil
       if uri && uri.path
         route = Rails.application.routes.recognize_path(uri.path) rescue nil
@@ -86,7 +86,7 @@ module Oneboxer
     url
   end
 
-  def self.apply(string_or_doc, args=nil)
+  def self.apply(string_or_doc, args = nil)
     doc = string_or_doc
     doc = Nokogiri::HTML::fragment(doc) if doc.is_a?(String)
     changed = false
@@ -95,7 +95,7 @@ module Oneboxer
       if args && args[:topic_id]
         url = append_source_topic_id(url, args[:topic_id])
       end
-      onebox, _preview = yield(url,element)
+      onebox, _preview = yield(url, element)
       if onebox
         parsed_onebox = Nokogiri::HTML::fragment(onebox)
         next unless parsed_onebox.children.count > 0
diff --git a/lib/pbkdf2.rb b/lib/pbkdf2.rb
index f21cc8aebce..1032b4a1ad0 100644
--- a/lib/pbkdf2.rb
+++ b/lib/pbkdf2.rb
@@ -20,18 +20,18 @@ class Pbkdf2
     u = ret = prf(h, password, salt + [1].pack("N"))
 
     2.upto(iterations) do
-     u = prf(h, password, u)
+      u = prf(h, password, u)
      ret.xor!(u)
     end
 
-    ret.bytes.map{|b| ("0" + b.to_s(16))[-2..-1]}.join("")
+    ret.bytes.map { |b| ("0" + b.to_s(16))[-2..-1] }.join("")
   end
 
   protected
 
   # fallback xor in case we need it for jruby ... way slower
-  def self.xor(x,y)
-    x.bytes.zip(y.bytes).map{|x,y| x ^ y}.pack('c*')
+  def self.xor(x, y)
+    x.bytes.zip(y.bytes).map { |x, y| x ^ y }.pack('c*')
   end
 
   def self.prf(hash_function, password, data)
diff --git a/lib/pinned_check.rb b/lib/pinned_check.rb
index b1a25a4d5db..54543499b34 100644
--- a/lib/pinned_check.rb
+++ b/lib/pinned_check.rb
@@ -2,16 +2,16 @@
 # taking into account anonymous users and users who have dismissed it
 class PinnedCheck
 
-  def self.unpinned?(topic,topic_user=nil)
+  def self.unpinned?(topic, topic_user = nil)
     topic.pinned_at &&
     topic_user &&
     topic_user.cleared_pinned_at &&
     topic_user.cleared_pinned_at > topic.pinned_at
   end
 
-  def self.pinned?(topic, topic_user=nil)
+  def self.pinned?(topic, topic_user = nil)
     !!topic.pinned_at &&
-    !unpinned?(topic,topic_user)
+    !unpinned?(topic, topic_user)
   end
 
 end
diff --git a/lib/plugin/auth_provider.rb b/lib/plugin/auth_provider.rb
index 570a245b081..996d9ba0413 100644
--- a/lib/plugin/auth_provider.rb
+++ b/lib/plugin/auth_provider.rb
@@ -12,7 +12,7 @@ class Plugin::AuthProvider
   end
 
   def to_json
-    result = {name: name}
+    result = { name: name }
     result['customUrl'] = custom_url if custom_url
     result['titleOverride'] = title if title
     result['titleSetting'] = title_setting if title_setting
diff --git a/lib/plugin/instance.rb b/lib/plugin/instance.rb
index ca749901078..50867afaa0e 100644
--- a/lib/plugin/instance.rb
+++ b/lib/plugin/instance.rb
@@ -58,14 +58,14 @@ class Plugin::Instance
     }
   end
 
-  def initialize(metadata=nil, path=nil)
+  def initialize(metadata = nil, path = nil)
     @metadata = metadata
     @path = path
     @idx = 0
   end
 
   def add_admin_route(label, location)
-    @admin_route = {label: label, location: location}
+    @admin_route = { label: label, location: location }
   end
 
   def enabled?
@@ -74,7 +74,7 @@ class Plugin::Instance
 
   delegate :name, to: :metadata
 
-  def add_to_serializer(serializer, attr, define_include_method=true, &block)
+  def add_to_serializer(serializer, attr, define_include_method = true, &block)
     klass = "#{serializer.to_s.classify}Serializer".constantize rescue "#{serializer.to_s}Serializer".constantize
 
     klass.attributes(attr) unless attr.to_s.start_with?("include_")
@@ -164,7 +164,7 @@ class Plugin::Instance
   def delete_extra_automatic_assets(good_paths)
     return unless Dir.exists? auto_generated_path
 
-    filenames = good_paths.map{|f| File.basename(f)}
+    filenames = good_paths.map { |f| File.basename(f) }
     # nuke old files
     Dir.foreach(auto_generated_path) do |p|
       next if [".", ".."].include?(p)
@@ -242,13 +242,13 @@ class Plugin::Instance
     DiscoursePluginRegistry.register_html_builder(name, &block)
   end
 
-  def register_asset(file, opts=nil)
+  def register_asset(file, opts = nil)
     full_path = File.dirname(path) << "/assets/" << file
     assets << [full_path, opts]
   end
 
   def register_color_scheme(name, colors)
-    color_schemes << {name: name, colors: colors}
+    color_schemes << { name: name, colors: colors }
   end
 
   def register_seed_data(key, value)
@@ -362,14 +362,13 @@ JS
       target = Rails.root.to_s + "/public/plugins/"
 
       Discourse::Utils.execute_command('mkdir', '-p', target)
-      target << name.gsub(/\s/,"_")
+      target << name.gsub(/\s/, "_")
       # TODO a cleaner way of registering and unregistering
       Discourse::Utils.execute_command('rm', '-f', target)
       Discourse::Utils.execute_command('ln', '-s', public_data, target)
     end
   end
 
-
   def auth_provider(opts)
     provider = Plugin::AuthProvider.new
 
@@ -379,7 +378,6 @@ JS
     auth_providers << provider
   end
 
-
   # shotgun approach to gem loading, in future we need to hack bundler
   #  to at least determine dependencies do not clash before loading
   #
@@ -390,7 +388,7 @@ JS
     PluginGem.load(path, name, version, opts)
   end
 
-  def enabled_site_setting(setting=nil)
+  def enabled_site_setting(setting = nil)
     if setting
       @enabled_site_setting = setting
     else
@@ -421,9 +419,9 @@ JS
 
       Dir.glob("#{root_path}/**/*") do |f|
         if File.directory?(f)
-          yield [f,true]
+          yield [f, true]
         elsif f.to_s.ends_with?(".js.es6") || f.to_s.ends_with?(".hbs")
-          yield [f,false]
+          yield [f, false]
         end
       end
     end
@@ -442,7 +440,7 @@ JS
   def write_asset(path, contents)
     unless File.exists?(path)
       ensure_directory(path)
-      File.open(path,"w") { |f| f.write(contents) }
+      File.open(path, "w") { |f| f.write(contents) }
     end
   end
 
diff --git a/lib/plugin/theme.rb b/lib/plugin/theme.rb
index 04128d6f352..41ba7dc9992 100644
--- a/lib/plugin/theme.rb
+++ b/lib/plugin/theme.rb
@@ -27,4 +27,3 @@ class Plugin::Theme
     end
   end
 end
-
diff --git a/lib/plugin_gem.rb b/lib/plugin_gem.rb
index 48df5e57c8b..6347cc8dce9 100644
--- a/lib/plugin_gem.rb
+++ b/lib/plugin_gem.rb
@@ -1,5 +1,5 @@
 module PluginGem
-  def self.load(path, name, version, opts=nil)
+  def self.load(path, name, version, opts = nil)
     opts ||= {}
 
     gems_path = File.dirname(path) + "/gems/#{RUBY_VERSION}"
diff --git a/lib/post_creator.rb b/lib/post_creator.rb
index 405a7e0537a..42b70558235 100644
--- a/lib/post_creator.rb
+++ b/lib/post_creator.rb
@@ -239,8 +239,8 @@ class PostCreator
     return unless post.reply_to_post_number.present?
 
     reply_info = Post.where(topic_id: post.topic_id, post_number: post.reply_to_post_number)
-                     .select(:user_id, :post_type)
-                     .first
+      .select(:user_id, :post_type)
+      .first
 
     if reply_info.present?
       post.reply_to_user_id ||= reply_info.user_id
@@ -316,11 +316,11 @@ class PostCreator
 
   def handle_spam
     if @spam
-      GroupMessage.create( Group[:moderators].name,
+      GroupMessage.create(Group[:moderators].name,
                            :spam_post_blocked,
-                           { user: @user,
-                             limit_once_per: 24.hours,
-                             message_params: {domains: @post.linked_hosts.keys.join(', ')} } )
+                           user: @user,
+                           limit_once_per: 24.hours,
+                           message_params: { domains: @post.linked_hosts.keys.join(', ') })
     elsif @post && errors.blank? && !skip_validations?
       SpamRulesEnforcer.enforce!(@post)
     end
@@ -339,7 +339,7 @@ class PostCreator
     unless @topic.topic_allowed_users.where(user_id: @user.id).exists?
       unless @topic.topic_allowed_groups.where('group_id IN (
                                               SELECT group_id FROM group_users where user_id = ?
-                                           )',@user.id).exists?
+                                           )', @user.id).exists?
         @topic.topic_allowed_users.create!(user_id: @user.id)
       end
     end
@@ -363,11 +363,13 @@ class PostCreator
   def find_category_id
     @opts.delete(:category) if @opts[:archetype].present? && @opts[:archetype] == Archetype.private_message
 
-    category = if (@opts[:category].is_a? Integer) || (@opts[:category] =~ /^\d+$/)
-                 Category.find_by(id: @opts[:category])
-               else
-                 Category.find_by(name_lower: @opts[:category].try(:downcase))
-               end
+    category =
+      if (@opts[:category].is_a? Integer) || (@opts[:category] =~ /^\d+$/)
+        Category.find_by(id: @opts[:category])
+      else
+        Category.find_by(name_lower: @opts[:category].try(:downcase))
+      end
+
     category&.id
   end
 
@@ -491,7 +493,6 @@ class PostCreator
                        last_read_post_number: @post.post_number,
                        highest_seen_post_number: @post.post_number)
 
-
       # assume it took us 5 seconds of reading time to make a post
       PostTiming.record_timing(topic_id: @post.topic_id,
                                user_id: @post.user_id,
diff --git a/lib/post_destroyer.rb b/lib/post_destroyer.rb
index 07f34e85ee7..3f7cdbffab1 100644
--- a/lib/post_destroyer.rb
+++ b/lib/post_destroyer.rb
@@ -6,10 +6,10 @@ class PostDestroyer
 
   def self.destroy_old_hidden_posts
     Post.where(deleted_at: nil, hidden: true)
-        .where("hidden_at < ?", 30.days.ago)
-        .find_each do |post|
-        PostDestroyer.new(Discourse.system_user, post).destroy
-      end
+      .where("hidden_at < ?", 30.days.ago)
+      .find_each do |post|
+      PostDestroyer.new(Discourse.system_user, post).destroy
+    end
   end
 
   def self.destroy_stubs
@@ -17,26 +17,26 @@ class PostDestroyer
 
     # exclude deleted topics and posts that are actively flagged
     Post.where(deleted_at: nil, user_deleted: true)
-        .where("NOT EXISTS (
+      .where("NOT EXISTS (
             SELECT 1 FROM topics t
             WHERE t.deleted_at IS NOT NULL AND
                   t.id = posts.topic_id
         )")
-        .where("updated_at < ? AND post_number > 1", SiteSetting.delete_removed_posts_after.hours.ago)
-        .where("NOT EXISTS (
+      .where("updated_at < ? AND post_number > 1", SiteSetting.delete_removed_posts_after.hours.ago)
+      .where("NOT EXISTS (
                   SELECT 1
                   FROM post_actions pa
                   WHERE pa.post_id = posts.id AND
                         pa.deleted_at IS NULL AND
                         pa.post_action_type_id IN (?)
               )", PostActionType.notify_flag_type_ids)
-        .find_each do |post|
+      .find_each do |post|
 
       PostDestroyer.new(Discourse.system_user, post, context: context).destroy
     end
   end
 
-  def initialize(user, post, opts={})
+  def initialize(user, post, opts = {})
     @user = user
     @post = post
     @topic = post.topic if post
diff --git a/lib/post_jobs_enqueuer.rb b/lib/post_jobs_enqueuer.rb
index 3227f76c3cf..cb8fdb56c1a 100644
--- a/lib/post_jobs_enqueuer.rb
+++ b/lib/post_jobs_enqueuer.rb
@@ -1,5 +1,5 @@
 class PostJobsEnqueuer
-  def initialize(post, topic, new_topic, opts={})
+  def initialize(post, topic, new_topic, opts = {})
     @post = post
     @topic = topic
     @new_topic = new_topic
diff --git a/lib/post_revisor.rb b/lib/post_revisor.rb
index 831faa47b43..f443a64d93b 100644
--- a/lib/post_revisor.rb
+++ b/lib/post_revisor.rb
@@ -42,7 +42,7 @@ class PostRevisor
 
   attr_reader :category_changed
 
-  def initialize(post, topic=nil)
+  def initialize(post, topic = nil)
     @post = post
     @topic = topic || post.topic
   end
@@ -112,7 +112,7 @@ class PostRevisor
   # - bypass_bump: do not bump the topic, even if last post
   # - skip_validations: ask ActiveRecord to skip validations
   # - skip_revision: do not create a new PostRevision record
-  def revise!(editor, fields, opts={})
+  def revise!(editor, fields, opts = {})
     @editor = editor
     @fields = fields.with_indifferent_access
     @opts = opts
@@ -197,7 +197,7 @@ class PostRevisor
   end
 
   def topic_changed?
-    PostRevisor.tracked_topic_fields.keys.any? {|f| @fields.has_key?(f)}
+    PostRevisor.tracked_topic_fields.keys.any? { |f| @fields.has_key?(f) }
   end
 
   def revise_post
@@ -253,15 +253,15 @@ class PostRevisor
       # UserActionCreator will create new UserAction records for the new owner
 
       UserAction.where(target_post_id: @post.id)
-                .where(user_id: prev_owner.id)
-                .where(action_type: USER_ACTIONS_TO_REMOVE)
-                .destroy_all
+        .where(user_id: prev_owner.id)
+        .where(action_type: USER_ACTIONS_TO_REMOVE)
+        .destroy_all
 
       if @post.post_number == 1
         UserAction.where(target_topic_id: @post.topic_id)
-                  .where(user_id: prev_owner.id)
-                  .where(action_type: UserAction::NEW_TOPIC)
-                  .destroy_all
+          .where(user_id: prev_owner.id)
+          .where(action_type: UserAction::NEW_TOPIC)
+          .destroy_all
       end
     end
 
@@ -283,9 +283,9 @@ class PostRevisor
     # post owner changed
     if prev_owner && new_owner && prev_owner != new_owner
       likes = UserAction.where(target_post_id: @post.id)
-                        .where(user_id: prev_owner.id)
-                        .where(action_type: UserAction::WAS_LIKED)
-                        .update_all(user_id: new_owner.id)
+        .where(user_id: prev_owner.id)
+        .where(action_type: UserAction::WAS_LIKED)
+        .update_all(user_id: new_owner.id)
 
       private_message = @post.topic.private_message?
 
@@ -412,8 +412,8 @@ class PostRevisor
 
   def is_last_post?
     !Post.where(topic_id: @topic.id)
-         .where("post_number > ?", @post.post_number)
-         .exists?
+      .where("post_number > ?", @post.post_number)
+      .exists?
   end
 
   def plugin_callbacks
diff --git a/lib/pretty_text.rb b/lib/pretty_text.rb
index 8c74bd6fe1f..cfe191f5051 100644
--- a/lib/pretty_text.rb
+++ b/lib/pretty_text.rb
@@ -128,7 +128,7 @@ module PrettyText
     end
   end
 
-  def self.markdown(text, opts={})
+  def self.markdown(text, opts = {})
     # we use the exact same markdown converter as the client
     # TODO: use the same extensions on both client and server (in particular the template for mentions)
     baked = nil
@@ -165,7 +165,7 @@ module PrettyText
         __optInput.customEmoji = #{custom_emoji.to_json};
         __optInput.emojiUnicodeReplacer = __emojiUnicodeReplacer;
         __optInput.lookupInlineOnebox = __lookupInlineOnebox;
-        #{opts[:linkify] == false ? "__optInput.linkify = false;": ""}
+        #{opts[:linkify] == false ? "__optInput.linkify = false;" : ""}
         __optInput.censoredWords = #{WordWatcher.words_for_action(:censor).join('|').to_json};
       JS
 
@@ -179,7 +179,6 @@ module PrettyText
 
       buffer << "__textOptions = __buildOptions(__optInput);\n"
 
-
       buffer << ("__pt = new __PrettyText(__textOptions);")
 
       # Be careful disabling sanitization. We allow for custom emails
@@ -225,7 +224,7 @@ module PrettyText
     end
   end
 
-  def self.cook(text, opts={})
+  def self.cook(text, opts = {})
     options = opts.dup
 
     # we have a minor inconsistency
@@ -281,7 +280,7 @@ module PrettyText
         if !uri.host.present? ||
            uri.host == site_uri.host ||
            uri.host.ends_with?("." << site_uri.host) ||
-           whitelist.any?{|u| uri.host == u || uri.host.ends_with?("." << u)}
+           whitelist.any? { |u| uri.host == u || uri.host.ends_with?("." << u) }
           # we are good no need for nofollow
         else
           l["rel"] = "nofollow noopener"
@@ -328,7 +327,7 @@ module PrettyText
     links
   end
 
-  def self.excerpt(html, max_length, options={})
+  def self.excerpt(html, max_length, options = {})
     # TODO: properly fix this HACK in ExcerptParser without introducing XSS
     doc = Nokogiri::HTML.fragment(html)
     strip_image_wrapping(doc)
@@ -342,7 +341,7 @@ module PrettyText
 
     # If the user is not basic, strip links from their bio
     fragment = Nokogiri::HTML.fragment(string)
-    fragment.css('a').each {|a| a.replace(a.inner_html) }
+    fragment.css('a').each { |a| a.replace(a.inner_html) }
     fragment.to_html
   end
 
diff --git a/lib/pretty_text/helpers.rb b/lib/pretty_text/helpers.rb
index c9859e04ad7..38abc290922 100644
--- a/lib/pretty_text/helpers.rb
+++ b/lib/pretty_text/helpers.rb
@@ -11,7 +11,7 @@ module PrettyText
         I18n.t(key)
       else
         str = I18n.t(key, Hash[opts.entries].symbolize_keys).dup
-        opts.each { |k,v| str.gsub!("{{#{k.to_s}}}", v.to_s) }
+        opts.each { |k, v| str.gsub!("{{#{k.to_s}}}", v.to_s) }
         str
       end
     end
diff --git a/lib/primary_group_lookup.rb b/lib/primary_group_lookup.rb
index c61bb1b7e5e..5f488dfedf9 100644
--- a/lib/primary_group_lookup.rb
+++ b/lib/primary_group_lookup.rb
@@ -1,5 +1,5 @@
 class PrimaryGroupLookup
-  def initialize(user_ids=[])
+  def initialize(user_ids = [])
     @user_ids = user_ids.tap(&:compact!).tap(&:uniq!).tap(&:flatten!)
   end
 
@@ -20,13 +20,13 @@ class PrimaryGroupLookup
 
   def user_lookup_hash
     users_with_primary_group = User.where(id: @user_ids)
-        .where.not(primary_group_id: nil)
-        .select(:id, :primary_group_id)
+      .where.not(primary_group_id: nil)
+      .select(:id, :primary_group_id)
 
     group_lookup = {}
     group_ids = users_with_primary_group.map(&:primary_group_id).compact
     Group.where(id: group_ids).select(self.class.lookup_columns)
-         .each { |g| group_lookup[g.id] = g }
+      .each { |g| group_lookup[g.id] = g }
 
     hash = {}
     users_with_primary_group.each do |u|
diff --git a/lib/promotion.rb b/lib/promotion.rb
index 82dd5a998cf..368032144d5 100644
--- a/lib/promotion.rb
+++ b/lib/promotion.rb
@@ -7,7 +7,6 @@ class Promotion
     @user = user
   end
 
-
   # Review a user for a promotion. Delegates work to a review_#{trust_level} method.
   # Returns true if the user was promoted, false otherwise.
   def review
@@ -17,7 +16,6 @@ class Promotion
     # Promotion beyond basic requires some expensive queries, so don't do that here.
     return false if @user.trust_level >= TrustLevel[2]
 
-
     review_method = :"review_tl#{@user.trust_level}"
     return send(review_method) if respond_to?(review_method)
 
@@ -43,7 +41,7 @@ class Promotion
     new_level = level
 
     if new_level < old_level && !@user.trust_level_locked
-      next_up = new_level+1
+      next_up = new_level + 1
       key = "tl#{next_up}_met?"
       if self.class.respond_to?(key) && self.class.send(key, @user)
         raise Discourse::InvalidAccess.new, I18n.t('trust_levels.change_failed_explanation',
@@ -62,10 +60,10 @@ class Promotion
       if admin
         StaffActionLogger.new(admin).log_trust_level_change(@user, old_level, new_level)
       else
-        UserHistory.create!( action: UserHistory.actions[:auto_trust_level_change],
-                             target_user_id: @user.id,
-                             previous_value: old_level,
-                             new_value: new_level)
+        UserHistory.create!(action: UserHistory.actions[:auto_trust_level_change],
+                            target_user_id: @user.id,
+                            previous_value: old_level,
+                            new_value: new_level)
       end
       @user.save!
       @user.user_profile.recook_bio
@@ -77,7 +75,6 @@ class Promotion
     true
   end
 
-
   def self.tl2_met?(user)
     stat = user.user_stat
     return false if stat.topics_entered < SiteSetting.tl2_requires_topics_entered
diff --git a/lib/rate_limiter.rb b/lib/rate_limiter.rb
index 0985db91162..59359af107e 100644
--- a/lib/rate_limiter.rb
+++ b/lib/rate_limiter.rb
@@ -72,7 +72,7 @@ class RateLimiter
 
     arr = $redis.lrange(@key, 0, @max) || []
     t0 = Time.now.to_i
-    arr.reject! {|a| (t0 - a.to_i) > @secs}
+    arr.reject! { |a| (t0 - a.to_i) > @secs }
     @max - arr.size
   end
 
diff --git a/lib/rate_limiter/limit_exceeded.rb b/lib/rate_limiter/limit_exceeded.rb
index 787bcdd381b..0836ecd3a7e 100644
--- a/lib/rate_limiter/limit_exceeded.rb
+++ b/lib/rate_limiter/limit_exceeded.rb
@@ -4,7 +4,7 @@ class RateLimiter
   class LimitExceeded < StandardError
     attr_reader :type
 
-    def initialize(available_in, type=nil)
+    def initialize(available_in, type = nil)
       @available_in = available_in
       @type = type
     end
diff --git a/lib/rate_limiter/on_create_record.rb b/lib/rate_limiter/on_create_record.rb
index 4232ab9a7f8..14374de6a12 100644
--- a/lib/rate_limiter/on_create_record.rb
+++ b/lib/rate_limiter/on_create_record.rb
@@ -13,7 +13,7 @@ class RateLimiter
       return @rate_limiter if @rate_limiter.present?
 
       limit_key = "create_#{self.class.name.underscore}"
-      max_setting = if user && user.new_user? and SiteSetting.has_setting?("rate_limit_new_user_#{limit_key}")
+      max_setting = if user && user.new_user? && SiteSetting.has_setting?("rate_limit_new_user_#{limit_key}")
         SiteSetting.send("rate_limit_new_user_#{limit_key}")
       else
         SiteSetting.send("rate_limit_#{limit_key}")
@@ -31,7 +31,7 @@ class RateLimiter
     end
 
     module ClassMethods
-      def rate_limit(limiter_method=nil)
+      def rate_limit(limiter_method = nil)
 
         limiter_method = limiter_method || :default_rate_limiter
 
diff --git a/lib/s3_helper.rb b/lib/s3_helper.rb
index 7fbfcc8d10e..778808a7018 100644
--- a/lib/s3_helper.rb
+++ b/lib/s3_helper.rb
@@ -6,7 +6,7 @@ class S3Helper
 
   attr_reader :s3_bucket_name
 
-  def initialize(s3_upload_bucket, tombstone_prefix='', options={})
+  def initialize(s3_upload_bucket, tombstone_prefix = '', options = {})
     @s3_options = default_s3_options.merge(options)
 
     @s3_bucket_name, @s3_bucket_folder_path = begin
@@ -24,14 +24,14 @@ class S3Helper
     check_missing_options
   end
 
-  def upload(file, path, options={})
+  def upload(file, path, options = {})
     path = get_path_for_s3_upload(path)
     obj = s3_bucket.object(path)
     obj.upload_file(file, options)
     path
   end
 
-  def remove(s3_filename, copy_to_tombstone=false)
+  def remove(s3_filename, copy_to_tombstone = false)
     bucket = s3_bucket
 
     # copy the file in tombstone
@@ -50,9 +50,8 @@ class S3Helper
     return if @tombstone_prefix.blank?
 
     # cf. http://docs.aws.amazon.com/AmazonS3/latest/dev/object-lifecycle-mgmt.html
-    s3_resource.client.put_bucket_lifecycle({
-      bucket: @s3_bucket_name,
-      lifecycle_configuration: {
+    s3_resource.client.put_bucket_lifecycle(bucket: @s3_bucket_name,
+                                            lifecycle_configuration: {
         rules: [
           {
             id: "purge-tombstone",
@@ -61,8 +60,7 @@ class S3Helper
             prefix: @tombstone_prefix
           }
         ]
-      }
-    })
+      })
   end
 
   private
diff --git a/lib/scheduler/defer.rb b/lib/scheduler/defer.rb
index e055e7f9206..7b4abf7d64c 100644
--- a/lib/scheduler/defer.rb
+++ b/lib/scheduler/defer.rb
@@ -22,7 +22,7 @@ module Scheduler
       @async = val
     end
 
-    def later(desc = nil, db=RailsMultisite::ConnectionManagement.current_db, &blk)
+    def later(desc = nil, db = RailsMultisite::ConnectionManagement.current_db, &blk)
       if @async
         start_thread unless (@thread && @thread.alive?) || @paused
         @queue << [db, blk, desc]
@@ -43,7 +43,7 @@ module Scheduler
 
     def do_all_work
       while !@queue.empty?
-        do_work(_non_block=true)
+        do_work(_non_block = true)
       end
     end
 
@@ -61,16 +61,16 @@ module Scheduler
     end
 
     # using non_block to match Ruby #deq
-    def do_work(non_block=false)
+    def do_work(non_block = false)
       db, job, desc = @queue.deq(non_block)
       begin
         RailsMultisite::ConnectionManagement.establish_connection(db: db) if db
         job.call
       rescue => ex
-        Discourse.handle_job_exception(ex, {message: "Running deferred code '#{desc}'"})
+        Discourse.handle_job_exception(ex, message: "Running deferred code '#{desc}'")
       end
     rescue => ex
-      Discourse.handle_job_exception(ex, {message: "Processing deferred code queue"})
+      Discourse.handle_job_exception(ex, message: "Processing deferred code queue")
     ensure
       ActiveRecord::Base.connection_handler.clear_active_connections!
     end
diff --git a/lib/scheduler/manager.rb b/lib/scheduler/manager.rb
index 48466a6687c..6b6cf9fd0e9 100644
--- a/lib/scheduler/manager.rb
+++ b/lib/scheduler/manager.rb
@@ -42,13 +42,13 @@ module Scheduler
       def keep_alive
         @manager.keep_alive
       rescue => ex
-        Discourse.handle_job_exception(ex, {message: "Scheduling manager keep-alive"})
+        Discourse.handle_job_exception(ex, message: "Scheduling manager keep-alive")
       end
 
       def reschedule_orphans
         @manager.reschedule_orphans!
       rescue => ex
-        Discourse.handle_job_exception(ex, {message: "Scheduling manager orphan rescheduler"})
+        Discourse.handle_job_exception(ex, message: "Scheduling manager orphan rescheduler")
       end
 
       def hostname
@@ -117,7 +117,7 @@ module Scheduler
           @mutex.synchronize { info.write! }
         end
       rescue => ex
-        Discourse.handle_job_exception(ex, {message: "Processing scheduled job queue"})
+        Discourse.handle_job_exception(ex, message: "Processing scheduled job queue")
       ensure
         @running = false
         ActiveRecord::Base.connection_handler.clear_active_connections!
@@ -175,11 +175,11 @@ module Scheduler
 
     end
 
-    def self.without_runner(redis=nil)
+    def self.without_runner(redis = nil)
       self.new(redis, skip_runner: true)
     end
 
-    def initialize(redis = nil, options=nil)
+    def initialize(redis = nil, options = nil)
       @redis = $redis || redis
       @random_ratio = 0.1
       unless options && options[:skip_runner]
@@ -236,7 +236,7 @@ module Scheduler
       end
     end
 
-    def reschedule_orphans_on!(hostname=nil)
+    def reschedule_orphans_on!(hostname = nil)
       redis.zrange(Manager.queue_key(hostname), 0, -1).each do |key|
         klass = get_klass(key)
         next unless klass
@@ -264,7 +264,7 @@ module Scheduler
       end
     end
 
-    def schedule_next_job(hostname=nil)
+    def schedule_next_job(hostname = nil)
       (key, due), _ = redis.zrange Manager.queue_key(hostname), 0, 0, withscores: true
       return unless key
 
@@ -310,7 +310,6 @@ module Scheduler
       end
     end
 
-
     def self.discover_schedules
       # hack for developemnt reloader is crazytown
       # multiple classes with same name can be in
@@ -343,7 +342,7 @@ module Scheduler
       "_scheduler_lock_"
     end
 
-    def self.queue_key(hostname=nil)
+    def self.queue_key(hostname = nil)
       if hostname
         "_scheduler_queue_#{hostname}_"
       else
@@ -351,7 +350,7 @@ module Scheduler
       end
     end
 
-    def self.schedule_key(klass,hostname=nil)
+    def self.schedule_key(klass, hostname = nil)
       if hostname
         "_scheduler_#{klass}_#{hostname}"
       else
diff --git a/lib/scheduler/schedule.rb b/lib/scheduler/schedule.rb
index a00fe1330f4..05c8085bc1f 100644
--- a/lib/scheduler/schedule.rb
+++ b/lib/scheduler/schedule.rb
@@ -1,13 +1,13 @@
 module Scheduler::Schedule
 
-  def daily(options=nil)
+  def daily(options = nil)
     if options
       @daily = options
     end
     @daily
   end
 
-  def every(duration=nil)
+  def every(duration = nil)
     if duration
       @every = duration
       if manager = Scheduler::Manager.current
diff --git a/lib/scheduler/web.rb b/lib/scheduler/web.rb
index 6d414ce8e91..e9d573ea442 100644
--- a/lib/scheduler/web.rb
+++ b/lib/scheduler/web.rb
@@ -15,8 +15,8 @@ module Scheduler
           return unless duration
           if duration < 1000
             "#{duration}ms"
-          elsif duration < 60*1000
-            "#{'%.2f' % (duration/1000.0)} secs"
+          elsif duration < 60 * 1000
+            "#{'%.2f' % (duration / 1000.0)} secs"
           end
         end
       end
@@ -24,7 +24,7 @@ module Scheduler
       app.get "/scheduler" do
         RailsMultisite::ConnectionManagement.with_connection("default") do
           @manager = Scheduler::Manager.without_runner
-          @schedules = Scheduler::Manager.discover_schedules.sort do |a,b|
+          @schedules = Scheduler::Manager.discover_schedules.sort do |a, b|
             a_next = a.schedule_info.next_run
             b_next = b.schedule_info.next_run
             if a_next && b_next
@@ -35,13 +35,13 @@ module Scheduler
               1
             end
           end
-          erb File.read(File.join(VIEWS, 'scheduler.erb')), locals: {view_path: VIEWS}
+          erb File.read(File.join(VIEWS, 'scheduler.erb')), locals: { view_path: VIEWS }
         end
       end
 
       app.get "/scheduler/history" do
         @scheduler_stats = SchedulerStat.order('started_at desc').limit(200)
-        erb File.read(File.join(VIEWS, 'history.erb')), locals: {view_path: VIEWS}
+        erb File.read(File.join(VIEWS, 'history.erb')), locals: { view_path: VIEWS }
       end
 
       app.post "/scheduler/:name/trigger" do
diff --git a/lib/score_calculator.rb b/lib/score_calculator.rb
index 8901c12e5ab..baf93cb457e 100644
--- a/lib/score_calculator.rb
+++ b/lib/score_calculator.rb
@@ -11,19 +11,18 @@ class ScoreCalculator
     }
   end
 
-  def initialize(weightings=nil)
+  def initialize(weightings = nil)
     @weightings = weightings || ScoreCalculator.default_score_weights
   end
 
   # Calculate the score for all posts based on the weightings
-  def calculate(opts=nil)
+  def calculate(opts = nil)
     update_posts_score(opts)
     update_posts_rank(opts)
     update_topics_rank(opts)
     update_topics_percent_rank(opts)
   end
 
-
   private
 
   def update_posts_score(opts)
@@ -110,7 +109,6 @@ SQL
               posts_required: SiteSetting.summary_posts_required,
               score_required: SiteSetting.summary_score_threshold)
 
-
     filter_topics(builder, opts)
 
     builder.exec
@@ -131,7 +129,6 @@ SQL
     builder.exec
   end
 
-
   def filter_topics(builder, opts)
     return builder unless opts
 
diff --git a/lib/screening_model.rb b/lib/screening_model.rb
index 26ed789c6c4..62cc0eb8a1a 100644
--- a/lib/screening_model.rb
+++ b/lib/screening_model.rb
@@ -24,7 +24,7 @@ module ScreeningModel
   end
 
   def action_name=(arg)
-    raise ArgumentError.new("Invalid action type #{arg}") if arg.nil? or !self.class.actions.has_key?(arg.to_sym)
+    raise ArgumentError.new("Invalid action type #{arg}") if arg.nil? || !self.class.actions.has_key?(arg.to_sym)
     self.action_type = self.class.actions[arg.to_sym]
   end
 
diff --git a/lib/search.rb b/lib/search.rb
index 0edd4eecf7c..843127e8499 100644
--- a/lib/search.rb
+++ b/lib/search.rb
@@ -27,25 +27,25 @@ class Search
     # base docker config
     #
     case SiteSetting.default_locale.to_sym
-      when :da     then 'danish'
-      when :de     then 'german'
-      when :en     then 'english'
-      when :es     then 'spanish'
-      when :fr     then 'french'
-      when :it     then 'italian'
-      when :nl     then 'dutch'
-      when :nb_NO  then 'norwegian'
-      when :pt     then 'portuguese'
-      when :pt_BR  then 'portuguese'
-      when :sv     then 'swedish'
-      when :ru     then 'russian'
+    when :da     then 'danish'
+    when :de     then 'german'
+    when :en     then 'english'
+    when :es     then 'spanish'
+    when :fr     then 'french'
+    when :it     then 'italian'
+    when :nl     then 'dutch'
+    when :nb_NO  then 'norwegian'
+    when :pt     then 'portuguese'
+    when :pt_BR  then 'portuguese'
+    when :sv     then 'swedish'
+    when :ru     then 'russian'
       else 'simple' # use the 'simple' stemmer for other languages
     end
   end
 
   def self.rebuild_problem_posts(limit = 10000)
     posts = Post.joins(:topic)
-            .where('posts.id IN (
+      .where('posts.id IN (
                SELECT p2.id FROM posts p2
                LEFT JOIN post_search_data pd ON locale = ? AND p2.id = pd.post_id
                WHERE pd.post_id IS NULL
@@ -58,7 +58,7 @@ class Search
     end
 
     posts = Post.joins(:topic)
-            .where('posts.id IN (
+      .where('posts.id IN (
                SELECT p2.id FROM posts p2
                LEFT JOIN topic_search_data pd ON locale = ? AND p2.topic_id = pd.topic_id
                WHERE pd.topic_id IS NULL AND p2.post_number = 1
@@ -105,7 +105,7 @@ class Search
       month = $2 ? $3.to_i : 1
       day = $4 ? $5.to_i : 1
 
-      return if day==0 || month==0 || day > 31 || month > 12
+      return if day == 0 || month == 0 || day > 31 || month > 12
 
       return Time.zone.parse("#{year}-#{month}-#{day}") rescue nil
     end
@@ -131,17 +131,16 @@ class Search
   def self.min_post_id_no_cache
     return 0 unless SiteSetting.search_prefer_recent_posts?
 
-
     offset, has_more = Post.unscoped
-                           .order('id desc')
-                           .offset(SiteSetting.search_recent_posts_size-1)
-                           .limit(2)
-                           .pluck(:id)
+      .order('id desc')
+      .offset(SiteSetting.search_recent_posts_size - 1)
+      .limit(2)
+      .pluck(:id)
 
     has_more ? offset : 0
   end
 
-  def self.min_post_id(opts=nil)
+  def self.min_post_id(opts = nil)
     return 0 unless SiteSetting.search_prefer_recent_posts?
 
     # It can be quite slow to count all the posts so let's cache it
@@ -153,7 +152,7 @@ class Search
   attr_accessor :term
   attr_reader :clean_term
 
-  def initialize(term, opts=nil)
+  def initialize(term, opts = nil)
     @opts = opts || {}
     @guardian = @opts[:guardian] || Guardian.new
     @search_context = @opts[:search_context]
@@ -195,7 +194,7 @@ class Search
     @valid
   end
 
-  def self.execute(term, opts=nil)
+  def self.execute(term, opts = nil)
     self.new(term, opts).execute
   end
 
@@ -213,7 +212,7 @@ class Search
 
     unless @filters.present? || @opts[:search_for_id]
       min_length = @opts[:min_search_term_length] || SiteSetting.min_search_term_length
-      terms = (@term || '').split(/\s(?=(?:[^"]|"[^"]*")*$)/).reject {|t| t.length < min_length }
+      terms = (@term || '').split(/\s(?=(?:[^"]|"[^"]*")*$)/).reject { |t| t.length < min_length }
 
       if terms.blank?
         @term = ''
@@ -240,7 +239,7 @@ class Search
     @results
   end
 
-  def self.advanced_filter(trigger,&block)
+  def self.advanced_filter(trigger, &block)
     (@advanced_filters ||= {})[trigger] = block
   end
 
@@ -292,11 +291,11 @@ class Search
     end
   end
 
-  advanced_filter(/in:wiki/) do |posts,match|
+  advanced_filter(/in:wiki/) do |posts, match|
     posts.where(wiki: true)
   end
 
-  advanced_filter(/badge:(.*)/) do |posts,match|
+  advanced_filter(/badge:(.*)/) do |posts, match|
     badge_id = Badge.where('name ilike ? OR id = ?', match, match.to_i).pluck(:id).first
     if badge_id
       posts.where('posts.user_id IN (SELECT ub.user_id FROM user_badges ub WHERE ub.badge_id = ?)', badge_id)
@@ -323,7 +322,7 @@ class Search
     posts.where("posts.user_id = #{@guardian.user.id}") if @guardian.user
   end
 
-  advanced_filter(/in:(watching|tracking)/) do |posts,match|
+  advanced_filter(/in:(watching|tracking)/) do |posts, match|
     if @guardian.user
       level = TopicUser.notification_levels[match.to_sym]
       posts.where("posts.topic_id IN (
@@ -358,7 +357,7 @@ class Search
     end
   end
 
-  advanced_filter(/category:(.+)/) do |posts,match|
+  advanced_filter(/category:(.+)/) do |posts, match|
     exact = false
 
     if match[0] == "="
@@ -381,7 +380,7 @@ class Search
     end
   end
 
-  advanced_filter(/^\#([a-zA-Z0-9\-:=]+)/) do |posts,match|
+  advanced_filter(/^\#([a-zA-Z0-9\-:=]+)/) do |posts, match|
 
     exact = true
 
@@ -422,7 +421,7 @@ class Search
     end
   end
 
-  advanced_filter(/group:(.+)/) do |posts,match|
+  advanced_filter(/group:(.+)/) do |posts, match|
     group_id = Group.where('name ilike ? OR (id = ? AND id > 0)', match, match.to_i).pluck(:id).first
     if group_id
       posts.where("posts.user_id IN (select gu.user_id from group_users gu where gu.group_id = ?)", group_id)
@@ -431,7 +430,7 @@ class Search
     end
   end
 
-  advanced_filter(/user:(.+)/) do |posts,match|
+  advanced_filter(/user:(.+)/) do |posts, match|
     user_id = User.where(staged: false).where('username_lower = ? OR id = ?', match.downcase, match.to_i).pluck(:id).first
     if user_id
       posts.where("posts.user_id = #{user_id}")
@@ -440,7 +439,7 @@ class Search
     end
   end
 
-  advanced_filter(/^\@([a-zA-Z0-9_\-.]+)/) do |posts,match|
+  advanced_filter(/^\@([a-zA-Z0-9_\-.]+)/) do |posts, match|
     user_id = User.where(staged: false).where(username_lower: match.downcase).pluck(:id).first
     if user_id
       posts.where("posts.user_id = #{user_id}")
@@ -449,7 +448,7 @@ class Search
     end
   end
 
-  advanced_filter(/before:(.*)/) do |posts,match|
+  advanced_filter(/before:(.*)/) do |posts, match|
     if date = Search.word_to_date(match)
       posts.where("posts.created_at < ?", date)
     else
@@ -457,7 +456,7 @@ class Search
     end
   end
 
-  advanced_filter(/after:(.*)/) do |posts,match|
+  advanced_filter(/after:(.*)/) do |posts, match|
     if date = Search.word_to_date(match)
       posts.where("posts.created_at > ?", date)
     else
@@ -490,16 +489,15 @@ class Search
 
   private
 
-
     def process_advanced_search!(term)
 
-      term.to_s.scan(/(([^" \t\n\x0B\f\r]+)?(("[^"]+")?))/).to_a.map do |(word,_)|
+      term.to_s.scan(/(([^" \t\n\x0B\f\r]+)?(("[^"]+")?))/).to_a.map do |(word, _)|
         next if word.blank?
 
         found = false
 
         Search.advanced_filters.each do |matcher, block|
-          cleaned = word.gsub(/["']/,"")
+          cleaned = word.gsub(/["']/, "")
           if cleaned =~ matcher
             (@filters ||= []) << [block, $1]
             found = true
@@ -539,7 +537,6 @@ class Search
       end.compact.join(' ')
     end
 
-
     def find_grouped_results
 
       if @results.type_filter.present?
@@ -600,11 +597,11 @@ class Search
       secure_category_ids
 
       categories = Category.includes(:category_search_data)
-                           .where("category_search_data.search_data @@ #{ts_query}")
-                           .references(:category_search_data)
-                           .order("topics_month DESC")
-                           .secured(@guardian)
-                           .limit(@limit)
+        .where("category_search_data.search_data @@ #{ts_query}")
+        .references(:category_search_data)
+        .order("topics_month DESC")
+        .secured(@guardian)
+        .limit(@limit)
 
       categories.each do |category|
         @results.add(category)
@@ -615,37 +612,37 @@ class Search
       return if SiteSetting.hide_user_profiles_from_public && !@guardian.user
 
       users = User.includes(:user_search_data)
-                  .references(:user_search_data)
-                  .where(active: true)
-                  .where(staged: false)
-                  .where("user_search_data.search_data @@ #{ts_query("simple")}")
-                  .order("CASE WHEN username_lower = '#{@original_term.downcase}' THEN 0 ELSE 1 END")
-                  .order("last_posted_at DESC")
-                  .limit(@limit)
+        .references(:user_search_data)
+        .where(active: true)
+        .where(staged: false)
+        .where("user_search_data.search_data @@ #{ts_query("simple")}")
+        .order("CASE WHEN username_lower = '#{@original_term.downcase}' THEN 0 ELSE 1 END")
+        .order("last_posted_at DESC")
+        .limit(@limit)
 
       users.each do |user|
         @results.add(user)
       end
     end
 
-    def posts_query(limit, opts=nil)
+    def posts_query(limit, opts = nil)
       opts ||= {}
       posts = Post.where(post_type: Topic.visible_post_types(@guardian.user))
-                  .joins(:post_search_data, :topic)
-                  .joins("LEFT JOIN categories ON categories.id = topics.category_id")
-                  .where("topics.deleted_at" => nil)
-                  .where("topics.visible")
+        .joins(:post_search_data, :topic)
+        .joins("LEFT JOIN categories ON categories.id = topics.category_id")
+        .where("topics.deleted_at" => nil)
+        .where("topics.visible")
 
       is_topic_search = @search_context.present? && @search_context.is_a?(Topic)
 
       if opts[:private_messages] || (is_topic_search && @search_context.private_message?)
-         posts = posts.where("topics.archetype =  ?", Archetype.private_message)
+        posts = posts.where("topics.archetype =  ?", Archetype.private_message)
 
          unless @guardian.is_admin?
            posts = posts.private_posts_for_user(@guardian.user)
          end
       else
-         posts = posts.where("topics.archetype <> ?", Archetype.private_message)
+        posts = posts.where("topics.archetype <> ?", Archetype.private_message)
       end
 
       if @term.present?
@@ -696,7 +693,7 @@ class Search
           posts = posts.where("topics.category_id in (?)", category_ids)
         elsif @search_context.is_a?(Topic)
           posts = posts.where("topics.id = #{@search_context.id}")
-                       .order("posts.post_number #{@order == :latest ? "DESC" : ""}")
+            .order("posts.post_number #{@order == :latest ? "DESC" : ""}")
         end
 
       end
@@ -767,11 +764,11 @@ class Search
         t.split(/[\)\(&']/)[0]
       end.compact!
 
-      query = Post.sanitize(all_terms.map {|t| "'#{PG::Connection.escape_string(t)}':*"}.join(" #{joiner} "))
+      query = Post.sanitize(all_terms.map { |t| "'#{PG::Connection.escape_string(t)}':*" }.join(" #{joiner} "))
       "TO_TSQUERY(#{locale || query_locale}, #{query})"
     end
 
-    def ts_query(locale=nil)
+    def ts_query(locale = nil)
       @ts_query_cache ||= {}
       @ts_query_cache[(locale || query_locale) + " " + @term] ||= Search.ts_query(@term, locale)
     end
@@ -825,7 +822,7 @@ class Search
       end
 
       if added < @limit
-        aggregate_posts(post_sql[:remaining]).each {|p| @results.add(p) }
+        aggregate_posts(post_sql[:remaining]).each { |p| @results.add(p) }
       end
     end
 
diff --git a/lib/search/grouped_search_results.rb b/lib/search/grouped_search_results.rb
index d6677155c28..90ca05f229f 100644
--- a/lib/search/grouped_search_results.rb
+++ b/lib/search/grouped_search_results.rb
@@ -57,8 +57,7 @@ class Search
       end
     end
 
-
-    def self.blurb_for(cooked, term=nil, blurb_length=200)
+    def self.blurb_for(cooked, term = nil, blurb_length = 200)
       cooked = SearchIndexer::HtmlScrubber.scrub(cooked).squish
 
       blurb = nil
diff --git a/lib/secure_session.rb b/lib/secure_session.rb
index bbe9a71833e..ecb46a6f67e 100644
--- a/lib/secure_session.rb
+++ b/lib/secure_session.rb
@@ -8,7 +8,7 @@ class SecureSession
     $redis.get("#{@prefix}#{key}")
   end
 
-  def []=(key,val)
+  def []=(key, val)
     if val == nil
       $redis.del("#{@prefix}#{key}")
     else
diff --git a/lib/single_sign_on.rb b/lib/single_sign_on.rb
index b8a20a80eb8..7578a8aabed 100644
--- a/lib/single_sign_on.rb
+++ b/lib/single_sign_on.rb
@@ -43,7 +43,7 @@ class SingleSignOn
       sso.send("#{k}=", val)
     end
 
-    decoded_hash.each do |k,v|
+    decoded_hash.each do |k, v|
       if field = k[/^custom\.(.+)$/, 1]
         sso.custom_fields[field] = v
       end
@@ -72,7 +72,7 @@ class SingleSignOn
     OpenSSL::HMAC.hexdigest("sha256", sso_secret, payload)
   end
 
-  def to_url(base_url=nil)
+  def to_url(base_url = nil)
     base = "#{base_url || sso_url}"
     "#{base}#{base.include?('?') ? '&' : '?'}#{payload}"
   end
@@ -86,7 +86,7 @@ class SingleSignOn
     payload = {}
 
     ACCESSORS.each do |k|
-     next if (val = send k) == nil
+      next if (val = send k) == nil
      payload[k] = val
     end
 
diff --git a/lib/site_setting_extension.rb b/lib/site_setting_extension.rb
index 99ab174d22d..5b9fb8987d6 100644
--- a/lib/site_setting_extension.rb
+++ b/lib/site_setting_extension.rb
@@ -169,13 +169,13 @@ module SiteSettingExtension
   end
 
   def client_settings_json_uncached
-    MultiJson.dump(Hash[*@client_settings.map{|n| [n, self.send(n)]}.flatten])
+    MultiJson.dump(Hash[*@client_settings.map { |n| [n, self.send(n)] }.flatten])
   end
 
   # Retrieve all settings
-  def all_settings(include_hidden=false)
+  def all_settings(include_hidden = false)
     @defaults
-      .reject{|s, _| hidden_settings.include?(s) && !include_hidden}
+      .reject { |s, _| hidden_settings.include?(s) && !include_hidden }
       .map do |s, v|
         value = send(s)
         type = types[get_data_type(s, value)]
@@ -190,9 +190,9 @@ module SiteSettingExtension
         }
 
         if type == :enum && enum_class(s)
-          opts.merge!({valid_values: enum_class(s).values, translate_names: enum_class(s).translate_names?})
+          opts.merge!(valid_values: enum_class(s).values, translate_names: enum_class(s).translate_names?)
         elsif type == :enum
-          opts.merge!({valid_values: choices[s].map{|c| {name: c, value: c}}, translate_names: false})
+          opts.merge!(valid_values: choices[s].map { |c| { name: c, value: c } }, translate_names: false)
         end
 
         opts[:textarea] = true if static_types[s] == :textarea
@@ -219,7 +219,7 @@ module SiteSettingExtension
       ensure_listen_for_changes
       old = current
 
-      new_hash =  Hash[*(provider.all.map { |s|
+      new_hash = Hash[*(provider.all.map { |s|
         [s.name.intern, convert(s.value, s.data_type, s.name)]
       }.to_a.flatten)]
 
@@ -325,11 +325,11 @@ module SiteSettingExtension
   end
 
   def notify_changed!
-    MessageBus.publish('/site_settings', {process: process_id})
+    MessageBus.publish('/site_settings', process: process_id)
   end
 
   def notify_clients!(name)
-    MessageBus.publish('/client_settings', {name: name, value: self.send(name)})
+    MessageBus.publish('/client_settings', name: name, value: self.send(name))
   end
 
   def has_setting?(name)
@@ -371,7 +371,7 @@ module SiteSettingExtension
     end
   end
 
-  def set_and_log(name, value, user=Discourse.system_user)
+  def set_and_log(name, value, user = Discourse.system_user)
     prev_value = send(name)
     set(name, value)
     StaffActionLogger.new(user).log_site_setting_change(name, prev_value, value) if has_setting?(name)
@@ -389,14 +389,14 @@ module SiteSettingExtension
     deletions = []
 
     new_hash.each do |name, value|
-      changes << [name,value] if !old.has_key?(name) || old[name] != value
+      changes << [name, value] if !old.has_key?(name) || old[name] != value
     end
 
-    old.each do |name,value|
-      deletions << [name,value] unless new_hash.has_key?(name)
+    old.each do |name, value|
+      deletions << [name, value] unless new_hash.has_key?(name)
     end
 
-    [changes,deletions]
+    [changes, deletions]
   end
 
   def get_data_type(name, val)
diff --git a/lib/site_settings/db_provider.rb b/lib/site_settings/db_provider.rb
index 7757299fbd7..4410e05eeef 100644
--- a/lib/site_settings/db_provider.rb
+++ b/lib/site_settings/db_provider.rb
@@ -33,8 +33,8 @@ class SiteSettings::DbProvider
     model ||= @model.new
 
     model.name = name
-    model.value =  value
-    model.data_type =  data_type
+    model.value = value
+    model.data_type = data_type
 
     # save! used to ensure after_commit is called
     model.save!
diff --git a/lib/slug.rb b/lib/slug.rb
index 0f3b62b3f07..5ee570198ee 100644
--- a/lib/slug.rb
+++ b/lib/slug.rb
@@ -5,11 +5,12 @@ module Slug
   CHAR_FILTER_REGEXP = /[:\/\?#\[\]@!\$&'\(\)\*\+,;=_\.~%\\`^\s|\{\}"<>]+/ # :/?#[]@!$&'()*+,;=_.~%\`^|{}"<>
 
   def self.for(string, default = 'topic')
-    slug = case (SiteSetting.slug_generation_method || :ascii).to_sym
-           when :ascii then self.ascii_generator(string)
-           when :encoded then self.encoded_generator(string)
-           when :none then self.none_generator(string)
-           end
+    slug =
+      case (SiteSetting.slug_generation_method || :ascii).to_sym
+      when :ascii then self.ascii_generator(string)
+      when :encoded then self.encoded_generator(string)
+      when :none then self.none_generator(string)
+      end
     # Reject slugs that only contain numbers, because they would be indistinguishable from id's.
     slug = (slug =~ /[^\d]/ ? slug : '')
     slug.blank? ? default : slug
@@ -23,8 +24,8 @@ module Slug
 
   def self.ascii_generator(string)
     string.tr("'", "")
-          .parameterize
-          .tr("_", "-")
+      .parameterize
+      .tr("_", "-")
   end
 
   def self.encoded_generator(string)
@@ -32,10 +33,10 @@ module Slug
     # including reserved characters from RFC3986.
     # See also URI::REGEXP::PATTERN.
     string.strip
-          .gsub(/\s+/, '-')
-          .gsub(CHAR_FILTER_REGEXP, '')
-          .gsub(/\A-+|-+\z/, '') # remove possible trailing and preceding dashes
-          .squeeze('-') # squeeze continuous dashes to prettify slug
+      .gsub(/\s+/, '-')
+      .gsub(CHAR_FILTER_REGEXP, '')
+      .gsub(/\A-+|-+\z/, '') # remove possible trailing and preceding dashes
+      .squeeze('-') # squeeze continuous dashes to prettify slug
   end
 
   def self.none_generator(string)
diff --git a/lib/source_url.rb b/lib/source_url.rb
index 41d4fe5decc..90a4391f5b1 100644
--- a/lib/source_url.rb
+++ b/lib/source_url.rb
@@ -6,7 +6,7 @@ class SourceURL < Tilt::Template
     source = input[:data]
     context = input[:environment].context_class.new(input)
 
-    result = new(filename){source}.render(context)
+    result = new(filename) { source }.render(context)
     context.metadata.merge(data: result)
   end
 
diff --git a/lib/spam_handler.rb b/lib/spam_handler.rb
index b14532c27d6..2b8253512c3 100644
--- a/lib/spam_handler.rb
+++ b/lib/spam_handler.rb
@@ -4,15 +4,15 @@ class SpamHandler
     return false if SiteSetting.max_new_accounts_per_registration_ip <= 0
 
     tl2_plus_accounts_with_same_ip = User.where("trust_level >= ?", TrustLevel[2])
-                                         .where(ip_address: ip_address.to_s)
-                                         .count
+      .where(ip_address: ip_address.to_s)
+      .count
 
     return false if tl2_plus_accounts_with_same_ip > 0
 
     staff_user_ids = Group[:staff].user_ids - [-1]
     staff_members_with_same_ip = User.where(id: staff_user_ids)
-                                     .where(ip_address: ip_address.to_s)
-                                     .count
+      .where(ip_address: ip_address.to_s)
+      .count
 
     return false if staff_members_with_same_ip > 0
 
@@ -20,9 +20,9 @@ class SpamHandler
     return false if ip_whitelisted
 
     tl0_accounts_with_same_ip = User.unscoped
-                                    .where(trust_level: TrustLevel[0])
-                                    .where(ip_address: ip_address.to_s)
-                                    .count
+      .where(trust_level: TrustLevel[0])
+      .where(ip_address: ip_address.to_s)
+      .count
 
     tl0_accounts_with_same_ip >= SiteSetting.max_new_accounts_per_registration_ip
   end
diff --git a/lib/sql_builder.rb b/lib/sql_builder.rb
index 70e461095c3..35598c57232 100644
--- a/lib/sql_builder.rb
+++ b/lib/sql_builder.rb
@@ -1,13 +1,13 @@
 class SqlBuilder
 
-  def initialize(template,klass=nil)
+  def initialize(template, klass = nil)
     @args = {}
     @sql = template
     @sections = {}
     @klass = klass
   end
 
-  [:set, :where2,:where,:order_by,:limit,:left_join,:join,:offset, :select].each do |k|
+  [:set, :where2, :where, :order_by, :limit, :left_join, :join, :offset, :select].each do |k|
     define_method k do |data, args = {}|
       @args.merge!(args)
       @sections[k] ||= []
@@ -18,7 +18,7 @@ class SqlBuilder
 
   def secure_category(secure_category_ids, category_alias = 'c')
     if secure_category_ids.present?
-      where("NOT COALESCE(" << category_alias << ".read_restricted, false) OR " << category_alias <<  ".id IN (:secure_category_ids)", secure_category_ids: secure_category_ids)
+      where("NOT COALESCE(" << category_alias << ".read_restricted, false) OR " << category_alias << ".id IN (:secure_category_ids)", secure_category_ids: secure_category_ids)
     else
       where("NOT COALESCE(" << category_alias << ".read_restricted, false)")
     end
@@ -28,17 +28,17 @@ class SqlBuilder
   def to_sql
     sql = @sql.dup
 
-    @sections.each do |k,v|
+    @sections.each do |k, v|
       joined = nil
       case k
       when :select
         joined = "SELECT " << v.join(" , ")
       when :where, :where2
-        joined = "WHERE " << v.map{|c| "(" << c << ")" }.join(" AND ")
+        joined = "WHERE " << v.map { |c| "(" << c << ")" }.join(" AND ")
       when :join
-        joined = v.map{|item| "JOIN " << item }.join("\n")
+        joined = v.map { |item| "JOIN " << item }.join("\n")
       when :left_join
-        joined = v.map{|item| "LEFT JOIN " << item }.join("\n")
+        joined = v.map { |item| "LEFT JOIN " << item }.join("\n")
       when :limit
         joined = "LIMIT " << v.last.to_s
       when :offset
@@ -64,7 +64,7 @@ class SqlBuilder
       if @args == {}
         ActiveRecord::Base.exec_sql(sql)
       else
-        ActiveRecord::Base.exec_sql(sql,@args)
+        ActiveRecord::Base.exec_sql(sql, @args)
       end
     end
   end
@@ -74,7 +74,7 @@ class SqlBuilder
   end
 
   class RailsDateTimeDecoder < PG::SimpleDecoder
-    def decode(string, tuple=nil, field=nil)
+    def decode(string, tuple = nil, field = nil)
       if Rails.version >= "4.2.0"
         @caster ||= ActiveRecord::Type::DateTime.new
         @caster.type_cast_from_database(string)
@@ -84,14 +84,13 @@ class SqlBuilder
     end
   end
 
-
   class ActiveRecordTypeMap < PG::BasicTypeMapForResults
     def initialize(connection)
       super(connection)
       rm_coder 0, 1114
       add_coder RailsDateTimeDecoder.new(name: "timestamp", oid: 1114, format: 0)
-      # we don't need deprecations
-     	self.default_type_map = PG::TypeMapInRuby.new
+       # we don't need deprecations
+       self.default_type_map = PG::TypeMapInRuby.new
     end
   end
 
diff --git a/lib/stats_socket.rb b/lib/stats_socket.rb
index 337bc7b058a..e1afc677baf 100644
--- a/lib/stats_socket.rb
+++ b/lib/stats_socket.rb
@@ -16,7 +16,7 @@ class StatsSocket < SocketServer
       when "v8_stat"
         stats = {}
         ObjectSpace.each_object(MiniRacer::Context) do |context|
-          context.heap_stats.each do |k,v|
+          context.heap_stats.each do |k, v|
             stats[k] = (stats[k] || 0) + v
           end
         end
diff --git a/lib/stylesheet/compiler.rb b/lib/stylesheet/compiler.rb
index e6a7530b88b..e886c6bdcef 100644
--- a/lib/stylesheet/compiler.rb
+++ b/lib/stylesheet/compiler.rb
@@ -15,7 +15,7 @@ module Stylesheet
       footer:after { content: '#{error}' }"
     end
 
-    def self.compile_asset(asset, options={})
+    def self.compile_asset(asset, options = {})
 
       if Importer.special_imports[asset.to_s]
         filename = "theme.scss"
@@ -26,12 +26,12 @@ module Stylesheet
         file = File.read path
       end
 
-      compile(file,filename,options)
+      compile(file, filename, options)
 
     end
 
-    def self.compile(stylesheet, filename, options={})
-      source_map_file = options[:source_map_file] || "#{filename.sub(".scss","")}.css.map";
+    def self.compile(stylesheet, filename, options = {})
+      source_map_file = options[:source_map_file] || "#{filename.sub(".scss", "")}.css.map";
 
       engine = SassC::Engine.new(stylesheet,
                                  importer: Importer,
@@ -44,7 +44,6 @@ module Stylesheet
                                  theme_field: options[:theme_field],
                                  load_paths: [ASSET_ROOT])
 
-
       result = engine.render
 
       if options[:rtl]
diff --git a/lib/stylesheet/manager.rb b/lib/stylesheet/manager.rb
index ebceac32698..85cd6bd0833 100644
--- a/lib/stylesheet/manager.rb
+++ b/lib/stylesheet/manager.rb
@@ -16,7 +16,7 @@ class Stylesheet::Manager
   end
 
   def self.clear_theme_cache!
-    cache.hash.keys.select{|k| k =~ /theme/}.each{|k|cache.delete(k)}
+    cache.hash.keys.select { |k| k =~ /theme/ }.each { |k|cache.delete(k) }
   end
 
   def self.stylesheet_href(target = :desktop, theme_key = :missing)
@@ -54,9 +54,9 @@ class Stylesheet::Manager
   end
 
   def self.precompile_css
-    themes = Theme.where('user_selectable OR key = ?', SiteSetting.default_theme_key).pluck(:key,:name)
+    themes = Theme.where('user_selectable OR key = ?', SiteSetting.default_theme_key).pluck(:key, :name)
     themes << nil
-    themes.each do |key,name|
+    themes.each do |key, name|
       [:desktop, :mobile, :desktop_rtl, :mobile_rtl].each do |target|
         theme_key = key || SiteSetting.default_theme_key
         cache_key = "#{target}_#{theme_key}"
@@ -104,7 +104,7 @@ class Stylesheet::Manager
     @theme_key = theme_key
   end
 
-  def compile(opts={})
+  def compile(opts = {})
     unless opts[:force]
       if File.exists?(stylesheet_fullpath)
         unless StylesheetCache.where(target: qualified_target, digest: digest).exists?
@@ -120,7 +120,7 @@ class Stylesheet::Manager
     end
 
     rtl = @target.to_s =~ /_rtl$/
-    css,source_map = begin
+    css, source_map = begin
       Stylesheet::Compiler.compile_asset(
         @target,
          rtl: rtl,
@@ -216,7 +216,7 @@ class Stylesheet::Manager
   end
 
   def stylesheet_filename_no_digest
-    stylesheet_filename(_with_digest=false)
+    stylesheet_filename(_with_digest = false)
   end
 
   def is_theme?
diff --git a/lib/stylesheet/watcher.rb b/lib/stylesheet/watcher.rb
index 138d750fd60..e7c9a5ab9b1 100644
--- a/lib/stylesheet/watcher.rb
+++ b/lib/stylesheet/watcher.rb
@@ -3,7 +3,7 @@ require 'listen'
 module Stylesheet
   class Watcher
 
-    def self.watch(paths=nil)
+    def self.watch(paths = nil)
       watcher = new(paths)
       watcher.start
       watcher
@@ -26,7 +26,6 @@ module Stylesheet
         end
       end
 
-
       root = Rails.root.to_s
       @paths.each do |watch|
         Thread.new do
@@ -34,7 +33,7 @@ module Stylesheet
             listener = Listen.to("#{root}/#{watch}", ignore: /xxxx/) do |modified, added, _|
               paths = [modified, added].flatten
               paths.compact!
-              paths.map!{|long| long[(root.length+1)..-1]}
+              paths.map! { |long| long[(root.length + 1)..-1] }
               process_change(paths)
             end
           rescue => e
@@ -55,7 +54,7 @@ module Stylesheet
       Stylesheet::Manager.cache.clear
 
       message = ["desktop", "mobile", "admin"].map do |name|
-        {target: name, new_href: Stylesheet::Manager.stylesheet_href(name.to_sym) , theme_key: SiteSetting.default_theme_key}
+        { target: name, new_href: Stylesheet::Manager.stylesheet_href(name.to_sym) , theme_key: SiteSetting.default_theme_key }
       end
 
       MessageBus.publish '/file-change', message
diff --git a/lib/suggested_topics_builder.rb b/lib/suggested_topics_builder.rb
index 9436bb5c5a9..cd857875b16 100644
--- a/lib/suggested_topics_builder.rb
+++ b/lib/suggested_topics_builder.rb
@@ -11,15 +11,14 @@ class SuggestedTopicsBuilder
     @results = []
   end
 
-
-  def add_results(results, priority=:low)
+  def add_results(results, priority = :low)
 
     # WARNING .blank? will execute an Active Record query
     return unless results
 
     # Only add results if we don't have those topic ids already
     results = results.where('topics.id NOT IN (?)', @excluded_topic_ids)
-                     .where(visible: true)
+      .where(visible: true)
 
     # If limit suggested to category is enabled, restrict to that category
     if @category_id && SiteSetting.limit_suggested_to_category?
@@ -29,8 +28,8 @@ class SuggestedTopicsBuilder
 
     unless results.empty?
       # Keep track of the ids we've added
-      @excluded_topic_ids.concat results.map {|r| r.id}
-      splice_results(results,priority)
+      @excluded_topic_ids.concat results.map { |r| r.id }
+      splice_results(results, priority)
     end
   end
 
@@ -40,7 +39,7 @@ class SuggestedTopicsBuilder
       # Topics from category @category_id need to be first in the list, all others after.
 
       other_category_index = @results.index { |r| r.category_id != @category_id }
-      category_results, other_category_results = results.partition{ |r| r.category_id == @category_id }
+      category_results, other_category_results = results.partition { |r| r.category_id == @category_id }
 
       if other_category_index
         @results.insert other_category_index, *category_results
@@ -66,7 +65,7 @@ class SuggestedTopicsBuilder
   end
 
   def category_results_left
-    SiteSetting.suggested_topics - @results.count{|r| r.category_id == @category_id}
+    SiteSetting.suggested_topics - @results.count { |r| r.category_id == @category_id }
   end
 
   def size
diff --git a/lib/table_migration_helper.rb b/lib/table_migration_helper.rb
index 4d0308341bc..605555d49f8 100644
--- a/lib/table_migration_helper.rb
+++ b/lib/table_migration_helper.rb
@@ -45,7 +45,7 @@ SQL
                                         new_name: new_name,
                                         delay: "#{delay.to_i || 0} seconds",
                                         after_migration: after_migration).to_a.length > 0
-        on_drop&.call
+      on_drop&.call
 
         ActiveRecord::Base.exec_sql("DROP TABLE #{old_name}")
     end
diff --git a/lib/tasks/add_topic_to_quotes.rake b/lib/tasks/add_topic_to_quotes.rake
index 51d1cf2edd8..ff36e46bf06 100644
--- a/lib/tasks/add_topic_to_quotes.rake
+++ b/lib/tasks/add_topic_to_quotes.rake
@@ -6,4 +6,3 @@ task "add_topic_to_quotes" => :environment do
     Post.update_all ["raw = ?, cooked = ?", new_raw, new_cooked], ["id = ?", p.id]
   end
 end
-
diff --git a/lib/tasks/admin.rake b/lib/tasks/admin.rake
index cd7e40d39fa..c57e03b7859 100644
--- a/lib/tasks/admin.rake
+++ b/lib/tasks/admin.rake
@@ -1,6 +1,6 @@
 
 desc "invite an admin to this discourse instance"
-task "admin:invite", [:email] => [:environment] do |_,args|
+task "admin:invite", [:email] => [:environment] do |_, args|
   email = args[:email]
   if !email || email !~ /@/
     puts "ERROR: Expecting rake admin:invite[some@email.com]"
@@ -20,7 +20,7 @@ task "admin:invite", [:email] => [:environment] do |_,args|
   puts "Granting admin!"
   user.grant_admin!
   user.change_trust_level!(4)
-  user.email_tokens.update_all  confirmed: true
+  user.email_tokens.update_all confirmed: true
 
   puts "Sending email!"
   email_token = user.email_tokens.create(email: user.email)
@@ -42,8 +42,8 @@ task "admin:create" => :environment do
       reset_password = ask("User with this email already exists! Do you want to reset the password for this email? (Y/n)  ")
       if (reset_password == "" || reset_password.downcase == 'y')
         begin
-          password = ask("Password:  ") {|q| q.echo = false}
-          password_confirmation = ask("Repeat password:  ") {|q| q.echo = false}
+          password = ask("Password:  ") { |q| q.echo = false }
+          password_confirmation = ask("Repeat password:  ") { |q| q.echo = false }
         end while password != password_confirmation
         admin.password = password
       end
@@ -53,8 +53,8 @@ task "admin:create" => :environment do
       admin.email = email
       admin.username = UserNameSuggester.suggest(admin.email)
       begin
-        password = ask("Password:  ") {|q| q.echo = false}
-        password_confirmation = ask("Repeat password:  ") {|q| q.echo = false}
+        password = ask("Password:  ") { |q| q.echo = false }
+        password_confirmation = ask("Repeat password:  ") { |q| q.echo = false }
       end while password != password_confirmation
       admin.password = password
     end
@@ -82,7 +82,7 @@ task "admin:create" => :environment do
   if (grant_admin == "" || grant_admin.downcase == 'y')
     admin.grant_admin!
     admin.change_trust_level!(4)
-    admin.email_tokens.update_all  confirmed: true
+    admin.email_tokens.update_all confirmed: true
     admin.activate
 
     say("\nYour account now has Admin privileges!")
diff --git a/lib/tasks/api.rake b/lib/tasks/api.rake
index ef42e8a7bd4..5a4ef6c85e0 100644
--- a/lib/tasks/api.rake
+++ b/lib/tasks/api.rake
@@ -1,6 +1,6 @@
 desc "generate api key if missing, return existing if already there"
 task "api_key:get" => :environment do
-    api_key = ApiKey.create_master_key
+  api_key = ApiKey.create_master_key
 
     puts api_key.key
 end
diff --git a/lib/tasks/assets.rake b/lib/tasks/assets.rake
index 57235096c16..9029f9cf4b5 100644
--- a/lib/tasks/assets.rake
+++ b/lib/tasks/assets.rake
@@ -71,10 +71,10 @@ def assets_path
   "#{Rails.root}/public/assets"
 end
 
-def compress_node(from,to)
+def compress_node(from, to)
   to_path = "#{assets_path}/#{to}"
   assets = cdn_relative_path("/assets")
-  source_map_root = assets + ((d=File.dirname(from)) == "." ? "" : "/#{d}")
+  source_map_root = assets + ((d = File.dirname(from)) == "." ? "" : "/#{d}")
   source_map_url = cdn_path "/assets/#{to}.map"
 
   cmd = "uglifyjs '#{assets_path}/#{from}' -p relative -c -m -o '#{to_path}' --source-map-root '#{source_map_root}' --source-map '#{assets_path}/#{to}.map' --source-map-url '#{source_map_url}'"
@@ -89,7 +89,7 @@ def compress_node(from,to)
   result
 end
 
-def compress_ruby(from,to)
+def compress_ruby(from, to)
   data = File.read("#{assets_path}/#{from}")
 
   uglified, map = Uglifier.new(comments: :none,
@@ -99,7 +99,7 @@ def compress_ruby(from,to)
                                  output_filename: File.basename(to)
                                }
                               )
-                          .compile_with_map(data)
+    .compile_with_map(data)
   dest = "#{assets_path}/#{to}"
 
   File.write(dest, uglified << "\n//# sourceMappingURL=#{cdn_path "/assets/#{to}.map"}")
@@ -121,11 +121,11 @@ def brotli(path)
   end
 end
 
-def compress(from,to)
+def compress(from, to)
   if $node_uglify
-    compress_node(from,to)
+    compress_node(from, to)
   else
-    compress_ruby(from,to)
+    compress_ruby(from, to)
   end
 end
 
@@ -148,10 +148,10 @@ task 'assets:precompile' => 'assets:precompile:before' do
     concurrent? do |proc|
       to_skip = Rails.configuration.assets.skip_minification || []
       manifest.files
-              .select{|k,v| k =~ /\.js$/}
-              .each do |file, info|
+        .select { |k, v| k =~ /\.js$/ }
+        .each do |file, info|
 
-          path = "#{assets_path}/#{file}"
+        path = "#{assets_path}/#{file}"
           _file = (d = File.dirname(file)) == "." ? "_#{file}" : "#{d}/_#{File.basename(file)}"
           _path = "#{assets_path}/#{_file}"
 
@@ -164,7 +164,7 @@ task 'assets:precompile' => 'assets:precompile:before' do
               # We can specify some files to never minify
               unless (ENV["DONT_MINIFY"] == "1") || to_skip.include?(info['logical_path'])
                 FileUtils.mv(path, _path)
-                compress(_file,file)
+                compress(_file, file)
               end
 
               info["size"] = File.size(path)
diff --git a/lib/tasks/auto_annotate_models.rake b/lib/tasks/auto_annotate_models.rake
index dde0cc03644..617f473c9b6 100644
--- a/lib/tasks/auto_annotate_models.rake
+++ b/lib/tasks/auto_annotate_models.rake
@@ -1,36 +1,34 @@
 # NOTE: only doing this in development as some production environments (Heroku)
 # NOTE: are sensitive to local FS writes, and besides -- it's just not proper
 # NOTE: to have a dev-mode tool do its thing in production.
-if(Rails.env.development? || Rails.env.test?)
+if (Rails.env.development? || Rails.env.test?)
   task :set_annotation_options do
     # You can override any of these by setting an environment variable of the
     # same name.
-    Annotate.set_defaults({
-      'position_in_routes'   => "before",
-      'position_in_class'    => "after",
-      'position_in_test'     => "before",
-      'position_in_fixture'  => "before",
-      'position_in_factory'  => "before",
-      'show_indexes'         => "true",
-      'simple_indexes'       => "false",
-      'model_dir'            => "app/models",
-      'include_version'      => "false",
-      'require'              => "",
-      'exclude_tests'        => "true",
-      'exclude_fixtures'     => "true",
-      'exclude_helpers'      => "true",
-      'exclude_factories'    => "true",
-      'exclude_serializers'  => "true",
-      'exclude_controllers'  => "true",
-      'ignore_model_sub_dir' => "false",
-      'skip_on_db_migrate'   => "true",
-      'format_bare'          => "true",
-      'format_rdoc'          => "false",
-      'format_markdown'      => "false",
-      'sort'                 => "false",
-      'force'                => "false",
-      'trace'                => "false",
-    })
+    Annotate.set_defaults('position_in_routes' => "before",
+                          'position_in_class'    => "after",
+                          'position_in_test'     => "before",
+                          'position_in_fixture'  => "before",
+                          'position_in_factory'  => "before",
+                          'show_indexes'         => "true",
+                          'simple_indexes'       => "false",
+                          'model_dir'            => "app/models",
+                          'include_version'      => "false",
+                          'require'              => "",
+                          'exclude_tests'        => "true",
+                          'exclude_fixtures'     => "true",
+                          'exclude_helpers'      => "true",
+                          'exclude_factories'    => "true",
+                          'exclude_serializers'  => "true",
+                          'exclude_controllers'  => "true",
+                          'ignore_model_sub_dir' => "false",
+                          'skip_on_db_migrate'   => "true",
+                          'format_bare'          => "true",
+                          'format_rdoc'          => "false",
+                          'format_markdown'      => "false",
+                          'sort'                 => "false",
+                          'force'                => "false",
+                          'trace'                => "false")
   end
 
 end
diff --git a/lib/tasks/autospec.rake b/lib/tasks/autospec.rake
index 3df52d0f051..2f1de2c4863 100644
--- a/lib/tasks/autospec.rake
+++ b/lib/tasks/autospec.rake
@@ -6,7 +6,7 @@ desc "Run all specs automatically as needed"
 task "autospec" => :environment do
   require 'autospec/manager'
 
-  debug = ARGV.any?{ |a|  a == "d" || a == "debug" } || ENV["DEBUG"]
+  debug = ARGV.any? { |a|  a == "d" || a == "debug" } || ENV["DEBUG"]
   force_polling = ARGV.any? { |a| a == "p" || a == "polling" }
   latency = ((ARGV.find { |a| a =~ /l=|latency=/ } || "").split("=")[1] || 3).to_i
 
diff --git a/lib/tasks/avatars.rake b/lib/tasks/avatars.rake
index 4c1da8fd54f..5b2df506cf6 100644
--- a/lib/tasks/avatars.rake
+++ b/lib/tasks/avatars.rake
@@ -24,7 +24,7 @@ task "avatars:clean" => :environment do
   OptimizedImage.where("upload_id IN (SELECT custom_upload_id FROM user_avatars) OR
                         upload_id IN (SELECT gravatar_upload_id FROM user_avatars) OR
                         upload_id IN (SELECT uploaded_avatar_id FROM users)")
-                .find_each do |optimized_image|
+    .find_each do |optimized_image|
     optimized_image.destroy!
     putc "." if (i += 1) % 10 == 0
   end
diff --git a/lib/tasks/backfill.thor b/lib/tasks/backfill.thor
index a69a58803d3..44afebbda59 100644
--- a/lib/tasks/backfill.thor
+++ b/lib/tasks/backfill.thor
@@ -1,7 +1,6 @@
 class Backfill < Thor
   desc "link_titles", "Backfills link titles"
 
-
   def link_titles
     require './config/environment'
     topic_links = TopicLink.where(crawled_at: nil, internal: false)
@@ -13,4 +12,3 @@ class Backfill < Thor
     end
   end
 end
-
diff --git a/lib/tasks/build_test_topic.rake b/lib/tasks/build_test_topic.rake
index e135cabc928..7c64a76566e 100644
--- a/lib/tasks/build_test_topic.rake
+++ b/lib/tasks/build_test_topic.rake
@@ -4,7 +4,6 @@ desc 'create pushstate/replacestate test topic'
 task 'build_test_topic' => :environment do
   puts 'Creating topic'
 
-
   # Acceptable options:
   #
   #   raw                     - raw text of post
@@ -33,7 +32,7 @@ task 'build_test_topic' => :environment do
     links = []
     [-30, -10, 10, 30].each do |offset|
       where = (post_number + offset)
-      if where >= 1 and where <= 100
+      if where >= (1) && where <= (100)
         links << "Link to ##{where}: #{topic_url}/#{where}"
       end
     end
diff --git a/lib/tasks/cdn.rake b/lib/tasks/cdn.rake
index c9b793cbf34..0e13c3ae8c7 100644
--- a/lib/tasks/cdn.rake
+++ b/lib/tasks/cdn.rake
@@ -34,7 +34,7 @@ task 'assets:prestage' => :environment do |t|
       "id" => config["id"],
       "login" => config["login"],
       "passwd" => config["password"],
-      "json" => {"prefetch_paths" => asset}.to_json
+      "json" => { "prefetch_paths" => asset }.to_json
     )
 
     response = http.request(request)
@@ -43,7 +43,7 @@ task 'assets:prestage' => :environment do |t|
       failed_assets.push(asset)
     end
   end
-  
+
   if failed_assets.length > 0
     raise "Failed to pre-stage #{failed_assets.length}/#{assets.length} files"
   end
diff --git a/lib/tasks/docker.rake b/lib/tasks/docker.rake
index b6089394478..64a4514ae78 100644
--- a/lib/tasks/docker.rake
+++ b/lib/tasks/docker.rake
@@ -16,7 +16,7 @@
 #                   this can also be set to a branch, e.g. "origin/tests-passed"
 #
 # Example usage:
-#   Run all core and plugin tests:  
+#   Run all core and plugin tests:
 #       docker run discourse/discourse_test:release
 #   Run only rspec tests:
 #       docker run -e RUBY_ONLY=1 discourse/discourse_test:release
@@ -25,7 +25,6 @@
 #   Run tests for a specific plugin (with a plugin mounted from host filesystem):
 #       docker run -e SKIP_CORE=1 SINGLE_PLUGIN='my-awesome-plugin' -v $(pwd)/my-awesome-plugin:/var/www/discourse/plugins/my-awesome-plugin discourse/discourse_test:release
 
-
 def run_or_fail(command)
   pid = Process.spawn(command)
   Process.wait(pid)
@@ -53,7 +52,6 @@ task 'docker:test' do
     puts "Starting postgres"
     @pg_pid = Process.spawn("#{@postgres_bin}postmaster -D tmp/test_data/pg")
 
-
     ENV["RAILS_ENV"] = "test"
 
     @good = run_or_fail("bundle exec rake db:create db:migrate")
diff --git a/lib/tasks/emoji.rake b/lib/tasks/emoji.rake
index a601dbc3c87..5ff933cab7f 100644
--- a/lib/tasks/emoji.rake
+++ b/lib/tasks/emoji.rake
@@ -446,10 +446,10 @@ def generate_emoji_groups(keywords)
       emoji_list_section = title_section.first.parent.parent.next_element
       emoji_list_section.css("a.plain img").each do |link|
         emoji_code = link.attr("title")
-                         .scan(/U\+(.{4,5})\b/)
-                         .flatten
-                         .map { |code| code.downcase.strip }
-                         .join("_")
+          .scan(/U\+(.{4,5})\b/)
+          .flatten
+          .map { |code| code.downcase.strip }
+          .join("_")
 
         emoji_char = code_to_emoji(emoji_code)
 
@@ -489,16 +489,16 @@ def write_db_json(emojis)
   # skin tones variations of emojis shouldn’t appear in autocomplete
   emojis_without_tones = emojis
     .select { |char, config|
-      !FITZPATRICK_SCALE.any? { |scale|
-        codepoints_to_code(char.codepoints, config["fitzpatrick_scale"])[scale]
-      }
-    }
+                           !FITZPATRICK_SCALE.any? { |scale|
+                             codepoints_to_code(char.codepoints, config["fitzpatrick_scale"])[scale]
+                           }
+                         }
     .map { |char, config|
-      {
-        "code" => codepoints_to_code(char.codepoints, config["fitzpatrick_scale"]).tr("_", "-"),
-        "name" => config["name"]
-      }
+    {
+      "code" => codepoints_to_code(char.codepoints, config["fitzpatrick_scale"]).tr("_", "-"),
+      "name" => config["name"]
     }
+  }
 
   emoji_with_tones = emojis
     .select { |code, config| config["fitzpatrick_scale"] }
@@ -532,9 +532,9 @@ end
 
 def codepoints_to_code(codepoints, fitzpatrick_scale)
   codepoints = codepoints
-                .map { |c| c.to_s(16).rjust(4, "0") }
-                .join("_")
-                .downcase
+    .map { |c| c.to_s(16).rjust(4, "0") }
+    .join("_")
+    .downcase
 
   if !fitzpatrick_scale
     codepoints.gsub!(/_fe0f$/, "")
diff --git a/lib/tasks/highlight.rake b/lib/tasks/highlight.rake
index d6baa771fbb..f0e0c2bc209 100644
--- a/lib/tasks/highlight.rake
+++ b/lib/tasks/highlight.rake
@@ -1,7 +1,7 @@
 desc "download latest version of highlight and prepare it"
 task "highlightjs:update" do
 
-  def run(cmd, opts={})
+  def run(cmd, opts = {})
     puts cmd
     system(cmd, opts.merge(out: $stdout, err: :out))
   end
diff --git a/lib/tasks/i18n_stats.rake b/lib/tasks/i18n_stats.rake
index 59884021368..ae48b2e9686 100644
--- a/lib/tasks/i18n_stats.rake
+++ b/lib/tasks/i18n_stats.rake
@@ -9,7 +9,7 @@ task "i18n:stats" => :environment do
 
       # detect pluralizable string
       if (source["other"] != nil)
-        target[namespace] = {pluralizable: true, content: source}
+        target[namespace] = { pluralizable: true, content: source }
         return
       end
 
@@ -36,7 +36,7 @@ task "i18n:stats" => :environment do
     same = []
     total = a.count
 
-    a.each do |key,value|
+    a.each do |key, value|
       if b[key] == nil
         minus << key
       end
@@ -45,13 +45,13 @@ task "i18n:stats" => :environment do
       end
     end
 
-    b.each do |key,value|
+    b.each do |key, value|
       if a[key] == nil
         plus << key
       end
     end
 
-    a.each do |key,value|
+    a.each do |key, value|
       if value.kind_of?(Hash)
         if value[:pluralizable]
           plural_keys.each do |pl|
@@ -61,7 +61,7 @@ task "i18n:stats" => :environment do
           end
 
           if b[key] != nil && b[key].kind_of?(Hash)
-            b[key][:content].each do |pl,val|
+            b[key][:content].each do |pl, val|
               if ! plural_keys.include?(pl)
                 if a[key][:content]["zero"] == nil
                   plus << "#{key}.#{pl}"
@@ -80,11 +80,11 @@ task "i18n:stats" => :environment do
       end
     end
 
-    return plus,minus,same,total
+    return plus, minus, same, total
   end
 
   def get_plurals(locale)
-    I18n.t("i18n.plural.keys", :locale => locale).map { |x| x.to_s }
+    I18n.t("i18n.plural.keys", locale: locale).map { |x| x.to_s }
   end
 
   puts "Discourse Translation Status Script"
diff --git a/lib/tasks/images.rake b/lib/tasks/images.rake
index c754841f05d..b74a7720a9f 100644
--- a/lib/tasks/images.rake
+++ b/lib/tasks/images.rake
@@ -2,7 +2,7 @@ require_dependency "file_helper"
 
 task "images:compress" => :environment do
   images = Dir.glob("#{Rails.root}/app/**/*.png")
-  image_sizes = Hash[*images.map{|i| [i,File.size(i)]}.to_a.flatten]
+  image_sizes = Hash[*images.map { |i| [i, File.size(i)] }.to_a.flatten]
   FileHelper.optimize_images!(images) do |name, optimized|
     if optimized
       new_size = File.size(name)
diff --git a/lib/tasks/import.rake b/lib/tasks/import.rake
index a462631c8c4..a0ec50de6c4 100644
--- a/lib/tasks/import.rake
+++ b/lib/tasks/import.rake
@@ -293,7 +293,6 @@ def update_posts
        AND reply_count <> Y.replies
   SQL
 
-
   # -- TODO: ensure this is how this works!
   # WITH X AS (
   #   SELECT pr.post_id, p.user_id
diff --git a/lib/tasks/integration.rake b/lib/tasks/integration.rake
index 1317eb6b1d8..32e2a8d1e98 100644
--- a/lib/tasks/integration.rake
+++ b/lib/tasks/integration.rake
@@ -38,7 +38,6 @@ task 'integration:create_fixtures' => :environment do
 
 end
 
-
 def fake_xhr(url)
   uri = URI(url)
 
diff --git a/lib/tasks/plugin.rake b/lib/tasks/plugin.rake
index 51c674132f0..56cfb312072 100644
--- a/lib/tasks/plugin.rake
+++ b/lib/tasks/plugin.rake
@@ -49,7 +49,7 @@ task 'plugin:install', :repo do |t, args|
 
   plugin_path = File.expand_path('plugins/' + name)
   if File.directory?(File.expand_path(plugin_path))
-   abort('Plugin directory, ' + plugin_path + ', already exists.')
+    abort('Plugin directory, ' + plugin_path + ', already exists.')
   end
 
   clone_status = system('git clone ' + repo + ' ' + plugin_path)
diff --git a/lib/tasks/posts.rake b/lib/tasks/posts.rake
index 0338f3c9fcc..f7793400401 100644
--- a/lib/tasks/posts.rake
+++ b/lib/tasks/posts.rake
@@ -13,7 +13,7 @@ task 'posts:fix_letter_avatars' => :environment do
   return unless SiteSetting.external_system_avatars_enabled
 
   search = Post.where("user_id <> -1")
-               .where("raw LIKE '%/letter\_avatar/%' OR cooked LIKE '%/letter\_avatar/%'")
+    .where("raw LIKE '%/letter\_avatar/%' OR cooked LIKE '%/letter\_avatar/%'")
 
   rebaked = 0
   total = search.count
@@ -27,7 +27,7 @@ task 'posts:fix_letter_avatars' => :environment do
 end
 
 desc 'Rebake all posts matching string/regex and optionally delay the loop'
-task 'posts:rebake_match', [:pattern, :type, :delay] => [:environment] do |_,args|
+task 'posts:rebake_match', [:pattern, :type, :delay] => [:environment] do |_, args|
   pattern = args[:pattern]
   type = args[:type]
   type = type.downcase if type
@@ -106,7 +106,7 @@ task 'posts:normalize_code' => :environment do
   Post.where("raw like '%
%%'").each do |p|
     normalized = Import::Normalize.normalize_code_blocks(p.raw, lang)
     if normalized != p.raw
-      p.revise(Discourse.system_user, { raw: normalized })
+      p.revise(Discourse.system_user, raw: normalized)
       putc "."
       i += 1
     end
@@ -116,14 +116,14 @@ task 'posts:normalize_code' => :environment do
   puts "#{i} posts normalized!"
 end
 
-def remap_posts(find, replace="")
+def remap_posts(find, replace = "")
   i = 0
   Post.where("raw LIKE ?", "%#{find}%").each do |p|
     new_raw = p.raw.dup
     new_raw = new_raw.gsub!(/#{Regexp.escape(find)}/, replace) || new_raw
 
     if new_raw != p.raw
-      p.revise(Discourse.system_user, { raw: new_raw }, { bypass_bump: true, skip_revision: true })
+      p.revise(Discourse.system_user, { raw: new_raw }, bypass_bump: true, skip_revision: true)
       putc "."
       i += 1
     end
@@ -132,7 +132,7 @@ def remap_posts(find, replace="")
 end
 
 desc 'Remap all posts matching specific string'
-task 'posts:remap', [:find, :replace] => [:environment] do |_,args|
+task 'posts:remap', [:find, :replace] => [:environment] do |_, args|
 
   find = args[:find]
   replace = args[:replace]
@@ -150,7 +150,7 @@ task 'posts:remap', [:find, :replace] => [:environment] do |_,args|
 end
 
 desc 'Delete occurrence of a word/string'
-task 'posts:delete_word', [:find] => [:environment] do |_,args|
+task 'posts:delete_word', [:find] => [:environment] do |_, args|
   require 'highline/import'
 
   find = args[:find]
diff --git a/lib/tasks/qunit.rake b/lib/tasks/qunit.rake
index 715af0ed6ef..a80e443ed4a 100644
--- a/lib/tasks/qunit.rake
+++ b/lib/tasks/qunit.rake
@@ -10,7 +10,7 @@ task "qunit:test", [:timeout, :qunit_path] => :environment do |_, args|
   end
 
   # ensure we have this port available
-  def port_available? port
+  def port_available?(port)
     server = TCPServer.open port
     server.close
     true
@@ -26,9 +26,9 @@ task "qunit:test", [:timeout, :qunit_path] => :environment do |_, args|
 
   unless pid = fork
     Discourse.after_fork
-    Rack::Server.start(:config => "config.ru",
-                       :AccessLog => [],
-                       :Port => port)
+    Rack::Server.start(config: "config.ru",
+                       AccessLog: [],
+                       Port: port)
     exit
   end
 
diff --git a/lib/tasks/release_note.rake b/lib/tasks/release_note.rake
index 54c40e267b1..4023727d45d 100644
--- a/lib/tasks/release_note.rake
+++ b/lib/tasks/release_note.rake
@@ -55,14 +55,14 @@ end
 
 def escape_brackets(line)
   line.gsub("<", "`<")
-      .gsub(">", ">`")
-      .gsub("[", "`[")
-      .gsub("]", "]`")
+    .gsub(">", ">`")
+    .gsub("[", "`[")
+    .gsub("]", "]`")
 end
 
 def split_comments(text)
   text = normalize_terms(text)
-  terms = ["FIX:", "FEATURE:", "UX:", "SECURITY:" ,"PERF:"]
+  terms = ["FIX:", "FEATURE:", "UX:", "SECURITY:" , "PERF:"]
   terms.each do |term|
     text = newlines_at_term(text, term)
   end
@@ -79,7 +79,7 @@ end
 
 def newlines_at_term(text, term)
   if text.include?(term)
-    text = text.split(term).map{ |l| l.strip }.join("\n#{term} ")
+    text = text.split(term).map { |l| l.strip }.join("\n#{term} ")
   end
   text
 end
diff --git a/lib/tasks/scheduler.rake b/lib/tasks/scheduler.rake
index 208d524ee59..d7d1efeb86b 100644
--- a/lib/tasks/scheduler.rake
+++ b/lib/tasks/scheduler.rake
@@ -1,21 +1,21 @@
 desc "This task is called by the Heroku scheduler add-on"
 
 # Every day at 6am
-task :enqueue_digest_emails => :environment do
+task enqueue_digest_emails: :environment do
   Jobs::EnqueueDigestEmails.new.execute(nil)
 end
 
 # Every day at 4am
-task :category_stats => :environment do
+task category_stats: :environment do
   Jobs::CategoryStats.new.execute(nil)
 end
 
 # Every 10 minutes
-task :periodical_updates => :environment do
+task periodical_updates: :environment do
   Jobs::PeriodicalUpdates.new.execute(nil)
 end
 
 # Every day
-task :version_check => :environment do
+task version_check: :environment do
   Jobs::VersionCheck.new.execute(nil)
-end
\ No newline at end of file
+end
diff --git a/lib/tasks/search.rake b/lib/tasks/search.rake
index c944812d793..ef84747cce4 100644
--- a/lib/tasks/search.rake
+++ b/lib/tasks/search.rake
@@ -2,7 +2,7 @@ task "search:reindex" => :environment do
   ENV['RAILS_DB'] ? reindex_search : reindex_search_all_sites
 end
 
-def reindex_search(db=RailsMultisite::ConnectionManagement.current_db)
+def reindex_search(db = RailsMultisite::ConnectionManagement.current_db)
   puts "Reindexing '#{db}'"
   puts ""
   puts "Posts:"
diff --git a/lib/tasks/typepad.thor b/lib/tasks/typepad.thor
index 26613f89b61..7db75d415ed 100644
--- a/lib/tasks/typepad.thor
+++ b/lib/tasks/typepad.thor
@@ -45,7 +45,7 @@ class Typepad < Thor
       end
     end
 
-    entries.each_with_index do |e,i|
+    entries.each_with_index do |e, i|
       if e[:title] =~ /Head/
         puts "#{i}: #{e[:title]}"
       end
@@ -56,7 +56,7 @@ class Typepad < Thor
 
     puts "Importing #{entries.size} entries"
     entries.each_with_index do |entry, idx|
-      puts "Importing (#{idx+1}/#{entries.size})"
+      puts "Importing (#{idx + 1}/#{entries.size})"
       next if entry[:body].blank?
 
       puts entry[:unique_url]
@@ -219,7 +219,7 @@ class Typepad < Thor
                 current << c
               end
             end
-            segments.delete_if {|s| s.nil? || s.size < 2}
+            segments.delete_if { |s| s.nil? || s.size < 2 }
             segments << current
 
             comment[:author] = segments[0]
diff --git a/lib/tasks/uploads.rake b/lib/tasks/uploads.rake
index e8c5dc67b29..9da415dba0b 100644
--- a/lib/tasks/uploads.rake
+++ b/lib/tasks/uploads.rake
@@ -27,8 +27,8 @@ def gather_uploads
   puts "", "Gathering uploads for '#{current_db}'...", ""
 
   Upload.where("url ~ '^\/uploads\/'")
-        .where("url !~ '^\/uploads\/#{current_db}'")
-        .find_each do |upload|
+    .where("url !~ '^\/uploads\/#{current_db}'")
+    .find_each do |upload|
     begin
       old_db = upload.url[/^\/uploads\/([^\/]+)\//, 1]
       from = upload.url.dup
@@ -100,7 +100,7 @@ def guess_filename(url, raw)
     filename ||= File.basename(url)
     filename
   rescue
-      nil
+    nil
   ensure
     f.try(:close!) rescue nil
   end
@@ -203,8 +203,8 @@ def migrate_to_s3
 
   # Migrate all uploads
   Upload.where.not(sha1: nil)
-        .where("url NOT LIKE '#{s3.absolute_base_url}%'")
-        .find_each do |upload|
+    .where("url NOT LIKE '#{s3.absolute_base_url}%'")
+    .find_each do |upload|
     # remove invalid uploads
     if upload.url.blank?
       upload.destroy!
@@ -215,7 +215,7 @@ def migrate_to_s3
     # retrieve the path to the local file
     path = local.path_for(upload)
     # make sure the file exists locally
-    if !path or !File.exists?(path)
+    if !path || !File.exists?(path)
       putc "X"
       next
     end
diff --git a/lib/tasks/user_actions.rake b/lib/tasks/user_actions.rake
index ffba1f2b228..f457454978e 100644
--- a/lib/tasks/user_actions.rake
+++ b/lib/tasks/user_actions.rake
@@ -2,9 +2,9 @@ desc "rebuild the user_actions table"
 task "user_actions:rebuild" => :environment do
   MessageBus.off
   UserAction.delete_all
-  PostAction.all.each{|i| UserActionCreator.log_post_action(i)}
-  Topic.all.each {|i| UserActionCreator.log_topic(i)}
-  Post.all.each {|i| UserActionCreator.log_post(i)}
+  PostAction.all.each { |i| UserActionCreator.log_post_action(i) }
+  Topic.all.each { |i| UserActionCreator.log_topic(i) }
+  Post.all.each { |i| UserActionCreator.log_post(i) }
   Notification.all.each do |notification|
     UserActionCreator.log_notification(notification.post,
                                        notification.user,
@@ -12,4 +12,3 @@ task "user_actions:rebuild" => :environment do
                                        notification.user)
   end
 end
-
diff --git a/lib/tasks/users.rake b/lib/tasks/users.rake
index 7772bba6600..d01d30b744b 100644
--- a/lib/tasks/users.rake
+++ b/lib/tasks/users.rake
@@ -1,5 +1,5 @@
 desc "Change topic/post ownership of all the topics/posts by a specific user (without creating new revision)"
-task "users:change_post_ownership", [:old_username, :new_username, :archetype] => [:environment] do |_,args|
+task "users:change_post_ownership", [:old_username, :new_username, :archetype] => [:environment] do |_, args|
   old_username = args[:old_username]
   new_username = args[:new_username]
   archetype = args[:archetype]
diff --git a/lib/text_sentinel.rb b/lib/text_sentinel.rb
index e86a897b67c..fa88e647f96 100644
--- a/lib/text_sentinel.rb
+++ b/lib/text_sentinel.rb
@@ -11,12 +11,12 @@ class TextSentinel
 
   ENTROPY_SCALE ||= 0.7
 
-  def initialize(text, opts=nil)
+  def initialize(text, opts = nil)
     @opts = opts || {}
     @text = text.to_s.encode('UTF-8', invalid: :replace, undef: :replace, replace: '')
   end
 
-  def self.body_sentinel(text, opts={})
+  def self.body_sentinel(text, opts = {})
     entropy = SiteSetting.body_min_entropy
     if opts[:private_message]
       scale_entropy = SiteSetting.min_private_message_post_length.to_f / SiteSetting.min_post_length.to_f
@@ -41,7 +41,7 @@ class TextSentinel
   # Non-ASCII characters are weighted heavier since they contain more "information"
   def entropy
     chars = @text.to_s.strip.split('')
-    @entropy ||= chars.pack('M*'*chars.size).gsub("\n",'').split('=').uniq.size
+    @entropy ||= chars.pack('M*' * chars.size).gsub("\n", '').split('=').uniq.size
   end
 
   def valid?
@@ -74,7 +74,6 @@ class TextSentinel
     @opts[:max_word_length].blank? || @text.split(/\s|\/|-|\.|:/).map(&:size).max <= @opts[:max_word_length]
   end
 
-
   def seems_quiet?
     # We don't allow all upper case content
     SiteSetting.allow_uppercase_posts || @text == @text.mb_chars.downcase.to_s || @text != @text.mb_chars.upcase.to_s
diff --git a/lib/timeline_lookup.rb b/lib/timeline_lookup.rb
index 1c62d879f52..90d4a5e02a6 100644
--- a/lib/timeline_lookup.rb
+++ b/lib/timeline_lookup.rb
@@ -2,7 +2,7 @@ module TimelineLookup
 
   # Given an array of tuples (id, post_number, days_ago), return at most `max_values` worth of a
   # lookup table to help the front end timeline display dates associated with posts
-  def self.build(tuples, max_values=300)
+  def self.build(tuples, max_values = 300)
     result = []
 
     every = (tuples.size.to_f / max_values).ceil
@@ -14,7 +14,7 @@ module TimelineLookup
       days_ago = t[2]
 
       if (days_ago != last_days_ago)
-        result << [idx+1, days_ago]
+        result << [idx + 1, days_ago]
         last_days_ago = days_ago
       end
 
diff --git a/lib/topic_creator.rb b/lib/topic_creator.rb
index ecd35fd116b..885f4f26053 100644
--- a/lib/topic_creator.rb
+++ b/lib/topic_creator.rb
@@ -80,13 +80,16 @@ class TopicCreator
     topic.topic_allowed_groups(true).each do |tag|
       tag.group.group_users.each do |gu|
         next if gu.user_id == -1 || gu.user_id == topic.user_id
-        action = case gu.notification_level
-                 when TopicUser.notification_levels[:tracking] then "track!"
-                 when TopicUser.notification_levels[:regular]  then "regular!"
-                 when TopicUser.notification_levels[:muted]    then "mute!"
-                 when TopicUser.notification_levels[:watching] then "watch!"
-                 else "track!"
-                 end
+
+        action =
+          case gu.notification_level
+          when TopicUser.notification_levels[:tracking] then "track!"
+          when TopicUser.notification_levels[:regular]  then "regular!"
+          when TopicUser.notification_levels[:muted]    then "mute!"
+          when TopicUser.notification_levels[:watching] then "watch!"
+          else "track!"
+          end
+
         topic.notifier.send(action, gu.user_id)
       end
     end
@@ -152,7 +155,7 @@ class TopicCreator
   def setup_auto_close_time(topic)
     return unless @opts[:auto_close_time].present?
     return unless @guardian.can_moderate?(topic)
-    topic.set_auto_close(@opts[:auto_close_time], {by_user: @user})
+    topic.set_auto_close(@opts[:auto_close_time], by_user: @user)
   end
 
   def process_private_message(topic)
@@ -163,8 +166,8 @@ class TopicCreator
       rollback_with!(topic, :no_user_selected)
     end
 
-    add_users(topic,@opts[:target_usernames])
-    add_groups(topic,@opts[:target_group_names])
+    add_users(topic, @opts[:target_usernames])
+    add_groups(topic, @opts[:target_group_names])
     topic.topic_allowed_users.build(user_id: @user.id)
   end
 
diff --git a/lib/topic_list_responder.rb b/lib/topic_list_responder.rb
index 05133300855..b53380345f6 100644
--- a/lib/topic_list_responder.rb
+++ b/lib/topic_list_responder.rb
@@ -21,4 +21,3 @@ module TopicListResponder
   end
 
 end
-
diff --git a/lib/topic_query.rb b/lib/topic_query.rb
index 51deb6654fa..934c3e84ef0 100644
--- a/lib/topic_query.rb
+++ b/lib/topic_query.rb
@@ -46,7 +46,6 @@ class TopicQuery
          no_definitions)
   end
 
-
   # Maps `order` to a columns in `topics`
   SORTABLE_MAPPING = {
     'likes' => 'like_count',
@@ -80,21 +79,21 @@ class TopicQuery
 
   def self.apply_custom_filters(results, topic_query)
     if @custom_filters
-      @custom_filters.each do |key,filter|
+      @custom_filters.each do |key, filter|
         results = filter.call(results, topic_query)
       end
     end
     results
   end
 
-  def initialize(user=nil, options={})
+  def initialize(user = nil, options = {})
     options.assert_valid_keys(TopicQuery.valid_options)
     @options = options.dup
     @user = user
     @guardian = Guardian.new(@user)
   end
 
-  def joined_topic_user(list=nil)
+  def joined_topic_user(list = nil)
     (list || Topic).joins("LEFT OUTER JOIN topic_users AS tu ON (topics.id = tu.topic_id AND tu.user_id = #{@user.id.to_i})")
   end
 
@@ -108,8 +107,8 @@ class TopicQuery
       if topic.private_message?
 
         group_ids = topic.topic_allowed_groups
-                      .where('group_id IN (SELECT group_id FROM group_users WHERE user_id = :user_id)', user_id: @user.id)
-                      .pluck(:group_id)
+          .where('group_id IN (SELECT group_id FROM group_users WHERE user_id = :user_id)', user_id: @user.id)
+          .pluck(:group_id)
         {
           topic: topic,
           my_group_ids: group_ids,
@@ -151,7 +150,7 @@ class TopicQuery
       builder.add_results(random_suggested(topic, builder.results_left, builder.excluded_topic_ids)) unless builder.full?
     end
 
-    params = {unordered: true}
+    params = { unordered: true }
     if topic.private_message?
       params[:preload_posters] = true
     end
@@ -170,19 +169,19 @@ class TopicQuery
   end
 
   def list_new
-    create_list(:new, {unordered: true}, new_results)
+    create_list(:new, { unordered: true }, new_results)
   end
 
   def list_unread
-    create_list(:unread, {unordered: true}, unread_results)
+    create_list(:unread, { unordered: true }, unread_results)
   end
 
   def list_posted
-    create_list(:posted) {|l| l.where('tu.posted') }
+    create_list(:posted) { |l| l.where('tu.posted') }
   end
 
   def list_bookmarks
-    create_list(:bookmarks) {|l| l.where('tu.bookmarked') }
+    create_list(:bookmarks) { |l| l.where('tu.bookmarked') }
   end
 
   def list_top_for(period)
@@ -207,14 +206,14 @@ class TopicQuery
   def not_archived(list, user)
     list.joins("LEFT JOIN user_archived_messages um
                        ON um.user_id = #{user.id.to_i} AND um.topic_id = topics.id")
-               .where('um.user_id IS NULL')
+      .where('um.user_id IS NULL')
   end
 
   def list_private_messages(user)
     list = private_messages_for(user, :user)
 
     list = not_archived(list, user)
-            .where('NOT (topics.participant_count = 1 AND topics.user_id = ?)', user.id)
+      .where('NOT (topics.participant_count = 1 AND topics.user_id = ?)', user.id)
 
     create_list(:private_messages, {}, list)
   end
@@ -262,8 +261,8 @@ class TopicQuery
   def list_category_topic_ids(category)
     query = default_results(category: category.id)
     pinned_ids = query.where('pinned_at IS NOT NULL AND category_id = ?', category.id)
-                      .limit(nil)
-                      .order('pinned_at DESC').pluck(:id)
+      .limit(nil)
+      .order('pinned_at DESC').pluck(:id)
     non_pinned_ids = query.where('pinned_at IS NULL OR category_id <> ?', category.id).pluck(:id)
     (pinned_ids + non_pinned_ids)
   end
@@ -276,8 +275,8 @@ class TopicQuery
 
   def self.new_filter(list, treat_as_new_topic_start_date)
     list.where("topics.created_at >= :created_at", created_at: treat_as_new_topic_start_date)
-        .where("tu.last_read_post_number IS NULL")
-        .where("COALESCE(tu.notification_level, :tracking) >= :tracking", tracking: TopicUser.notification_levels[:tracking])
+      .where("tu.last_read_post_number IS NULL")
+      .where("COALESCE(tu.notification_level, :tracking) >= :tracking", tracking: TopicUser.notification_levels[:tracking])
   end
 
   def self.unread_filter(list, user_id, opts)
@@ -293,8 +292,8 @@ class TopicQuery
     col_name = opts[:staff] ? "highest_staff_post_number" : "highest_post_number"
 
     list
-        .where("tu.last_read_post_number < topics.#{col_name}")
-        .where("COALESCE(tu.notification_level, :regular) >= :tracking",
+      .where("tu.last_read_post_number < topics.#{col_name}")
+      .where("COALESCE(tu.notification_level, :regular) >= :tracking",
                regular: TopicUser.notification_levels[:regular], tracking: TopicUser.notification_levels[:tracking])
   end
 
@@ -322,12 +321,12 @@ class TopicQuery
 
   end
 
-  def create_list(filter, options={}, topics = nil)
+  def create_list(filter, options = {}, topics = nil)
     topics ||= default_results(options)
     topics = yield(topics) if block_given?
 
     options = options.merge(@options)
-    if ["activity","default"].include?(options[:order] || "activity") &&
+    if ["activity", "default"].include?(options[:order] || "activity") &&
         !options[:unordered] &&
         filter != :private_messages
       topics = prioritize_pinned_topics(topics, options)
@@ -348,7 +347,7 @@ class TopicQuery
     end
 
     topics.each do |t|
-      t.allowed_user_ids = filter == :private_messages ? t.allowed_users.map{|u| u.id} : []
+      t.allowed_user_ids = filter == :private_messages ? t.allowed_users.map { |u| u.id } : []
     end
 
     list = TopicList.new(filter, @user, topics, options.merge(@options))
@@ -356,7 +355,7 @@ class TopicQuery
     list
   end
 
-  def latest_results(options={})
+  def latest_results(options = {})
     result = default_results(options)
     result = remove_muted_topics(result, @user) unless options && options[:state] == "muted".freeze
     result = remove_muted_categories(result, @user, exclude: options[:category])
@@ -370,12 +369,12 @@ class TopicQuery
     result
   end
 
-  def unread_results(options={})
+  def unread_results(options = {})
     result = TopicQuery.unread_filter(
-        default_results(options.reverse_merge(:unordered => true)),
+        default_results(options.reverse_merge(unordered: true)),
         @user&.id,
         staff: @user&.staff?)
-    .order('CASE WHEN topics.user_id = tu.user_id THEN 1 ELSE 2 END')
+      .order('CASE WHEN topics.user_id = tu.user_id THEN 1 ELSE 2 END')
 
     self.class.results_filter_callbacks.each do |filter_callback|
       result = filter_callback.call(:unread, result, @user, options)
@@ -384,10 +383,10 @@ class TopicQuery
     suggested_ordering(result, options)
   end
 
-  def new_results(options={})
+  def new_results(options = {})
     # TODO does this make sense or should it be ordered on created_at
     #  it is ordering on bumped_at now
-    result = TopicQuery.new_filter(default_results(options.reverse_merge(:unordered => true)), @user.user_option.treat_as_new_topic_start_date)
+    result = TopicQuery.new_filter(default_results(options.reverse_merge(unordered: true)), @user.user_option.treat_as_new_topic_start_date)
     result = remove_muted_topics(result, @user)
     result = remove_muted_categories(result, @user, exclude: options[:category])
     result = remove_muted_tags(result, @user, options)
@@ -436,8 +435,8 @@ class TopicQuery
       end
 
       result = result.joins("LEFT OUTER JOIN topic_users AS tu ON (topics.id = tu.topic_id AND tu.user_id = #{user.id.to_i})")
-                     .order("topics.bumped_at DESC")
-                     .private_messages
+        .order("topics.bumped_at DESC")
+        .private_messages
 
       result = result.limit(options[:per_page]) unless options[:limit] == false
       result = result.visible if options[:visible] || @user.nil? || @user.regular?
@@ -489,9 +488,8 @@ class TopicQuery
       category_id
     end
 
-
     # Create results based on a bunch of default options
-    def default_results(options={})
+    def default_results(options = {})
       options.reverse_merge!(@options)
       options.reverse_merge!(per_page: per_page_setting)
 
@@ -504,7 +502,7 @@ class TopicQuery
 
       if @user
         result = result.joins("LEFT OUTER JOIN topic_users AS tu ON (topics.id = tu.topic_id AND tu.user_id = #{@user.id.to_i})")
-                       .references('tu')
+          .references('tu')
       end
 
       category_id = get_category_id(options[:category])
@@ -559,7 +557,7 @@ class TopicQuery
           end
         elsif @options[:no_tags]
           # the following will do: ("topics"."id" NOT IN (SELECT DISTINCT "topic_tags"."topic_id" FROM "topic_tags"))
-          result = result.where.not(:id => TopicTag.select(:topic_id).uniq)
+          result = result.where.not(id: TopicTag.select(:topic_id).uniq)
         end
       end
 
@@ -578,7 +576,7 @@ class TopicQuery
       result = result.limit(options[:per_page]) unless options[:limit] == false
 
       result = result.visible if options[:visible]
-      result = result.where.not(topics: {id: options[:except_topic_ids]}).references(:topics) if options[:except_topic_ids]
+      result = result.where.not(topics: { id: options[:except_topic_ids] }).references(:topics) if options[:except_topic_ids]
 
       if options[:page]
         offset = options[:page].to_i * options[:per_page]
@@ -641,7 +639,7 @@ class TopicQuery
         end
       end
 
-      if (filter=options[:filter]) && @user
+      if (filter = options[:filter]) && @user
         action =
           if filter == "bookmarked"
             PostActionType.types[:bookmark]
@@ -665,7 +663,7 @@ class TopicQuery
       result = result.where('topics.posts_count <= ?', options[:max_posts]) if options[:max_posts].present?
       result = result.where('topics.posts_count >= ?', options[:min_posts]) if options[:min_posts].present?
 
-      result = TopicQuery.apply_custom_filters(result,self)
+      result = TopicQuery.apply_custom_filters(result, self)
 
       @guardian.filter_allowed_categories(result)
     end
@@ -677,12 +675,12 @@ class TopicQuery
 
       list
     end
-    def remove_muted_categories(list, user, opts=nil)
+    def remove_muted_categories(list, user, opts = nil)
       category_id = get_category_id(opts[:exclude]) if opts
 
       if user
         list = list.references("cu")
-                   .where("
+          .where("
           NOT EXISTS (
             SELECT 1
               FROM category_users cu
@@ -699,7 +697,7 @@ class TopicQuery
 
       list
     end
-    def remove_muted_tags(list, user, opts=nil)
+    def remove_muted_tags(list, user, opts = nil)
       if user.nil? || !SiteSetting.tagging_enabled || !SiteSetting.remove_muted_tags_from_latest
         list
       else
@@ -732,7 +730,7 @@ class TopicQuery
     def new_messages(params)
 
       TopicQuery.new_filter(messages_for_groups_or_user(params[:my_group_ids]), Time.at(SiteSetting.min_new_topics_time).to_datetime)
-                .limit(params[:count])
+        .limit(params[:count])
 
     end
 
@@ -741,7 +739,7 @@ class TopicQuery
         messages_for_groups_or_user(params[:my_group_ids]),
         @user&.id,
         staff: @user&.staff?)
-                .limit(params[:count])
+        .limit(params[:count])
     end
 
     def related_messages_user(params)
@@ -811,7 +809,7 @@ class TopicQuery
       query.order('topics.bumped_at DESC')
     end
 
-    def random_suggested(topic, count, excluded_topic_ids=[])
+    def random_suggested(topic, count, excluded_topic_ids = [])
       result = default_results(unordered: true, per_page: count).where(closed: false, archived: false)
       excluded_topic_ids += Category.topic_ids.to_a
       result = result.where("topics.id NOT IN (?)", excluded_topic_ids) unless excluded_topic_ids.empty?
@@ -829,7 +827,7 @@ class TopicQuery
       # of muted, big edge case
       #
       # we over select in case cache is stale
-      max = (count*1.3).to_i
+      max = (count * 1.3).to_i
       ids = RandomTopicSelector.next(max) + RandomTopicSelector.next(max, topic.category)
 
       result.where(id: ids.uniq)
diff --git a/lib/topic_retriever.rb b/lib/topic_retriever.rb
index 672ca60a696..82f815d9f7c 100644
--- a/lib/topic_retriever.rb
+++ b/lib/topic_retriever.rb
@@ -1,6 +1,6 @@
 class TopicRetriever
 
-  def initialize(embed_url, opts=nil)
+  def initialize(embed_url, opts = nil)
     @embed_url = embed_url
     @author_username = opts[:author_username]
     @opts = opts || {}
@@ -34,7 +34,6 @@ class TopicRetriever
       # It's possible another process or job found the embed already. So if that happened bail out.
       return if TopicEmbed.where(embed_url: @embed_url).exists?
 
-
       # First check RSS if that is enabled
       if SiteSetting.feed_polling_enabled?
         Jobs::PollFeed.new.execute({})
diff --git a/lib/topic_subtype.rb b/lib/topic_subtype.rb
index 0d8224c4e45..731ed29c3e0 100644
--- a/lib/topic_subtype.rb
+++ b/lib/topic_subtype.rb
@@ -9,7 +9,7 @@ class TopicSubtype
   end
 
   def attributes
-    {'id' => @id, 'options' => @options }
+    { 'id' => @id, 'options' => @options }
   end
 
   def self.list
@@ -41,7 +41,7 @@ class TopicSubtype
     'pending_users'
   end
 
-  def self.register(name, options={})
+  def self.register(name, options = {})
     @subtypes ||= {}
     @subtypes[name] = TopicSubtype.new(name, options)
   end
diff --git a/lib/topic_view.rb b/lib/topic_view.rb
index 482853d71e8..d631a331353 100644
--- a/lib/topic_view.rb
+++ b/lib/topic_view.rb
@@ -37,7 +37,7 @@ class TopicView
     wpcf.flatten.uniq
   end
 
-  def initialize(topic_id, user=nil, options={})
+  def initialize(topic_id, user = nil, options = {})
     @message_bus_last_id = MessageBus.last_id("/topic/#{topic_id}")
     @user = user
     @guardian = Guardian.new(@user)
@@ -50,11 +50,13 @@ class TopicView
     end
 
     @page = 1 if (!@page || @page.zero?)
-    @chunk_size = case
-                    when options[:slow_platform] then TopicView.slow_chunk_size
-                    when @print then TopicView.print_chunk_size
-                    else TopicView.chunk_size
-                  end
+    @chunk_size =
+      case
+      when options[:slow_platform] then TopicView.slow_chunk_size
+      when @print then TopicView.print_chunk_size
+      else TopicView.chunk_size
+      end
+
     @limit ||= @chunk_size
 
     setup_filtered_posts
@@ -82,12 +84,15 @@ class TopicView
 
   def canonical_path
     path = relative_url
-    path << if @post_number
-      page = ((@post_number.to_i - 1) / @limit) + 1
-      (page > 1) ? "?page=#{page}" : ""
-    else
-      (@page && @page.to_i > 1) ? "?page=#{@page}" : ""
-    end
+
+    path <<
+      if @post_number
+        page = ((@post_number.to_i - 1) / @limit) + 1
+        (page > 1) ? "?page=#{page}" : ""
+      else
+        (@page && @page.to_i > 1) ? "?page=#{@page}" : ""
+      end
+
     path
   end
 
@@ -161,7 +166,7 @@ class TopicView
     return @desired_post if @desired_post.present?
     return nil if posts.blank?
 
-    @desired_post = posts.detect {|p| p.post_number == @post_number.to_i}
+    @desired_post = posts.detect { |p| p.post_number == @post_number.to_i }
     @desired_post ||= posts.first
     @desired_post
   end
@@ -175,7 +180,7 @@ class TopicView
 
   def read_time
     return nil if @post_number.present? && @post_number.to_i != 1 # only show for topic URLs
-    (@topic.word_count/SiteSetting.read_time_word_count).floor if @topic.word_count
+    (@topic.word_count / SiteSetting.read_time_word_count).floor if @topic.word_count
   end
 
   def like_count
@@ -235,7 +240,6 @@ class TopicView
     filter_posts_in_range(min_idx, max_idx)
   end
 
-
   def filter_posts_paged(page)
     page = [page, 1].max
     min = @limit * (page - 1)
@@ -248,7 +252,7 @@ class TopicView
     filter_posts_in_range(min, max)
   end
 
-  def filter_best(max, opts={})
+  def filter_best(max, opts = {})
     filter = FilterBestPosts.new(@topic, @filtered_posts, max, opts)
     @posts = filter.posts
     @filtered_posts = filter.filtered_posts
@@ -261,9 +265,9 @@ class TopicView
 
   def has_deleted?
     @predelete_filtered_posts.with_deleted
-                             .where("posts.deleted_at IS NOT NULL")
-                             .where("posts.post_number > 1")
-                             .exists?
+      .where("posts.deleted_at IS NOT NULL")
+      .where("posts.post_number > 1")
+      .exists?
   end
 
   def topic_user
@@ -275,17 +279,17 @@ class TopicView
 
   def post_counts_by_user
     @post_counts_by_user ||= Post.where(topic_id: @topic.id)
-                                 .where("user_id IS NOT NULL")
-                                 .group(:user_id)
-                                 .order("count_all DESC")
-                                 .limit(24)
-                                 .count
+      .where("user_id IS NOT NULL")
+      .group(:user_id)
+      .order("count_all DESC")
+      .limit(24)
+      .count
   end
 
   def participants
     @participants ||= begin
       participants = {}
-      User.where(id: post_counts_by_user.map {|k,v| k}).includes(:primary_group).each {|u| participants[u.id] = u}
+      User.where(id: post_counts_by_user.map { |k, v| k }).includes(:primary_group).each { |u| participants[u.id] = u }
       participants
     end
   end
@@ -303,7 +307,7 @@ class TopicView
   end
 
   def link_counts
-    @link_counts ||= TopicLink.counts_for(guardian,@topic, posts)
+    @link_counts ||= TopicLink.counts_for(guardian, @topic, posts)
   end
 
   # Are we the initial page load? If so, we can return extra information like
@@ -331,7 +335,7 @@ class TopicView
 
   def current_post_ids
     @current_post_ids ||= if @posts.is_a?(Array)
-      @posts.map {|p| p.id }
+      @posts.map { |p| p.id }
     else
       @posts.pluck(:post_number)
     end
@@ -341,13 +345,13 @@ class TopicView
   # calculations.
   def filtered_post_stream
     @filtered_post_stream ||= @filtered_posts.order(:sort_order)
-                                             .pluck(:id,
+      .pluck(:id,
                                                     :post_number,
                                                     'EXTRACT(DAYS FROM CURRENT_TIMESTAMP - created_at)::INT AS days_ago')
   end
 
   def filtered_post_ids
-    @filtered_post_ids ||= filtered_post_stream.map {|tuple| tuple[0]}
+    @filtered_post_ids ||= filtered_post_stream.map { |tuple| tuple[0] }
   end
 
   protected
@@ -359,11 +363,11 @@ class TopicView
       return result unless topic_user.present?
 
       post_numbers = PostTiming
-                .where(topic_id: @topic.id, user_id: @user.id)
-                .where(post_number: current_post_ids)
-                .pluck(:post_number)
+        .where(topic_id: @topic.id, user_id: @user.id)
+        .where(post_number: current_post_ids)
+        .pluck(:post_number)
 
-      post_numbers.each {|pn| result << pn}
+      post_numbers.each { |pn| result << pn }
       result
     end
   end
@@ -383,8 +387,8 @@ class TopicView
   def filter_posts_by_ids(post_ids)
     # TODO: Sort might be off
     @posts = Post.where(id: post_ids, topic_id: @topic.id)
-                 .includes(:user, :reply_to_user, :incoming_email)
-                 .order('sort_order')
+      .includes(:user, :reply_to_user, :incoming_email)
+      .order('sort_order')
     @posts = filter_post_types(@posts)
     @posts = @posts.with_deleted if @guardian.can_see_deleted_posts?
     @posts
@@ -435,7 +439,7 @@ class TopicView
 
     # Username filters
     if @username_filters.present?
-      usernames = @username_filters.map{|u| u.downcase}
+      usernames = @username_filters.map { |u| u.downcase }
       @filtered_posts = @filtered_posts.where('post_number = 1 OR posts.user_id IN (SELECT u.id FROM users u WHERE username_lower IN (?))', usernames)
       @contains_gaps = true
     end
diff --git a/lib/topics_bulk_action.rb b/lib/topics_bulk_action.rb
index 5e4d8d9f75d..1af2db62a2e 100644
--- a/lib/topics_bulk_action.rb
+++ b/lib/topics_bulk_action.rb
@@ -1,6 +1,6 @@
 class TopicsBulkAction
 
-  def initialize(user, topic_ids, operation, options={})
+  def initialize(user, topic_ids, operation, options = {})
     @user = user
     @topic_ids = topic_ids
     @operation = operation
@@ -45,7 +45,7 @@ class TopicsBulkAction
           if group
             GroupArchivedMessage.move_to_inbox!(group.id, t.id)
           else
-            UserArchivedMessage.move_to_inbox!(@user.id,t.id)
+            UserArchivedMessage.move_to_inbox!(@user.id, t.id)
           end
         end
       end
@@ -177,6 +177,4 @@ class TopicsBulkAction
       @topics ||= Topic.where(id: @topic_ids)
     end
 
-
 end
-
diff --git a/lib/twitter_api.rb b/lib/twitter_api.rb
index 2c9ce48a601..da281fe05fe 100644
--- a/lib/twitter_api.rb
+++ b/lib/twitter_api.rb
@@ -5,7 +5,7 @@ class TwitterApi
 
     def prettify_tweet(tweet)
       text = tweet["full_text"].dup
-      if entities = tweet["entities"] and urls = entities["urls"]
+      if (entities = tweet["entities"]) && (urls = entities["urls"])
         urls.each do |url|
           text.gsub!(url["url"], "#{url["display_url"]}")
         end
@@ -125,7 +125,6 @@ class TwitterApi
       URI.parse "#{BASE_URL}/oauth2/token"
     end
 
-
     def http(uri)
       Net::HTTP.new(uri.host, uri.port).tap { |http| http.use_ssl = true }
     end
diff --git a/lib/unread.rb b/lib/unread.rb
index f04ffcd2289..36a7d09e816 100644
--- a/lib/unread.rb
+++ b/lib/unread.rb
@@ -8,10 +8,9 @@ class Unread
     @topic_user = topic_user
   end
 
-
   def unread_posts
     return 0 if do_not_notify?(@topic_user.notification_level)
-    result = ((@topic_user.highest_seen_post_number||0) - (@topic_user.last_read_post_number||0))
+    result = ((@topic_user.highest_seen_post_number || 0) - (@topic_user.last_read_post_number || 0))
     result = 0 if result < 0
     result
   end
@@ -22,7 +21,7 @@ class Unread
 
     highest_post_number = @guardian.is_staff? ? @topic.highest_staff_post_number : @topic.highest_post_number
 
-    return 0 if (@topic_user.last_read_post_number||0) > highest_post_number
+    return 0 if (@topic_user.last_read_post_number || 0) > highest_post_number
 
     new_posts = (highest_post_number - @topic_user.highest_seen_post_number)
     new_posts = 0 if new_posts < 0
diff --git a/lib/validators/allow_user_locale_enabled_validator.rb b/lib/validators/allow_user_locale_enabled_validator.rb
index ebae4be4509..73d3cb5c51b 100644
--- a/lib/validators/allow_user_locale_enabled_validator.rb
+++ b/lib/validators/allow_user_locale_enabled_validator.rb
@@ -1,6 +1,6 @@
 class AllowUserLocaleEnabledValidator
 
-  def initialize(opts={})
+  def initialize(opts = {})
     @opts = opts
   end
 
@@ -15,4 +15,4 @@ class AllowUserLocaleEnabledValidator
     I18n.t("site_settings.errors.user_locale_not_enabled");
   end
 
-end
\ No newline at end of file
+end
diff --git a/lib/validators/alternative_reply_by_email_addresses_validator.rb b/lib/validators/alternative_reply_by_email_addresses_validator.rb
index d35dedf7c3a..412059ce86e 100644
--- a/lib/validators/alternative_reply_by_email_addresses_validator.rb
+++ b/lib/validators/alternative_reply_by_email_addresses_validator.rb
@@ -1,5 +1,5 @@
 class AlternativeReplyByEmailAddressesValidator
-  def initialize(opts={})
+  def initialize(opts = {})
     @opts = opts
   end
 
diff --git a/lib/validators/email_setting_validator.rb b/lib/validators/email_setting_validator.rb
index e9fb583167b..e44725396d3 100644
--- a/lib/validators/email_setting_validator.rb
+++ b/lib/validators/email_setting_validator.rb
@@ -1,5 +1,5 @@
 class EmailSettingValidator
-  def initialize(opts={})
+  def initialize(opts = {})
     @opts = opts
   end
 
diff --git a/lib/validators/integer_setting_validator.rb b/lib/validators/integer_setting_validator.rb
index 185eb0a7994..48a8d6ca7a1 100644
--- a/lib/validators/integer_setting_validator.rb
+++ b/lib/validators/integer_setting_validator.rb
@@ -1,5 +1,5 @@
 class IntegerSettingValidator
-  def initialize(opts={})
+  def initialize(opts = {})
     @opts = opts
     @opts[:min] = 0 unless @opts[:min].present? || @opts[:hidden]
     @opts[:max] = 20000 unless @opts[:max].present? || @opts[:hidden]
@@ -7,18 +7,18 @@ class IntegerSettingValidator
 
   def valid_value?(val)
     return false if val.to_i.to_s != val.to_s
-    return false if @opts[:min] and @opts[:min].to_i > val.to_i
-    return false if @opts[:max] and @opts[:max].to_i < val.to_i
+    return false if @opts[:min] && @opts[:min].to_i > (val.to_i)
+    return false if @opts[:max] && @opts[:max].to_i < (val.to_i)
     true
   end
 
   def error_message
     if @opts[:min] && @opts[:max]
-      I18n.t('site_settings.errors.invalid_integer_min_max', {min: @opts[:min], max: @opts[:max]})
+      I18n.t('site_settings.errors.invalid_integer_min_max', min: @opts[:min], max: @opts[:max])
     elsif @opts[:min]
-      I18n.t('site_settings.errors.invalid_integer_min', {min: @opts[:min]})
+      I18n.t('site_settings.errors.invalid_integer_min', min: @opts[:min])
     elsif @opts[:max]
-      I18n.t('site_settings.errors.invalid_integer_max', {max: @opts[:max]})
+      I18n.t('site_settings.errors.invalid_integer_max', max: @opts[:max])
     else
       I18n.t('site_settings.errors.invalid_integer')
     end
diff --git a/lib/validators/pop3_polling_enabled_setting_validator.rb b/lib/validators/pop3_polling_enabled_setting_validator.rb
index f62e252bbbe..d002f4eee7f 100644
--- a/lib/validators/pop3_polling_enabled_setting_validator.rb
+++ b/lib/validators/pop3_polling_enabled_setting_validator.rb
@@ -2,7 +2,7 @@ require "net/pop"
 
 class POP3PollingEnabledSettingValidator
 
-  def initialize(opts={})
+  def initialize(opts = {})
     @opts = opts
   end
 
diff --git a/lib/validators/post_validator.rb b/lib/validators/post_validator.rb
index dec44496a8a..a9b1f468c45 100644
--- a/lib/validators/post_validator.rb
+++ b/lib/validators/post_validator.rb
@@ -24,7 +24,7 @@ class Validators::PostValidator < ActiveModel::Validator
       post.errors.add(:topic_id, :blank, options) if post.topic_id.blank?
     end
 
-    if post.new_record? and post.user_id.nil?
+    if post.new_record? && post.user_id.nil?
       post.errors.add(:user_id, :blank, options)
     end
   end
diff --git a/lib/validators/regex_setting_validator.rb b/lib/validators/regex_setting_validator.rb
index e1aa9900b64..895342372aa 100644
--- a/lib/validators/regex_setting_validator.rb
+++ b/lib/validators/regex_setting_validator.rb
@@ -2,7 +2,7 @@ class RegexSettingValidator
 
   LOREM = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam eget sem non elit tincidunt rhoncus.'.freeze
 
-  def initialize(opts={})
+  def initialize(opts = {})
     @opts = opts
   end
 
diff --git a/lib/validators/reply_by_email_address_validator.rb b/lib/validators/reply_by_email_address_validator.rb
index 024a1aab707..3c3b5698f89 100644
--- a/lib/validators/reply_by_email_address_validator.rb
+++ b/lib/validators/reply_by_email_address_validator.rb
@@ -1,5 +1,5 @@
 class ReplyByEmailAddressValidator
-  def initialize(opts={})
+  def initialize(opts = {})
     @opts = opts
   end
 
diff --git a/lib/validators/reply_by_email_enabled_validator.rb b/lib/validators/reply_by_email_enabled_validator.rb
index e7333de0f6c..8170a129354 100644
--- a/lib/validators/reply_by_email_enabled_validator.rb
+++ b/lib/validators/reply_by_email_enabled_validator.rb
@@ -1,6 +1,6 @@
 class ReplyByEmailEnabledValidator
 
-  def initialize(opts={})
+  def initialize(opts = {})
     @opts = opts
   end
 
diff --git a/lib/validators/sso_overrides_email_validator.rb b/lib/validators/sso_overrides_email_validator.rb
index 4af0149b5f6..202cfc7b00c 100644
--- a/lib/validators/sso_overrides_email_validator.rb
+++ b/lib/validators/sso_overrides_email_validator.rb
@@ -1,5 +1,5 @@
 class SsoOverridesEmailValidator
-  def initialize(opts={})
+  def initialize(opts = {})
     @opts = opts
   end
 
diff --git a/lib/validators/string_setting_validator.rb b/lib/validators/string_setting_validator.rb
index 07a65500bdd..b7ffc2dcf3e 100644
--- a/lib/validators/string_setting_validator.rb
+++ b/lib/validators/string_setting_validator.rb
@@ -1,5 +1,5 @@
 class StringSettingValidator
-  def initialize(opts={})
+  def initialize(opts = {})
     @opts = opts
     @regex = Regexp.new(opts[:regex]) if opts[:regex]
     @regex_error = opts[:regex_error] || 'site_settings.errors.regex_mismatch'
@@ -8,12 +8,12 @@ class StringSettingValidator
   def valid_value?(val)
     return true if !val.present?
 
-    if (@opts[:min] and @opts[:min].to_i > val.length) || (@opts[:max] and @opts[:max].to_i < val.length)
+    if (@opts[:min] && @opts[:min].to_i > (val.length)) || (@opts[:max] && @opts[:max].to_i < (val.length))
       @length_fail = true
       return false
     end
 
-    if @regex and !(val =~ @regex)
+    if @regex && !(val =~ @regex)
       @regex_fail = true
       return false
     end
@@ -26,11 +26,11 @@ class StringSettingValidator
       I18n.t(@regex_error)
     elsif @length_fail
       if @opts[:min] && @opts[:max]
-        I18n.t('site_settings.errors.invalid_string_min_max', {min: @opts[:min], max: @opts[:max]})
+        I18n.t('site_settings.errors.invalid_string_min_max', min: @opts[:min], max: @opts[:max])
       elsif @opts[:min]
-        I18n.t('site_settings.errors.invalid_string_min', {min: @opts[:min]})
+        I18n.t('site_settings.errors.invalid_string_min', min: @opts[:min])
       else
-        I18n.t('site_settings.errors.invalid_string_max', {max: @opts[:max]})
+        I18n.t('site_settings.errors.invalid_string_max', max: @opts[:max])
       end
     else
       I18n.t('site_settings.errors.invalid_string')
diff --git a/lib/validators/topic_title_length_validator.rb b/lib/validators/topic_title_length_validator.rb
index 82d9d54f9ee..bdee42c81c8 100644
--- a/lib/validators/topic_title_length_validator.rb
+++ b/lib/validators/topic_title_length_validator.rb
@@ -7,15 +7,16 @@ class TopicTitleLengthValidator < ActiveModel::EachValidator
   private
 
     def title_validator(record)
-      length_range = if record.user.try(:admin?)
-                       1..SiteSetting.max_topic_title_length
-                     elsif record.private_message?
-                       SiteSetting.private_message_title_length
-                     else
-                       SiteSetting.topic_title_length
-                     end
+      length_range =
+        if record.user.try(:admin?)
+          1..SiteSetting.max_topic_title_length
+        elsif record.private_message?
+          SiteSetting.private_message_title_length
+        else
+          SiteSetting.topic_title_length
+        end
 
-      ActiveModel::Validations::LengthValidator.new({attributes: :title, in: length_range, allow_blank: true})
+      ActiveModel::Validations::LengthValidator.new(attributes: :title, in: length_range, allow_blank: true)
     end
 
 end
diff --git a/lib/validators/username_setting_validator.rb b/lib/validators/username_setting_validator.rb
index 3dbc75fba1d..d9aa18ad5fc 100644
--- a/lib/validators/username_setting_validator.rb
+++ b/lib/validators/username_setting_validator.rb
@@ -1,5 +1,5 @@
 class UsernameSettingValidator
-  def initialize(opts={})
+  def initialize(opts = {})
     @opts = opts
   end
 
diff --git a/lib/wizard.rb b/lib/wizard.rb
index e7a74f190c1..d577c2aa29a 100644
--- a/lib/wizard.rb
+++ b/lib/wizard.rb
@@ -87,10 +87,10 @@ class Wizard
     end
 
     first_admin_id = User.where(admin: true)
-                      .human_users
-                      .joins(:user_auth_tokens)
-                      .order('user_auth_tokens.created_at')
-                      .pluck(:id).first
+      .human_users
+      .joins(:user_auth_tokens)
+      .order('user_auth_tokens.created_at')
+      .pluck(:id).first
 
     if @user&.id && first_admin_id == @user.id
       !Wizard::Builder.new(@user).build.completed?
diff --git a/lib/wizard/builder.rb b/lib/wizard/builder.rb
index 56e6bc4a32f..d3ba97ff1f6 100644
--- a/lib/wizard/builder.rb
+++ b/lib/wizard/builder.rb
@@ -82,7 +82,7 @@ class Wizard
         username = Discourse.system_user.username if username.blank?
         contact = step.add_field(id: 'site_contact', type: 'dropdown', value: username)
 
-        User.where(admin: true).pluck(:username).each {|c| contact.add_choice(c) }
+        User.where(admin: true).pluck(:username).each { |c| contact.add_choice(c) }
 
         step.on_update do |updater|
           updater.apply_settings(:contact_email, :contact_url)
@@ -120,8 +120,8 @@ class Wizard
         themes = step.add_field(id: 'base_scheme_id', type: 'dropdown', required: true, value: scheme_id)
         ColorScheme.base_color_scheme_colors.each do |t|
           with_hash = t[:colors].dup
-          with_hash.map{|k,v| with_hash[k] = "##{v}"}
-          themes.add_choice(t[:id], data: {colors: with_hash})
+          with_hash.map { |k, v| with_hash[k] = "##{v}" }
+          themes.add_choice(t[:id], data: { colors: with_hash })
         end
         step.add_field(id: 'theme_preview', type: 'component')
 
@@ -187,12 +187,10 @@ class Wizard
       end
 
       @wizard.append_step('emoji') do |step|
-        sets = step.add_field({
-          id: 'emoji_set',
-          type: 'radio',
-          required: true,
-          value: SiteSetting.emoji_set
-        })
+        sets = step.add_field(id: 'emoji_set',
+                              type: 'radio',
+                              required: true,
+                              value: SiteSetting.emoji_set)
 
         emoji = ["smile", "+1", "tada", "poop"]
 
@@ -201,10 +199,8 @@ class Wizard
             ""
           end
 
-          sets.add_choice(set[:value], {
-            label: I18n.t("js.#{set[:name]}"),
-            extra_label: "#{imgs.join}"
-          })
+          sets.add_choice(set[:value],             label: I18n.t("js.#{set[:name]}"),
+                                                   extra_label: "#{imgs.join}")
 
           step.on_update do |updater|
             updater.apply_settings(:emoji_set)
diff --git a/lib/wizard/field.rb b/lib/wizard/field.rb
index 0816e055d7f..45fdacc9992 100644
--- a/lib/wizard/field.rb
+++ b/lib/wizard/field.rb
@@ -27,7 +27,7 @@ class Wizard
       @choices = []
     end
 
-    def add_choice(id, opts=nil)
+    def add_choice(id, opts = nil)
       choice = Choice.new(id, opts || {})
       choice.field = self
 
diff --git a/lib/wizard/step_updater.rb b/lib/wizard/step_updater.rb
index f05605c33fe..3d8ad87a3d6 100644
--- a/lib/wizard/step_updater.rb
+++ b/lib/wizard/step_updater.rb
@@ -44,7 +44,7 @@ class Wizard
     end
 
     def apply_settings(*ids)
-      ids.each {|id| apply_setting(id)}
+      ids.each { |id| apply_setting(id) }
     end
 
   end
diff --git a/plugins/discourse-narrative-bot/db/fixtures/001_discobot.rb b/plugins/discourse-narrative-bot/db/fixtures/001_discobot.rb
index e9ce7b2dd6a..ebc2299937f 100644
--- a/plugins/discourse-narrative-bot/db/fixtures/001_discobot.rb
+++ b/plugins/discourse-narrative-bot/db/fixtures/001_discobot.rb
@@ -1,4 +1,4 @@
-discobot_username ='discobot'
+discobot_username = 'discobot'
 user = User.find_by(id: -2)
 
 if !user
@@ -37,7 +37,7 @@ if !user
 end
 
 bot = User.find(-2)
-bot.update!(admin:true, moderator: false)
+bot.update!(admin: true, moderator: false)
 
 bot.user_option.update!(
   email_private_messages: false,
diff --git a/plugins/discourse-narrative-bot/lib/discourse_narrative_bot/advanced_user_narrative.rb b/plugins/discourse-narrative-bot/lib/discourse_narrative_bot/advanced_user_narrative.rb
index fb6b4e2e14a..b5fbe5bc732 100644
--- a/plugins/discourse-narrative-bot/lib/discourse_narrative_bot/advanced_user_narrative.rb
+++ b/plugins/discourse-narrative-bot/lib/discourse_narrative_bot/advanced_user_narrative.rb
@@ -101,7 +101,7 @@ module DiscourseNarrativeBot
 
     def reset_bot(user, post)
       if pm_to_bot?(post)
-        reset_data(user, { topic_id: post.topic_id })
+        reset_data(user, topic_id: post.topic_id)
       else
         reset_data(user)
       end
@@ -116,15 +116,13 @@ module DiscourseNarrativeBot
 
       fake_delay
 
-      post = PostCreator.create!(@user, {
-        raw: I18n.t(
+      post = PostCreator.create!(@user,         raw: I18n.t(
           "#{I18N_KEY}.edit.bot_created_post_raw",
           i18n_post_args(discobot_username: self.discobot_user.username)
         ),
-        topic_id: data[:topic_id],
-        skip_bot: true,
-        skip_validations: true
-      })
+                                                topic_id: data[:topic_id],
+                                                skip_bot: true,
+                                                skip_validations: true)
 
       set_state_data(:post_id, post.id)
       post
@@ -133,15 +131,13 @@ module DiscourseNarrativeBot
     def init_tutorial_recover
       data = get_data(@user)
 
-      post = PostCreator.create!(@user, {
-        raw: I18n.t(
+      post = PostCreator.create!(@user,         raw: I18n.t(
           "#{I18N_KEY}.recover.deleted_post_raw",
           i18n_post_args(discobot_username: self.discobot_user.username)
         ),
-        topic_id: data[:topic_id],
-        skip_bot: true,
-        skip_validations: true
-      })
+                                                topic_id: data[:topic_id],
+                                                skip_bot: true,
+                                                skip_validations: true)
 
       set_state_data(:post_id, post.id)
 
diff --git a/plugins/discourse-narrative-bot/lib/discourse_narrative_bot/base.rb b/plugins/discourse-narrative-bot/lib/discourse_narrative_bot/base.rb
index e00cf5eb2f0..f2bbc9d3b1c 100644
--- a/plugins/discourse-narrative-bot/lib/discourse_narrative_bot/base.rb
+++ b/plugins/discourse-narrative-bot/lib/discourse_narrative_bot/base.rb
@@ -109,7 +109,7 @@ module DiscourseNarrativeBot
             skip_trigger: TrackSelector.skip_trigger,
             reset_trigger: "#{TrackSelector.reset_trigger} #{self.class.reset_trigger}"
           )
-        ), {}, { skip_send_email: false })
+        ), {}, skip_send_email: false)
       end
     end
 
@@ -168,8 +168,8 @@ module DiscourseNarrativeBot
       end
     end
 
-    def i18n_post_args(extra={})
-      {base_uri: Discourse.base_uri}.merge(extra)
+    def i18n_post_args(extra = {})
+      { base_uri: Discourse.base_uri }.merge(extra)
     end
 
     def valid_topic?(topic_id)
diff --git a/plugins/discourse-narrative-bot/lib/discourse_narrative_bot/new_user_narrative.rb b/plugins/discourse-narrative-bot/lib/discourse_narrative_bot/new_user_narrative.rb
index 76e5b2e6fe0..7596d335a15 100644
--- a/plugins/discourse-narrative-bot/lib/discourse_narrative_bot/new_user_narrative.rb
+++ b/plugins/discourse-narrative-bot/lib/discourse_narrative_bot/new_user_narrative.rb
@@ -121,7 +121,7 @@ module DiscourseNarrativeBot
 
     def reset_bot(user, post)
       if pm_to_bot?(post)
-        reset_data(user, { topic_id: post.topic_id })
+        reset_data(user, topic_id: post.topic_id)
       else
         reset_data(user)
       end
@@ -154,7 +154,7 @@ module DiscourseNarrativeBot
       PostRevisor.new(post, topic).revise!(
         self.discobot_user,
         { raw: raw },
-        { skip_validations: true, force_new_version: true }
+        skip_validations: true, force_new_version: true
       )
 
       set_state_data(:post_version, post.reload.version || 0)
diff --git a/plugins/discourse-narrative-bot/plugin.rb b/plugins/discourse-narrative-bot/plugin.rb
index adc514e29c4..79aba1b6ede 100644
--- a/plugins/discourse-narrative-bot/plugin.rb
+++ b/plugins/discourse-narrative-bot/plugin.rb
@@ -96,7 +96,7 @@ after_initialize do
           end
 
         respond_to do |format|
-          format.svg { render inline: svg}
+          format.svg { render inline: svg }
         end
       end
     end
diff --git a/plugins/discourse-narrative-bot/spec/discourse_narrative_bot/advanced_user_narrative_spec.rb b/plugins/discourse-narrative-bot/spec/discourse_narrative_bot/advanced_user_narrative_spec.rb
index a3dd4e826ca..5c2eeb04523 100644
--- a/plugins/discourse-narrative-bot/spec/discourse_narrative_bot/advanced_user_narrative_spec.rb
+++ b/plugins/discourse-narrative-bot/spec/discourse_narrative_bot/advanced_user_narrative_spec.rb
@@ -7,7 +7,7 @@ RSpec.describe DiscourseNarrativeBot::AdvancedUserNarrative do
 
   let(:topic) do
     Fabricate(:private_message_topic, first_post: first_post,
-      topic_allowed_users: [
+                                      topic_allowed_users: [
         Fabricate.build(:topic_allowed_user, user: discobot_user),
         Fabricate.build(:topic_allowed_user, user: user),
       ]
@@ -79,15 +79,13 @@ RSpec.describe DiscourseNarrativeBot::AdvancedUserNarrative do
 
         new_post = Post.offset(1).last
 
-        expect(narrative.get_data(user)).to eq({
-          "topic_id" => topic.id,
-          "state" => "tutorial_edit",
-          "last_post_id" => new_post.id,
-          "track" => described_class.to_s,
-          "tutorial_edit" => {
+        expect(narrative.get_data(user)).to eq("topic_id" => topic.id,
+                                               "state" => "tutorial_edit",
+                                               "last_post_id" => new_post.id,
+                                               "track" => described_class.to_s,
+                                               "tutorial_edit" => {
             "post_id" => Post.last.id
-          }
-        })
+          })
 
         expect(new_post.raw).to eq(expected_raw.chomp)
         expect(new_post.topic.id).to eq(topic.id)
@@ -111,15 +109,13 @@ RSpec.describe DiscourseNarrativeBot::AdvancedUserNarrative do
 
         new_post = Post.offset(1).last
 
-        expect(narrative.get_data(user)).to eq({
-          "topic_id" => new_post.topic.id,
-          "state" => "tutorial_edit",
-          "last_post_id" => new_post.id,
-          "track" => described_class.to_s,
-          "tutorial_edit" => {
+        expect(narrative.get_data(user)).to eq("topic_id" => new_post.topic.id,
+                                               "state" => "tutorial_edit",
+                                               "last_post_id" => new_post.id,
+                                               "track" => described_class.to_s,
+                                               "tutorial_edit" => {
             "post_id" => Post.last.id
-          }
-        })
+          })
 
         expect(new_post.raw).to eq(expected_raw.chomp)
         expect(new_post.topic.id).to_not eq(topic.id)
@@ -659,11 +655,9 @@ RSpec.describe DiscourseNarrativeBot::AdvancedUserNarrative do
           'discourse_narrative_bot.advanced_user_narrative.details.reply', base_uri: ''
         ))
 
-        expect(narrative.get_data(user)).to eq({
-          "state" => "end",
-          "topic_id" => topic.id,
-          "track" => described_class.to_s
-        })
+        expect(narrative.get_data(user)).to eq("state" => "end",
+                                               "topic_id" => topic.id,
+                                               "track" => described_class.to_s)
 
         expect(user.badges.where(name: DiscourseNarrativeBot::AdvancedUserNarrative::BADGE_NAME).exists?)
           .to eq(true)
diff --git a/plugins/discourse-narrative-bot/spec/discourse_narrative_bot/new_user_narrative_spec.rb b/plugins/discourse-narrative-bot/spec/discourse_narrative_bot/new_user_narrative_spec.rb
index b234519ed9f..f85c05b070f 100644
--- a/plugins/discourse-narrative-bot/spec/discourse_narrative_bot/new_user_narrative_spec.rb
+++ b/plugins/discourse-narrative-bot/spec/discourse_narrative_bot/new_user_narrative_spec.rb
@@ -8,7 +8,7 @@ describe DiscourseNarrativeBot::NewUserNarrative do
 
   let(:topic) do
     Fabricate(:private_message_topic, first_post: first_post,
-      topic_allowed_users: [
+                                      topic_allowed_users: [
         Fabricate.build(:topic_allowed_user, user: discobot_user),
         Fabricate.build(:topic_allowed_user, user: user),
       ]
@@ -83,12 +83,10 @@ describe DiscourseNarrativeBot::NewUserNarrative do
 
         new_post = Post.last
 
-        expect(narrative.get_data(user)).to eq({
-          "topic_id" => topic.id,
-          "state" => "tutorial_bookmark",
-          "last_post_id" => new_post.id,
-          "track" => described_class.to_s
-        })
+        expect(narrative.get_data(user)).to eq("topic_id" => topic.id,
+                                               "state" => "tutorial_bookmark",
+                                               "last_post_id" => new_post.id,
+                                               "track" => described_class.to_s)
 
         expect(new_post.raw).to eq(expected_raw.chomp)
         expect(new_post.topic.id).to eq(topic.id)
@@ -111,12 +109,10 @@ describe DiscourseNarrativeBot::NewUserNarrative do
 
         new_post = Post.last
 
-        expect(narrative.get_data(user)).to eq({
-          "topic_id" => new_post.topic.id,
-          "state" => "tutorial_bookmark",
-          "last_post_id" => new_post.id,
-          "track" => described_class.to_s
-        })
+        expect(narrative.get_data(user)).to eq("topic_id" => new_post.topic.id,
+                                               "state" => "tutorial_bookmark",
+                                               "last_post_id" => new_post.id,
+                                               "track" => described_class.to_s)
 
         expect(new_post.raw).to eq(expected_raw.chomp)
         expect(new_post.topic.id).to_not eq(topic.id)
@@ -922,11 +918,9 @@ describe DiscourseNarrativeBot::NewUserNarrative do
 
           expect(first_post.reload.raw).to eq('Hello world')
 
-          expect(narrative.get_data(user)).to include({
-            "state" => "end",
-            "topic_id" => new_post.topic_id,
-            "track" => described_class.to_s,
-          })
+          expect(narrative.get_data(user)).to include("state" => "end",
+                                                      "topic_id" => new_post.topic_id,
+                                                      "track" => described_class.to_s)
 
           expect(user.badges.where(name: DiscourseNarrativeBot::NewUserNarrative::BADGE_NAME).exists?)
             .to eq(true)
diff --git a/plugins/discourse-narrative-bot/spec/discourse_narrative_bot/track_selector_spec.rb b/plugins/discourse-narrative-bot/spec/discourse_narrative_bot/track_selector_spec.rb
index b6166ccfcfe..5e7594a2e72 100644
--- a/plugins/discourse-narrative-bot/spec/discourse_narrative_bot/track_selector_spec.rb
+++ b/plugins/discourse-narrative-bot/spec/discourse_narrative_bot/track_selector_spec.rb
@@ -42,7 +42,7 @@ describe DiscourseNarrativeBot::TrackSelector do
 
       let(:topic) do
         Fabricate(:private_message_topic, first_post: first_post,
-          topic_allowed_users: [
+                                          topic_allowed_users: [
             Fabricate.build(:topic_allowed_user, user: discobot_user),
             Fabricate.build(:topic_allowed_user, user: user),
           ]
@@ -454,7 +454,6 @@ describe DiscourseNarrativeBot::TrackSelector do
           expect(new_post.raw).to eq(random_mention_reply)
         end
 
-
         describe 'rate limiting random reply message in public topic' do
           let(:topic) { Fabricate(:topic) }
           let(:other_post) { Fabricate(:post, raw: '@discobot show me something', topic: topic) }
diff --git a/plugins/discourse-nginx-performance-report/app/jobs/scheduled/daily_performance_report.rb b/plugins/discourse-nginx-performance-report/app/jobs/scheduled/daily_performance_report.rb
index 78b25666e4d..80d44a2aeb2 100644
--- a/plugins/discourse-nginx-performance-report/app/jobs/scheduled/daily_performance_report.rb
+++ b/plugins/discourse-nginx-performance-report/app/jobs/scheduled/daily_performance_report.rb
@@ -45,7 +45,6 @@ module Jobs
                            title: I18n.t('performance_report.initial_topic_title'),
                            skip_validations: true)
 
-
       unless post && post.topic_id
         raise StandardError, "Could not create or retrieve performance report topic id"
       end
diff --git a/plugins/discourse-nginx-performance-report/lib/log_analyzer.rb b/plugins/discourse-nginx-performance-report/lib/log_analyzer.rb
index 79cac5163ad..439b1202470 100644
--- a/plugins/discourse-nginx-performance-report/lib/log_analyzer.rb
+++ b/plugins/discourse-nginx-performance-report/lib/log_analyzer.rb
@@ -2,7 +2,6 @@ class LogAnalyzer
 
   class LineParser
 
-
     # log_format log_discourse '[$time_local] "$http_host" $remote_addr "$request" "$http_user_agent" "$sent_http_x_discourse_route" $status $bytes_sent "$http_referer" $upstream_response_time $request_time "$sent_http_x_discourse_username"';
 
     attr_accessor :time, :ip_address, :url, :route, :user_agent, :rails_duration, :total_duration,
@@ -69,8 +68,8 @@ class LogAnalyzer
       @aggregate_type = :duration
     end
 
-    def add(id, duration, aggregate=nil)
-      ary = (@data[id] ||= [0,0])
+    def add(id, duration, aggregate = nil)
+      ary = (@data[id] ||= [0, 0])
       ary[0] += duration
       ary[1] += 1
       unless aggregate.nil?
@@ -83,8 +82,8 @@ class LogAnalyzer
       end
     end
 
-    def top(n, aggregator_formatter=nil)
-      @data.sort{|a,b| b[1][0] <=> a[1][0]}.first(n).map do |metric, ary|
+    def top(n, aggregator_formatter = nil)
+      @data.sort { |a, b| b[1][0] <=> a[1][0] }.first(n).map do |metric, ary|
         metric = metric.to_s
         metric = "[empty]" if metric.length == 0
         result = [metric, ary[0], ary[1]]
@@ -93,7 +92,7 @@ class LogAnalyzer
           if aggregator_formatter
             result.push aggregator_formatter.call(ary[2], ary[0], ary[1])
           else
-            result.push ary[2].sort{|a,b| b[1] <=> a[1]}.first(5).map{|k,v|
+            result.push ary[2].sort { |a, b| b[1] <=> a[1] }.first(5).map { |k, v|
             v = "%.2f" % v if Float === v
             "#{k}(#{v})"}.join(" ")
           end
@@ -104,7 +103,7 @@ class LogAnalyzer
     end
   end
 
-  def initialize(filenames, args={})
+  def initialize(filenames, args = {})
     @filenames = filenames
     @ip_to_rails_duration = Aggeregator.new
     @username_to_rails_duration = Aggeregator.new
@@ -148,7 +147,7 @@ class LogAnalyzer
 
         @url_to_rails_duration.add(parsed.url, parsed.rails_duration)
 
-        @status_404_to_count.add(parsed.url,1) if parsed.status == "404"
+        @status_404_to_count.add(parsed.url, 1) if parsed.status == "404"
       end
     end
     self
diff --git a/plugins/discourse-nginx-performance-report/script/nginx_analyze.rb b/plugins/discourse-nginx-performance-report/script/nginx_analyze.rb
index 8550806f879..480beb67ebd 100644
--- a/plugins/discourse-nginx-performance-report/script/nginx_analyze.rb
+++ b/plugins/discourse-nginx-performance-report/script/nginx_analyze.rb
@@ -30,7 +30,7 @@ def top(cols, aggregator, count, aggregator_formatter = nil)
 
   col_just = []
 
-  col_widths = map_with_index(cols) do |name,idx|
+  col_widths = map_with_index(cols) do |name, idx|
     max_width = name.length
 
     if cols[idx].respond_to? :align
@@ -46,14 +46,14 @@ def top(cols, aggregator, count, aggregator_formatter = nil)
       row[idx] = row[idx].to_s
       max_width = row[idx].length if row[idx].length > max_width
     end
-    [max_width,80].min
+    [max_width, 80].min
   end
 
-  puts(map_with_index(cols) do |name,idx|
+  puts(map_with_index(cols) do |name, idx|
     name.ljust(col_widths[idx])
   end.join(" "))
 
-  puts(map_with_index(cols) do |name,idx|
+  puts(map_with_index(cols) do |name, idx|
     ("-" * name.length).ljust(col_widths[idx])
   end.join(" "))
 
@@ -102,7 +102,7 @@ end
 puts
 puts "Analyzed: #{analyzer.filenames.join(",")} on #{`hostname`}"
 if limit
-  puts "Limited to #{DateTime.now - (limit.to_f / (60*24.0))} - #{DateTime.now}"
+  puts "Limited to #{DateTime.now - (limit.to_f / (60 * 24.0))} - #{DateTime.now}"
 end
 puts SPACER
 puts "#{analyzer.from_time} - #{analyzer.to_time}"
@@ -121,7 +121,7 @@ puts SPACER
 puts
 puts "Top 100 routes by Server Load"
 puts
-top(["Route", "Duration", "Reqs", Column.new("Mobile", :rjust)], analyzer.route_to_rails_duration, 100, lambda{
+top(["Route", "Duration", "Reqs", Column.new("Mobile", :rjust)], analyzer.route_to_rails_duration, 100, lambda {
   |hash, name, total|
   "#{hash["mobile"] || 0} (#{"%.2f" % (((hash["mobile"] || 0) / (total + 0.0)) * 100)})%"}
 )
diff --git a/plugins/poll/db/migrate/20151016163051_merge_polls_votes.rb b/plugins/poll/db/migrate/20151016163051_merge_polls_votes.rb
index 17e6459e120..33bd122bdf9 100644
--- a/plugins/poll/db/migrate/20151016163051_merge_polls_votes.rb
+++ b/plugins/poll/db/migrate/20151016163051_merge_polls_votes.rb
@@ -5,11 +5,11 @@ class MergePollsVotes < ActiveRecord::Migration
       polls_votes = {}
       PostCustomField.where(post_id: post_id).where("name LIKE 'polls-votes-%'").find_each do |pcf|
         user_id = pcf.name["polls-votes-".size..-1]
-        polls_votes["#{user_id}"] = ::JSON.parse(pcf.value||"{}")
+        polls_votes["#{user_id}"] = ::JSON.parse(pcf.value || "{}")
       end
 
       pcf = PostCustomField.find_or_create_by(name: "polls-votes", post_id: post_id)
-      pcf.value = ::JSON.parse(pcf.value||"{}").merge(polls_votes).to_json
+      pcf.value = ::JSON.parse(pcf.value || "{}").merge(polls_votes).to_json
       pcf.save
     end
   end
diff --git a/plugins/poll/db/migrate/20160321164925_close_polls_in_closed_topics.rb b/plugins/poll/db/migrate/20160321164925_close_polls_in_closed_topics.rb
index 5ca969c68dc..978a41c890c 100644
--- a/plugins/poll/db/migrate/20160321164925_close_polls_in_closed_topics.rb
+++ b/plugins/poll/db/migrate/20160321164925_close_polls_in_closed_topics.rb
@@ -2,9 +2,9 @@ class ClosePollsInClosedTopics < ActiveRecord::Migration
 
   def up
     PostCustomField.joins(post: :topic)
-                   .where("post_custom_fields.name = 'polls'")
-                   .where("topics.closed")
-                   .find_each do |pcf|
+      .where("post_custom_fields.name = 'polls'")
+      .where("topics.closed")
+      .find_each do |pcf|
       polls = ::JSON.parse(pcf.value || "{}")
       polls.values.each { |poll| poll["status"] = "closed" }
       pcf.value = polls.to_json
diff --git a/plugins/poll/lib/polls_updater.rb b/plugins/poll/lib/polls_updater.rb
index 5464005175d..488331041b1 100644
--- a/plugins/poll/lib/polls_updater.rb
+++ b/plugins/poll/lib/polls_updater.rb
@@ -101,7 +101,7 @@ module DiscoursePoll
         post.save_custom_fields(true)
 
         # publish the changes
-        MessageBus.publish("/polls/#{post.topic_id}", { post_id: post.id, polls: polls })
+        MessageBus.publish("/polls/#{post.topic_id}", post_id: post.id, polls: polls)
       end
     end
 
diff --git a/plugins/poll/lib/tasks/migrate_old_polls.rake b/plugins/poll/lib/tasks/migrate_old_polls.rake
index 17e5c3946c8..d8f2ee40644 100644
--- a/plugins/poll/lib/tasks/migrate_old_polls.rake
+++ b/plugins/poll/lib/tasks/migrate_old_polls.rake
@@ -27,9 +27,9 @@ desc "Migrate old polls to new syntax"
 task "poll:migrate_old_polls" => :environment do
   # iterate over all polls
   PluginStoreRow.where(plugin_name: "poll")
-                .where("key LIKE 'poll_options_%'")
-                .pluck(:key)
-                .each do |poll_options_key|
+    .where("key LIKE 'poll_options_%'")
+    .pluck(:key)
+    .each do |poll_options_key|
     # extract the post_id
     post_id = poll_options_key["poll_options_".length..-1].to_i
     # load the post from the db
@@ -56,9 +56,9 @@ task "poll:migrate_old_polls" => :environment do
         options = post.custom_fields["polls"]["poll"]["options"]
         # iterate over all votes
         PluginStoreRow.where(plugin_name: "poll")
-                      .where("key LIKE 'poll_vote_#{post_id}_%'")
-                      .pluck(:key, :value)
-                      .each do |poll_vote_key, vote|
+          .where("key LIKE 'poll_vote_#{post_id}_%'")
+          .pluck(:key, :value)
+          .each do |poll_vote_key, vote|
           # extract the user_id
           user_id = poll_vote_key["poll_vote_#{post_id}_%".length..-1].to_i
           # find the selected option
diff --git a/plugins/poll/plugin.rb b/plugins/poll/plugin.rb
index 2bf54226e3f..33709ecb0f5 100644
--- a/plugins/poll/plugin.rb
+++ b/plugins/poll/plugin.rb
@@ -136,7 +136,7 @@ after_initialize do
 
           post.save_custom_fields(true)
 
-          MessageBus.publish("/polls/#{post.topic_id}", {post_id: post.id, polls: polls })
+          MessageBus.publish("/polls/#{post.topic_id}", post_id: post.id, polls: polls)
 
           polls[poll_name]
         end
@@ -230,7 +230,7 @@ after_initialize do
           end
 
           next unless option["voter_ids"]
-          user_ids << option["voter_ids"].slice((params[:offset].to_i || 0)  * 25, 25)
+          user_ids << option["voter_ids"].slice((params[:offset].to_i || 0) * 25, 25)
         end
 
         user_ids.flatten!
@@ -295,7 +295,7 @@ after_initialize do
     end
   end
 
-  validate(:post, :validate_polls) do |force=nil|
+  validate(:post, :validate_polls) do |force = nil|
     return if !SiteSetting.poll_enabled? && (self.user && !self.user.staff?)
 
     # only care when raw has changed!
@@ -360,9 +360,8 @@ after_initialize do
   # tells the front-end we have a poll for that post
   on(:post_created) do |post|
     next if post.is_first_post? || post.custom_fields[DiscoursePoll::POLLS_CUSTOM_FIELD].blank?
-    MessageBus.publish("/polls/#{post.topic_id}", {
-                         post_id: post.id,
-                         polls: post.custom_fields[DiscoursePoll::POLLS_CUSTOM_FIELD]})
+    MessageBus.publish("/polls/#{post.topic_id}",                          post_id: post.id,
+                                                                           polls: post.custom_fields[DiscoursePoll::POLLS_CUSTOM_FIELD])
   end
 
   add_to_serializer(:post, :polls, false) do
diff --git a/plugins/poll/spec/controllers/polls_controller_spec.rb b/plugins/poll/spec/controllers/polls_controller_spec.rb
index 677a72d6098..02db8bdf930 100644
--- a/plugins/poll/spec/controllers/polls_controller_spec.rb
+++ b/plugins/poll/spec/controllers/polls_controller_spec.rb
@@ -13,7 +13,7 @@ describe ::DiscoursePoll::PollsController do
     it "works" do
       MessageBus.expects(:publish)
 
-      xhr :put, :vote, { post_id: poll.id, poll_name: "poll", options: ["5c24fc1df56d764b550ceae1b9319125"] }
+      xhr :put, :vote, post_id: poll.id, poll_name: "poll", options: ["5c24fc1df56d764b550ceae1b9319125"]
 
       expect(response).to be_success
       json = ::JSON.parse(response.body)
@@ -23,7 +23,7 @@ describe ::DiscoursePoll::PollsController do
     end
 
     it "requires at least 1 valid option" do
-      xhr :put, :vote, { post_id: poll.id, poll_name: "poll", options: ["A", "B"] }
+      xhr :put, :vote, post_id: poll.id, poll_name: "poll", options: ["A", "B"]
 
       expect(response).not_to be_success
       json = ::JSON.parse(response.body)
@@ -31,10 +31,10 @@ describe ::DiscoursePoll::PollsController do
     end
 
     it "supports vote changes" do
-      xhr :put, :vote, { post_id: poll.id, poll_name: "poll", options: ["5c24fc1df56d764b550ceae1b9319125"] }
+      xhr :put, :vote, post_id: poll.id, poll_name: "poll", options: ["5c24fc1df56d764b550ceae1b9319125"]
       expect(response).to be_success
 
-      xhr :put, :vote, { post_id: poll.id, poll_name: "poll", options: ["e89dec30bbd9bf50fabf6a05b4324edf"] }
+      xhr :put, :vote, post_id: poll.id, poll_name: "poll", options: ["e89dec30bbd9bf50fabf6a05b4324edf"]
       expect(response).to be_success
       json = ::JSON.parse(response.body)
       expect(json["poll"]["voters"]).to eq(1)
@@ -44,13 +44,13 @@ describe ::DiscoursePoll::PollsController do
 
     it "works even if topic is closed" do
       topic.update_attribute(:closed, true)
-      xhr :put, :vote, { post_id: poll.id, poll_name: "poll", options: ["5c24fc1df56d764b550ceae1b9319125"] }
+      xhr :put, :vote, post_id: poll.id, poll_name: "poll", options: ["5c24fc1df56d764b550ceae1b9319125"]
       expect(response).to be_success
     end
 
     it "ensures topic is not archived" do
       topic.update_attribute(:archived, true)
-      xhr :put, :vote, { post_id: poll.id, poll_name: "poll", options: ["A"] }
+      xhr :put, :vote, post_id: poll.id, poll_name: "poll", options: ["A"]
       expect(response).not_to be_success
       json = ::JSON.parse(response.body)
       expect(json["errors"][0]).to eq(I18n.t("poll.topic_must_be_open_to_vote"))
@@ -58,21 +58,21 @@ describe ::DiscoursePoll::PollsController do
 
     it "ensures post is not trashed" do
       poll.trash!
-      xhr :put, :vote, { post_id: poll.id, poll_name: "poll", options: ["A"] }
+      xhr :put, :vote, post_id: poll.id, poll_name: "poll", options: ["A"]
       expect(response).not_to be_success
       json = ::JSON.parse(response.body)
       expect(json["errors"][0]).to eq(I18n.t("poll.post_is_deleted"))
     end
 
     it "ensures polls are associated with the post" do
-      xhr :put, :vote, { post_id: Fabricate(:post).id, poll_name: "foobar", options: ["A"] }
+      xhr :put, :vote, post_id: Fabricate(:post).id, poll_name: "foobar", options: ["A"]
       expect(response).not_to be_success
       json = ::JSON.parse(response.body)
       expect(json["errors"][0]).to eq(I18n.t("poll.no_polls_associated_with_this_post"))
     end
 
     it "checks the name of the poll" do
-      xhr :put, :vote, { post_id: poll.id, poll_name: "foobar", options: ["A"] }
+      xhr :put, :vote, post_id: poll.id, poll_name: "foobar", options: ["A"]
       expect(response).not_to be_success
       json = ::JSON.parse(response.body)
       expect(json["errors"][0]).to eq(I18n.t("poll.no_poll_with_this_name", name: "foobar"))
@@ -80,7 +80,7 @@ describe ::DiscoursePoll::PollsController do
 
     it "ensures poll is open" do
       closed_poll = create_post(raw: "[poll status=closed]\n- A\n- B\n[/poll]")
-      xhr :put, :vote, { post_id: closed_poll.id, poll_name: "poll", options: ["5c24fc1df56d764b550ceae1b9319125"] }
+      xhr :put, :vote, post_id: closed_poll.id, poll_name: "poll", options: ["5c24fc1df56d764b550ceae1b9319125"]
       expect(response).not_to be_success
       json = ::JSON.parse(response.body)
       expect(json["errors"][0]).to eq(I18n.t("poll.poll_must_be_open_to_vote"))
@@ -88,9 +88,9 @@ describe ::DiscoursePoll::PollsController do
 
     it "doesn't discard anonymous votes when someone votes" do
       default_poll = poll.custom_fields["polls"]["poll"]
-      add_anonymous_votes(poll, default_poll, 17, {"5c24fc1df56d764b550ceae1b9319125" => 11, "e89dec30bbd9bf50fabf6a05b4324edf" => 6})
+      add_anonymous_votes(poll, default_poll, 17, "5c24fc1df56d764b550ceae1b9319125" => 11, "e89dec30bbd9bf50fabf6a05b4324edf" => 6)
 
-      xhr :put, :vote, { post_id: poll.id, poll_name: "poll", options: ["5c24fc1df56d764b550ceae1b9319125"] }
+      xhr :put, :vote, post_id: poll.id, poll_name: "poll", options: ["5c24fc1df56d764b550ceae1b9319125"]
       expect(response).to be_success
 
       json = ::JSON.parse(response.body)
@@ -148,7 +148,7 @@ describe ::DiscoursePoll::PollsController do
     it "works for OP" do
       MessageBus.expects(:publish)
 
-      xhr :put, :toggle_status, { post_id: poll.id, poll_name: "poll", status: "closed" }
+      xhr :put, :toggle_status, post_id: poll.id, poll_name: "poll", status: "closed"
       expect(response).to be_success
       json = ::JSON.parse(response.body)
       expect(json["poll"]["status"]).to eq("closed")
@@ -158,7 +158,7 @@ describe ::DiscoursePoll::PollsController do
       log_in(:moderator)
       MessageBus.expects(:publish)
 
-      xhr :put, :toggle_status, { post_id: poll.id, poll_name: "poll", status: "closed" }
+      xhr :put, :toggle_status, post_id: poll.id, poll_name: "poll", status: "closed"
       expect(response).to be_success
       json = ::JSON.parse(response.body)
       expect(json["poll"]["status"]).to eq("closed")
@@ -166,7 +166,7 @@ describe ::DiscoursePoll::PollsController do
 
     it "ensures post is not trashed" do
       poll.trash!
-      xhr :put, :toggle_status, { post_id: poll.id, poll_name: "poll", status: "closed" }
+      xhr :put, :toggle_status, post_id: poll.id, poll_name: "poll", status: "closed"
       expect(response).not_to be_success
       json = ::JSON.parse(response.body)
       expect(json["errors"][0]).to eq(I18n.t("poll.post_is_deleted"))
diff --git a/plugins/poll/spec/controllers/posts_controller_spec.rb b/plugins/poll/spec/controllers/posts_controller_spec.rb
index 41bd0a42db8..dd0219f3845 100644
--- a/plugins/poll/spec/controllers/posts_controller_spec.rb
+++ b/plugins/poll/spec/controllers/posts_controller_spec.rb
@@ -12,7 +12,7 @@ describe PostsController do
   describe "polls" do
 
     it "works" do
-      xhr :post, :create, { title: title, raw: "[poll]\n- A\n- B\n[/poll]" }
+      xhr :post, :create, title: title, raw: "[poll]\n- A\n- B\n[/poll]"
       expect(response).to be_success
       json = ::JSON.parse(response.body)
       expect(json["cooked"]).to match("data-poll-")
@@ -21,7 +21,7 @@ describe PostsController do
 
     it "works on any post" do
       post = Fabricate(:post)
-      xhr :post, :create, { topic_id: post.topic.id, raw: "[poll]\n- A\n- B\n[/poll]" }
+      xhr :post, :create, topic_id: post.topic.id, raw: "[poll]\n- A\n- B\n[/poll]"
       expect(response).to be_success
       json = ::JSON.parse(response.body)
       expect(json["cooked"]).to match("data-poll-")
@@ -29,14 +29,14 @@ describe PostsController do
     end
 
     it "should have different options" do
-      xhr :post, :create, { title: title, raw: "[poll]\n- A\n- A\n[/poll]" }
+      xhr :post, :create, title: title, raw: "[poll]\n- A\n- A\n[/poll]"
       expect(response).not_to be_success
       json = ::JSON.parse(response.body)
       expect(json["errors"][0]).to eq(I18n.t("poll.default_poll_must_have_different_options"))
     end
 
     it "should have at least 2 options" do
-      xhr :post, :create, { title: title, raw: "[poll]\n- A\n[/poll]" }
+      xhr :post, :create, title: title, raw: "[poll]\n- A\n[/poll]"
       expect(response).not_to be_success
       json = ::JSON.parse(response.body)
       expect(json["errors"][0]).to eq(I18n.t("poll.default_poll_must_have_at_least_2_options"))
@@ -47,7 +47,7 @@ describe PostsController do
       (SiteSetting.poll_maximum_options + 1).times { |n| raw << "\n- #{n}" }
       raw << "\n[/poll]"
 
-      xhr :post, :create, { title: title, raw: raw }
+      xhr :post, :create, title: title, raw: raw
 
       expect(response).not_to be_success
       json = ::JSON.parse(response.body)
@@ -55,14 +55,14 @@ describe PostsController do
     end
 
     it "should have valid parameters" do
-      xhr :post, :create, { title: title, raw: "[poll type=multiple min=5]\n- A\n- B\n[/poll]" }
+      xhr :post, :create, title: title, raw: "[poll type=multiple min=5]\n- A\n- B\n[/poll]"
       expect(response).not_to be_success
       json = ::JSON.parse(response.body)
       expect(json["errors"][0]).to eq(I18n.t("poll.default_poll_with_multiple_choices_has_invalid_parameters"))
     end
 
     it "prevents self-xss" do
-      xhr :post, :create, { title: title, raw: "[poll name=]\n- A\n- B\n[/poll]" }
+      xhr :post, :create, title: title, raw: "[poll name=]\n- A\n- B\n[/poll]"
       expect(response).to be_success
       json = ::JSON.parse(response.body)
       expect(json["cooked"]).to match("data-poll-")
@@ -71,7 +71,7 @@ describe PostsController do
     end
 
     it "also works whe there is a link starting with '[poll'" do
-      xhr :post, :create, { title: title, raw: "[Polls are awesome](/foobar)\n[poll]\n- A\n- B\n[/poll]" }
+      xhr :post, :create, title: title, raw: "[Polls are awesome](/foobar)\n[poll]\n- A\n- B\n[/poll]"
       expect(response).to be_success
       json = ::JSON.parse(response.body)
       expect(json["cooked"]).to match("data-poll-")
@@ -79,7 +79,7 @@ describe PostsController do
     end
 
     it "prevents pollception" do
-      xhr :post, :create, { title: title, raw: "[poll name=1]\n- A\n[poll name=2]\n- B\n- C\n[/poll]\n- D\n[/poll]" }
+      xhr :post, :create, title: title, raw: "[poll name=1]\n- A\n[poll name=2]\n- B\n- C\n[/poll]\n- D\n[/poll]"
       expect(response).to be_success
       json = ::JSON.parse(response.body)
       expect(json["cooked"]).to match("data-poll-")
@@ -93,13 +93,13 @@ describe PostsController do
 
         let(:post_id) do
           freeze_time(4.minutes.ago) do
-            xhr :post, :create, { title: title, raw: "[poll]\n- A\n- B\n[/poll]" }
+            xhr :post, :create, title: title, raw: "[poll]\n- A\n- B\n[/poll]"
             ::JSON.parse(response.body)["id"]
           end
         end
 
         it "can be changed" do
-          xhr :put, :update, { id: post_id, post: { raw: "[poll]\n- A\n- B\n- C\n[/poll]" } }
+          xhr :put, :update, id: post_id, post: { raw: "[poll]\n- A\n- B\n- C\n[/poll]" }
           expect(response).to be_success
           json = ::JSON.parse(response.body)
           expect(json["post"]["polls"]["poll"]["options"][2]["html"]).to eq("C")
@@ -107,7 +107,7 @@ describe PostsController do
 
         it "resets the votes" do
           DiscoursePoll::Poll.vote(post_id, "poll", ["5c24fc1df56d764b550ceae1b9319125"], user)
-          xhr :put, :update, { id: post_id, post: { raw: "[poll]\n- A\n- B\n- C\n[/poll]" } }
+          xhr :put, :update, id: post_id, post: { raw: "[poll]\n- A\n- B\n- C\n[/poll]" }
           expect(response).to be_success
           json = ::JSON.parse(response.body)
           expect(json["post"]["polls_votes"]).to_not be
@@ -123,7 +123,7 @@ describe PostsController do
 
         let(:post_id) do
           freeze_time(6.minutes.ago) do
-            xhr :post, :create, { title: title, raw: poll }
+            xhr :post, :create, title: title, raw: poll
             ::JSON.parse(response.body)["id"]
           end
         end
@@ -137,7 +137,7 @@ describe PostsController do
         describe "with no vote" do
 
           it "OP can change the options" do
-            xhr :put, :update, { id: post_id, post: { raw: new_option } }
+            xhr :put, :update, id: post_id, post: { raw: new_option }
             expect(response).to be_success
             json = ::JSON.parse(response.body)
             expect(json["post"]["polls"]["poll"]["options"][1]["html"]).to eq("C")
@@ -145,14 +145,14 @@ describe PostsController do
 
           it "staff can change the options" do
             log_in_user(Fabricate(:moderator))
-            xhr :put, :update, { id: post_id, post: { raw: new_option } }
+            xhr :put, :update, id: post_id, post: { raw: new_option }
             expect(response).to be_success
             json = ::JSON.parse(response.body)
             expect(json["post"]["polls"]["poll"]["options"][1]["html"]).to eq("C")
           end
 
           it "support changes on the post" do
-            xhr :put, :update, { id: post_id, post: { raw: updated } }
+            xhr :put, :update, id: post_id, post: { raw: updated }
             expect(response).to be_success
             json = ::JSON.parse(response.body)
             expect(json["post"]["cooked"]).to match("before")
@@ -167,7 +167,7 @@ describe PostsController do
           end
 
           it "OP cannot change the options" do
-            xhr :put, :update, { id: post_id, post: { raw: new_option } }
+            xhr :put, :update, id: post_id, post: { raw: new_option }
             expect(response).not_to be_success
             json = ::JSON.parse(response.body)
             expect(json["errors"][0]).to eq(I18n.t(
@@ -178,7 +178,7 @@ describe PostsController do
 
           it "staff can change the options and votes are merged" do
             log_in_user(Fabricate(:moderator))
-            xhr :put, :update, { id: post_id, post: { raw: new_option } }
+            xhr :put, :update, id: post_id, post: { raw: new_option }
             expect(response).to be_success
             json = ::JSON.parse(response.body)
             expect(json["post"]["polls"]["poll"]["options"][1]["html"]).to eq("C")
@@ -190,10 +190,10 @@ describe PostsController do
           it "staff can change the options and anonymous votes are merged" do
             post = Post.find_by(id: post_id)
             default_poll = post.custom_fields["polls"]["poll"]
-            add_anonymous_votes(post, default_poll, 7, {"5c24fc1df56d764b550ceae1b9319125" => 7})
+            add_anonymous_votes(post, default_poll, 7, "5c24fc1df56d764b550ceae1b9319125" => 7)
 
             log_in_user(Fabricate(:moderator))
-            xhr :put, :update, { id: post_id, post: { raw: new_option } }
+            xhr :put, :update, id: post_id, post: { raw: new_option }
             expect(response).to be_success
 
             json = ::JSON.parse(response.body)
@@ -204,7 +204,7 @@ describe PostsController do
           end
 
           it "support changes on the post" do
-            xhr :put, :update, { id: post_id, post: { raw: updated } }
+            xhr :put, :update, id: post_id, post: { raw: updated }
             expect(response).to be_success
             json = ::JSON.parse(response.body)
             expect(json["post"]["cooked"]).to match("before")
@@ -221,14 +221,14 @@ describe PostsController do
   describe "named polls" do
 
     it "should have different options" do
-      xhr :post, :create, { title: title, raw: "[poll name=""foo""]\n- A\n- A\n[/poll]" }
+      xhr :post, :create, title: title, raw: "[poll name=""foo""]\n- A\n- A\n[/poll]"
       expect(response).not_to be_success
       json = ::JSON.parse(response.body)
       expect(json["errors"][0]).to eq(I18n.t("poll.named_poll_must_have_different_options", name: "foo"))
     end
 
     it "should have at least 2 options" do
-      xhr :post, :create, { title: title, raw: "[poll name='foo']\n- A\n[/poll]" }
+      xhr :post, :create, title: title, raw: "[poll name='foo']\n- A\n[/poll]"
       expect(response).not_to be_success
       json = ::JSON.parse(response.body)
       expect(json["errors"][0]).to eq(I18n.t("poll.named_poll_must_have_at_least_2_options", name: "foo"))
@@ -239,7 +239,7 @@ describe PostsController do
   describe "multiple polls" do
 
     it "works" do
-      xhr :post, :create, { title: title, raw: "[poll]\n- A\n- B\n[/poll]\n[poll name=foo]\n- A\n- B\n[/poll]" }
+      xhr :post, :create, title: title, raw: "[poll]\n- A\n- B\n[/poll]\n[poll name=foo]\n- A\n- B\n[/poll]"
       expect(response).to be_success
       json = ::JSON.parse(response.body)
       expect(json["cooked"]).to match("data-poll-")
@@ -248,14 +248,14 @@ describe PostsController do
     end
 
     it "should have a name" do
-      xhr :post, :create, { title: title, raw: "[poll]\n- A\n- B\n[/poll]\n[poll]\n- A\n- B\n[/poll]" }
+      xhr :post, :create, title: title, raw: "[poll]\n- A\n- B\n[/poll]\n[poll]\n- A\n- B\n[/poll]"
       expect(response).not_to be_success
       json = ::JSON.parse(response.body)
       expect(json["errors"][0]).to eq(I18n.t("poll.multiple_polls_without_name"))
     end
 
     it "should have unique name" do
-      xhr :post, :create, { title: title, raw: "[poll name=foo]\n- A\n- B\n[/poll]\n[poll name=foo]\n- A\n- B\n[/poll]" }
+      xhr :post, :create, title: title, raw: "[poll name=foo]\n- A\n- B\n[/poll]\n[poll name=foo]\n- A\n- B\n[/poll]"
       expect(response).not_to be_success
       json = ::JSON.parse(response.body)
       expect(json["errors"][0]).to eq(I18n.t("poll.multiple_polls_with_same_name", name: "foo"))
diff --git a/plugins/poll/spec/integration/poll_endpoints_spec.rb b/plugins/poll/spec/integration/poll_endpoints_spec.rb
index 47c6080585d..67e247e4f21 100644
--- a/plugins/poll/spec/integration/poll_endpoints_spec.rb
+++ b/plugins/poll/spec/integration/poll_endpoints_spec.rb
@@ -13,10 +13,8 @@ describe "DiscoursePoll endpoints" do
         user
       )
 
-      get "/polls/voters.json", {
-        post_id: post.id,
-        poll_name: DiscoursePoll::DEFAULT_POLL_NAME
-      }
+      get "/polls/voters.json",         post_id: post.id,
+                                        poll_name: DiscoursePoll::DEFAULT_POLL_NAME
 
       expect(response.status).to eq(200)
 
@@ -36,11 +34,9 @@ describe "DiscoursePoll endpoints" do
         user
       )
 
-      get "/polls/voters.json", {
-        post_id: post.id,
-        poll_name: DiscoursePoll::DEFAULT_POLL_NAME,
-        option_id: 'e89dec30bbd9bf50fabf6a05b4324edf'
-      }
+      get "/polls/voters.json",         post_id: post.id,
+                                        poll_name: DiscoursePoll::DEFAULT_POLL_NAME,
+                                        option_id: 'e89dec30bbd9bf50fabf6a05b4324edf'
 
       expect(response.status).to eq(200)
 
@@ -57,7 +53,7 @@ describe "DiscoursePoll endpoints" do
 
     describe 'when post_id is blank' do
       it 'should raise the right error' do
-        expect { get "/polls/voters.json", { poll_name: DiscoursePoll::DEFAULT_POLL_NAME } }
+        expect { get "/polls/voters.json", poll_name: DiscoursePoll::DEFAULT_POLL_NAME }
           .to raise_error(ActionController::ParameterMissing)
       end
     end
@@ -65,17 +61,15 @@ describe "DiscoursePoll endpoints" do
     describe 'when post_id is not valid' do
       it 'should raise the right error' do
         expect do
-          get "/polls/voters.json", {
-            post_id: -1,
-            poll_name: DiscoursePoll::DEFAULT_POLL_NAME
-          }
+          get "/polls/voters.json",             post_id: -1,
+                                                poll_name: DiscoursePoll::DEFAULT_POLL_NAME
         end.to raise_error(Discourse::InvalidParameters, 'post_id is invalid')
       end
     end
 
     describe 'when poll_name is blank' do
       it 'should raise the right error' do
-        expect { get "/polls/voters.json", { post_id: post.id } }
+        expect { get "/polls/voters.json", post_id: post.id }
           .to raise_error(ActionController::ParameterMissing)
       end
     end
@@ -101,10 +95,8 @@ describe "DiscoursePoll endpoints" do
           user
         )
 
-        get "/polls/voters.json", {
-          post_id: post.id,
-          poll_name: DiscoursePoll::DEFAULT_POLL_NAME
-        }
+        get "/polls/voters.json",           post_id: post.id,
+                                            poll_name: DiscoursePoll::DEFAULT_POLL_NAME
 
         expect(response.status).to eq(200)
 
diff --git a/plugins/poll/spec/lib/polls_validator_spec.rb b/plugins/poll/spec/lib/polls_validator_spec.rb
index 629fc0527af..a4d6fc27b63 100644
--- a/plugins/poll/spec/lib/polls_validator_spec.rb
+++ b/plugins/poll/spec/lib/polls_validator_spec.rb
@@ -71,7 +71,6 @@ describe ::DiscoursePoll::PollsValidator do
       )
     end
 
-
     it 'should ensure that polls have at least 2 options' do
       raw = <<~RAW
       [poll]
diff --git a/script/bench.rb b/script/bench.rb
index 9de35492a8c..84893f5ebda 100644
--- a/script/bench.rb
+++ b/script/bench.rb
@@ -64,7 +64,6 @@ end
 
 @timings = {}
 
-
 def measure(name)
   start = Time.now
   yield
@@ -100,7 +99,6 @@ unless $? == 0
   abort "Apache Bench is not installed. Try: apt-get install apache2-utils or brew install ab"
 end
 
-
 unless File.exists?("config/database.yml")
   puts "Copying database.yml.development.sample to database.yml"
   `cp config/database.yml.development-sample config/database.yml`
@@ -108,7 +106,6 @@ end
 
 ENV["RAILS_ENV"] = "profile"
 
-
 discourse_env_vars = %w(DISCOURSE_DUMP_HEAP RUBY_GC_HEAP_INIT_SLOTS RUBY_GC_HEAP_FREE_SLOTS RUBY_GC_HEAP_GROWTH_FACTOR RUBY_GC_HEAP_GROWTH_MAX_SLOTS RUBY_GC_MALLOC_LIMIT RUBY_GC_OLDMALLOC_LIMIT RUBY_GC_MALLOC_LIMIT_MAX RUBY_GC_OLDMALLOC_LIMIT_MAX RUBY_GC_MALLOC_LIMIT_GROWTH_FACTOR RUBY_GC_OLDMALLOC_LIMIT_GROWTH_FACTOR RUBY_GC_HEAP_OLDOBJECT_LIMIT_FACTOR)
 
 if @include_env
@@ -124,7 +121,7 @@ else
   end
 end
 
-def port_available? port
+def port_available?(port)
   server = TCPServer.open("0.0.0.0", port)
   server.close
   true
@@ -174,13 +171,14 @@ begin
   puts "precompiling assets"
   run("bundle exec rake assets:precompile")
 
-  pid = if @unicorn
-          ENV['UNICORN_PORT'] = @port.to_s
-          FileUtils.mkdir_p(File.join('tmp', 'pids'))
-          spawn("bundle exec unicorn -c config/unicorn.conf.rb")
-        else
-          spawn("bundle exec thin start -p #{@port}")
-        end
+  pid =
+    if @unicorn
+      ENV['UNICORN_PORT'] = @port.to_s
+      FileUtils.mkdir_p(File.join('tmp', 'pids'))
+      spawn("bundle exec unicorn -c config/unicorn.conf.rb")
+    else
+      spawn("bundle exec thin start -p #{@port}")
+    end
 
   while port_available? @port
     sleep 1
@@ -199,7 +197,7 @@ begin
     # ["user", "/u/admin1/activity"],
   ]
 
-  tests = tests.map{|k,url| ["#{k}_admin", "#{url}#{append}"]} + tests
+  tests = tests.map { |k, url| ["#{k}_admin", "#{url}#{append}"] } + tests
 
   # NOTE: we run the most expensive page first in the bench
 
@@ -210,15 +208,13 @@ begin
     a[50] < b[50] ? a : b
   end
 
-
   results = {}
   @best_of.times do
     tests.each do |name, url|
-      results[name] = best_of(bench(url, name),results[name])
+      results[name] = best_of(bench(url, name), results[name])
     end
   end
 
-
   puts "Your Results: (note for timings- percentile is first, duration is second in millisecs)"
 
   # Prevent using external facts because it breaks when running in the
@@ -226,8 +222,8 @@ begin
   Facter::Util::Config.external_facts_dirs = []
   facts = Facter.to_hash
 
-  facts.delete_if{|k,v|
-    !["operatingsystem","architecture","kernelversion",
+  facts.delete_if { |k, v|
+    !["operatingsystem", "architecture", "kernelversion",
     "memorysize", "physicalprocessorcount", "processor0",
     "virtual"].include?(k)
   }
@@ -238,15 +234,12 @@ begin
     YAML.load `ruby script/memstats.rb #{pid} --yaml`
   end
 
-
   mem = get_mem(pid)
 
-  results = results.merge({
-    "timings" => @timings,
-    "ruby-version" => "#{RUBY_VERSION}-p#{RUBY_PATCHLEVEL}",
-    "rss_kb" => mem["rss_kb"],
-    "pss_kb" => mem["pss_kb"]
-  }).merge(facts)
+  results = results.merge("timings" => @timings,
+                          "ruby-version" => "#{RUBY_VERSION}-p#{RUBY_PATCHLEVEL}",
+                          "rss_kb" => mem["rss_kb"],
+                          "pss_kb" => mem["pss_kb"]).merge(facts)
 
   if @unicorn
     child_pids = `ps --ppid #{pid} | awk '{ print $1; }' | grep -v PID`.split("\n")
@@ -270,7 +263,7 @@ begin
   end
 
   if @result_file
-    File.open(@result_file,"wb") do |f|
+    File.open(@result_file, "wb") do |f|
       f.write(results)
     end
   end
diff --git a/script/benchmarks/markdown/bench.rb b/script/benchmarks/markdown/bench.rb
index a69318ec19d..74926c95a2a 100644
--- a/script/benchmarks/markdown/bench.rb
+++ b/script/benchmarks/markdown/bench.rb
@@ -4,7 +4,6 @@ require File.expand_path('../../../../config/environment', __FILE__)
 # set any flags here
 # MiniRacer::Platform.set_flags! :noturbo
 
-
 tests = [
   ["tiny post", "**hello**"],
   ["giant post", File.read("giant_post.md")],
@@ -28,7 +27,7 @@ PrettyText.v8.eval("window.commonmark = window.markdownit('commonmark')")
 # exit
 
 Benchmark.ips do |x|
-  [true,false].each do |sanitize|
+  [true, false].each do |sanitize|
     tests.each do |test, text|
       x.report("#{test} sanitize: #{sanitize}") do
         PrettyText.markdown(text, sanitize: sanitize)
@@ -36,7 +35,6 @@ Benchmark.ips do |x|
     end
   end
 
-
   tests.each do |test, text|
     x.report("markdown it no extensions commonmark #{test}") do
       PrettyText.v8.eval("window.commonmark.render(#{text.inspect})")
@@ -44,7 +42,6 @@ Benchmark.ips do |x|
   end
 end
 
-
 # 27-07-2017 - Sam's NUC
 #
 # v8 5.7
@@ -131,4 +128,3 @@ end
 #                           1.448k (± 6.7%) i/s -      7.239k in   5.024831s
 # markdown it no extensions commonmark lots of mentions
 #                           1.986k (± 5.2%) i/s -      9.990k in   5.044624s
-
diff --git a/script/bulk_import/base.rb b/script/bulk_import/base.rb
index 377eb8b20a5..7ed396c2fa7 100644
--- a/script/bulk_import/base.rb
+++ b/script/bulk_import/base.rb
@@ -10,7 +10,7 @@ module BulkImport; end
 class BulkImport::Base
 
   NOW ||= "now()".freeze
-  PRIVATE_OFFSET ||= 2 ** 30
+  PRIVATE_OFFSET ||= 2**30
 
   def initialize
     db = ActiveRecord::Base.connection_config
@@ -477,7 +477,7 @@ class BulkImport::Base
     start = Time.now
     imported_ids = []
     process_method_name = "process_#{name}"
-    sql = "COPY #{name.pluralize} (#{columns.map {|c| "\"#{c}\""}.join(",")}) FROM STDIN"
+    sql = "COPY #{name.pluralize} (#{columns.map { |c| "\"#{c}\"" }.join(",")}) FROM STDIN"
 
     @raw_connection.copy_data(sql, @encoder) do
       rows.each do |row|
diff --git a/script/diff_heaps.rb b/script/diff_heaps.rb
index e854f2f65ae..947f4b02b36 100644
--- a/script/diff_heaps.rb
+++ b/script/diff_heaps.rb
@@ -30,11 +30,10 @@ end
 
 diff.group_by do |x|
   [x["type"], x["file"], x["line"]]
-end.map {|x,y|
- [x, y.count]
-}.sort{ |a,b|
- b[1] <=> a[1]
-}.each{ |x,y|
+end.map { |x, y|
+  [x, y.count]
+}.sort { |a, b|
+  b[1] <=> a[1]
+}.each { |x, y|
   puts "Leaked #{y} #{x[0]} objects at: #{x[1]}:#{x[2]}"
 }
-
diff --git a/script/discourse b/script/discourse
index c07d6685ef4..7bbb2714abe 100755
--- a/script/discourse
+++ b/script/discourse
@@ -28,8 +28,8 @@ class DiscourseCLI < Thor
 
     discourse remap --regex "\[\/?color(=[^\]]*)*]" "" # removing "color" bbcodes
   LONGDESC
-  option :global, :type => :boolean
-  option :regex, :type => :boolean
+  option :global, type: :boolean
+  option :regex, type: :boolean
   def remap(from, to)
     load_rails
 
@@ -48,7 +48,7 @@ class DiscourseCLI < Thor
 
     if options[:global]
       RailsMultisite::ConnectionManagement.each_connection do |db|
-        puts "","Remapping tables on #{db}...",""
+        puts "", "Remapping tables on #{db}...", ""
         do_remap(from, to, options[:regex])
       end
     else
@@ -85,7 +85,7 @@ class DiscourseCLI < Thor
   end
 
   desc "restore", "Restore a Discourse backup"
-  def restore(filename=nil)
+  def restore(filename = nil)
 
     if !filename
       puts "You must provide a filename to restore. Did you mean one of the following?\n\n"
@@ -175,7 +175,7 @@ class DiscourseCLI < Thor
   end
 
   desc "export_category", "Export a category, all its topics, and all users who posted in those topics"
-  def export_category(category_id, filename=nil)
+  def export_category(category_id, filename = nil)
     raise "Category id argument is missing!" unless category_id
 
     load_rails
@@ -225,7 +225,7 @@ class DiscourseCLI < Thor
     require File.expand_path(File.dirname(__FILE__) + "/../lib/import_export/import_export")
   end
 
-  def do_remap(from, to, regex=false)
+  def do_remap(from, to, regex = false)
     sql = "SELECT table_name, column_name
 FROM information_schema.columns
 WHERE table_schema='public' and (data_type like 'char%' or data_type like 'text%') and is_updatable = 'YES'"
@@ -257,7 +257,6 @@ WHERE table_schema='public' and (data_type like 'char%' or data_type like 'text%
     end
   end
 
-
 end
 
 DiscourseCLI.start(ARGV)
diff --git a/script/import_scripts/askbot.rb b/script/import_scripts/askbot.rb
index ec0cfc7cb8c..5620f0aa294 100644
--- a/script/import_scripts/askbot.rb
+++ b/script/import_scripts/askbot.rb
@@ -24,11 +24,11 @@ class ImportScripts::MyAskBot < ImportScripts::Base
     @tagmap = []
     @td = PG::TextDecoder::TimestampWithTimeZone.new
     @client = PG.connect(
-      :dbname   => DB_NAME,
-      :host     => DB_HOST,
-      :port     => DB_PORT,
-      :user     => DB_USER,
-      :password => DB_PASS
+      dbname: DB_NAME,
+      host: DB_HOST,
+      port: DB_PORT,
+      user: DB_USER,
+      password: DB_PASS
     )
   end
 
@@ -79,7 +79,7 @@ class ImportScripts::MyAskBot < ImportScripts::Base
         tid = tag["thread_id"].to_i
         tnm = tag["name"].downcase
         if @tagmap[tid]
-          @tagmap[tid].push( tnm )
+          @tagmap[tid].push(tnm)
         else
           @tagmap[tid] = [ tnm ]
         end
@@ -110,7 +110,7 @@ class ImportScripts::MyAskBot < ImportScripts::Base
 
       break if users.ntuples() < 1
 
-      next if all_records_exist? :users, users.map {|u| u["id"].to_i}
+      next if all_records_exist? :users, users.map { |u| u["id"].to_i }
 
       create_users(users, total: total_count, offset: offset) do |user|
         {
@@ -155,7 +155,7 @@ class ImportScripts::MyAskBot < ImportScripts::Base
 
       break if posts.ntuples() < 1
 
-      next if all_records_exist? :posts, posts.map {|p| p["id"].to_i}
+      next if all_records_exist? :posts, posts.map { |p| p["id"].to_i }
 
       create_posts(posts, total: post_count, offset: offset) do |post|
         pid = post["id"]
@@ -174,7 +174,7 @@ class ImportScripts::MyAskBot < ImportScripts::Base
           id: pid,
           title: post["title"],
           category: cat,
-          custom_fields: {import_id: pid, import_thread_id: tid, import_tags: tags},
+          custom_fields: { import_id: pid, import_thread_id: tid, import_tags: tags },
           user_id: user_id_from_imported_user_id(post["author_id"]) || Discourse::SYSTEM_USER_ID,
           created_at: Time.zone.at(@td.decode(post["added_at"])),
           raw: post["text"],
@@ -210,7 +210,7 @@ class ImportScripts::MyAskBot < ImportScripts::Base
 
       break if posts.ntuples() < 1
 
-      next if all_records_exist? :posts, posts.map {|p| p["id"].to_i}
+      next if all_records_exist? :posts, posts.map { |p| p["id"].to_i }
 
       create_posts(posts, total: post_count, offset: offset) do |post|
         tid = post["thread_id"].to_i
@@ -220,7 +220,7 @@ class ImportScripts::MyAskBot < ImportScripts::Base
         {
           id: pid,
           topic_id: parent[:topic_id],
-          custom_fields: {import_id: pid},
+          custom_fields: { import_id: pid },
           user_id: user_id_from_imported_user_id(post["author_id"]) || Discourse::SYSTEM_USER_ID,
           created_at: Time.zone.at(@td.decode(post["added_at"])),
           raw: post["text"]
@@ -230,47 +230,48 @@ class ImportScripts::MyAskBot < ImportScripts::Base
   end
 
   def post_process_posts
-      puts "", "Postprocessing posts..."
-      current = 0
-      max = Post.count
-      # Rewrite internal links; e.g.
-      # ask.cvxr.com/question/(\d+)/[^'"}]*
-      # I am sure this is incomplete, but we didn't make heavy use of internal
-      # links on our site.
-      tmp = Regexp.quote("http://" << OLD_SITE)
-      r1 = /"(#{tmp})?\/question\/(\d+)\/[a-zA-Z-]*\/?"/
-      r2 = /\((#{tmp})?\/question\/(\d+)\/[a-zA-Z-]*\/?\)/
-      r3 = /?/
-      Post.find_each do |post|
-        raw = post.raw.gsub(r1) do
-          if topic = topic_lookup_from_imported_post_id($2)
-            "\"#{topic[:url]}\""
-          else
-            $&
-          end
+    puts "", "Postprocessing posts..."
+    current = 0
+    max = Post.count
+    # Rewrite internal links; e.g.
+    # ask.cvxr.com/question/(\d+)/[^'"}]*
+    # I am sure this is incomplete, but we didn't make heavy use of internal
+    # links on our site.
+    tmp = Regexp.quote("http://" << OLD_SITE)
+    r1 = /"(#{tmp})?\/question\/(\d+)\/[a-zA-Z-]*\/?"/
+    r2 = /\((#{tmp})?\/question\/(\d+)\/[a-zA-Z-]*\/?\)/
+    r3 = /?/
+    Post.find_each do |post|
+      raw = post.raw.gsub(r1) do
+        if topic = topic_lookup_from_imported_post_id($2)
+          "\"#{topic[:url]}\""
+        else
+          $&
         end
-        raw = raw.gsub(r2) do
-          if topic = topic_lookup_from_imported_post_id($2)
-            "(#{topic[:url]})"
-          else
-            $&
-          end
-        end
-        raw = raw.gsub(r3) do
-           if topic = topic_lookup_from_imported_post_id($1)
-            trec = Topic.find_by(id: topic[:topic_id])
-            "[#{trec.title}](#{topic[:url]})"
-          else
-            $&
-          end
-        end
-        if raw != post.raw
-          post.raw = raw
-          post.save
-        end
-        print_status(current += 1, max)
       end
+      raw = raw.gsub(r2) do
+        if topic = topic_lookup_from_imported_post_id($2)
+          "(#{topic[:url]})"
+        else
+          $&
+        end
+      end
+      raw = raw.gsub(r3) do
+        if topic = topic_lookup_from_imported_post_id($1)
+          trec = Topic.find_by(id: topic[:topic_id])
+          "[#{trec.title}](#{topic[:url]})"
+        else
+          $&
+        end
+      end
+
+      if raw != post.raw
+        post.raw = raw
+        post.save
+      end
+      print_status(current += 1, max)
     end
   end
+end
 
 ImportScripts::MyAskBot.new.perform
diff --git a/script/import_scripts/base.rb b/script/import_scripts/base.rb
index 4acd2b76a0c..b156a0f70c8 100644
--- a/script/import_scripts/base.rb
+++ b/script/import_scripts/base.rb
@@ -30,7 +30,7 @@ class ImportScripts::Base
     @bbcode_to_md = true if use_bbcode_to_md?
     @site_settings_during_import = {}
     @old_site_settings = {}
-    @start_times = {import: Time.now}
+    @start_times = { import: Time.now }
   end
 
   def preload_i18n
@@ -56,7 +56,7 @@ class ImportScripts::Base
     reset_topic_counters
 
     elapsed = Time.now - @start_times[:import]
-    puts '', '', 'Done (%02dh %02dmin %02dsec)' % [elapsed/3600, elapsed/60%60, elapsed%60]
+    puts '', '', 'Done (%02dh %02dmin %02dsec)' % [elapsed / 3600, elapsed / 60 % 60, elapsed % 60]
 
   ensure
     reset_site_settings
@@ -118,7 +118,7 @@ class ImportScripts::Base
     delegate method_name, to: :@lookup
   end
 
-  def create_admin(opts={})
+  def create_admin(opts = {})
     admin = User.new
     admin.email = opts[:email] || "sam.saffron@gmail.com"
     admin.username = opts[:username] || "sam"
@@ -140,7 +140,7 @@ class ImportScripts::Base
   # Required fields are :id and :name, where :id is the id of the
   # group in the original datasource. The given id will not be used
   # to create the Discourse group record.
-  def create_groups(results, opts={})
+  def create_groups(results, opts = {})
     created = 0
     skipped = 0
     failed = 0
@@ -171,12 +171,12 @@ class ImportScripts::Base
   end
 
   def create_group(opts, import_id)
-    opts = opts.dup.tap {|o| o.delete(:id) }
+    opts = opts.dup.tap { |o| o.delete(:id) }
     import_name = opts[:name]
     opts[:name] = UserNameSuggester.suggest(import_name)
 
     existing = Group.where(name: opts[:name]).first
-    return existing if existing and existing.custom_fields["import_id"].to_i == import_id.to_i
+    return existing if existing && existing.custom_fields["import_id"].to_i == (import_id.to_i)
     g = existing || Group.new(opts)
     g.custom_fields["import_id"] = import_id
     g.custom_fields["import_name"] = import_name
@@ -196,8 +196,8 @@ class ImportScripts::Base
 
     existing = "#{type.to_s.classify}CustomField".constantize
     existing = existing.where(name: 'import_id')
-                       .joins('JOIN import_ids ON val = value')
-                       .count
+      .joins('JOIN import_ids ON val = value')
+      .count
     if existing == import_ids.length
       puts "Skipping #{import_ids.length} already imported #{type}"
       return true
@@ -216,7 +216,7 @@ class ImportScripts::Base
   # Required fields are :id and :email, where :id is the id of the
   # user in the original datasource. The given id will not be used to
   # create the Discourse user record.
-  def create_users(results, opts={})
+  def create_users(results, opts = {})
     created = 0
     skipped = 0
     failed = 0
@@ -422,7 +422,7 @@ class ImportScripts::Base
   # Attributes will be passed to the PostCreator.
   # Topics should give attributes title and category.
   # Replies should provide topic_id. Use topic_lookup_from_imported_post_id to find the topic.
-  def create_posts(results, opts={})
+  def create_posts(results, opts = {})
     skipped = 0
     created = 0
     total = opts[:total] || results.size
@@ -502,7 +502,7 @@ class ImportScripts::Base
   # Block should return a hash with the attributes for the bookmark.
   # Required fields are :user_id and :post_id, where both ids are
   # the values in the original datasource.
-  def create_bookmarks(results, opts={})
+  def create_bookmarks(results, opts = {})
     created = 0
     skipped = 0
     total = opts[:total] || results.size
@@ -539,7 +539,7 @@ class ImportScripts::Base
     [created, skipped]
   end
 
-  def close_inactive_topics(opts={})
+  def close_inactive_topics(opts = {})
     num_days = opts[:days] || 30
     puts '', "Closing topics that have been inactive for more than #{num_days} days."
 
@@ -775,7 +775,7 @@ class ImportScripts::Base
   end
 
   def get_start_time(key)
-    @start_times.fetch(key) {|k| @start_times[k] = Time.now}
+    @start_times.fetch(key) { |k| @start_times[k] = Time.now }
   end
 
   def batches(batch_size)
diff --git a/script/import_scripts/base/csv_helper.rb b/script/import_scripts/base/csv_helper.rb
index c505ce71015..e70f850bc4f 100644
--- a/script/import_scripts/base/csv_helper.rb
+++ b/script/import_scripts/base/csv_helper.rb
@@ -10,7 +10,7 @@ module ImportScripts
       end
 
       def initialize(cols)
-        cols.each_with_index do |col,idx|
+        cols.each_with_index do |col, idx|
           self.class.send(:define_method, col.downcase.gsub(/[\W]/, '_').squeeze('_')) do
             @row[idx]
           end
@@ -72,4 +72,4 @@ module ImportScripts
       end
     end
   end
-end
\ No newline at end of file
+end
diff --git a/script/import_scripts/bbpress.rb b/script/import_scripts/bbpress.rb
index e91b8ef8ae5..7b3a35afd5c 100644
--- a/script/import_scripts/bbpress.rb
+++ b/script/import_scripts/bbpress.rb
@@ -1,7 +1,6 @@
 require 'mysql2'
 require File.expand_path(File.dirname(__FILE__) + "/base.rb")
 
-
 # Before running this script, paste these lines into your shell,
 # then use arrow keys to edit the values
 =begin
@@ -125,7 +124,7 @@ class ImportScripts::Bbpress < ImportScripts::Base
     end
 
     # gather every existent username
-    anon_posts.each do |id,post|
+    anon_posts.each do |id, post|
       anon_names[post['name']] = Hash.new if not anon_names[post['name']]
       # overwriting email address, one user can only use one email address
       anon_names[post['name']]['email'] = post['email']
@@ -133,7 +132,7 @@ class ImportScripts::Bbpress < ImportScripts::Base
     end
 
     # make sure every user name has a unique email address
-    anon_names.each do |k,name|
+    anon_names.each do |k, name|
       if not emails.include? name['email']
         emails.push ( name['email'])
       else
@@ -141,7 +140,6 @@ class ImportScripts::Bbpress < ImportScripts::Base
       end
     end
 
-
     create_users(anon_names) do |k, n|
       {
         id: k,
diff --git a/script/import_scripts/bespoke_1.rb b/script/import_scripts/bespoke_1.rb
index 5cd1744212a..0026ff30ace 100644
--- a/script/import_scripts/bespoke_1.rb
+++ b/script/import_scripts/bespoke_1.rb
@@ -43,7 +43,7 @@ class ImportScripts::Bespoke < ImportScripts::Base
     end
 
     def initialize(cols)
-      cols.each_with_index do |col,idx|
+      cols.each_with_index do |col, idx|
         self.class.send(:define_method, col) do
           @row[idx]
         end
@@ -71,7 +71,7 @@ class ImportScripts::Bespoke < ImportScripts::Base
     File.open(filename).each_line do |line|
 
       # escaping is mental here
-      line.gsub!(/\\(.{1})/){|m| m[-1] == '"'? '""': m[-1]}
+      line.gsub!(/\\(.{1})/) { |m| m[-1] == '"' ? '""' : m[-1] }
       line.strip!
 
       current_row << "\n" unless current_row.empty?
@@ -119,7 +119,7 @@ class ImportScripts::Bespoke < ImportScripts::Base
   end
 
   def total_rows(table)
-    File.foreach("#{@path}/#{table}.csv").inject(0) {|c, line| c+1} - 1
+    File.foreach("#{@path}/#{table}.csv").inject(0) { |c, line| c + 1 } - 1
   end
 
   def import_users
@@ -169,7 +169,7 @@ class ImportScripts::Bespoke < ImportScripts::Base
   def import_categories
     rows = []
     csv_parse("categories") do |row|
-      rows << {id: row.id, name: row.name, description: row.description}
+      rows << { id: row.id, name: row.name, description: row.description }
     end
 
     create_categories(rows) do |row|
@@ -181,46 +181,46 @@ class ImportScripts::Bespoke < ImportScripts::Base
     # purple and #1223f3
     raw.gsub!(/\[color=[#a-z0-9]+\]/i, "")
     raw.gsub!(/\[\/color\]/i, "")
-    raw.gsub!(/\[signature\].+\[\/signature\]/im,"")
+    raw.gsub!(/\[signature\].+\[\/signature\]/im, "")
     raw
   end
 
   def import_post_batch!(posts, topics, offset, total)
-      create_posts(posts, total: total, offset: offset) do |post|
+    create_posts(posts, total: total, offset: offset) do |post|
 
-        mapped = {}
+      mapped = {}
 
-        mapped[:id] = post[:id]
-        mapped[:user_id] = user_id_from_imported_user_id(post[:user_id]) || -1
-        mapped[:raw] = post[:body]
-        mapped[:created_at] = post[:created_at]
+      mapped[:id] = post[:id]
+      mapped[:user_id] = user_id_from_imported_user_id(post[:user_id]) || -1
+      mapped[:raw] = post[:body]
+      mapped[:created_at] = post[:created_at]
 
-        topic = topics[post[:topic_id]]
+      topic = topics[post[:topic_id]]
 
-        unless topic[:post_id]
-          mapped[:category] = category_id_from_imported_category_id(topic[:category_id])
-          mapped[:title] = post[:title]
-          topic[:post_id] = post[:id]
-        else
-          parent = topic_lookup_from_imported_post_id(topic[:post_id])
-          next unless parent
+      unless topic[:post_id]
+        mapped[:category] = category_id_from_imported_category_id(topic[:category_id])
+        mapped[:title] = post[:title]
+        topic[:post_id] = post[:id]
+      else
+        parent = topic_lookup_from_imported_post_id(topic[:post_id])
+        next unless parent
 
-          mapped[:topic_id] = parent[:topic_id]
+        mapped[:topic_id] = parent[:topic_id]
 
-          reply_to_post_id = post_id_from_imported_post_id(post[:reply_id])
-          if reply_to_post_id
-            reply_to_post_number = @post_number_map[reply_to_post_id]
-            if reply_to_post_number && reply_to_post_number > 1
-              mapped[:reply_to_post_number] = reply_to_post_number
-            end
+        reply_to_post_id = post_id_from_imported_post_id(post[:reply_id])
+        if reply_to_post_id
+          reply_to_post_number = @post_number_map[reply_to_post_id]
+          if reply_to_post_number && reply_to_post_number > 1
+            mapped[:reply_to_post_number] = reply_to_post_number
           end
         end
-
-        next if topic[:deleted] or post[:deleted]
-
-        mapped
       end
 
+      next if topic[:deleted] || post[:deleted]
+
+      mapped
+    end
+
       posts.clear
   end
 
@@ -262,7 +262,7 @@ class ImportScripts::Bespoke < ImportScripts::Base
         created_at: DateTime.parse(row.dcreate)
       }
       posts << row
-      count+=1
+      count += 1
 
       if posts.length > 0 && posts.length % BATCH_SIZE == 0
         import_post_batch!(posts, topic_map, count - posts.length, total)
@@ -274,7 +274,6 @@ class ImportScripts::Bespoke < ImportScripts::Base
     exit
   end
 
-
 end
 
 unless ARGV[0] && Dir.exist?(ARGV[0])
diff --git a/script/import_scripts/discuz_x.rb b/script/import_scripts/discuz_x.rb
index 791b6c38da2..8ee30b359cd 100644
--- a/script/import_scripts/discuz_x.rb
+++ b/script/import_scripts/discuz_x.rb
@@ -176,11 +176,11 @@ class ImportScripts::DiscuzX < ImportScripts::Base
           last_posted_at: user['last_posted_at'],
           moderator: @moderator_group_id.include?(user['group_id']),
           admin: @admin_group_id.include?(user['group_id']),
-          website: (user['website'] and user['website'].include?('.')) ? user['website'].strip : ( user['qq'] and user['qq'].strip == user['qq'].strip.to_i and user['qq'].strip.to_i > 10000 ) ? 'http://user.qzone.qq.com/' + user['qq'].strip : nil,
-          bio_raw: first_exists((user['bio'] and CGI.unescapeHTML(user['bio'])), user['sightml'], user['spacenote']).strip[0,3000],
-          location: first_exists(user['address'], (!user['resideprovince'].blank? ? [user['resideprovince'],  user['residecity'], user['residedist'], user['residecommunity']] : [user['birthprovince'],  user['birthcity'], user['birthdist'], user['birthcommunity']]).reject{|location|location.blank?}.join(' ')),
+          website: (user['website'] && user['website'].include?('.')) ? user['website'].strip : (user['qq'] && user['qq'].strip == (user['qq'].strip.to_i) && user['qq'].strip.to_i > (10000)) ? 'http://user.qzone.qq.com/' + user['qq'].strip : nil,
+          bio_raw: first_exists((user['bio'] && CGI.unescapeHTML(user['bio'])), user['sightml'], user['spacenote']).strip[0, 3000],
+          location: first_exists(user['address'], (!user['resideprovince'].blank? ? [user['resideprovince'],  user['residecity'], user['residedist'], user['residecommunity']] : [user['birthprovince'],  user['birthcity'], user['birthdist'], user['birthcommunity']]).reject { |location|location.blank? }.join(' ')),
           post_create_action: lambda do |newmember|
-            if user['avatar_exists'] == 1 and newmember.uploaded_avatar_id.blank?
+            if user['avatar_exists'] == (1) && newmember.uploaded_avatar_id.blank?
               path, filename = discuzx_avatar_fullpath(user['id'])
               if path
                 begin
@@ -199,7 +199,7 @@ class ImportScripts::DiscuzX < ImportScripts::Base
                 end
               end
             end
-            if !user['spacecss'].blank? and newmember.user_profile.profile_background.blank?
+            if !user['spacecss'].blank? && newmember.user_profile.profile_background.blank?
               # profile background
               if matched = user['spacecss'].match(/body\s*{[^}]*url\('?(.+?)'?\)/i)
                 body_background = matched[1].split(ORIGINAL_SITE_PREFIX, 2).last
@@ -234,7 +234,7 @@ class ImportScripts::DiscuzX < ImportScripts::Base
 
             # we don't send email to the unconfirmed user
             newmember.update(email_digests: user['email_confirmed'] == 1) if newmember.email_digests
-            newmember.update(name: '') if !newmember.name.blank? and newmember.name == newmember.username
+            newmember.update(name: '') if !newmember.name.blank? && newmember.name == (newmember.username)
           end
         }
       end
@@ -259,10 +259,10 @@ class ImportScripts::DiscuzX < ImportScripts::Base
 
     max_position = Category.all.max_by(&:position).position
     create_categories(results) do |row|
-      next if row['type'] == 'group' or row['status'] == 2 # or row['status'].to_i == 3 # 如果不想导入群组,取消注释
+      next if row['type'] == ('group') || row['status'] == (2) # or row['status'].to_i == 3 # 如果不想导入群组,取消注释
       extra = PHP.unserialize(row['extra']) if !row['extra'].blank?
-      if extra and !extra["namecolor"].blank?
-        color = extra["namecolor"][1,6]
+      if extra && !extra["namecolor"].blank?
+        color = extra["namecolor"][1, 6]
       end
 
       Category.all.max_by(&:position).position
@@ -273,7 +273,7 @@ class ImportScripts::DiscuzX < ImportScripts::Base
         description: row['description'],
         position: row['position'].to_i + max_position,
         color: color,
-        suppress_from_homepage: (row['status'] == 0 or row['status'] == 3),
+        suppress_from_homepage: (row['status'] == (0) || row['status'] == (3)),
         post_create_action: lambda do |category|
           if slug = @category_slug[row['id']]
             category.update(slug: slug)
@@ -289,7 +289,7 @@ class ImportScripts::DiscuzX < ImportScripts::Base
             if upload
               category.logo_url = upload.url
               # FIXME: I don't know how to get '/shared' by script. May change to Rails.root
-              category.color = Miro::DominantColors.new(File.join('/shared', category.logo_url)).to_hex.first[1,6] if !color
+              category.color = Miro::DominantColors.new(File.join('/shared', category.logo_url)).to_hex.first[1, 6] if !color
               category.save!
             end
           end
@@ -332,10 +332,10 @@ class ImportScripts::DiscuzX < ImportScripts::Base
              LIMIT #{BATCH_SIZE}
             OFFSET #{offset};
           ")
-          # u.status != -1 AND u.groupid != 4 AND u.groupid != 5 用户未被锁定、禁访或禁言。在现实中的 Discuz 论坛,禁止的用户通常是广告机或驱逐的用户,这些不需要导入。
+      # u.status != -1 AND u.groupid != 4 AND u.groupid != 5 用户未被锁定、禁访或禁言。在现实中的 Discuz 论坛,禁止的用户通常是广告机或驱逐的用户,这些不需要导入。
       break if results.size < 1
 
-      next if all_records_exist? :posts, results.map {|p| p["id"].to_i}
+      next if all_records_exist? :posts, results.map { |p| p["id"].to_i }
 
       create_posts(results, total: total_count, offset: offset) do |m|
         skip = false
@@ -364,7 +364,7 @@ class ImportScripts::DiscuzX < ImportScripts::Base
             if results.empty?
               puts "WARNING: can't find poll options for topic #{m['topic_id']}, skip poll"
             else
-              mapped[:raw].prepend "[poll#{poll['multiple'] ? ' type=multiple' : ''}#{poll['maxchoices'] > 0 ? " max=#{poll['maxchoices']}" : ''}]\n#{results.map{|option|'- ' + option['polloption']}.join("\n")}\n[/poll]\n"
+              mapped[:raw].prepend "[poll#{poll['multiple'] ? ' type=multiple' : ''}#{poll['maxchoices'] > 0 ? " max=#{poll['maxchoices']}" : ''}]\n#{results.map { |option|'- ' + option['polloption'] }.join("\n")}\n[/poll]\n"
             end
           end
         else
@@ -398,7 +398,7 @@ class ImportScripts::DiscuzX < ImportScripts::Base
           end
         elsif (m['status'] & 2) >> 1 == 1 # waiting for approve
           mapped[:post_create_action] = lambda do |post|
-            PostAction.act(Discourse.system_user, post, 6, {take_action: false})
+            PostAction.act(Discourse.system_user, post, 6, take_action: false)
           end
         end
         skip ? nil : mapped
@@ -423,7 +423,7 @@ class ImportScripts::DiscuzX < ImportScripts::Base
 
       break if results.size < 1
 
-       # next if all_records_exist?
+      # next if all_records_exist?
 
       create_bookmarks(results, total: total_count, offset: offset) do |row|
         {
@@ -434,7 +434,6 @@ class ImportScripts::DiscuzX < ImportScripts::Base
     end
   end
 
-
   def import_private_messages
     puts '', 'creating private messages'
 
@@ -494,7 +493,7 @@ class ImportScripts::DiscuzX < ImportScripts::Base
                 SELECT plid thread_id, uid user_id
                   FROM #{table_name 'ucenter_pm_members'}
                  WHERE plid = #{m['thread_id']};
-              ").map {|r| r['user_id']}.uniq
+              ").map { |r| r['user_id'] }.uniq
 
           mapped[:target_usernames] = import_user_ids.map! do |import_user_id|
             import_user_id.to_s == m['user_id'].to_s ? nil : User.find_by(id: user_id_from_imported_user_id(import_user_id)).try(:username)
@@ -587,7 +586,7 @@ class ImportScripts::DiscuzX < ImportScripts::Base
     s.gsub!(/\[img[^\]]*\]https?:\/\/#{ORIGINAL_SITE_PREFIX}\/(.*)\[\/img\]/i, '[x-attach]\1[/x-attach]') # dont convert attachment
     s.gsub!(/]*src="https?:\/\/#{ORIGINAL_SITE_PREFIX}\/(.*)".*?>/i, '[x-attach]\1[/x-attach]') # dont convert attachment
     s.gsub!(/\[img[^\]]*\]https?:\/\/www\.touhou\.cc\/blog\/(.*)\[\/img\]/i, '[x-attach]../blog/\1[/x-attach]') # 私货
-    s.gsub!(/\[img[^\]]*\]https?:\/\/www\.touhou\.cc\/ucenter\/avatar.php\?uid=(\d+)[^\]]*\[\/img\]/i) { "[x-attach]#{discuzx_avatar_fullpath($1,false)[0]}[/x-attach]" } # 私货
+    s.gsub!(/\[img[^\]]*\]https?:\/\/www\.touhou\.cc\/ucenter\/avatar.php\?uid=(\d+)[^\]]*\[\/img\]/i) { "[x-attach]#{discuzx_avatar_fullpath($1, false)[0]}[/x-attach]" } # 私货
     s.gsub!(/\[img=(\d+),(\d+)\]([^\]]*)\[\/img\]/i, '')
     s.gsub!(/\[img\]([^\]]*)\[\/img\]/i, '')
 
@@ -671,7 +670,7 @@ class ImportScripts::DiscuzX < ImportScripts::Base
     # @someone without the url
     s.gsub!(/@\[url=[^\[\]]*?\](\S*)\[\/url\]/i, '@\1')
 
-    s.scan(/http(?:s)?:\/\/#{ORIGINAL_SITE_PREFIX.gsub('.', '\.')}\/[^\[\]\s]*/) {|link|puts "WARNING: post #{import_id} can't replace internal url #{link}"}
+    s.scan(/http(?:s)?:\/\/#{ORIGINAL_SITE_PREFIX.gsub('.', '\.')}\/[^\[\]\s]*/) { |link|puts "WARNING: post #{import_id} can't replace internal url #{link}" }
 
     s.strip
   end
@@ -785,7 +784,7 @@ class ImportScripts::DiscuzX < ImportScripts::Base
           FROM #{table_name 'forum_attachment'}
           WHERE pid = #{post.custom_fields['import_id']}"
       if !inline_attachments.empty?
-          sql << " AND aid NOT IN (#{inline_attachments.join(',')})"
+        sql << " AND aid NOT IN (#{inline_attachments.join(',')})"
       end
 
       results = mysql_query(sql)
@@ -805,7 +804,7 @@ class ImportScripts::DiscuzX < ImportScripts::Base
       end
 
       if new_raw != post.raw
-        PostRevisor.new(post).revise!(post.user, { raw: new_raw }, { bypass_bump: true, edit_reason: '从 Discuz 中导入附件' })
+        PostRevisor.new(post).revise!(post.user, { raw: new_raw }, bypass_bump: true, edit_reason: '从 Discuz 中导入附件')
       end
 
       success_count += 1
@@ -818,7 +817,7 @@ class ImportScripts::DiscuzX < ImportScripts::Base
   end
 
   # Create the full path to the discuz avatar specified from user id
-  def discuzx_avatar_fullpath(user_id, absolute=true)
+  def discuzx_avatar_fullpath(user_id, absolute = true)
     padded_id = user_id.to_s.rjust(9, '0')
 
     part_1 = padded_id[0..2]
@@ -945,7 +944,7 @@ class ImportScripts::DiscuzX < ImportScripts::Base
   end
 
   def first_exists(*items)
-    items.find{|item|!item.blank?} || ''
+    items.find { |item|!item.blank? } || ''
   end
 
   def mysql_query(sql)
diff --git a/script/import_scripts/disqus.rb b/script/import_scripts/disqus.rb
index 6f0929d8588..a73febe4768 100644
--- a/script/import_scripts/disqus.rb
+++ b/script/import_scripts/disqus.rb
@@ -11,7 +11,7 @@ class ImportScripts::Disqus < ImportScripts::Base
   def initialize
     abort("File '#{IMPORT_FILE}' not found") if !File.exist?(IMPORT_FILE)
 
-    @category = Category.where(name: IMPORT_CATEGORY).first 
+    @category = Category.where(name: IMPORT_CATEGORY).first
     abort("Category #{IMPORT_CATEGORY} not found") if @category.blank?
 
     @parser = DisqusSAX.new
@@ -135,7 +135,7 @@ class DisqusSAX < Nokogiri::XML::SAX::Document
         thread = @threads[id]
         thread[:posts] << @post
       else
-        @thread = {id: id, posts: []}
+        @thread = { id: id, posts: [] }
       end
     when 'parent'
       if @post
@@ -194,7 +194,7 @@ class DisqusSAX < Nokogiri::XML::SAX::Document
   end
 
   def inside?(*params)
-    return !params.find{|p| !@inside[p]}
+    return !params.find { |p| !@inside[p] }
   end
 
   def normalize
@@ -203,7 +203,7 @@ class DisqusSAX < Nokogiri::XML::SAX::Document
         # Remove any threads that have no posts
         @threads.delete(id)
       else
-        t[:posts].delete_if {|p| p[:is_spam] == 'true' || p[:is_deleted] == 'true'}
+        t[:posts].delete_if { |p| p[:is_spam] == 'true' || p[:is_deleted] == 'true' }
       end
     end
 
diff --git a/script/import_scripts/drupal-6.rb b/script/import_scripts/drupal-6.rb
index 1df513df409..018a1fba904 100644
--- a/script/import_scripts/drupal-6.rb
+++ b/script/import_scripts/drupal-6.rb
@@ -5,7 +5,7 @@ class ImportScripts::Drupal < ImportScripts::Base
 
   DRUPAL_DB = ENV['DRUPAL_DB'] || "newsite3"
   VID = ENV['DRUPAL_VID'] || 1
-  
+
   def initialize
     super
 
@@ -23,7 +23,7 @@ class ImportScripts::Drupal < ImportScripts::Base
 
   def execute
     create_users(@client.query("SELECT uid id, name, mail email, created FROM users;")) do |row|
-      {id: row['id'], username: row['name'], email: row['email'], created_at: Time.zone.at(row['created'])}
+      { id: row['id'], username: row['name'], email: row['email'], created_at: Time.zone.at(row['created']) }
     end
 
     # You'll need to edit the following query for your Drupal install:
@@ -32,7 +32,7 @@ class ImportScripts::Drupal < ImportScripts::Base
     #   * Table name may be term_data.
     #   * May need to select a vid other than 1.
     create_categories(categories_query) do |c|
-      {id: c['tid'], name: c['name'], description: c['description']}
+      { id: c['tid'], name: c['name'], description: c['description'] }
     end
 
     # "Nodes" in Drupal are divided into types. Here we import two types,
@@ -65,8 +65,8 @@ class ImportScripts::Drupal < ImportScripts::Base
 
     results = @client.query("
       SELECT n.nid nid,
-	n.title title, 
-	n.uid uid, 
+	n.title title,
+	n.uid uid,
 	n.created created,
 	n.sticky sticky,
 	nr.body body
@@ -85,7 +85,7 @@ class ImportScripts::Drupal < ImportScripts::Base
         created_at: Time.zone.at(row['created']),
         pinned_at: row['sticky'].to_i == 1 ? Time.zone.at(row['created']) : nil,
         title: row['title'].try(:strip),
-        custom_fields: {import_id: "nid:#{row['nid']}"}
+        custom_fields: { import_id: "nid:#{row['nid']}" }
       }
     end
   end
@@ -123,7 +123,7 @@ class ImportScripts::Drupal < ImportScripts::Base
 
       break if results.size < 1
 
-      next if all_records_exist? :posts, results.map {|p| "nid:#{p['nid']}"}
+      next if all_records_exist? :posts, results.map { |p| "nid:#{p['nid']}" }
 
       create_posts(results, total: total_count, offset: offset) do |row|
         {
@@ -141,7 +141,7 @@ class ImportScripts::Drupal < ImportScripts::Base
 
   def create_replies
     puts '', "creating replies in topics"
-    
+
     if ENV['DRUPAL_IMPORT_BLOG']
       node_types = "('forum','blog')"
     else
@@ -149,7 +149,7 @@ class ImportScripts::Drupal < ImportScripts::Base
     end
 
     total_count = @client.query("
-      SELECT COUNT(*) count 
+      SELECT COUNT(*) count
       FROM comments c
       LEFT JOIN node n ON n.nid=c.nid
       WHERE node.type IN #{node_types}
@@ -167,18 +167,18 @@ class ImportScripts::Drupal < ImportScripts::Base
                c.uid,
                c.timestamp,
                c.comment body
-        FROM comments c 
+        FROM comments c
         LEFT JOIN node n ON n.nid=c.nid
         WHERE n.type IN #{node_types}
           AND n.status = 1
-          AND c.status=0 
+          AND c.status=0
         LIMIT #{batch_size}
           OFFSET #{offset};
       ", cache_rows: false)
 
       break if results.size < 1
 
-      next if all_records_exist? :posts, results.map {|p| "cid:#{p['cid']}"}
+      next if all_records_exist? :posts, results.map { |p| "cid:#{p['cid']}" }
 
       create_posts(results, total: total_count, offset: offset) do |row|
         topic_mapping = topic_lookup_from_imported_post_id("nid:#{row['nid']}")
@@ -192,7 +192,7 @@ class ImportScripts::Drupal < ImportScripts::Base
           }
           if row['pid']
             parent = topic_lookup_from_imported_post_id("cid:#{row['pid']}")
-            h[:reply_to_post_number] = parent[:post_number] if parent and parent[:post_number] > 1
+            h[:reply_to_post_number] = parent[:post_number] if parent && parent[:post_number] > (1)
           end
           h
         else
@@ -205,6 +205,6 @@ class ImportScripts::Drupal < ImportScripts::Base
 
 end
 
-if __FILE__==$0
+if __FILE__ == $0
   ImportScripts::Drupal.new.perform
 end
diff --git a/script/import_scripts/drupal.rb b/script/import_scripts/drupal.rb
index a15933b10c1..6b773486d00 100644
--- a/script/import_scripts/drupal.rb
+++ b/script/import_scripts/drupal.rb
@@ -23,7 +23,7 @@ class ImportScripts::Drupal < ImportScripts::Base
 
   def execute
     create_users(@client.query("SELECT uid id, name, mail email, created FROM users;")) do |row|
-      {id: row['id'], username: row['name'], email: row['email'], created_at: Time.zone.at(row['created'])}
+      { id: row['id'], username: row['name'], email: row['email'], created_at: Time.zone.at(row['created']) }
     end
 
     # You'll need to edit the following query for your Drupal install:
@@ -32,7 +32,7 @@ class ImportScripts::Drupal < ImportScripts::Base
     #   * Table name may be term_data.
     #   * May need to select a vid other than 1.
     create_categories(categories_query) do |c|
-      {id: c['tid'], name: c['name'], description: c['description']}
+      { id: c['tid'], name: c['name'], description: c['description'] }
     end
 
     # "Nodes" in Drupal are divided into types. Here we import two types,
@@ -82,7 +82,7 @@ class ImportScripts::Drupal < ImportScripts::Base
         created_at: Time.zone.at(row['created']),
         pinned_at: row['sticky'].to_i == 1 ? Time.zone.at(row['created']) : nil,
         title: row['title'].try(:strip),
-        custom_fields: {import_id: "nid:#{row['nid']}"}
+        custom_fields: { import_id: "nid:#{row['nid']}" }
       }
     end
   end
@@ -121,7 +121,7 @@ class ImportScripts::Drupal < ImportScripts::Base
 
       break if results.size < 1
 
-      next if all_records_exist? :posts, results.map {|p| "nid:#{p['nid']}"}
+      next if all_records_exist? :posts, results.map { |p| "nid:#{p['nid']}" }
 
       create_posts(results, total: total_count, offset: offset) do |row|
         {
@@ -169,7 +169,7 @@ class ImportScripts::Drupal < ImportScripts::Base
 
       break if results.size < 1
 
-      next if all_records_exist? :posts, results.map {|p| "cid:#{p['cid']}"}
+      next if all_records_exist? :posts, results.map { |p| "cid:#{p['cid']}" }
 
       create_posts(results, total: total_count, offset: offset) do |row|
         topic_mapping = topic_lookup_from_imported_post_id("nid:#{row['nid']}")
@@ -183,7 +183,7 @@ class ImportScripts::Drupal < ImportScripts::Base
           }
           if row['pid']
             parent = topic_lookup_from_imported_post_id("cid:#{row['pid']}")
-            h[:reply_to_post_number] = parent[:post_number] if parent and parent[:post_number] > 1
+            h[:reply_to_post_number] = parent[:post_number] if parent && parent[:post_number] > (1)
           end
           h
         else
@@ -196,6 +196,6 @@ class ImportScripts::Drupal < ImportScripts::Base
 
 end
 
-if __FILE__==$0
+if __FILE__ == $0
   ImportScripts::Drupal.new.perform
 end
diff --git a/script/import_scripts/drupal_json.rb b/script/import_scripts/drupal_json.rb
index ac40525caf6..d99fb86f871 100644
--- a/script/import_scripts/drupal_json.rb
+++ b/script/import_scripts/drupal_json.rb
@@ -8,7 +8,7 @@ class ImportScripts::DrupalJson < ImportScripts::Base
 
   def initialize
     super
-    @users_json  = load_json("formatted_users.json")
+    @users_json = load_json("formatted_users.json")
   end
 
   def execute
@@ -40,6 +40,6 @@ class ImportScripts::DrupalJson < ImportScripts::Base
   end
 end
 
-if __FILE__==$0
+if __FILE__ == $0
   ImportScripts::DrupalJson.new.perform
 end
diff --git a/script/import_scripts/drupal_qa.rb b/script/import_scripts/drupal_qa.rb
index 9899f73ad5e..98d79198646 100644
--- a/script/import_scripts/drupal_qa.rb
+++ b/script/import_scripts/drupal_qa.rb
@@ -56,7 +56,7 @@ class ImportScripts::DrupalQA < ImportScripts::Drupal
 
       break if results.size < 1
 
-      next if all_records_exist? :posts, results.map {|p| "nid:#{p['nid']}"}
+      next if all_records_exist? :posts, results.map { |p| "nid:#{p['nid']}" }
 
       create_posts(results, total: total_count, offset: offset) do |row|
         {
@@ -102,7 +102,7 @@ class ImportScripts::DrupalQA < ImportScripts::Drupal
 
       break if results.size < 1
 
-      next if all_records_exist? :posts, results.map {|p| "cid:#{p['cid']}"}
+      next if all_records_exist? :posts, results.map { |p| "cid:#{p['cid']}" }
 
       create_posts(results, total: total_count, offset: offset) do |row|
         topic_mapping = topic_lookup_from_imported_post_id("nid:#{row['nid']}")
@@ -155,7 +155,7 @@ class ImportScripts::DrupalQA < ImportScripts::Drupal
 
       break if results.size < 1
 
-      next if all_records_exist? :posts, results.map {|p| "cid:#{p['cid']}"}
+      next if all_records_exist? :posts, results.map { |p| "cid:#{p['cid']}" }
 
       create_posts(results, total: total_count, offset: offset) do |row|
         topic_mapping = topic_lookup_from_imported_post_id("nid:#{row['nid']}")
@@ -207,7 +207,7 @@ class ImportScripts::DrupalQA < ImportScripts::Drupal
 
       break if results.size < 1
 
-      next if all_records_exist? :posts, results.map {|p| "cid:#{p['cid']}"}
+      next if all_records_exist? :posts, results.map { |p| "cid:#{p['cid']}" }
 
       create_posts(results, total: total_count, offset: offset) do |row|
         topic_mapping = topic_lookup_from_imported_post_id("nid:#{row['nid']}")
@@ -235,6 +235,6 @@ class ImportScripts::DrupalQA < ImportScripts::Drupal
 
 end
 
-if __FILE__==$0
+if __FILE__ == $0
   ImportScripts::DrupalQA.new.perform
 end
diff --git a/script/import_scripts/fluxbb.rb b/script/import_scripts/fluxbb.rb
index d754c5db0c7..7b886447153 100644
--- a/script/import_scripts/fluxbb.rb
+++ b/script/import_scripts/fluxbb.rb
@@ -74,7 +74,7 @@ class ImportScripts::FluxBB < ImportScripts::Base
 
       break if results.size < 1
 
-      next if all_records_exist? :users, results.map {|u| u["id"].to_i}
+      next if all_records_exist? :users, results.map { |u| u["id"].to_i }
 
       create_users(results, total: total_count, offset: offset) do |user|
         { id: user['id'],
@@ -91,7 +91,7 @@ class ImportScripts::FluxBB < ImportScripts::Base
           admin: user['group_id'] == 1 }
       end
 
-      groupusers = results.select{ |user| user['group_id'] > 2 }
+      groupusers = results.select { |user| user['group_id'] > 2 }
 
       groupusers.each do |user|
         if user['group_id']
@@ -164,7 +164,7 @@ class ImportScripts::FluxBB < ImportScripts::Base
       ").to_a
 
       break if results.size < 1
-      next if all_records_exist? :posts, results.map {|m| m['id'].to_i}
+      next if all_records_exist? :posts, results.map { |m| m['id'].to_i }
 
       create_posts(results, total: total_count, offset: offset) do |m|
         skip = false
diff --git a/script/import_scripts/getsatisfaction.rb b/script/import_scripts/getsatisfaction.rb
index de5ff13a62b..ffa0b0388e8 100644
--- a/script/import_scripts/getsatisfaction.rb
+++ b/script/import_scripts/getsatisfaction.rb
@@ -37,7 +37,6 @@ class ImportScripts::GetSatisfaction < ImportScripts::Base
     super
   end
 
-
   def execute
     c = Category.find_by(name: 'Old Forum') ||
       Category.create!(name: 'Old Forum', user: Discourse.system_user)
@@ -61,7 +60,7 @@ class ImportScripts::GetSatisfaction < ImportScripts::Base
     end
 
     def initialize(cols)
-      cols.each_with_index do |col,idx|
+      cols.each_with_index do |col, idx|
         self.class.send(:define_method, col) do
           @row[idx]
         end
@@ -134,7 +133,7 @@ class ImportScripts::GetSatisfaction < ImportScripts::Base
   def total_rows(table)
     # In case of Excel export file, I converted it to CSV and used:
     # CSV.foreach("#{@path}/#{table}.csv", encoding:'iso-8859-1:utf-8').inject(0) {|c, line| c+1} - 1
-    File.foreach("#{@path}/#{table}.csv").inject(0) {|c, line| c+1} - 1
+    File.foreach("#{@path}/#{table}.csv").inject(0) { |c, line| c + 1 } - 1
   end
 
   def import_users
@@ -191,7 +190,7 @@ class ImportScripts::GetSatisfaction < ImportScripts::Base
   def import_categories
     rows = []
     csv_parse("categories") do |row|
-      rows << {id: row.id, name: row.name, description: row.description}
+      rows << { id: row.id, name: row.name, description: row.description }
     end
 
     create_categories(rows) do |row|
@@ -209,7 +208,7 @@ class ImportScripts::GetSatisfaction < ImportScripts::Base
       code = $2
       hoist = SecureRandom.hex
       # tidy code, wow, this is impressively crazy
-      code.gsub!(/  (\s*)/,"\n\\1")
+      code.gsub!(/  (\s*)/, "\n\\1")
       code.gsub!(/^\s*\n$/, "\n")
       code.gsub!(/\n+/m, "\n")
       code.strip!
@@ -231,48 +230,47 @@ class ImportScripts::GetSatisfaction < ImportScripts::Base
   end
 
   def import_post_batch!(posts, topics, offset, total)
-      create_posts(posts, total: total, offset: offset) do |post|
+    create_posts(posts, total: total, offset: offset) do |post|
 
-        mapped = {}
+      mapped = {}
 
-        mapped[:id] = post[:id]
-        mapped[:user_id] = user_id_from_imported_user_id(post[:user_id]) || -1
-        mapped[:raw] = post[:body]
-        mapped[:created_at] = post[:created_at]
+      mapped[:id] = post[:id]
+      mapped[:user_id] = user_id_from_imported_user_id(post[:user_id]) || -1
+      mapped[:raw] = post[:body]
+      mapped[:created_at] = post[:created_at]
 
-        topic = topics[post[:topic_id]]
+      topic = topics[post[:topic_id]]
 
-        unless topic
-          p "MISSING TOPIC #{post[:topic_id]}"
-          p post
-          next
-        end
+      unless topic
+        p "MISSING TOPIC #{post[:topic_id]}"
+        p post
+        next
+      end
 
+      unless topic[:post_id]
+        mapped[:title] = post[:title] || "Topic title missing"
+        topic[:post_id] = post[:id]
+        mapped[:category] = post[:category]
+      else
+        parent = topic_lookup_from_imported_post_id(topic[:post_id])
+        next unless parent
 
-        unless topic[:post_id]
-          mapped[:title] = post[:title] || "Topic title missing"
-          topic[:post_id] = post[:id]
-          mapped[:category] = post[:category]
-        else
-          parent = topic_lookup_from_imported_post_id(topic[:post_id])
-          next unless parent
+        mapped[:topic_id] = parent[:topic_id]
 
-          mapped[:topic_id] = parent[:topic_id]
-
-          reply_to_post_id = post_id_from_imported_post_id(post[:reply_id])
-          if reply_to_post_id
-            reply_to_post_number = @post_number_map[reply_to_post_id]
-            if reply_to_post_number && reply_to_post_number > 1
-              mapped[:reply_to_post_number] = reply_to_post_number
-            end
+        reply_to_post_id = post_id_from_imported_post_id(post[:reply_id])
+        if reply_to_post_id
+          reply_to_post_number = @post_number_map[reply_to_post_id]
+          if reply_to_post_number && reply_to_post_number > 1
+            mapped[:reply_to_post_number] = reply_to_post_number
           end
         end
-
-        next if topic[:deleted] or post[:deleted]
-
-        mapped
       end
 
+      next if topic[:deleted] || post[:deleted]
+
+      mapped
+    end
+
       posts.clear
   end
 
@@ -324,7 +322,7 @@ class ImportScripts::GetSatisfaction < ImportScripts::Base
         created_at: DateTime.parse(row.created_at)
       }
       posts << row
-      count+=1
+      count += 1
 
       if posts.length > 0 && posts.length % BATCH_SIZE == 0
         import_post_batch!(posts, topic_map, count - posts.length, total)
diff --git a/script/import_scripts/jive.rb b/script/import_scripts/jive.rb
index c64e87a66bb..ae077bda2ee 100644
--- a/script/import_scripts/jive.rb
+++ b/script/import_scripts/jive.rb
@@ -6,7 +6,7 @@ require File.expand_path(File.dirname(__FILE__) + "/base.rb")
 class ImportScripts::Jive < ImportScripts::Base
 
   BATCH_SIZE = 1000
-  CATEGORY_IDS = [2023,2003,2004,2042,2036,2029] # categories that should be imported
+  CATEGORY_IDS = [2023, 2003, 2004, 2042, 2036, 2029] # categories that should be imported
 
   def initialize(path)
     @path = path
@@ -45,7 +45,7 @@ class ImportScripts::Jive < ImportScripts::Base
     end
 
     def initialize(cols)
-      cols.each_with_index do |col,idx|
+      cols.each_with_index do |col, idx|
         self.class.send(:define_method, col) do
           @row[idx]
         end
@@ -72,7 +72,7 @@ class ImportScripts::Jive < ImportScripts::Base
 
     File.open(filename).each_line do |line|
 
-      line.gsub!(/\\(.{1})/){|m| m[-1] == '"'? '""': m[-1]}
+      line.gsub!(/\\(.{1})/) { |m| m[-1] == '"' ? '""' : m[-1] }
       line.strip!
 
       current_row << "\n" unless current_row.empty?
@@ -120,7 +120,7 @@ class ImportScripts::Jive < ImportScripts::Base
   end
 
   def total_rows(table)
-    File.foreach("#{@path}/#{table}.csv").inject(0) {|c, line| c+1} - 1
+    File.foreach("#{@path}/#{table}.csv").inject(0) { |c, line| c + 1 } - 1
   end
 
   def import_groups
@@ -128,7 +128,7 @@ class ImportScripts::Jive < ImportScripts::Base
 
     rows = []
     csv_parse("groups") do |row|
-      rows << {id: row.groupid, name: row.name}
+      rows << { id: row.groupid, name: row.name }
     end
 
     create_groups(rows) do |row|
@@ -204,7 +204,7 @@ class ImportScripts::Jive < ImportScripts::Base
 
     csv_parse("communities") do |row|
       next unless CATEGORY_IDS.include?(row.communityid.to_i)
-      rows << {id: row.communityid, name: "#{row.name} (#{row.communityid})"}
+      rows << { id: row.communityid, name: "#{row.name} (#{row.communityid})" }
     end
 
     create_categories(rows) do |row|
@@ -228,47 +228,47 @@ class ImportScripts::Jive < ImportScripts::Base
   end
 
   def import_post_batch!(posts, topics, offset, total)
-      create_posts(posts, total: total, offset: offset) do |post|
+    create_posts(posts, total: total, offset: offset) do |post|
 
-        mapped = {}
+      mapped = {}
 
-        mapped[:id] = post[:id]
-        mapped[:user_id] = user_id_from_imported_user_id(post[:user_id]) || -1
-        mapped[:raw] = post[:body]
-        mapped[:created_at] = post[:created_at]
+      mapped[:id] = post[:id]
+      mapped[:user_id] = user_id_from_imported_user_id(post[:user_id]) || -1
+      mapped[:raw] = post[:body]
+      mapped[:created_at] = post[:created_at]
 
-        topic = topics[post[:topic_id]]
+      topic = topics[post[:topic_id]]
 
-        unless topic
-          p "MISSING TOPIC #{post[:topic_id]}"
-          p post
-          next
-        end
+      unless topic
+        p "MISSING TOPIC #{post[:topic_id]}"
+        p post
+        next
+      end
 
-        unless topic[:post_id]
-          mapped[:category] = category_id_from_imported_category_id(topic[:category_id])
-          mapped[:title] = post[:title]
-          topic[:post_id] = post[:id]
-        else
-          parent = topic_lookup_from_imported_post_id(topic[:post_id])
-          next unless parent
+      unless topic[:post_id]
+        mapped[:category] = category_id_from_imported_category_id(topic[:category_id])
+        mapped[:title] = post[:title]
+        topic[:post_id] = post[:id]
+      else
+        parent = topic_lookup_from_imported_post_id(topic[:post_id])
+        next unless parent
 
-          mapped[:topic_id] = parent[:topic_id]
+        mapped[:topic_id] = parent[:topic_id]
 
-          reply_to_post_id = post_id_from_imported_post_id(post[:reply_id])
-          if reply_to_post_id
-            reply_to_post_number = @post_number_map[reply_to_post_id]
-            if reply_to_post_number && reply_to_post_number > 1
-              mapped[:reply_to_post_number] = reply_to_post_number
-            end
+        reply_to_post_id = post_id_from_imported_post_id(post[:reply_id])
+        if reply_to_post_id
+          reply_to_post_number = @post_number_map[reply_to_post_id]
+          if reply_to_post_number && reply_to_post_number > 1
+            mapped[:reply_to_post_number] = reply_to_post_number
           end
         end
-
-        next if topic[:deleted] or post[:deleted]
-
-        mapped
       end
 
+      next if topic[:deleted] || post[:deleted]
+
+      mapped
+    end
+
       posts.clear
   end
 
@@ -290,14 +290,14 @@ class ImportScripts::Jive < ImportScripts::Base
         #IMAGE UPLOADER
         if thread.imagecount
           Dir.foreach("/var/www/discourse/script/import_scripts/jive/img/#{thread.messageid}") do |item|
-          next if item == '.' or item == '..' or item == '.DS_Store'
+            next if item == ('.') || item == ('..') || item == ('.DS_Store')
             photo_path = "/var/www/discourse/script/import_scripts/jive/img/#{thread.messageid}/#{item}"
             upload = create_upload(thread.userid, photo_path, File.basename(photo_path))
                if upload.persisted?
-                  puts "Image upload is successful for #{photo_path}, new path is #{upload.url}!"
-                  thread.body.gsub!(item,upload.url)
+                 puts "Image upload is successful for #{photo_path}, new path is #{upload.url}!"
+                  thread.body.gsub!(item, upload.url)
                else
-                  puts "Error: Image upload is not successful for #{photo_path}!"
+                 puts "Error: Image upload is not successful for #{photo_path}!"
                end
           end
         end
@@ -305,15 +305,15 @@ class ImportScripts::Jive < ImportScripts::Base
         #ATTACHMENT UPLOADER
         if thread.attachmentcount
           Dir.foreach("/var/www/discourse/script/import_scripts/jive/attach/#{thread.messageid}") do |item|
-          next if item == '.' or item == '..' or item == '.DS_Store'
+            next if item == ('.') || item == ('..') || item == ('.DS_Store')
             attach_path = "/var/www/discourse/script/import_scripts/jive/attach/#{thread.messageid}/#{item}"
             upload = create_upload(thread.userid, attach_path, File.basename(attach_path))
                if upload.persisted?
-                  puts "Attachment upload is successful for #{attach_path}, new path is #{upload.url}!"
-                  thread.body.gsub!(item,upload.url)
-                  thread.body << "

#{attachment_html(upload,item)}" + puts "Attachment upload is successful for #{attach_path}, new path is #{upload.url}!" + thread.body.gsub!(item, upload.url) + thread.body << "

#{attachment_html(upload, item)}" else - puts "Error: Attachment upload is not successful for #{attach_path}!" + puts "Error: Attachment upload is not successful for #{attach_path}!" end end end @@ -337,7 +337,7 @@ class ImportScripts::Jive < ImportScripts::Base topic_map.each do |_, topic| posts << topic if topic[:body] - count+=1 + count += 1 end csv_parse("messages") do |thread| @@ -350,14 +350,14 @@ class ImportScripts::Jive < ImportScripts::Base #IMAGE UPLOADER if thread.imagecount Dir.foreach("/var/www/discourse/script/import_scripts/jive/img/#{thread.messageid}") do |item| - next if item == '.' or item == '..' or item == '.DS_Store' + next if item == ('.') || item == ('..') || item == ('.DS_Store') photo_path = "/var/www/discourse/script/import_scripts/jive/img/#{thread.messageid}/#{item}" upload = create_upload(thread.userid, photo_path, File.basename(photo_path)) if upload.persisted? - puts "Image upload is successful for #{photo_path}, new path is #{upload.url}!" - thread.body.gsub!(item,upload.url) + puts "Image upload is successful for #{photo_path}, new path is #{upload.url}!" + thread.body.gsub!(item, upload.url) else - puts "Error: Image upload is not successful for #{photo_path}!" + puts "Error: Image upload is not successful for #{photo_path}!" end end end @@ -365,15 +365,15 @@ class ImportScripts::Jive < ImportScripts::Base #ATTACHMENT UPLOADER if thread.attachmentcount Dir.foreach("/var/www/discourse/script/import_scripts/jive/attach/#{thread.messageid}") do |item| - next if item == '.' or item == '..' or item == '.DS_Store' + next if item == ('.') || item == ('..') || item == ('.DS_Store') attach_path = "/var/www/discourse/script/import_scripts/jive/attach/#{thread.messageid}/#{item}" upload = create_upload(thread.userid, attach_path, File.basename(attach_path)) if upload.persisted? - puts "Attachment upload is successful for #{attach_path}, new path is #{upload.url}!" - thread.body.gsub!(item,upload.url) - thread.body << "

#{attachment_html(upload,item)}" + puts "Attachment upload is successful for #{attach_path}, new path is #{upload.url}!" + thread.body.gsub!(item, upload.url) + thread.body << "

#{attachment_html(upload, item)}" else - puts "Error: Attachment upload is not successful for #{attach_path}!" + puts "Error: Attachment upload is not successful for #{attach_path}!" end end end @@ -387,7 +387,7 @@ class ImportScripts::Jive < ImportScripts::Base created_at: DateTime.parse(thread.creationdate) } posts << row - count+=1 + count += 1 if posts.length > 0 && posts.length % BATCH_SIZE == 0 import_post_batch!(posts, topic_map, count - posts.length, total) diff --git a/script/import_scripts/jive_api.rb b/script/import_scripts/jive_api.rb index 0441db26280..f8c3734a351 100644 --- a/script/import_scripts/jive_api.rb +++ b/script/import_scripts/jive_api.rb @@ -334,7 +334,7 @@ class ImportScripts::JiveApi < ImportScripts::Base SQL end - def get(url_or_path, authenticated=false) + def get(url_or_path, authenticated = false) tries ||= 3 command = ["curl", "--silent"] diff --git a/script/import_scripts/json_generic.rb b/script/import_scripts/json_generic.rb index c6474b26674..f98bcebcbc5 100755 --- a/script/import_scripts/json_generic.rb +++ b/script/import_scripts/json_generic.rb @@ -6,7 +6,7 @@ require File.expand_path(File.dirname(__FILE__) + "/base.rb") class ImportScripts::JsonGeneric < ImportScripts::Base JSON_FILE_PATH = ENV['JSON_FILE'] - BATCH_SIZE ||= 1000 + BATCH_SIZE ||= 1000 def initialize super @@ -59,7 +59,6 @@ class ImportScripts::JsonGeneric < ImportScripts::Base end end - def import_discussions puts "", "Importing discussions" @@ -103,6 +102,6 @@ class ImportScripts::JsonGeneric < ImportScripts::Base end end -if __FILE__==$0 +if __FILE__ == $0 ImportScripts::JsonGeneric.new.perform end diff --git a/script/import_scripts/kunena.rb b/script/import_scripts/kunena.rb index 3cb52e7b38a..1aa333593ee 100644 --- a/script/import_scripts/kunena.rb +++ b/script/import_scripts/kunena.rb @@ -3,7 +3,7 @@ require File.expand_path(File.dirname(__FILE__) + "/base.rb") class ImportScripts::Kunena < ImportScripts::Base - KUNENA_DB = "kunena" + KUNENA_DB = "kunena" def initialize super @@ -38,7 +38,7 @@ class ImportScripts::Kunena < ImportScripts::Base @users = nil create_categories(@client.query("SELECT id, parent, name, description, ordering FROM jos_kunena_categories ORDER BY parent, id;")) do |c| - h = {id: c['id'], name: c['name'], description: c['description'], position: c['ordering'].to_i} + h = { id: c['id'], name: c['name'], description: c['description'], position: c['ordering'].to_i } if c['parent'].to_i > 0 h[:parent_category_id] = category_id_from_imported_category_id(c['parent']) end @@ -61,12 +61,12 @@ class ImportScripts::Kunena < ImportScripts::Base puts "fetching Joomla users data from mysql" results = @client.query("SELECT id, username, email, registerDate FROM jos_users;", cache_rows: false) results.each do |u| - next unless u['id'].to_i > 0 and u['username'].present? and u['email'].present? - username = u['username'].gsub(' ', '_').gsub(/[^A-Za-z0-9_]/, '')[0,User.username_length.end] + next unless u['id'].to_i > (0) && u['username'].present? && u['email'].present? + username = u['username'].gsub(' ', '_').gsub(/[^A-Za-z0-9_]/, '')[0, User.username_length.end] if username.length < User.username_length.first username = username * User.username_length.first end - @users[u['id'].to_i] = {id: u['id'].to_i, username: username, email: u['email'], created_at: u['registerDate']} + @users[u['id'].to_i] = { id: u['id'].to_i, username: username, email: u['email'], created_at: u['registerDate'] } end puts "fetching Kunena user data from mysql" @@ -109,7 +109,7 @@ class ImportScripts::Kunena < ImportScripts::Base break if results.size < 1 - next if all_records_exist? :posts, results.map {|p| p['id'].to_i} + next if all_records_exist? :posts, results.map { |p| p['id'].to_i } create_posts(results, total: total_count, offset: offset) do |m| skip = false diff --git a/script/import_scripts/kunena3.rb b/script/import_scripts/kunena3.rb index 2f4d7808c44..4a271202748 100644 --- a/script/import_scripts/kunena3.rb +++ b/script/import_scripts/kunena3.rb @@ -60,7 +60,7 @@ class ImportScripts::Kunena < ImportScripts::Base @users = nil create_categories(@client.query("SELECT id, #{PARENT_FIELD} as parent_id, name, description, ordering FROM #{KUNENA_PREFIX}kunena_categories ORDER BY #{PARENT_FIELD}, id;")) do |c| - h = {id: c['id'], name: c['name'], description: c['description'], position: c['ordering'].to_i} + h = { id: c['id'], name: c['name'], description: c['description'], position: c['ordering'].to_i } if c['parent_id'].to_i > 0 h[:parent_category_id] = category_id_from_imported_category_id(c['parent_id']) end @@ -83,12 +83,12 @@ class ImportScripts::Kunena < ImportScripts::Base puts "fetching Joomla users data from mysql" results = @client.query("SELECT id, username, email, registerDate FROM #{KUNENA_PREFIX}users;", cache_rows: false) results.each do |u| - next unless u['id'].to_i > 0 and u['username'].present? and u['email'].present? - username = u['username'].gsub(' ', '_').gsub(/[^A-Za-z0-9_]/, '')[0,User.username_length.end] + next unless u['id'].to_i > (0) && u['username'].present? && u['email'].present? + username = u['username'].gsub(' ', '_').gsub(/[^A-Za-z0-9_]/, '')[0, User.username_length.end] if username.length < User.username_length.first username = username * User.username_length.first end - @users[u['id'].to_i] = {id: u['id'].to_i, username: username, email: u['email'], created_at: u['registerDate']} + @users[u['id'].to_i] = { id: u['id'].to_i, username: username, email: u['email'], created_at: u['registerDate'] } end puts "fetching Kunena user data from mysql" @@ -131,7 +131,7 @@ class ImportScripts::Kunena < ImportScripts::Base break if results.size < 1 - next if all_records_exist? :posts, results.map {|p| p['id'].to_i} + next if all_records_exist? :posts, results.map { |p| p['id'].to_i } create_posts(results, total: total_count, offset: offset) do |m| skip = false diff --git a/script/import_scripts/lithium.rb b/script/import_scripts/lithium.rb index 54cd27e1d92..b366a2a4d78 100644 --- a/script/import_scripts/lithium.rb +++ b/script/import_scripts/lithium.rb @@ -10,8 +10,6 @@ # that was done using import_scripts/support/convert_mysql_xml_to_mysql.rb # - - require 'mysql2' require 'csv' require 'reverse_markdown' @@ -19,7 +17,7 @@ require File.expand_path(File.dirname(__FILE__) + "/base.rb") require 'htmlentities' # remove table conversion -[:table,:td,:tr,:th,:thead,:tbody].each do |tag| +[:table, :td, :tr, :th, :thead, :tbody].each do |tag| ReverseMarkdown::Converters.unregister(tag) end @@ -101,7 +99,7 @@ class ImportScripts::Lithium < ImportScripts::Base break if users.size < 1 - next if all_records_exist? :users, users.map {|u| u["id"].to_i} + next if all_records_exist? :users, users.map { |u| u["id"].to_i } create_users(users, total: user_count, offset: offset) do |user| @@ -123,7 +121,7 @@ class ImportScripts::Lithium < ImportScripts::Base end def unix_time(t) - Time.at(t/1000.0) + Time.at(t / 1000.0) end def import_profile_picture(old_user, imported_user) @@ -191,7 +189,6 @@ class ImportScripts::Lithium < ImportScripts::Base top_level_ids = Set.new child_ids = Set.new - parent = nil CSV.foreach(CATEGORY_CSV) do |row| display_id = row[2].strip @@ -216,7 +213,6 @@ class ImportScripts::Lithium < ImportScripts::Base top_level_categories = categories.select { |c| top_level_ids.include? c["display_id"] } - create_categories(top_level_categories) do |category| info = category_info[category["display_id"]] info[:id] = category["node_id"] @@ -228,7 +224,6 @@ class ImportScripts::Lithium < ImportScripts::Base } end - puts "", "importing children categories..." children_categories = categories.select { |c| child_ids.include? c["display_id"] } @@ -246,7 +241,7 @@ class ImportScripts::Lithium < ImportScripts::Base end puts "", "securing categories" - category_info.each do |_,info| + category_info.each do |_, info| if info[:secure] id = category_id_from_imported_category_id(info[:id]) if id @@ -278,7 +273,7 @@ class ImportScripts::Lithium < ImportScripts::Base break if topics.size < 1 - next if all_records_exist? :posts, topics.map {|topic| "#{topic["node_id"]} #{topic["id"]}"} + next if all_records_exist? :posts, topics.map { |topic| "#{topic["node_id"]} #{topic["id"]}" } create_posts(topics, total: topic_count, offset: offset) do |topic| @@ -295,7 +290,7 @@ class ImportScripts::Lithium < ImportScripts::Base raw: raw, created_at: unix_time(topic["post_date"]), views: topic["views"], - custom_fields: {import_unique_id: topic["unique_id"]}, + custom_fields: { import_unique_id: topic["unique_id"] }, import_mode: true } else @@ -326,7 +321,7 @@ class ImportScripts::Lithium < ImportScripts::Base break if posts.size < 1 - next if all_records_exist? :posts, posts.map {|post| "#{post["node_id"]} #{post["root_id"]} #{post["id"]}"} + next if all_records_exist? :posts, posts.map { |post| "#{post["node_id"]} #{post["root_id"]} #{post["id"]}" } create_posts(posts, total: post_count, offset: offset) do |post| raw = post["raw"] @@ -340,7 +335,7 @@ class ImportScripts::Lithium < ImportScripts::Base topic_id: topic[:topic_id], raw: raw, created_at: unix_time(post["post_date"]), - custom_fields: {import_unique_id: post["unique_id"]}, + custom_fields: { import_unique_id: post["unique_id"] }, import_mode: true } @@ -365,7 +360,7 @@ class ImportScripts::Lithium < ImportScripts::Base "smileysurprised" => "dizzy_face", "smileytongue" => "stuck_out_tongue", "smileyvery-happy" => "grin", - "smileywink" => "wink", + "smileywink" => "wink", "smileyfrustrated" => "confounded", "smileyembarrassed" => "flushed", "smileylol" => "laughing", @@ -382,7 +377,6 @@ class ImportScripts::Lithium < ImportScripts::Base "catlol" => "joy_cat" } - def import_likes puts "\nimporting likes..." @@ -395,8 +389,6 @@ class ImportScripts::Lithium < ImportScripts::Base existing_map[import_id] = post_id end - - puts "loading data into temp table" PostAction.exec_sql("create temp table like_data(user_id int, post_id int, created_at timestamp without time zone)") PostAction.transaction do @@ -436,7 +428,6 @@ class ImportScripts::Lithium < ImportScripts::Base WHERE ua.id IS NULL AND pa.post_action_type_id = 2 SQL - # reverse action UserAction.exec_sql <<-SQL INSERT INTO user_actions (user_id, action_type, target_topic_id, target_post_id, acting_user_id, created_at, updated_at) @@ -490,7 +481,6 @@ class ImportScripts::Lithium < ImportScripts::Base existing_map[import_id] = post_id end - puts "loading data into temp table" PostAction.exec_sql("create temp table accepted_data(post_id int primary key)") PostAction.transaction do @@ -507,7 +497,6 @@ class ImportScripts::Lithium < ImportScripts::Base end end - puts "deleting dupe answers" PostAction.exec_sql <<-SQL DELETE FROM accepted_data WHERE post_id NOT IN ( @@ -553,7 +542,7 @@ class ImportScripts::Lithium < ImportScripts::Base users = {} - [inbox,outbox].each do |r| + [inbox, outbox].each do |r| r.each do |row| ary = (users[row["note_id"]] ||= Set.new) user_id = user_id_from_imported_user_id(row["user_id"]) @@ -567,7 +556,7 @@ class ImportScripts::Lithium < ImportScripts::Base subject_to_first_note = {} mysql_query("SELECT note_id, subject, sender_user_id FROM tblia_notes_content order by note_id").each do |row| - user_id = user_id_from_imported_user_id(row["sender_user_id"]) + user_id = user_id_from_imported_user_id(row["sender_user_id"]) ary = (users[row["note_id"]] ||= Set.new) if user_id ary << user_id @@ -581,7 +570,7 @@ class ImportScripts::Lithium < ImportScripts::Base puts "Loading user_id to username map" user_map = {} - User.pluck(:id, :username).each do |id,username| + User.pluck(:id, :username).each do |id, username| user_map[id] = username end @@ -596,17 +585,16 @@ class ImportScripts::Lithium < ImportScripts::Base OFFSET #{offset} SQL - break if topics.size < 1 - next if all_records_exist? :posts, topics.map {|topic| "pm_#{topic["note_id"]}"} + next if all_records_exist? :posts, topics.map { |topic| "pm_#{topic["note_id"]}" } create_posts(topics, total: topic_count, offset: offset) do |topic| user_id = user_id_from_imported_user_id(topic["sender_user_id"]) || Discourse::SYSTEM_USER_ID participants = users[topic["note_id"]] - usernames = (participants - [user_id]).map{|id| user_map[id]} + usernames = (participants - [user_id]).map { |id| user_map[id] } subject = topic["subject"] topic_id = nil @@ -646,7 +634,6 @@ class ImportScripts::Lithium < ImportScripts::Base def close_topics - puts "\nclosing closed topics..." sql = "select unique_id post_id from message2 where root_id = id AND (attributes & 0x0002 ) != 0;" @@ -658,8 +645,8 @@ class ImportScripts::Lithium < ImportScripts::Base existing_map[import_id.to_i] = post_id.to_i end - results.map{|r| r["post_id"]}.each_slice(500) do |ids| - mapped = ids.map{|id| existing_map[id]}.compact + results.map { |r| r["post_id"] }.each_slice(500) do |ids| + mapped = ids.map { |id| existing_map[id] }.compact Topic.exec_sql(" UPDATE topics SET closed = true WHERE id IN (SELECT topic_id FROM posts where id in (:ids)) @@ -668,7 +655,6 @@ class ImportScripts::Lithium < ImportScripts::Base end - def create_permalinks puts "Creating permalinks" @@ -739,7 +725,6 @@ SQL def post_process_posts puts "", "Postprocessing posts..." - current = 0 max = Post.count @@ -766,7 +751,6 @@ SQL end end - def postprocess_post_raw(raw, user_id) doc = Nokogiri::HTML.fragment(raw) @@ -827,7 +811,7 @@ SQL ":#{SMILEY_SUBS[$1] || $1}:" end # nbsp central - raw.gsub!(/([a-zA-Z0-9]) ([a-zA-Z0-9])/,"\\1 \\2") + raw.gsub!(/([a-zA-Z0-9]) ([a-zA-Z0-9])/, "\\1 \\2") raw end diff --git a/script/import_scripts/mbox-experimental.rb b/script/import_scripts/mbox-experimental.rb index 065b0111bd8..12c18515abb 100644 --- a/script/import_scripts/mbox-experimental.rb +++ b/script/import_scripts/mbox-experimental.rb @@ -14,4 +14,3 @@ module ImportScripts Importer.new(@settings).perform end end - diff --git a/script/import_scripts/mbox.rb b/script/import_scripts/mbox.rb index e7c25ed18c6..d0b379aa12a 100755 --- a/script/import_scripts/mbox.rb +++ b/script/import_scripts/mbox.rb @@ -46,7 +46,7 @@ class ImportScripts::Mbox < ImportScripts::Base exit end - validates_format_of :email, :with => /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/i, :on => :create + validates_format_of :email, with: /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/i, on: :create def execute import_categories @@ -63,7 +63,7 @@ class ImportScripts::Mbox < ImportScripts::Base mappings = CATEGORY_MAPPINGS.values - ['uncategorized'] create_categories(mappings) do |c| - {id: c, name: c} + { id: c, name: c } end end @@ -109,7 +109,7 @@ class ImportScripts::Mbox < ImportScripts::Base each_line(f) do |line| line = line.scrub if line =~ SPLIT_AT -p message_count += 1 + p message_count += 1 if !msg.empty? mail = Mail.read_from_string(msg) yield mail, f @@ -163,7 +163,7 @@ p message_count += 1 puts "#{not_found.size} records couldn't be associated with parents" if not_found.present? - db.execute "UPDATE emails SET reply_to = NULL WHERE msg_id IN (#{not_found.map {|nf| "'#{nf}'"}.join(',')})" + db.execute "UPDATE emails SET reply_to = NULL WHERE msg_id IN (#{not_found.map { |nf| "'#{nf}'" }.join(',')})" end dupe_titles = db.execute "SELECT title, COUNT(*) FROM emails GROUP BY title HAVING count(*) > 1" @@ -197,7 +197,7 @@ p message_count += 1 from_email.gsub!(/ /, '') end end -p end + end display_names = from.try(:display_names) if display_names.present? @@ -308,7 +308,7 @@ p end title.strip #In case of mixed localized prefixes there could be many of them if the mail client didn't strip the localized ones - if original_length > title.length + if original_length > title.length clean_title(title) else title @@ -331,9 +331,9 @@ p end total_count = all_users.size batches(BATCH_SIZE) do |offset| - users = all_users[offset..offset+BATCH_SIZE-1] + users = all_users[offset..offset + BATCH_SIZE - 1] break if users.nil? - next if all_records_exist? :users, users.map {|u| u[1]} + next if all_records_exist? :users, users.map { |u| u[1] } create_users(users, total: total_count, offset: offset) do |u| { @@ -374,7 +374,7 @@ p end new_raw = p.raw.dup new_raw = new_raw.gsub!(/#{Regexp.escape(find)}/i, replace) || new_raw if new_raw != p.raw - p.revise(Discourse.system_user, { raw: new_raw }, { bypass_bump: true }) + p.revise(Discourse.system_user, { raw: new_raw }, bypass_bump: true) print_warning "\nReplaced #{find} with #{replace} in topic #{p.topic_id}" end end @@ -411,10 +411,10 @@ p end topic_count = all_topics.size batches(BATCH_SIZE) do |offset| - topics = all_topics[offset..offset+BATCH_SIZE-1] + topics = all_topics[offset..offset + BATCH_SIZE - 1] break if topics.nil? - next if all_records_exist? :posts, topics.map {|t| t[0]} + next if all_records_exist? :posts, topics.map { |t| t[0] } create_posts(topics, total: topic_count, offset: offset) do |t| raw_email = t[5] @@ -454,7 +454,7 @@ p end raw = clean_raw(raw) raw = raw.dup.to_s raw.gsub!(/#{from_email}/, "@#{username}") - cleaned_email = from_email.dup.sub(/@/,' at ') + cleaned_email = from_email.dup.sub(/@/, ' at ') raw.gsub!(/#{cleaned_email}/, "@#{username}") { id: t[0], title: clean_title(title), @@ -490,11 +490,11 @@ p end puts "Replies: #{post_count}" batches(BATCH_SIZE) do |offset| - posts = replies[offset..offset+BATCH_SIZE-1] + posts = replies[offset..offset + BATCH_SIZE - 1] break if posts.nil? break if posts.count < 1 - next if all_records_exist? :posts, posts.map {|p| p[0]} + next if all_records_exist? :posts, posts.map { |p| p[0] } create_posts(posts, total: post_count, offset: offset) do |p| parent_id = p[6] @@ -521,7 +521,7 @@ p end user_id = user_id_from_imported_user_id(from_email) || Discourse::SYSTEM_USER_ID raw = clean_raw(raw).to_s raw.gsub!(/#{from_email}/, "@#{username}") - cleaned_email = from_email.dup.sub(/@/,' at ') + cleaned_email = from_email.dup.sub(/@/, ' at ') raw.gsub!(/#{cleaned_email}/, "@#{username}") # import the attachments mail.attachments.each do |attachment| diff --git a/script/import_scripts/muut.rb b/script/import_scripts/muut.rb index ccd356d90db..24134ee3f92 100644 --- a/script/import_scripts/muut.rb +++ b/script/import_scripts/muut.rb @@ -59,7 +59,6 @@ class ImportScripts::Muut < ImportScripts::Base end end - def import_categories puts "", "Importing categories" @@ -72,7 +71,6 @@ class ImportScripts::Muut < ImportScripts::Base end end - def import_discussions puts "", "Importing discussions" @@ -81,7 +79,6 @@ class ImportScripts::Muut < ImportScripts::Base @imported_json['categories'].each do |category| - @imported_json['threads'][category['path']].each do |thread| next if thread["seed"]["key"] == "skip-this-topic" @@ -96,7 +93,7 @@ class ImportScripts::Muut < ImportScripts::Base end # update user display name - if thread["seed"]["author"] && thread["seed"]["author"]["displayname"] != "" && mapped[:user_id] != -1 + if thread["seed"]["author"] && thread["seed"]["author"]["displayname"] != "" && mapped[:user_id] != -1 user = User.find_by(id: mapped[:user_id]) if user user.name = thread["seed"]["author"]["displayname"] @@ -181,6 +178,6 @@ class ImportScripts::Muut < ImportScripts::Base end -if __FILE__==$0 +if __FILE__ == $0 ImportScripts::Muut.new.perform end diff --git a/script/import_scripts/mybb.rb b/script/import_scripts/mybb.rb index 8bf101c39ab..f9201ecacfa 100644 --- a/script/import_scripts/mybb.rb +++ b/script/import_scripts/mybb.rb @@ -37,7 +37,7 @@ class ImportScripts::MyBB < ImportScripts::Base end def execute - SiteSetting.disable_emails=true + SiteSetting.disable_emails = true import_users import_categories import_posts @@ -66,7 +66,7 @@ class ImportScripts::MyBB < ImportScripts::Base break if results.size < 1 - next if all_records_exist? :users, results.map {|u| u["id"].to_i} + next if all_records_exist? :users, results.map { |u| u["id"].to_i } create_users(results, total: total_count, offset: offset) do |user| { id: user['id'], @@ -87,7 +87,7 @@ class ImportScripts::MyBB < ImportScripts::Base ") create_categories(results) do |row| - h = {id: row['id'], name: CGI.unescapeHTML(row['name']), description: CGI.unescapeHTML(row['description'])} + h = { id: row['id'], name: CGI.unescapeHTML(row['name']), description: CGI.unescapeHTML(row['description']) } if row['parent_id'].to_i > 0 h[:parent_category_id] = category_id_from_imported_category_id(row['parent_id']) end @@ -120,7 +120,7 @@ class ImportScripts::MyBB < ImportScripts::Base break if results.size < 1 - next if all_records_exist? :posts, results.map {|m| m['id'].to_i} + next if all_records_exist? :posts, results.map { |m| m['id'].to_i } create_posts(results, total: total_count, offset: offset) do |m| skip = false @@ -235,7 +235,7 @@ class ImportScripts::MyBB < ImportScripts::Base def create_permalinks puts '', 'Creating redirects...', '' - SiteSetting.permalink_normalizations= '/(\\w+)-(\\d+)[-.].*/\\1-\\2.html' + SiteSetting.permalink_normalizations = '/(\\w+)-(\\d+)[-.].*/\\1-\\2.html' puts '', 'Users...', '' total_users = User.count start_time = Time.now @@ -244,7 +244,7 @@ class ImportScripts::MyBB < ImportScripts::Base ucf = u.custom_fields count += 1 if ucf && ucf["import_id"] && ucf["import_username"] - Permalink.create(url: "#{BASE}/user-#{ucf['import_id']}.html", external_url: "/u/#{u.username}" ) rescue nil + Permalink.create(url: "#{BASE}/user-#{ucf['import_id']}.html", external_url: "/u/#{u.username}") rescue nil end print_status(count, total_users, start_time) end @@ -260,7 +260,7 @@ class ImportScripts::MyBB < ImportScripts::Base unless QUIET puts ("forum-#{id}.html --> /c/#{cat.id}") end - Permalink.create( url: "#{BASE}/forum-#{id}.html", category_id: cat.id ) rescue nil + Permalink.create(url: "#{BASE}/forum-#{id}.html", category_id: cat.id) rescue nil print_status(count, total_categories, start_time) end @@ -286,7 +286,7 @@ class ImportScripts::MyBB < ImportScripts::Base count += 1 if topic = topic_lookup_from_imported_post_id(post['id']) id = post['topic_id'] - Permalink.create( url: "#{BASE}/thread-#{id}.html", topic_id: topic[:topic_id] ) rescue nil + Permalink.create(url: "#{BASE}/thread-#{id}.html", topic_id: topic[:topic_id]) rescue nil unless QUIET puts ("#{BASE}/thread-#{id}.html --> http://localhost:3000/t/#{topic[:topic_id]}") end @@ -296,8 +296,6 @@ class ImportScripts::MyBB < ImportScripts::Base end end - - def mysql_query(sql) @client.query(sql, cache_rows: false) end diff --git a/script/import_scripts/mylittleforum.rb b/script/import_scripts/mylittleforum.rb index fbec5dad462..f0ec1524720 100644 --- a/script/import_scripts/mylittleforum.rb +++ b/script/import_scripts/mylittleforum.rb @@ -2,7 +2,6 @@ require "mysql2" require File.expand_path(File.dirname(__FILE__) + "/base.rb") require 'htmlentities' - # Before running this script, paste these lines into your shell, # then use arrow keys to edit the values =begin @@ -16,7 +15,6 @@ export IMAGE_BASE="http://www.example.com/forum" export BASE="forum" =end - class ImportScripts::MylittleforumSQL < ImportScripts::Base DB_HOST ||= ENV['DB_HOST'] || "localhost" @@ -37,10 +35,9 @@ class ImportScripts::MylittleforumSQL < ImportScripts::Base # Site settings SiteSetting.disable_emails = true if FORCE_HOSTNAME - SiteSetting.force_hostname=FORCE_HOSTNAME + SiteSetting.force_hostname = FORCE_HOSTNAME end - def initialize if IMPORT_AFTER > "1970-01-01" @@ -57,7 +54,7 @@ class ImportScripts::MylittleforumSQL < ImportScripts::Base database: DB_NAME ) rescue Exception => e - puts '='*50 + puts '=' * 50 puts e.message puts < #{username}") end @@ -210,7 +207,7 @@ EOM OFFSET #{offset};") break if discussions.size < 1 - next if all_records_exist? :posts, discussions.map {|t| "discussion#" + t['DiscussionID'].to_s} + next if all_records_exist? :posts, discussions.map { |t| "discussion#" + t['DiscussionID'].to_s } create_posts(discussions, total: total_count, offset: offset) do |discussion| @@ -226,7 +223,7 @@ EOM { id: "discussion#" + discussion['DiscussionID'].to_s, user_id: user_id_from_imported_user_id(discussion['InsertUserID']) || Discourse::SYSTEM_USER_ID, - title: discussion['Name'].gsub('\\"','"'), + title: discussion['Name'].gsub('\\"', '"'), category: category_id_from_imported_category_id(discussion['CategoryID']), raw: raw, created_at: Time.zone.at(discussion['DateInserted']), @@ -260,7 +257,7 @@ EOM OFFSET #{offset};") break if comments.size < 1 - next if all_records_exist? :posts, comments.map {|comment| "comment#" + comment['CommentID'].to_s} + next if all_records_exist? :posts, comments.map { |comment| "comment#" + comment['CommentID'].to_s } create_posts(comments, total: total_count, offset: offset) do |comment| next unless t = topic_lookup_from_imported_post_id("discussion#" + comment['DiscussionID'].to_s) @@ -286,9 +283,9 @@ EOM youtube_cooked = clean_up(youtube_raw.dup.to_s) # get just src from