Skip to content

Commit

Permalink
refactor: move preferences controller to kiqr gem
Browse files Browse the repository at this point in the history
  • Loading branch information
kjellberg committed Apr 22, 2024
1 parent 9b86be8 commit a07ccf5
Show file tree
Hide file tree
Showing 19 changed files with 75 additions and 77 deletions.
42 changes: 21 additions & 21 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ GEM
debug (1.9.2)
irb (~> 1.10)
reline (>= 0.3.8)
devise (4.9.3)
devise (4.9.4)
bcrypt (~> 3.0)
orm_adapter (~> 0.1)
railties (>= 4.1.0)
Expand Down Expand Up @@ -165,7 +165,7 @@ GEM
jbuilder (2.11.5)
actionview (>= 5.0.0)
activesupport (>= 5.0.0)
json (2.7.1)
json (2.7.2)
language_server-protocol (3.17.0.3)
launchy (3.0.0)
addressable (~> 2.8)
Expand All @@ -188,9 +188,9 @@ GEM
net-smtp
marcel (1.0.4)
matrix (0.4.2)
meta-tags (2.20.0)
meta-tags (2.21.0)
actionpack (>= 6.0.0, < 7.2)
method_source (1.0.0)
method_source (1.1.0)
mini_mime (1.1.5)
minitest (5.22.3)
msgpack (1.7.2)
Expand All @@ -205,17 +205,17 @@ GEM
net-smtp (0.5.0)
net-protocol
nio4r (2.7.1)
nokogiri (1.16.3-aarch64-linux)
nokogiri (1.16.4-aarch64-linux)
racc (~> 1.4)
nokogiri (1.16.3-arm-linux)
nokogiri (1.16.4-arm-linux)
racc (~> 1.4)
nokogiri (1.16.3-arm64-darwin)
nokogiri (1.16.4-arm64-darwin)
racc (~> 1.4)
nokogiri (1.16.3-x86-linux)
nokogiri (1.16.4-x86-linux)
racc (~> 1.4)
nokogiri (1.16.3-x86_64-darwin)
nokogiri (1.16.4-x86_64-darwin)
racc (~> 1.4)
nokogiri (1.16.3-x86_64-linux)
nokogiri (1.16.4-x86_64-linux)
racc (~> 1.4)
orm_adapter (0.5.0)
parallel (1.24.0)
Expand All @@ -224,7 +224,7 @@ GEM
racc
psych (5.1.2)
stringio
public_suffix (5.0.4)
public_suffix (5.0.5)
public_uid (2.2.0)
activerecord (> 4.2)
puma (6.4.2)
Expand Down Expand Up @@ -272,11 +272,11 @@ GEM
thor (~> 1.0, >= 1.2.2)
zeitwerk (~> 2.6)
rainbow (3.1.1)
rake (13.1.0)
rake (13.2.1)
rdoc (6.6.3.1)
psych (>= 4.0.0)
regexp_parser (2.9.0)
reline (0.5.0)
reline (0.5.2)
io-console (~> 0.5)
responders (3.1.1)
actionpack (>= 5.2)
Expand All @@ -303,7 +303,7 @@ GEM
rubocop-performance (1.20.2)
rubocop (>= 1.48.1, < 2.0)
rubocop-ast (>= 1.30.0, < 2.0)
ruby-next-core (1.0.2)
ruby-next-core (1.0.3)
ruby-progressbar (1.13.0)
rubyzip (2.3.2)
selenium-webdriver (4.19.0)
Expand Down Expand Up @@ -349,17 +349,17 @@ GEM
stimulus-rails (1.3.3)
railties (>= 6.0.0)
stringio (3.1.0)
tailwindcss-rails (2.3.0)
tailwindcss-rails (2.4.0)
railties (>= 6.0.0)
tailwindcss-rails (2.3.0-aarch64-linux)
tailwindcss-rails (2.4.0-aarch64-linux)
railties (>= 6.0.0)
tailwindcss-rails (2.3.0-arm-linux)
tailwindcss-rails (2.4.0-arm-linux)
railties (>= 6.0.0)
tailwindcss-rails (2.3.0-arm64-darwin)
tailwindcss-rails (2.4.0-arm64-darwin)
railties (>= 6.0.0)
tailwindcss-rails (2.3.0-x86_64-darwin)
tailwindcss-rails (2.4.0-x86_64-darwin)
railties (>= 6.0.0)
tailwindcss-rails (2.3.0-x86_64-linux)
tailwindcss-rails (2.4.0-x86_64-linux)
railties (>= 6.0.0)
thor (1.3.1)
timeout (0.4.1)
Expand All @@ -370,7 +370,7 @@ GEM
tzinfo (2.0.6)
concurrent-ruby (~> 1.0)
unicode-display_width (2.5.0)
view_component (3.11.0)
view_component (3.12.1)
activesupport (>= 5.2.0, < 8.0)
concurrent-ruby (~> 1.0)
method_source (~> 1.0)
Expand Down
27 changes: 0 additions & 27 deletions app/controllers/users/preferences_controller.rb

This file was deleted.

