diff --git a/tracks/app/controllers/application.rb b/tracks/app/controllers/application.rb index c3f41ad1..c6f2f491 100644 --- a/tracks/app/controllers/application.rb +++ b/tracks/app/controllers/application.rb @@ -13,5 +13,14 @@ class ApplicationController < ActionController::Base helper :application include LoginSystem + + def count_shown_items(hidden) + count = 0 + sub = 0 + hidden.each do |h| + sub = Todo.find_all("done=0 AND context_id=#{h.id}").length + sub + end + total = Todo.find_all("done=0").length - sub + end end \ No newline at end of file diff --git a/tracks/app/controllers/feed_controller.rb b/tracks/app/controllers/feed_controller.rb index aa29c14f..28cabaf7 100644 --- a/tracks/app/controllers/feed_controller.rb +++ b/tracks/app/controllers/feed_controller.rb @@ -4,7 +4,6 @@ class FeedController < ApplicationController helper :feed model :todo, :context, :project - before_filter :login_required def index end @@ -14,21 +13,39 @@ class FeedController < ApplicationController # and the item context as the description # def na_feed - @not_done = Todo.find_all( "done=0", "created DESC" ) - @headers["Content-Type"] = "text/xml; charset=utf-8" + # Check whether the token in the URL matches the word in the User's table + # Render the RSS feed if it is, or show an error message if not + @token = @params['token'] + @user_name = @params['name'] + @current_user = User.find_by_login(@user_name) + if (@token == @current_user.word && @user_name == @current_user.login) + @not_done = Todo.find_all( "done=0", "created DESC" ) + @headers["Content-Type"] = "text/xml; charset=utf-8" + else + render_text "Sorry, you don't have permission to view this page." + end end # Builds a plain text page listing all the next actions, - # sorted by context. Showing notes doesn' make much sense here + # sorted by context. Showing notes doesn't make much sense here # so they are omitted. You can use this with GeekTool to get your next actions # on the desktop: - # curl http://url_for_the_app/feed/na_text + # curl [url from "TXT" link on todo/list] # def na_text - @places = Context.find_all - @projects = Project.find_all - @not_done = Todo.find_all( "done=0", "context_id ASC" ) - @headers["Content-Type"] = "text/plain; charset=utf-8" + # Check whether the token in the URL matches the word in the User's table + # Render the text file if it is, or show an error message if not + @token = @params['token'] + @user_name = @params['name'] + @current_user = User.find_by_login(@user_name) + if (@token == @current_user.word && @user_name == @current_user.login) + @places = Context.find_all + @projects = Project.find_all + @not_done = Todo.find_all( "done=0", "context_id ASC" ) + @headers["Content-Type"] = "text/plain; charset=utf-8" + else + render_text "Sorry, you don't have permission to view this page." + end end end diff --git a/tracks/app/controllers/todo_controller.rb b/tracks/app/controllers/todo_controller.rb index 4c017f98..fbf6df13 100644 --- a/tracks/app/controllers/todo_controller.rb +++ b/tracks/app/controllers/todo_controller.rb @@ -19,12 +19,7 @@ class TodoController < ApplicationController @done = Todo.find_all_by_done( 1, "completed DESC", 5 ) # Set count badge to number of not-done, not hidden context items - count = 0 - sub = 0 - @hidden_places.each do |h| - sub = Todo.find_all("done=0 AND context_id=#{h.id}").length + sub - end - @count = Todo.find_all("done=0").length - sub + @count = count_shown_items(@hidden_places) end diff --git a/tracks/app/views/layouts/standard.rhtml b/tracks/app/views/layouts/standard.rhtml index 246fe382..8198de27 100644 --- a/tracks/app/views/layouts/standard.rhtml +++ b/tracks/app/views/layouts/standard.rhtml @@ -23,10 +23,10 @@