diff --git a/app/controllers/api/v0/api_controller.rb b/app/controllers/api/v0/api_controller.rb index 01581e600..394d9d00a 100644 --- a/app/controllers/api/v0/api_controller.rb +++ b/app/controllers/api/v0/api_controller.rb @@ -35,7 +35,7 @@ module Api def authenticate! @user = authenticated_user - return error_unauthorized unless @user && !@user.banned + return error_unauthorized unless @user && !@user.suspended? end def authorize_super_admin diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 329c47b4c..37241ca85 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -128,7 +128,7 @@ class ApplicationController < ActionController::Base end def raise_suspended - raise "SUSPENDED" if current_user&.banned + raise SuspendedError if current_user&.suspended? end def internal_navigation? diff --git a/app/controllers/chat_channels_controller.rb b/app/controllers/chat_channels_controller.rb index a2c988392..780976345 100644 --- a/app/controllers/chat_channels_controller.rb +++ b/app/controllers/chat_channels_controller.rb @@ -101,7 +101,7 @@ class ChatChannelsController < ApplicationController user = User.find_by(username: username) membership = user&.chat_channel_memberships&.find_by(chat_channel: chat_channel) if user && membership - user.add_role(:banned) + user.add_role(:suspended) user.messages.where(chat_channel: chat_channel).delete_all membership.update(status: "removed_from_channel") Pusher.trigger(chat_channel.pusher_channels, "user-banned", { userId: user.id }.to_json) @@ -116,7 +116,7 @@ class ChatChannelsController < ApplicationController when "/unban" user = User.find_by(username: username) if user - user.remove_role(:banned) + user.remove_role(:suspended) render json: { status: "moderation-success", message: "#{username} was unsuspended." }, status: :ok else render json: { diff --git a/app/controllers/omniauth_callbacks_controller.rb b/app/controllers/omniauth_callbacks_controller.rb index 2da288848..ff131dfb1 100644 --- a/app/controllers/omniauth_callbacks_controller.rb +++ b/app/controllers/omniauth_callbacks_controller.rb @@ -95,7 +95,7 @@ class OmniauthCallbacksController < Devise::OmniauthCallbacksController flash[:alert] = user_errors redirect_to new_user_registration_url end - rescue ::Authentication::Errors::PreviouslyBanned => e + rescue ::Authentication::Errors::PreviouslySuspended => e flash[:global_notice] = e.message redirect_to root_path rescue StandardError => e diff --git a/app/decorators/user_decorator.rb b/app/decorators/user_decorator.rb index 37040afb2..6981e4311 100644 --- a/app/decorators/user_decorator.rb +++ b/app/decorators/user_decorator.rb @@ -100,7 +100,7 @@ class UserDecorator < ApplicationDecorator # returns true if the user has been suspended and has no content def fully_banished? - articles_count.zero? && comments_count.zero? && banned + articles_count.zero? && comments_count.zero? && suspended? end def stackbit_integration? diff --git a/app/errors/authentication/errors.rb b/app/errors/authentication/errors.rb index 98069f835..6f69f0c00 100644 --- a/app/errors/authentication/errors.rb +++ b/app/errors/authentication/errors.rb @@ -1,6 +1,6 @@ module Authentication module Errors - PREVIOUSLY_BANNED_MESSAGE = "It appears that your previous %s " \ + PREVIOUSLY_SUSPENDED_MESSAGE = "It appears that your previous %s " \ "account was suspended. As such, we've taken measures to prevent you from " \ "creating a new account with %s and its community. If you " \ "think that there has been a mistake, please email us at %s, " \ @@ -15,9 +15,9 @@ module Authentication class ProviderNotEnabled < Error end - class PreviouslyBanned < Error + class PreviouslySuspended < Error def message - format(PREVIOUSLY_BANNED_MESSAGE, + format(PREVIOUSLY_SUSPENDED_MESSAGE, community_name: SiteConfig.community_name, community_email: SiteConfig.email_addresses[:contact]) end diff --git a/app/errors/suspended_error.rb b/app/errors/suspended_error.rb new file mode 100644 index 000000000..2e93d10c1 --- /dev/null +++ b/app/errors/suspended_error.rb @@ -0,0 +1 @@ +class SuspendedError < StandardError; end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 68f5d0ddc..c0fc32d6b 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -290,6 +290,8 @@ module ApplicationHelper end def role_display_name(role) + # TODO: [@jacobherrington] After all Forems have successfully deployed and the banned role + # has been deleted, removed this ternary. role.name == "banned" ? "Suspended" : role.name.titlecase end end diff --git a/app/models/article.rb b/app/models/article.rb index 7722e9016..df7a3bb6b 100644 --- a/app/models/article.rb +++ b/app/models/article.rb @@ -748,7 +748,7 @@ class Article < ApplicationRecord return unless Reaction.article_vomits.where(reactable_id: user.articles.pluck(:id)).size > 2 - user.add_role(:banned) + user.add_role(:suspended) Note.create( author_id: SiteConfig.mascot_user_id, noteable_id: user_id, diff --git a/app/models/comment.rb b/app/models/comment.rb index ff4a329c5..8b807c8e6 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -274,7 +274,7 @@ class Comment < ApplicationRecord return unless Reaction.comment_vomits.where(reactable_id: user.comments.pluck(:id)).size > 2 - user.add_role(:banned) + user.add_role(:suspended) Note.create( author_id: SiteConfig.mascot_user_id, noteable_id: user_id, diff --git a/app/models/organization.rb b/app/models/organization.rb index 62812ab15..1d06f958d 100644 --- a/app/models/organization.rb +++ b/app/models/organization.rb @@ -115,7 +115,9 @@ class Organization < ApplicationRecord credits.unspent.size >= num_credits_needed end - def banned + def suspended? + # Hacky, yuck! + # TODO: [@jacobherrington] Remove this method false end diff --git a/app/models/role.rb b/app/models/role.rb index 78874a4c0..8ab2158b4 100644 --- a/app/models/role.rb +++ b/app/models/role.rb @@ -1,17 +1,17 @@ class Role < ApplicationRecord ROLES = %w[ admin - banned chatroom_beta_tester codeland_admin - comment_banned + comment_suspended + mod_relations_admin podcast_admin restricted_liquid_tag single_resource_admin super_admin - tag_moderator - mod_relations_admin support_admin + suspended + tag_moderator tech_admin trusted warned diff --git a/app/models/user.rb b/app/models/user.rb index a3e1aa586..cf871b9d1 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -368,13 +368,14 @@ class User < ApplicationRecord end end - # methods for Administrate field - def banned - has_role? :banned + def suspended? + # TODO: [@jacobherrington] After all of our Forems have been successfully deployed, + # and data scripts have successfully removed the banned role, we can remove `has_role?(:banned)` + has_role?(:suspended) || has_role?(:banned) end def warned - has_role? :warned + has_role?(:warned) end def admin? @@ -397,7 +398,7 @@ class User < ApplicationRecord return @trusted if defined? @trusted @trusted = Rails.cache.fetch("user-#{id}/has_trusted_role", expires_in: 200.hours) do - has_role? :trusted + has_role?(:trusted) end end @@ -408,8 +409,11 @@ class User < ApplicationRecord end end - def comment_banned - has_role? :comment_banned + def comment_suspended? + # TODO: [@jacobherrington] After all of our Forems have been successfully deployed, + # and data scripts have successfully removed the comment_banned role, + # we can remove `has_role?(:comment_banned)` + has_role?(:comment_suspended) || has_role?(:comment_banned) end def workshop_eligible? diff --git a/app/models/users/suspended_username.rb b/app/models/users/suspended_username.rb index 6f6d29cf1..89908a99c 100644 --- a/app/models/users/suspended_username.rb +++ b/app/models/users/suspended_username.rb @@ -8,7 +8,7 @@ module Users Digest::SHA256.hexdigest(username) end - def self.previously_banned?(username) + def self.previously_suspended?(username) where(username_hash: hash_username(username)).any? end diff --git a/app/policies/api_secret_policy.rb b/app/policies/api_secret_policy.rb index df584b3d0..a916af811 100644 --- a/app/policies/api_secret_policy.rb +++ b/app/policies/api_secret_policy.rb @@ -1,6 +1,6 @@ class ApiSecretPolicy < ApplicationPolicy def create? - !user_is_banned? + !user_suspended? end def destroy? diff --git a/app/policies/application_policy.rb b/app/policies/application_policy.rb index c0e856f3e..9881e44a5 100644 --- a/app/policies/application_policy.rb +++ b/app/policies/application_policy.rb @@ -71,9 +71,7 @@ class ApplicationPolicy user.has_role?(:support_admin) end - def user_is_banned? - user.banned - end + delegate :suspended?, to: :user, prefix: true def user_is_trusted? user.has_role?(:trusted) diff --git a/app/policies/article_policy.rb b/app/policies/article_policy.rb index 3d511da5f..cca5b1af2 100644 --- a/app/policies/article_policy.rb +++ b/app/policies/article_policy.rb @@ -12,7 +12,7 @@ class ArticlePolicy < ApplicationPolicy end def create? - !user_is_banned? + !user_suspended? end def delete_confirm? diff --git a/app/policies/chat_channel_policy.rb b/app/policies/chat_channel_policy.rb index 7d89f75d2..ec114d77f 100644 --- a/app/policies/chat_channel_policy.rb +++ b/app/policies/chat_channel_policy.rb @@ -12,7 +12,7 @@ class ChatChannelPolicy < ApplicationPolicy end def moderate? - !user_is_banned? && codeland_admin? + !user_suspended? && codeland_admin? end def show? diff --git a/app/policies/comment_policy.rb b/app/policies/comment_policy.rb index 8ea7efd5d..a3d7936ea 100644 --- a/app/policies/comment_policy.rb +++ b/app/policies/comment_policy.rb @@ -4,7 +4,7 @@ class CommentPolicy < ApplicationPolicy end def create? - !user_is_banned? && !user_is_comment_banned? && !user_is_blocked? + !user_suspended? && !user.comment_suspended? && !user_is_blocked? end def update? @@ -65,10 +65,6 @@ class CommentPolicy < ApplicationPolicy user.moderator_for_tags.present? end - def user_is_comment_banned? - user.has_role? :comment_banned - end - def user_is_author? record.user_id == user.id end diff --git a/app/policies/follow_policy.rb b/app/policies/follow_policy.rb index 1919cfdf0..7f78290b2 100644 --- a/app/policies/follow_policy.rb +++ b/app/policies/follow_policy.rb @@ -2,7 +2,7 @@ class FollowPolicy < ApplicationPolicy PERMITTED_ATTRIBUTES = %i[id explicit_points].freeze def create? - !user_is_banned? + !user_suspended? end # record is an object of ActiveRecord_Relation diff --git a/app/policies/github_repo_policy.rb b/app/policies/github_repo_policy.rb index f51f93052..f78a259b1 100644 --- a/app/policies/github_repo_policy.rb +++ b/app/policies/github_repo_policy.rb @@ -1,10 +1,10 @@ class GithubRepoPolicy < ApplicationPolicy def index? - !user_is_banned? && user.authenticated_through?(:github) + !user_suspended? && user.authenticated_through?(:github) end def update_or_create? - !user_is_banned? && user.authenticated_through?(:github) + !user_suspended? && user.authenticated_through?(:github) end def permitted_attributes diff --git a/app/policies/image_upload_policy.rb b/app/policies/image_upload_policy.rb index 693632b55..737344119 100644 --- a/app/policies/image_upload_policy.rb +++ b/app/policies/image_upload_policy.rb @@ -1,5 +1,5 @@ class ImageUploadPolicy < ApplicationPolicy def create? - !user_is_banned? + !user_suspended? end end diff --git a/app/policies/message_policy.rb b/app/policies/message_policy.rb index 243ac959c..042066ea5 100644 --- a/app/policies/message_policy.rb +++ b/app/policies/message_policy.rb @@ -1,6 +1,6 @@ class MessagePolicy < ApplicationPolicy def create? - !user_is_banned? + !user_suspended? end def destroy? diff --git a/app/policies/organization_policy.rb b/app/policies/organization_policy.rb index 7cb4e7682..9479add56 100644 --- a/app/policies/organization_policy.rb +++ b/app/policies/organization_policy.rb @@ -1,6 +1,6 @@ class OrganizationPolicy < ApplicationPolicy def create? - !user.banned + !user.suspended? end def update? diff --git a/app/policies/rating_vote_policy.rb b/app/policies/rating_vote_policy.rb index 53b7d435d..008aa91a5 100644 --- a/app/policies/rating_vote_policy.rb +++ b/app/policies/rating_vote_policy.rb @@ -1,6 +1,6 @@ class RatingVotePolicy < ApplicationPolicy def create? - !user_is_banned? + !user_suspended? end def permitted_attributes diff --git a/app/policies/reaction_policy.rb b/app/policies/reaction_policy.rb index 2affe2763..9d205990d 100644 --- a/app/policies/reaction_policy.rb +++ b/app/policies/reaction_policy.rb @@ -4,6 +4,6 @@ class ReactionPolicy < ApplicationPolicy end def create? - !user_is_banned? + !user_suspended? end end diff --git a/app/policies/stripe_active_card_policy.rb b/app/policies/stripe_active_card_policy.rb index 46d2addf1..a3e906d3a 100644 --- a/app/policies/stripe_active_card_policy.rb +++ b/app/policies/stripe_active_card_policy.rb @@ -1,10 +1,10 @@ class StripeActiveCardPolicy < ApplicationPolicy def create? - !user_is_banned? + !user_suspended? end def update? - !user_is_banned? + !user_suspended? end def destroy? diff --git a/app/policies/stripe_subscription_policy.rb b/app/policies/stripe_subscription_policy.rb index 8758cf982..0aed47557 100644 --- a/app/policies/stripe_subscription_policy.rb +++ b/app/policies/stripe_subscription_policy.rb @@ -1,10 +1,10 @@ class StripeSubscriptionPolicy < ApplicationPolicy def create? - !user_is_banned? + !user_suspended? end def update? - !user_is_banned? + !user_suspended? end def destroy? diff --git a/app/policies/user_block_policy.rb b/app/policies/user_block_policy.rb index d936f7c7b..ac6cbb09a 100644 --- a/app/policies/user_block_policy.rb +++ b/app/policies/user_block_policy.rb @@ -1,10 +1,10 @@ class UserBlockPolicy < ApplicationPolicy def create? - !user_is_banned? + !user_suspended? end def destroy? - !user_is_banned? + !user_suspended? end def permitted_attributes diff --git a/app/policies/user_policy.rb b/app/policies/user_policy.rb index f6f30ea70..f82327fa3 100644 --- a/app/policies/user_policy.rb +++ b/app/policies/user_policy.rb @@ -93,7 +93,7 @@ class UserPolicy < ApplicationPolicy end def join_org? - !user_is_banned? + !user_suspended? end def leave_org? @@ -109,7 +109,7 @@ class UserPolicy < ApplicationPolicy end def moderation_routes? - (user.has_role?(:trusted) || minimal_admin?) && !user.banned + (user.has_role?(:trusted) || minimal_admin?) && !user.suspended? end def update_password? diff --git a/app/queries/admin/moderators_query.rb b/app/queries/admin/moderators_query.rb index bbd795688..88a2dec35 100644 --- a/app/queries/admin/moderators_query.rb +++ b/app/queries/admin/moderators_query.rb @@ -4,7 +4,9 @@ module Admin state: :trusted }.with_indifferent_access.freeze - VALID_ROLES = %i[banned warned trusted comment_banned].freeze + # TODO: [@jacobherrington] Once all Forems have been deployed and the data update scripts have + # succesfully completed, we can remove banned and comment_banned roles from the codebase + VALID_ROLES = %i[banned comment_banned comment_suspended suspended trusted warned].freeze def self.call(relation: User.all, options: {}) options = DEFAULT_OPTIONS.merge(options) diff --git a/app/services/authentication/authenticator.rb b/app/services/authentication/authenticator.rb index f3456f5cd..0e2dd1c41 100644 --- a/app/services/authentication/authenticator.rb +++ b/app/services/authentication/authenticator.rb @@ -97,8 +97,8 @@ module Authentication def find_or_create_user! username = provider.user_nickname - banned_user = Users::SuspendedUsername.previously_banned?(username) - raise ::Authentication::Errors::PreviouslyBanned if banned_user + suspended_user = Users::SuspendedUsername.previously_suspended?(username) + raise ::Authentication::Errors::PreviouslySuspended if suspended_user existing_user = User.where( provider.user_username_field => username, diff --git a/app/services/moderator/manage_activity_and_roles.rb b/app/services/moderator/manage_activity_and_roles.rb index 9b5bee2b0..718314fc8 100644 --- a/app/services/moderator/manage_activity_and_roles.rb +++ b/app/services/moderator/manage_activity_and_roles.rb @@ -57,12 +57,12 @@ module Moderator def handle_user_status(role, note) case role when "Suspend" || "Spammer" - user.add_role(:banned) + user.add_role(:suspended) remove_privileges when "Warn" warned when "Comment Suspend" - comment_banned + comment_suspended when "Regular Member" regular_member when "Trusted" @@ -96,9 +96,9 @@ module Moderator raise "You need super admin status to take this action" unless @admin.has_role?(:super_admin) end - def comment_banned - user.add_role(:comment_banned) - user.remove_role(:banned) + def comment_suspended + user.add_role(:comment_suspended) + user.remove_role(:suspended) remove_privileges end @@ -109,14 +109,14 @@ module Moderator def warned user.add_role(:warned) - user.remove_role(:banned) + user.remove_role(:suspended) remove_privileges end def remove_negative_roles - user.remove_role(:banned) if user.banned + user.remove_role(:suspended) if user.suspended? user.remove_role(:warned) if user.warned - user.remove_role(:comment_banned) if user.comment_banned + user.remove_role(:comment_suspended) if user.comment_suspended? end def update_trusted_cache diff --git a/app/services/profiles/update.rb b/app/services/profiles/update.rb index 21cd34784..9052d68f9 100644 --- a/app/services/profiles/update.rb +++ b/app/services/profiles/update.rb @@ -97,7 +97,7 @@ module Profiles end def conditionally_resave_articles - return unless core_profile_details_changed? && !@user.banned + return unless core_profile_details_changed? && !@user.suspended? Users::ResaveArticlesWorker.perform_async(@user.id) end diff --git a/app/services/re_captcha/check_enabled.rb b/app/services/re_captcha/check_enabled.rb index 04bc9d769..2151b5393 100644 --- a/app/services/re_captcha/check_enabled.rb +++ b/app/services/re_captcha/check_enabled.rb @@ -21,8 +21,8 @@ module ReCaptcha return true if @user.nil? # recaptcha will not be enabled for tag moderator/trusted/admin users return false if @user.tag_moderator? || @user.trusted || @user.any_admin? - # recaptcha will be enabled if the user has been banned - return true if @user.banned + # recaptcha will be enabled if the user has been suspended + return true if @user.suspended? # recaptcha will be enabled if the user has a vomit or is too recent @user.vomitted_on? || @user.created_at.after?(1.month.ago) diff --git a/app/services/search/query_builders/user.rb b/app/services/search/query_builders/user.rb index fede56475..e832edba0 100644 --- a/app/services/search/query_builders/user.rb +++ b/app/services/search/query_builders/user.rb @@ -21,8 +21,9 @@ module Search @params = params.deep_symbolize_keys - # default to excluding users who are banned - @params[:exclude_roles] = ["banned"] + # default to excluding users who are suspended + # TODO: [@jacobherrington] banned can be removed once the data scripts have succesfully run on all Forems + @params[:exclude_roles] = %w[suspended banned] build_body end diff --git a/app/services/tag_moderators/add_trusted_role.rb b/app/services/tag_moderators/add_trusted_role.rb index d2490e429..7cb2a8ba3 100644 --- a/app/services/tag_moderators/add_trusted_role.rb +++ b/app/services/tag_moderators/add_trusted_role.rb @@ -1,7 +1,7 @@ module TagModerators class AddTrustedRole def self.call(user) - return if user.has_role?(:trusted) || user.has_role?(:banned) + return if user.has_role?(:trusted) || user.suspended? user.add_role(:trusted) user.update(email_community_mod_newsletter: true) diff --git a/app/services/users/delete.rb b/app/services/users/delete.rb index fe72b23f7..54696930e 100644 --- a/app/services/users/delete.rb +++ b/app/services/users/delete.rb @@ -10,7 +10,7 @@ module Users delete_user_activity user.unsubscribe_from_newsletters EdgeCache::Bust.call("/#{user.username}") - Users::SuspendedUsername.create_from_user(user) if user.has_role?(:banned) + Users::SuspendedUsername.create_from_user(user) if user.suspended? user.destroy Rails.cache.delete("user-destroy-token-#{user.id}") end diff --git a/app/views/admin/feedback_messages/_abuse_reports.html.erb b/app/views/admin/feedback_messages/_abuse_reports.html.erb index d4d2a523f..b3eecf806 100644 --- a/app/views/admin/feedback_messages/_abuse_reports.html.erb +++ b/app/views/admin/feedback_messages/_abuse_reports.html.erb @@ -38,7 +38,7 @@ <%= reaction.reactable_type %>: <%= reaction.reactable_type == "User" ? reaction.reactable.username : reaction.reactable.title %> - <% if reaction.reactable_type == "User" && reaction.reactable.banned %> + <% if reaction.reactable_type == "User" && reaction.reactable.suspended? %> Suspended <% end %> <% if reaction.reactable_type == "User" && reaction.reactable.vomitted_on? %> diff --git a/app/views/admin/users/_current_roles.html.erb b/app/views/admin/users/_current_roles.html.erb index 0ce1d15c6..969b93f26 100644 --- a/app/views/admin/users/_current_roles.html.erb +++ b/app/views/admin/users/_current_roles.html.erb @@ -4,7 +4,7 @@
    <% @user.roles.each do |role| %> - <% if role.name == "banned" || role.name == "super_admin" || @user.id == current_user.id %> + <% if role.name == "banned" || role.name == "suspended" || role.name == "super_admin" || @user.id == current_user.id %>
  • <%= role_display_name(role) %> <%= role.resource_name.to_s %>
  • <% else %>
  • diff --git a/app/views/admin/users/edit.html.erb b/app/views/admin/users/edit.html.erb index d627557f7..b6fc28338 100644 --- a/app/views/admin/users/edit.html.erb +++ b/app/views/admin/users/edit.html.erb @@ -20,11 +20,11 @@

    User Status - <% if @user.banned %> + <% if @user.suspended? %> 🚨 Member is Suspended 🚨 <% elsif @user.warned %> Member is Warned - <% elsif @user.comment_banned %> + <% elsif @user.comment_suspended? %> Member is Comment Suspended <% elsif @user.trusted %> Member is Trusted diff --git a/app/views/users/_meta.html.erb b/app/views/users/_meta.html.erb index 7f6319e04..3a8e4f09e 100644 --- a/app/views/users/_meta.html.erb +++ b/app/views/users/_meta.html.erb @@ -19,7 +19,7 @@ <%= auto_discovery_link_tag(:rss, app_url("/feed/#{@user.username}"), title: "#{community_name} RSS Feed") %> <% end %> -<% if @user.banned %> +<% if @user.suspended? %> <% end %> diff --git a/config/initializers/honeybadger.rb b/config/initializers/honeybadger.rb index 11ac2ca33..f71085dab 100644 --- a/config/initializers/honeybadger.rb +++ b/config/initializers/honeybadger.rb @@ -2,7 +2,7 @@ # https://docs.honeybadger.io/lib/ruby/getting-started/ignoring-errors.html#ignore-programmatically MESSAGE_FINGERPRINTS = { - "SUSPENDED" => "banned", + "SuspendedError" => "banned", "Rack::Timeout::RequestTimeoutException" => "rack_timeout", "Rack::Timeout::RequestTimeoutError" => "rack_timeout", "PG::QueryCanceled" => "pg_query_canceled" diff --git a/lib/data_update_scripts/20210119131811_replace_instances_of_banned_and_comment_banned.rb b/lib/data_update_scripts/20210119131811_replace_instances_of_banned_and_comment_banned.rb new file mode 100644 index 000000000..17dd6e1de --- /dev/null +++ b/lib/data_update_scripts/20210119131811_replace_instances_of_banned_and_comment_banned.rb @@ -0,0 +1,10 @@ +module DataUpdateScripts + class ReplaceInstancesOfBannedAndCommentBanned + def run + # Update names for the banned and comment_banned roles + # Details: https://github.com/forem/forem/pull/11581 + Role.find_by(name: "banned")&.update(name: "suspended") + Role.find_by(name: "comment_banned")&.update(name: "comment_suspended") + end + end +end diff --git a/spec/factories/users.rb b/spec/factories/users.rb index cae7781da..2419d898a 100644 --- a/spec/factories/users.rb +++ b/spec/factories/users.rb @@ -79,8 +79,8 @@ FactoryBot.define do after(:build) { |user| user.add_role(:trusted) } end - trait :banned do - after(:build) { |user| user.add_role(:banned) } + trait :suspended do + after(:build) { |user| user.add_role(:suspended) } end trait :invited do diff --git a/spec/models/article_spec.rb b/spec/models/article_spec.rb index 7891e3d57..6835377c9 100644 --- a/spec/models/article_spec.rb +++ b/spec/models/article_spec.rb @@ -916,7 +916,7 @@ RSpec.describe Article, type: :model do it "does not suspend user if only single vomit" do article.body_markdown = article.body_markdown.gsub(article.title, "This post is about Yahoomagoo gogo") article.save - expect(article.user.banned).to be false + expect(article.user.suspended?).to be false end it "suspends user with 3 comment vomits" do @@ -929,7 +929,7 @@ RSpec.describe Article, type: :model do article.save second_article.save third_article.save - expect(article.user.banned).to be true + expect(article.user.suspended?).to be true expect(Note.last.reason).to eq "automatic_suspend" end diff --git a/spec/models/comment_spec.rb b/spec/models/comment_spec.rb index 387f2c9b8..ed85829fd 100644 --- a/spec/models/comment_spec.rb +++ b/spec/models/comment_spec.rb @@ -445,7 +445,7 @@ RSpec.describe Comment, type: :model do it "does no suspend user if only single vomit" do comment.body_markdown = "This post is about Yahoomagoo gogo" comment.save - expect(comment.user.banned).to be false + expect(comment.user.suspended?).to be false end it "suspends user with 3 comment vomits" do @@ -456,7 +456,7 @@ RSpec.describe Comment, type: :model do comment.save second_comment.save third_comment.save - expect(comment.user.banned).to be true + expect(comment.user.suspended?).to be true expect(Note.last.reason).to eq "automatic_suspend" end diff --git a/spec/models/role_spec.rb b/spec/models/role_spec.rb index 50d990932..76a14b07f 100644 --- a/spec/models/role_spec.rb +++ b/spec/models/role_spec.rb @@ -8,9 +8,9 @@ RSpec.describe Role, type: :model do describe "::ROLES" do it "contains the correct values" do expected_roles = %w[ - admin banned chatroom_beta_tester codeland_admin comment_banned podcast_admin restricted_liquid_tag - single_resource_admin super_admin tag_moderator mod_relations_admin support_admin tech_admin trusted - warned workshop_pass + admin chatroom_beta_tester codeland_admin comment_suspended mod_relations_admin podcast_admin + restricted_liquid_tag single_resource_admin super_admin support_admin suspended tag_moderator tech_admin + trusted warned workshop_pass ] expect(described_class::ROLES).to eq(expected_roles) end diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 542cbf652..9b44107e0 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -624,6 +624,34 @@ RSpec.describe User, type: :model do end end + describe "#suspended?" do + subject { user.suspended? } + + context "with suspended role" do + before do + user.add_role(:suspended) + end + + it { is_expected.to be true } + end + + it { is_expected.to be false } + end + + describe "#comment_suspended?" do + subject { user.comment_suspended? } + + context "with comment_suspended role" do + before do + user.add_role(:comment_suspended) + end + + it { is_expected.to be true } + end + + it { is_expected.to be false } + end + describe "#moderator_for_tags" do let(:tags) { create_list(:tag, 2) } diff --git a/spec/models/users/suspended_username_spec.rb b/spec/models/users/suspended_username_spec.rb index e212e513c..580c1831d 100644 --- a/spec/models/users/suspended_username_spec.rb +++ b/spec/models/users/suspended_username_spec.rb @@ -8,25 +8,25 @@ RSpec.describe Users::SuspendedUsername, type: :model do it { is_expected.to validate_uniqueness_of(:username_hash) } end - describe ".previously_banned?" do - it "returns true if the user has been previously banned" do - user = create(:user, :banned) + describe ".previously_suspended?" do + it "returns true if the user has been previously suspended" do + user = create(:user, :suspended) described_class.create_from_user(user) - expect(described_class.previously_banned?(user.username)).to be true + expect(described_class.previously_suspended?(user.username)).to be true end - it "returns false if the user has not been previously_banned" do + it "returns false if the user has not been previously_suspended" do user = create(:user) - expect(described_class.previously_banned?(user.username)).to be false + expect(described_class.previously_suspended?(user.username)).to be false end end describe ".create_from_user" do it "records a hash of the username in the database" do expect do - described_class.create_from_user(create(:user, :banned)) + described_class.create_from_user(create(:user, :suspended)) end.to change(described_class, :count).by(1) end end diff --git a/spec/policies/api_secret_policy_spec.rb b/spec/policies/api_secret_policy_spec.rb index be48d7b1c..a9dd27505 100644 --- a/spec/policies/api_secret_policy_spec.rb +++ b/spec/policies/api_secret_policy_spec.rb @@ -29,8 +29,8 @@ RSpec.describe ApiSecretPolicy, type: :policy do it { is_expected.to permit_mass_assignment_of(valid_attributes) } end - context "when the user is banned" do - let(:user) { create(:user, :banned) } + context "when the user is suspended" do + let(:user) { create(:user, :suspended) } let(:api_secret) { build_stubbed(:api_secret) } it { is_expected.to forbid_actions %i[create] } diff --git a/spec/policies/article_policy_spec.rb b/spec/policies/article_policy_spec.rb index 7413019ae..4befe68e7 100644 --- a/spec/policies/article_policy_spec.rb +++ b/spec/policies/article_policy_spec.rb @@ -24,8 +24,8 @@ RSpec.describe ArticlePolicy do it { is_expected.to permit_actions(%i[new create preview]) } it { is_expected.to forbid_actions(%i[update edit manage delete_confirm destroy admin_unpublish]) } - context "with banned status" do - before { user.add_role(:banned) } + context "with suspended status" do + before { user.add_role(:suspended) } it { is_expected.to permit_actions(%i[new preview]) } it { is_expected.to forbid_actions(%i[create edit manage update delete_confirm destroy admin_unpublish]) } @@ -38,8 +38,8 @@ RSpec.describe ArticlePolicy do it { is_expected.to permit_actions(%i[update edit manage new create delete_confirm destroy preview]) } it { is_expected.to permit_mass_assignment_of(valid_attributes) } - context "with banned status" do - before { user.add_role(:banned) } + context "with suspended status" do + before { user.add_role(:suspended) } it { is_expected.to permit_actions(%i[update new delete_confirm destroy preview]) } end diff --git a/spec/policies/comment_policy_spec.rb b/spec/policies/comment_policy_spec.rb index a6c500589..9bafa19bd 100644 --- a/spec/policies/comment_policy_spec.rb +++ b/spec/policies/comment_policy_spec.rb @@ -33,14 +33,14 @@ RSpec.describe CommentPolicy, type: :policy do it { is_expected.to permit_mass_assignment_of(valid_attributes_for_create).for_action(:create) } - context "with banned status" do - before { user.add_role(:banned) } + context "with suspended status" do + before { user.add_role(:suspended) } it { is_expected.to forbid_actions(%i[create edit update destroy delete_confirm hide unhide admin_delete]) } end - context "with banned_comment status" do - before { user.add_role(:comment_banned) } + context "with comment_suspended role" do + before { user.add_role(:comment_suspended) } it { is_expected.to forbid_actions(%i[create edit update destroy delete_confirm hide unhide admin_delete]) } end @@ -80,8 +80,8 @@ RSpec.describe CommentPolicy, type: :policy do it { is_expected.to permit_mass_assignment_of(valid_attributes_for_create).for_action(:create) } it { is_expected.to permit_mass_assignment_of(valid_attributes_for_update).for_action(:update) } - context "with banned status" do - before { user.add_role(:banned) } + context "with suspended status" do + before { user.add_role(:suspended) } it { is_expected.to permit_actions(%i[edit update destroy delete_confirm]) } it { is_expected.to forbid_actions(%i[create hide unhide moderator_create admin_delete]) } @@ -91,8 +91,8 @@ RSpec.describe CommentPolicy, type: :policy do end end - context "with banned_comment status" do - before { user.add_role(:comment_banned) } + context "with comment_suspended role" do + before { user.add_role(:comment_suspended) } it { is_expected.to permit_actions(%i[edit update destroy delete_confirm]) } it { is_expected.to forbid_actions(%i[create hide unhide moderator_create admin_delete]) } diff --git a/spec/policies/follow_policy_spec.rb b/spec/policies/follow_policy_spec.rb index c7a1b6b89..412155697 100644 --- a/spec/policies/follow_policy_spec.rb +++ b/spec/policies/follow_policy_spec.rb @@ -14,8 +14,8 @@ RSpec.describe FollowPolicy, type: :policy do it { is_expected.to permit_actions(%i[create]) } - context "when user is banned" do - before { user.add_role(:banned) } + context "when user is suspended" do + before { user.add_role(:suspended) } it { is_expected.to forbid_actions(%i[create]) } end diff --git a/spec/policies/github_repo_policy_spec.rb b/spec/policies/github_repo_policy_spec.rb index 9b3c5f087..ff3785c5e 100644 --- a/spec/policies/github_repo_policy_spec.rb +++ b/spec/policies/github_repo_policy_spec.rb @@ -29,8 +29,8 @@ RSpec.describe GithubRepoPolicy, type: :policy do it { is_expected.to permit_actions(%i[index update_or_create]) } end - context "when user is banned" do - let(:user) { build(:user, :banned) } + context "when user is suspended" do + let(:user) { build(:user, :suspended) } let(:github_repo) { build(:github_repo, user: user) } it { is_expected.to forbid_actions(%i[index update_or_create]) } diff --git a/spec/policies/image_upload_policy_spec.rb b/spec/policies/image_upload_policy_spec.rb index c62bf0fb0..3b5da2838 100644 --- a/spec/policies/image_upload_policy_spec.rb +++ b/spec/policies/image_upload_policy_spec.rb @@ -16,8 +16,8 @@ RSpec.describe ImageUploadPolicy, type: :policy do it { is_expected.to permit_actions(%i[create]) } - context "when user is banned" do - let(:user) { build(:user, :banned) } + context "when user is suspended" do + let(:user) { build(:user, :suspended) } it { is_expected.to forbid_actions(%i[create]) } end diff --git a/spec/policies/organization_policy_spec.rb b/spec/policies/organization_policy_spec.rb index 3b71aa81e..f3a1afb0c 100644 --- a/spec/policies/organization_policy_spec.rb +++ b/spec/policies/organization_policy_spec.rb @@ -18,8 +18,8 @@ RSpec.describe OrganizationPolicy, type: :policy do it { is_expected.to permit_action(:create) } end - context "when user is banned" do - let(:user) { build(:user, :banned) } + context "when user is suspended" do + let(:user) { build(:user, :suspended) } it { is_expected.to forbid_actions(%i[create update]) } end diff --git a/spec/policies/reaction_policy_spec.rb b/spec/policies/reaction_policy_spec.rb index e96f58c24..c944891da 100644 --- a/spec/policies/reaction_policy_spec.rb +++ b/spec/policies/reaction_policy_spec.rb @@ -16,8 +16,8 @@ RSpec.describe ReactionPolicy do context "when user is signed in" do it { is_expected.to permit_actions(%i[index create]) } - context "when user is banned" do - before { user.add_role(:banned) } + context "when user is suspended" do + before { user.add_role(:suspended) } it { is_expected.to permit_actions(%i[index]) } it { is_expected.to forbid_actions(%i[create]) } diff --git a/spec/policies/stripe_active_card_policy_spec.rb b/spec/policies/stripe_active_card_policy_spec.rb index 52ba1a5d5..ef01cc227 100644 --- a/spec/policies/stripe_active_card_policy_spec.rb +++ b/spec/policies/stripe_active_card_policy_spec.rb @@ -14,8 +14,8 @@ RSpec.describe StripeActiveCardPolicy, type: :policy do it { is_expected.to permit_actions(%i[create update destroy]) } - context "when user is banned" do - let(:user) { build(:user, :banned) } + context "when user is suspended" do + let(:user) { build(:user, :suspended) } it { is_expected.to forbid_actions(%i[create update]) } end diff --git a/spec/policies/user_policy_spec.rb b/spec/policies/user_policy_spec.rb index b1752232d..30049eef2 100644 --- a/spec/policies/user_policy_spec.rb +++ b/spec/policies/user_policy_spec.rb @@ -20,8 +20,8 @@ RSpec.describe UserPolicy, type: :policy do it { is_expected.to permit_actions(permitted_actions) } - context "with banned status" do - before { user.add_role(:banned) } + context "with suspended status" do + before { user.add_role(:suspended) } it { is_expected.to forbid_actions(%i[join_org moderation_routes]) } end diff --git a/spec/queries/admin/moderators_query_spec.rb b/spec/queries/admin/moderators_query_spec.rb index 130d6a544..ee7140ae6 100644 --- a/spec/queries/admin/moderators_query_spec.rb +++ b/spec/queries/admin/moderators_query_spec.rb @@ -9,7 +9,7 @@ RSpec.describe Admin::ModeratorsQuery, type: :query do let!(:user4) { create(:user, :admin, name: "Susi", comments_count: 10) } let(:user5) { create(:user, :trusted, :admin, name: "Beth") } let(:user6) { create(:user, :admin, name: "Jean", comments_count: 5) } - let(:user7) { create(:user, :banned, name: "Harry") } + let(:user7) { create(:user, :suspended, name: "Harry") } describe ".call" do context "when no arguments are given" do diff --git a/spec/requests/admin/users_manage_spec.rb b/spec/requests/admin/users_manage_spec.rb index e62230017..07ddff543 100644 --- a/spec/requests/admin/users_manage_spec.rb +++ b/spec/requests/admin/users_manage_spec.rb @@ -117,7 +117,7 @@ RSpec.describe "Admin::Users", type: :request do params = { user: { user_status: "Comment Suspend", note_for_current_role: "comment suspend this user" } } patch "/admin/users/#{user.id}/user_status", params: params - expect(user.roles.first.name).to eq("comment_banned") + expect(user.roles.first.name).to eq("comment_suspended") expect(Note.first.content).to eq("comment suspend this user") end @@ -129,11 +129,11 @@ RSpec.describe "Admin::Users", type: :request do patch "/admin/users/#{user.id}/user_status", params: params expect(user.roles.count).to eq(1) - expect(user.roles.last.name).to eq("comment_banned") + expect(user.roles.last.name).to eq("comment_suspended") end - it "selects super admin role when user was banned" do - user.add_role(:banned) + it "selects super admin role when user was suspended" do + user.add_role(:suspended) user.reload params = { user: { user_status: "Super Admin", note_for_current_role: "they deserve it for some reason" } } diff --git a/spec/requests/api/v0/articles_spec.rb b/spec/requests/api/v0/articles_spec.rb index 719f6fee9..31bc62d91 100644 --- a/spec/requests/api/v0/articles_spec.rb +++ b/spec/requests/api/v0/articles_spec.rb @@ -562,8 +562,8 @@ RSpec.describe "Api::V0::Articles", type: :request do expect(response).to have_http_status(:unauthorized) end - it "fails with a banned user" do - user.add_role(:banned) + it "fails with a suspended user" do + user.add_role(:suspended) post api_articles_path, headers: { "api-key" => api_secret.secret, "content-type" => "application/json" } expect(response).to have_http_status(:unauthorized) end diff --git a/spec/requests/listings_spec.rb b/spec/requests/listings_spec.rb index 92fbbc89a..0c41ade53 100644 --- a/spec/requests/listings_spec.rb +++ b/spec/requests/listings_spec.rb @@ -332,12 +332,12 @@ RSpec.describe "/listings", type: :request do end end - context "when user is banned" do + context "when user is suspended" do it "raises error" do - user.add_role(:banned) + user.add_role(:suspended) expect do post "/listings", params: listing_params - end.to raise_error("SUSPENDED") + end.to raise_error(SuspendedError) end end diff --git a/spec/requests/user/user_profile_spec.rb b/spec/requests/user/user_profile_spec.rb index ac8e7f8e8..0dfa5f697 100644 --- a/spec/requests/user/user_profile_spec.rb +++ b/spec/requests/user/user_profile_spec.rb @@ -56,13 +56,13 @@ RSpec.describe "UserProfiles", type: :request do expect { get "/#{user.username}" }.to raise_error(ActiveRecord::RecordNotFound) end - it "renders noindex meta if banned" do - user.add_role(:banned) + it "renders noindex meta if suspended" do + user.add_role(:suspended) get "/#{user.username}" expect(response.body).to include("") end - it "does not render noindex meta if not banned" do + it "does not render noindex meta if not suspended" do get "/#{user.username}" expect(response.body).not_to include("") end diff --git a/spec/services/moderator/manage_activity_and_roles_spec.rb b/spec/services/moderator/manage_activity_and_roles_spec.rb index b52206e53..311afc1d3 100644 --- a/spec/services/moderator/manage_activity_and_roles_spec.rb +++ b/spec/services/moderator/manage_activity_and_roles_spec.rb @@ -5,7 +5,7 @@ RSpec.describe Moderator::ManageActivityAndRoles, type: :service do let(:admin) { create(:user, :super_admin) } it "updates user status" do - user.add_role(:banned) + user.add_role(:suspended) user.reload described_class.handle_user_roles( admin: admin, @@ -13,7 +13,7 @@ RSpec.describe Moderator::ManageActivityAndRoles, type: :service do user_params: { note_for_current_role: "warning user", user_status: "Warn" }, ) expect(user.warned).to be true - expect(user.banned).to be false + expect(user.suspended?).to be false end it "updates user to super admin" do @@ -54,13 +54,13 @@ RSpec.describe Moderator::ManageActivityAndRoles, type: :service do end it "updates negative role to positive role" do - user.add_role(:comment_banned) + user.add_role(:comment_suspended) described_class.handle_user_roles( admin: admin, user: user, user_params: { note_for_current_role: "user in good standing", user_status: "Regular Member" }, ) - expect(user.banned).to be false + expect(user.suspended?).to be false expect(user.roles.count).to eq(0) end diff --git a/spec/services/profiles/update_spec.rb b/spec/services/profiles/update_spec.rb index db02e0449..285e31dbd 100644 --- a/spec/services/profiles/update_spec.rb +++ b/spec/services/profiles/update_spec.rb @@ -118,11 +118,11 @@ RSpec.describe Profiles::Update, type: :service do end end - it "doesn't enqueue resave articles job when changing #{username_field} for a banned user" do - banned_user = create(:user, :banned) + it "doesn't enqueue resave articles job when changing #{username_field} for a suspended user" do + suspended_user = create(:user, :suspended) expect do - described_class.call(banned_user, user: { username_field => "greatnewusername" }) + described_class.call(suspended_user, user: { username_field => "greatnewusername" }) end.not_to change(Users::ResaveArticlesWorker.jobs, :size) end end diff --git a/spec/services/re_captcha/check_enabled_spec.rb b/spec/services/re_captcha/check_enabled_spec.rb index 540cc3932..7936475dc 100644 --- a/spec/services/re_captcha/check_enabled_spec.rb +++ b/spec/services/re_captcha/check_enabled_spec.rb @@ -52,11 +52,11 @@ RSpec.describe ReCaptcha::CheckEnabled, type: :request do expect(described_class.call(vomitted_user)).to be(true) end - it "marks ReCaptcha as enabled when a banned user is logged in" do - older_user.add_role(:banned) + it "marks ReCaptcha as enabled when a suspended user is logged in" do + older_user.add_role(:suspended) sign_in older_user expect(described_class.call(older_user)).to be(true) - older_user.remove_role(:banned) + older_user.remove_role(:suspended) end end end diff --git a/spec/services/search/query_builders/user_spec.rb b/spec/services/search/query_builders/user_spec.rb index 7bc2de36b..363aa907e 100644 --- a/spec/services/search/query_builders/user_spec.rb +++ b/spec/services/search/query_builders/user_spec.rb @@ -29,7 +29,7 @@ RSpec.describe Search::QueryBuilders::User, type: :service do it "applies EXCLUDED_TERM_KEYS by default" do filter = described_class.new(params: {}) expected_filters = [ - { "terms" => { "roles" => ["banned"] } }, + { "terms" => { "roles" => %w[suspended banned] } }, ] expect(filter.as_hash.dig("query", "bool", "must_not")).to match_array(expected_filters) end @@ -43,7 +43,7 @@ RSpec.describe Search::QueryBuilders::User, type: :service do } }] expected_filters = [ - { "terms" => { "roles" => ["banned"] } }, + { "terms" => { "roles" => %w[suspended banned] } }, ] expect(filter.as_hash.dig("query", "bool", "must_not")).to match_array(expected_filters) expect(filter.as_hash.dig("query", "bool", "must")).to match_array(expected_query) diff --git a/spec/services/search/user_spec.rb b/spec/services/search/user_spec.rb index 8903d190a..731142747 100644 --- a/spec/services/search/user_spec.rb +++ b/spec/services/search/user_spec.rb @@ -46,9 +46,9 @@ RSpec.describe Search::User, type: :service do context "with a filter" do it "searches by excluding roles" do user1.add_role(:admin) - user2.add_role(:banned) + user2.add_role(:suspended) index_documents([user1, user2]) - query_params = { size: 5, exclude_roles: ["banned"] } + query_params = { size: 5, exclude_roles: %w[suspended banned] } user_docs = described_class.search_documents(params: query_params) expect(user_docs.count).to eq(1) diff --git a/spec/services/tag_moderators/add_trusted_role_spec.rb b/spec/services/tag_moderators/add_trusted_role_spec.rb index 8b6c904e2..febb97517 100644 --- a/spec/services/tag_moderators/add_trusted_role_spec.rb +++ b/spec/services/tag_moderators/add_trusted_role_spec.rb @@ -7,8 +7,8 @@ RSpec.describe TagModerators::AddTrustedRole, type: :service do expect { described_class.call(user) }.to change { user.reload.roles.size }.by(1) end - it "does not add the fole for banned users" do - user = create(:user, :banned) + it "does not add the fole for suspended users" do + user = create(:user, :suspended) expect { described_class.call(user) }.not_to change { user.reload.roles.size } end diff --git a/spec/services/users/delete_spec.rb b/spec/services/users/delete_spec.rb index cc8edb61d..53d686472 100644 --- a/spec/services/users/delete_spec.rb +++ b/spec/services/users/delete_spec.rb @@ -185,9 +185,9 @@ RSpec.describe Users::Delete, type: :service do end end - context "when the user was banned" do + context "when the user was suspended" do it "stores a hash of the username so the user can't sign up again" do - user = create(:user, :banned) + user = create(:user, :suspended) expect do described_class.call(user) end.to change(Users::SuspendedUsername, :count).by(1) diff --git a/spec/system/admin/admin_bans_or_warns_user_spec.rb b/spec/system/admin/admin_bans_or_warns_user_spec.rb index b9dbd0ab3..174459df4 100644 --- a/spec/system/admin/admin_bans_or_warns_user_spec.rb +++ b/spec/system/admin/admin_bans_or_warns_user_spec.rb @@ -51,7 +51,7 @@ RSpec.describe "Admin bans user", type: :system do # to-do: add spec for invalid bans it "checks that the user is suspended and has note" do suspend_user - expect(user.banned).to eq(true) + expect(user.suspended?).to eq(true) expect(Note.last.reason).to eq "Suspend" end @@ -60,16 +60,16 @@ RSpec.describe "Admin bans user", type: :system do add_tag_moderator_role suspend_user - expect(user.banned).to eq(true) + expect(user.suspended?).to eq(true) expect(user.trusted).to eq(false) expect(user.warned).to eq(false) expect(user.has_role?(:tag_modertor)).to eq(false) end - it "unbans user" do - user.add_role(:banned) + it "unsuspends user" do + user.add_role(:suspended) unsuspend_user - expect(user.has_role?(:banned)).to eq(false) + expect(user.has_role?(:suspended)).to eq(false) end end diff --git a/spec/system/authentication/user_with_suspended_username_spec.rb b/spec/system/authentication/user_with_suspended_username_spec.rb index ce4c2a999..d8e0df34c 100644 --- a/spec/system/authentication/user_with_suspended_username_spec.rb +++ b/spec/system/authentication/user_with_suspended_username_spec.rb @@ -11,7 +11,7 @@ RSpec.describe "User with suspended username tried to sign up via OAuth" do allow(ForemStatsClient).to receive(:increment) end - context "when a user has been previously banned", :aggregate_failures do + context "when a user has been previously suspended", :aggregate_failures do it "displays an error message" do username = OmniAuth.config.mock_auth[:twitter].extra.raw_info.username create(:suspended_username, username: username) @@ -20,13 +20,13 @@ RSpec.describe "User with suspended username tried to sign up via OAuth" do click_on("Continue with Twitter", match: :first) expect(page).to have_current_path(root_path) - expected_message = ::Authentication::Errors::PreviouslyBanned.new.message + expected_message = ::Authentication::Errors::PreviouslySuspended.new.message expect(page).to have_content(expected_message) expect(ForemStatsClient) .to have_received(:increment) .with("identity.errors", tags: [ - "error:Authentication::Errors::PreviouslyBanned", + "error:Authentication::Errors::PreviouslySuspended", "message:#{expected_message}", ]) end diff --git a/spec/system/banned_user_interactions_spec.rb b/spec/system/banned_user_interactions_spec.rb index f68c72c9a..f24d9f570 100644 --- a/spec/system/banned_user_interactions_spec.rb +++ b/spec/system/banned_user_interactions_spec.rb @@ -1,10 +1,10 @@ require "rails_helper" -RSpec.describe "Banned user", type: :system do - let(:banned_user) { create(:user, :banned) } +RSpec.describe "Suspended user", type: :system do + let(:suspended_user) { create(:user, :suspended) } it "tries to create an article" do - sign_in banned_user - expect { visit "/new" }.to raise_error("SUSPENDED") + sign_in suspended_user + expect { visit "/new" }.to raise_error(SuspendedError) end end diff --git a/spec/workers/moderator/banish_user_worker_spec.rb b/spec/workers/moderator/banish_user_worker_spec.rb index 41fd72ead..dbf4cd8ad 100644 --- a/spec/workers/moderator/banish_user_worker_spec.rb +++ b/spec/workers/moderator/banish_user_worker_spec.rb @@ -18,9 +18,9 @@ RSpec.describe Moderator::BanishUserWorker, type: :worker do user.reload end - it "makes user banned and username spam" do + it "makes user suspended and username spam" do expect(user.username).to include("spam") - expect(user.has_role?(:banned)).to be true + expect(user.has_role?(:suspended)).to be true end it "deletes user content" do