Changeset 479
- Timestamp:
- 08/10/07 12:54:31 (1 year ago)
- Files:
-
- branches/jargon/radiant/app/controllers/admin/user_controller.rb (modified) (3 diffs)
- branches/jargon/radiant/app/controllers/admin/welcome_controller.rb (modified) (2 diffs)
- branches/jargon/radiant/app/controllers/application.rb (modified) (2 diffs)
- branches/jargon/radiant/app/helpers/admin/user_helper.rb (modified) (1 diff)
- branches/jargon/radiant/app/helpers/application_helper.rb (modified) (3 diffs)
- branches/jargon/radiant/app/models/user.rb (modified) (2 diffs)
- branches/jargon/radiant/app/views/admin/user/edit.rhtml (modified) (1 diff)
- branches/jargon/radiant/app/views/admin/user/index.rhtml (modified) (1 diff)
- branches/jargon/radiant/app/views/admin/user/preferences.rhtml (modified) (1 diff)
- branches/jargon/radiant/db/migrate/016_add_language_column_to_user.rb (added)
- branches/jargon/radiant/db/schema.rb (modified) (2 diffs)
- branches/jargon/radiant/lang/de.yaml (modified) (1 diff)
- branches/jargon/radiant/lang/en.yaml (modified) (1 diff)
- branches/jargon/radiant/lang/ja.yaml (modified) (1 diff)
- branches/jargon/radiant/lang/nl.yaml (modified) (1 diff)
- branches/jargon/radiant/lib/login_system.rb (modified) (3 diffs)
- branches/jargon/radiant/public/stylesheets/admin/main.css (modified) (5 diffs)
- branches/jargon/radiant/test/functional/admin/abstract_model_controller_test.rb (modified) (1 diff)
- branches/jargon/radiant/test/functional/admin/export_controller_test.rb (modified) (1 diff)
- branches/jargon/radiant/test/functional/admin/extension_controller_test.rb (modified) (1 diff)
- branches/jargon/radiant/test/functional/admin/layout_controller_test.rb (modified) (3 diffs)
- branches/jargon/radiant/test/functional/admin/page_controller_test.rb (modified) (1 diff)
- branches/jargon/radiant/test/functional/admin/user_controller_test.rb (modified) (5 diffs)
- branches/jargon/radiant/test/functional/admin/welcome_controller_test.rb (modified) (3 diffs)
- branches/jargon/radiant/test/functional/application_controller_test.rb (modified) (1 diff)
- branches/jargon/radiant/test/functional/login_system_test.rb (modified) (6 diffs)
- branches/jargon/radiant/test/unit/user_test.rb (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/jargon/radiant/app/controllers/admin/user_controller.rb
r464 r479 7 7 8 8 def preferences 9 @user = User.find(session['user'].id)9 @user = current_user 10 10 if valid_params? 11 11 handle_new_or_edit_post( … … 19 19 20 20 def remove 21 if session['user'].id.to_s == params[:id].to_s21 if current_user.id.to_s == params[:id].to_s 22 22 announce_cannot_delete_self 23 23 redirect_to user_index_url … … 39 39 def valid_params? 40 40 hash = (params[:user] || {}).symbolize_keys 41 (hash.keys - [:password, :password_confirmation, :email ]).size == 041 (hash.keys - [:password, :password_confirmation, :email, :language]).size == 0 42 42 end 43 43 end branches/jargon/radiant/app/controllers/admin/welcome_controller.rb
r464 r479 10 10 login = params[:user][:login] 11 11 password = params[:user][:password] 12 session['user'] = User.authenticate(login, password) 13 if session['user'] 12 user = User.authenticate(login, password) 13 if user 14 session['user_id'] = user.id 14 15 redirect_to welcome_url 15 16 else … … 20 21 21 22 def logout 22 session['user '] = nil23 session['user_id'] = nil 23 24 announce_logged_out 24 25 redirect_to login_url branches/jargon/radiant/app/controllers/application.rb
r429 r479 13 13 before_filter :set_javascripts_and_stylesheets 14 14 15 around_filter :set_language 16 15 17 attr_accessor :config 16 18 … … 20 22 end 21 23 22 helper_method :include_stylesheet, :include_javascript23 24 def include_stylesheet(sheet) 24 25 @stylesheets << sheet 25 26 end 27 helper_method :include_stylesheet 26 28 27 29 def include_javascript(script) 28 30 @javascripts << script 29 31 end 32 helper_method :include_javascript 30 33 31 34 private 32 35 33 36 def set_current_user 34 UserActionObserver.current_user = session['user']37 UserActionObserver.current_user = current_user 35 38 end 36 39 37 40 def set_javascripts_and_stylesheets 38 41 @stylesheets = ['admin/main'] 39 42 @javascripts = ['prototype', 'string', 'effects', 'dragdrop', 'controls', 'tabcontrol', 'ruledtable'] 40 43 end 44 45 def set_language 46 lang = current_user && current_user.language 47 lang = nil if lang.blank? 48 lang ||= Gibberish.default_language 49 Gibberish.use_language(lang.to_sym) { yield } 50 end 41 51 end branches/jargon/radiant/app/helpers/admin/user_helper.rb
r1 r479 1 1 module Admin::UserHelper 2 3 def languages 4 @languages || Gibberish.languages.map do |code| 5 name = ''; 6 Gibberish.use_language(code) do 7 name = Gibberish.translations[:language] 8 end 9 [name, code.to_s] 10 end.sort_by { |(name, code)| name } 11 end 12 2 13 end branches/jargon/radiant/app/helpers/application_helper.rb
r464 r479 17 17 18 18 def logged_in? 19 session['user'] ? true : false19 current_user.nil? ? false : true 20 20 end 21 21 … … 50 50 tabs = admin.tabs 51 51 links = tabs.map do |tab| 52 nav_link_to(tab.name, tab.url) if tab.shown_for?( session['user'])52 nav_link_to(tab.name, tab.url) if tab.shown_for?(current_user) 53 53 end.compact 54 54 links.join(separator) … … 84 84 85 85 def admin? 86 user = session['user']86 user = current_user 87 87 user and user.admin? 88 88 end 89 89 90 90 def developer? 91 user = session['user']91 user = current_user 92 92 user and (user.developer? or user.admin?) 93 93 end branches/jargon/radiant/app/models/user.rb
r405 r479 2 2 3 3 class User < ActiveRecord::Base 4 5 def self.valid_languages 6 Gibberish.languages.map(&:to_s) + [''] 7 end 4 8 5 9 # Default Order … … 19 23 20 24 validates_format_of :email, :message => 'invalid e-mail address', :allow_nil => true, :with => /^$|^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i 25 26 validates_inclusion_of :language, :in => valid_languages, :allow_nil => true, :message => 'invalid language' 21 27 22 28 validates_length_of :name, :maximum => 100, :allow_nil => true, :message => '%d-character limit' branches/jargon/radiant/app/views/admin/user/edit.rhtml
r464 r479 41 41 </tr> 42 42 <tr> 43 <td class="label"><label for="user_language"><%= "Language"[:preferred_language] %></label></td> 44 <td class="field"><%= select "user", "language", [['', '']] + languages %></td> 45 <td class="help"><%= "Preferred language for the administrative interface."[:note_preferred_language] %></td> 46 </tr> 47 <tr> 43 48 <td class="label"><label class="optional" for="user_notes"><%= "Notes"[:notes] %></label></td> 44 49 <td class="field"><%= text_area "user", "notes", :size => '40x4' %></td> branches/jargon/radiant/app/views/admin/user/index.rhtml
r464 r479 25 25 %> 26 26 </td> 27 <td class="remove"><%= user.id != session['user'].id ? link_to(image('remove', :alt => 'Remove User'), user_remove_url(:id => user)) : image('remove-disabled', :alt => 'Remove'[:remove]) %></td>27 <td class="remove"><%= user.id != current_user.id ? link_to(image('remove', :alt => 'Remove User'), user_remove_url(:id => user)) : image('remove-disabled', :alt => 'Remove'[:remove]) %></td> 28 28 </tr> 29 29 <% end -%> branches/jargon/radiant/app/views/admin/user/preferences.rhtml
r464 r479 17 17 <td class="help"><%= "Optional"[:optional] %>.</td> 18 18 </tr> 19 <tr> 20 <td class="label"><label for="user_language"><%= "Language"[:preferred_language] %></label></td> 21 <td class="field"><%= select "user", "language", [['', '']] + languages %></td> 22 <td class="help"><%= "Preferred language for the administrative interface."[:note_preferred_language] %></td> 23 </tr> 19 24 </table> 20 25 <p class="buttons"> branches/jargon/radiant/db/schema.rb
r423 r479 3 3 # then regenerate this schema definition. 4 4 5 ActiveRecord::Schema.define(:version => 1 5) do5 ActiveRecord::Schema.define(:version => 16) do 6 6 7 7 create_table "config", :force => true do |t| … … 79 79 t.column "notes", :text 80 80 t.column "lock_version", :integer, :default => 0 81 t.column "language", :string, :limit => 40 81 82 end 82 83 branches/jargon/radiant/lang/de.yaml
r476 r479 1 1 # Please add values here as the interface is changed and updated. More information can be found in /vendor/plugins/gibberish/README 2 2 3 language: 'German -DE'3 language: 'German' 4 4 5 5 # Abstract Model Controller branches/jargon/radiant/lang/en.yaml
r466 r479 2 2 # Please add values here as the interface is changed and updated. More information can be found in /vendor/plugins/gibberish/README 3 3 4 language: 'English -US'4 language: 'English' 5 5 6 6 # Abstract Model Controller branches/jargon/radiant/lang/ja.yaml
r473 r479 1 1 # Please add values here as the interface is changed and updated. More information can be found in /vendor/plugins/gibberish/README 2 2 3 language: 'Japanese -JP'3 language: 'Japanese' 4 4 5 5 # Abstract Model Controller branches/jargon/radiant/lang/nl.yaml
r473 r479 1 1 # Please add values here as the interface is changed and updated. More information can be found in /vendor/plugins/gibberish/README 2 2 3 language: ' Nederlands-NL'3 language: 'Dutch' 4 4 5 5 # Abstract Model Controller branches/jargon/radiant/lib/login_system.rb
r405 r479 2 2 def self.append_features(base) 3 3 base.class_eval %{ 4 helper_method :current_user 5 4 6 before_filter :authenticate 5 7 … … 12 14 13 15 protected 14 16 17 def current_user 18 id = session['user_id'] 19 User.find_by_id(id) if id 20 end 21 15 22 def authenticate 16 23 action = params['action'].to_s.intern 17 user = session['user']24 user = current_user 18 25 if no_login_required? or (user and user_has_access_to_action?(action)) 19 26 true … … 36 43 37 44 def user_has_role?(role) 38 session['user'].send("#{role}?")45 current_user.send("#{role}?") 39 46 end 40 47 branches/jargon/radiant/public/stylesheets/admin/main.css
r405 r479 277 277 padding-top: 15px; 278 278 padding-bottom: 10px; 279 width: 100%;279 width: 100%; 280 280 } 281 281 #content .form-area h3 { … … 297 297 #content .form-area .title { 298 298 margin-bottom: 0; 299 width: 100%;299 width: 100%; 300 300 } 301 301 #content .form-area .title label { … … 345 345 } 346 346 #content table.fieldset { 347 border-bottom: 1px solid # DFD3C3;347 border-bottom: 1px solid #dfd3c3; 348 348 margin-bottom: .3em; 349 349 width: 100%; … … 351 351 #content table.fieldset td { 352 352 background-color: white; 353 border-top: 1px solid # DFD3C3;353 border-top: 1px solid #dfd3c3; 354 354 padding: 6px; 355 355 } … … 371 371 padding-left: 0px; 372 372 padding-right: 10px; 373 text-align: right;373 text-align: left; 374 374 } 375 375 #content #extended-metadata .fieldset td.field { branches/jargon/radiant/test/functional/admin/abstract_model_controller_test.rb
r405 r479 24 24 @request = ActionController::TestRequest.new 25 25 @response = ActionController::TestResponse.new 26 @request.session['user '] = users(:existing)26 @request.session['user_id'] = users(:existing).id 27 27 @cache = @controller.cache = FakeResponseCache.new 28 28 branches/jargon/radiant/test/functional/admin/export_controller_test.rb
r405 r479 12 12 @request = ActionController::TestRequest.new 13 13 @response = ActionController::TestResponse.new 14 @request.session['user '] = users(:developer)14 @request.session['user_id'] = users(:developer).id 15 15 end 16 16 branches/jargon/radiant/test/functional/admin/extension_controller_test.rb
r405 r479 13 13 @request = ActionController::TestRequest.new 14 14 @response = ActionController::TestResponse.new 15 @request.session['user '] = users(:admin)15 @request.session['user_id'] = users(:admin).id 16 16 end 17 17 branches/jargon/radiant/test/functional/admin/layout_controller_test.rb
r405 r479 13 13 @request = ActionController::TestRequest.new 14 14 @response = ActionController::TestResponse.new 15 @request.session['user '] = users(:developer)15 @request.session['user_id'] = users(:developer).id 16 16 end 17 17 … … 22 22 [:index, :new, :edit, :remove].each do |action| 23 23 define_method "test_#{action}_action_allowed_if_admin" do 24 get action, { :id => 1 }, { 'user ' => users(:admin)}24 get action, { :id => 1 }, { 'user_id' => users(:admin).id } 25 25 assert_response :success, "action: #{action}" 26 26 end … … 32 32 33 33 define_method "test_#{action}_action__not_allowed_if_other" do 34 get action, { :id => 1 }, { 'user ' => users(:existing)}, {}34 get action, { :id => 1 }, { 'user_id' => users(:existing).id }, {} 35 35 assert_redirected_to page_index_url, "action: #{action}" 36 36 assert_match /privileges/, flash[:error], "action: #{action}" branches/jargon/radiant/test/functional/admin/page_controller_test.rb
r405 r479 13 13 @request = ActionController::TestRequest.new 14 14 @response = ActionController::TestResponse.new 15 @request.session['user '] = users(:existing)15 @request.session['user_id'] = users(:existing).id 16 16 17 17 @page_title = 'Just a Test' branches/jargon/radiant/test/functional/admin/user_controller_test.rb
r429 r479 14 14 @request = ActionController::TestRequest.new 15 15 @response = ActionController::TestResponse.new 16 @user = @request.session['user'] = create_test_user 16 @user = create_test_user 17 @request.session['user_id'] = @user.id 17 18 end 18 19 … … 27 28 [:index, :new, :edit, :remove].each do |action| 28 29 define_method "test_#{action}_action_allowed_if_admin" do 29 get action, { :id => 1 }, { 'user ' => users(:admin)}30 get action, { :id => 1 }, { 'user_id' => users(:admin).id } 30 31 assert_response :success, "action: #{action}" 31 32 end 32 33 33 34 define_method "test_#{action}_action_not_allowed_if_other" do 34 get action, { :id => 1 }, { 'user ' => users(:non_admin)}35 get action, { :id => 1 }, { 'user_id' => users(:non_admin).id } 35 36 assert_redirected_to page_index_url, "action: #{action}" 36 37 assert_match /privileges/, flash[:error], "action: #{action}" … … 40 41 def test_remove__cannot_remove_self 41 42 @user = users(:admin) 42 get :remove, { :id => @user.id }, { 'user ' => @user}43 get :remove, { :id => @user.id }, { 'user_id' => @user.id } 43 44 assert_redirected_to user_index_url 44 45 assert_match /cannot.*self/i, flash[:error] … … 58 59 :preferences, 59 60 { :user => { :password => '', :password_confirmation => '', :email => 'updated@gmail.com' } }, 60 { 'user ' => @user}61 { 'user_id' => @user.id } 61 62 ) 62 63 @user = User.find(@user.id) … … 76 77 :preferences, 77 78 { :user => { :password => 'funtimes', :password_confirmation => 'funtimes' } }, 78 { 'user ' => @user}79 { 'user_id' => @user.id } 79 80 ) 80 81 @user = User.find(@user.id) branches/jargon/radiant/test/functional/admin/welcome_controller_test.rb
r429 r479 29 29 assert_redirected_to welcome_url 30 30 31 user = session['user']31 user = User.find_by_id(session['user_id']) 32 32 assert_kind_of User, user 33 33 assert_equal 'existing', user.login … … 39 39 assert_response :success 40 40 assert_match /invalid/i, flash[:error] 41 assert_nil session['user ']41 assert_nil session['user_id'] 42 42 end 43 43 … … 45 45 get :logout, nil, { 'user' => users(:existing) } 46 46 assert_redirected_to login_url 47 assert_nil session['user ']47 assert_nil session['user_id'] 48 48 assert_match /logged out/i, flash[:notice] 49 49 end branches/jargon/radiant/test/functional/application_controller_test.rb
r405 r479 38 38 def test_before_filter 39 39 UserActionObserver.current_user = nil 40 get :test, {}, { 'user ' => @user}40 get :test, {}, { 'user_id' => @user.id } 41 41 assert_response :success 42 assert_equal @user , UserActionObserver.current_user42 assert_equal @user.id, UserActionObserver.current_user.id 43 43 end 44 44 end branches/jargon/radiant/test/functional/login_system_test.rb
r405 r479 58 58 59 59 def test_authenticate__with_user_in_session 60 get :index, {}, { 'user ' => users(:existing)}60 get :index, {}, { 'user_id' => users(:existing).id } 61 61 assert_response :success 62 62 end … … 76 76 def test_only_allow_access_to__when_user_in_role 77 77 @controller = OnlyAllowAccessToWhenController.new 78 get :edit, {}, { 'user ' => users(:admin)}78 get :edit, {}, { 'user_id' => users(:admin).id } 79 79 assert_response :success 80 80 end 81 81 def test_only_allow_access_to__when_user_in_role_2 82 82 @controller = OnlyAllowAccessToWhenController.new 83 get :new, {}, { 'user ' => users(:developer)}83 get :new, {}, { 'user_id' => users(:developer).id } 84 84 assert_response :success 85 85 end 86 86 def test_only_allow_access_to__when_user_in_role_3 87 87 @controller = OnlyAllowAccessToWhenController.new 88 get :another, {}, { 'user ' => users(:admin)}88 get :another, {}, { 'user_id' => users(:admin).id } 89 89 assert_response :success 90 90 end 91 91 def test_only_allow_access_to__when_user_not_in_role 92 92 @controller = OnlyAllowAccessToWhenController.new 93 get :edit, {}, { 'user ' => users(:non_admin)}93 get :edit, {}, { 'user_id' => users(:non_admin).id } 94 94 assert_redirected_to :action => :test 95 95 assert_equal 'Fun.', flash[:error] … … 97 97 def test_only_allow_access_to__when_user_not_in_role_2 98 98 @controller = OnlyAllowAccessToWhenController.new 99 get :new, {}, { 'user ' => users(:non_admin)}99 get :new, {}, { 'user_id' => users(:non_admin).id } 100 100 assert_redirected_to :action => :test 101 101 assert_equal 'Fun.', flash[:error] … … 103 103 def test_only_allow_access_to__when__user_not_in_role_3 104 104 @controller = OnlyAllowAccessToWhenController.new 105 get :another, {}, { 'user ' => users(:non_admin)}105 get :another, {}, { 'user_id' => users(:non_admin).id } 106 106 assert_response :success 107 107 end 108 108 def test_only_allow_access_to__when__user_not_in_role__defaults 109 109 @controller = OnlyAllowAccessToWhenDefaultsController.new 110 get :edit, {}, { 'user ' => users(:non_admin)}110 get :edit, {}, { 'user_id' => users(:non_admin).id } 111 111 assert_redirected_to :action => :index 112 112 assert_equal 'Access denied.', flash[:error] … … 116 116 @controller = OnlyAllowAccessToIfController.new 117 117 @controller.condition = true 118 get :edit, {}, { 'user ' => users(:existing)}118 get :edit, {}, { 'user_id' => users(:existing).id } 119 119 assert_response :success 120 120 end … … 122 122 @controller = OnlyAllowAccessToIfController.new 123 123 @controller.condition = false 124 get :edit, {}, { 'user ' => users(:existing)}124 get :edit, {}, { 'user_id' => users(:existing).id } 125 125 assert_response :redirect 126 126 end branches/jargon/radiant/test/unit/user_test.rb
r405 r479 90 90 end 91 91 92 def test_validates_inclusion_of 93 assert_valid :language, nil, '' 94 assert_valid :language, *Gibberish.languages.map(&:to_s) 95 assert_invalid :language, 'invalid language', 'abc' 96 end 97 92 98 def test_save__password_encrypted 93 99 @user.confirm_password = true
