Skip to content

Commit 8bb690e

Browse files
authored
Merge pull request #726 from coopdevs/develop
Release v4.5.0
2 parents c1eabb2 + 9e5c05f commit 8bb690e

9 files changed

+156
-27
lines changed

Gemfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ gem 'rails', '~> 6.1.1'
44
gem 'rails-i18n', '~> 7.0'
55
gem 'rdiscount', '~> 2.2.7'
66
gem 'rubyzip', '~> 2.3.0'
7-
gem 'activeadmin', '~> 2.9.0'
7+
gem 'activeadmin', '~> 2.14'
88
gem 'bootsnap', '~> 1.12.0', require: false
99
gem 'has_scope', '~> 0.7.2'
1010
gem 'pundit', '~> 2.1.0'

Gemfile.lock

+26-26
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,15 @@ GEM
4444
activemodel (>= 5.2.0)
4545
activestorage (>= 5.2.0)
4646
activesupport (>= 5.2.0)
47-
activeadmin (2.9.0)
47+
activeadmin (2.14.0)
4848
arbre (~> 1.2, >= 1.2.1)
4949
formtastic (>= 3.1, < 5.0)
5050
formtastic_i18n (~> 0.4)
5151
inherited_resources (~> 1.7)
5252
jquery-rails (~> 4.2)
5353
kaminari (~> 1.0, >= 1.2.1)
54-
railties (>= 5.2, < 6.2)
55-
ransack (~> 2.1, >= 2.1.1)
54+
railties (>= 6.1, < 7.1)
55+
ransack (>= 2.1.1, < 4)
5656
activejob (6.1.7.6)
5757
activesupport (= 6.1.7.6)
5858
globalid (>= 0.3.6)
@@ -78,8 +78,8 @@ GEM
7878
public_suffix (>= 2.0.2, < 6.0)
7979
airbrussh (1.4.0)
8080
sshkit (>= 1.6.1, != 1.7.0)
81-
arbre (1.4.0)
82-
activesupport (>= 3.0.0, < 6.2)
81+
arbre (1.5.0)
82+
activesupport (>= 3.0.0, < 7.1)
8383
ruby2_keywords (>= 0.0.2, < 1.0)
8484
ast (2.4.2)
8585
autoprefixer-rails (10.4.13.0)
@@ -163,7 +163,7 @@ GEM
163163
ffi (1.15.5)
164164
formtastic (4.0.0)
165165
actionpack (>= 5.2.0)
166-
formtastic_i18n (0.6.0)
166+
formtastic_i18n (0.7.0)
167167
fugit (1.9.0)
168168
et-orbi (~> 1, >= 1.2.7)
169169
raabro (~> 1.4)
@@ -182,10 +182,10 @@ GEM
182182
image_processing (1.12.2)
183183
mini_magick (>= 4.9.5, < 5)
184184
ruby-vips (>= 2.0.17, < 3)
185-
inherited_resources (1.12.0)
186-
actionpack (>= 5.2, < 6.2)
185+
inherited_resources (1.13.1)
186+
actionpack (>= 5.2, < 7.1)
187187
has_scope (~> 0.6)
188-
railties (>= 5.2, < 6.2)
188+
railties (>= 5.2, < 7.1)
189189
responders (>= 2, < 4)
190190
jmespath (1.6.1)
191191
jquery-rails (4.4.0)
@@ -195,18 +195,18 @@ GEM
195195
json (2.6.3)
196196
json_translate (4.0.1)
197197
activerecord (>= 4.2.0)
198-
kaminari (1.2.1)
198+
kaminari (1.2.2)
199199
activesupport (>= 4.1.0)
200-
kaminari-actionview (= 1.2.1)
201-
kaminari-activerecord (= 1.2.1)
202-
kaminari-core (= 1.2.1)
203-
kaminari-actionview (1.2.1)
200+
kaminari-actionview (= 1.2.2)
201+
kaminari-activerecord (= 1.2.2)
202+
kaminari-core (= 1.2.2)
203+
kaminari-actionview (1.2.2)
204204
actionview
205-
kaminari-core (= 1.2.1)
206-
kaminari-activerecord (1.2.1)
205+
kaminari-core (= 1.2.2)
206+
kaminari-activerecord (1.2.2)
207207
activerecord
208-
kaminari-core (= 1.2.1)
209-
kaminari-core (1.2.1)
208+
kaminari-core (= 1.2.2)
209+
kaminari-core (1.2.2)
210210
kgio (2.11.3)
211211
launchy (2.5.0)
212212
addressable (~> 2.7)
@@ -315,19 +315,19 @@ GEM
315315
rainbow (3.0.0)
316316
raindrops (0.19.1)
317317
rake (13.1.0)
318-
ransack (2.4.2)
319-
activerecord (>= 5.2.4)
320-
activesupport (>= 5.2.4)
318+
ransack (3.0.1)
319+
activerecord (>= 6.0.4)
320+
activesupport (>= 6.0.4)
321321
i18n
322322
rb-fsevent (0.10.4)
323323
rb-inotify (0.10.1)
324324
ffi (~> 1.0)
325325
rdiscount (2.2.7)
326326
redis (4.8.1)
327327
regexp_parser (2.8.2)
328-
responders (3.0.1)
329-
actionpack (>= 5.0)
330-
railties (>= 5.0)
328+
responders (3.1.1)
329+
actionpack (>= 5.2)
330+
railties (>= 5.2)
331331
rest-client (2.1.0)
332332
http-accept (>= 1.7.0, < 2.0)
333333
http-cookie (>= 1.0.2, < 2.0)
@@ -370,7 +370,7 @@ GEM
370370
ruby-progressbar (1.11.0)
371371
ruby-vips (2.1.4)
372372
ffi (~> 1.12)
373-
ruby2_keywords (0.0.4)
373+
ruby2_keywords (0.0.5)
374374
rubyzip (2.3.2)
375375
sassc (2.4.0)
376376
ffi (~> 1.9)
@@ -453,7 +453,7 @@ PLATFORMS
453453

