Divide UserController into a UserController and a PreferencesController. Divide FeedController into a FeedController and a FeedlistController. Pull up layout and login filter into ApplicationController and override as needed. Ignored new tmp directories.

git-svn-id: http://www.rousette.org.uk/svn/tracks-repos/trunk@376 a4c988fc-2ded-0310-b66e-134b36920a42
This commit is contained in:
lukemelia 2006-12-13 08:31:48 +00:00
parent 1e4f462f21
commit 1d22f08670
25 changed files with 218 additions and 88 deletions

View file

@ -1,8 +1,6 @@
class AdminController < ApplicationController class AdminController < ApplicationController
before_filter :login_required
before_filter :admin_login_required before_filter :admin_login_required
layout 'standard'
def index def index
@user_pages, @users = paginate :users, :order => 'login ASC', :per_page => 10 @user_pages, @users = paginate :users, :order => 'login ASC', :per_page => 10

View file

@ -13,8 +13,11 @@ class ApplicationController < ActionController::Base
helper :application helper :application
include LoginSystem include LoginSystem
layout 'standard'
before_filter :set_session_expiration before_filter :set_session_expiration
before_filter :get_current_user before_filter :get_current_user
prepend_before_filter :login_required
after_filter :set_charset after_filter :set_charset

View file

@ -2,6 +2,8 @@ class BackendController < ApplicationController
wsdl_service_name 'Backend' wsdl_service_name 'Backend'
web_service_api TodoApi web_service_api TodoApi
web_service_scaffold :invoke web_service_scaffold :invoke
skip_before_filter :login_required
def new_todo(username, token, context_id, description) def new_todo(username, token, context_id, description)
check_token_against_user_word(username, token) check_token_against_user_word(username, token)

View file

@ -2,10 +2,8 @@ class ContextController < ApplicationController
helper :todo helper :todo
prepend_before_filter :login_required
before_filter :init, :except => [:create, :destroy, :order] before_filter :init, :except => [:create, :destroy, :order]
before_filter :init_todos, :only => :show before_filter :init_todos, :only => :show
layout "standard", :except => :date_preview
def index def index
list list

View file

@ -3,19 +3,14 @@
class FeedController < ApplicationController class FeedController < ApplicationController
helper :feed helper :feed
session :disabled => true, :except => 'index' # Prevents session control from interfering with feed layout nil
before_filter :check_token_against_user_word, :except => 'index' session :disabled => true # Prevents session control from interfering with feed
prepend_before_filter :login_required, :only => 'index'
skip_before_filter :login_required
before_filter :check_token_against_user_word
before_filter :prepare_for_feed, :only => [:rss, :text, :ical] before_filter :prepare_for_feed, :only => [:rss, :text, :ical]
def index
@page_title = 'TRACKS::Feeds'
init_data_for_sidebar
render :layout => 'standard'
end
# Build an RSS feed # Build an RSS feed
def rss def rss
headers["Content-Type"] = "text/xml; charset=utf-8" headers["Content-Type"] = "text/xml; charset=utf-8"

View file

@ -0,0 +1,11 @@
class FeedlistController < ApplicationController
helper :feedlist
def index
@page_title = 'TRACKS::Feeds'
init_data_for_sidebar
render :layout => 'standard'
end
end

View file

@ -1,6 +1,8 @@
class LoginController < ApplicationController class LoginController < ApplicationController
layout 'login' layout 'login'
skip_before_filter :set_session_expiration skip_before_filter :set_session_expiration
skip_before_filter :login_required
open_id_consumer if Tracks::Config.auth_schemes.include?('open_id') open_id_consumer if Tracks::Config.auth_schemes.include?('open_id')
def login def login

View file

@ -2,7 +2,6 @@ class MobileController < ApplicationController
layout 'mobile' layout 'mobile'
prepend_before_filter :login_required
before_filter :init, :except => :update before_filter :init, :except => :update
# Plain list of all next actions, paginated 6 per page # Plain list of all next actions, paginated 6 per page

View file

