From 87ff4373f531f7546de829cfd7f0522f034fb6b6 Mon Sep 17 00:00:00 2001 From: Jeremy Mack Date: Tue, 5 Feb 2013 15:59:17 -0500 Subject: [PATCH 01/23] Removed unnecessary @.'s Since CoffeeScript automatically converts @ to this. when immediately followed by a character. --- .../admin/models/site_customization.js.coffee | 8 ++--- app/assets/javascripts/discourse.js.coffee | 6 ++-- .../components/autocomplete.js.coffee | 32 +++++++++---------- 3 files changed, 23 insertions(+), 23 deletions(-) diff --git a/app/assets/javascripts/admin/models/site_customization.js.coffee b/app/assets/javascripts/admin/models/site_customization.js.coffee index 46a8622d11..fe8780d7e4 100644 --- a/app/assets/javascripts/admin/models/site_customization.js.coffee +++ b/app/assets/javascripts/admin/models/site_customization.js.coffee @@ -7,20 +7,20 @@ window.Discourse.SiteCustomization = Discourse.Model.extend trackedProperties: ['enabled','name', 'stylesheet', 'header', 'override_default_style'] description: (-> - "#{@.name}#{if @.enabled then ' (*)' else ''}" + "#{@name}#{if @enabled then ' (*)' else ''}" ).property('selected', 'name') changed: (-> - return false unless @.originals + return false unless @originals @trackedProperties.any (p)=> - @.originals[p] != @get(p) + @originals[p] != @get(p) ).property('override_default_style','enabled','name', 'stylesheet', 'header', 'originals') # TODO figure out how to call with apply startTrackingChanges: -> @set('originals',{}) @trackedProperties.each (p)=> - @.originals[p] = @get(p) + @originals[p] = @get(p) true previewUrl: (-> diff --git a/app/assets/javascripts/discourse.js.coffee b/app/assets/javascripts/discourse.js.coffee index aad1f9cb47..4e167c1494 100644 --- a/app/assets/javascripts/discourse.js.coffee +++ b/app/assets/javascripts/discourse.js.coffee @@ -256,9 +256,9 @@ window.Discourse = Ember.Application.createWithMixins @rerender() else $('link').each -> - if @.href.match(me.name) and me.hash - $(@).data('orig', @.href) unless $(@).data('orig') - @.href = $(@).data('orig') + "&hash=" + me.hash + if @href.match(me.name) and me.hash + $(@).data('orig', @href) unless $(@).data('orig') + @href = $(@).data('orig') + "&hash=" + me.hash window.Discourse.Router = Discourse.Router.reopen(location: 'discourse_location') diff --git a/app/assets/javascripts/discourse/components/autocomplete.js.coffee b/app/assets/javascripts/discourse/components/autocomplete.js.coffee index 412e5eb445..26d89d441c 100644 --- a/app/assets/javascripts/discourse/components/autocomplete.js.coffee +++ b/app/assets/javascripts/discourse/components/autocomplete.js.coffee @@ -3,14 +3,14 @@ template = null $.fn.autocomplete = (options)-> - - return if @.length == 0 - - if options && options.cancel && @.data("closeAutocomplete") - @.data("closeAutocomplete")() + + return if @length == 0 + + if options && options.cancel && @data("closeAutocomplete") + @data("closeAutocomplete")() return this - alert "only supporting one matcher at the moment" unless @.length == 1 + alert "only supporting one matcher at the moment" unless @length == 1 autocompleteOptions = null selectedOption = null @@ -47,27 +47,27 @@ if isInput - width = @.width() - height = @.height() + width = @width() + height = @height() + + wrap = @wrap("
").parent() - wrap = @.wrap("
").parent() - wrap.width(width) - @.width(80) - @.attr('name', @.attr('name') + "-renamed") + @width(80) + @attr('name', @attr('name') + "-renamed") + + vals = @val().split(",") - vals = @.val().split(",") - vals.each (x)-> unless x == "" x = options.reverseTransform(x) if options.reverseTransform addInputSelectedItem(x) - @.val("") + @val("") completeStart = 0 wrap.click => - @.focus() + @focus() true From 28c25940d20613faf14dacd43ec4ff6bd0ab3832 Mon Sep 17 00:00:00 2001 From: Mike Linksvayer Date: Tue, 5 Feb 2013 22:48:55 -0800 Subject: [PATCH 02/23] Update app/views/static/faq.html.erb remove example.com from example.com/tos --- app/views/static/faq.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/static/faq.html.erb b/app/views/static/faq.html.erb index 88b5722382..7c49b771cf 100644 --- a/app/views/static/faq.html.erb +++ b/app/views/static/faq.html.erb @@ -130,7 +130,7 @@

