From 0b849341e0f4dda762953964500a57fc9df67f04 Mon Sep 17 00:00:00 2001 From: Andy Zhao <17884966+Zhao-Andy@users.noreply.github.com> Date: Tue, 1 Sep 2020 13:39:39 -0400 Subject: [PATCH] Remove ghostify from app (#10139) * Remove ghostify from app * Remove unused ghostify specs --- app/controllers/admin/users_controller.rb | 6 ++-- app/controllers/users_controller.rb | 13 ------- app/models/user.rb | 3 +- app/services/moderator/delete_user.rb | 38 ++------------------- app/views/admin/users/edit.html.erb | 13 ------- app/views/users/_account.html.erb | 7 ---- spec/requests/admin/users_manage_spec.rb | 29 ++-------------- spec/requests/user/user_settings_spec.rb | 15 -------- spec/services/moderator/delete_user_spec.rb | 28 ++------------- 9 files changed, 12 insertions(+), 140 deletions(-) diff --git a/app/controllers/admin/users_controller.rb b/app/controllers/admin/users_controller.rb index 19f5ceb85..4dde6d852 100644 --- a/app/controllers/admin/users_controller.rb +++ b/app/controllers/admin/users_controller.rb @@ -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) diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 50f8fbbaa..6fff81473 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -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) diff --git a/app/models/user.rb b/app/models/user.rb index 4e5682804..b0c040f9e 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -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 diff --git a/app/services/moderator/delete_user.rb b/app/services/moderator/delete_user.rb index a760bde9d..f6f5e1ca4 100644 --- a/app/services/moderator/delete_user.rb +++ b/app/services/moderator/delete_user.rb @@ -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 diff --git a/app/views/admin/users/edit.html.erb b/app/views/admin/users/edit.html.erb index 5956f2890..a46c0adb4 100644 --- a/app/views/admin/users/edit.html.erb +++ b/app/views/admin/users/edit.html.erb @@ -147,18 +147,6 @@ <% if current_user.has_role?(:super_admin) %> -
This will - completely destroy the user and convert all of their articles & comments into a ghost author. This action is irreversible. -
-Do not do this lightly.
- <%= 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 %> - - <% end %> -This will @@ -166,7 +154,6 @@
Do not do this lightly.
<%= 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 %> <% end %>- 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 }) %>. -
- <% end %> -Feel free to contact <%= email_link %> with any questions.