Skip to content

Commit

Permalink
Fund listing page functions without sign in
Browse files Browse the repository at this point in the history
Resolve #592
Resolve #594
  • Loading branch information
suninthesky committed Feb 13, 2018
1 parent 33d9220 commit 8971714
Show file tree
Hide file tree
Showing 56 changed files with 260 additions and 668 deletions.
2 changes: 1 addition & 1 deletion app/cells/application/index.slim
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ div class=[muted]
- elsif options[:current_user].subscription_version == 2
= link_to 'Reveal & Apply ❯', reveals_path(fund: options[:fund]), method: :post, class: 'blue'
- else
= link_to status[:link_text] || 'Apply ❯', proposal_fund_path(model, options[:fund]), class: 'blue'
= link_to status[:link_text] || 'Apply ❯', fund_path(options[:fund], model), class: 'blue'
1 change: 1 addition & 0 deletions app/cells/breadcrumb_cell.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
class BreadcrumbCell < Cell::ViewModel
def show
return unless model.is_a?(Hash) && model.present?
model.delete_if { |k, _v| k.nil? }
render
end

Expand Down
2 changes: 1 addition & 1 deletion app/cells/eligibility/quiz.slim
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ h3.mb10 Quiz

.uk-form.uk-form-stacked.uk-clearfix
- if model.present?
= simple_form_for :check, url: eligibility_proposal_fund_path(model, fund), method: :patch do |f|
= simple_form_for :check, url: eligibility_path(fund, model), method: :patch do |f|

- if model.recipient.incomplete_first_proposal?

Expand Down
2 changes: 1 addition & 1 deletion app/cells/filter/show.slim
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ form#filter.flex.flex-wrap

.md.inline-block
| Grant duration:
= select 'duration', [["all", "All"], ["proposal", "Your proposal (#{@options[:funding_duration]} months)"], ["up-to-2y", "Up to 2 years"], ["2y-plus", "More than 2 years"]]
= select 'duration', [["all", "All"], proposal_duration, ["up-to-2y", "Up to 2 years"], ["2y-plus", "More than 2 years"]].compact
9 changes: 6 additions & 3 deletions app/cells/filter_cell.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,14 @@ def selected?(id, value)
def select(id, options)
tag.select id: id do
options.map do |opt|
unless opt.kind_of?(Array)
opt = [opt, opt.humanize.capitalize]
end
opt = [opt, opt.humanize.capitalize] unless opt.is_a?(Array)
tag.option(opt[1], value: url_encode(opt[0]), selected: selected?(id, opt[0]))
end.reduce(:+)
end
end

def proposal_duration
['proposal', "Your proposal (#{options[:funding_duration]} months)"] if
options[:funding_duration]
end
end
5 changes: 1 addition & 4 deletions app/cells/footer_themes/show.slim
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
ul
- themes.each do |theme|
li.mb10
- if proposal.present?
= link_to theme.name, theme_proposal_funds_path(proposal, theme), class: 'slate'
- else
= link_to theme.name, public_funds_theme_path(theme), class: 'slate'
= link_to theme.name, theme_path(theme, proposal), class: 'slate'
2 changes: 1 addition & 1 deletion app/cells/fund_insight/title.slim
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
h3.uk-margin-top
=> link_to model.title, proposal_fund_path(proposal, model), class: 'yellow'
=> link_to model.title, fund_path(model, proposal), class: 'yellow'
span.year.muted= model.subtitle
14 changes: 5 additions & 9 deletions app/cells/fund_insight_cell.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@ def title

def themes
model.themes.map do |theme|
link_to(theme.name, theme_path(theme), class: "tag #{theme.classes}")
link_to(
theme.name,
theme_path(theme, options[:proposal]),
class: "tag #{theme.classes}"
)
end.join
end

Expand Down Expand Up @@ -89,14 +93,6 @@ def title_name
funder.funds.size > 1 ? [name, funder.name] : [funder.name, name]
end

def theme_path(theme)
if options[:proposal]
theme_proposal_funds_path(options[:proposal], theme)
else
public_funds_theme_path(theme)
end
end

