diff --git a/Gemfile b/Gemfile
index f014403c..2fe1dd4a 100644
--- a/Gemfile
+++ b/Gemfile
@@ -17,10 +17,6 @@ gem "sanitize", "~>1.2.1"
gem "will_paginate"
gem "acts_as_list", "~>0.1.4"
gem "aasm", "~>2.2.0"
-# TODO: gem "rubyjedi-actionwebservice", :require => "actionwebservice"
-# gem "rubycas-client", "~>2.2.1"
-# gem "ruby-openid", :require => "openid"
-# gem "open_id_authentication"
gem 'htmlentities', '~> 4.3.0'
gem "mail"
gem "swf_fu"
@@ -60,16 +56,16 @@ gem 'bcrypt-ruby', '~> 3.0.0'
group :development do
if RUBY_VERSION.to_f >= 1.9
-# gem "ruby-debug19", :require => 'ruby-debug'
+ # gem "ruby-debug19", :require => 'ruby-debug'
gem "mongrel", "1.2.0.pre2"
else
-# gem "ruby-debug"
-# gem "mongrel"
+ gem "ruby-debug"
+ gem "mongrel"
end
gem "yard"
end
-#
-# group :test do
+
+group :test do
# gem "test-unit", "1.2.3"
# gem "flexmock"
# gem "ZenTest", ">=4.0.0"
@@ -90,4 +86,4 @@ end
# uncomment to be able to make screenshots from scenarios
#gem "capybara-screenshot"
#gem "launchy"
-# end
+end
diff --git a/app/controllers/contexts_controller.rb b/app/controllers/contexts_controller.rb
index 47f1e33d..7d75fa13 100644
--- a/app/controllers/contexts_controller.rb
+++ b/app/controllers/contexts_controller.rb
@@ -56,13 +56,7 @@ class ContextsController < ApplicationController
end
end
end
-
- # Example XML usage: curl -H 'Accept: application/xml' -H 'Content-Type:
- # application/xml'
- # -u username:password
- # -d 'new context_name'
- # http://our.tracks.host/contexts
- #
+
def create
if params[:format] == 'application/xml' && params['exception']
render_failure "Expected post format is valid xml like so: context name.", 400
@@ -77,7 +71,7 @@ class ContextsController < ApplicationController
end
format.xml do
if @context.new_record?
- render_failure @context.errors.to_xml, 409
+ render_failure @context.errors.to_xml.html_safe, 409
else
head :created, :location => context_url(@context)
end
diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb
index 273c3d0a..711f6dff 100644
--- a/app/controllers/projects_controller.rb
+++ b/app/controllers/projects_controller.rb
@@ -139,15 +139,9 @@ class ProjectsController < ApplicationController
end
end
- # Example XML usage: curl -H 'Accept: application/xml' -H 'Content-Type:
- # application/xml'
- # -u username:password
- # -d 'new project_name'
- # http://our.tracks.host/projects
- #
def create
if params[:format] == 'application/xml' && params['exception']
- render_failure "Expected post format is valid xml like so: project name."
+ render_failure "Expected post format is valid xml like so: project name.", 400
return
end
@project = current_user.projects.build(params['project'])
@@ -161,7 +155,7 @@ class ProjectsController < ApplicationController
format.js { @down_count = current_user.projects.size }
format.xml do
if @project.new_record?
- render_failure @project.errors.full_messages.join(', ')
+ render_failure @project.errors.to_xml.html_safe, 409
else
head :created, :location => project_url(@project), :text => @project.id
end
diff --git a/app/controllers/recurring_todos_controller.rb b/app/controllers/recurring_todos_controller.rb
index 2937bac5..0ec4edd7 100644
--- a/app/controllers/recurring_todos_controller.rb
+++ b/app/controllers/recurring_todos_controller.rb
@@ -161,10 +161,10 @@ class RecurringTodosController < ApplicationController
format.html do
if @saved
- notify :notice, t('todos.recurring_deleted_success'), 2.0
+ notify :notice, t('todos.recurring_deleted_success')
redirect_to :action => 'index'
else
- notify :error, t('todos.error_deleting_recurring', :description => @recurring_todo.description), 2.0
+ notify :error, t('todos.error_deleting_recurring', :description => @recurring_todo.description)
redirect_to :action => 'index'
end
end
diff --git a/app/controllers/stats_controller.rb b/app/controllers/stats_controller.rb
index b1e2b099..227ea004 100644
--- a/app/controllers/stats_controller.rb
+++ b/app/controllers/stats_controller.rb
@@ -106,7 +106,7 @@ class StatsController < ApplicationController
# convert to array and fill in non-existing weeks with 0
@max_weeks = difference_in_weeks(@today, @actions_completion_time.last.completed_at)
@actions_completed_per_week_array = convert_to_weeks_running_array(@actions_completion_time, @max_weeks+1)
-
+
# stop the chart after 10 weeks
@count = [10, @max_weeks].min
@@ -179,7 +179,7 @@ class StatsController < ApplicationController
# cut off chart at 52 weeks = one year
@count = [52, @max_weeks].min
- @actions_open_per_week_array = convert_to_weeks_running_from_today_array(@actions_started, @max_weeks)
+ @actions_open_per_week_array = convert_to_weeks_running_from_today_array(@actions_started, @max_weeks+1)
@actions_open_per_week_array = cut_off_array(@actions_open_per_week_array, @count)
@max_actions = @actions_open_per_week_array.max
@@ -440,7 +440,7 @@ class StatsController < ApplicationController
@pie_height=325
# get the current date wih time set to 0:0
- @today = Time.zone.now.beginning_of_day
+ @today = Time.zone.now.utc.beginning_of_day
# define the number of seconds in a day
@seconds_per_day = 60*60*24
@@ -633,38 +633,33 @@ class StatsController < ApplicationController
return selected_todo_ids
end
- def convert_to_array(hash, upper_bound)
- return Array.new(upper_bound){ |i| hash[i] }
- end
-
# uses the supplied block to determine array of indexes in hash
# the block should return an array of indexes each is added to the hash and summed
- def convert_to_hash(records)
+ def convert_to_array(records, upper_bound)
# use 0 to initialise action count to zero
- hash = Hash.new(0)
- records.each { |r| (yield r).each { |i| hash[i] += 1} }
- return hash
+ a = Array.new(upper_bound){|i| 0 }
+ records.each { |r| (yield r).each { |i| a[i] += 1 } }
+ return a
end
def convert_to_months_from_today_array(records, array_size, date_method_on_todo)
- return convert_to_array(convert_to_hash(records){ |r| [difference_in_months(@today, r.send(date_method_on_todo))]}, array_size)
+ return convert_to_array(records, array_size){ |r| [difference_in_months(@today, r.send(date_method_on_todo))]}
end
def convert_to_days_from_today_array(records, array_size, date_method_on_todo)
- return convert_to_array(convert_to_hash(records){ |r| [difference_in_days(@today, r.send(date_method_on_todo))]}, array_size)
+ return convert_to_array(records, array_size){ |r| [difference_in_days(@today, r.send(date_method_on_todo))]}
end
def convert_to_weeks_from_today_array(records, array_size, date_method_on_todo)
- return convert_to_array(convert_to_hash(records) { |r| [difference_in_weeks(@today, r.send(date_method_on_todo))]}, array_size)
+ return convert_to_array(records, array_size) { |r| [difference_in_weeks(@today, r.send(date_method_on_todo))]}
end
def convert_to_weeks_running_array(records, array_size)
- return convert_to_array(convert_to_hash(records) { |r| [difference_in_weeks(r.completed_at, r.created_at)]}, array_size)
+ return convert_to_array(records, array_size) { |r| [difference_in_weeks(r.completed_at, r.created_at)]}
end
def convert_to_weeks_running_from_today_array(records, array_size)
- hash = convert_to_hash(records) { |r| week_indexes_of(r) }
- return convert_to_array(hash, array_size)
+ return convert_to_array(records, array_size) { |r| week_indexes_of(r) }
end
def week_indexes_of(record)
@@ -698,14 +693,14 @@ class StatsController < ApplicationController
end
# assumes date1 > date2
- # this results in the number of months before the month of date1, not taking days into account, so diff of 31-12 and 1-1 is 1 month!
+ # this results in the number of months before the month of date1, not taking days into account, so diff of 31-dec and 1-jan is 1 month!
def difference_in_months(date1, date2)
- return (date1.year - date2.year)*12 + (date1.month - date2.month)
+ return (date1.utc.year - date2.utc.year)*12 + (date1.utc.month - date2.utc.month)
end
# assumes date1 > date2
def difference_in_days(date1, date2)
- return ((date1.at_midnight-date2.at_midnight)/@seconds_per_day).to_i
+ return ((date1.utc.at_midnight-date2.utc.at_midnight)/@seconds_per_day).to_i
end
# assumes date1 > date2
diff --git a/app/controllers/todos_controller.rb b/app/controllers/todos_controller.rb
index 97cb80a4..d7ec5636 100644
--- a/app/controllers/todos_controller.rb
+++ b/app/controllers/todos_controller.rb
@@ -11,10 +11,6 @@ class TodosController < ApplicationController
protect_from_forgery :except => :check_deferred
- # # these are needed for todo_feed_content. TODO: remove this view stuff from controller
- # include ActionView::Helpers::SanitizeHelper
- # extend ActionView::Helpers::SanitizeHelper::ClassMethods
-
def with_feed_query_scope(&block)
unless TodosController.is_feed_request(request)
Todo.send(:where, ['todos.state = ?', 'active']) do
@@ -143,8 +139,8 @@ class TodosController < ApplicationController
render :action => 'index'
end
format.xml { render :xml => @todos.to_xml( *to_xml_params ) }
- format.rss
- format.atom
+ format.rss { @feed_title, @feed_description = 'Tracks Actions', "Actions for #{current_user.display_name}" }
+ format.atom { @feed_title, @feed_description = 'Tracks Actions', "Actions for #{current_user.display_name}" }
format.text
format.ics
end
@@ -192,7 +188,7 @@ class TodosController < ApplicationController
@todo.project_id = project.id
elsif !(p.project_id.nil? || p.project_id.blank?)
project = current_user.projects.find_by_id(p.project_id)
- @todo.errors.add(:project, "unknown") if project.nil?
+ @todo.errors[:project] << "unknown" if project.nil?
end
if p.context_specified_by_name?
@@ -202,33 +198,26 @@ class TodosController < ApplicationController
@todo.context_id = context.id
elsif !(p.context_id.nil? || p.context_id.blank?)
context = current_user.contexts.find_by_id(p.context_id)
- @todo.errors.add(:context, "unknown") if context.nil?
+ @todo.errors[:context] << "unknown" if context.nil?
end
if @todo.errors.empty?
@todo.starred= (params[:new_todo_starred]||"").include? "true" if params[:new_todo_starred]
-
@todo.add_predecessor_list(predecessor_list)
-
- # Fix for #977 because AASM overrides @state on creation
- specified_state = @todo.state
@saved = @todo.save
-
@todo.update_state_from_project if @saved
else
@saved = false
end
- unless (@saved == false) || tag_list.blank?
+ unless ( !@saved ) || tag_list.blank?
@todo.tag_with(tag_list)
@todo.tags.reload
end
if @saved
- unless @todo.uncompleted_predecessors.empty? || @todo.state == 'project_hidden'
- @todo.state = 'pending'
- end
- @todo.save
+ @todo.block! unless @todo.uncompleted_predecessors.empty? || @todo.state == 'project_hidden'
+ @saved = @todo.save
end
@todo.reload if @saved
@@ -268,7 +257,7 @@ class TodosController < ApplicationController
if @saved
head :created, :location => todo_url(@todo)
else
- render :xml => @todo.errors.to_xml, :status => 422
+ render_failure @todo.errors.to_xml.html_safe, 409
end
end
end
@@ -1424,84 +1413,6 @@ class TodosController < ApplicationController
return !( all_list_uniq_ids.length == all_list_count )
end
- # def render_text_feed
- # lambda do
- # render :action => 'index', :layout => false, :content_type => Mime::TEXT
- # end
- # end
- #
- # def render_ical_feed
- # lambda do
- # render :action => 'index', :layout => false, :content_type => Mime::ICS
- # end
- # end
- #
- # def self.is_feed_request(req)
- # ['rss','atom','txt','ics'].include?(req.parameters[:format])
- # end
- #
- # class FindConditionBuilder
- #
- # def initialize
- # @queries = Array.new
- # @params = Array.new
- # end
- #
- # def add(query, param)
- # @queries << query
- # @params << param
- # end
- #
- # def to_conditions
- # [@queries.join(' AND ')] + @params
- # end
- # end
- # def render_rss_feed
- # lambda do
- # render_rss_feed_for @todos, :feed => todo_feed_options,
- # :item => {
- # :title => :description,
- # :link => lambda { |t| @project_feed.nil? ? context_url(t.context) : project_url(t.project) },
- # :guid => lambda { |t| todo_url(t) },
- # :description => todo_feed_content
- # }
- # end
- # end
- #
- # def todo_feed_options
- # options = Todo.feed_options(current_user)
- # options[:title] = @feed_title
- # return options
- # end
- #
- # def todo_feed_content
- # # TODO: move view stuff into view, also the includes at the top
- # lambda do |i|
- # item_notes = i.rendered_notes if i.notes?
- # due = "
#{t('todos.feeds.due', :date => format_date(i.due))}
\n" if i.due?
- # done = "#{t('todos.feeds.completed', :date => format_date(i.completed_at))}
\n" if i.completed?
- # context_link = "#{ i.context.name }"
- # if i.project_id?
- # project_link = "#{ i.project.name }"
- # else
- # project_link = "#{t('common.none')}"
- # end
- # "#{done||''}#{due||''}#{item_notes||''}\n#{t('common.project')}: #{project_link}
\n#{t('common.context')}: #{context_link}
"
- # end
- # end
- #
- # def render_atom_feed
- # lambda do
- # render_atom_feed_for @todos, :feed => todo_feed_options,
- # :item => {
- # :title => :description,
- # :link => lambda { |t| context_url(t.context) },
- # :description => todo_feed_content,
- # :author => lambda { |p| nil }
- # }
- # end
- # end
-
class TodoCreateParamsHelper
def initialize(params, prefs)
diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb
index 9174dfbc..c0029a9f 100644
--- a/app/controllers/users_controller.rb
+++ b/app/controllers/users_controller.rb
@@ -65,7 +65,7 @@ class UsersController < ApplicationController
# POST /users POST /users.xml
def create
if params['exception']
- render_failure "Expected post format is valid xml like so: usernameabc123."
+ render_failure "Expected post format is valid xml like so: usernameabc123."
return
end
respond_to do |format|
@@ -112,23 +112,21 @@ class UsersController < ApplicationController
return
end
format.xml do
- unless User.find_by_id_and_is_admin(session['user_id'], true)
+ unless current_user && current_user.is_admin
render :text => "401 Unauthorized: Only admin users are allowed access to this function.", :status => 401
return
end
unless check_create_user_params
- render_failure "Expected post format is valid xml like so: usernameabc123."
+ render_failure "Expected post format is valid xml like so: usernameabc123.", 400
return
end
- user = User.new(params[:request])
- if Tracks::Config.auth_schemes.include?('cas') && session[:cas_user]
- user.auth_type = "cas" #if they area cas user
- end
- user.password_confirmation = params[:request][:password]
- if user.save
+ user = User.new(params[:user])
+ user.password_confirmation = params[:user][:password]
+ saved = user.save
+ unless user.new_record?
render :text => t('users.user_created'), :status => 200
else
- render_failure user.errors.to_xml
+ render_failure user.errors.to_xml, 409
end
return
end
@@ -144,9 +142,9 @@ class UsersController < ApplicationController
respond_to do |format|
format.html do
if @saved
- notify :notice, t('users.successfully_deleted_user', :username => @deleted_user.login), 2.0
+ notify :notice, t('users.successfully_deleted_user', :username => @deleted_user.login)
else
- notify :error, t('users.failed_to_delete_user', :username => @deleted_user.login), 2.0
+ notify :error, t('users.failed_to_delete_user', :username => @deleted_user.login)
end
redirect_to users_url
end
@@ -204,11 +202,11 @@ class UsersController < ApplicationController
end
def check_create_user_params
- return false unless params.has_key?(:request)
- return false unless params[:request].has_key?(:login)
- return false if params[:request][:login].empty?
- return false unless params[:request].has_key?(:password)
- return false if params[:request][:password].empty?
+ return false unless params.has_key?(:user)
+ return false unless params[:user].has_key?(:login)
+ return false if params[:user][:login].empty?
+ return false unless params[:user].has_key?(:password)
+ return false if params[:user][:password].empty?
return true
end
diff --git a/app/helpers/todos_helper.rb b/app/helpers/todos_helper.rb
index 6b22deb1..f5be24f0 100644
--- a/app/helpers/todos_helper.rb
+++ b/app/helpers/todos_helper.rb
@@ -473,6 +473,17 @@ module TodosHelper
return $tracks_tab_index
end
+ def feed_content_for_todo(todo)
+ item_notes = todo.notes ? todo.rendered_notes : ''
+ due = todo.due ? content_tag(:div, t('todos.feeds.due', :date => format_date(todo.due))) : ''
+ done = todo.completed? ? content_tag(:div, t('todos.feeds.completed', :date => format_date(todo.completed_at))) : ''
+ context_link = link_to(context_url(todo.context), todo.context.name)
+ project_link = todo.project.is_a?(NullProject) ? content_tag(:em, t('common.none')) : link_to(project_url(todo.project), todo.project.name)
+ return "#{done} #{due} #{item_notes}\n" +
+ content_tag(:div, "#{t('common.project')}: #{project_link}") + "\n" +
+ content_tag(:div, "#{t('common.context')}: #{context_link}")
+ end
+
private
def image_tag_for_star(todo)
diff --git a/app/models/todo.rb b/app/models/todo.rb
index 5682cb8f..47bc1060 100644
--- a/app/models/todo.rb
+++ b/app/models/todo.rb
@@ -246,13 +246,6 @@ class Todo < ActiveRecord::Base
defer! if active? && !date.blank? && date > user.date
end
- def self.feed_options(user)
- {
- :title => 'Tracks Actions',
- :description => "Actions for #{user.display_name}"
- }
- end
-
def starred?
return has_tag?(STARRED_TAG_NAME)
end
diff --git a/app/views/contexts/_context.text.erb b/app/views/contexts/_context.text.erb
new file mode 100644
index 00000000..65767520
--- /dev/null
+++ b/app/views/contexts/_context.text.erb
@@ -0,0 +1,6 @@
+<%
+ todos_in_context = not_done_todos.select { |t| t.context_id == context.id }
+ if todos_in_context.length > 0
+-%> <%= context.name.upcase %>:
+<%= render :partial => "todos/todo", :collection => todos_in_context -%>
+<% end -%>
diff --git a/app/views/contexts/_text_context.rhtml b/app/views/contexts/_text_context.rhtml
deleted file mode 100644
index 84e57a25..00000000
--- a/app/views/contexts/_text_context.rhtml
+++ /dev/null
@@ -1,7 +0,0 @@
-<%
-context = text_context
-todos_in_context = not_done_todos.select { |t| t.context_id == context.id }
-if todos_in_context.length > 0
--%> <%= context.name.upcase %>:
-<%= render :partial => "todos/text_todo", :collection => todos_in_context -%>
-<% end -%>
diff --git a/app/views/todos/_text_todo.rhtml b/app/views/todos/_todo.text.erb
similarity index 95%
rename from app/views/todos/_text_todo.rhtml
rename to app/views/todos/_todo.text.erb
index adc39b91..50cb5a78 100644
--- a/app/views/todos/_text_todo.rhtml
+++ b/app/views/todos/_todo.text.erb
@@ -1,9 +1,7 @@
-<%
+<%
require 'htmlentities'
htmlentities = HTMLEntities.new
-todo = text_todo
-
if (todo.starred?)
result_string = " * "
else
@@ -23,6 +21,6 @@ end
unless todo.project.nil?
result_string << "(" + todo.project.name + ")"
-end
+end
-%><%= result_string -%>
diff --git a/app/views/todos/index.atom.builder b/app/views/todos/index.atom.builder
new file mode 100644
index 00000000..6c49ba80
--- /dev/null
+++ b/app/views/todos/index.atom.builder
@@ -0,0 +1,13 @@
+atom_feed do |feed|
+ feed.title(@feed_title)
+ feed.subtitle(@feed_description)
+ feed.updated(@todos.last.updated_at)
+
+ @todos.each do |todo|
+ feed.entry(todo) do |entry|
+ entry.title(h(todo.description))
+ entry.link(todo.project ? project_url(todo.project) : context_url(todo.context))
+ entry.content(feed_content_for_todo(todo), :type => :html)
+ end
+ end
+end
\ No newline at end of file
diff --git a/app/views/todos/index.rss.builder b/app/views/todos/index.rss.builder
new file mode 100644
index 00000000..423239a5
--- /dev/null
+++ b/app/views/todos/index.rss.builder
@@ -0,0 +1,20 @@
+xml.instruct! :xml, :version => "1.0"
+xml.rss :version => "2.0" do
+ xml.channel do
+ xml.title @feed_title
+ xml.description @feed_description
+ xml.link todos_url
+ xml.language 'en-us'
+ xml.ttl 40
+
+ @todos.each do |todo|
+ xml.item do
+ xml.title h(todo.description)
+ xml.description feed_content_for_todo(todo)
+ xml.pubDate todo.created_at.to_s(:rfc822)
+ xml.link todo.project ? project_url(todo.project) : context_url(todo.context)
+ xml.guid todo_url(todo)
+ end
+ end
+ end
+end
\ No newline at end of file
diff --git a/app/views/todos/index.text.erb b/app/views/todos/index.text.erb
index 194cd44d..6b7eced1 100644
--- a/app/views/todos/index.text.erb
+++ b/app/views/todos/index.text.erb
@@ -1 +1 @@
-<%= render :partial => "contexts/text_context", :collection => @contexts, :locals => { :todos => @todos, :not_done_todos => @not_done_todos } %>
+<%= render :partial => @contexts, :locals => { :todos => @todos, :not_done_todos => @not_done_todos } %>
diff --git a/app/views/users/new.html.erb b/app/views/users/new.html.erb
index 47e1e783..715d6fb0 100644
--- a/app/views/users/new.html.erb
+++ b/app/views/users/new.html.erb
@@ -1,7 +1,7 @@