Allow deleting users to disown their comments

This commit is contained in:
Peter Bhat Harkins 2018-01-29 13:03:45 -06:00
parent 6810e23854
commit 27febc315e
6 changed files with 63 additions and 29 deletions

View File

@ -98,12 +98,10 @@ in a `config/initializers/production.rb` or similar file:
* Put your site's custom CSS in `app/assets/stylesheets/local`.
* Seed the database to create an initial administrator user and at least one tag:
* Seed the database to create an initial administrator user, the `inactive-user`, and at least one tag:
```sh
lobsters$ rake db:seed
created user: test, password: test
created tag: test
```
* Run the Rails server in development mode. You should be able to login to

View File

@ -234,6 +234,11 @@ button:disabled {
color: gray;
}
input.deletion {
color: darkred;
border: 1px solid darkred;
}
.totp_code::-webkit-inner-spin-button,
.totp_code::-webkit-outer-spin-button {
-webkit-appearance: none;

View File

@ -12,6 +12,9 @@ class SettingsController < ApplicationController
def delete_account
if @user.try(:authenticate, params[:user][:password].to_s)
@user.delete!
if params[:disown].present?
@user.disown_comments!
end
reset_session
flash[:success] = "Your account has been deleted."
return redirect_to "/"

View File

@ -85,9 +85,9 @@ class User < ActiveRecord::Base
end
BANNED_USERNAMES = [ "admin", "administrator", "contact", "fraud", "guest",
"help", "hostmaster", "mailer-daemon", "moderator", "moderators", "nobody",
"postmaster", "root", "security", "support", "sysop", "webmaster",
"enable", "new", "signup", ]
"help", "hostmaster", "inactive-user", "mailer-daemon", "moderator",
"moderators", "nobody", "postmaster", "root", "security", "support",
"sysop", "webmaster", "enable", "new", "signup", ]
# days old accounts are considered new for
NEW_USER_DAYS = 7
@ -344,6 +344,11 @@ class User < ActiveRecord::Base
end
end
def disown_comments!
inactive_user = User.find_by!(:username => 'inactive-user')
self.comments.update_all(:user_id => inactive_user.id)
end
def disable_2fa!
self.totp_secret = nil
self.save!

View File

@ -300,28 +300,41 @@
<br>
<br>
<%= form_for @edit_user, :url => delete_account_path, :method => :post,
:html => { :id => "delete_user" } do |f| %>
<div class="legend">
Delete Account
</div>
<div class="deletion">
<%= form_for @edit_user, :url => delete_account_path, :method => :post,
:html => { :id => "delete_user" } do |f| %>
<div class="legend">
Delete Account
</div>
<p>
To permanently delete your account, verify your current password below.
Your account will be put into a deleted state, your comments will be marked
as deleted and no longer readable by any other users, and your private
messages will be deleted.
Your submitted stories will not be deleted.
Your username will remain reserved and will not be available to be used on
any other account.
</p>
<p>
To permanently delete your account, verify your current password below.
</p>
<ul>
<li>Your account will be put into a deleted state.</li>
<li>Your username will remain reserved and will not be available to be
used on any other account.</li>
<li>Your private messages will be deleted.</li>
<li>Your submitted stories will not be deleted.</li>
<li>
Your comments with negative scores will be deleted, and you can click
"disown comments" below if you want all of your comments to change to
list <a href="/u/inactive-user">inactive-user</a> as the author
instead of your username.
</li>
</ul>
<div class="boxline">
<%= f.label :password, "Verify Password:", :class => "required" %>
<%= f.password_field :password, :size => 40, :autocomplete => "off" %>
</div>
<div class="boxline">
<%= f.label :password, "Verify Password:", :class => "required" %>
<%= f.password_field :password, :size => 40, :autocomplete => "off" %>
</div>
<div class="boxline">
<%= f.label :disown, "Disown Comments:" %>
<%= check_box_tag :disown %>
</div>
<br>
<%= f.submit "Yes, Delete My Account" %>
<% end %>
<br>
<%= f.submit "Yes, Delete My Account", :class => "deletion" %>
<% end %>
</div>
</div>

View File

@ -1,4 +1,14 @@
pwd = SecureRandom.base58
User.create(:username => "inactive-user", :email => "inactive-user@example.com", :password => pwd, :password_confirmation => pwd)
User.create(:username => "test", :email => "test@example.com", :password => "test", :password_confirmation => "test", :is_admin => true, :is_moderator => true)
puts "created user: test, password: test"
Tag.create(:tag => "test")
puts "created tag: test"
puts "created:"
puts " * an admin with username/password of test/test"
puts " * inactive-user for disowned comments by deleted users"
puts " * a test tag"
puts
puts "If this is a dev environment, you probably want to run `rails fake_data`"
puts "If this is production, you want to run `rails console` to rename your admin and tag"