@ -1,9 +1,5 @@
class NoteController < ApplicationController class NoteController < ApplicationController
prepend_before_filter :login_required
layout "standard"
def index def index
@all_notes = @user.notes @all_notes = @user.notes
@page_title = "TRACKS::All notes" @page_title = "TRACKS::All notes"

View file

@ -0,0 +1,25 @@
class PreferencesController < ApplicationController
def index
@page_title = "TRACKS::Preferences"
@prefs = @user.preference
end
def edit
@page_title = "TRACKS::Edit Preferences"
@prefs = @user.preference
render :object => @prefs
end
def update
user_success = @user.update_attributes(params['user'])
prefs_success = @user.preference.update_attributes(params['prefs'])
if user_success && prefs_success
redirect_to :action => 'index'
else
render :action => 'edit'
end
end
end

View file

@ -1,12 +1,9 @@
class ProjectController < ApplicationController class ProjectController < ApplicationController
helper :todo helper :todo
prepend_before_filter :login_required
before_filter :init, :except => [:create, :destroy, :order, :toggle_project_done] before_filter :init, :except => [:create, :destroy, :order, :toggle_project_done]
before_filter :init_todos, :only => :show before_filter :init_todos, :only => :show
layout "standard", :except => :date_preview
def index def index
list list
render_action "list" render_action "list"

View file

@ -2,9 +2,8 @@ class TodoController < ApplicationController
helper :todo helper :todo
prepend_before_filter :login_required
append_before_filter :init, :except => [ :destroy, :completed, :completed_archive, :check_tickler ] append_before_filter :init, :except => [ :destroy, :completed, :completed_archive, :check_tickler ]
layout "standard", :except => :date_preview layout 'standard', :except => :date_preview
# Main method for listing tasks # Main method for listing tasks
# Set page title, and fill variables with contexts and done and not-done tasks # Set page title, and fill variables with contexts and done and not-done tasks

View file

@ -1,6 +1,5 @@
class UserController < ApplicationController class UserController < ApplicationController
layout 'standard'
prepend_before_filter :login_required
if Tracks::Config.auth_schemes.include?('open_id') if Tracks::Config.auth_schemes.include?('open_id')
open_id_consumer open_id_consumer
before_filter :begin_open_id_auth, :only => :update_auth_type before_filter :begin_open_id_auth, :only => :update_auth_type
@ -68,7 +67,7 @@ class UserController < ApplicationController
def update_password def update_password
if do_change_password_for(@user) if do_change_password_for(@user)
redirect_to :controller => 'user', :action => 'preferences' redirect_to :controller => 'preferences'
else else
redirect_to :controller => 'user', :action => 'change_password' redirect_to :controller => 'user', :action => 'change_password'
notify :warning, "There was a problem saving the password. Please retry." notify :warning, "There was a problem saving the password. Please retry."
@ -97,7 +96,7 @@ class UserController < ApplicationController
@user.auth_type = params[:user][:auth_type] @user.auth_type = params[:user][:auth_type]
if @user.save if @user.save
notify :notice, "Authentication type updated." notify :notice, "Authentication type updated."
redirect_to :controller => 'user', :action => 'preferences' redirect_to :controller => 'preferences'
else else
notify :warning, "There was a problem updating your authentication type: #{ @user.errors.full_messages.join(', ')}" notify :warning, "There was a problem updating your authentication type: #{ @user.errors.full_messages.join(', ')}"
redirect_to :controller => 'user', :action => 'change_auth_type' redirect_to :controller => 'user', :action => 'change_auth_type'

View file

