summaryrefslogtreecommitdiff
path: root/config/initializers
diff options
context:
space:
mode:
Diffstat (limited to 'config/initializers')
-rw-r--r--config/initializers/leaguer_firefox_submit_hack.rb34
-rw-r--r--config/initializers/leaguer_html5_autovalidation.rb107
-rw-r--r--config/initializers/mailboxer.rb2
-rw-r--r--config/initializers/permissions_system.rb11
-rw-r--r--config/initializers/secret_token.rb6
5 files changed, 158 insertions, 2 deletions
diff --git a/config/initializers/leaguer_firefox_submit_hack.rb b/config/initializers/leaguer_firefox_submit_hack.rb
new file mode 100644
index 0000000..2120379
--- /dev/null
+++ b/config/initializers/leaguer_firefox_submit_hack.rb
@@ -0,0 +1,34 @@
+# -*- ruby-indent-level: 2; indent-tabs-mode: nil -*-
+# This hacks around <input type="submit"> being sized weird by replacing it with <button type="submit">
+# This was nescessary in FF28, no longer in FF30.
+# I have no idea about Chrome or Safari; I imagine browsers are converging on making it sized sanely.
+module ActionView
+ module Helpers
+ module FormTagHelper
+
+ # This is modified from actionpack-4.0.2/lib/action_view/helpers/form_tag_helper.rb#submit_tag
+ def submit_tag(value = "Save changes", options = {})
+ options = options.stringify_keys
+
+ if disable_with = options.delete("disable_with")
+ message = ":disable_with option is deprecated and will be removed from Rails 4.1. " \
+ "Use 'data: { disable_with: \'Text\' }' instead."
+ ActiveSupport::Deprecation.warn message
+
+ options["data-disable-with"] = disable_with
+ end
+
+ if confirm = options.delete("confirm")
+ message = ":confirm option is deprecated and will be removed from Rails 4.1. " \
+ "Use 'data: { confirm: \'Text\' }' instead'."
+ ActiveSupport::Deprecation.warn message
+
+ options["data-confirm"] = confirm
+ end
+
+ content_tag(:button, value, { "type" => "submit", "name" => "commit", "value" => value }.update(options))
+ end
+
+ end
+ end
+end
diff --git a/config/initializers/leaguer_html5_autovalidation.rb b/config/initializers/leaguer_html5_autovalidation.rb
new file mode 100644
index 0000000..82f630e
--- /dev/null
+++ b/config/initializers/leaguer_html5_autovalidation.rb
@@ -0,0 +1,107 @@
+module ActionView
+ module Helpers
+ module Tags
+ class Base
+ def initialize_with_html5_validators(object_name, method_name, template_object, options = {})
+ initialize_without_html5_validators(object_name, method_name, template_object, options)
+
+ if /(Area|Button|Box|Field|Select)$/ =~ self.class.name and @object.respond_to? :_validators
+ inject_html5_validators(@object._validators[@method_name.to_sym])
+ if @method_name.to_s.end_with?("_confirmation")
+ orig_method_name = @method_name.to_s.sub(/_confirmation$/,'').to_sym
+ if @object._validators[orig_method_name].any?{|v|v.is_a?(ActiveModel::Validations::ConfirmationValidator)}
+ inject_html5_validators(@object._validators[orig_method_name])
+ end
+ end
+ end
+ end
+ alias_method_chain :initialize, :html5_validators
+
+ private
+
+ def inject_html5_validators(validators = [])
+ validators.each do |v|
+ # XXX: evaluate :if/:unless?
+ if (v.options.keys & [:if, :unless]).empty?
+ case v
+ when ActiveModel::Validations::AbsenceValidator
+ # The opposite of required
+ # XXX: perhaps disable the input?
+ when ActiveModel::Validations::AcceptanceValidator
+ # XXX: If in a text-ish input, perhaps create a pattern from :accept?
+ @options[:required] = :required
+ when ActiveRecord::Validations::AssociatedValidator
+ # Can't possibly do anything here
+ when ActiveModel::Validations::ConfirmationValidator
+ # Do nothing here
+ when ActiveModel::Validations::ExclusionValidator
+ # XXX: There is no simple way to do this.
+ when ActiveModel::Validations::FormatValidator
+ # XXX: Does not support :without
+ if v.options[:with] and not v.options[:with].is_a?(Proc)
+ pattern = v.options[:with].source.sub(/^\\A/,'').sub(/\\[Zz]$/,'')
+ pattern = "(|#{pattern})" if (v.options[:allow_nil] or v.options[:allow_blank])
+ @options[:pattern] = pattern
+ end
+ when ActiveModel::Validations::InclusionValidator
+ # XXX: There is no simple way to do this.
+ when ActiveModel::Validations::LengthValidator
+ @options[:minlength] = v.options[:minimum] if v.options[:minimum]
+ @options[:maxlength] = v.options[:maximum] if v.options[:maximum]
+ when ActiveModel::Validations::NumericalityValidator
+ # XXX: Does not support :other_than
+ # XXX: Does not correctly handle any of these things being a Proc
+ @options[:required] = :required unless v.options[:allow_nil]
+ @options[:step] = 1 if v.options[:only_integer]
+
+ if v.options[:greater_than]
+ if @options[:step] or v.options[:even] or v.options[:odd]
+ @options[:min] = v.options[:greater_than] + 1
+ else
+ # Floating point limit BS
+ @options[:min] = v.options[:greater_than]
+ end
+ end
+ if v.options[:greater_than_or_equal_to]
+ @options[:min] = v.options[:greater_than_or_equal_to]
+ end
+
+ if v.options[:less_than]
+ if @options[:step] or v.options[:even] or v.options[:odd]
+ @options[:max] = v.options[:less_than] - 1
+ else
+ # Floating point limit BS
+ @options[:max] = v.options[:less_than]
+ end
+ end
+ if v.options[:less_than_or_equal_to]
+ @options[:max] = v.options[:less_than_or_equal_to]
+ end
+
+ if v.options[:equal_to]
+ @options[:min] = @options[:max] = v.options[:equal_to]
+ end
+
+ if v.options[:even] and @options[:min]
+ @options[:min] = @options[:min] + @options[:min] % 2
+ @options[:step] = 2
+ end
+ if v.options[:odd] and @options[:min]
+ @options[:min] = @options[:min] + (@options[:min]+1) % 2
+ @options[:step] = 2
+ end
+ when ActiveModel::Validations::PresenceValidator, ActiveRecord::Validations::PresenceValidator
+ @options[:required] = :required
+ when ActiveRecord::Validations::UniquenessValidator
+ # Can't do this without making network calls
+ when ActiveModel::Validations::WithValidator
+ # Just here for completeness; can't possibly do anything
+ end # case
+ end # if
+ end # each
+ end # def
+ end # class Base
+ end # module Tags
+ end # module Helpers
+end # module ActionView
+
diff --git a/config/initializers/mailboxer.rb b/config/initializers/mailboxer.rb
index 8876f80..b529481 100644
--- a/config/initializers/mailboxer.rb
+++ b/config/initializers/mailboxer.rb
@@ -1,7 +1,7 @@
Mailboxer.setup do |config|
#Configures if you applications uses or no the email sending for Notifications and Messages
- config.uses_emails = true
+ config.uses_emails = false
#Configures the default from for the email sent for Messages and Notifications of Mailboxer
config.default_from = "no-reply@mailboxer.com"
diff --git a/config/initializers/permissions_system.rb b/config/initializers/permissions_system.rb
new file mode 100644
index 0000000..9d1de9f
--- /dev/null
+++ b/config/initializers/permissions_system.rb
@@ -0,0 +1,11 @@
+module ActiveRecord
+ class Base
+ def check_permission(user, verb)
+ user.can?("#{verb.to_s}_#{self.class.name.underscore}".to_sym) or self.owned_by?(user)
+ end
+
+ def owned_by?(user)
+ return false
+ end
+ end
+end
diff --git a/config/initializers/secret_token.rb b/config/initializers/secret_token.rb
index 604d43d..fbab4b9 100644
--- a/config/initializers/secret_token.rb
+++ b/config/initializers/secret_token.rb
@@ -9,4 +9,8 @@
# Make sure your secret_key_base is kept private
# if you're sharing your code publicly.
-Leaguer::Application.config.secret_key_base = 'cc884af613d0dd093f1d6c9153abac1200c5a0db923613245b80c5c3f5e9c9f9ba51712b702f2d494a22ddea8ab40601b38a41eb39eec97b50a7a2e37748b1bc'
+Leaguer::Application.config.secret_key_base = if Rails.env.development? or Rails.env.test?
+ ('x' * 30) # meets minimum requirement of 30 chars long
+else
+ ENV['SECRET_TOKEN']
+end