[deploy] Move community_copyright_start_year to SiteConfig (#9863)
* Move community_copyright_start_year to SiteConfig * Properly translate year to string * Change year logic * Add env default to copyright year * Fix logic * Fix codeclimage issue * Add view element * Add constants in properly and use dynamic date
This commit is contained in:
parent
244d632565
commit
f452086280
11 changed files with 31 additions and 9 deletions
|
|
@ -96,6 +96,7 @@ module Admin
|
|||
community_description
|
||||
community_member_label
|
||||
community_action
|
||||
community_copyright_start_year
|
||||
tagline
|
||||
]
|
||||
end
|
||||
|
|
|
|||
|
|
@ -188,10 +188,10 @@ module ApplicationHelper
|
|||
end
|
||||
|
||||
def copyright_notice
|
||||
start_year = ApplicationConfig["COMMUNITY_COPYRIGHT_START_YEAR"]
|
||||
start_year = SiteConfig.community_copyright_start_year.to_s
|
||||
current_year = Time.current.year.to_s
|
||||
return start_year if current_year == start_year
|
||||
return current_year if start_year.strip.length.zero?
|
||||
return current_year if start_year.strip.length < 4 # 978 is not a valid year!
|
||||
|
||||
"#{start_year} - #{current_year}"
|
||||
end
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ module BadgeRewarder
|
|||
MINIMUM_QUALITY = -25
|
||||
|
||||
def self.award_yearly_club_badges
|
||||
total_years = Time.current.year - ApplicationConfig["COMMUNITY_COPYRIGHT_START_YEAR"].to_i
|
||||
total_years = Time.current.year - SiteConfig.community_copyright_start_year.to_i
|
||||
(1..total_years).each do |i|
|
||||
message = "Happy #{ApplicationConfig['COMMUNITY_NAME']} birthday! " \
|
||||
"Can you believe it's been #{i} #{'year'.pluralize(i)} already?!"
|
||||
|
|
|
|||
|
|
@ -41,6 +41,10 @@ module Constants
|
|||
description: "Used to determine the action of community e.g coding, reading, training etc.",
|
||||
placeholder: ""
|
||||
},
|
||||
community_copyright_start_year: {
|
||||
description: "Used to mark the year this forem was started.",
|
||||
placeholder: Time.zone.today.year.to_s
|
||||
},
|
||||
tagline: {
|
||||
description: "Used in signup modal.",
|
||||
placeholder: "We're a place where coders share, stay up-to-date and grow their careers."
|
||||
|
|
|
|||
|
|
@ -30,6 +30,9 @@ class SiteConfig < RailsSettings::Base
|
|||
field :community_member_label, type: :string, default: "user"
|
||||
field :community_action, type: :string
|
||||
field :tagline, type: :string
|
||||
field :community_copyright_start_year, type: :integer,
|
||||
default: ApplicationConfig["COMMUNITY_COPYRIGHT_START_YEAR"] ||
|
||||
Time.zone.today.year
|
||||
|
||||
# Emails
|
||||
field :email_addresses, type: :hash, default: {
|
||||
|
|
|
|||
|
|
@ -243,6 +243,15 @@
|
|||
placeholder: "We're a place where coders share, stay up-to-date and grow their careers." %>
|
||||
<div class="alert alert-info">Used in signup modal.</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<%= admin_config_label :community_copyright_start_year %>
|
||||
<%= f.text_field :community_copyright_start_year,
|
||||
class: "form-control",
|
||||
value: SiteConfig.community_copyright_start_year,
|
||||
placeholder: Constants::SiteConfig::DETAILS[:community_copyright_start_year][:placeholder] %>
|
||||
<div class="alert alert-info"><%= Constants::SiteConfig::DETAILS[:community_copyright_start_year][:description] %></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@ export APP_DOMAIN="localhost:3000"
|
|||
export APP_PROTOCOL="http://"
|
||||
|
||||
# Community Related Variables
|
||||
export COMMUNITY_COPYRIGHT_START_YEAR="2016"
|
||||
export COMMUNITY_NAME="DEV(local)"
|
||||
|
||||
# Email related variables
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@ APP_DOMAIN: "localhost:3000"
|
|||
APP_PROTOCOL: "http://"
|
||||
|
||||
# Community Related Variables
|
||||
COMMUNITY_COPYRIGHT_START_YEAR: "2016"
|
||||
COMMUNITY_NAME: "DEV(local)"
|
||||
|
||||
# Email related variables
|
||||
|
|
|
|||
|
|
@ -52,21 +52,21 @@ RSpec.describe ApplicationHelper, type: :helper do
|
|||
|
||||
context "when the start year and current year is the same" do
|
||||
it "returns the current year only" do
|
||||
allow(ApplicationConfig).to receive(:[]).with("COMMUNITY_COPYRIGHT_START_YEAR").and_return(current_year)
|
||||
SiteConfig.community_copyright_start_year = current_year
|
||||
expect(helper.copyright_notice).to eq(current_year)
|
||||
end
|
||||
end
|
||||
|
||||
context "when the start year and current year is different" do
|
||||
it "returns the start and current year" do
|
||||
allow(ApplicationConfig).to receive(:[]).with("COMMUNITY_COPYRIGHT_START_YEAR").and_return("2014")
|
||||
SiteConfig.community_copyright_start_year = "2014"
|
||||
expect(helper.copyright_notice).to eq("2014 - #{current_year}")
|
||||
end
|
||||
end
|
||||
|
||||
context "when the start year is blank" do
|
||||
it "returns the current year" do
|
||||
allow(ApplicationConfig).to receive(:[]).with("COMMUNITY_COPYRIGHT_START_YEAR").and_return(" ")
|
||||
SiteConfig.community_copyright_start_year = " "
|
||||
expect(helper.copyright_notice).to eq(current_year)
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ RSpec.describe BadgeRewarder, type: :labor do
|
|||
before do
|
||||
stub_const("#{described_class}::YEARS", BadgeRewarder::YEARS.slice(1, 2, 3))
|
||||
allow(ApplicationConfig).to receive(:[])
|
||||
allow(ApplicationConfig).to receive(:[]).with("COMMUNITY_COPYRIGHT_START_YEAR").and_return(3.years.ago.year)
|
||||
SiteConfig.community_copyright_start_year = 3.years.ago.year
|
||||
create(:badge, title: "one-year-club")
|
||||
create(:badge, title: "two-year-club")
|
||||
create(:badge, title: "three-year-club")
|
||||
|
|
|
|||
|
|
@ -96,6 +96,13 @@ RSpec.describe "/admin/config", type: :request do
|
|||
expect(SiteConfig.community_member_label).to eq(action)
|
||||
end
|
||||
|
||||
it "updates the community_copyright_start_year" do
|
||||
year = "2018"
|
||||
post "/admin/config", params: { site_config: { community_copyright_start_year: year },
|
||||
confirmation: confirmation_message }
|
||||
expect(SiteConfig.community_copyright_start_year).to eq(2018)
|
||||
end
|
||||
|
||||
it "updates the tagline" do
|
||||
description = "Hey hey #{rand(100)}"
|
||||
post "/admin/config", params: { site_config: { tagline: description }, confirmation: confirmation_message }
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue