Rename banned and comment_banned roles (#12270)
* Rename banned and comment_banned roles * Add data update script to rename roles containing 'ban' * Add named error for Suspended users * Update unidiomatic method names * Rename misc banned to suspended * Apply suggestions from code review Co-authored-by: Michael Kohl <me@citizen428.net> * Add unit tests for suspended methods This commit also adds TODO comments for removing banned and comment_banned from the codebase after data update scripts have successfully run on all of our Forems. Co-authored-by: Michael Kohl <me@citizen428.net>
This commit is contained in:
parent
fa20539238
commit
a5b2d109d5
76 changed files with 208 additions and 164 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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?
|
||||
|
|
|
|||
|
|
@ -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: {
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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?
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
module Authentication
|
||||
module Errors
|
||||
PREVIOUSLY_BANNED_MESSAGE = "It appears that your previous %<community_name>s " \
|
||||
PREVIOUSLY_SUSPENDED_MESSAGE = "It appears that your previous %<community_name>s " \
|
||||
"account was suspended. As such, we've taken measures to prevent you from " \
|
||||
"creating a new account with %<community_name>s and its community. If you " \
|
||||
"think that there has been a mistake, please email us at %<community_email>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
|
||||
|
|
|
|||
1
app/errors/suspended_error.rb
Normal file
1
app/errors/suspended_error.rb
Normal file
|
|
@ -0,0 +1 @@
|
|||
class SuspendedError < StandardError; end
|
||||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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?
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
class ApiSecretPolicy < ApplicationPolicy
|
||||
def create?
|
||||
!user_is_banned?
|
||||
!user_suspended?
|
||||
end
|
||||
|
||||
def destroy?
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ class ArticlePolicy < ApplicationPolicy
|
|||
end
|
||||
|
||||
def create?
|
||||
!user_is_banned?
|
||||
!user_suspended?
|
||||
end
|
||||
|
||||
def delete_confirm?
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ class ChatChannelPolicy < ApplicationPolicy
|
|||
end
|
||||
|
||||
def moderate?
|
||||
!user_is_banned? && codeland_admin?
|
||||
!user_suspended? && codeland_admin?
|
||||
end
|
||||
|
||||
def show?
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
class ImageUploadPolicy < ApplicationPolicy
|
||||
def create?
|
||||
!user_is_banned?
|
||||
!user_suspended?
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
class MessagePolicy < ApplicationPolicy
|
||||
def create?
|
||||
!user_is_banned?
|
||||
!user_suspended?
|
||||
end
|
||||
|
||||
def destroy?
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
class OrganizationPolicy < ApplicationPolicy
|
||||
def create?
|
||||
!user.banned
|
||||
!user.suspended?
|
||||
end
|
||||
|
||||
def update?
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
class RatingVotePolicy < ApplicationPolicy
|
||||
def create?
|
||||
!user_is_banned?
|
||||
!user_suspended?
|
||||
end
|
||||
|
||||
def permitted_attributes
|
||||
|
|
|
|||
|
|
@ -4,6 +4,6 @@ class ReactionPolicy < ApplicationPolicy
|
|||
end
|
||||
|
||||
def create?
|
||||
!user_is_banned?
|
||||
!user_suspended?
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -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?
|
||||
|
|
|
|||
|
|
@ -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?
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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?
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@
|
|||
<span>
|
||||
<strong><%= reaction.reactable_type %>:</strong>
|
||||
<a href="<%= reaction.reactable.path %>" target="_blank" rel="noopener"><%= reaction.reactable_type == "User" ? reaction.reactable.username : reaction.reactable.title %></a>
|
||||
<% if reaction.reactable_type == "User" && reaction.reactable.banned %>
|
||||
<% if reaction.reactable_type == "User" && reaction.reactable.suspended? %>
|
||||
<span class="badge badge-danger">Suspended</span>
|
||||
<% end %>
|
||||
<% if reaction.reactable_type == "User" && reaction.reactable.vomitted_on? %>
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
<div class="crayons-card__body">
|
||||
<ul>
|
||||
<% @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 %>
|
||||
<li><%= role_display_name(role) %> <em><%= role.resource_name.to_s %></em></li>
|
||||
<% else %>
|
||||
<li>
|
||||
|
|
|
|||
|
|
@ -20,11 +20,11 @@
|
|||
<div>
|
||||
<h2>
|
||||
User Status
|
||||
<% if @user.banned %>
|
||||
<% if @user.suspended? %>
|
||||
<span class="badge badge-danger">🚨 Member is Suspended 🚨</span>
|
||||
<% elsif @user.warned %>
|
||||
<span class="badge badge-warning">Member is Warned</span>
|
||||
<% elsif @user.comment_banned %>
|
||||
<% elsif @user.comment_suspended? %>
|
||||
<span class="badge badge-warning">Member is Comment Suspended</span>
|
||||
<% elsif @user.trusted %>
|
||||
<span class="badge badge-success">Member is Trusted</span>
|
||||
|
|
|
|||
|
|
@ -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? %>
|
||||
<meta name="robots" content="noindex">
|
||||
<meta name="robots" content="nofollow">
|
||||
<% end %>
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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) }
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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] }
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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]) }
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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]) }
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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]) }
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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" } }
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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("<meta name=\"robots\" content=\"noindex\">")
|
||||
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("<meta name=\"robots\" content=\"noindex\">")
|
||||
end
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue