Skip to content

Commit 747c982

Browse files
committed
Don't let admins delete users with submissions
1 parent 385f48a commit 747c982

File tree

4 files changed

+17
-7
lines changed

4 files changed

+17
-7
lines changed

app/controllers/settings_controller.rb

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,16 @@ def update
3434
end
3535

3636
def dangerously_destroy_user
37+
@user = authenticate_current_user_destroy
38+
if @user.submissions.length != 0
39+
redirect_to user_has_submissions_participant_settings_url
40+
return
41+
end
3742
im_sure = params[:im_sure]
3843
if im_sure != '1'
3944
redirect_to verify_dangerously_destroying_user_participant_settings_url, notice: 'Please check the checkbox after you have read the instructions.'
4045
return
4146
end
42-
@user = authenticate_current_user_destroy
4347
username = @user.login
4448
sign_out if current_user == @user
4549
email = @user.email
@@ -53,6 +57,10 @@ def verify_dangerously_destroying_user
5357
@user = authenticate_current_user_destroy
5458
end
5559

60+
def user_has_submissions
61+
@user = authenticate_current_user_destroy
62+
end
63+
5664
private
5765

5866
def authenticate_current_user_destroy
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<div class="jumbotron hero-unit-alert alert-danger">
2+
You can't delete this user, because they have submissions. Advice them to delete their own account by pressing "Request deleting account" -button themselves from their User settings.
3+
<br>
4+
<br>
5+
<strong>Make sure that they realize they will lose their progress in all of their courses, and can't ever get any certificates etc. for anything they've done after account deletion.</strong>
6+
</div>

app/views/settings/verify_dangerously_destroying_user.html.erb

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,9 @@
11
<h1>Confirm deleting account: <%= @user.username %> (<%= @user.email %>)</h1>
22

3-
<div class="jumbotron hero-unit-alert alert-danger">
4-
Before deleting this user, make sure they don't have any submissions. If they have submissions, advice them to delete their own account by pressing "Request deleting account" -button themselves from their User settings.
5-
</div>
6-
7-
83
<%= form_tag(dangerously_destroy_user_participant_settings_path, method: :delete, class: 'form-horizontal') do %>
94
<div class="form-group">
105
<%= check_box_tag :im_sure %>
11-
<%= label_tag "I've read the above and I'm sure I understand the consequences", nil, class: "control-label", for: :im_sure %>
6+
<%= label_tag "I'm sure this user wants to be deleted.", nil, class: "control-label", for: :im_sure %>
127
</div>
138
<p><strong>Pressing the button below will permanently destroy this mooc.fi account.</strong></p>
149
<%= submit_tag("Destroy this account permanently", class: "btn btn-danger", data: { confirm: "Are you sure you want to delete the account #{@user.login}?"}, disabled: "disabled", id: :destroy_button) %>

config/routes.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,7 @@
240240
post 'dangerously_destroy_user', to: 'settings#dangerously_destroy_user'
241241
get 'verify_dangerously_destroying_user', to: 'settings#verify_dangerously_destroying_user'
242242
delete 'dangerously_destroy_user', to: 'settings#dangerously_destroy_user'
243+
get 'user_has_submissions', to: 'settings#user_has_submissions'
243244
end
244245
resources :certificates, only: [:index]
245246
collection do

0 commit comments

Comments
 (0)