Skip to content

Commit

Permalink
v2.0.4
Browse files Browse the repository at this point in the history
Merge pull request #686 from TechforgoodCAST/develop
  • Loading branch information
suninthesky authored Jul 12, 2018
2 parents f17ddb5 + 4ac151b commit a9ac6b3
Show file tree
Hide file tree
Showing 27 changed files with 66 additions and 446 deletions.
70 changes: 35 additions & 35 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ GEM
erubi (~> 1.4)
rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.0, >= 1.0.3)
activeadmin (1.1.0)
activeadmin (1.3.0)
arbre (>= 1.1.1)
coffee-rails
formtastic (~> 3.1)
formtastic_i18n
inherited_resources (~> 1.7)
jquery-rails
kaminari (>= 0.15, < 2.0)
railties (>= 4.2, < 5.2)
inherited_resources (>= 1.7.0)
jquery-rails (>= 4.2.0)
kaminari (>= 0.15)
railties (>= 4.2, < 5.3)
ransack (~> 1.3)
sass (~> 3.1)
sprockets (< 4.1)
Expand Down Expand Up @@ -127,14 +127,14 @@ GEM
dotenv-rails (2.2.1)
dotenv (= 2.2.1)
railties (>= 3.2, < 5.2)
erubi (1.6.1)
erubi (1.7.1)
execjs (2.7.0)
factory_bot (4.8.2)
activesupport (>= 3.0.0)
factory_bot_rails (4.8.2)
factory_bot (~> 4.8.2)
railties (>= 3.0.0)
ffi (1.9.18)
ffi (1.9.25)
formtastic (3.1.5)
actionpack (>= 3.2.13)
formtastic_i18n (0.6.0)
Expand All @@ -147,9 +147,9 @@ GEM
temple (>= 0.8.0)
thor
tilt
has_scope (0.7.1)
actionpack (>= 4.1, < 5.2)
activesupport (>= 4.1, < 5.2)
has_scope (0.7.2)
actionpack (>= 4.1)
activesupport (>= 4.1)
hashdiff (0.3.4)
hashids (1.0.4)
http-cookie (1.0.3)
Expand All @@ -158,32 +158,32 @@ GEM
multi_xml (>= 0.5.2)
i18n (0.8.6)
i18n_data (0.8.0)
inherited_resources (1.7.2)
actionpack (>= 3.2, < 5.2.x)
inherited_resources (1.8.0)
actionpack (>= 4.2, <= 5.2)
has_scope (~> 0.6)
railties (>= 3.2, < 5.2.x)
railties (>= 4.2, <= 5.2)
responders
intercom-rails (0.3.5)
activesupport (> 3.0)
jbuilder (2.7.0)
activesupport (>= 4.2.0)
multi_json (>= 1.2)
jquery-rails (4.3.1)
jquery-rails (4.3.3)
rails-dom-testing (>= 1, < 3)
railties (>= 4.2.0)
thor (>= 0.14, < 2.0)
kaminari (1.0.1)
kaminari (1.1.1)
activesupport (>= 4.1.0)
kaminari-actionview (= 1.0.1)
kaminari-activerecord (= 1.0.1)
kaminari-core (= 1.0.1)
kaminari-actionview (1.0.1)
kaminari-actionview (= 1.1.1)
kaminari-activerecord (= 1.1.1)
kaminari-core (= 1.1.1)
kaminari-actionview (1.1.1)
actionview
kaminari-core (= 1.0.1)
kaminari-activerecord (1.0.1)
kaminari-core (= 1.1.1)
kaminari-activerecord (1.1.1)
activerecord
kaminari-core (= 1.0.1)
kaminari-core (1.0.1)
kaminari-core (= 1.1.1)
kaminari-core (1.1.1)
listen (3.1.5)
rb-fsevent (~> 0.9, >= 0.9.4)
rb-inotify (~> 0.9, >= 0.9.7)
Expand All @@ -206,11 +206,11 @@ GEM
mixpanel-ruby (2.2.0)
money (6.9.0)
i18n (>= 0.6.4, < 0.9)
multi_json (1.12.1)
multi_json (1.13.1)
multi_xml (0.6.0)
netrc (0.11.0)
nio4r (2.1.0)
nokogiri (1.8.2)
nokogiri (1.8.4)
mini_portile2 (~> 2.3.0)
orm_adapter (0.5.0)
parallel (1.11.2)
Expand All @@ -221,7 +221,7 @@ GEM
capybara (~> 2.1)
cliver (~> 0.3.1)
websocket-driver (>= 0.2.0)
polyamorous (1.3.1)
polyamorous (1.3.3)
activerecord (>= 3.0)
powerpack (0.1.1)
pry (0.10.4)
Expand All @@ -234,7 +234,7 @@ GEM
puma (3.9.1)
pundit (1.1.0)
activesupport (>= 3.0.0)
rack (2.0.4)
rack (2.0.5)
rack-contrib (1.2.0)
rack (>= 0.9.1)
rack-test (0.6.3)
Expand Down Expand Up @@ -273,14 +273,14 @@ GEM
thor (>= 0.18.1, < 2.0)
rainbow (2.2.2)
rake
rake (12.0.0)
ransack (1.8.3)
rake (12.3.1)
ransack (1.8.8)
actionpack (>= 3.0)
activerecord (>= 3.0)
activesupport (>= 3.0)
i18n
polyamorous (~> 1.3)
rb-fsevent (0.10.2)
polyamorous (~> 1.3.2)
rb-fsevent (0.10.3)
rb-inotify (0.9.10)
ffi (>= 0.5.0, < 2)
redcarpet (3.4.0)
Expand All @@ -291,7 +291,7 @@ GEM
http-cookie (>= 1.0.2, < 2.0)
mime-types (>= 1.16, < 4.0)
netrc (~> 0.8)
rollbar (2.15.0)
rollbar (2.16.3)
multi_json
rspec-cells (0.3.4)
cells (>= 4.0.0, < 6.0.0)
Expand Down Expand Up @@ -324,7 +324,7 @@ GEM
ruby_dep (1.5.0)
rubyzip (1.2.1)
safe_yaml (1.0.4)
sass (3.5.1)
sass (3.5.6)
sass-listen (~> 4.0.0)
sass-listen (4.0.0)
rb-fsevent (~> 0.9, >= 0.9.4)
Expand Down Expand Up @@ -360,7 +360,7 @@ GEM
spring-watcher-listen (2.0.1)
listen (>= 2.7, < 4.0)
spring (>= 1.2, < 3.0)
sprockets (3.7.1)
sprockets (3.7.2)
concurrent-ruby (~> 1.0)
rack (> 1, < 3)
sprockets-rails (3.2.0)
Expand All @@ -374,7 +374,7 @@ GEM
multi_json (~> 1.0)
stripe (>= 1.31.0, <= 1.58.0)
temple (0.8.0)
thor (0.19.4)
thor (0.20.0)
thread_safe (0.3.6)
tilt (2.0.8)
tunemygc (1.0.69)
Expand Down
11 changes: 0 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,9 @@ Prerequisites: [Ruby](https://www.ruby-lang.org), [Bundler](https://bundler.io/)
3. `rails db:setup`
4. Create `.env` file with appropriate configuration:
```
BEEHIVE_DATA_TOKEN=<token>
BEEHIVE_DATA_FUND_SUMMARY_ENDPOINT=<beehive_data_server>/v1/integrations/fund_summary
BEEHIVE_INSIGHT_ENDPOINT=<beehive_data_server>/insight/beneficiaries
BEEHIVE_INSIGHT_AMOUNTS_ENDPOINT=<beehive_data_server>/insight/amounts
BEEHIVE_INSIGHT_DURATIONS_ENDPOINT=<beehive_data_server>/insight/durations
STRIPE_SECRET_KEY=<secret_key>
STRIPE_PUBLISHABLE_KEY=<publishable_key>
STRIPE_PLANS=<name>:<amount>,<name>:<amount>
# (optional if needed)
DATABASE_URL=postgres://username:password@localhost/beehive-data_development
DATABASE_URL_TEST=postgres://username:password@localhost/beehive-data_test
```
5. `rails s` and `bin/webpack-dev-server` to start local development servers

Expand Down
6 changes: 1 addition & 5 deletions app/admin/fund.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
permit_params :funder_id, :name, :description, :open_call,
:state, :currency, :application_link, :key_criteria,
:restrictions_known, :priorities_known,
:featured, :skip_beehive_data, :open_data,
:featured, :open_data,
:period_start, :period_end, :grant_count, :amount_awarded_sum,
:amount_awarded_distribution, :award_month_distribution,
:country_distribution, :sources, :national,
Expand Down Expand Up @@ -279,10 +279,6 @@ def scoped_collection
end
end

f.inputs 'Options' do
f.input :skip_beehive_data, as: :boolean
end

f.actions
end
end
9 changes: 5 additions & 4 deletions app/admin/user.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
ActiveAdmin.register User do
config.per_page = 10

permit_params :first_name, :last_name, :org_type, :agree_to_terms,
:email, :password, :password_confirmation, :organisation_id,
:organisation_type
permit_params :agree_to_terms, :email, :first_name, :last_name,
:marketing_consent, :organisation_id, :organisation_type,
:password, :password_confirmation

controller do
def scoped_collection
Expand Down Expand Up @@ -47,15 +47,16 @@ def scoped_collection

form do |f|
f.inputs 'User Details' do
f.semantic_errors *f.object.errors.keys
f.input :organisation_id
f.input :organisation_type, as: :select, collection: %w[Recipient Funder]
f.input :org_type, as: :select, collection: ORG_TYPES.map{|o| [o[0], o[1]] }
f.input :first_name
f.input :last_name
f.input :email
f.input :password
f.input :password_confirmation
f.input :agree_to_terms
f.input :marketing_consent
end
f.actions
end
Expand Down
18 changes: 0 additions & 18 deletions app/cells/proposal_indicators_cell.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,6 @@ def eligibility_progress_bar
render view: :progress_bar, locals: {bg_color: bg_color, names: names, states: states}
end

def suitability_progress_bar
@counts = suitability_counts
@pcs = count_percentages(@counts)
bg_color = { 0 => 'bg-red', 1 => 'bg-yellow', 2 => 'bg-green', -1 => 'bg-blue' }
names = { 0 => 'unsuitable', 1 => 'fair suitability', 2 => 'suitable', -1 => 'to check' }
states = [-1, 0, 1, 2]
render view: :progress_bar, locals: {bg_color: bg_color, names: names, states: states}
end

def funds_checked
model.assessments.where("eligibility_status != #{INCOMPLETE}").size
end
Expand All @@ -37,13 +28,4 @@ def eligibility_counts
model.assessments.group(:eligibility_status).size
)
end

def suitability_counts
{
-1 => model.suitability.count{ |k, s| s.fetch('total') == nil },
0 => model.suitability.count{ |k, s| s.fetch('total') < 0.2 },
1 => model.suitability.count{ |k, s| s.fetch('total').between?(0.2, 0.5) },
2 => model.suitability.count{ |k, s| s.fetch('total') > 0.5 },
}
end
end
2 changes: 1 addition & 1 deletion app/controllers/proposals_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def load_proposal
def proposal_params
params.require(:proposal).permit(
:affect_geo, :all_funding_required, :funding_duration, :funding_type,
:private, :tagline, :title, :total_costs,
:private, :public_consent, :tagline, :title, :total_costs,
district_ids: [], country_ids: [], theme_ids: []
)
end
Expand Down
3 changes: 2 additions & 1 deletion app/controllers/signup/suitability_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ def form_params
],
proposal: [
:affect_geo, :all_funding_required, :funding_duration, :private,
:tagline, :title, :total_costs, district_ids: [], country_ids: []
:public_consent, :tagline, :title, :total_costs,
district_ids: [], country_ids: []
],
user: [
:agree_to_terms, :email, :first_name, :last_name,
Expand Down
32 changes: 0 additions & 32 deletions app/models/fund.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,7 @@ class Fund < ApplicationRecord
validate :validate_sources, :validate_districts
validate :period_start_before_period_end, :period_end_in_past, if: :open_data?

attr_accessor :skip_beehive_data

before_validation :set_slug, unless: :slug
before_validation :check_beehive_data,
if: proc { |o| o.skip_beehive_data.to_i.zero? }

def self.version
XXhash.xxh32(active.order(:updated_at).pluck(:updated_at).join)
Expand Down Expand Up @@ -182,34 +178,6 @@ def to_param

private

def check_beehive_data # TODO: refactor as service
return unless open_data && slug
options = {
headers: {
'Authorization' => 'Token token=' + ENV['BEEHIVE_DATA_TOKEN']
}
}
resp = HTTParty.get(
ENV['BEEHIVE_DATA_FUND_SUMMARY_ENDPOINT'] + slug, options
)
# attributes we're looking for in the response
resp_attributes = %w(
amount_awarded_distribution
award_month_distribution
org_type_distribution
income_distribution
country_distribution
sources
grant_count
period_end
period_start
beneficiary_distribution
grant_examples
amount_awarded_sum
)
assign_attributes(resp.slice(*resp_attributes)) if slug == resp['fund_slug']
end

def months_to_str(months)
if months == 12
'1 year'
Expand Down
21 changes: 1 addition & 20 deletions app/models/proposal.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class Proposal < ApplicationRecord
in: 0..3, message: 'please select an option'
}