Terms of Service

- Yes, legalese is boring, but we must protect ourselves (and by extension, you and your data) against unfriendly folks. So, like everyone else, we have a Terms of Service TOS describing your (and our) behavior and rights related to content, privacy, and laws. To use this service, you must agree to abide by the TOS. + Yes, legalese is boring, but we must protect ourselves (and by extension, you and your data) against unfriendly folks. So, like everyone else, we have a Terms of Service TOS describing your (and our) behavior and rights related to content, privacy, and laws. To use this service, you must agree to abide by the TOS.

From 24584ae916f278a8064ab52797a1d7eac590b5c4 Mon Sep 17 00:00:00 2001 From: Sebastian Sogamoso Date: Wed, 6 Feb 2013 08:32:41 -0500 Subject: [PATCH 03/23] Remove empty helpers --- app/helpers/forum_helper.rb | 2 -- app/helpers/list_helper.rb | 2 -- app/helpers/notifications_helper.rb | 2 -- app/helpers/user_notifications_helper.rb | 3 --- 4 files changed, 9 deletions(-) delete mode 100644 app/helpers/forum_helper.rb delete mode 100644 app/helpers/list_helper.rb delete mode 100644 app/helpers/notifications_helper.rb delete mode 100644 app/helpers/user_notifications_helper.rb diff --git a/app/helpers/forum_helper.rb b/app/helpers/forum_helper.rb deleted file mode 100644 index cfbd978b92..0000000000 --- a/app/helpers/forum_helper.rb +++ /dev/null @@ -1,2 +0,0 @@ -module ForumHelper -end diff --git a/app/helpers/list_helper.rb b/app/helpers/list_helper.rb deleted file mode 100644 index eaa1d0e156..0000000000 --- a/app/helpers/list_helper.rb +++ /dev/null @@ -1,2 +0,0 @@ -module ListHelper -end diff --git a/app/helpers/notifications_helper.rb b/app/helpers/notifications_helper.rb deleted file mode 100644 index 7342393a70..0000000000 --- a/app/helpers/notifications_helper.rb +++ /dev/null @@ -1,2 +0,0 @@ -module NotificationsHelper -end diff --git a/app/helpers/user_notifications_helper.rb b/app/helpers/user_notifications_helper.rb deleted file mode 100644 index 721eba5f46..0000000000 --- a/app/helpers/user_notifications_helper.rb +++ /dev/null @@ -1,3 +0,0 @@ -module UserNotificationsHelper - -end From 8d568b05c469a81378bbe19fceb36a38d640302d Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Wed, 6 Feb 2013 11:55:54 -0500 Subject: [PATCH 04/23] Don't enable Cache-Control if the site has restricted access. --- app/controllers/application_controller.rb | 23 +++++++++++++++++++++-- app/controllers/list_controller.rb | 3 +-- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index ccdcf23673..4a95d6f2ab 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -135,14 +135,33 @@ class ApplicationController < ActionController::Base render json: MultiJson.dump(obj) end + def can_cache_content? + # Don't cache unless we're in production mode + return false unless Rails.env.production? + + # Don't cache logged in users + return false if current_user.present? + + # Don't cache if there's restricted access + return false if SiteSetting.restrict_access? + + true + end + + # Our custom cache method + def discourse_expires_in(time_length) + return unless can_cache_content? + expires_in time_length, public: true + end + # Helper method - if no logged in user (anonymous), use Rails' conditional GET # support. Should be very fast behind a cache. def anonymous_etag(*args) - if current_user.blank? and Rails.env.production? + if can_cache_content? yield if stale?(*args) # Add a one minute expiry - expires_in 1.minute, :public => true + expires_in time_length, public: true else yield end diff --git a/app/controllers/list_controller.rb b/app/controllers/list_controller.rb index 005b3d14c0..5d58635024 100644 --- a/app/controllers/list_controller.rb +++ b/app/controllers/list_controller.rb @@ -58,8 +58,7 @@ class ListController < ApplicationController draft = Draft.get(current_user, list.draft_key, list.draft_sequence) if current_user list.draft = draft - # Add expiry of 1 minute for anonymous - expires_in 1.minute, :public => true if current_user.blank? + discourse_expires_in 1.minute respond_to do |format| format.html do From 6043a370ad9bd5837a6f7f567e4207073d9a5936 Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Wed, 6 Feb 2013 12:07:22 -0500 Subject: [PATCH 05/23] Oops, that should be 1.minute --- app/controllers/application_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 4a95d6f2ab..18fb2898fb 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -161,7 +161,7 @@ class ApplicationController < ActionController::Base yield if stale?(*args) # Add a one minute expiry - expires_in time_length, public: true + expires_in 1.minute, public: true else yield end From 77908ed3d8cfef0ea8b9d804a7fbfb42f502f8b3 Mon Sep 17 00:00:00 2001 From: Ben Doerr Date: Wed, 6 Feb 2013 12:39:15 -0500 Subject: [PATCH 06/23] Split -vendor-placeholder selector by vendor. Some browsers (specifically Firefox(18) that I know of) fail to select correctly if the selectors are combined. This was fixed in bootstrap (https://github.com/twitter/bootstrap/blob/master/less/forms.less#L210). Not sure of the exact commit but there is a nice comment. --- app/assets/stylesheets/vendor/bootstrap.css.scss | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/app/assets/stylesheets/vendor/bootstrap.css.scss b/app/assets/stylesheets/vendor/bootstrap.css.scss index 813d5da2c0..b4e5717117 100644 --- a/app/assets/stylesheets/vendor/bootstrap.css.scss +++ b/app/assets/stylesheets/vendor/bootstrap.css.scss @@ -1418,7 +1418,13 @@ body { -moz-box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.025); box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.025); } - :-moz-placeholder, :-ms-input-placeholder, ::-webkit-input-placeholder { + :-moz-placeholder { + color: #999999; + } + ::-webkit-input-placeholder { + color: #999999; + } + :-ms-input-placeholder { color: #999999; } .help-block, .help-inline { From 2ce69c73eb4cf32193a5ec39bafe8fbac38cad83 Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Wed, 6 Feb 2013 14:27:11 -0500 Subject: [PATCH 07/23] Use double quotes in image uploads instead of single quotes. Our sanitizer seems to hate single quotes. --- app/assets/javascripts/discourse/views/composer_view.js.coffee | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/assets/javascripts/discourse/views/composer_view.js.coffee b/app/assets/javascripts/discourse/views/composer_view.js.coffee index 611ffd2a04..8e7e0df825 100644 --- a/app/assets/javascripts/discourse/views/composer_view.js.coffee +++ b/app/assets/javascripts/discourse/views/composer_view.js.coffee @@ -192,7 +192,7 @@ window.Discourse.ComposerView = window.Discourse.View.extend done: (e, data) => @set('loadingImage', false) upload = data.result - html = "" + html = "" @addMarkdown(html) fail: (e, data) => From de871ccf8a5611c89f3e86ce565f89bea4acb0d1 Mon Sep 17 00:00:00 2001 From: Bruno Bonamin Date: Wed, 6 Feb 2013 17:46:45 -0200 Subject: [PATCH 08/23] Fixed minor typo in lib/guardian.rb Just a letter switch I found upon browsing the code :) --- lib/guardian.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/guardian.rb b/lib/guardian.rb index d5d406f65b..72f475a4ee 100644 --- a/lib/guardian.rb +++ b/lib/guardian.rb @@ -1,4 +1,4 @@ -# The guardian is responsible for confirming access to various site resources and opreations +# The guardian is responsible for confirming access to various site resources and operations class Guardian attr_reader :user From 9f1c978f114de452c1e6d56d7905221a984277ae Mon Sep 17 00:00:00 2001 From: Charles Oppenheimer Date: Wed, 6 Feb 2013 11:47:39 -0800 Subject: [PATCH 09/23] initial rake db:migrate was failing if hstore was already set --- db/migrate/20120921162512_add_meta_data_to_forum_threads.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/migrate/20120921162512_add_meta_data_to_forum_threads.rb b/db/migrate/20120921162512_add_meta_data_to_forum_threads.rb index 7f313de0f9..9bc65aa1e3 100644 --- a/db/migrate/20120921162512_add_meta_data_to_forum_threads.rb +++ b/db/migrate/20120921162512_add_meta_data_to_forum_threads.rb @@ -1,6 +1,6 @@ class AddMetaDataToForumThreads < ActiveRecord::Migration def change - execute "CREATE EXTENSION hstore" + execute "CREATE EXTENSION IF NOT EXITS hstore" add_column :forum_threads, :meta_data, :hstore end end From f1a3e76d2b5c6466811d3d59a4571d4bf8365ccd Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Wed, 6 Feb 2013 15:29:03 -0500 Subject: [PATCH 10/23] Support for replacing Site Message content with keys specific to a multisite. --- lib/multisite_i18n.rb | 31 +++++++++++++++++++++ lib/system_message.rb | 17 ++++++------ spec/components/multisite_i18n_spec.rb | 37 ++++++++++++++++++++++++++ 3 files changed, 77 insertions(+), 8 deletions(-) create mode 100644 lib/multisite_i18n.rb create mode 100644 spec/components/multisite_i18n_spec.rb diff --git a/lib/multisite_i18n.rb b/lib/multisite_i18n.rb new file mode 100644 index 0000000000..2d59c0c737 --- /dev/null +++ b/lib/multisite_i18n.rb @@ -0,0 +1,31 @@ +# Allow us to override i18n keys based on the current site you're viewing. +module MultisiteI18n + + class << self + + # It would be nice if there was an easier way to detect if a key is missing. + def translation_or_nil(key, opts) + missing_text = "missing multisite translation" + result = I18n.t(key, opts.merge(default: missing_text)) + return nil if result == missing_text + result + end + + def site_translate(current_site, key, opts=nil) + opts ||= {} + translation = MultisiteI18n.translation_or_nil("#{current_site || ""}.#{key}", opts) + if translation.blank? + return I18n.t(key, opts) + else + return translation + end + end + + def t(*args) + MultisiteI18n.site_translate(RailsMultisite::ConnectionManagement.current_db, *args) + end + + alias :translate :t + end + +end diff --git a/lib/system_message.rb b/lib/system_message.rb index 92aaf39903..ed54356f51 100644 --- a/lib/system_message.rb +++ b/lib/system_message.rb @@ -1,5 +1,6 @@ # Handle sending a message to a user from the system. require_dependency 'post_creator' +require_dependency 'multisite_i18n' class SystemMessage @@ -14,20 +15,20 @@ class SystemMessage def create(type, params = {}) defaults = {site_name: SiteSetting.title, - username: @recipient.username, - user_preferences_url: "#{Discourse.base_url}/users/#{@recipient.username_lower}/preferences", - new_user_tips: I18n.t("system_messages.usage_tips.text_body_template"), - site_password: "", - base_url: Discourse.base_url} + username: @recipient.username, + user_preferences_url: "#{Discourse.base_url}/users/#{@recipient.username_lower}/preferences", + new_user_tips: MultisiteI18n.t("system_messages.usage_tips.text_body_template"), + site_password: "", + base_url: Discourse.base_url} params = defaults.merge(params) if SiteSetting.restrict_access? - params[:site_password] = I18n.t('system_messages.site_password', access_password: SiteSetting.access_password) + params[:site_password] = MultisiteI18n.t('system_messages.site_password', access_password: SiteSetting.access_password) end - title = I18n.t("system_messages.#{type}.subject_template", params) - raw_body = I18n.t("system_messages.#{type}.text_body_template", params) + title = MultisiteI18n.t("system_messages.#{type}.subject_template", params) + raw_body = MultisiteI18n.t("system_messages.#{type}.text_body_template", params) PostCreator.create(SystemMessage.system_user, raw: raw_body, diff --git a/spec/components/multisite_i18n_spec.rb b/spec/components/multisite_i18n_spec.rb new file mode 100644 index 0000000000..abdedac99d --- /dev/null +++ b/spec/components/multisite_i18n_spec.rb @@ -0,0 +1,37 @@ +require 'spec_helper' +require_dependency 'multisite_i18n' + +describe MultisiteI18n do + + before do + I18n.stubs(:t).with('test', {}).returns('default i18n') + MultisiteI18n.stubs(:translation_or_nil).with("default.test", {}).returns(nil) + MultisiteI18n.stubs(:translation_or_nil).with("other_site.test", {}).returns("overwritten i18n") + end + + context "no value for a multisite key" do + it "it returns the default i18n key" do + MultisiteI18n.site_translate('default', 'test').should == "default i18n" + end + end + + context "with a value for the multisite key" do + it "returns the overwritten value" do + MultisiteI18n.site_translate('other_site', 'test').should == "overwritten i18n" + end + end + + context "when we call t, it uses the current site" do + + it "returns the original" do + MultisiteI18n.t('test').should == 'default i18n' + end + + it "returns the overwritten" do + RailsMultisite::ConnectionManagement.stubs(:current_db).returns('other_site') + MultisiteI18n.t('test').should == "overwritten i18n" + end + + end + +end \ No newline at end of file From 2d2b907d2c505125462f094e585d489bc2e1f9ce Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Wed, 6 Feb 2013 15:47:36 -0500 Subject: [PATCH 11/23] Temporary Nuclear option on topic titles - disallow non ascii characters so we can stay on top of the trolls. This is meant to be replaced soon with a more permissive and safe method of sanitizing. --- app/models/topic.rb | 16 ++++++++++++++++ config/locales/en.yml | 1 + spec/models/topic_spec.rb | 14 ++++++++++++++ 3 files changed, 31 insertions(+) diff --git a/app/models/topic.rb b/app/models/topic.rb index 13a93a661a..327c910d3d 100644 --- a/app/models/topic.rb +++ b/app/models/topic.rb @@ -24,6 +24,7 @@ class Topic < ActiveRecord::Base serialize :meta_data, ActiveRecord::Coders::Hstore validate :unique_title + validate :nuclear_option belongs_to :category has_many :posts @@ -112,6 +113,21 @@ class Topic < ActiveRecord::Base errors.add(:title, I18n.t(:has_already_been_used)) if finder.exists? end + # This is bad, but people are screwing us on try.discourse.org - soon we'll replace with + # a much more sane validation of odd characters to allow for other languages and such. + def nuclear_option + + # Let presence validation catch it if it's blank + return if title.blank? + + title.each_char do |c| + unless (20..126).include?(c.ord) + errors.add(:title, I18n.t(:invalid_characters)) + return + end + end + end + def new_version_required? return true if title_changed? diff --git a/config/locales/en.yml b/config/locales/en.yml index 4304928806..a86b81ffcb 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -8,6 +8,7 @@ en: too_many_links: "has too many links" just_posted_that: "is too similar to what you recently posted" has_already_been_used: "has already been used" + invalid_characters: "contains invalid characters" activerecord: attributes: diff --git a/spec/models/topic_spec.rb b/spec/models/topic_spec.rb index a65d0350d6..e50030ba00 100644 --- a/spec/models/topic_spec.rb +++ b/spec/models/topic_spec.rb @@ -1,3 +1,5 @@ +# encoding: UTF-8 + require 'spec_helper' describe Topic do @@ -24,6 +26,18 @@ describe Topic do it { should rate_limit } + context 'topic title content' do + + it "allows a regular title with a few ascii characters" do + Fabricate.build(:topic, title: "hello this is my cool topic! welcome: all;").should be_valid + end + + it "doesn't allow non standard ascii" do + Fabricate.build(:topic, title: "Iñtërnâtiônàlizætiøn").should_not be_valid + end + + end + context 'topic title uniqueness' do From c18a23f63c0ab7fc18521bde645d1cf38d36bd45 Mon Sep 17 00:00:00 2001 From: Charles Oppenheimer Date: Wed, 6 Feb 2013 13:37:38 -0800 Subject: [PATCH 12/23] Fixed typo in EXISTS sql --- db/migrate/20120921162512_add_meta_data_to_forum_threads.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/migrate/20120921162512_add_meta_data_to_forum_threads.rb b/db/migrate/20120921162512_add_meta_data_to_forum_threads.rb index 9bc65aa1e3..99d646ae78 100644 --- a/db/migrate/20120921162512_add_meta_data_to_forum_threads.rb +++ b/db/migrate/20120921162512_add_meta_data_to_forum_threads.rb @@ -1,6 +1,6 @@ class AddMetaDataToForumThreads < ActiveRecord::Migration def change - execute "CREATE EXTENSION IF NOT EXITS hstore" + execute "CREATE EXTENSION IF NOT EXISTS hstore" add_column :forum_threads, :meta_data, :hstore end end From 77a924eadc86948d104c7f533f5be5915a94efe3 Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Wed, 6 Feb 2013 17:26:31 -0500 Subject: [PATCH 13/23] Revert "Merge pull request #22 from sandal/patch-1" This reverts commit 0b6b63f24a8a727e37497263a9e4172effc4da95, reversing changes made to e2b99f5d33b6664b8cacd0db78c5c53a6c0412f2. --- AUTHORS.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/AUTHORS.md b/AUTHORS.md index efa85d26dc..7a9c8fec28 100644 --- a/AUTHORS.md +++ b/AUTHORS.md @@ -14,6 +14,6 @@ * Nick Sahler - UI Implementation, supplemental -* Don Petersen - Ruby developer, installation scripts +* Don Petersen - Ruby developmer, installation scripts *For a more detailed list of the many individuals that contributed to the design and development of Discourse outside of GitHub, please refer to the official Discourse website.* From 94e58d733e2114e09567df8e28942756f369b43b Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Wed, 6 Feb 2013 17:36:07 -0500 Subject: [PATCH 14/23] Add moderator style while in topic --- .../javascripts/discourse/templates/post.js.handlebars | 4 ++-- app/assets/stylesheets/application/topic-post.css.scss | 6 ++++++ app/serializers/post_serializer.rb | 5 +++++ 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/app/assets/javascripts/discourse/templates/post.js.handlebars b/app/assets/javascripts/discourse/templates/post.js.handlebars index a485931a86..69cebae745 100644 --- a/app/assets/javascripts/discourse/templates/post.js.handlebars +++ b/app/assets/javascripts/discourse/templates/post.js.handlebars @@ -28,8 +28,8 @@