mirror of
https://github.com/TracksApp/tracks.git
synced 2026-04-18 10:09:02 +02:00
all unit and functional tests are passing
This commit is contained in:
parent
96db48dd86
commit
13b58f3a10
40 changed files with 1107 additions and 1494 deletions
|
|
@ -1,37 +1,25 @@
|
|||
class MessageGateway < ActionMailer::Base
|
||||
# include ActionView::Helpers::SanitizeHelper
|
||||
# extend ActionView::Helpers::SanitizeHelper::ClassMethods
|
||||
include ActionView::Helpers::SanitizeHelper
|
||||
extend ActionView::Helpers::SanitizeHelper::ClassMethods
|
||||
|
||||
def receive(email)
|
||||
puts "email = #{email}"
|
||||
address = ''
|
||||
if SITE_CONFIG['email_dispatch'] == 'to'
|
||||
address = email.to[0]
|
||||
else
|
||||
address = email.from[0]
|
||||
end
|
||||
|
||||
user = User.where("preferences.sms_email" => address.strip).first(:include => [:preference])
|
||||
if user.nil?
|
||||
user = User.where("preferences.sms_email" => address.strip[1.100]).first(:include => [:preference])
|
||||
end
|
||||
user = get_user_from_email_address(email)
|
||||
return if user.nil?
|
||||
|
||||
context = user.prefs.sms_context
|
||||
|
||||
description = nil
|
||||
notes = nil
|
||||
|
||||
if email.content_type == "multipart/related"
|
||||
description = sanitize email.subject
|
||||
body_part = email.parts.find{|m| m.content_type == "text/plain"}
|
||||
notes = sanitize body_part.body.strip
|
||||
|
||||
if email.multipart?
|
||||
description = get_text_or_nil(email.subject)
|
||||
notes = get_first_text_plain_part(email)
|
||||
else
|
||||
if email.subject && email.subject.blank?
|
||||
description = sanitize email.body.strip
|
||||
if email.subject.blank?
|
||||
description = get_decoded_text_or_nil(email.body)
|
||||
notes = nil
|
||||
else
|
||||
description = sanitize email.subject.strip
|
||||
notes = sanitize email.body.strip
|
||||
description = get_text_or_nil(email.subject)
|
||||
notes = get_decoded_text_or_nil(email.body)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -41,4 +29,33 @@ class MessageGateway < ActionMailer::Base
|
|||
todo = Todo.from_rich_message(user, context.id, description, notes)
|
||||
todo.save!
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def get_address(email)
|
||||
return SITE_CONFIG['email_dispatch'] == 'to' ? email.to[0] : email.from[0]
|
||||
end
|
||||
|
||||
def get_user_from_email_address(email)
|
||||
address = get_address(email)
|
||||
user = User.where("preferences.sms_email" => address.strip).includes(:preference).first
|
||||
if user.nil?
|
||||
user = User.where("preferences.sms_email" => address.strip[1.100]).includes(:preference).first
|
||||
end
|
||||
return user
|
||||
end
|
||||
|
||||
def get_text_or_nil(text)
|
||||
return text ? sanitize(text.strip) : nil
|
||||
end
|
||||
|
||||
def get_decoded_text_or_nil(text)
|
||||
return text ? sanitize(text.decoded.strip) : nil
|
||||
end
|
||||
|
||||
def get_first_text_plain_part(email)
|
||||
parts = email.parts.reject{|part| !part.content_type.start_with?("text/plain") }
|
||||
return parts ? sanitize(parts[0].decoded.strip) : ""
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ class Preference < ActiveRecord::Base
|
|||
belongs_to :sms_context, :class_name => 'Context'
|
||||
|
||||
attr_accessible :date_format, :week_starts, :show_number_completed, :show_completed_projects_in_sidebar,
|
||||
:show_hidden_contexts_in_sidebar, :staleness_starts, :due_style, :admin_email
|
||||
:show_hidden_contexts_in_sidebar, :staleness_starts, :due_style, :admin_email, :locale
|
||||
|
||||
def self.due_styles
|
||||
{ :due_in_n_days => 0, :due_on => 1}
|
||||
|
|
|
|||
|
|
@ -51,30 +51,30 @@ class RecurringTodo < ActiveRecord::Base
|
|||
|
||||
def validate_daily
|
||||
if (!only_work_days) && (daily_every_x_days.nil? || daily_every_x_days.blank?)
|
||||
errors.add_to_base("Every other nth day may not be empty for recurrence setting")
|
||||
errors[:base] << "Every other nth day may not be empty for recurrence setting"
|
||||
end
|
||||
end
|
||||
|
||||
def validate_weekly
|
||||
if weekly_every_x_week.nil? || weekly_every_x_week.blank?
|
||||
errors.add_to_base("Every other nth week may not be empty for recurrence setting")
|
||||
errors[:base] << "Every other nth week may not be empty for recurrence setting"
|
||||
end
|
||||
something_set = false
|
||||
%w{sunday monday tuesday wednesday thursday friday saturday}.each do |day|
|
||||
something_set ||= self.send("on_#{day}")
|
||||
end
|
||||
errors.add_to_base("You must specify at least one day on which the todo recurs") if !something_set
|
||||
errors[:base] << "You must specify at least one day on which the todo recurs" if !something_set
|
||||
end
|
||||
|
||||
def validate_monthly
|
||||
case recurrence_selector
|
||||
when 0 # 'monthly_every_x_day'
|
||||
errors.add_to_base("The day of the month may not be empty for recurrence setting") if monthly_every_x_day.nil? || monthly_every_x_day.blank?
|
||||
errors.add_to_base("Every other nth month may not be empty for recurrence setting") if monthly_every_x_month.nil? || monthly_every_x_month.blank?
|
||||
errors[:base] << "The day of the month may not be empty for recurrence setting" if monthly_every_x_day.nil? || monthly_every_x_day.blank?
|
||||
errors[:base] << "Every other nth month may not be empty for recurrence setting" if monthly_every_x_month.nil? || monthly_every_x_month.blank?
|
||||
when 1 # 'monthly_every_xth_day'
|
||||
errors.add_to_base("Every other nth month may not be empty for recurrence setting") if monthly_every_x_month2.nil? || monthly_every_x_month2.blank?
|
||||
errors.add_to_base("The nth day of the month may not be empty for recurrence setting") if monthly_every_xth_day.nil? || monthly_every_xth_day.blank?
|
||||
errors.add_to_base("The day of the month may not be empty for recurrence setting") if monthly_day_of_week.nil? || monthly_day_of_week.blank?
|
||||
errors[:base] <<"Every other nth month may not be empty for recurrence setting" if monthly_every_x_month2.nil? || monthly_every_x_month2.blank?
|
||||
errors[:base] <<"The nth day of the month may not be empty for recurrence setting" if monthly_every_xth_day.nil? || monthly_every_xth_day.blank?
|
||||
errors[:base] <<"The day of the month may not be empty for recurrence setting" if monthly_day_of_week.nil? || monthly_day_of_week.blank?
|
||||
else
|
||||
raise Exception.new, "unexpected value of recurrence selector '#{self.recurrence_selector}'"
|
||||
end
|
||||
|
|
@ -83,26 +83,26 @@ class RecurringTodo < ActiveRecord::Base
|
|||
def validate_yearly
|
||||
case recurrence_selector
|
||||
when 0 # 'yearly_every_x_day'
|
||||
errors.add_to_base("The month of the year may not be empty for recurrence setting") if yearly_month_of_year.nil? || yearly_month_of_year.blank?
|
||||
errors.add_to_base("The day of the month may not be empty for recurrence setting") if yearly_every_x_day.nil? || yearly_every_x_day.blank?
|
||||
errors[:base] << "The month of the year may not be empty for recurrence setting" if yearly_month_of_year.nil? || yearly_month_of_year.blank?
|
||||
errors[:base] << "The day of the month may not be empty for recurrence setting" if yearly_every_x_day.nil? || yearly_every_x_day.blank?
|
||||
when 1 # 'yearly_every_xth_day'
|
||||
errors.add_to_base("The month of the year may not be empty for recurrence setting") if yearly_month_of_year2.nil? || yearly_month_of_year2.blank?
|
||||
errors.add_to_base("The nth day of the month may not be empty for recurrence setting") if yearly_every_xth_day.nil? || yearly_every_xth_day.blank?
|
||||
errors.add_to_base("The day of the week may not be empty for recurrence setting") if yearly_day_of_week.nil? || yearly_day_of_week.blank?
|
||||
errors[:base] << "The month of the year may not be empty for recurrence setting" if yearly_month_of_year2.nil? || yearly_month_of_year2.blank?
|
||||
errors[:base] << "The nth day of the month may not be empty for recurrence setting" if yearly_every_xth_day.nil? || yearly_every_xth_day.blank?
|
||||
errors[:base] << "The day of the week may not be empty for recurrence setting" if yearly_day_of_week.nil? || yearly_day_of_week.blank?
|
||||
else
|
||||
raise Exception.new, "unexpected value of recurrence selector '#{self.recurrence_selector}'"
|
||||
end
|
||||
end
|
||||
|
||||
def starts_and_ends_on_validations
|
||||
errors.add_to_base("The start date needs to be filled in") if start_from.nil? || start_from.blank?
|
||||
errors[:base] << "The start date needs to be filled in" if start_from.nil? || start_from.blank?
|
||||
case self.ends_on
|
||||
when 'ends_on_number_of_times'
|
||||
errors.add_to_base("The number of recurrences needs to be filled in for 'Ends on'") if number_of_occurences.nil? || number_of_occurences.blank?
|
||||
errors[:base] << "The number of recurrences needs to be filled in for 'Ends on'" if number_of_occurences.nil? || number_of_occurences.blank?
|
||||
when "ends_on_end_date"
|
||||
errors.add_to_base("The end date needs to be filled in for 'Ends on'") if end_date.nil? || end_date.blank?
|
||||
errors[:base] << "The end date needs to be filled in for 'Ends on'" if end_date.nil? || end_date.blank?
|
||||
else
|
||||
errors.add_to_base("The end of the recurrence is not selected") unless ends_on == "no_end_date"
|
||||
errors[:base] << "The end of the recurrence is not selected" unless ends_on == "no_end_date"
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -112,9 +112,9 @@ class RecurringTodo < ActiveRecord::Base
|
|||
when 'show_from_date'
|
||||
# no validations
|
||||
when 'due_date'
|
||||
errors.add_to_base("Please select when to show the action") if show_always.nil?
|
||||
errors[:base] << "Please select when to show the action" if show_always.nil?
|
||||
unless show_always
|
||||
errors.add_to_base("Please fill in the number of days to show the todo before the due date") if show_from_delta.nil? || show_from_delta.blank?
|
||||
errors[:base] << "Please fill in the number of days to show the todo before the due date" if show_from_delta.nil? || show_from_delta.blank?
|
||||
end
|
||||
else
|
||||
raise Exception.new, "unexpected value of recurrence target selector '#{self.recurrence_target}'"
|
||||
|
|
|
|||
|
|
@ -372,9 +372,9 @@ class Todo < ActiveRecord::Base
|
|||
|
||||
context_id = default_context_id
|
||||
unless(context.nil?)
|
||||
found_context = user.contexts.active.find_by_namepart(context)
|
||||
found_context = user.contexts.find_by_namepart(context) if found_context.nil?
|
||||
context_id = found_context.id unless found_context.nil?
|
||||
found_context = user.contexts.active.where("name like ?", "%#{context}%").first
|
||||
found_context = user.contexts.where("name like ?", "%#{context}%").first if !found_context
|
||||
context_id = found_context.id if found_context
|
||||
end
|
||||
|
||||
unless user.contexts.exists? context_id
|
||||
|
|
|
|||
|
|
@ -5,6 +5,11 @@ class User < ActiveRecord::Base
|
|||
# Virtual attribute for the unencrypted password
|
||||
attr_accessor :password
|
||||
attr_protected :is_admin # don't allow mass-assignment for this
|
||||
|
||||
attr_accessible :login, :first_name, :last_name, :password_confirmation, :password, :auth_type, :open_id_url
|
||||
#for will_paginate plugin
|
||||
cattr_accessor :per_page
|
||||
@@per_page = 5
|
||||
|
||||
has_many :contexts,
|
||||
:order => 'position ASC',
|
||||
|
|
@ -91,8 +96,6 @@ class User < ActiveRecord::Base
|
|||
has_many :notes, :order => "created_at DESC", :dependent => :delete_all
|
||||
has_one :preference, :dependent => :destroy
|
||||
|
||||
attr_protected :is_admin
|
||||
|
||||
validates_presence_of :login
|
||||
validates_presence_of :password, :if => :password_required?
|
||||
validates_length_of :password, :within => 5..40, :if => :password_required?
|
||||
|
|
@ -105,10 +108,6 @@ class User < ActiveRecord::Base
|
|||
before_create :crypt_password, :generate_token
|
||||
before_update :crypt_password
|
||||
|
||||
#for will_paginate plugin
|
||||
cattr_accessor :per_page
|
||||
@@per_page = 5
|
||||
|
||||
def validate_auth_type
|
||||
unless Tracks::Config.auth_schemes.include?(auth_type)
|
||||
errors.add("auth_type", "not a valid authentication type (#{auth_type})")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue