Commit 06dd530edecf90711c5bf7fe6918729a0096a572
Exists in
master
and in
4 other branches
Merge branch 'user_delete_account' of /home/git/repositories/gitlab/gitlabhq
Showing
3 changed files
with
66 additions
and
1 deletions
Show diff stats
app/controllers/registrations_controller.rb
1 | 1 | class RegistrationsController < Devise::RegistrationsController |
2 | 2 | before_filter :signup_enabled? |
3 | 3 | |
4 | + def destroy | |
5 | + if current_user.owned_projects.count > 0 | |
6 | + redirect_to account_profile_path, alert: "Remove projects and groups before removing account." and return | |
7 | + end | |
8 | + current_user.destroy | |
9 | + | |
10 | + respond_to do |format| | |
11 | + format.html { redirect_to new_user_session_path, notice: "Account successfully removed." } | |
12 | + end | |
13 | + end | |
14 | + | |
4 | 15 | private |
5 | 16 | |
6 | 17 | def signup_enabled? | ... | ... |
app/views/profiles/account.html.haml
... | ... | @@ -77,4 +77,10 @@ |
77 | 77 | .input |
78 | 78 | = f.submit 'Save username', class: "btn btn-save" |
79 | 79 | |
80 | - | |
80 | +- if Gitlab.config.gitlab.signup_enabled | |
81 | + %fieldset.remove-account | |
82 | + %legend | |
83 | + Remove account | |
84 | + %small.cred.pull-right | |
85 | + Before removing the account you must remove all projects! | |
86 | + = link_to 'Delete account', user_registration_path, confirm: "REMOVE #{current_user.name}? Are you sure?", method: :delete, class: "btn btn-remove delete-key btn-small pull-right" | |
81 | 87 | \ No newline at end of file | ... | ... |
... | ... | @@ -0,0 +1,48 @@ |
1 | +require 'spec_helper' | |
2 | + | |
3 | +describe "Profile account page" do | |
4 | + let(:user) { create(:user) } | |
5 | + | |
6 | + before do | |
7 | + login_as :user | |
8 | + end | |
9 | + | |
10 | + describe "when signup is enabled" do | |
11 | + before do | |
12 | + Gitlab.config.gitlab.stub(:signup_enabled).and_return(true) | |
13 | + visit account_profile_path | |
14 | + end | |
15 | + it { page.should have_content("Remove account") } | |
16 | + | |
17 | + it "should delete the account", js: true do | |
18 | + expect { click_link "Delete account" }.to change {User.count}.by(-1) | |
19 | + current_path.should == new_user_session_path | |
20 | + end | |
21 | + end | |
22 | + | |
23 | + describe "when signup is enabled and user has a project" do | |
24 | + before do | |
25 | + Gitlab.config.gitlab.stub(:signup_enabled).and_return(true) | |
26 | + @project = create(:project, namespace: @user.namespace) | |
27 | + @project.team << [@user, :master] | |
28 | + visit account_profile_path | |
29 | + end | |
30 | + it { page.should have_content("Remove account") } | |
31 | + | |
32 | + it "should not allow user to delete the account" do | |
33 | + expect { click_link "Delete account" }.not_to change {User.count}.by(-1) | |
34 | + end | |
35 | + end | |
36 | + | |
37 | + describe "when signup is disabled" do | |
38 | + before do | |
39 | + Gitlab.config.gitlab.stub(:signup_enabled).and_return(false) | |
40 | + visit account_profile_path | |
41 | + end | |
42 | + | |
43 | + it "should not have option to remove account" do | |
44 | + page.should_not have_content("Remove account") | |
45 | + current_path.should == account_profile_path | |
46 | + end | |
47 | + end | |
48 | +end | |
0 | 49 | \ No newline at end of file | ... | ... |