def grant_types_message
costs = model.permitted_costs.reject(&:zero?)
.map { |c| FUNDING_TYPES[c][0].split.first.downcase }
Expand Down
2 changes: 1 addition & 1 deletion app/cells/new_proposal_links/dashboard.slim
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
.fs16.center.py15.border-top.border-lightest-gray
= link_to 'Funds', proposal_funds_path(model), class: 'red px15'
= link_to 'Funds', funds_path(model), class: 'red px15'
= link_to 'Edit', edit_proposal_path(model), class: 'blue px15'
2 changes: 1 addition & 1 deletion app/cells/progress/apply.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def message
when ELIGIBLE
link_to(
'Apply ❯',
url_helpers.apply_proposal_fund_path(@proposal, @fund),
url_helpers.apply_path(@fund, @proposal),
class: 'fs15 btn white bg-blue shadow'
)
else
Expand Down
2 changes: 1 addition & 1 deletion app/cells/suitability/index.slim
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
=< status[:status]
- if status[:message]
.mb5 = status[:message]
= link_to status[:link_text], proposal_fund_path(model, fund), class: 'blue'
= link_to status[:link_text], fund_path(fund, model), class: 'blue'
2 changes: 1 addition & 1 deletion app/cells/suitability/quiz.slim
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ h4.mb10

.uk-form.uk-form-stacked.uk-clearfix
- if model.present?
= simple_form_for :check, url: eligibility_proposal_fund_path(model, fund), method: :patch do |f|
= simple_form_for :check, url: eligibility_path(fund, model), method: :patch do |f|

- if model.recipient.incomplete_first_proposal?

Expand Down
2 changes: 1 addition & 1 deletion app/cells/v2_navbar/show.slim
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@
= link_to 'Sign out', logout_path, class: "#{type} ml35"
- else
= link_to 'About', about_path, class: "#{type} ml35"
= link_to 'Funds', public_funds_path, class: "#{type} ml35"
= link_to 'Funds', funds_path, class: "#{type} ml35"
= link_to 'Sign in', sign_in_path, class: "#{type} ml35"
6 changes: 3 additions & 3 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def load_last_proposal
@proposal = if params[:proposal_id]
@recipient.proposals.find_by(id: params[:proposal_id])
else
@recipient.proposals.last
@recipient.proposals.last # TODO: remove
end
end

Expand Down Expand Up @@ -99,10 +99,10 @@ def start_path
return edit_signup_recipient_path(@recipient) unless @recipient.valid? # NOTE: legacy
return new_signup_proposal_path unless @proposal
return new_signup_proposal_path if @proposal.initial? # NOTE: legacy
proposal_funds_path(@proposal)
funds_path(@proposal)
end

def ensure_not_signed_up
redirect_to proposal_funds_path(@proposal) if signed_up?
redirect_to funds_path(@proposal) if signed_up?
end
end
2 changes: 1 addition & 1 deletion app/controllers/eligibilities_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def create
@recipient.update_funds_checked!(@proposal.eligibility)
Assessment.analyse_and_update!(Fund.active, @proposal) # TODO: refactor
track_quiz_completion(@fund)
redirect_to proposal_fund_path(@proposal, @fund)
redirect_to fund_path(@fund, @proposal)
end
end

Expand Down
6 changes: 1 addition & 5 deletions app/controllers/enquiries_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,6 @@ def authenticate
end

def user_not_authorised
if @current_user.subscription_version == 2
redirect_to account_upgrade_path(@recipient)
else
redirect_to proposal_fund_path(@proposal, @fund)
end
redirect_to account_upgrade_path(@recipient)
end
end
6 changes: 3 additions & 3 deletions app/controllers/feedback_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def new
@fund = Fund.find_by(slug: @redirect_to_funder) # TODO: refactor

return unless current_user.feedbacks.count.positive?
redirect_to proposal_funds_path(@proposal),
redirect_to funds_path(@proposal),
alert: "It looks like you've already provided feedback"
end

Expand All @@ -17,7 +17,7 @@ def create

if @feedback.save
session.delete(:redirect_to_funder)
redirect_to proposal_fund_path(@proposal, @fund),
redirect_to fund_path(@fund, @proposal),
notice: "You're a star! Thanks for the feedback."
else
render :new
Expand All @@ -34,7 +34,7 @@ def update # TODO: depreceted
if @feedback.update_attributes(params.require(:feedback).permit(:price))
flash[:notice] = 'Thanks for the feedback!'
redirect_to session.delete(:return_to) ||
proposal_funds_path(@proposal)
funds_path(@proposal)
else
render :edit
end
Expand Down
22 changes: 10 additions & 12 deletions app/controllers/funds_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class FundsController < ApplicationController
before_action :ensure_logged_in, :update_legacy_suitability, except: :sources
before_action :update_legacy_suitability, except: :sources
before_action :load_fund, only: %i[hidden show]

def show
Expand All @@ -9,7 +9,7 @@ def show
end

def index
update_analysis(query)
update_analysis(query) if @proposal
@funds = query.page(params[:page])
# TODO: refactor
@fund_count = query.size
Expand All @@ -19,25 +19,21 @@ def index

