mirror of
https://github.com/TracksApp/tracks.git
synced 2026-01-06 09:18:50 +01:00
Removed superfluous 'tracks' directory at the root of the repository.
Testing commits to github.
This commit is contained in:
parent
6a42901514
commit
4cbf5a34d3
2269 changed files with 0 additions and 0 deletions
30
lib/activerecord_base_tag_extensions.rb
Normal file
30
lib/activerecord_base_tag_extensions.rb
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
class ActiveRecord::Base
|
||||
# These methods will work for any model instances
|
||||
|
||||
# Tag with deletes all the current tags before adding the new ones
|
||||
# This makes the edit form more intiuitive:
|
||||
# Whatever is in the tags text field is what gets set as the tags for that action
|
||||
# If you submit an empty tags text field, all the tags are removed.
|
||||
def tag_with(tags, user)
|
||||
Tag.transaction do
|
||||
Tagging.delete_all("taggable_id = #{self.id} and taggable_type = '#{self.class}' and user_id = #{user.id}")
|
||||
tags.downcase.split(",").each do |tag|
|
||||
Tag.find_or_create_by_name(tag.strip).on(self, user)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def tag_list
|
||||
tags.map(&:name).join(', ')
|
||||
end
|
||||
|
||||
def delete_tags tag_string
|
||||
split = tag_string.downcase.split(",")
|
||||
tags.delete tags.select{|t| split.include? t.name.strip}
|
||||
end
|
||||
|
||||
def add_tag tag_name
|
||||
Tag.find_or_create_by_name(tag_name.strip).on(self,user)
|
||||
end
|
||||
|
||||
end
|
||||
113
lib/authenticated_test_helper.rb
Normal file
113
lib/authenticated_test_helper.rb
Normal file
|
|
@ -0,0 +1,113 @@
|
|||
module AuthenticatedTestHelper
|
||||
# Sets the current user in the session from the user fixtures.
|
||||
def login_as(user)
|
||||
@request.session['user_id'] = user ? users(user).id : nil
|
||||
end
|
||||
|
||||
def content_type(type)
|
||||
@request.env['Content-Type'] = type
|
||||
end
|
||||
|
||||
def accept(accept)
|
||||
@request.env["HTTP_ACCEPT"] = accept
|
||||
end
|
||||
|
||||
def authorize_as(user)
|
||||
if user
|
||||
@request.env["HTTP_AUTHORIZATION"] = "Basic #{Base64.encode64("#{users(user).login}:test")}"
|
||||
accept 'application/xml'
|
||||
content_type 'application/xml'
|
||||
else
|
||||
@request.env["HTTP_AUTHORIZATION"] = nil
|
||||
accept nil
|
||||
content_type nil
|
||||
end
|
||||
end
|
||||
|
||||
# http://project.ioni.st/post/217#post-217
|
||||
#
|
||||
# def test_new_publication
|
||||
# assert_difference(Publication, :count) do
|
||||
# post :create, :publication => {...}
|
||||
# # ...
|
||||
# end
|
||||
# end
|
||||
#
|
||||
def assert_difference(object, method = nil, difference = 1)
|
||||
initial_value = object.send(method)
|
||||
yield
|
||||
assert_equal initial_value + difference, object.send(method), "#{object}##{method}"
|
||||
end
|
||||
|
||||
def assert_no_difference(object, method, &block)
|
||||
assert_difference object, method, 0, &block
|
||||
end
|
||||
|
||||
# Assert the block redirects to the login
|
||||
#
|
||||
# assert_requires_login(:bob) { |c| c.get :edit, :id => 1 }
|
||||
#
|
||||
def assert_requires_login(login = nil)
|
||||
yield HttpLoginProxy.new(self, login)
|
||||
end
|
||||
|
||||
def assert_http_authentication_required(login = nil)
|
||||
yield XmlLoginProxy.new(self, login)
|
||||
end
|
||||
|
||||
def reset!(*instance_vars)
|
||||
instance_vars = [:controller, :request, :response] unless instance_vars.any?
|
||||
instance_vars.collect! { |v| "@#{v}".to_sym }
|
||||
instance_vars.each do |var|
|
||||
instance_variable_set(var, instance_variable_get(var).class.new)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
class BaseLoginProxy
|
||||
attr_reader :controller
|
||||
attr_reader :options
|
||||
def initialize(controller, login)
|
||||
@controller = controller
|
||||
@login = login
|
||||
end
|
||||
|
||||
private
|
||||
def authenticated
|
||||
raise NotImplementedError
|
||||
end
|
||||
|
||||
def check
|
||||
raise NotImplementedError
|
||||
end
|
||||
|
||||
def method_missing(method, *args)
|
||||
@controller.reset!
|
||||
authenticate
|
||||
@controller.send(method, *args)
|
||||
check
|
||||
end
|
||||
end
|
||||
|
||||
class HttpLoginProxy < BaseLoginProxy
|
||||
protected
|
||||
def authenticate
|
||||
@controller.login_as @login if @login
|
||||
end
|
||||
|
||||
def check
|
||||
@controller.assert_redirected_to :controller => 'account', :action => 'login'
|
||||
end
|
||||
end
|
||||
|
||||
class XmlLoginProxy < BaseLoginProxy
|
||||
protected
|
||||
def authenticate
|
||||
@controller.accept 'application/xml'
|
||||
@controller.authorize_as @login if @login
|
||||
end
|
||||
|
||||
def check
|
||||
@controller.assert_response 401
|
||||
end
|
||||
end
|
||||
20
lib/config.rb
Normal file
20
lib/config.rb
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
module Tracks
|
||||
|
||||
class Config
|
||||
|
||||
def self.salt
|
||||
SALT
|
||||
end
|
||||
|
||||
def self.auth_schemes
|
||||
AUTHENTICATION_SCHEMES
|
||||
end
|
||||
|
||||
def self.openid_enabled?
|
||||
auth_schemes.include?('open_id')
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
197
lib/login_system.rb
Normal file
197
lib/login_system.rb
Normal file
|
|
@ -0,0 +1,197 @@
|
|||
require_dependency "user"
|
||||
|
||||
module LoginSystem
|
||||
|
||||
def current_user
|
||||
get_current_user
|
||||
end
|
||||
|
||||
def prefs
|
||||
current_user.prefs unless current_user.nil?
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
# overwrite this if you want to restrict access to only a few actions
|
||||
# or if you want to check if the user has the correct rights
|
||||
# example:
|
||||
#
|
||||
# # only allow nonbobs
|
||||
# def authorize?(user)
|
||||
# user.login != "bob"
|
||||
# end
|
||||
def authorize?(user)
|
||||
true
|
||||
end
|
||||
|
||||
# overwrite this method if you only want to protect certain actions of the controller
|
||||
# example:
|
||||
#
|
||||
# # don't protect the login and the about method
|
||||
# def protect?(action)
|
||||
# if ['action', 'about'].include?(action)
|
||||
# return false
|
||||
# else
|
||||
# return true
|
||||
# end
|
||||
# end
|
||||
def protect?(action)
|
||||
true
|
||||
end
|
||||
|
||||
# When called with before_filter :login_from_cookie will check for an :auth_token
|
||||
# cookie and log the user back in if appropriate
|
||||
def login_from_cookie
|
||||
return unless cookies[:auth_token] && !logged_in?
|
||||
user = User.find_by_remember_token(cookies[:auth_token])
|
||||
if user && user.remember_token?
|
||||
session['user_id'] = user.id
|
||||
set_current_user(user)
|
||||
current_user.remember_me
|
||||
cookies[:auth_token] = { :value => current_user.remember_token , :expires => current_user.remember_token_expires_at }
|
||||
flash[:notice] = "Logged in successfully. Welcome back!"
|
||||
end
|
||||
end
|
||||
|
||||
def login_or_feed_token_required
|
||||
if ['rss', 'atom', 'txt', 'ics'].include?(params[:format])
|
||||
if user = User.find_by_token(params[:token])
|
||||
set_current_user(user)
|
||||
return true
|
||||
end
|
||||
end
|
||||
login_required
|
||||
end
|
||||
|
||||
# login_required filter. add
|
||||
#
|
||||
# before_filter :login_required
|
||||
#
|
||||
# if the controller should be under any rights management.
|
||||
# for finer access control you can overwrite
|
||||
#
|
||||
# def authorize?(user)
|
||||
#
|
||||
def login_required
|
||||
|
||||
if not protect?(action_name)
|
||||
return true
|
||||
end
|
||||
|
||||
login_from_cookie
|
||||
|
||||
if session['user_id'] and authorize?(get_current_user)
|
||||
return true
|
||||
end
|
||||
|
||||
http_user, http_pass = get_basic_auth_data
|
||||
if user = User.authenticate(http_user, http_pass)
|
||||
session['user_id'] = user.id
|
||||
set_current_user(user)
|
||||
return true
|
||||
end
|
||||
|
||||
# store current location so that we can
|
||||
# come back after the user logged in
|
||||
store_location unless params[:format] == 'js'
|
||||
|
||||
# call overwriteable reaction to unauthorized access
|
||||
access_denied
|
||||
return false
|
||||
end
|
||||
|
||||
def login_optional
|
||||
|
||||
login_from_cookie
|
||||
|
||||
if session['user_id'] and authorize?(get_current_user)
|
||||
return true
|
||||
end
|
||||
|
||||
http_user, http_pass = get_basic_auth_data
|
||||
if user = User.authenticate(http_user, http_pass)
|
||||
session['user_id'] = user.id
|
||||
set_current_user(user)
|
||||
return true
|
||||
end
|
||||
|
||||
return true
|
||||
end
|
||||
|
||||
def logged_in?
|
||||
current_user != nil
|
||||
end
|
||||
|
||||
def get_current_user
|
||||
if @user.nil? && session['user_id']
|
||||
@user = User.find session['user_id'], :include => :preference
|
||||
end
|
||||
@prefs = @user.prefs unless @user.nil?
|
||||
@user
|
||||
end
|
||||
|
||||
def set_current_user(user)
|
||||
@user = user
|
||||
end
|
||||
|
||||
# overwrite if you want to have special behavior in case the user is not authorized
|
||||
# to access the current operation.
|
||||
# the default action is to redirect to the login screen
|
||||
# example use :
|
||||
# a popup window might just close itself for instance
|
||||
def access_denied
|
||||
respond_to do |format|
|
||||
format.html { redirect_to login_path }
|
||||
format.m { redirect_to formatted_login_path(:format => 'm') }
|
||||
format.js { render :partial => 'login/redirect_to_login' }
|
||||
format.xml { basic_auth_denied }
|
||||
format.rss { basic_auth_denied }
|
||||
format.atom { basic_auth_denied }
|
||||
format.text { basic_auth_denied }
|
||||
end
|
||||
end
|
||||
|
||||
# store current uri in the session.
|
||||
# we can return to this location by calling return_location
|
||||
def store_location
|
||||
session['return-to'] = request.request_uri
|
||||
end
|
||||
|
||||
# move to the last store_location call or to the passed default one
|
||||
def redirect_back_or_default(default)
|
||||
if session['return-to'].nil?
|
||||
redirect_to default
|
||||
else
|
||||
redirect_to session['return-to']
|
||||
session['return-to'] = nil
|
||||
end
|
||||
end
|
||||
|
||||
# HTTP Basic auth code adapted from Coda Hale's simple_http_auth plugin. Thanks, Coda!
|
||||
def get_basic_auth_data
|
||||
|
||||
auth_locations = ['REDIRECT_REDIRECT_X_HTTP_AUTHORIZATION',
|
||||
'REDIRECT_X_HTTP_AUTHORIZATION',
|
||||
'X-HTTP_AUTHORIZATION', 'HTTP_AUTHORIZATION']
|
||||
|
||||
authdata = nil
|
||||
for location in auth_locations
|
||||
if request.env.has_key?(location)
|
||||
authdata = request.env[location].to_s.split
|
||||
end
|
||||
end
|
||||
if authdata and authdata[0] == 'Basic'
|
||||
user, pass = Base64.decode64(authdata[1]).split(':')[0..1]
|
||||
else
|
||||
user, pass = ['', '']
|
||||
end
|
||||
return user, pass
|
||||
end
|
||||
|
||||
def basic_auth_denied
|
||||
response.headers["Status"] = "Unauthorized"
|
||||
response.headers["WWW-Authenticate"] = "Basic realm=\"'Tracks Login Required'\""
|
||||
render :text => "401 Unauthorized: You are not authorized to interact with Tracks.", :status => 401
|
||||
end
|
||||
|
||||
end
|
||||
5
lib/name_part_finder.rb
Normal file
5
lib/name_part_finder.rb
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
module NamePartFinder
|
||||
def find_by_namepart(namepart)
|
||||
find_by_name(namepart) || find(:first, :conditions => ["name LIKE ?", namepart + '%'])
|
||||
end
|
||||
end
|
||||
27
lib/prototype_helper_extensions.rb
Normal file
27
lib/prototype_helper_extensions.rb
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
module ActionView
|
||||
module Helpers
|
||||
module PrototypeHelper
|
||||
|
||||
def remote_to_href(options = {})
|
||||
remote_function(options.merge(:url => javascript_variable('this.href'))) + "\n"
|
||||
end
|
||||
|
||||
class JavaScriptGenerator #:nodoc:
|
||||
module GeneratorMethods
|
||||
|
||||
# Executes the content of the block if the user confirms the javascript confirmation. Example:
|
||||
#
|
||||
# page.confirming("Are you sure?") do
|
||||
# page.visual_effect :hide, 'information'
|
||||
# end
|
||||
def confirming(message)
|
||||
message = "'#{message}'" unless message =~ /^['"]/
|
||||
self << "if (confirm(#{message})) {"
|
||||
yield
|
||||
self << "}"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
1113
lib/redcloth.rb
Normal file
1113
lib/redcloth.rb
Normal file
File diff suppressed because it is too large
Load diff
64
lib/source_view.rb
Normal file
64
lib/source_view.rb
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
# Inspiration from Bruce Williams [http://codefluency.com/articles/2006/07/01/rails-views-getting-in-context/]
|
||||
module Tracks
|
||||
|
||||
module SourceViewSwitching
|
||||
|
||||
class Responder
|
||||
|
||||
def initialize(source_view)
|
||||
@source_view = source_view.underscore.gsub(/\s+/,'_').to_sym rescue nil
|
||||
end
|
||||
|
||||
def nil?
|
||||
yield if @source_view.nil? && block_given?
|
||||
end
|
||||
|
||||
def method_missing(check_source_view,*args)
|
||||
yield if check_source_view == @source_view && block_given?
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
module Controller
|
||||
|
||||
def self.included(base)
|
||||
base.send(:helper, Tracks::SourceViewSwitching::Helper)
|
||||
base.send(:helper_method, :source_view)
|
||||
end
|
||||
|
||||
def source_view_is( s )
|
||||
s == (params[:_source_view] || @source_view).to_sym
|
||||
end
|
||||
|
||||
def source_view_is_one_of( *s )
|
||||
s.include?(params[:_source_view].to_sym)
|
||||
end
|
||||
|
||||
def source_view
|
||||
responder = Tracks::SourceViewSwitching::Responder.new(params[:_source_view] || @source_view)
|
||||
block_given? ? yield(responder) : responder
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
module Helper
|
||||
|
||||
def source_view_tag(name)
|
||||
hidden_field_tag :_source_view, name.underscore.gsub(/\s+/,'_')
|
||||
end
|
||||
|
||||
def source_view_is( s )
|
||||
s == (params[:_source_view] || @source_view).to_sym
|
||||
end
|
||||
|
||||
def source_view_is_one_of( *s )
|
||||
s.include?(params[:_source_view].to_sym)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
ActionController::Base.send(:include, Tracks::SourceViewSwitching::Controller)
|
||||
17
lib/tasks/extract_fixtures.rake
Normal file
17
lib/tasks/extract_fixtures.rake
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
desc ' Create YAML test fixtures from data in an existing database.
|
||||
Defaults to development database. Set RAILS_ENV to override (taken from Rails Recipes book).'
|
||||
task :extract_fixtures => :environment do
|
||||
sql = "SELECT * FROM %s"
|
||||
skip_tables = ["schema_info", "sessions", "users"]
|
||||
ActiveRecord::Base.establish_connection
|
||||
(ActiveRecord::Base.connection.tables - skip_tables).each do |table_name|
|
||||
i = "000"
|
||||
File.open("#{RAILS_ROOT}/db/exported_fixtures/#{table_name}.yml", 'w' ) do |file|
|
||||
data = ActiveRecord::Base.connection.select_all(sql % table_name)
|
||||
file.write data.inject({}) { |hash, record|
|
||||
hash["#{table_name}_#{i.succ!}"] = record
|
||||
hash
|
||||
}.to_yaml
|
||||
end
|
||||
end
|
||||
end
|
||||
34
lib/tasks/gems.rake
Normal file
34
lib/tasks/gems.rake
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
desc "Copy third-party gems into ./lib"
|
||||
task :freeze_other_gems do
|
||||
# TODO Get this list from parsing environment.rb
|
||||
libraries = %w(redcloth)
|
||||
require 'rubygems'
|
||||
require 'find'
|
||||
|
||||
libraries.each do |library|
|
||||
library_gem = Gem.cache.search(library).sort_by { |g| g.version }.last
|
||||
puts "Freezing #{library} for #{library_gem.version}..."
|
||||
|
||||
# TODO Add dependencies to list of libraries to freeze
|
||||
#library_gem.dependencies.each { |g| libraries << g }
|
||||
|
||||
folder_for_library = "#{library_gem.name}-#{library_gem.version}"
|
||||
system "cd vendor; gem unpack -v '#{library_gem.version}' #{library_gem.name};"
|
||||
|
||||
# Copy files recursively to ./lib
|
||||
folder_for_library_with_lib = "vendor/#{folder_for_library}/lib/"
|
||||
Find.find(folder_for_library_with_lib) do |original_file|
|
||||
destination_file = "./lib/" + original_file.gsub(folder_for_library_with_lib, '')
|
||||
|
||||
if File.directory?(original_file)
|
||||
if !File.exist?(destination_file)
|
||||
Dir.mkdir destination_file
|
||||
end
|
||||
else
|
||||
File.copy original_file, destination_file
|
||||
end
|
||||
end
|
||||
|
||||
system "rm -r vendor/#{folder_for_library}"
|
||||
end
|
||||
end
|
||||
8
lib/tasks/load_exported_fixtures.rake
Normal file
8
lib/tasks/load_exported_fixtures.rake
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
desc "Load exported fixtures (in db/exported_fixtures) into the current environment's database"
|
||||
task :load_exported_fixtures => :environment do
|
||||
require 'active_record/fixtures'
|
||||
ActiveRecord::Base.establish_connection(RAILS_ENV.to_sym)
|
||||
Dir.glob(File.join(RAILS_ROOT, 'db', 'exported_fixtures', '*.{yml,csv}')).each do |fixture_file|
|
||||
Fixtures.create_fixtures('db/exported_fixtures', File.basename(fixture_file, '.*'))
|
||||
end
|
||||
end
|
||||
50
lib/tasks/query_trace_toggle.rake
Normal file
50
lib/tasks/query_trace_toggle.rake
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
namespace :query_trace do
|
||||
desc "Enables the query_trace plugin. Must restart server to take effect."
|
||||
task :on => :environment do
|
||||
unless File.exist?("#{RAILS_ROOT}/vendor/query_trace.tar.gz")
|
||||
Dir.chdir("#{RAILS_ROOT}/vendor") do
|
||||
url = "https://terralien.devguard.com/svn/projects/plugins/query_trace"
|
||||
puts "Loading query_trace from #{url}..."
|
||||
system "svn co #{url} query_trace"
|
||||
system "tar zcf query_trace.tar.gz --exclude=.svn query_trace"
|
||||
FileUtils.rm_rf("query_trace")
|
||||
end
|
||||
end
|
||||
Dir.chdir("#{RAILS_ROOT}/vendor/plugins") do
|
||||
system "tar zxf ../query_trace.tar.gz query_trace"
|
||||
end
|
||||
puts "QueryTrace plugin enabled. Must restart server to take effect."
|
||||
end
|
||||
|
||||
desc "Disables the query_trace plugin. Must restart server to take effect."
|
||||
task :off => :environment do
|
||||
FileUtils.rm_rf("#{RAILS_ROOT}/vendor/plugins/query_trace")
|
||||
puts "QueryTrace plugin disabled. Must restart server to take effect."
|
||||
end
|
||||
end
|
||||
|
||||
namespace :query_analyzer do
|
||||
desc "Enables the query_analyzer plugin. Must restart server to take effect."
|
||||
task :on => :environment do
|
||||
unless File.exist?("#{RAILS_ROOT}/vendor/query_analyzer.tar.gz")
|
||||
Dir.chdir("#{RAILS_ROOT}/vendor") do
|
||||
url = "http://svn.nfectio.us/plugins/query_analyzer"
|
||||
puts "Loading query_analyzer from #{url}..."
|
||||
system "svn co #{url} query_analyzer"
|
||||
system "tar zcf query_analyzer.tar.gz --exclude=.svn query_analyzer"
|
||||
FileUtils.rm_rf("query_analyzer")
|
||||
end
|
||||
end
|
||||
Dir.chdir("#{RAILS_ROOT}/vendor/plugins") do
|
||||
system "tar zxf ../query_analyzer.tar.gz query_analyzer"
|
||||
end
|
||||
puts "QueryAnalyzer plugin enabled. Must restart server to take effect."
|
||||
end
|
||||
|
||||
desc "Disables the query_analyzer plugin. Must restart server to take effect."
|
||||
task :off => :environment do
|
||||
FileUtils.rm_rf("#{RAILS_ROOT}/vendor/plugins/query_analyzer")
|
||||
puts "QueryAnalyzer plugin disabled. Must restart server to take effect."
|
||||
end
|
||||
end
|
||||
|
||||
25
lib/tasks/reset_password.rake
Normal file
25
lib/tasks/reset_password.rake
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
namespace :tracks do
|
||||
desc 'Replace the password of USER with a new one.'
|
||||
task :password => :environment do
|
||||
|
||||
Dependencies.load_paths.unshift(File.dirname(__FILE__) + "/..../vendor/gems/highline-1.4.0/lib")
|
||||
require "highline/import"
|
||||
|
||||
user = User.find_by_login(ENV['USER'])
|
||||
if user.nil?
|
||||
puts "Sorry, we couldn't find user '#{ENV['USER']}'. To specify a different user, pass USER=username to this task."
|
||||
exit 0
|
||||
end
|
||||
|
||||
puts "Changing Tracks password for #{ENV['USER']}."
|
||||
password = ask("New password: ") { |q| q.echo = false }
|
||||
password_confirmation = ask('Retype new password: ') { |q| q.echo = false }
|
||||
|
||||
begin
|
||||
user.change_password(password, password_confirmation)
|
||||
rescue ActiveRecord::RecordInvalid
|
||||
puts "Sorry, we couldn't change #{ENV['USER']}'s password: "
|
||||
user.errors.each_full { |msg| puts "- #{msg}\n" }
|
||||
end
|
||||
end
|
||||
end
|
||||
15
lib/tasks/setup_tracks.rake
Normal file
15
lib/tasks/setup_tracks.rake
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
desc "Initialises the installation, copy the *.tmpl files and directories to versions named without the .tmpl extension. It won't overwrite the files and directories if you've already copied them. You need to manually copy database.yml.tmpl -> database.yml and fill in the details before you run this task."
|
||||
task :setup_tracks => :environment do
|
||||
# Check the root directory for template files
|
||||
FileList["*.tmpl"].each do |template_file|
|
||||
f = File.basename(template_file) # with suffix
|
||||
f_only = File.basename(template_file,".tmpl") # without suffix
|
||||
if File.exists?(f_only)
|
||||
puts f_only + " already exists"
|
||||
else
|
||||
cp_r(f, f_only)
|
||||
puts f_only + " created"
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
40
lib/tasks/upgrade_sqlite_db.rake
Normal file
40
lib/tasks/upgrade_sqlite_db.rake
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
desc "Updates sqlite/sqlite3 databases created under Tracks 1.03 to the format required for Tracks 1.04. After this is done, you should be able to keep up to date with changes in the schema by running rake db:migrate."
|
||||
task :upgrade_sqlite_db => :environment do
|
||||
# Change the three lines below appropriately for your setup
|
||||
old_db = "tracks_103.db"
|
||||
new_db = "tracks_104.db"
|
||||
cmd = "sqlite3"
|
||||
replace_string = "update todos set done='f' where done=0;\nupdate todos set done='t' where done=1;\nupdate contexts set hide='f' where hide=0;\nupdate contexts set hide='t' where hide=1;\nupdate projects set done='f' where done=0;\nupdate projects set done='t' where done=1;\nCREATE TABLE 'schema_info' (\n 'version' INTEGER default NULL\n);\nINSERT INTO \"schema_info\" VALUES(1);\nCOMMIT;"
|
||||
|
||||
# cd to the db directory
|
||||
cd("db") do
|
||||
# Dump the old db into the temp file and replace the tinyints with booleans
|
||||
`#{cmd} #{old_db} .dump | sed "s/tinyint(4) NOT NULL default '0'/boolean default 'f'/" > temp.sql`
|
||||
# Create a second sqldump file for writing
|
||||
sqldump = File.open("temp2.sql", "w+")
|
||||
File.open("temp.sql") do |file|
|
||||
file.each_line do |line|
|
||||
# If COMMIT is on the line, insert the replace string
|
||||
# else just write the line back in
|
||||
# This effectively replaces COMMIT with the replace string
|
||||
if /COMMIT/ =~ line
|
||||
sqldump.write replace_string
|
||||
else
|
||||
sqldump.write line
|
||||
end
|
||||
end
|
||||
sqldump.close
|
||||
end
|
||||
|
||||
# Read the second dump back in to a new db
|
||||
system "#{cmd} #{new_db} < temp2.sql"
|
||||
puts "Created the a new database called #{new_db}."
|
||||
# Clean up the temp files
|
||||
rm("temp.sql")
|
||||
rm("temp2.sql")
|
||||
puts "Temporary files cleaned up."
|
||||
end
|
||||
|
||||
# rake db:migrate
|
||||
puts "Now check the database and run 'rake db:migrate' in the root of your Tracks installation."
|
||||
end
|
||||
55
lib/todo_list.rb
Normal file
55
lib/todo_list.rb
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
module Tracks
|
||||
module TodoList
|
||||
|
||||
def not_done_todos(opts={})
|
||||
@not_done_todos ||= self.find_not_done_todos(opts)
|
||||
end
|
||||
|
||||
def done_todos
|
||||
@done_todos ||= self.find_done_todos
|
||||
end
|
||||
|
||||
def deferred_todos
|
||||
@deferred_todos ||= self.find_deferred_todos
|
||||
end
|
||||
|
||||
def find_not_done_todos(opts={})
|
||||
with_not_done_scope(opts) do
|
||||
self.todos.find(:all, :order => "todos.due IS NULL, todos.due ASC, todos.created_at ASC")
|
||||
end
|
||||
end
|
||||
|
||||
def find_deferred_todos(opts={})
|
||||
self.todos.find_in_state(:all, :deferred, :order => "todos.due IS NULL, todos.due ASC, todos.created_at ASC")
|
||||
end
|
||||
|
||||
def find_done_todos
|
||||
self.todos.find_in_state(:all, :completed, :order => "todos.completed_at DESC", :limit => self.user.prefs.show_number_completed)
|
||||
end
|
||||
|
||||
def not_done_todo_count(opts={})
|
||||
with_not_done_scope(opts) do
|
||||
self.todos.count
|
||||
end
|
||||
end
|
||||
|
||||
def with_not_done_scope(opts={})
|
||||
conditions = ["todos.state = ?", 'active']
|
||||
if opts.has_key?(:include_project_hidden_todos) && (opts[:include_project_hidden_todos] == true)
|
||||
conditions = ["(todos.state = ? or todos.state = ?)", 'active', 'project_hidden']
|
||||
end
|
||||
self.todos.send :with_scope, :find => {:conditions => conditions} do
|
||||
yield
|
||||
end
|
||||
end
|
||||
|
||||
def done_todo_count
|
||||
self.todos.count_in_state(:completed)
|
||||
end
|
||||
|
||||
def deferred_todo_count
|
||||
self.todos.count_in_state(:deferred)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue