diff --git a/app/controllers/admin/configs_controller.rb b/app/controllers/admin/configs_controller.rb
index d8f45cdb6..828d86089 100644
--- a/app/controllers/admin/configs_controller.rb
+++ b/app/controllers/admin/configs_controller.rb
@@ -96,6 +96,7 @@ module Admin
community_description
community_member_label
community_action
+ community_copyright_start_year
tagline
]
end
diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb
index 412c908df..923f5acf1 100644
--- a/app/helpers/application_helper.rb
+++ b/app/helpers/application_helper.rb
@@ -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
diff --git a/app/labor/badge_rewarder.rb b/app/labor/badge_rewarder.rb
index 36d95a4b3..33c7fbb92 100644
--- a/app/labor/badge_rewarder.rb
+++ b/app/labor/badge_rewarder.rb
@@ -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?!"
diff --git a/app/lib/constants/site_config.rb b/app/lib/constants/site_config.rb
index 9d9dc729c..702e885ab 100644
--- a/app/lib/constants/site_config.rb
+++ b/app/lib/constants/site_config.rb
@@ -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."
diff --git a/app/models/site_config.rb b/app/models/site_config.rb
index c304bb642..9cffbfe50 100644
--- a/app/models/site_config.rb
+++ b/app/models/site_config.rb
@@ -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: {
diff --git a/app/views/admin/configs/show.html.erb b/app/views/admin/configs/show.html.erb
index 9e306baea..66c314b67 100644
--- a/app/views/admin/configs/show.html.erb
+++ b/app/views/admin/configs/show.html.erb
@@ -243,6 +243,15 @@
placeholder: "We're a place where coders share, stay up-to-date and grow their careers." %>
Used in signup modal.
+
+
diff --git a/config/.env_sample b/config/.env_sample
index 3f100f258..2cac95618 100644
--- a/config/.env_sample
+++ b/config/.env_sample
@@ -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
diff --git a/config/sample_application.yml b/config/sample_application.yml
index c94c2f6ce..68805c4bd 100644
--- a/config/sample_application.yml
+++ b/config/sample_application.yml
@@ -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
diff --git a/spec/helpers/application_helper_spec.rb b/spec/helpers/application_helper_spec.rb
index 0f29ae6d6..df92e8fde 100644
--- a/spec/helpers/application_helper_spec.rb
+++ b/spec/helpers/application_helper_spec.rb
@@ -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
diff --git a/spec/labor/badge_rewarder_spec.rb b/spec/labor/badge_rewarder_spec.rb
index cef7cea4c..93e6e28ca 100644
--- a/spec/labor/badge_rewarder_spec.rb
+++ b/spec/labor/badge_rewarder_spec.rb
@@ -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")
diff --git a/spec/requests/admin/configs_spec.rb b/spec/requests/admin/configs_spec.rb
index 69d47e1a8..d388dc984 100644
--- a/spec/requests/admin/configs_spec.rb
+++ b/spec/requests/admin/configs_spec.rb
@@ -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 }