File renamed without changes.
File renamed without changes.
16 changes: 0 additions & 16 deletions config/locales/kiqr.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,22 +32,6 @@ en:
languages:
en: "English"
sv: "Swedish"
users:
preferences:
edit:
title: "User preferences"
description: "Update your user preferences."
form:
time_zone:
label: "Time zone"
placeholder: "Select a time zone"
locale:
label: "Language"
prompt: "Select a language"
placeholder: "Select your preferred language"
submit_button: "Save changes"
update:
updated: "User preferences have been updated."
account_mailer:
invitation_email:
welcome: "Welcome to %{app_name}"
Expand Down
1 change: 0 additions & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
# These routes are required for the KIQR core to function properly.
# Do not remove this unless you know what you're doing.
kiqr_routes
draw :authentication

# => Teamable scope
# Routes inside this block will be prefixed with /team/<team_id> if
Expand Down
4 changes: 0 additions & 4 deletions config/routes/authentication.rb

This file was deleted.

29 changes: 29 additions & 0 deletions gems/kiqr/app/controllers/kiqr/preferences_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
module Kiqr
class PreferencesController < ApplicationController
def edit
@user = current_user
end

def update
@user = current_user
if @user.update(preferences_params)
redirect_to edit_user_preferences_path, notice: t(".updated")
else
render :edit, status: :unprocessable_entity
end
end

private

def options_for_locale
I18n.available_locales.map do |locale|
[I18n.t("languages.#{locale}"), locale]
end
end
helper_method :options_for_locale

def preferences_params
params.require(:user).permit(:time_zone, :locale)
end
end
end
15 changes: 15 additions & 0 deletions gems/kiqr/config/locales/kiqr/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,21 @@ en:
new:
title: "Setup your personal account"
description: "Finish the registration by setting up your user profile."
preferences:
edit:
title: "User preferences"
description: "Update your user preferences."
form:
time_zone:
label: "Time zone"
placeholder: "Select a time zone"
locale:
label: "Language"
prompt: "Select a language"
placeholder: "Select your preferred language"
submit_button: "Save changes"
update:
updated: "User preferences have been updated."
registrations:
new:
heading:
Expand Down
2 changes: 2 additions & 0 deletions gems/kiqr/lib/kiqr/rails/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ def kiqr_routes(options = {})
get "two-factor/disable", controller: options[:controllers][:two_factor], action: "disable", as: :disable_two_factor
post "two-factor/verify", controller: options[:controllers][:two_factor], action: "verify", as: :verify_two_factor
delete "two-factor/destroy", controller: options[:controllers][:two_factor], action: "destroy", as: :destroy_two_factor
resource :preferences, controller: options[:controllers][:preferences], only: %i[edit update], as: :user_preferences
end
end

Expand All @@ -34,6 +35,7 @@ def default_controllers(options)
options[:controllers][:registrations] ||= "kiqr/registrations"
options[:controllers][:sessions] ||= "kiqr/sessions"
options[:controllers][:two_factor] ||= "kiqr/two_factor"
options[:controllers][:preferences] ||= "kiqr/preferences"
options
end

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require "test_helper"

class AccountUsersControllerTest < ActionDispatch::IntegrationTest
class Kiqr::AccountUsersControllerTest < ActionDispatch::IntegrationTest
test "can't show members as personal account" do
user = create(:user)
sign_in user
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require "test_helper"

class AccountsControllerTest < ActionDispatch::IntegrationTest
class Kiqr::AccountsControllerTest < ActionDispatch::IntegrationTest
test "can render new account page" do
sign_in create(:user)
get new_account_path
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require "test_helper"

class Users::InvitationsControllerTest < ActionDispatch::IntegrationTest
class Kiqr::InvitationsControllerTest < ActionDispatch::IntegrationTest
test "can view page without beeing signed in" do
invitation = create(:account_invitation)
get invitation_path(invitation)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require "test_helper"

class Users::OnboardingControllerTest < ActionDispatch::IntegrationTest
class Kiqr::OnboardingControllerTest < ActionDispatch::IntegrationTest
test "redirects to dashboard_path if user is already onboarded" do
sign_in create(:user)
get onboarding_path
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require "test_helper"

class Users::PreferencesControllerTest < ActionDispatch::IntegrationTest
class Kiqr::PreferencesControllerTest < ActionDispatch::IntegrationTest
test "should get edit page" do
user = create(:user)
sign_in(user)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require "test_helper"

class Users::RegistrationControllerTest < ActionDispatch::IntegrationTest
class Kiqr::RegistrationControllerTest < ActionDispatch::IntegrationTest
test "can view cancellation page" do
sign_in create(:user)
get cancel_user_registration_path
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require "test_helper"

class Users::SessionsControllerTest < ActionDispatch::IntegrationTest
class Kiqr::SessionsControllerTest < ActionDispatch::IntegrationTest
test "can sign in if two factor is disabled" do
user = create(:user)
post user_session_path, params: {user: {email: user.email, password: user.password}}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require "test_helper"

class Users::TwoFactorControllerTest < ActionDispatch::IntegrationTest
class Kiqr::TwoFactorControllerTest < ActionDispatch::IntegrationTest
test "should not be able to setup 2fa if already enabled" do
sign_in create(:user, :otp_enabled)
get setup_two_factor_path
Expand Down

0 comments on commit a07ccf5

Please sign in to comment.