From 89f182899f2e8e8d9048a97e28affae3ede5d103 Mon Sep 17 00:00:00 2001
From: Robin Ward
Date: Wed, 26 Jun 2013 10:57:35 -0400
Subject: [PATCH] Support for custom Privacy Policies
---
.../controllers/admin_site_content_edit_controller.js | 4 ++--
.../discourse/templates/header.js.handlebars | 1 +
app/controllers/admin/site_contents_controller.rb | 10 ++++++++--
app/helpers/application_helper.rb | 6 +++++-
app/models/site_content.rb | 1 +
app/models/site_content_type.rb | 4 ++++
app/serializers/site_content_serializer.rb | 7 ++++++-
app/serializers/site_serializer.rb | 1 +
app/views/static/privacy.cs.html.erb | 4 ++++
app/views/static/privacy.en.html.erb | 6 +++++-
app/views/static/privacy.ru.html.erb | 6 +++++-
app/views/static/privacy.zh_CN.html.erb | 4 ++++
config/locales/client.en.yml | 1 +
config/locales/server.en.yml | 5 +++--
db/fixtures/site_content_types.rb | 0
lib/site_content_class_methods.rb | 1 -
16 files changed, 50 insertions(+), 11 deletions(-)
delete mode 100644 db/fixtures/site_content_types.rb
diff --git a/app/assets/javascripts/admin/controllers/admin_site_content_edit_controller.js b/app/assets/javascripts/admin/controllers/admin_site_content_edit_controller.js
index 981d15c6f..dfaebeb04 100644
--- a/app/assets/javascripts/admin/controllers/admin_site_content_edit_controller.js
+++ b/app/assets/javascripts/admin/controllers/admin_site_content_edit_controller.js
@@ -9,8 +9,8 @@
Discourse.AdminSiteContentEditController = Discourse.Controller.extend({
saveDisabled: function() {
- if (this.get('saving')) return true;
- if (this.blank('content.content')) return true;
+ if (this.get('saving')) { return true; }
+ if ((!this.get('content.allow_blank')) && this.blank('content.content')) { return true; }
return false;
}.property('saving', 'content.content'),
diff --git a/app/assets/javascripts/discourse/templates/header.js.handlebars b/app/assets/javascripts/discourse/templates/header.js.handlebars
index 7d72ebf46..0fbf11769 100644
--- a/app/assets/javascripts/discourse/templates/header.js.handlebars
+++ b/app/assets/javascripts/discourse/templates/header.js.handlebars
@@ -123,6 +123,7 @@
{{#titledLinkTo "list.latest" titleKey="filters.latest.help"}}{{i18n filters.latest.title}}{{/titledLinkTo}}
{{#linkTo 'faq'}}{{i18n faq}}{{/linkTo}}
+
{{#if categories}}
{{#linkTo "list.categories"}}{{i18n filters.categories.title}}{{/linkTo}}
diff --git a/app/controllers/admin/site_contents_controller.rb b/app/controllers/admin/site_contents_controller.rb
index 5d4d6124a..e900dbb54 100644
--- a/app/controllers/admin/site_contents_controller.rb
+++ b/app/controllers/admin/site_contents_controller.rb
@@ -7,8 +7,14 @@ class Admin::SiteContentsController < Admin::AdminController
def update
site_content = SiteContent.find_or_new(params[:id].to_s)
- site_content.content = params[:content]
- site_content.save!
+
+ # Updating to nothing is the same as removing it
+ if params[:content].present?
+ site_content.content = params[:content]
+ site_content.save!
+ else
+ site_content.destroy
+ end
render nothing: true
end
diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb
index 88a93627a..634ffa5fe 100644
--- a/app/helpers/application_helper.rb
+++ b/app/helpers/application_helper.rb
@@ -73,8 +73,12 @@ module ApplicationHelper
result
end
+ # Look up site content for a key. If the key is blank, you can supply a block and that
+ # will be rendered instead.
def markdown_content(key, replacements=nil)
- PrettyText.cook(SiteContent.content_for(key, replacements || {})).html_safe
+ result = PrettyText.cook(SiteContent.content_for(key, replacements || {})).html_safe
+ result = yield if result.blank? && block_given?
+ result
end
def faq_path
diff --git a/app/models/site_content.rb b/app/models/site_content.rb
index ee8484aa1..bfe232591 100644
--- a/app/models/site_content.rb
+++ b/app/models/site_content.rb
@@ -18,6 +18,7 @@ class SiteContent < ActiveRecord::Base
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'
add_content_type :login_required_welcome_message, default_18n_key: 'login_required.welcome_message'
+ add_content_type :privacy_policy, allow_blank: true
def site_content_type
@site_content_type ||= SiteContent.content_types.find {|t| t.content_type == content_type.to_sym}
diff --git a/app/models/site_content_type.rb b/app/models/site_content_type.rb
index 9b562f44f..5ba91888c 100644
--- a/app/models/site_content_type.rb
+++ b/app/models/site_content_type.rb
@@ -16,6 +16,10 @@ class SiteContentType
I18n.t("content_types.#{content_type}.description")
end
+ def allow_blank?
+ !!@opts[:allow_blank]
+ end
+
def default_content
if @opts[:default_18n_key].present?
return I18n.t(@opts[:default_18n_key])
diff --git a/app/serializers/site_content_serializer.rb b/app/serializers/site_content_serializer.rb
index 2c6dbf365..942b09416 100644
--- a/app/serializers/site_content_serializer.rb
+++ b/app/serializers/site_content_serializer.rb
@@ -4,7 +4,8 @@ class SiteContentSerializer < ApplicationSerializer
:title,
:description,
:content,
- :format
+ :format,
+ :allow_blank?
def title
object.site_content_type.title
@@ -22,4 +23,8 @@ class SiteContentSerializer < ApplicationSerializer
return object.content if object.content.present?
object.site_content_type.default_content
end
+
+ def allow_blank?
+ object.site_content_type.allow_blank?
+ end
end
diff --git a/app/serializers/site_serializer.rb b/app/serializers/site_serializer.rb
index 91371b9e9..0caf55df4 100644
--- a/app/serializers/site_serializer.rb
+++ b/app/serializers/site_serializer.rb
@@ -5,6 +5,7 @@ class SiteSerializer < ApplicationSerializer
:post_types,
:uncategorized_slug
+
has_many :categories, serializer: BasicCategorySerializer, embed: :objects
has_many :post_action_types, embed: :objects
has_many :trust_levels, embed: :objects
diff --git a/app/views/static/privacy.cs.html.erb b/app/views/static/privacy.cs.html.erb
index 6c8d8a902..b52f833d5 100644
--- a/app/views/static/privacy.cs.html.erb
+++ b/app/views/static/privacy.cs.html.erb
@@ -4,6 +4,8 @@
Ochrana soukromí
+<%= markdown_content(:privacy_policy) do %>
+
@@ -76,3 +78,5 @@
Pokud se rozhodneme změnit naše podmínky ochrany soukromí, zašleme tyto změny na tuto stránku.
+
+<% end %>
\ No newline at end of file
diff --git a/app/views/static/privacy.en.html.erb b/app/views/static/privacy.en.html.erb
index 63557d1d5..4465bfabe 100644
--- a/app/views/static/privacy.en.html.erb
+++ b/app/views/static/privacy.en.html.erb
@@ -4,6 +4,8 @@
Privacy
+<%= markdown_content(:privacy_policy) do %>
+
@@ -95,4 +97,6 @@ If we decide to change our privacy policy, we will post those changes on this pa
This document is CC-BY-SA. It was last updated May 31, 2013.
-
\ No newline at end of file
+
+
+<% end %>
\ No newline at end of file
diff --git a/app/views/static/privacy.ru.html.erb b/app/views/static/privacy.ru.html.erb
index 1ea1f5d4c..fbd7a6c47 100644
--- a/app/views/static/privacy.ru.html.erb
+++ b/app/views/static/privacy.ru.html.erb
@@ -4,6 +4,8 @@
Конфиденциальность
+<%= markdown_content(:privacy_policy) do %>
+
@@ -96,4 +98,6 @@
Данный документ распространяется под лицензией CC-BY-SA. Дата последнего обновления - 31 мая 2013 года.
-
\ No newline at end of file
+
+
+<% end %>
\ No newline at end of file
diff --git a/app/views/static/privacy.zh_CN.html.erb b/app/views/static/privacy.zh_CN.html.erb
index 12a8b0a48..9ee00d86f 100644
--- a/app/views/static/privacy.zh_CN.html.erb
+++ b/app/views/static/privacy.zh_CN.html.erb
@@ -4,6 +4,8 @@
隐私条款
+<%= markdown_content(:privacy_policy) do %>
+
@@ -76,3 +78,5 @@ By using our site, you consent to our web site privacy policy.
If we decide to change our privacy policy, we will post those changes on this page.
+
+<% end %>
\ No newline at end of file
diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml
index c89cb4015..babe6e57f 100644
--- a/config/locales/client.en.yml
+++ b/config/locales/client.en.yml
@@ -87,6 +87,7 @@ en:
show_more: "show more"
links: Links
faq: "FAQ"
+ privacy_policy: "Privacy Policy"
you: "You"
or: "or"
now: "just now"
diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml
index e0e451163..bc8cf1158 100644
--- a/config/locales/server.en.yml
+++ b/config/locales/server.en.yml
@@ -413,12 +413,13 @@ 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."
-
+ privacy_policy:
+ title: "Privacy Policy"
+ description: "Your site's privacy policy. Leave blank for default policy."
login_required_welcome_message:
title: "Login Required: Welcome Message"
description: "Welcome message that is displayed to logged out users when
the 'login required' setting is enabled."
-
tos_user_content_license:
title: "Terms of Service: Content License"
description: "The text for the Content License section of the Terms of Service."
diff --git a/db/fixtures/site_content_types.rb b/db/fixtures/site_content_types.rb
deleted file mode 100644
index e69de29bb..000000000
diff --git a/lib/site_content_class_methods.rb b/lib/site_content_class_methods.rb
index 5e4055d1f..5bc553f5e 100644
--- a/lib/site_content_class_methods.rb
+++ b/lib/site_content_class_methods.rb
@@ -20,7 +20,6 @@ module SiteContentClassMethods
replacements = {site_name: SiteSetting.title}.merge!(replacements)
replacements = SiteSetting.settings_hash.merge!(replacements)
-
site_content = SiteContent.select(:content).where(content_type: content_type).first
result = ""