Skip to content

Commit

Permalink
Support for custom Privacy Policies
Browse files Browse the repository at this point in the history
  • Loading branch information
eviltrout committed Jun 26, 2013
1 parent 196a8f4 commit 89f1828
Show file tree
Hide file tree
Showing 16 changed files with 50 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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'),

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@
{{#titledLinkTo "list.latest" titleKey="filters.latest.help"}}{{i18n filters.latest.title}}{{/titledLinkTo}}
</li>
<li>{{#linkTo 'faq'}}{{i18n faq}}{{/linkTo}}</li>

{{#if categories}}
<li class='heading' title="{{i18n filters.categories.help}}">
{{#linkTo "list.categories"}}{{i18n filters.categories.title}}{{/linkTo}}
Expand Down
10 changes: 8 additions & 2 deletions app/controllers/admin/site_contents_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,14 @@ def show

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
Expand Down
6 changes: 5 additions & 1 deletion app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,12 @@ def crawlable_meta_data(opts=nil)
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
Expand Down
1 change: 1 addition & 0 deletions app/models/site_content.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ def self.formats
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}
Expand Down
4 changes: 4 additions & 0 deletions app/models/site_content_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ def description
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])
Expand Down
7 changes: 6 additions & 1 deletion app/serializers/site_content_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ class SiteContentSerializer < ApplicationSerializer
:title,
:description,
:content,
:format
:format,
:allow_blank?

def title
object.site_content_type.title
Expand All @@ -22,4 +23,8 @@ def content
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
1 change: 1 addition & 0 deletions app/serializers/site_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions app/views/static/privacy.cs.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
<li><a class="active" href="<%=privacy_path%>">Ochrana soukromí</a></li>
</ul>

<%= markdown_content(:privacy_policy) do %>

<div id="collect"></div>
<h2><a href="#collect">Jaké osobní informace sbíráme?</a></h2>
<p>
Expand Down Expand Up @@ -76,3 +78,5 @@
<p>
Pokud se rozhodneme změnit naše podmínky ochrany soukromí, zašleme tyto změny na tuto stránku.
</p>

<% end %>
6 changes: 5 additions & 1 deletion app/views/static/privacy.en.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
<li><a class="active" href="<%=privacy_path%>">Privacy</a></li>
</ul>

<%= markdown_content(:privacy_policy) do %>

<div id="collect"></div>
<h2><a href="#collect">What information do we collect?</a></h2>
<p>
Expand Down Expand Up @@ -95,4 +97,6 @@ If we decide to change our privacy policy, we will post those changes on this pa

<p>
This document is CC-BY-SA. It was last updated May 31, 2013.
</p>
</p>

<% end %>
6 changes: 5 additions & 1 deletion app/views/static/privacy.ru.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
<li><a class="active" href="<%=privacy_path%>">Конфиденциальность</a></li>
</ul>

<%= markdown_content(:privacy_policy) do %>

<div id="collect"></div>
<h2><a href="#collect">Какую информацию мы храним?</a></h2>
<p>
Expand Down Expand Up @@ -96,4 +98,6 @@

<p>
Данный документ распространяется под лицензией CC-BY-SA. Дата последнего обновления - 31 мая 2013 года.
</p>
</p>

<% end %>
4 changes: 4 additions & 0 deletions app/views/static/privacy.zh_CN.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
<li><a class="active" href="/privacy">隐私条款</a></li>
</ul>

<%= markdown_content(:privacy_policy) do %>

<div id="collect"></div>
<h2><a href="#collect">What information do we collect?</a></h2>
<p>
Expand Down Expand Up @@ -76,3 +78,5 @@ By using our site, you consent to our web site privacy policy.
<p>
If we decide to change our privacy policy, we will post those changes on this page.
</p>

<% end %>
1 change: 1 addition & 0 deletions config/locales/client.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ en:
show_more: "show more"
links: Links
faq: "FAQ"
privacy_policy: "Privacy Policy"
you: "You"
or: "or"
now: "just now"
Expand Down
5 changes: 3 additions & 2 deletions config/locales/server.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand Down
Empty file removed db/fixtures/site_content_types.rb
Empty file.
1 change: 0 additions & 1 deletion lib/site_content_class_methods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ def content_for(content_type, replacements=nil)
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 = ""
Expand Down

0 comments on commit 89f1828

Please sign in to comment.