Skip to content

Commit

Permalink
feat: delete user accounts
Browse files Browse the repository at this point in the history
  • Loading branch information
kjellberg committed Mar 30, 2024
1 parent 7e87de5 commit d8936ea
Show file tree
Hide file tree
Showing 13 changed files with 142 additions and 28 deletions.
4 changes: 2 additions & 2 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ namespace :lint do
end

task :default do
Rake::Task["lint:standard"].invoke
Rake::Task["lint:erb"].invoke
Rake::Task["test"].invoke
Rake::Task["test:system"].invoke
Rake::Task["lint:standard"].invoke
Rake::Task["lint:erb"].invoke
end
10 changes: 10 additions & 0 deletions app/assets/stylesheets/application.tailwind.css
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,13 @@
@apply border border-rose-500;
}
}

@layer components {
.box {
@apply bg-surface w-full rounded-lg p-8 shadow;
}

.kiqr-button {
@apply border-border rounded bg-rose-500 px-4 py-2 text-white;
}
}
4 changes: 4 additions & 0 deletions app/controllers/users/cancellations_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class Users::CancellationsController < ApplicationController
def show
end
end
9 changes: 8 additions & 1 deletion app/views/partials/navigations/_settings.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<%= render(PageLayouts::Settings::NavigationItem::Component.new(
label: t('.items.account.label'),
description: t('.items.account.description'),
icon: "fa fa-user",
icon: Current.account.personal? ? "fa fa-user" : "fa fa-users",
path: edit_account_path
)) %>

Expand All @@ -21,3 +21,10 @@
icon: "fa fa-lock",
path: edit_user_registration_path
)) %>

<%= render(PageLayouts::Settings::NavigationItem::Component.new(
label: t('.items.delete_user.label'),
description: t('.items.delete_user.description'),
icon: "fa fa-person-circle-minus",
path: delete_user_registration_path
)) %>
16 changes: 16 additions & 0 deletions app/views/users/cancellations/show.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<% title t(".title") %>

<%= render(PageLayouts::Settings::Component.new(
title: t(".title"),
description: t(".description")
)) do %>
<div class="box">
<header class="border-b pb-4 mb-4">
<h3 class="font-bold text-primary uppercase"><%= t(".box_title") %></h3>
</header>
<article class="prose">
<p><%= t(".content") %></p>
<%= button_to t(".submit"), user_registration_path, name: "commit", class:"kiqr-button", data: { confirm: t(".confirmation_message"), turbo_confirm: t(".confirmation_message") }, method: :delete %>
</article>
</div>
<% end %>
22 changes: 22 additions & 0 deletions app/views/users/registrations/edit.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<% title t(".title") %>

<%= render(PageLayouts::Settings::Component.new(
title: t(".title"),
description: t(".description")
)) do %>

<%= simple_form_for(resource, as: resource_name, url: registration_path(resource_name), html: { method: :put }) do |f| %>
<%= f.input :email, placeholder: t(".form.email.placeholder"), required: true, autofocus: true %>

<div class="flex flex-col lg:flex-row justify-between items-start gap-4">
<%= f.input :password, placeholder: t(".form.password.placeholder"), required: true, hint: ("#{@minimum_password_length} characters minimum" if @minimum_password_length), input_html: { autocomplete: "new-password" } %>
<%= f.input :password_confirmation, placeholder: t(".form.password_confirmation.placeholder"), required: true, input_html: { autocomplete: "new-password" } %>
</div>

<%= f.input :current_password, placeholder: t(".form.current_password.placeholder"), hint: t(".form.current_password.hint"), required: true, input_html: { autocomplete: "current-password" } %>

<div class="mt-4 flex justify-between items-center">
<%= f.button :submit, t(".form.submit_button") %>
</div>
<% end %>
<% end %>
29 changes: 27 additions & 2 deletions config/locales/kiqr.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,21 @@ en:
register: "Create account"
settings:
account_settings: "Account settings"
user_settings: "Login & security"
user_settings: "Your personal settings"
items:
account:
label: "Profile settings"
description: "Edit your account profile"
user:
label: "Login credentials"
description: "Change user email or password."
delete_user:
label: "Delete user account"
description: "Remove all user related data"
accounts:
edit:
title: "Profile settings"
description: "Edit your account profile"
description: "Edit your account profile."
update:
success: "Your account profile has been updated successfully."
form:
Expand Down Expand Up @@ -59,3 +62,25 @@ en:
submit_button: "Create your account"
already_have_account: Already have an account?
sign_in: Sign in!
edit:
title: "Login credentials"
description: "Change user email or password."
form:
email:
placeholder: "Enter a valid email address"
password:
placeholder: "Create a secure password"
password_confirmation:
placeholder: "Confirm your password"
current_password:
placeholder: "Enter your current password"
hint: "we need your current password to confirm your changes"
submit_button: "Save changes"
cancellations:
show:
title: "Delete account"
description: "Delete your user account and all of your data."
box_title: "Delete your user account"
content: "Need to cancel your account? No worries. We're sad to see you go but understand that sometimes things change. If you have any feedback or if there's anything we can do to improve your experience, please let us know. Your input is invaluable to us. Remember, you're always welcome back!"
submit: "Delete my account"
confirmation_message: "Are you sure? This will DELETE all of your data."
1 change: 1 addition & 0 deletions config/routes/authentication.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
scope module: :users, path: :users do
get "onboarding" => "onboarding#new"
post "onboarding" => "onboarding#create"
get "delete" => "cancellations#show", :as => :delete_user_registration
end