@ -66,24 +66,4 @@ module FeedHelper
sprintf("%s%s%s%s", @request.protocol, @request.host, @request.port_string, url_for(:controller => 'todo', :action => 'show', :id => todo.id)) sprintf("%s%s%s%s", @request.protocol, @request.host, @request.port_string, url_for(:controller => 'todo', :action => 'show', :id => todo.id))
end end
def rss_feed_link(options = {})
image_tag = image_tag("feed-icon.png", :size => "16X16", :border => 0, :class => "rss-icon")
linkoptions = {:controller => 'feed', :action => 'rss', :login => "#{@user.login}", :token => "#{@user.word}"}
linkoptions.merge!(options)
link_to(image_tag, linkoptions, :title => "RSS feed")
end
def text_feed_link(options = {})
linkoptions = {:controller => 'feed', :action => 'text', :login => "#{@user.login}", :token => "#{@user.word}"}
linkoptions.merge!(options)
link_to('<span class="feed">TXT</span>', linkoptions, :title => "Plain text feed" )
end
def ical_feed_link(options = {})
linkoptions = {:controller => 'feed', :action => 'ical', :login => "#{@user.login}", :token => "#{@user.word}"}
linkoptions.merge!(options)
link_to('<span class="feed">iCal</span>', linkoptions, :title => "iCal feed")
end
end end

View file

@ -0,0 +1,23 @@
module FeedlistHelper
def rss_feed_link(options = {})
image_tag = image_tag("feed-icon.png", :size => "16X16", :border => 0, :class => "rss-icon")
linkoptions = {:controller => 'feed', :action => 'rss', :login => "#{@user.login}", :token => "#{@user.word}"}
linkoptions.merge!(options)
link_to(image_tag, linkoptions, :title => "RSS feed")
end
def text_feed_link(options = {})
linkoptions = {:controller => 'feed', :action => 'text', :login => "#{@user.login}", :token => "#{@user.word}"}
linkoptions.merge!(options)
link_to('<span class="feed">TXT</span>', linkoptions, :title => "Plain text feed" )
end
def ical_feed_link(options = {})
linkoptions = {:controller => 'feed', :action => 'ical', :login => "#{@user.login}", :token => "#{@user.word}"}
linkoptions.merge!(options)
link_to('<span class="feed">iCal</span>', linkoptions, :title => "iCal feed")
end
end

View file

@ -0,0 +1,2 @@
module PreferencesHelper
end

View file

@ -0,0 +1,82 @@
<div id="display_box">
<div id="feeds">
<div id="feedlegend">
<h3>Legend:</h3>
<dl>
<dt><%= image_tag("feed-icon.png", :size => "16X16", :border => 0)%></dt><dd>RSS Feed</dd>
<dt><span class="feed">TXT</span></dt><dd>Plain Text Feed</dd>
<dt><span class="feed">iCal</span></dt><dd>iCal feed</dd>
</dl>
<p>Note: All feeds show only actions that have not been marked as done.</p>
</div>
<ul>
<li>
<%= rss_feed_link({ :limit => 15 }) %>
<%= text_feed_link({ :limit => 15 }) %>
<%= ical_feed_link({ :limit => 15 }) %>
Last 15 actions
</li>
<li>
<%= rss_feed_link %>
<%= text_feed_link %>
<%= ical_feed_link %>
All actions
</li>
<li>
<%= rss_feed_link({ :due => 0 }) %>
<%= text_feed_link({ :due => 0 }) %>
<%= ical_feed_link({ :due => 0 }) %>
Actions due today or earlier
</li>
<li>
<%= rss_feed_link({ :due => 6 }) %>
<%= text_feed_link({ :due => 6 }) %>
<%= ical_feed_link({ :due => 6 }) %>
Actions due in 7 days or earlier
</li>
<li>
<%= rss_feed_link({ :done => 7 }) %>
<%= text_feed_link({ :done => 7 }) %>
Actions completed in the last 7 days
</li>
<li>
<%= rss_feed_link({ :action => 'list_contexts_only', :feedtype => 'rss' }) %>
<%= text_feed_link({ :action => 'list_contexts_only', :feedtype => 'text' }) %>
All Contexts
</li>
<li>
<%= rss_feed_link({ :action => 'list_projects_only', :feedtype => 'rss' }) %>
<%= text_feed_link({ :action => 'list_projects_only', :feedtype => 'text' }) %>
All Projects
</li>
<li><h4>Feeds for uncompleted actions in a specific context:</h4>
<ul>
<% for context in @contexts %>
<li>
<%= rss_feed_link({ :context => context }) %>
<%= text_feed_link({ :context => context }) %>
<%= ical_feed_link({ :context => context }) %>
Next actions in <strong><%=h context.name %></strong>
</li>
<% end %>
</ul>
</li>
<li><h4>Feeds for uncompleted actions in a specific project:</h4>
<ul>
<% for project in @projects %>
<li>
<%= rss_feed_link({ :project => project }) %>
<%= text_feed_link({ :project => project }) %>
<%= ical_feed_link({ :project => project }) %>
Next actions for <strong><%=h project.name %></strong>
</li>
<% end %>
</ul>
</li>
</ul>
</div>
</div><!-- End of display_box -->
<div id="input_box">
<%= render "sidebar/sidebar" %>
</div><!-- End of input box -->

View file

@ -46,11 +46,11 @@
<li><%= navigation_link( "Tickler", {:controller => "todo", :action => "tickler"}, :title => "Tickler" ) %></li> <li><%= navigation_link( "Tickler", {:controller => "todo", :action => "tickler"}, :title => "Tickler" ) %></li>
<li><%= navigation_link( "Done", {:controller => "todo", :action => "completed"}, {:accesskey=>"d", :title=>"Completed"} ) %></li> <li><%= navigation_link( "Done", {:controller => "todo", :action => "completed"}, {:accesskey=>"d", :title=>"Completed"} ) %></li>
<li><%= navigation_link( "Notes", {:controller => "note", :action => "index"}, {:accesskey => "o", :title => "Show all notes"} ) %></li> <li><%= navigation_link( "Notes", {:controller => "note", :action => "index"}, {:accesskey => "o", :title => "Show all notes"} ) %></li>
<li><%= navigation_link( "Preferences", {:controller => "user", :action => "preferences"}, {:accesskey => "u", :title => "Show my preferences"} ) %></li> <li><%= navigation_link( "Preferences", {:controller => "preferences", :action => "index"}, {:accesskey => "u", :title => "Show my preferences"} ) %></li>
<% if @user.is_admin? -%> <% if @user.is_admin? -%>
<li><%= navigation_link("Admin", {:controller => "admin", :action => "index"}, {:accesskey => "a", :title => "Add or delete users"} ) %></li> <li><%= navigation_link("Admin", {:controller => "admin", :action => "index"}, {:accesskey => "a", :title => "Add or delete users"} ) %></li>
<% end -%> <% end -%>
<li><%= navigation_link(image_tag("feed-icon.png", :size => "16X16", :border => 0), {:controller => "feed", :action => "index"}, :title => "See a list of available feeds" ) %></li> <li><%= navigation_link(image_tag("feed-icon.png", :size => "16X16", :border => 0), {:controller => "feedlist", :action => "index"}, :title => "See a list of available feeds" ) %></li>
</ul> </ul>
</div> </div>

View file

@ -19,7 +19,7 @@
</div> </div>
<div id="input_box" class="container context"> <div id="input_box" class="container context">
<% form_tag :action => 'update_preferences' do %> <% form_tag :action => 'update' do %>
<table> <table>
<tr> <tr>
<td><label>first name:</label></td> <td><label>first name:</label></td>
@ -62,7 +62,7 @@
<%= row_with_select_field("verbose_action_descriptors") %> <%= row_with_select_field("verbose_action_descriptors") %>
<tr><td><%= submit_tag "Update" %></td> <tr><td><%= submit_tag "Update" %></td>
<td><%= link_to "Cancel", :controller => 'user', :action => 'preferences' %></td> <td><%= link_to "Cancel", :action => 'index' %></td>
</tr> </tr>
</table> </table>
<% end %> <% end %>

View file

