diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 616c1567f..006edccf4 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -54,6 +54,10 @@ module ApplicationHelper result end + def markdown_content(key, replacements=nil) + PrettyText.cook(SiteContent.content_for(key, replacements || {})).html_safe + end + def faq_path return "#{Discourse::base_uri}/faq" end diff --git a/app/models/site_content.rb b/app/models/site_content.rb index 47dd86c88..70dddaa6f 100644 --- a/app/models/site_content.rb +++ b/app/models/site_content.rb @@ -12,11 +12,13 @@ class SiteContent < ActiveRecord::Base @formats ||= Enum.new(:plain, :markdown, :html, :css) end - content_type :usage_tips, :markdown, default_18n_key: 'system_messages.usage_tips.text_body_template' - content_type :welcome_user, :markdown, default_18n_key: 'system_messages.welcome_user.text_body_template' - content_type :welcome_invite, :markdown, default_18n_key: 'system_messages.welcome_invite.text_body_template' - content_type :education_new_topic, :markdown, default_18n_key: 'education.new-topic' - content_type :education_new_reply, :markdown, default_18n_key: 'education.new-reply' + add_content_type :usage_tips, default_18n_key: 'system_messages.usage_tips.text_body_template' + add_content_type :welcome_user, default_18n_key: 'system_messages.welcome_user.text_body_template' + add_content_type :welcome_invite, default_18n_key: 'system_messages.welcome_invite.text_body_template' + add_content_type :education_new_topic, default_18n_key: 'education.new-topic' + add_content_type :education_new_reply, default_18n_key: 'education.new-reply' + add_content_type :tos_user_content_license, default_18n_key: 'terms_of_service.user_content_license' + add_content_type :tos_miscellaneous, default_18n_key: 'terms_of_service.miscellaneous' def site_content_type @site_content_type ||= SiteContent.content_types.find {|t| t.content_type == content_type.to_sym} diff --git a/app/views/static/tos.en.html.erb b/app/views/static/tos.en.html.erb index f104bc71e..9f1862b79 100644 --- a/app/views/static/tos.en.html.erb +++ b/app/views/static/tos.en.html.erb @@ -36,17 +36,7 @@

3. User Content License

- - -

- User contributions are licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License. Without limiting any of those representations or warranties, <%= SiteSetting.company_short_name %> has the right (though not the obligation) to, in <%= SiteSetting.company_short_name %>’s sole discretion (i) refuse or remove any content that, in <%= SiteSetting.company_short_name %>’s reasonable opinion, violates any <%= SiteSetting.company_short_name %> policy or is in any way harmful or objectionable, or (ii) terminate or deny access to and use of the Website to any individual or entity for any reason, in <%= SiteSetting.company_short_name %>’s sole discretion. <%= SiteSetting.company_short_name %> will have no obligation to provide a refund of any amounts previously paid. -

- -

- Without limiting any of those representations or warranties, <%= SiteSetting.company_short_name %> has the right (though not the obligation) to, in <%= SiteSetting.company_short_name %>’s sole discretion (i) refuse or remove any content that, in <%= SiteSetting.company_short_name %>’s reasonable opinion, violates any <%= SiteSetting.company_short_name %> policy or is in any way harmful or objectionable, or (ii) terminate or deny access to and use of the Website to any individual or entity for any reason, in <%= SiteSetting.company_short_name %>’s sole discretion. <%= SiteSetting.company_short_name %> will have no obligation to provide a refund of any amounts previously paid. -

+<%= markdown_content(:tos_user_content_license) %>

4. Payment and Renewal

@@ -133,6 +123,4 @@ You agree to indemnify and hold harmless <%= SiteSetting.company_short_name %>,

18. Miscellaneous

-

- This Agreement constitutes the entire agreement between <%= SiteSetting.company_short_name %> and you concerning the subject matter hereof, and they may only be modified by a written amendment signed by an authorized executive of <%= SiteSetting.company_short_name %>, or by the posting by <%= SiteSetting.company_short_name %> of a revised version. Except to the extent applicable law, if any, provides otherwise, this Agreement, any access to or use of the Website will be governed by the laws of the state of California, U.S.A., excluding its conflict of law provisions, and the proper venue for any disputes arising out of or relating to any of the same will be the state and federal courts located in San Francisco County, California. Except for claims for injunctive or equitable relief or claims regarding intellectual property rights (which may be brought in any competent court without the posting of a bond), any dispute arising under this Agreement shall be finally settled in accordance with the Comprehensive Arbitration Rules of the Judicial Arbitration and Mediation Service, Inc. (“JAMS”) by three arbitrators appointed in accordance with such Rules. The arbitration shall take place in San Francisco, California, in the English language and the arbitral decision may be enforced in any court. The prevailing party in any action or proceeding to enforce this Agreement shall be entitled to costs and attorneys’ fees. If any part of this Agreement is held invalid or unenforceable, that part will be construed to reflect the parties’ original intent, and the remaining portions will remain in full force and effect. A waiver by either party of any term or condition of this Agreement or any breach thereof, in any one instance, will not waive such term or condition or any subsequent breach thereof. You may assign your rights under this Agreement to any party that consents to, and agrees to be bound by, its terms and conditions; <%= SiteSetting.company_short_name %> may assign its rights under this Agreement without condition. This Agreement will be binding upon and will inure to the benefit of the parties, their successors and permitted assigns. -