validates :all_funding_required, :private, inclusion: {
validates :all_funding_required, :private, :public_consent, inclusion: {
message: 'please select an option', in: [true, false]
}

Expand Down Expand Up @@ -90,13 +90,6 @@ def recipient_subscribed
errors.add(:title, 'Upgrade subscription to create multiple proposals')
end

def beehive_insight_durations # TODO: depreceted
@beehive_insight_durations ||= call_beehive_insight(
ENV['BEEHIVE_INSIGHT_DURATIONS_ENDPOINT'],
duration: funding_duration
)
end

def initial_recommendation # TODO: deprecated
suitability = CheckSuitabilityFactory.new
update_column(
Expand Down Expand Up @@ -183,16 +176,4 @@ def clear_districts_if_country_wide
def recipient_country_unless_multinational
self.countries = [countries.first] if affect_geo < 3
end

def call_beehive_insight(endpoint, data) # TODO: depreceted
options = {
body: { data: data }.to_json,
headers: {
'Content-Type' => 'application/json',
'Authorization' => 'Token token=' + ENV['BEEHIVE_DATA_TOKEN']
}
}
resp = HTTParty.post(endpoint, options)
JSON.parse(resp.body).to_h
end
end
Loading

0 comments on commit a9ac6b3

Please sign in to comment.