Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .circleci/settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ defaults: &defaults
low: 720000
high: 5000000

fiat_only:
audit_emails: [ 'admin@example.com']

production:
<<: *defaults

Expand Down
3 changes: 2 additions & 1 deletion app/admin/issues.rb
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ def related_person
nf.input :body, input_html: {rows: 3}
nf.input :expires_at, as: :datepicker
nf.input :archived_at, as: :datepicker
nf.input :note_type
ArbreHelpers::Attachment.has_many_attachments(context, nf)
end
end
Expand Down Expand Up @@ -526,7 +527,7 @@ def related_person
h3 "Current Note Seeds"
if seeds = resource.note_seeds.presence
ArbreHelpers::Layout.panel_grid(self, seeds) do |d|
attributes_table_for d, :public, :fruit, :created_at, :updated_at, :expires_at
attributes_table_for d, :public, :fruit, :created_at, :updated_at, :expires_at, :note_type
para d.body
ArbreHelpers::Attachment.attachments_list self, (d.fruit.try(:attachments) || d.attachments)
end
Expand Down
4 changes: 4 additions & 0 deletions app/models/admin_user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ def add_tag(tag)
tags.reload
end

def fiat_only?
Settings.fiat_only.audit_emails.include? self.email
end

private

def set_api_token
Expand Down
90 changes: 47 additions & 43 deletions app/models/currency.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,48 +2,52 @@ class Currency
include StaticModels::Model

static_models_dense [
[:id, :code, :name, :decimals ],
[1, :btc, 'bitcoin', 4 ],
[2, :ltc, 'litecoin', 4 ],
[3, :bch, 'bcash', 4 ],
[4, :usd, 'us_dollar', 2 ],
[5, :ars, 'argentine_peso', 2 ],
[6, :uyu, 'uruguayan_peso', 2 ],
[7, :eur, 'euro', 2 ],
[8, :clp, 'chilean_peso', 2 ],
[9, :pen, 'peruvian_sol', 2 ],
[10, :brl, 'brazilian_real', 2 ],
[11, :cop, 'colombian_peso', 2 ],
[12, :mxn, 'mexican_peso', 2 ],
[13, :pyg, 'paraguayan_guarani', 2 ],
[14, :cny, 'chinese_yuan', 2 ],
[15, :inr, 'indian_rupee', 2 ],
[16, :vef, 'venezuelan_bolivar', 2 ],
[17, :aud, 'australian_dollar', 2 ],
[18, :gbp, 'pound_sterling', 2 ],
[19, :hkd, 'hong_kong_dollar', 2 ],
[20, :bob, 'bolivian_peso', 2 ],
[21, :ada, 'ada', 8 ],
[22, :bnb, 'binance_coin', 8 ],
[23, :dai, 'dai', 8 ],
[24, :eth, 'ethereum', 8 ],
[25, :link, 'link', 8 ],
[26, :sushi,'sushi', 8 ],
[27, :uni, 'uni', 8 ],
[28, :usdt, 'usd_tether', 8 ],
[29, :ftt, 'ftt', 8 ],
[30, :yfi, 'yfi', 8 ],
[31, :dot, 'dot', 8 ],
[32, :doge, 'doge', 8 ],
[33, :soya, 'soya', 8 ],
[34, :usdc, 'usdc', 2 ],
[35, :sol, 'sol', 8 ],
[36, :cora, 'cora', 8 ],
[37, :brz, 'brazilian_digital_token', 8 ],
[38, :shib, 'shiba_inu', 8 ],
[39, :mana, 'mana', 8 ],
[40, :chz, 'chiliz', 8 ],
[41, :xlm, 'stellar', 8 ],
[42, :xrp, 'ripple', 8 ],
[:id, :code, :name, :decimals, :type],
[1, :btc, 'bitcoin', 4, :crypto],
[2, :ltc, 'litecoin', 4, :crypto],
[3, :bch, 'bcash', 4, :crypto],
[4, :usd, 'us_dollar', 2, :fiat],
[5, :ars, 'argentine_peso', 2, :fiat],
[6, :uyu, 'uruguayan_peso', 2, :fiat],
[7, :eur, 'euro', 2, :fiat],
[8, :clp, 'chilean_peso', 2, :fiat],
[9, :pen, 'peruvian_sol', 2, :fiat],
[10, :brl, 'brazilian_real', 2, :fiat],
[11, :cop, 'colombian_peso', 2, :fiat],
[12, :mxn, 'mexican_peso', 2, :fiat],
[13, :pyg, 'paraguayan_guarani', 2, :fiat],
[14, :cny, 'chinese_yuan', 2, :fiat],
[15, :inr, 'indian_rupee', 2, :fiat],
[16, :vef, 'venezuelan_bolivar', 2, :fiat],
[17, :aud, 'australian_dollar', 2, :fiat],
[18, :gbp, 'pound_sterling', 2, :fiat],
[19, :hkd, 'hong_kong_dollar', 2, :fiat],
[20, :bob, 'bolivian_peso', 2, :fiat],
[21, :ada, 'ada', 8, :crypto],
[22, :bnb, 'binance_coin', 8, :crypto],
[23, :dai, 'dai', 8, :crypto],
[24, :eth, 'ethereum', 8, :crypto],
[25, :link, 'link', 8, :crypto],
[26, :sushi, 'sushi', 8, :crypto],
[27, :uni, 'uni', 8, :crypto],
[28, :usdt, 'usd_tether', 8, :crypto],
[29, :ftt, 'ftt', 8, :crypto],
[30, :yfi, 'yfi', 8, :crypto],
[31, :dot, 'dot', 8, :crypto],
[32, :doge, 'doge', 8, :crypto],
[33, :soya, 'soya', 8, :crypto],
[34, :usdc, 'usdc', 2, :crypto],
[35, :sol, 'sol', 8, :crypto],
[36, :cora, 'cora', 8, :crypto],
[37, :brz, 'brazilian_digital_token', 8, :crypto],
[38, :shib, 'shiba_inu', 8, :crypto],
[39, :mana, 'mana', 8, :crypto],
[40, :chz, 'chiliz', 8, :crypto],
[41, :xlm, 'stellar', 8, :crypto],
[42, :xrp, 'ripple', 8, :crypto],
]

