-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
37 changed files
with
581 additions
and
198 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
module Progress | ||
class Request < Base | ||
def initialize(*args) | ||
super | ||
end | ||
|
||
def label | ||
'Update fund details' | ||
end | ||
|
||
def indicator | ||
"bg-blue #{@position}" | ||
end | ||
|
||
def message | ||
if @proposal.recipient.requests.find_by(fund_id: @fund.id) | ||
tag.a('Requested', class: 'btn fs15 slate border-silver disabled') | ||
else | ||
link_to('Request', url_helpers.requests_path(fund: @fund), method: :post, class: 'fs15 btn white bg-blue shadow') | ||
end | ||
end | ||
|
||
def highlight | ||
'bg-light-blue' | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,4 +6,8 @@ def self.policy_class | |
def featured | ||
fund.featured | ||
end | ||
|
||
def stub? | ||
fund.stub? | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
class RequestsController < ApplicationController | ||
before_action :ensure_logged_in | ||
|
||
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) | ||
end | ||
|
||
private | ||
|
||
def user_not_authorised | ||
redirect_to account_upgrade_path(@recipient) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
class Request < ApplicationRecord | ||
belongs_to :recipient | ||
belongs_to :fund | ||
|
||
validates :recipient, :fund, presence: true | ||
validates :fund, uniqueness: { scope: :recipient, | ||
message: 'only one request per fund / recipient' } | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class RequestPolicy < ApplicationPolicy | ||
def create? | ||
true | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
module Check | ||
module Eligibility | ||
class Theme | ||
include Check::Base | ||
|
||
def call(proposal, fund) | ||
validate_call proposal, fund | ||
proposal_themes = get_proposal_themes(proposal) | ||
match_score = match_themes(proposal_themes, fund.themes) | ||
return eligible true if match_score.size > 0 | ||
eligible false | ||
end | ||
|
||
private | ||
|
||
def get_proposal_themes(proposal) | ||
# get all the themes from a proposal, including the related themes attached to each theme | ||
proposal_themes = {} | ||
proposal.themes.each do |theme| | ||
proposal_themes[theme.name] = 1 | ||
theme.related.each do |theme_name, theme_score| | ||
proposal_themes[theme_name] = [theme_score, proposal_themes[theme_name] || 0].max | ||
end | ||
end | ||
proposal_themes | ||
end | ||
|
||
def match_themes(proposal_themes, fund_themes) | ||
# return the themes from the proposal that match those from the fund | ||
fund_theme_names = fund_themes.pluck(:name) | ||
proposal_themes.select { |theme, score| fund_theme_names.include? theme } | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.