mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-12-17 19:12:37 -05:00
Can change TOS content via site content editor
This commit is contained in:
parent
af9b27358c
commit
72b4f41254
8 changed files with 80 additions and 24 deletions
|
@ -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
|
||||
|
|
|
@ -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}
|
||||
|
|
|
@ -36,17 +36,7 @@
|
|||
|
||||
<div id="3"></div>
|
||||
<h2><a href="#3">3. User Content License</a></h2>
|
||||
<!--<p>
|
||||
By submitting Content to <%= SiteSetting.company_short_name %> for inclusion on your Website, you grant <%= SiteSetting.company_short_name %> a world-wide, royalty-free, and non-exclusive license to reproduce, modify, adapt and publish the Content solely for the purpose of displaying, distributing and promoting your content. If you delete Content, <%= SiteSetting.company_short_name %> will use reasonable efforts to remove it from the Website, but you acknowledge that caching or references to the Content may not be made immediately unavailable.
|
||||
</p>-->
|
||||
|
||||
<p>
|
||||
User contributions are licensed under a <a href="http://creativecommons.org/licenses/by-nc-sa/3.0/deed.en_US">Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License</a>. 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.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
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.
|
||||
</p>
|
||||
<%= markdown_content(:tos_user_content_license) %>
|
||||
|
||||
<div id="4"></div>
|
||||
<h2><a href="#4">4. Payment and Renewal</a></h2>
|
||||
|
@ -133,6 +123,4 @@ You agree to indemnify and hold harmless <%= SiteSetting.company_short_name %>,
|
|||
|
||||
<div id="18"></div>
|
||||
<h2><a href="#18">18. Miscellaneous</a></h2>
|
||||
<p>
|
||||
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.
|
||||
</p>
|
||||
<%= markdown_content(:tos_miscellaneous) %>
|
||||
|
|
|
@ -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."
|
||||
|
|
|
@ -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
|
||||
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue