Skip to content

Commit

Permalink
Revert "Revert "187121499 enable default currency""
Browse files Browse the repository at this point in the history
This reverts commit ca55c9a.
  • Loading branch information
owennny committed Apr 29, 2024
1 parent 76cb323 commit 1787ba7
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 1 deletion.
7 changes: 6 additions & 1 deletion app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

class UsersController < ApplicationController
before_action :authenticate_user!, only: :search
before_action :set_currency_options, only: [:edit, :new, :create, :update]
load_and_authorize_resource

# GET /users/1
Expand Down Expand Up @@ -40,7 +41,7 @@ def search

def user_params
params[:user][:timezone] = params[:user][:timezone].presence || nil
params.require(:user).permit(:name, :biography, :nickname, :affiliation,
params.require(:user).permit(:name, :biography, :nickname, :affiliation, :default_currency,
:picture, :picture_cache, :timezone)
end

Expand All @@ -49,5 +50,9 @@ def user_params
def load_user
@user ||= (params[:id] && params[:id] != 'current' && User.find(params[:id])) || current_user
end

# rubocop:enable Naming/MemoizedInstanceVariableName
def set_currency_options
@currency_options = CurrencyConversion::VALID_CURRENCIES.map { |currency| [currency, currency] }
end
end
2 changes: 2 additions & 0 deletions app/models/currency_conversion.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ class CurrencyConversion < ApplicationRecord
VALID_CURRENCIES = %w[AUD CAD CHF CNY EUR GBP JPY USD].freeze
belongs_to :conference
validates :rate, numericality: { greater_than: 0 }
# Ensure from_currency and to_currency are among the VALID_CURRENCIES
validates :from_currency, :to_currency, inclusion: { in: VALID_CURRENCIES }
validates :from_currency, uniqueness: { scope: :to_currency }, on: :create

def self.convert_currency(conference, amount, from_currency, to_currency)
Expand Down
1 change: 1 addition & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
# confirmed_at :datetime
# current_sign_in_at :datetime
# current_sign_in_ip :string
# default_currency :string
# email :string default(""), not null
# email_public :boolean default(FALSE)
# encrypted_password :string default(""), not null
Expand Down
3 changes: 3 additions & 0 deletions app/views/users/edit.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
The timezone setting will update the event schedules to show using the time you selected.
Your browser is current set to
%span.js-localTimezone
.form-group
= f.label :default_currency, 'Default Currency'
= f.select :default_currency, options_for_select(@currency_options, selected: @user.default_currency), {}, { class: 'form-control' }
.form-group
= f.label :avatar
%br
Expand Down
1 change: 1 addition & 0 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -627,6 +627,7 @@
t.boolean "is_disabled", default: false
t.string "picture"
t.string "timezone"
t.string "default_currency"
t.index ["confirmation_token"], name: "index_users_on_confirmation_token", unique: true
t.index ["email"], name: "index_users_on_email", unique: true
t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true
Expand Down
1 change: 1 addition & 0 deletions spec/factories/users.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
# confirmed_at :datetime
# current_sign_in_at :datetime
# current_sign_in_ip :string
# default_currency :string
# email :string default(""), not null
# email_public :boolean default(FALSE)
# encrypted_password :string default(""), not null
Expand Down
1 change: 1 addition & 0 deletions spec/models/user_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
# confirmed_at :datetime
# current_sign_in_at :datetime
# current_sign_in_ip :string
# default_currency :string
# email :string default(""), not null
# email_public :boolean default(FALSE)
# encrypted_password :string default(""), not null
Expand Down

0 comments on commit 1787ba7

Please sign in to comment.