+<%= markdown_content(:tos_miscellaneous) %> diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml index 926f4c151..efb14724f 100644 --- a/config/locales/server.en.yml +++ b/config/locales/server.en.yml @@ -326,6 +326,12 @@ en: welcome_invite: title: "Welcome: Invited User" description: "A private message automatically sent to all new invited users when they accept the invitation from another user to participate." + tos_user_content_license: + title: "Terms of Service: Content License" + description: "The text for the Content License section of the Terms of Service." + tos_miscellaneous: + title: "Terms of Service: Miscellaneous" + description: "The text for the Miscellaneous section of the Terms of Service." site_settings: default_locale: "The default language of this Discourse instance (ISO 639-1 Code)" @@ -862,3 +868,10 @@ en: see_more: "See More" search_title: "Search for this topic" search_google: "Search Google" + + terms_of_service: + user_content_license: | + User contributions are licensed under a [Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License](http://creativecommons.org/licenses/by-nc-sa/3.0/deed.en_US). Without limiting any of those representations or warranties, %{company_short_name} has the right (though not the obligation) to, in %{company_short_name}’s sole discretion (i) refuse or remove any content that, in %{company_short_name}’s reasonable opinion, violates any %{company_short_name} policy or is in any way harmful or objectionable, or (ii) terminate or deny access to and use of the Website to any individual or entity for any reason, in %{company_short_name}’s sole discretion. %{company_short_name} will have no obligation to provide a refund of any amounts previously paid. + + Without limiting any of those representations or warranties, %{company_short_name} has the right (though not the obligation) to, in %{company_short_name}’s sole discretion (i) refuse or remove any content that, in %{company_short_name}’s reasonable opinion, violates any %{company_short_name} policy or is in any way harmful or objectionable, or (ii) terminate or deny access to and use of the Website to any individual or entity for any reason, in %{company_short_name}’s sole discretion. %{company_short_name} will have no obligation to provide a refund of any amounts previously paid. + miscellaneous: "This Agreement constitutes the entire agreement between %{company_short_name} and you concerning the subject matter ereof, and they may only be modified by a written amendment signed by an authorized executive of %{company_short_name}, or by the posting by %{company_short_name} of a revised version. Except to the extent applicable law, if any, provides otherwise, this Agreement, any access to or use of the Website will be governed by the laws of the state of California, U.S.A., excluding its conflict of law provisions, and the proper venue for any disputes arising out of or relating to any of the same will be the state and federal courts located in San Francisco County, California. Except for claims for injunctive or equitable relief or claims regarding intellectual property rights (which may be brought in any competent court without the posting of a bond), any dispute arising under this Agreement shall be finally settled in accordance with the Comprehensive Arbitration Rules of the Judicial Arbitration and Mediation Service, Inc. (“JAMS”) by three arbitrators appointed in accordance with such Rules. The arbitration shall take place in San Francisco, California, in the English language and the arbitral decision may be enforced in any court. The prevailing party in any action or proceeding to enforce this Agreement shall be entitled to costs and attorneys’ fees. If any part of this Agreement is held invalid or unenforceable, that part will be construed to reflect the parties’ original intent, and the remaining portions will remain in full force and effect. A waiver by either party of any term or condition of this Agreement or any breach thereof, in any one instance, will not waive such term or condition or any subsequent breach thereof. You may assign your rights under this Agreement to any party that consents to, and agrees to be bound by, its terms and conditions; %{company_short_name} may assign its rights under this Agreement without condition. This Agreement will be binding upon and will inure to the benefit of the parties, their successors and permitted assigns." diff --git a/lib/site_content_class_methods.rb b/lib/site_content_class_methods.rb index 7843b0c0b..fc1333cb1 100644 --- a/lib/site_content_class_methods.rb +++ b/lib/site_content_class_methods.rb @@ -4,19 +4,36 @@ module SiteContentClassMethods @types || [] end - def content_type(content_type, format, opts=nil) + def find_content_type(ct) + SiteContent.content_types.find {|t| t.content_type == ct.to_sym} + end + + def add_content_type(content_type, opts=nil) opts ||= {} @types ||= [] + format = opts[:format] || :markdown @types << SiteContentType.new(content_type, format, opts) end def content_for(content_type, replacements=nil) replacements ||= {} + replacements = SiteSetting.settings_hash.merge!(replacements) site_content = SiteContent.select(:content).where(content_type: content_type).first - return "" if site_content.blank? - site_content.content % replacements + result = "" + if site_content.blank? + ct = find_content_type(content_type) + result = ct.default_content if ct.present? + else + result = site_content.content + end + + result.gsub!(/\%\{[^}]+\}/) do |m| + replacements[m[2..-2].to_sym] || m + end + + result end diff --git a/lib/site_setting_extension.rb b/lib/site_setting_extension.rb index c3c573d86..60aff615d 100644 --- a/lib/site_setting_extension.rb +++ b/lib/site_setting_extension.rb @@ -38,6 +38,13 @@ module SiteSettingExtension @@client_settings end + def settings_hash + result = {} + @defaults.each do |s, v| + result[s] = send(s).to_s + end + result + end def client_settings_json Rails.cache.fetch(SiteSettingExtension.client_settings_cache_key, expires_in: 30.minutes) do diff --git a/spec/fabricators/site_content_fabricator.rb b/spec/fabricators/site_content_fabricator.rb index 56ce55c05..0eb26630f 100644 --- a/spec/fabricators/site_content_fabricator.rb +++ b/spec/fabricators/site_content_fabricator.rb @@ -6,4 +6,9 @@ end Fabricator(:site_content_basic, from: :site_content) do content_type 'breaking.bad' content "best show ever" +end + +Fabricator(:site_content_site_setting, from: :site_content) do + content_type 'site.replacement' + content "%{title} is evil." end \ No newline at end of file diff --git a/spec/models/site_content_spec.rb b/spec/models/site_content_spec.rb index ed8512d1e..faf35c81f 100644 --- a/spec/models/site_content_spec.rb +++ b/spec/models/site_content_spec.rb @@ -11,6 +11,10 @@ describe SiteContent do SiteContent.content_for('breaking.bad').should == "" end + it "returns the default value for a content type with a default" do + SiteContent.content_for("usage_tips").should be_present + end + context "without replacements" do let!(:site_content) { Fabricate(:site_content_basic) } @@ -32,11 +36,27 @@ describe SiteContent do SiteContent.content_for('great.poem', replacements.merge(extra: 'key')).should == "roses are red. grapes are blue." end - it "raises an error with missing keys" do - -> { SiteContent.content_for('great.poem', flower: 'roses') }.should raise_error + it "ignores missing keys" do + SiteContent.content_for('great.poem', flower: 'roses').should == "roses are red. %{food} are blue." end end + + context "replacing site_settings" do + let!(:site_content) { Fabricate(:site_content_site_setting) } + + it "replaces site_settings by default" do + SiteSetting.stubs(:title).returns("Evil Trout") + SiteContent.content_for('site.replacement').should == "Evil Trout is evil." + end + + it "allows us to override the default site settings" do + SiteSetting.stubs(:title).returns("Evil Trout") + SiteContent.content_for('site.replacement', title: 'Good Tuna').should == "Good Tuna is evil." + end + + end + end end