Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'upstream/master' into customize-notific…
…ations
- Loading branch information
Showing
66 changed files
with
5,068 additions
and
81 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,192 @@ | ||
@import 'variables'; | ||
@import 'mixins'; | ||
|
||
.partnerships-container { | ||
width: 800px; | ||
max-width: 96%; | ||
margin: 100px auto; | ||
&.partnerships-container-show { | ||
h1 { | ||
text-align: left; | ||
} | ||
} | ||
h1 { | ||
text-align: center; | ||
font-size: 2.5em; | ||
padding: 1em 0; | ||
img { | ||
height: 2.2em; | ||
width: 2.2em; | ||
transform: rotate(6deg); | ||
border-radius: 0.2em; | ||
vertical-align: -0.7em; | ||
margin-left: 0.3em; | ||
} | ||
} | ||
.partner-credits-explainer { | ||
@include themeable( | ||
background, | ||
theme-container-background, | ||
$white | ||
); | ||
box-sizing: border-box; | ||
padding: 25px 20px 30px; | ||
border-radius: 12px; | ||
margin: 50px auto 40px; | ||
width: calc(100% - 20px); | ||
@include themeable( | ||
border, | ||
theme-border, | ||
1px solid $light-medium-gray | ||
); | ||
@include themeable( | ||
box-shadow, | ||
theme-container-box-shadow, | ||
2px 2px 8px darken($light-medium-gray, 5%) | ||
); | ||
.partner-explainer-notice { | ||
padding: 15px; | ||
margin: 25px 0px 12px; | ||
border-radius: 3px; | ||
font-weight: bold; | ||
@include themeable( | ||
background, | ||
theme-container-accent-background, | ||
$light-gray | ||
); | ||
} | ||
h4 { | ||
font-size: 0.8em; | ||
margin: 3px 0px; | ||
@include themeable( | ||
color, | ||
theme-secondary-color, | ||
$medium-gray | ||
); | ||
} | ||
h3 { | ||
margin: 5px 0px; | ||
font-size: 1.8em; | ||
@include themeable( | ||
color, | ||
theme-color, | ||
#131a38 | ||
); | ||
img { | ||
height: 1.2em; | ||
width: 1.2em; | ||
vertical-align: -0.25em; | ||
border-radius: 100px; | ||
margin-right: 0.3em; | ||
} | ||
} | ||
select { | ||
display: block; | ||
font-size: 1.3em; | ||
} | ||
textarea { | ||
width: 80%; | ||
font-size: 1em; | ||
padding: 0.5em; | ||
border-radius: 3px; | ||
display: block; | ||
height: 300px; | ||
@include themeable( | ||
border, | ||
theme-container-border, | ||
1px solid $light-medium-gray | ||
); | ||
} | ||
input { | ||
width: 50%; | ||
font-size: 1.3em; | ||
padding: 0.5em; | ||
border-radius: 3px; | ||
display: block; | ||
@include themeable( | ||
border, | ||
theme-container-border, | ||
1px solid $light-medium-gray | ||
); | ||
} | ||
a, button { | ||
padding: 5px 20px; | ||
font-size: 1.5em; | ||
border-radius: 8px; | ||
font-weight: bold; | ||
margin: 8px 0px; | ||
display: inline-block; | ||
border: 0px; | ||
@include themeable( | ||
background, | ||
theme-anchor-color, | ||
$bold-blue | ||
); | ||
@include themeable( | ||
color, | ||
theme-container-background, | ||
white | ||
); | ||
} | ||
} | ||
.partnership-options { | ||
margin: 40px 0px; | ||
} | ||
.partnership-option-card { | ||
@include themeable( | ||
background, | ||
theme-container-background, | ||
$white | ||
); | ||
text-align: left; | ||
width: 100%; | ||
@media screen and ( min-width: 820px ){ | ||
width: calc(50% - 15px); | ||
margin-right: 8px; | ||
ul { | ||
height: 220px; | ||
} | ||
} | ||
box-sizing: border-box; | ||
padding: 15px; | ||
border-radius: 12px; | ||
margin: 10px 0px; | ||
display: inline-block; | ||
@include themeable( | ||
border, | ||
theme-border, | ||
1px solid $light-medium-gray | ||
); | ||
@include themeable( | ||
box-shadow, | ||
theme-container-box-shadow, | ||
2px 2px 8px darken($light-medium-gray, 5%) | ||
); | ||
li { | ||
padding: 8px 0px; | ||
} | ||
h2 { | ||
margin: 0px; | ||
padding: 10px 0px; | ||
border-bottom: 2px solid rgba(0,0,0,0.1); | ||
} | ||
.partnership-option-cta { | ||
display: block; | ||
font-size: 1.6em; | ||
padding: 20px 0px; | ||
text-align: center; | ||
border-radius: 5px; | ||
font-weight: bold; | ||
@include themeable( | ||
background, | ||
theme-anchor-color, | ||
$bold-blue | ||
); | ||
@include themeable( | ||
color, | ||
theme-container-background, | ||
white | ||
); | ||
} | ||
} | ||
} |
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,104 @@ | ||
class PartnershipsController < ApplicationController | ||
before_action :set_cache_control_headers, only: %i[index] | ||
before_action :authenticate_user!, only: %i[create] | ||
after_action :verify_authorized | ||
|
||
def index | ||
skip_authorization | ||
set_surrogate_key_header "partnership-index" | ||
end | ||
|
||
def show | ||
skip_authorization | ||
end | ||
|
||
def create | ||
@level = params[:sponsorship_level] | ||
@number_of_credits_needed = credits_for_level | ||
@organization = Organization.find(params[:organization_id]) | ||
update_sponsorship_instructions | ||
authorize @organization, :admin_of_org? | ||
@available_org_credits = @organization.credits.where(spent: false) | ||
if @level == "tag" | ||
@tag = Tag.find_by(name: params[:tag_name]) | ||
@tag.sponsor_organization_id = @organization.id | ||
slackbot_ping("@#{current_user.username} bought a ##{@tag.name} sponsorship for @#{@organization.username}") | ||
if @available_org_credits.size >= @number_of_credits_needed | ||
@tag.save! | ||
spend_credits | ||
redirect_back(fallback_location: "/partnerships") | ||
else | ||
raise "Not enough credits" | ||
end | ||
elsif @level == "media" | ||
# For now. Just ping slack. | ||
slackbot_ping("📹 @#{current_user.username} bought #{@number_of_credits_needed} media credits for @#{@organization.username}") | ||
if @available_org_credits.size >= @number_of_credits_needed | ||
spend_credits | ||
redirect_back(fallback_location: "/partnerships") | ||
end | ||
elsif @level == "editorial" | ||
SlackBot.ping( | ||
message: "@#{current_user.username} bought #{@number_of_credits_needed} credits for @#{@organization.username}", | ||
channel: "incoming-partners", | ||
username: "media_sponsor", | ||
icon_emoji: ":partyparrot:", | ||
) | ||
slackbot_ping("✍ @#{current_user.username} bought an editorial partnership for @#{@organization.username}") | ||
if @available_org_credits.size >= @number_of_credits_needed | ||
spend_credits | ||
redirect_back(fallback_location: "/partnerships") | ||
end | ||
else | ||
@organization.sponsorship_level = @level | ||
@organization.sponsorship_status = "pending" | ||
@organization.sponsorship_expires_at = (@organization.sponsorship_expires_at || Time.current) + 1.month | ||
slackbot_ping("@#{current_user.username} bought a #{@level} sponsorship for @#{@organization.username}") | ||
if @available_org_credits.size >= @number_of_credits_needed | ||
@organization.save! | ||
spend_credits | ||
redirect_back(fallback_location: "/partnerships") | ||
else | ||
raise "Not enough credits" | ||
end | ||
end | ||
end | ||
|
||
private | ||
|
||
def credits_for_level | ||
if @level == "gold" | ||
6000 | ||
elsif @level == "silver" | ||
300 | ||
elsif @level == "tag" | ||
500 | ||
elsif @level == "bronze" | ||
50 | ||
elsif @level == "editorial" | ||
500 | ||
elsif @level == "media" | ||
params[:sponsorship_amount].to_i | ||
else | ||
raise "Invalid level" | ||
end | ||
end | ||
|
||
def update_sponsorship_instructions | ||
@organization.sponsorship_instructions = @organization.sponsorship_instructions + "\n---\n#{Time.current}\n---\n" + params[:sponsorship_instructions].to_s | ||
@organization.sponsorship_instructions_updated_at = Time.current | ||
end | ||
|
||
def spend_credits | ||
@available_org_credits.limit(@number_of_credits_needed).update_all(spent: true) | ||
end | ||
|
||
def slackbot_ping(text) | ||
SlackBot.ping( | ||
message: text, | ||
channel: "incoming-partners", | ||
username: "media_sponsor", | ||
icon_emoji: ":partyparrot:", | ||
) | ||
end | ||
end |
Oops, something went wrong.