@ -26,7 +26,7 @@
<li>Verbose action descriptors: <span class="highlight"><%= @prefs.verbose_action_descriptors %></span></li> <li>Verbose action descriptors: <span class="highlight"><%= @prefs.verbose_action_descriptors %></span></li>
</ul> </ul>
<div class="actions"> <div class="actions">
<%= link_to "Edit preferences &raquo;", { :controller => 'user', :action => 'edit_preferences'}, :class => 'edit_link' %> <%= link_to "Edit preferences &raquo;", { :controller => 'preferences', :action => 'edit'}, :class => 'edit_link' %>
</div> </div>
<h2>Your token</h2> <h2>Your token</h2>

View file

@ -9,7 +9,7 @@
<% form_tag :action => 'update_auth_type' do %> <% form_tag :action => 'update_auth_type' do %>
<div><label for="user_auth_type">Authentication type:</label> <%= select('user', 'auth_type', Tracks::Config.auth_schemes.collect {|p| [ p, p ] }) %></div> <div><label for="user_auth_type">Authentication type:</label> <%= select('user', 'auth_type', Tracks::Config.auth_schemes.collect {|p| [ p, p ] }) %></div>
<div id="open_id" style="display:<%= @user.auth_type == 'open_id' ? 'block' : 'none' %>"><label for="user_open_id_url">Identity URL:</label> <input type="text" name="openid_url" value="<%= @user.open_id_url %>" class="open_id" /></div> <div id="open_id" style="display:<%= @user.auth_type == 'open_id' ? 'block' : 'none' %>"><label for="user_open_id_url">Identity URL:</label> <input type="text" name="openid_url" value="<%= @user.open_id_url %>" class="open_id" /></div>
<div class="actions"><%= submit_tag 'Change Authentication Type' %> <%= link_to 'Cancel', :action => 'preferences' %></div> <div class="actions"><%= submit_tag 'Change Authentication Type' %> <%= link_to 'Cancel', :controller => 'preferences' %></div>
<%= observe_field( :user_auth_type, :function => "$('open_id').style.display = value == 'open_id' ? 'block' : 'none'") %> <%= observe_field( :user_auth_type, :function => "$('open_id').style.display = value == 'open_id' ? 'block' : 'none'") %>

View file

@ -17,7 +17,7 @@
<td><%= password_field "updateuser", "password_confirmation", :size => 40 %></td> <td><%= password_field "updateuser", "password_confirmation", :size => 40 %></td>
</tr> </tr>
<tr> <tr>
<td><%= link_to 'Cancel', :action => 'preferences' %></td> <td><%= link_to 'Cancel', :controller => 'preferences' %></td>
<td><%= submit_tag 'Change password' %></td> <td><%= submit_tag 'Change password' %></td>
</tr> </tr>
</table> </table>

View file

@ -63,7 +63,7 @@ ActionController::Routing::Routes.draw do |map|
map.connect 'notes', :controller => 'note', :action => 'index' map.connect 'notes', :controller => 'note', :action => 'index'
# Feed Routes # Feed Routes
map.connect 'feeds', :controller => 'feed', :action => 'index' map.connect 'feeds', :controller => 'feedlist', :action => 'index'
map.connect 'feed/:action/:login/:token', :controller => 'feed' map.connect 'feed/:action/:login/:token', :controller => 'feed'
# Install the default route as the lowest priority. # Install the default route as the lowest priority.

View file

