fixes rich_api to handle contexts that contain @ like @home

git-svn-id: http://www.rousette.org.uk/svn/tracks-repos/trunk@702 a4c988fc-2ded-0310-b66e-134b36920a42
This commit is contained in:
lrbalt 2008-01-25 20:39:44 +00:00
parent 327b2e11eb
commit a9a05289ec

View file

@ -57,40 +57,48 @@ class BackendController < ApplicationController
private
# Check whether the token in the URL matches the token in the User's table
def check_token(username, token)
@user = User.find_by_login( username )
unless (token == @user.token)
raise(InvalidToken, "Sorry, you don't have permission to perform this action.")
end
# Check whether the token in the URL matches the token in the User's table
def check_token(username, token)
@user = User.find_by_login( username )
unless (token == @user.token)
raise(InvalidToken, "Sorry, you don't have permission to perform this action.")
end
end
def check_context_belongs_to_user(context_id)
unless @user.contexts.exists? context_id
raise(CannotAccessContext, "Cannot access a context that does not belong to this user.")
end
def check_context_belongs_to_user(context_id)
unless @user.contexts.exists? context_id
raise(CannotAccessContext, "Cannot access a context that does not belong to this user.")
end
end
def create_todo(description, context_id, project_id = nil, notes="")
item = @user.todos.build
item.description = description
item.notes = notes
item.context_id = context_id
item.project_id = project_id unless project_id.nil?
item.save
raise item.errors.full_messages.to_s if item.new_record?
item
end
def create_todo(description, context_id, project_id = nil, notes="")
item = @user.todos.build
item.description = description
item.notes = notes
item.context_id = context_id
item.project_id = project_id unless project_id.nil?
item.save
raise item.errors.full_messages.to_s if item.new_record?
item
end
def split_by_char(separator,string)
parts = string.split(separator)
return safe_strip(parts[0]), safe_strip(parts[1])
def split_by_char(separator,string)
parts = string.split(separator)
# if the separator is used more than once, concat the last parts this is
# needed to get 'description @ @home > project' working for contexts
# starting with @
if parts.length > 2
2.upto(parts.length-1) { |i| parts[1] += parts[i] }
end
return safe_strip(parts[0]), safe_strip(parts[1])
end
def safe_strip(s)
s.strip! unless s.nil?
s
end
def safe_strip(s)
s.strip! unless s.nil?
s
end
end
class InvalidToken < RuntimeError; end