mirror of
https://github.com/maybe-finance/maybe.git
synced 2025-07-21 14:19:39 +02:00
Since the very first 0.1.0-alpha.1 release, we've been moving quickly to add new features to the Maybe app. In doing so, some parts of the codebase have become outdated, unnecessary, or overly-complex as a natural result of this feature prioritization. Now that "core" Maybe is complete, we're moving into a second phase of development where we'll be working hard to improve the accuracy of existing features and build additional features on top of "core". This PR is a quick overhaul of the existing codebase aimed to: - Establish the brand new and simplified dashboard view (pictured above) - Establish and move towards the conventions introduced in Cursor rules and project design overview #1788 - Consolidate layouts and improve the performance of layout queries - Organize the core models of the Maybe domain (i.e. Account::Entry, Account::Transaction, etc.) and break out specific traits of each model into dedicated concerns for better readability - Remove stale / dead code from codebase - Remove overly complex code paths in favor of simpler ones
71 lines
2.1 KiB
Ruby
71 lines
2.1 KiB
Ruby
class UsersController < ApplicationController
|
|
before_action :set_user
|
|
|
|
def update
|
|
@user = Current.user
|
|
|
|
if email_changed?
|
|
if @user.initiate_email_change(user_params[:email])
|
|
if Rails.application.config.app_mode.self_hosted? && !Setting.require_email_confirmation
|
|
handle_redirect(t(".success"))
|
|
else
|
|
redirect_to settings_profile_path, notice: t(".email_change_initiated")
|
|
end
|
|
else
|
|
error_message = @user.errors.any? ? @user.errors.full_messages.to_sentence : t(".email_change_failed")
|
|
redirect_to settings_profile_path, alert: error_message
|
|
end
|
|
else
|
|
@user.update!(user_params.except(:redirect_to, :delete_profile_image))
|
|
@user.profile_image.purge if should_purge_profile_image?
|
|
|
|
respond_to do |format|
|
|
format.html { handle_redirect(t(".success")) }
|
|
format.json { head :ok }
|
|
end
|
|
end
|
|
end
|
|
|
|
def destroy
|
|
if @user.deactivate
|
|
Current.session.destroy
|
|
redirect_to root_path, notice: t(".success")
|
|
else
|
|
redirect_to settings_profile_path, alert: @user.errors.full_messages.to_sentence
|
|
end
|
|
end
|
|
|
|
private
|
|
def handle_redirect(notice)
|
|
case user_params[:redirect_to]
|
|
when "onboarding_preferences"
|
|
redirect_to preferences_onboarding_path
|
|
when "home"
|
|
redirect_to root_path
|
|
when "preferences"
|
|
redirect_to settings_preferences_path, notice: notice
|
|
else
|
|
redirect_to settings_profile_path, notice: notice
|
|
end
|
|
end
|
|
|
|
def should_purge_profile_image?
|
|
user_params[:delete_profile_image] == "1" &&
|
|
user_params[:profile_image].blank?
|
|
end
|
|
|
|
def email_changed?
|
|
user_params[:email].present? && user_params[:email] != @user.email
|
|
end
|
|
|
|
def user_params
|
|
params.require(:user).permit(
|
|
:first_name, :last_name, :email, :profile_image, :redirect_to, :delete_profile_image, :onboarded_at, :show_sidebar,
|
|
family_attributes: [ :name, :currency, :country, :locale, :date_format, :timezone, :id, :data_enrichment_enabled ]
|
|
)
|
|
end
|
|
|
|
def set_user
|
|
@user = Current.user
|
|
end
|
|
end
|