@ -0,0 +1,50 @@
require File.dirname(__FILE__) + '/../test_helper'
require 'preferences_controller'
require 'preference'
# Re-raise errors caught by the controller.
class PreferencesController; def rescue_action(e) raise e end; end
class PreferencesControllerTest < Test::Unit::TestCase
fixtures :users
def setup
assert_equal "test", ENV['RAILS_ENV']
assert_equal "change-me", Tracks::Config.salt
@controller = PreferencesController.new
@request = ActionController::TestRequest.new
@response = ActionController::TestResponse.new
end
def test_preferences
get :index # should fail because no login
assert_redirected_to :controller => 'login', :action => 'login'
@request.session['user_id'] = users(:admin_user).id # log in the admin user
get :index
assert_response :success
assert_equal assigns['page_title'], "TRACKS::Preferences"
assert_not_nil assigns['prefs']
end
def test_edit_preferences
get :edit # should fail because no login
assert_redirected_to :controller => 'login', :action => 'login'
@request.session['user_id'] = users(:admin_user).id # log in the admin user
get :edit
assert_response :success
assert_equal assigns['page_title'], "TRACKS::Edit Preferences"
assert_not_nil assigns['prefs']
assert_template 'preferences/edit'
end
def test_update_preferences
@request.session['user_id'] = users(:admin_user).id # log in the admin user
post :update, {:user => { :first_name => 'Jane', :last_name => 'Doe'}, :prefs => { :date_format => "%m-%d-%Y", :week_starts => "0", :show_number_completed => "10", :show_completed_projects_in_sidebar => "false", :show_hidden_contexts_in_sidebar => "false", :staleness_starts => "14", :due_style => "1", :admin_email => "my.email@domain.com" }}
updated_admin_user = User.find(users(:admin_user).id)
assert_not_nil updated_admin_user.preference
assert_equal 'Jane', updated_admin_user.first_name
assert_equal 'Doe', updated_admin_user.last_name
assert_redirected_to :action => 'index'
end
end

View file

@ -15,37 +15,6 @@ class UserControllerTest < Test::Unit::TestCase
@request = ActionController::TestRequest.new @request = ActionController::TestRequest.new
@response = ActionController::TestResponse.new @response = ActionController::TestResponse.new
end end
def test_preferences
get :preferences # should fail because no login
assert_redirected_to :controller => 'login', :action => 'login'
@request.session['user_id'] = users(:admin_user).id # log in the admin user
get :preferences
assert_response :success
assert_equal assigns['page_title'], "TRACKS::Preferences"
assert_not_nil assigns['prefs']
end
def test_edit_preferences
get :edit_preferences # should fail because no login
assert_redirected_to :controller => 'login', :action => 'login'
@request.session['user_id'] = users(:admin_user).id # log in the admin user
get :edit_preferences
assert_response :success
assert_equal assigns['page_title'], "TRACKS::Edit Preferences"
assert_not_nil assigns['prefs']
assert_template 'user/preference_edit_form'
end
def test_update_preferences
@request.session['user_id'] = users(:admin_user).id # log in the admin user
post :update_preferences, {:user => { :first_name => 'Jane', :last_name => 'Doe'}, :prefs => { :date_format => "%m-%d-%Y", :week_starts => "0", :show_number_completed => "10", :show_completed_projects_in_sidebar => "false", :show_hidden_contexts_in_sidebar => "false", :staleness_starts => "14", :due_style => "1", :admin_email => "my.email@domain.com" }}
updated_admin_user = User.find(users(:admin_user).id)
assert_not_nil updated_admin_user.preference
assert_equal 'Jane', updated_admin_user.first_name
assert_equal 'Doe', updated_admin_user.last_name
assert_redirected_to :action => 'preferences'
end
def test_update_password_successful def test_update_password_successful
get :change_password # should fail because no login get :change_password # should fail because no login
@ -56,7 +25,7 @@ class UserControllerTest < Test::Unit::TestCase
assert_response :success assert_response :success
assert_equal assigns['page_title'], "TRACKS::Change password" assert_equal assigns['page_title'], "TRACKS::Change password"
post :update_password, :updateuser => {:password => 'newpassword', :password_confirmation => 'newpassword'} post :update_password, :updateuser => {:password => 'newpassword', :password_confirmation => 'newpassword'}
assert_redirected_to :controller => 'user', :action => 'preferences' assert_redirected_to :controller => 'preferences'
@updated_user = User.find(users(:admin_user).id) @updated_user = User.find(users(:admin_user).id)
assert_equal @updated_user.password, Digest::SHA1.hexdigest("#{Tracks::Config.salt}--newpassword--") assert_equal @updated_user.password, Digest::SHA1.hexdigest("#{Tracks::Config.salt}--newpassword--")
assert_equal flash[:notice], "Password updated." assert_equal flash[:notice], "Password updated."