def themed
@theme = Theme.find_by(slug: params[:theme])
redirect_to root_path, alert: 'Not found' unless @theme
redirect_to funds_path(@proposal), alert: 'Not found' unless @theme
@funds = themed_query.page(params[:page])
@fund_count = themed_query.size # TODO: refactor
end

def hidden
return redirect_to root_path unless @fund
@assessment = @proposal.assessments.where(fund: @fund).first
@assessment = @proposal.assessments.where(fund: @fund).first if @proposal
end

private

def user_not_authorised
if @current_user.subscription_version == 2
return redirect_to root_path if @fund.nil?
redirect_to hidden_proposal_fund_path(@proposal, @fund)
else
redirect_to account_upgrade_path(@recipient)
end
return redirect_to funds_path(@proposal) if @fund.nil?
redirect_to hidden_path(@fund, @proposal)
end

def update_analysis(funds)
Expand All @@ -50,7 +46,7 @@ def update_analysis(funds)
end

def update_legacy_suitability # TODO: depreceted
@proposal.update_legacy_suitability
@proposal&.update_legacy_suitability
end

def query
Expand All @@ -69,6 +65,8 @@ def themed_query
end

def load_fund
@fund = Fund.includes(:funder).active.find_by_hashid(params[:id])
@fund = Fund.includes(:funder)
.where("state = 'active' OR state = 'stub'")
.find_by_hashid(params[:id])
end
end
10 changes: 5 additions & 5 deletions app/controllers/proposals_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def create
if @proposal.save
Assessment.analyse_and_update!(Fund.active, @proposal)
@proposal.next_step!
redirect_to proposal_funds_path(@proposal)
redirect_to funds_path(@proposal)
else
render :new
end
Expand All @@ -44,20 +44,20 @@ def update
fund = Fund.find_by_hashid(session.delete(:return_to))
format.js do
if session[:return_to]
render js: "window.location.href = '#{proposal_fund_path(@proposal, fund)}';
render js: "window.location.href = '#{fund_path(fund, @proposal)}';
$('button[type=submit]').prop('disabled', true)
.removeAttr('data-disable-with');"
else
render js: "window.location.href = '#{proposal_funds_path(@proposal)}';
render js: "window.location.href = '#{funds_path(@proposal)}';
$('button[type=submit]').prop('disabled', true)
.removeAttr('data-disable-with');"
end
end
format.html do
if session[:return_to]
redirect_to proposal_fund_path(@proposal, fund)
redirect_to fund_path(fund, @proposal)
else
redirect_to proposal_funds_path(@proposal)
redirect_to funds_path(@proposal)
end
end
else
Expand Down
35 changes: 0 additions & 35 deletions app/controllers/public_funds_controller.rb

This file was deleted.

2 changes: 1 addition & 1 deletion app/controllers/requests_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ def create
authorize :request
fund = Fund.find_by_hashid(params[:fund])
Request.create(fund: fund, recipient: @recipient, message: params[:message])
redirect_to proposal_fund_path(@proposal, fund)
redirect_to fund_path(fund, @proposal)
end

private
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/reveals_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ def create
fund = Fund.find_by_hashid(params[:fund])
@recipient.reveals << fund.slug
@recipient.save
redirect_to proposal_fund_path(@proposal, params[:fund])
redirect_to fund_path(fund, @proposal)
end

private
Expand Down
6 changes: 3 additions & 3 deletions app/controllers/signup_proposals_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def create
if @proposal.save
Assessment.analyse_and_update!(Fund.active, @proposal)
@proposal.next_step!
redirect_to proposal_funds_path(@proposal)
redirect_to funds_path(@proposal)
else
render :new
end
Expand All @@ -45,9 +45,9 @@ def update

def return_to_path
if session[:return_to]
proposal_fund_path(@proposal, session.delete(:return_to))
fund_path(session.delete(:return_to), @proposal)
else
proposal_funds_path(@proposal)
funds_path(@proposal)
end
end

Expand Down
11 changes: 1 addition & 10 deletions app/policies/enquiry_policy.rb
Original file line number Diff line number Diff line change
@@ -1,19 +1,10 @@
class EnquiryPolicy < ApplicationPolicy
def create?
use_subscription_version(__method__)
assessment&.eligibility_status == ELIGIBLE ? _fund_policy_show? : false
end

private

def v1_create? # TODO: deprecated
return true if user.subscription_active?
_fund_policy_show? ? record.proposal.eligible?(record.fund.slug) : false
end

def v2_create?
assessment&.eligibility_quiz == 1 ? _fund_policy_show? : false
end

def _fund_policy_show?
FundPolicy.new(user, FundContext.new(record.fund, record.proposal)).show?
end
Expand Down
Loading

0 comments on commit 8971714

Please sign in to comment.