Remove ghostify from app (#10139)
* Remove ghostify from app * Remove unused ghostify specs
This commit is contained in:
parent
6298715612
commit
0b849341e0
9 changed files with 12 additions and 140 deletions
|
|
@ -58,9 +58,9 @@ module Admin
|
|||
def full_delete
|
||||
@user = User.find(params[:id])
|
||||
begin
|
||||
Moderator::DeleteUser.call(admin: current_user, user: @user, user_params: user_params)
|
||||
Moderator::DeleteUser.call(user: @user)
|
||||
message = "@#{@user.username} (email: #{@user.email.presence || 'no email'}, user_id: #{@user.id}) " \
|
||||
"has been fully deleted. If requested, old content may have been ghostified. " \
|
||||
"has been fully deleted." \
|
||||
"If this is a GDPR delete, delete them from Mailchimp & Google Analytics."
|
||||
flash[:success] = message
|
||||
rescue StandardError => e
|
||||
|
|
@ -186,7 +186,7 @@ module Admin
|
|||
allowed_params = %i[
|
||||
new_note note_for_current_role user_status
|
||||
pro merge_user_id add_credits remove_credits
|
||||
add_org_credits remove_org_credits ghostify
|
||||
add_org_credits remove_org_credits
|
||||
organization_id identity_id backup_data_id
|
||||
]
|
||||
params.require(:user).permit(allowed_params)
|
||||
|
|
|
|||
|
|
@ -266,8 +266,6 @@ class UsersController < ApplicationController
|
|||
handle_integrations_tab
|
||||
when "billing"
|
||||
handle_billing_tab
|
||||
when "account"
|
||||
handle_account_tab
|
||||
when "response-templates"
|
||||
handle_response_templates_tab
|
||||
else
|
||||
|
|
@ -335,17 +333,6 @@ class UsersController < ApplicationController
|
|||
@customer = Payments::Customer.get(stripe_code) if stripe_code.present?
|
||||
end
|
||||
|
||||
def handle_account_tab
|
||||
community_name = SiteConfig.community_name
|
||||
@email_body = <<~HEREDOC
|
||||
Hello #{community_name} Team,\n
|
||||
I would like to delete my account.\n
|
||||
You can keep any comments and discussion posts under the Ghost account.\n
|
||||
Regards,
|
||||
YOUR-#{community_name}-USERNAME-HERE
|
||||
HEREDOC
|
||||
end
|
||||
|
||||
def handle_response_templates_tab
|
||||
@response_templates = current_user.response_templates
|
||||
@response_template = ResponseTemplate.find_or_initialize_by(id: params[:id], user: current_user)
|
||||
|
|
|
|||
|
|
@ -92,8 +92,7 @@ class User < ApplicationRecord
|
|||
}.freeze
|
||||
|
||||
attr_accessor :scholar_email, :new_note, :note_for_current_role, :user_status, :pro, :merge_user_id,
|
||||
:add_credits, :remove_credits, :add_org_credits, :remove_org_credits, :ghostify,
|
||||
:ip_address
|
||||
:add_credits, :remove_credits, :add_org_credits, :remove_org_credits, :ip_address
|
||||
|
||||
rolify after_add: :index_roles, after_remove: :index_roles
|
||||
|
||||
|
|
|
|||
|
|
@ -1,21 +1,9 @@
|
|||
module Moderator
|
||||
class DeleteUser < ManageActivityAndRoles
|
||||
attr_reader :user, :admin, :user_params
|
||||
attr_reader :user, :user_params
|
||||
|
||||
def self.call(admin:, user:, user_params:)
|
||||
if user_params[:ghostify] == "true"
|
||||
new(user: user, admin: admin, user_params: user_params).ghostify
|
||||
else
|
||||
Users::DeleteWorker.perform_async(user.id, true)
|
||||
end
|
||||
end
|
||||
|
||||
def ghostify
|
||||
@ghost = User.find_by(username: "ghost")
|
||||
reassign_articles
|
||||
reassign_comments
|
||||
delete_user
|
||||
CacheBuster.bust("/ghost")
|
||||
def self.call(user:)
|
||||
Users::DeleteWorker.perform_async(user.id, true)
|
||||
end
|
||||
|
||||
private
|
||||
|
|
@ -23,25 +11,5 @@ module Moderator
|
|||
def delete_user
|
||||
Users::DeleteWorker.new.perform(user.id, true)
|
||||
end
|
||||
|
||||
def reassign_comments
|
||||
return unless user.comments.any?
|
||||
|
||||
user.comments.find_each do |comment|
|
||||
comment.update(user_id: @ghost.id)
|
||||
end
|
||||
@ghost.touch(:last_comment_at)
|
||||
end
|
||||
|
||||
def reassign_articles
|
||||
return unless user.articles.any?
|
||||
|
||||
# preload associations that are going to be used during indexing
|
||||
user.articles.preload(:organization, :tag_taggings, :tags).find_each do |article|
|
||||
path = "/#{@ghost.username}/#{article.slug}"
|
||||
article.update_columns(user_id: @ghost.id, path: path)
|
||||
article.index_to_elasticsearch_inline
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -147,18 +147,6 @@
|
|||
</div>
|
||||
|
||||
<% if current_user.has_role?(:super_admin) %>
|
||||
<div class="mb-6">
|
||||
<h3>Delete User & Turn Content Into Ghost</h3>
|
||||
<p>This will
|
||||
<strong>completely destroy the user</strong> and convert all of their articles & comments into a ghost author. This action is irreversible.
|
||||
</p>
|
||||
<p><strong>Do not do this lightly.</strong></p>
|
||||
<%= form_for(@user, url: full_delete_admin_user_path(@user), html: { method: :post, onsubmit: "return confirm('Are you sure? 👻 This is extremely destructive and irreversible. The user will be deleted and their articles & comments will be converted to Ghost')" }) do |f| %>
|
||||
<%= f.hidden_field :ghostify, value: true %>
|
||||
<button class="btn btn-danger">👻 Fully Delete User & Ghostify 👻</button>
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<h3>Fully Delete User</h3>
|
||||
<p>This will
|
||||
|
|
@ -166,7 +154,6 @@
|
|||
</p>
|
||||
<p><strong>Do not do this lightly.</strong></p>
|
||||
<%= form_for(@user, url: full_delete_admin_user_path(@user), html: { method: :post, onsubmit: "return confirm('Are you sure? This is extremely destructive and irreversible.')" }) do |f| %>
|
||||
<%= f.hidden_field :ghostify, value: false %>
|
||||
<button class="btn btn-danger">☠️ Fully Delete User & All Activity ☠️</button>
|
||||
<% end %>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -105,13 +105,6 @@
|
|||
</div>
|
||||
|
||||
<div>
|
||||
<% if current_user.articles_count.positive? || current_user.comments_count.positive? %>
|
||||
<p>
|
||||
If you would like to keep your content under the <%= link_to "@ghost", "/ghost" %> account,
|
||||
please <%= email_link(text: "click here", additional_info: { subject: "Request Account Deletion", body: @email_body }) %>.
|
||||
</p>
|
||||
<% end %>
|
||||
|
||||
<p>Feel free to contact <%= email_link %> with any questions.</p>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -8,7 +8,6 @@ RSpec.describe "Admin::Users", type: :request do
|
|||
let(:article) { create(:article, user: user) }
|
||||
let(:article2) { create(:article, user: user2) }
|
||||
let(:badge) { create(:badge, title: "one-year-club") }
|
||||
let(:ghost) { create(:user, username: "ghost", github_username: "Ghost") }
|
||||
let(:organization) { create(:organization) }
|
||||
|
||||
before do
|
||||
|
|
@ -62,11 +61,6 @@ RSpec.describe "Admin::Users", type: :request do
|
|||
GithubRepo.create(params)
|
||||
end
|
||||
|
||||
def call_ghost
|
||||
ghost
|
||||
post "/admin/users/#{user.id}/full_delete", params: { user: { ghostify: "true" } }
|
||||
end
|
||||
|
||||
context "when merging users" do
|
||||
before do
|
||||
full_profile
|
||||
|
|
@ -170,25 +164,6 @@ RSpec.describe "Admin::Users", type: :request do
|
|||
expect(user.credits.size).to eq(2)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
context "when deleting user and converting content to ghost" do
|
||||
it "raises a 'record not found' error after deletion" do
|
||||
call_ghost
|
||||
expect { User.find(user.id) }.to raise_exception(ActiveRecord::RecordNotFound)
|
||||
end
|
||||
|
||||
it "reassigns comment and article content to ghost account" do
|
||||
create(:article, user: user)
|
||||
call_ghost
|
||||
articles = ghost.articles
|
||||
expect(articles.count).to eq(2)
|
||||
expect(ghost.comments.count).to eq(1)
|
||||
expect(ghost.comments.last.path).to include("ghost")
|
||||
expect(articles.last.path).to include("ghost")
|
||||
expect(articles.last.elasticsearch_doc.dig("_source", "path")).to include("ghost")
|
||||
end
|
||||
end
|
||||
|
||||
context "when deleting user" do
|
||||
def create_mention
|
||||
|
|
@ -217,13 +192,13 @@ RSpec.describe "Admin::Users", type: :request do
|
|||
|
||||
it "raises a 'record not found' error after deletion" do
|
||||
sidekiq_perform_enqueued_jobs do
|
||||
post "/admin/users/#{user.id}/full_delete", params: { user: { ghostify: "false" } }
|
||||
post "/admin/users/#{user.id}/full_delete"
|
||||
end
|
||||
expect { User.find(user.id) }.to raise_exception(ActiveRecord::RecordNotFound)
|
||||
end
|
||||
|
||||
it "expect flash message" do
|
||||
post "/admin/users/#{user.id}/full_delete", params: { user: { ghostify: "false" } }
|
||||
post "/admin/users/#{user.id}/full_delete"
|
||||
expect(request.flash["success"]).to include("fully deleted")
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -56,7 +56,6 @@ RSpec.describe "UserSettings", type: :request do
|
|||
end
|
||||
|
||||
describe ":account" do
|
||||
let(:ghost_account_message) { "If you would like to keep your content under the" }
|
||||
let(:remove_oauth_section) { "Remove OAuth Associations" }
|
||||
let(:user) { create(:user, :with_identity) }
|
||||
|
||||
|
|
@ -70,20 +69,6 @@ RSpec.describe "UserSettings", type: :request do
|
|||
expect(response).to have_http_status(:ok)
|
||||
end
|
||||
|
||||
it "does not render the ghost account email option if the user has no content" do
|
||||
get user_settings_path(tab: "account")
|
||||
expect(response.body).not_to include(ghost_account_message)
|
||||
end
|
||||
|
||||
it "does render the ghost account email option if the user has content" do
|
||||
create(:article, user: user)
|
||||
user.update(articles_count: 1)
|
||||
|
||||
get user_settings_path(tab: "account")
|
||||
|
||||
expect(response.body).to include(ghost_account_message)
|
||||
end
|
||||
|
||||
it "shows the 'Remove OAuth' section if a user has multiple enabled identities" do
|
||||
allow(Authentication::Providers).to receive(:enabled).and_return(Authentication::Providers.available)
|
||||
providers = Authentication::Providers.available.first(2)
|
||||
|
|
|
|||
|
|
@ -2,12 +2,11 @@ require "rails_helper"
|
|||
|
||||
RSpec.describe Moderator::DeleteUser, type: :service do
|
||||
let(:user) { create(:user) }
|
||||
let(:admin) { create(:user, :super_admin) }
|
||||
|
||||
describe "delete_user" do
|
||||
it "deletes user" do
|
||||
sidekiq_perform_enqueued_jobs do
|
||||
described_class.call(user: user, admin: admin, user_params: {})
|
||||
described_class.call(user: user)
|
||||
end
|
||||
expect(User.find_by(id: user.id)).to be_nil
|
||||
end
|
||||
|
|
@ -18,7 +17,7 @@ RSpec.describe Moderator::DeleteUser, type: :service do
|
|||
|
||||
expect do
|
||||
sidekiq_perform_enqueued_jobs do
|
||||
described_class.call(user: user, admin: admin, user_params: {})
|
||||
described_class.call(user: user)
|
||||
end
|
||||
end.to change(Follow, :count).by(-2)
|
||||
end
|
||||
|
|
@ -26,30 +25,9 @@ RSpec.describe Moderator::DeleteUser, type: :service do
|
|||
it "deletes user's articles" do
|
||||
article = create(:article, user: user)
|
||||
sidekiq_perform_enqueued_jobs do
|
||||
described_class.call(user: user, admin: admin, user_params: {})
|
||||
described_class.call(user: user)
|
||||
end
|
||||
expect(Article.find_by(id: article.id)).to be_nil
|
||||
end
|
||||
end
|
||||
|
||||
describe "#ghostify" do
|
||||
let(:deleter) { described_class.new(user: user, admin: admin, user_params: { ghostify: true }) }
|
||||
|
||||
before do
|
||||
user.update(username: "ghost")
|
||||
create(:article, user: user)
|
||||
end
|
||||
|
||||
it "reassigns articles" do
|
||||
allow(deleter).to receive(:reassign_articles)
|
||||
deleter.ghostify
|
||||
expect(deleter).to have_received(:reassign_articles)
|
||||
end
|
||||
|
||||
it "reassigns comments" do
|
||||
allow(deleter).to receive(:reassign_comments)
|
||||
deleter.ghostify
|
||||
expect(deleter).to have_received(:reassign_comments)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue