Merge branch 'master' into experiment/ticket-ui-2

This commit is contained in:
scott
2018-05-04 15:19:50 -06:00
4 changed files with 61 additions and 32 deletions

View File

@@ -0,0 +1,25 @@
class DeleteUserJob < ActiveJob::Base
queue_as :default
def perform(user_id)
user = User.find(user_id)
return if user.is_admin?
return if user.id == 2 #prevent the system user from being destroyed
topic_posts = Post.where(topic_id: Topic.where(user_id: user.id))
# move any authored docs to system user
Doc.where(user_id: user.id).update_all(user_id: 2)
# unassign from any topics assigned to
user.unassign_all
# Remove all posts in threads created by destroyed user
topic_posts.destroy_all
# Remove PII from any backups or import errors
user.destroy
end
end

View File

@@ -91,12 +91,12 @@ class User < ActiveRecord::Base
# Relationships
has_many :topics, dependent: :delete_all
has_many :posts, dependent: :delete_all
has_many :votes, dependent: :delete_all
has_many :topics, dependent: :destroy
has_many :posts, dependent: :destroy
has_many :votes, dependent: :destroy
has_many :docs
has_many :backups, dependent: :delete_all
has_many :api_keys, dependent: :delete_all
has_many :api_keys, dependent: :destroy
has_attachment :avatar, accept: [:jpg, :png, :gif]
is_gravtastic
@@ -136,21 +136,7 @@ class User < ActiveRecord::Base
return if self.is_admin?
return if self.id == 2 #prevent the system user from being destroyed
topic_posts = Post.where(topic_id: Topic.where(user_id: self.id))
# move any authored docs to system user
Doc.where(user_id: self.id).update_all(user_id: 2)
# unassign from any topics assigned to
self.unassign_all
# Remove all posts in threads created by destroyed user
topic_posts.destroy_all
# Remove PII from any backups or import errors
self.destroy
DeleteUserJob.perform_later(self.id)
end
# Removes or anonymizes associated records

View File

@@ -4,11 +4,12 @@ namespace :db do
require 'faker'
# How many fake objects to create
number_support_team = 3
number_users = 10
number_docs = rand(5..10)
number_threads = rand(5..15)
number_tickets = rand(20..50)
number_support_team = 2
number_users = 5
number_docs = 3
number_doc_comments = 0
number_threads = 0
number_tickets = 15
groups = [[0, 'billing'],[1, 'shipping'],[2, 'returns'],[3, '']]
@@ -115,7 +116,7 @@ namespace :db do
title: title,
body: Faker::Lorem.paragraphs(rand(1..5)).join('<br/><br/>'),
meta_description: Faker::Lorem.sentences(1),
user_id: rand(1..5)
user_id: User.team.sample.id
)
puts "Created Doc: #{doc.title}"
end
@@ -130,10 +131,10 @@ namespace :db do
Doc.all.each do |doc|
f = Forum.where(name: 'Doc comments').first
rand(0..2).times do
number_doc_comments.times do
topic = f.topics.create!(
name: build_question(Faker::Hacker.ingverb + " " + Faker::Hacker.noun),
user_id: User.where(admin: false).sample.id,
user_id: User.customers.sample.id,
doc_id: doc.id
)
post = topic.posts.create!(
@@ -149,7 +150,7 @@ namespace :db do
rand(0..5).times do
post = topic.posts.create!(
body: Faker::Lorem.paragraphs(rand(1..2)).join('<br/><br/>'),
user_id: rand(4..14),
user_id: User.customers.sample.id,
kind: 'reply'
)
puts "Post added to doc"
@@ -169,7 +170,7 @@ namespace :db do
f = Forum.find(rand(3..6))
topic = f.topics.new
topic.name = build_question(Faker::Hacker.ingverb + " " + Faker::Hacker.noun)
topic.user_id = User.where(admin: false).sample.id
topic.user_id = User.customers.sample.id
if f.private?
topic.private = true
puts "Private Ticket Created!"
@@ -196,7 +197,7 @@ namespace :db do
rand(2..5).times do
post = topic.posts.create!(
body: Faker::Lorem.paragraphs(rand(1..3)).join('<br/><br/>'),
user_id: rand(3..12),
user_id: User.customers.sample.id,
kind: 'reply'
)
puts "Post added to topic"
@@ -218,9 +219,9 @@ namespace :db do
topic = f.topics.create!(
name: ticket_issue.split("|")[0],
user_id: User.where(admin: false).sample.id,
user_id: User.customers.sample.id,
private: true,
assigned_user_id: User.where(admin: true).sample.id,
assigned_user_id: User.agents.sample.id,
team_list: ticket_issue.split("|")[1]
)

View File

@@ -0,0 +1,17 @@
require 'test_helper'
class DeleteUserJobTest < ActiveJob::TestCase
test "all user articles should be deleted" do
u = User.find(9)
assert_difference 'Topic.all.count', -7 do
assert_difference "Post.all.count", -9 do
DeleteUserJob.perform_now(u.id)
end
end
assert_equal 0, Topic.where(user_id: u.id).count
assert_equal 0, Post.where(user_id: u.id).count
assert_equal 0, ApiKey.where(user_id: u.id).count
end
end