def is_fiat?
type == :fiat
end
end
4 changes: 4 additions & 0 deletions app/models/fund_deposit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ def name
"##{id}: #{amount} #{currency_code} #{deposit_method_code}"
end

def self.deposits_fiat_only_condition
where(currency_id: Currency.all.select(&:is_fiat?)) if AdminUser.current_admin_user&.fiat_only?
end

private

def refresh_person_regularity!
Expand Down
4 changes: 4 additions & 0 deletions app/models/fund_transfer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,8 @@ def self.collection_scoped_by_persons
where(source_person_id: Person.by_admin_user_tags)
.or(FundTransfer.where(target_person_id: Person.by_admin_user_tags))
end

def self.transfers_fiat_only_condition
where(currency_id: Currency.all.select(&:is_fiat?)) if AdminUser.current_admin_user&.fiat_only?
end
end
4 changes: 4 additions & 0 deletions app/models/fund_withdrawal.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ def name
"##{id}: #{amount} #{currency_code} #{country}"
end

def self.withdrawals_fiat_only_condition
where(currency_id: Currency.all.select(&:is_fiat?)) if AdminUser.current_admin_user&.fiat_only?
end

private

def refresh_person_country_tagging!
Expand Down
4 changes: 4 additions & 0 deletions app/models/note_base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@ class NoteBase < ApplicationRecord

validates :body, presence: true
validates :title, length: { maximum: 255 }
validates :note_type, presence: true

def name_body
title || body
end

NOTE_TYPE_VALUES = { fiat_note: 1, cripto_note: 2 }.freeze
enum note_type: { unknown: 0 }.merge(NOTE_TYPE_VALUES)
end
6 changes: 4 additions & 2 deletions app/models/person.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,10 @@ class Person < ApplicationRecord

HAS_MANY = HAS_MANY_REPLACEABLE + HAS_MANY_PLAIN

has_many :received_transfers, :class_name => 'FundTransfer', :foreign_key => 'target_person_id'
has_many :sent_transfers, :class_name => 'FundTransfer', :foreign_key => 'source_person_id'
has_many :received_transfers, -> { transfers_fiat_only_condition }, :class_name => 'FundTransfer', :foreign_key => 'target_person_id'
has_many :sent_transfers, -> { transfers_fiat_only_condition }, :class_name => 'FundTransfer', :foreign_key => 'source_person_id'
has_many :fund_deposits, -> { deposits_fiat_only_condition } #TODO: check others relations
has_many :fund_withdrawals, -> { withdrawals_fiat_only_condition } #TODO: check others relations

has_many :comments, as: :commentable
accepts_nested_attributes_for :comments, allow_destroy: true
Expand Down
3 changes: 3 additions & 0 deletions config/settings.example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ defaults: &defaults
low: 720000
high: 5000000

fiat_only:
audit_emails: [ 'admin@example.com' ]

production:
<<: *defaults

Expand Down
5 changes: 5 additions & 0 deletions db/migrate/20230524141147_add_note_type_to_notes.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddNoteTypeToNotes < ActiveRecord::Migration[5.2]
def change
add_column :notes, :note_type, :integer, :default => 0, null: false
end
end
5 changes: 5 additions & 0 deletions db/migrate/20230524141334_add_note_type_to_note_seeds.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddNoteTypeToNoteSeeds < ActiveRecord::Migration[5.2]
def change
add_column :note_seeds, :note_type, :integer, :default => 0, null: false
end
end
6 changes: 3 additions & 3 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 2023_03_14_195347) do
ActiveRecord::Schema.define(version: 2023_05_24_141334) do