scope "(/team/:account_id)", account_id: %r{[^/]+} do
Expand Down
7 changes: 7 additions & 0 deletions config/tailwind.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@ module.exports = {
DEFAULT: "1.5em",
},
},
typography: {
DEFAULT: {
css: {
maxWidth: '100%',
}
}
}
},
},
plugins: [
Expand Down
26 changes: 13 additions & 13 deletions test/system/accounts/edit_acounts_test.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
require "application_system_test_case"

class EditAccountsTest < ApplicationSystemTestCase
setup do
@user = create(:user)
@team_account = create(:account, name: "Team account")
@team_account.account_users << AccountUser.create(user: @user, role: "owner")
end

test "can edit personal account" do
sign_in(@user)
user = create(:user)

sign_in(user)
visit edit_account_path

# Fill the personal account setup form
Expand All @@ -17,21 +13,25 @@ class EditAccountsTest < ApplicationSystemTestCase
click_on "commit"
assert_text I18n.t("accounts.update.success")

@user.personal_account.reload
assert_equal "New name", @user.personal_account.name
user.personal_account.reload
assert_equal "New name", user.personal_account.name
end

test "can edit team account" do
sign_in(@user)
visit edit_account_path(account_id: @team_account)
user = create(:user)
team_account = create(:account, name: "Team account")
team_account.account_users << AccountUser.create(user: user, role: "owner")

sign_in(user)
visit edit_account_path(account_id: team_account)

# Fill the personal account setup form
fill_in "account[name]", with: "New team name"

click_on "commit"
assert_text I18n.t("accounts.update.success")

@team_account.reload
assert_equal "New team name", @team_account.name
team_account.reload
assert_equal "New team name", team_account.name
end
end
21 changes: 11 additions & 10 deletions test/system/signin_test.rb
Original file line number Diff line number Diff line change
@@ -1,32 +1,33 @@
require "application_system_test_case"

class SigninTest < ApplicationSystemTestCase
setup do
@user = create(:user)
@unconfirmed_user = create(:user, :unconfirmed)
end

test "signs in with a verified user" do
user = create(:user)

visit new_user_session_path
fill_in "user[email]", with: @user.email
fill_in "user[password]", with: @user.password
fill_in "user[email]", with: user.email
fill_in "user[password]", with: user.password
click_on "commit"

assert_current_path dashboard_path
end

test "displays unconfirmed email message" do
unconfirmed_user = create(:user, :unconfirmed)

visit new_user_session_path
fill_in "user[email]", with: @unconfirmed_user.email
fill_in "user[password]", with: @unconfirmed_user.password
fill_in "user[email]", with: unconfirmed_user.email
fill_in "user[password]", with: unconfirmed_user.password
click_on "commit"

assert_text I18n.t("devise.failure.unconfirmed")
end

test "displays invalid password message" do
user = create(:user)

visit new_user_session_path
fill_in "user[email]", with: @user.email
fill_in "user[email]", with: user.email
fill_in "user[password]", with: "invalid"
click_on "commit"

Expand Down
21 changes: 21 additions & 0 deletions test/system/users/cancellation_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
require "application_system_test_case"

class EditAccountsTest < ApplicationSystemTestCase
test "can delete a fresh user" do
user = create(:user)
sign_in(user)
visit delete_user_registration_path
accept_confirm { click_on "commit" }

assert_text I18n.t("devise.registrations.destroyed")
assert_nil User.find_by_id(user.id)
end

test "can't delete a user if they're an owner of a team" do
skip("https://github.com/kiqr/kiqr/issues/1")
end

test "can't delete a user if theres an active subscription on their personal account" do
skip("https://github.com/kiqr/kiqr/issues/1")
end
end
File renamed without changes.

0 comments on commit d8936ea

Please sign in to comment.