Skip to content

Commit 9d0b37f

Browse files
committed
Finalize account deletion api
1 parent 14643f0 commit 9d0b37f

File tree

8 files changed

+21
-7
lines changed

8 files changed

+21
-7
lines changed

app/controllers/api/v8/users/request_deletion_controller.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ class RequestDeletionController < Api::V8::BaseController
77
skip_authorization_check
88

99
def create
10-
user = User.find(params[:user_id])
10+
user = current_user
11+
user = User.find_by!(id: params[:user_id]) unless params[:user_id] == 'current'
1112
authorize! :destroy, user
1213
UserMailer.destroy_confirmation(user).deliver_now
1314
render json: {

app/controllers/users_controller.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,11 @@ def destroy_user
114114
token = VerificationToken.delete_user.find_by!(user: user, token: params[:id])
115115
username = user.login
116116
sign_out if current_user == user
117+
email = user.email
118+
username = user.login
117119
user.destroy
118-
redirect_to root_url, notice: "The account #{username} has been permanently destroyed."
120+
RecentlyChangedUserDetail.deleted.create!(old_value: false, new_value: true, email: email, username: username)
121+
redirect_to root_url, notice: "Your account has been permanently destroyed."
119122
end
120123

121124
def send_destroy_email
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
class RecentlyChangedUserDetail < ActiveRecord::Base
2-
enum change_type: [:email_changed]
2+
enum change_type: [:email_changed, :deleted]
33
end

app/views/user_mailer/destroy_confirmation.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<body>
77
<p>Hello!</p>
88

9-
<p>You have requested deleting your mooc.fi account "<%= @user.login %>".</p>
9+
<p>You have requested deleting your mooc.fi account.</p>
1010

1111
<p>Please proceed to the following link to continue the deletion process.</p>
1212

app/views/user_mailer/destroy_confirmation.text.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Hello!
22

3-
You have requested deleting your mooc.fi account "<%= @user.login %>".
3+
You have requested deleting your mooc.fi account.
44

55
Please proceed to the following link to continue the deletion process.
66

config/routes.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@
4242
namespace :v8, defaults: {format: 'json'} do
4343
resources :apidocs, only: :index, path: 'documentation'
4444

45-
resources :users, only: [:show, :create, :update]
45+
resources :users, only: [:show, :create, :update] do
46+
resources :request_deletion, only: [:create], module: :users
47+
end
4648

4749
namespace :users do
4850
resources :password_reset, only: [:create]
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
class AddUserFieldsToRecentlyChangedUserDetails < ActiveRecord::Migration
2+
def change
3+
add_column :recently_changed_user_details, :username, :string
4+
add_column :recently_changed_user_details, :email, :string
5+
end
6+
end

db/schema.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#
1212
# It's strongly recommended that you check this file into your version control system.
1313

14-
ActiveRecord::Schema.define(version: 20180608084626) do
14+
ActiveRecord::Schema.define(version: 20180613083429) do
1515

1616
# These are extensions that must be enabled in order to support this database
1717
enable_extension "plpgsql"
@@ -253,6 +253,8 @@
253253
t.string "new_value", null: false
254254
t.datetime "created_at"
255255
t.datetime "updated_at"
256+
t.string "username"
257+
t.string "email"
256258
end
257259

258260
create_table "reply_to_feedback_answers", force: :cascade do |t|

0 commit comments

Comments
 (0)