create_table "active_admin_comments", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4", force: :cascade do |t|
t.string "namespace"
Expand Down Expand Up @@ -642,6 +642,7 @@
t.date "expires_at"
t.boolean "public", default: false, null: false
t.date "archived_at"
t.integer "note_type", default: 0, null: false
t.index ["archived_at"], name: "index_note_seeds_on_archived_at"
t.index ["fruit_id"], name: "index_note_seeds_on_fruit_id"
t.index ["issue_id"], name: "index_note_seeds_on_issue_id"
Expand All @@ -659,6 +660,7 @@
t.bigint "replaced_by_id"
t.boolean "public", default: false, null: false
t.date "archived_at"
t.integer "note_type", default: 0, null: false
t.index ["archived_at"], name: "index_notes_on_archived_at"
t.index ["issue_id"], name: "index_notes_on_issue_id"
t.index ["person_id"], name: "index_notes_on_person_id"
Expand Down Expand Up @@ -834,8 +836,6 @@
t.index ["issue_id"], name: "index_workflows_on_issue_id"
end

add_foreign_key "admin_user_taggings", "admin_users"
add_foreign_key "admin_user_taggings", "tags"
add_foreign_key "affinities", "affinities", column: "replaced_by_id"
add_foreign_key "affinities", "affinity_seeds"
add_foreign_key "affinities", "people"
Expand Down
7 changes: 7 additions & 0 deletions spec/models/admin_user_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,11 @@
admin.disable!
expect(admin.active).to eq(false)
end

it 'admin fiat only' do
admin = create(:admin_user)
expect(admin.fiat_only?).to eq(false)
Settings.fiat_only['audit_emails'] = [ admin.email ]
expect(admin.fiat_only?).to eq(true)
end
end
14 changes: 14 additions & 0 deletions spec/models/fund_deposit_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -224,4 +224,18 @@
expect { create(:an_fund_deposit, person: alice) }
.not_to change { alice.tags }
end

it 'filter deposits by fiat currencies when user admin is auditor' do
admin_user = create(:admin_user)
AdminUser.current_admin_user = admin_user
Settings.fiat_only['audit_emails'] = [ admin_user.email ]
new_person = create(:empty_person)
create(:full_fund_deposit, person: new_person, currency: Currency.find_by_code('ars'))
create(:full_fund_deposit, person: new_person, currency: Currency.find_by_code('usd'))
create(:full_fund_deposit, person: new_person, currency: Currency.find_by_code('btc'))
create(:full_fund_deposit, person: new_person, currency: Currency.find_by_code('ada'))
fund_deposits = new_person.fund_deposits
expect(fund_deposits.count).to eq 2
fund_deposits.each { |d| expect(d.currency.is_fiat?).to eq true}
end
end
19 changes: 19 additions & 0 deletions spec/models/fund_transfer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,23 @@
)
assert_logging(object, :create_entity, 1)
end

it 'filter transfers by fiat currencies when user admin is auditor' do
admin_user = create(:admin_user)
AdminUser.current_admin_user = admin_user
Settings.fiat_only['audit_emails'] = [ admin_user.email ]

create(:fund_transfer, source_person: source_person, target_person: target_person, currency: Currency.find_by_code('ars'))
create(:fund_transfer, source_person: source_person, target_person: target_person, currency: Currency.find_by_code('usd'))
create(:fund_transfer, source_person: source_person, target_person: target_person, currency: Currency.find_by_code('btc'))
create(:fund_transfer, source_person: source_person, target_person: target_person, currency: Currency.find_by_code('ada'))

sent_transfers = source_person.sent_transfers
expect(sent_transfers.count).to eq 2
sent_transfers.each { |d| expect(d.currency.is_fiat?).to eq true }

received_transfers = target_person.received_transfers
expect(received_transfers.count).to eq 2
sent_transfers.each { |d| expect(d.currency.is_fiat?).to eq true }
end
end
14 changes: 14 additions & 0 deletions spec/models/fund_withdrawal_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,18 @@
expect { create(:an_fund_withdrawal, person: alice) }
.not_to change{ alice.tags }
end

it 'filter withdrawals by fiat currencies when user admin is auditor' do
admin_user = create(:admin_user)
AdminUser.current_admin_user = admin_user
Settings.fiat_only['audit_emails'] = [ admin_user.email ]
new_person = create(:empty_person)
create(:full_fund_withdrawal, person: new_person, currency: Currency.find_by_code('ars'))
create(:full_fund_withdrawal, person: new_person, currency: Currency.find_by_code('usd'))
create(:full_fund_withdrawal, person: new_person, currency: Currency.find_by_code('btc'))
create(:full_fund_withdrawal, person: new_person, currency: Currency.find_by_code('ada'))
fund_withdrawal = new_person.fund_withdrawals
expect(fund_withdrawal.count).to eq 2
fund_withdrawal.each { |d| expect(d.currency.is_fiat?).to eq true}
end
end