454454
DEPENDENCIES
455455
active_storage_validations (~> 1.1.3)
456-
activeadmin (~> 2.9.0)
456+
activeadmin (~> 2.14)
457457
aws-sdk-s3 (~> 1.94)
458458
bootsnap (~> 1.12.0)
459459
bootstrap-sass (~> 3.4)

app/admin/category.rb

+3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
actions
88
end
99

10+
filter :created_at
11+
filter :updated_at
12+
1013
form do |f|
1114
f.inputs do
1215
f.input :name

app/admin/organization.rb

+2
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ def destroy
6969
filter :phone
7070
filter :city, as: :select, collection: -> { Organization.pluck(:city).uniq }
7171
filter :neighborhood
72+
filter :created_at
73+
filter :updated_at
7274

7375
permit_params :name, :email, :web, :phone, :city, :neighborhood,
7476
:address, :description, :public_opening_times, :logo

app/admin/petition.rb

+2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
end
1212
end
1313

14+
filter :organization
1415
filter :status, as: :select, collection: -> { Petition.statuses }
1516
filter :created_at
17+
filter :updated_at
1618
end

app/admin/post.rb

+1
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,5 @@
5757
filter :is_group
5858
filter :active
5959
filter :created_at
60+
filter :updated_at
6061
end

app/admin/transfer.rb

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
ActiveAdmin.register Transfer do
2+
includes :post, movements: { account: [:accountable, :organization] }
3+
4+
actions :index, :destroy
5+
6+
action_item :upload_csv, only: :index do
7+
link_to I18n.t("active_admin.users.upload_from_csv"), action: "upload_csv"
8+
end
9+
10+
collection_action :upload_csv do
11+
render "admin/csv/upload_csv"
12+
end
13+
14+
collection_action :import_csv, method: :post do
15+
errors = TransferImporter.call(params[:dump][:organization_id], params[:dump][:file])
16+
flash[:error] = errors.join("<br/>").html_safe if errors.present?
17+
18+
redirect_to action: :index
19+
end
20+
21+
index do
22+
id_column
23+
column :post
24+
column :reason
25+
column "From - To" do |transfer|
26+
accounts_from_movements(transfer, with_links: true).join(" #{glyph(:arrow_right)} ").html_safe
27+
end
28+
column :amount do |transfer|
29+
seconds_to_hm(transfer.movements.first.amount.abs)
30+
end
31+
column :created_at do |transfer|
32+
l transfer.created_at.to_date, format: :long
33+
end
34+
column :organization do |transfer|
35+
transfer.movements.first.account.organization
36+
end
37+
actions
38+
end
39+
40+
filter :reason
41+
filter :created_at
42+
end

app/admin/user.rb

+1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
filter :phone
3636
filter :postcode
3737
filter :locale
38+
filter :created_at
3839

3940
form do |f|
4041
f.semantic_errors *f.object.errors.keys

app/services/transfer_importer.rb

+78
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
# Used in the Admin section to import transfers
2+
# to a specific organization, from a CSV file.
3+
4+
require "csv"
5+
6+
class TransferImporter
7+
Row = Struct.new(
8+
:source_id,
9+
:source_type,
10+
:destination_id,
11+
:destination_type,
12+
:amount,
13+
:created_at,
14+
:reason,
15+
:post_id
16+
) do
17+
def transfer_from_row(organization_id, errors)
18+
source = find_account(source_id, source_type, organization_id, errors, 'source')
19+
destination = find_account(destination_id, destination_type, organization_id, errors, 'destination')
20+
return unless source && destination
21+
22+
Transfer.new(
23+
source: source,
24+
destination: destination,
25+
amount: amount,
26+
created_at: created_at,
27+
reason: reason,
28+
post_id: post_id,
29+
)
30+
end
31+
32+
private
33+
34+
def find_account(id, type, organization_id, errors, direction)
35+
acc = if type.downcase == 'organization'
36+
Organization.find(organization_id).account
37+
else
38+
Member.find_by(member_uid: id, organization_id: organization_id)&.account
39+
end
40+
41+
unless acc
42+
errors.push(account_id: id, errors: "#{direction}_id #{id} not found in organization #{organization_id}")
43+
return false
44+
end
45+
acc
46+
end
47+
end
48+
49+
class << self
50+
def call(organization_id, csv_data)
51+
data = csv_data.read
52+
errors = []
53+
54+
CSV.parse(data, headers: false) do |data_row|
55+
row = Row.new(
56+
data_row[0],
57+
data_row[1],
58+
data_row[2],
59+
data_row[3],
60+
data_row[4],
61+
data_row[5],
62+
data_row[6],
63+
data_row[7]
64+
)
65+
process_row(row, organization_id, errors)
66+
end
67+
68+
errors
69+
end
70+
71+
def process_row(row, organization_id, errors)
72+
transfer = row.transfer_from_row(organization_id, errors)
73+
return if !transfer || transfer.save
74+
75+
errors.push(account_id: row.source_id, errors: transfer.errors.full_messages)
76+
end
77+
end
78+
end

0 commit comments

Comments
 (0)