railscart 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +3 -0
- data/License.txt +26 -0
- data/Manifest.txt +462 -0
- data/README.txt +1 -0
- data/Rakefile +4 -0
- data/bin/railscart +114 -0
- data/config/hoe.rb +78 -0
- data/config/requirements.rb +19 -0
- data/lib/railscart.rb +5 -0
- data/lib/railscart/version.rb +9 -0
- data/log/debug.log +0 -0
- data/script/destroy +14 -0
- data/script/generate +14 -0
- data/script/txt2html +74 -0
- data/setup.rb +1585 -0
- data/starter-app/README +182 -0
- data/starter-app/Rakefile +10 -0
- data/starter-app/app/controllers/application.rb +14 -0
- data/starter-app/app/helpers/application_helper.rb +3 -0
- data/starter-app/app/models/role.rb +3 -0
- data/starter-app/app/models/tag.rb +37 -0
- data/starter-app/app/models/tagging.rb +16 -0
- data/starter-app/app/models/user.rb +101 -0
- data/starter-app/app/views/layouts/application.rhtml +20 -0
- data/starter-app/config/boot.rb +45 -0
- data/starter-app/config/database.yml +23 -0
- data/starter-app/config/environment.rb +119 -0
- data/starter-app/config/environments/development.rb +21 -0
- data/starter-app/config/environments/production.rb +21 -0
- data/starter-app/config/environments/test.rb +19 -0
- data/starter-app/config/routes.rb +28 -0
- data/starter-app/db/migrate/001_add_sessions.rb +16 -0
- data/starter-app/db/migrate/002_create_tags_and_taggings.rb +28 -0
- data/starter-app/db/migrate/003_railscart_to_version_19.rb +9 -0
- data/starter-app/db/migrate/004_railscart_to_version_20.rb +9 -0
- data/starter-app/db/migrate/005_create_users.rb +17 -0
- data/starter-app/db/migrate/006_create_roles.rb +20 -0
- data/starter-app/db/sample/addresses.yml +29 -0
- data/starter-app/db/sample/categories.yml +35 -0
- data/starter-app/db/sample/countries.yml +4 -0
- data/starter-app/db/sample/line_items.yml +32 -0
- data/starter-app/db/sample/option_groups.yml +16 -0
- data/starter-app/db/sample/option_values.yml +13 -0
- data/starter-app/db/sample/options.yml +3 -0
- data/starter-app/db/sample/orders.yml +17 -0
- data/starter-app/db/sample/products.yml +70 -0
- data/starter-app/db/sample/roles.yml +3 -0
- data/starter-app/db/sample/skus.yml +35 -0
- data/starter-app/db/sample/states.yml +204 -0
- data/starter-app/db/sample/taggings.yml +16 -0
- data/starter-app/db/sample/tags.yml +6 -0
- data/starter-app/db/sample/txns.yml +13 -0
- data/starter-app/db/sample/users.yml +10 -0
- data/starter-app/db/sample/variations.yml +20 -0
- data/starter-app/doc/README_FOR_APP +2 -0
- data/starter-app/lib/authenticated_system.rb +116 -0
- data/starter-app/lib/authenticated_test_helper.rb +10 -0
- data/starter-app/lib/custom_fixtures.rb +7 -0
- data/starter-app/lib/hijacker.rb +78 -0
- data/starter-app/lib/role_requirement_system.rb +142 -0
- data/starter-app/lib/role_requirement_test_helper.rb +86 -0
- data/starter-app/lib/tagging_extensions.rb +104 -0
- data/starter-app/lib/tasks/rc_sample_data.rake +31 -0
- data/starter-app/lib/tasks/sample/images/ror_bag.jpg +0 -0
- data/starter-app/lib/tasks/sample/images/ror_baseball_jersey.jpg +0 -0
- data/starter-app/lib/tasks/sample/images/ror_jr_spaghetti.jpg +0 -0
- data/starter-app/lib/tasks/sample/images/ror_mug.jpg +0 -0
- data/starter-app/lib/tasks/sample/images/ror_ringer_tshirt.jpg +0 -0
- data/starter-app/lib/tasks/sample/images/ror_stein.jpg +0 -0
- data/starter-app/lib/tasks/sample/images/ror_tote.jpg +0 -0
- data/starter-app/public/.htaccess +40 -0
- data/starter-app/public/404.html +30 -0
- data/starter-app/public/500.html +30 -0
- data/starter-app/public/dispatch.cgi +10 -0
- data/starter-app/public/dispatch.fcgi +24 -0
- data/starter-app/public/dispatch.rb +10 -0
- data/starter-app/public/favicon.ico +0 -0
- data/starter-app/public/images/rails.png +0 -0
- data/starter-app/public/index.html +277 -0
- data/starter-app/public/javascripts/application.js +2 -0
- data/starter-app/public/javascripts/controls.js +833 -0
- data/starter-app/public/javascripts/dragdrop.js +942 -0
- data/starter-app/public/javascripts/effects.js +1088 -0
- data/starter-app/public/javascripts/prototype.js +4184 -0
- data/starter-app/public/robots.txt +1 -0
- data/starter-app/public/stylesheets/application.css +186 -0
- data/starter-app/public/stylesheets/cart/_controller.css +4 -0
- data/starter-app/public/stylesheets/checkout/_controller.css +13 -0
- data/starter-app/script/about +3 -0
- data/starter-app/script/breakpointer +3 -0
- data/starter-app/script/console +3 -0
- data/starter-app/script/destroy +3 -0
- data/starter-app/script/generate +3 -0
- data/starter-app/script/performance/benchmarker +3 -0
- data/starter-app/script/performance/profiler +3 -0
- data/starter-app/script/plugin +3 -0
- data/starter-app/script/process/inspector +3 -0
- data/starter-app/script/process/reaper +3 -0
- data/starter-app/script/process/spawner +3 -0
- data/starter-app/script/runner +3 -0
- data/starter-app/script/server +3 -0
- data/starter-app/test/fixtures/users.yml +7 -0
- data/starter-app/test/test_helper.rb +28 -0
- data/starter-app/test/unit/user_test.rb +8 -0
- data/starter-app/vendor/plugins/acts_as_list/README +23 -0
- data/starter-app/vendor/plugins/acts_as_list/init.rb +3 -0
- data/starter-app/vendor/plugins/acts_as_list/lib/active_record/acts/list.rb +256 -0
- data/starter-app/vendor/plugins/acts_as_list/test/list_test.rb +332 -0
- data/starter-app/vendor/plugins/acts_as_tree/README +26 -0
- data/starter-app/vendor/plugins/acts_as_tree/Rakefile +22 -0
- data/starter-app/vendor/plugins/acts_as_tree/init.rb +1 -0
- data/starter-app/vendor/plugins/acts_as_tree/lib/active_record/acts/tree.rb +96 -0
- data/starter-app/vendor/plugins/acts_as_tree/test/abstract_unit.rb +0 -0
- data/starter-app/vendor/plugins/acts_as_tree/test/acts_as_tree_test.rb +219 -0
- data/starter-app/vendor/plugins/acts_as_tree/test/database.yml +0 -0
- data/starter-app/vendor/plugins/acts_as_tree/test/fixtures/mixin.rb +0 -0
- data/starter-app/vendor/plugins/acts_as_tree/test/fixtures/mixins.yml +0 -0
- data/starter-app/vendor/plugins/acts_as_tree/test/schema.rb +0 -0
- data/starter-app/vendor/plugins/calendar_date_select/CHANGELOG +170 -0
- data/starter-app/vendor/plugins/calendar_date_select/MIT-LICENSE +20 -0
- data/starter-app/vendor/plugins/calendar_date_select/README +10 -0
- data/starter-app/vendor/plugins/calendar_date_select/init.rb +15 -0
- data/starter-app/vendor/plugins/calendar_date_select/js_test/functional/.tmp_cds_test.html +306 -0
- data/starter-app/vendor/plugins/calendar_date_select/js_test/functional/cds_test.html +324 -0
- data/starter-app/vendor/plugins/calendar_date_select/js_test/prototype.js +4184 -0
- data/starter-app/vendor/plugins/calendar_date_select/js_test/test.css +40 -0
- data/starter-app/vendor/plugins/calendar_date_select/js_test/unit/cds_helper_methods.html +46 -0
- data/starter-app/vendor/plugins/calendar_date_select/js_test/unittest.js +564 -0
- data/starter-app/vendor/plugins/calendar_date_select/lib/calendar_date_select.rb +192 -0
- data/starter-app/vendor/plugins/calendar_date_select/lib/includes_helper.rb +22 -0
- data/starter-app/vendor/plugins/calendar_date_select/public/images/calendar_date_select/calendar.gif +0 -0
- data/starter-app/vendor/plugins/calendar_date_select/public/javascripts/calendar_date_select/calendar_date_select.js +439 -0
- data/starter-app/vendor/plugins/calendar_date_select/public/javascripts/calendar_date_select/format_american.js +34 -0
- data/starter-app/vendor/plugins/calendar_date_select/public/javascripts/calendar_date_select/format_euro_24hr.js +7 -0
- data/starter-app/vendor/plugins/calendar_date_select/public/javascripts/calendar_date_select/format_finnish.js +24 -0
- data/starter-app/vendor/plugins/calendar_date_select/public/javascripts/calendar_date_select/format_hyphen_ampm.js +36 -0
- data/starter-app/vendor/plugins/calendar_date_select/public/javascripts/calendar_date_select/format_italian.js +24 -0
- data/starter-app/vendor/plugins/calendar_date_select/public/javascripts/calendar_date_select/locale/fi.js +10 -0
- data/starter-app/vendor/plugins/calendar_date_select/public/stylesheets/calendar_date_select/blue.css +130 -0
- data/starter-app/vendor/plugins/calendar_date_select/public/stylesheets/calendar_date_select/default.css +135 -0
- data/starter-app/vendor/plugins/calendar_date_select/public/stylesheets/calendar_date_select/plain.css +128 -0
- data/starter-app/vendor/plugins/calendar_date_select/public/stylesheets/calendar_date_select/red.css +135 -0
- data/starter-app/vendor/plugins/calendar_date_select/public/stylesheets/calendar_date_select/silver.css +133 -0
- data/starter-app/vendor/plugins/calendar_date_select/test/functional/calendar_date_select_test.rb +95 -0
- data/starter-app/vendor/plugins/calendar_date_select/test/functional/helper_methods_test.rb +15 -0
- data/starter-app/vendor/plugins/calendar_date_select/test/test_helper.rb +26 -0
- data/starter-app/vendor/plugins/engines/CHANGELOG +258 -0
- data/starter-app/vendor/plugins/engines/MIT-LICENSE +21 -0
- data/starter-app/vendor/plugins/engines/README +63 -0
- data/starter-app/vendor/plugins/engines/Rakefile +32 -0
- data/starter-app/vendor/plugins/engines/about.yml +7 -0
- data/starter-app/vendor/plugins/engines/boot.rb +18 -0
- data/starter-app/vendor/plugins/engines/generators/plugin_migration/USAGE +45 -0
- data/starter-app/vendor/plugins/engines/generators/plugin_migration/plugin_migration_generator.rb +79 -0
- data/starter-app/vendor/plugins/engines/generators/plugin_migration/templates/plugin_migration.erb +13 -0
- data/starter-app/vendor/plugins/engines/init.rb +2 -0
- data/starter-app/vendor/plugins/engines/lib/engines.rb +169 -0
- data/starter-app/vendor/plugins/engines/lib/engines/assets.rb +38 -0
- data/starter-app/vendor/plugins/engines/lib/engines/plugin.rb +125 -0
- data/starter-app/vendor/plugins/engines/lib/engines/plugin/list.rb +30 -0
- data/starter-app/vendor/plugins/engines/lib/engines/plugin/loader.rb +18 -0
- data/starter-app/vendor/plugins/engines/lib/engines/plugin/locator.rb +11 -0
- data/starter-app/vendor/plugins/engines/lib/engines/plugin/migrator.rb +60 -0
- data/starter-app/vendor/plugins/engines/lib/engines/rails_extensions/action_mailer.rb +85 -0
- data/starter-app/vendor/plugins/engines/lib/engines/rails_extensions/active_record.rb +24 -0
- data/starter-app/vendor/plugins/engines/lib/engines/rails_extensions/asset_helpers.rb +119 -0
- data/starter-app/vendor/plugins/engines/lib/engines/rails_extensions/dependencies.rb +145 -0
- data/starter-app/vendor/plugins/engines/lib/engines/rails_extensions/migrations.rb +161 -0
- data/starter-app/vendor/plugins/engines/lib/engines/rails_extensions/rails.rb +11 -0
- data/starter-app/vendor/plugins/engines/lib/engines/rails_extensions/routing.rb +84 -0
- data/starter-app/vendor/plugins/engines/lib/engines/testing.rb +87 -0
- data/starter-app/vendor/plugins/engines/tasks/engines.rake +148 -0
- data/starter-app/vendor/plugins/in_place_editing/README +14 -0
- data/starter-app/vendor/plugins/in_place_editing/Rakefile +22 -0
- data/starter-app/vendor/plugins/in_place_editing/init.rb +2 -0
- data/starter-app/vendor/plugins/in_place_editing/lib/in_place_editing.rb +25 -0
- data/starter-app/vendor/plugins/in_place_editing/lib/in_place_macros_helper.rb +71 -0
- data/starter-app/vendor/plugins/in_place_editing/test/in_place_editing_test.rb +69 -0
- data/starter-app/vendor/plugins/paginating_find/CHANGELOG +117 -0
- data/starter-app/vendor/plugins/paginating_find/README +89 -0
- data/starter-app/vendor/plugins/paginating_find/init.rb +2 -0
- data/starter-app/vendor/plugins/paginating_find/lib/paginating_find.rb +135 -0
- data/starter-app/vendor/plugins/paginating_find/lib/paging_enumerator.rb +158 -0
- data/starter-app/vendor/plugins/paginating_find/lib/paging_helper.rb +47 -0
- data/starter-app/vendor/plugins/paginating_find/test_app/Rakefile +10 -0
- data/starter-app/vendor/plugins/paginating_find/test_app/app/controllers/application.rb +2 -0
- data/starter-app/vendor/plugins/paginating_find/test_app/config/boot.rb +44 -0
- data/starter-app/vendor/plugins/paginating_find/test_app/config/database.yml +6 -0
- data/starter-app/vendor/plugins/paginating_find/test_app/config/environment.rb +53 -0
- data/starter-app/vendor/plugins/paginating_find/test_app/config/environments/test.rb +19 -0
- data/starter-app/vendor/plugins/paginating_find/test_app/config/routes.rb +22 -0
- data/starter-app/vendor/plugins/paginating_find/test_app/db/schema.rb +16 -0
- data/starter-app/vendor/plugins/paginating_find/test_app/script/breakpointer +3 -0
- data/starter-app/vendor/plugins/paginating_find/test_app/script/console +3 -0
- data/starter-app/vendor/plugins/paginating_find/test_app/test/fixtures/articles.yml +19 -0
- data/starter-app/vendor/plugins/paginating_find/test_app/test/fixtures/authors.yml +7 -0
- data/starter-app/vendor/plugins/paginating_find/test_app/test/fixtures/edits.yml +11 -0
- data/starter-app/vendor/plugins/paginating_find/test_app/test/fixtures/models.rb +18 -0
- data/starter-app/vendor/plugins/paginating_find/test_app/test/test_helper.rb +33 -0
- data/starter-app/vendor/plugins/paginating_find/test_app/test/unit/abstract_test.rb +7 -0
- data/starter-app/vendor/plugins/paginating_find/test_app/test/unit/group_test.rb +40 -0
- data/starter-app/vendor/plugins/paginating_find/test_app/test/unit/paginating_find_test.rb +194 -0
- data/starter-app/vendor/plugins/paginating_find/test_app/test/unit/paging_enumerator_test.rb +143 -0
- data/starter-app/vendor/plugins/railscart/.rakeTasks +7 -0
- data/starter-app/vendor/plugins/railscart/CHANGELOG +1 -0
- data/starter-app/vendor/plugins/railscart/LICENSE +26 -0
- data/starter-app/vendor/plugins/railscart/README +2 -0
- data/starter-app/vendor/plugins/railscart/Rakefile +10 -0
- data/starter-app/vendor/plugins/railscart/VERSION +1 -0
- data/starter-app/vendor/plugins/railscart/app/controllers/account_controller.rb +48 -0
- data/starter-app/vendor/plugins/railscart/app/controllers/admin/base_controller.rb +7 -0
- data/starter-app/vendor/plugins/railscart/app/controllers/admin/categories_controller.rb +107 -0
- data/starter-app/vendor/plugins/railscart/app/controllers/admin/option_groups_controller.rb +36 -0
- data/starter-app/vendor/plugins/railscart/app/controllers/admin/option_values_controller.rb +42 -0
- data/starter-app/vendor/plugins/railscart/app/controllers/admin/options_controller.rb +52 -0
- data/starter-app/vendor/plugins/railscart/app/controllers/admin/orders_controller.rb +194 -0
- data/starter-app/vendor/plugins/railscart/app/controllers/admin/overview_controller.rb +14 -0
- data/starter-app/vendor/plugins/railscart/app/controllers/admin/products_controller.rb +147 -0
- data/starter-app/vendor/plugins/railscart/app/controllers/admin/reports_controller.rb +53 -0
- data/starter-app/vendor/plugins/railscart/app/controllers/admin/users_controller.rb +45 -0
- data/starter-app/vendor/plugins/railscart/app/controllers/admin/variations_controller.rb +73 -0
- data/starter-app/vendor/plugins/railscart/app/controllers/cart_controller.rb +45 -0
- data/starter-app/vendor/plugins/railscart/app/controllers/checkout_controller.rb +179 -0
- data/starter-app/vendor/plugins/railscart/app/controllers/rails_cart/base_controller.rb +41 -0
- data/starter-app/vendor/plugins/railscart/app/controllers/store_controller.rb +20 -0
- data/starter-app/vendor/plugins/railscart/app/helpers/account_helper.rb +2 -0
- data/starter-app/vendor/plugins/railscart/app/helpers/admin/base_helper.rb +15 -0
- data/starter-app/vendor/plugins/railscart/app/helpers/admin/categories_helper.rb +3 -0
- data/starter-app/vendor/plugins/railscart/app/helpers/admin/option_groups_helper.rb +2 -0
- data/starter-app/vendor/plugins/railscart/app/helpers/admin/option_values_helper.rb +2 -0
- data/starter-app/vendor/plugins/railscart/app/helpers/admin/orders_helper.rb +11 -0
- data/starter-app/vendor/plugins/railscart/app/helpers/admin/overview_helper.rb +12 -0
- data/starter-app/vendor/plugins/railscart/app/helpers/admin/users_helper.rb +2 -0
- data/starter-app/vendor/plugins/railscart/app/helpers/admin/variations_helper.rb +2 -0
- data/starter-app/vendor/plugins/railscart/app/helpers/cart_helper.rb +6 -0
- data/starter-app/vendor/plugins/railscart/app/helpers/checkout_helper.rb +17 -0
- data/starter-app/vendor/plugins/railscart/app/helpers/rails_cart/base_helper.rb +67 -0
- data/starter-app/vendor/plugins/railscart/app/helpers/search_helper.rb +10 -0
- data/starter-app/vendor/plugins/railscart/app/helpers/store_helper.rb +3 -0
- data/starter-app/vendor/plugins/railscart/app/models/address.rb +17 -0
- data/starter-app/vendor/plugins/railscart/app/models/cart.rb +37 -0
- data/starter-app/vendor/plugins/railscart/app/models/cart_item.rb +28 -0
- data/starter-app/vendor/plugins/railscart/app/models/category.rb +66 -0
- data/starter-app/vendor/plugins/railscart/app/models/country.rb +3 -0
- data/starter-app/vendor/plugins/railscart/app/models/line_item.rb +24 -0
- data/starter-app/vendor/plugins/railscart/app/models/option.rb +4 -0
- data/starter-app/vendor/plugins/railscart/app/models/option_group.rb +6 -0
- data/starter-app/vendor/plugins/railscart/app/models/option_value.rb +4 -0
- data/starter-app/vendor/plugins/railscart/app/models/order.rb +86 -0
- data/starter-app/vendor/plugins/railscart/app/models/order_mailer.rb +20 -0
- data/starter-app/vendor/plugins/railscart/app/models/payment.rb +49 -0
- data/starter-app/vendor/plugins/railscart/app/models/product.rb +76 -0
- data/starter-app/vendor/plugins/railscart/app/models/search_criteria.rb +27 -0
- data/starter-app/vendor/plugins/railscart/app/models/sku.rb +7 -0
- data/starter-app/vendor/plugins/railscart/app/models/state.rb +3 -0
- data/starter-app/vendor/plugins/railscart/app/models/tax_treatment.rb +2 -0
- data/starter-app/vendor/plugins/railscart/app/models/txn.rb +7 -0
- data/starter-app/vendor/plugins/railscart/app/models/variation.rb +5 -0
- data/starter-app/vendor/plugins/railscart/app/views/account/index.rhtml +3 -0
- data/starter-app/vendor/plugins/railscart/app/views/account/login.rhtml +12 -0
- data/starter-app/vendor/plugins/railscart/app/views/account/signup.rhtml +16 -0
- data/starter-app/vendor/plugins/railscart/app/views/admin/categories/_form.rhtml +27 -0
- data/starter-app/vendor/plugins/railscart/app/views/admin/categories/edit.rhtml +9 -0
- data/starter-app/vendor/plugins/railscart/app/views/admin/categories/list.rhtml +47 -0
- data/starter-app/vendor/plugins/railscart/app/views/admin/categories/new.rhtml +8 -0
- data/starter-app/vendor/plugins/railscart/app/views/admin/option_groups/_form.rhtml +19 -0
- data/starter-app/vendor/plugins/railscart/app/views/admin/option_groups/new.rhtml +8 -0
- data/starter-app/vendor/plugins/railscart/app/views/admin/option_values/_form.rhtml +8 -0
- data/starter-app/vendor/plugins/railscart/app/views/admin/option_values/edit.rhtml +8 -0
- data/starter-app/vendor/plugins/railscart/app/views/admin/option_values/list.rhtml +22 -0
- data/starter-app/vendor/plugins/railscart/app/views/admin/option_values/new.rhtml +8 -0
- data/starter-app/vendor/plugins/railscart/app/views/admin/options/_form.rhtml +7 -0
- data/starter-app/vendor/plugins/railscart/app/views/admin/options/edit.rhtml +26 -0
- data/starter-app/vendor/plugins/railscart/app/views/admin/options/list.rhtml +23 -0
- data/starter-app/vendor/plugins/railscart/app/views/admin/options/new.rhtml +8 -0
- data/starter-app/vendor/plugins/railscart/app/views/admin/orders/_address.rhtml +37 -0
- data/starter-app/vendor/plugins/railscart/app/views/admin/orders/index.rhtml +99 -0
- data/starter-app/vendor/plugins/railscart/app/views/admin/orders/show.rhtml +43 -0
- data/starter-app/vendor/plugins/railscart/app/views/admin/overview/index.rhtml +0 -0
- data/starter-app/vendor/plugins/railscart/app/views/admin/products/_form.rhtml +55 -0
- data/starter-app/vendor/plugins/railscart/app/views/admin/products/_menu.rhtml +8 -0
- data/starter-app/vendor/plugins/railscart/app/views/admin/products/_new_variation.rhtml +0 -0
- data/starter-app/vendor/plugins/railscart/app/views/admin/products/edit.rhtml +8 -0
- data/starter-app/vendor/plugins/railscart/app/views/admin/products/index.rhtml +66 -0
- data/starter-app/vendor/plugins/railscart/app/views/admin/products/new.rhtml +13 -0
- data/starter-app/vendor/plugins/railscart/app/views/admin/products/show.rhtml +26 -0
- data/starter-app/vendor/plugins/railscart/app/views/admin/reports/index.rhtml +29 -0
- data/starter-app/vendor/plugins/railscart/app/views/admin/reports/sales_total.rhtml +28 -0
- data/starter-app/vendor/plugins/railscart/app/views/admin/users/_form.rhtml +29 -0
- data/starter-app/vendor/plugins/railscart/app/views/admin/users/_menu.rhtml +5 -0
- data/starter-app/vendor/plugins/railscart/app/views/admin/users/edit.rhtml +8 -0
- data/starter-app/vendor/plugins/railscart/app/views/admin/users/index.rhtml +26 -0
- data/starter-app/vendor/plugins/railscart/app/views/admin/users/new.rhtml +6 -0
- data/starter-app/vendor/plugins/railscart/app/views/admin/users/show.rhtml +9 -0
- data/starter-app/vendor/plugins/railscart/app/views/admin/variations/_form.rhtml +33 -0
- data/starter-app/vendor/plugins/railscart/app/views/admin/variations/_option_values.rhtml +5 -0
- data/starter-app/vendor/plugins/railscart/app/views/admin/variations/list.rhtml +23 -0
- data/starter-app/vendor/plugins/railscart/app/views/admin/variations/new.rhtml +14 -0
- data/starter-app/vendor/plugins/railscart/app/views/cart/index.rhtml +49 -0
- data/starter-app/vendor/plugins/railscart/app/views/checkout/_address.rhtml +51 -0
- data/starter-app/vendor/plugins/railscart/app/views/checkout/_address_ro.rhtml +18 -0
- data/starter-app/vendor/plugins/railscart/app/views/checkout/_cart_item.rhtml +5 -0
- data/starter-app/vendor/plugins/railscart/app/views/checkout/_extra.rhtml +1 -0
- data/starter-app/vendor/plugins/railscart/app/views/checkout/addresses.rhtml +49 -0
- data/starter-app/vendor/plugins/railscart/app/views/checkout/cvv.rhtml +15 -0
- data/starter-app/vendor/plugins/railscart/app/views/checkout/empty_cart.rhtml +4 -0
- data/starter-app/vendor/plugins/railscart/app/views/checkout/final_confirmation.rhtml +92 -0
- data/starter-app/vendor/plugins/railscart/app/views/checkout/incomplete.rhtml +7 -0
- data/starter-app/vendor/plugins/railscart/app/views/checkout/thank_you.rhtml +11 -0
- data/starter-app/vendor/plugins/railscart/app/views/layouts/admin.rhtml +69 -0
- data/starter-app/vendor/plugins/railscart/app/views/layouts/products.rhtml +20 -0
- data/starter-app/vendor/plugins/railscart/app/views/layouts/simple.rhtml +37 -0
- data/starter-app/vendor/plugins/railscart/app/views/order_mailer/cancel.rhtml +15 -0
- data/starter-app/vendor/plugins/railscart/app/views/order_mailer/confirm.rhtml +18 -0
- data/starter-app/vendor/plugins/railscart/app/views/shared/_order_details.rhtml +35 -0
- data/starter-app/vendor/plugins/railscart/app/views/shared/_paginate.rhtml +34 -0
- data/starter-app/vendor/plugins/railscart/app/views/shared/_report_criteria.rhtml +32 -0
- data/starter-app/vendor/plugins/railscart/app/views/shared/_tax_treatments.rhtml +12 -0
- data/starter-app/vendor/plugins/railscart/app/views/shared/_variations.rhtml +60 -0
- data/starter-app/vendor/plugins/railscart/app/views/store/_menu.rhtml +7 -0
- data/starter-app/vendor/plugins/railscart/app/views/store/_products.rhtml +10 -0
- data/starter-app/vendor/plugins/railscart/app/views/store/list.rhtml +16 -0
- data/starter-app/vendor/plugins/railscart/app/views/store/show.rhtml +71 -0
- data/starter-app/vendor/plugins/railscart/assets/.htaccess +40 -0
- data/starter-app/vendor/plugins/railscart/assets/404.html +30 -0
- data/starter-app/vendor/plugins/railscart/assets/500.html +30 -0
- data/starter-app/vendor/plugins/railscart/assets/dispatch.cgi +10 -0
- data/starter-app/vendor/plugins/railscart/assets/dispatch.fcgi +24 -0
- data/starter-app/vendor/plugins/railscart/assets/dispatch.rb +10 -0
- data/starter-app/vendor/plugins/railscart/assets/favicon.ico +0 -0
- data/starter-app/vendor/plugins/railscart/assets/images/amex_cid.gif +0 -0
- data/starter-app/vendor/plugins/railscart/assets/images/creditcard.gif +0 -0
- data/starter-app/vendor/plugins/railscart/assets/images/discover_cid.gif +0 -0
- data/starter-app/vendor/plugins/railscart/assets/images/master_cid.jpg +0 -0
- data/starter-app/vendor/plugins/railscart/assets/images/products/ror_bag.jpg +0 -0
- data/starter-app/vendor/plugins/railscart/assets/images/products/ror_baseball_jersey.jpg +0 -0
- data/starter-app/vendor/plugins/railscart/assets/images/products/ror_jr_spaghetti.jpg +0 -0
- data/starter-app/vendor/plugins/railscart/assets/images/products/ror_mug.jpg +0 -0
- data/starter-app/vendor/plugins/railscart/assets/images/products/ror_ringer_tshirt.jpg +0 -0
- data/starter-app/vendor/plugins/railscart/assets/images/products/ror_stein.jpg +0 -0
- data/starter-app/vendor/plugins/railscart/assets/images/products/ror_tote.jpg +0 -0
- data/starter-app/vendor/plugins/railscart/assets/images/rails.png +0 -0
- data/starter-app/vendor/plugins/railscart/assets/images/railscart/progress.gif +0 -0
- data/starter-app/vendor/plugins/railscart/assets/images/railscart/railscart_logo142x65.gif +0 -0
- data/starter-app/vendor/plugins/railscart/assets/images/railscart/railscart_logo245x112.gif +0 -0
- data/starter-app/vendor/plugins/railscart/assets/images/railscart/spinner.gif +0 -0
- data/starter-app/vendor/plugins/railscart/assets/images/spinner.gif +0 -0
- data/starter-app/vendor/plugins/railscart/assets/images/visa_cid.gif +0 -0
- data/starter-app/vendor/plugins/railscart/assets/javascripts/application.js +2 -0
- data/starter-app/vendor/plugins/railscart/assets/javascripts/controls.js +833 -0
- data/starter-app/vendor/plugins/railscart/assets/javascripts/dragdrop.js +942 -0
- data/starter-app/vendor/plugins/railscart/assets/javascripts/effects.js +1088 -0
- data/starter-app/vendor/plugins/railscart/assets/javascripts/lowpro.js +307 -0
- data/starter-app/vendor/plugins/railscart/assets/javascripts/prototype.js +2515 -0
- data/starter-app/vendor/plugins/railscart/assets/robots.txt +1 -0
- data/starter-app/vendor/plugins/railscart/assets/stylesheets/cart/_controller.css +71 -0
- data/starter-app/vendor/plugins/railscart/assets/stylesheets/checkout/_controller.css +31 -0
- data/starter-app/vendor/plugins/railscart/assets/stylesheets/fullscreen.css +63 -0
- data/starter-app/vendor/plugins/railscart/assets/stylesheets/orders/_controller.css +3 -0
- data/starter-app/vendor/plugins/railscart/assets/stylesheets/products/_controller.css +13 -0
- data/starter-app/vendor/plugins/railscart/assets/stylesheets/railscart-admin.css +295 -0
- data/starter-app/vendor/plugins/railscart/assets/stylesheets/railscart.css +66 -0
- data/starter-app/vendor/plugins/railscart/assets/stylesheets/store/_controller.css +23 -0
- data/starter-app/vendor/plugins/railscart/db/migrate/001_create_addresses.rb +22 -0
- data/starter-app/vendor/plugins/railscart/db/migrate/002_create_cart_items.rb +14 -0
- data/starter-app/vendor/plugins/railscart/db/migrate/003_create_carts.rb +12 -0
- data/starter-app/vendor/plugins/railscart/db/migrate/004_create_categories.rb +15 -0
- data/starter-app/vendor/plugins/railscart/db/migrate/005_create_categories_products.rb +12 -0
- data/starter-app/vendor/plugins/railscart/db/migrate/006_create_line_items.rb +17 -0
- data/starter-app/vendor/plugins/railscart/db/migrate/007_create_option_groups.rb +12 -0
- data/starter-app/vendor/plugins/railscart/db/migrate/008_create_option_values.rb +11 -0
- data/starter-app/vendor/plugins/railscart/db/migrate/009_create_options.rb +11 -0
- data/starter-app/vendor/plugins/railscart/db/migrate/010_create_orders.rb +24 -0
- data/starter-app/vendor/plugins/railscart/db/migrate/011_create_products.rb +22 -0
- data/starter-app/vendor/plugins/railscart/db/migrate/012_ignore_users.rb +9 -0
- data/starter-app/vendor/plugins/railscart/db/migrate/013_create_txns.rb +21 -0
- data/starter-app/vendor/plugins/railscart/db/migrate/014_ignore_roles.rb +9 -0
- data/starter-app/vendor/plugins/railscart/db/migrate/015_create_variations.rb +14 -0
- data/starter-app/vendor/plugins/railscart/db/migrate/016_create_tax_treatments.rb +23 -0
- data/starter-app/vendor/plugins/railscart/db/migrate/017_create_skus.rb +13 -0
- data/starter-app/vendor/plugins/railscart/db/migrate/018_create_countries.rb +11 -0
- data/starter-app/vendor/plugins/railscart/db/migrate/019_create_states.rb +13 -0
- data/starter-app/vendor/plugins/railscart/db/migrate/020_modify_users.rb +9 -0
- data/starter-app/vendor/plugins/railscart/init.rb +16 -0
- data/starter-app/vendor/plugins/railscart/install.rb +3 -0
- data/starter-app/vendor/plugins/railscart/lib/constants/enumerable_constants.rb +207 -0
- data/starter-app/vendor/plugins/railscart/lib/format.rb +12 -0
- data/starter-app/vendor/plugins/railscart/lib/gateway/bogus_gateway.rb +63 -0
- data/starter-app/vendor/plugins/railscart/lib/shipping/flat_rate.rb +10 -0
- data/starter-app/vendor/plugins/railscart/lib/tasks/rc_bootstrap.rake +24 -0
- data/starter-app/vendor/plugins/railscart/lib/tax/sales_tax.rb +26 -0
- data/starter-app/vendor/plugins/railscart/routes.rb +3 -0
- data/starter-app/vendor/plugins/railscart/script/about +3 -0
- data/starter-app/vendor/plugins/railscart/script/breakpointer +3 -0
- data/starter-app/vendor/plugins/railscart/script/console +3 -0
- data/starter-app/vendor/plugins/railscart/script/destroy +3 -0
- data/starter-app/vendor/plugins/railscart/script/generate +3 -0
- data/starter-app/vendor/plugins/railscart/script/performance/benchmarker +3 -0
- data/starter-app/vendor/plugins/railscart/script/performance/profiler +3 -0
- data/starter-app/vendor/plugins/railscart/script/plugin +3 -0
- data/starter-app/vendor/plugins/railscart/script/process/inspector +3 -0
- data/starter-app/vendor/plugins/railscart/script/process/reaper +3 -0
- data/starter-app/vendor/plugins/railscart/script/process/spawner +3 -0
- data/starter-app/vendor/plugins/railscart/script/runner +3 -0
- data/starter-app/vendor/plugins/railscart/script/server +3 -0
- data/starter-app/vendor/plugins/railscart/test/fixtures/addresses.yml +29 -0
- data/starter-app/vendor/plugins/railscart/test/fixtures/categories.yml +40 -0
- data/starter-app/vendor/plugins/railscart/test/fixtures/line_items.yml +32 -0
- data/starter-app/vendor/plugins/railscart/test/fixtures/orders.yml +17 -0
- data/starter-app/vendor/plugins/railscart/test/fixtures/products.yml +63 -0
- data/starter-app/vendor/plugins/railscart/test/fixtures/products_tags.yml +10 -0
- data/starter-app/vendor/plugins/railscart/test/fixtures/roles.yml +6 -0
- data/starter-app/vendor/plugins/railscart/test/fixtures/roles_users.yml +3 -0
- data/starter-app/vendor/plugins/railscart/test/fixtures/skus.yml +5 -0
- data/starter-app/vendor/plugins/railscart/test/fixtures/tags.yml +7 -0
- data/starter-app/vendor/plugins/railscart/test/fixtures/tax_treatments.yml +7 -0
- data/starter-app/vendor/plugins/railscart/test/fixtures/txns.yml +13 -0
- data/starter-app/vendor/plugins/railscart/test/fixtures/users.yml +40 -0
- data/starter-app/vendor/plugins/railscart/test/fixtures/variations.yml +16 -0
- data/starter-app/vendor/plugins/railscart/test/functional/account_controller_test.rb +129 -0
- data/starter-app/vendor/plugins/railscart/test/functional/admin/base_controller_test.rb +18 -0
- data/starter-app/vendor/plugins/railscart/test/functional/admin/option_groups_controller_test.rb +18 -0
- data/starter-app/vendor/plugins/railscart/test/functional/admin/option_values_controller_test.rb +18 -0
- data/starter-app/vendor/plugins/railscart/test/functional/admin/orders_controller_test.rb +18 -0
- data/starter-app/vendor/plugins/railscart/test/functional/admin/overview_controller_test.rb +18 -0
- data/starter-app/vendor/plugins/railscart/test/functional/admin/products_controller_test.rb +125 -0
- data/starter-app/vendor/plugins/railscart/test/functional/admin/users_controller_test.rb +58 -0
- data/starter-app/vendor/plugins/railscart/test/functional/admin/variations_controller_test.rb +18 -0
- data/starter-app/vendor/plugins/railscart/test/functional/application_controller_test.rb +30 -0
- data/starter-app/vendor/plugins/railscart/test/functional/cart_controller_test.rb +76 -0
- data/starter-app/vendor/plugins/railscart/test/functional/checkout_controller_test.rb +20 -0
- data/starter-app/vendor/plugins/railscart/test/integration/authentication_test.rb +53 -0
- data/starter-app/vendor/plugins/railscart/test/integration/product_admin_test.rb +135 -0
- data/starter-app/vendor/plugins/railscart/test/integration/user_stories_test.rb +59 -0
- data/starter-app/vendor/plugins/railscart/test/integration/variations_test.rb +24 -0
- data/starter-app/vendor/plugins/railscart/test/test_helper.rb +45 -0
- data/starter-app/vendor/plugins/railscart/test/unit/address_test.rb +10 -0
- data/starter-app/vendor/plugins/railscart/test/unit/cart_item_test.rb +55 -0
- data/starter-app/vendor/plugins/railscart/test/unit/cart_test.rb +35 -0
- data/starter-app/vendor/plugins/railscart/test/unit/category_test.rb +52 -0
- data/starter-app/vendor/plugins/railscart/test/unit/line_item_test.rb +61 -0
- data/starter-app/vendor/plugins/railscart/test/unit/option_group_test.rb +12 -0
- data/starter-app/vendor/plugins/railscart/test/unit/order_test.rb +49 -0
- data/starter-app/vendor/plugins/railscart/test/unit/product_test.rb +107 -0
- data/starter-app/vendor/plugins/railscart/test/unit/role_test.rb +10 -0
- data/starter-app/vendor/plugins/railscart/test/unit/sales_tax_test.rb +46 -0
- data/starter-app/vendor/plugins/railscart/test/unit/sku_test.rb +10 -0
- data/starter-app/vendor/plugins/railscart/test/unit/tag_test.rb +9 -0
- data/starter-app/vendor/plugins/railscart/test/unit/tax_treatment_test.rb +10 -0
- data/starter-app/vendor/plugins/railscart/test/unit/txn_test.rb +10 -0
- data/starter-app/vendor/plugins/railscart/test/unit/variation_test.rb +9 -0
- data/starter-app/vendor/plugins/railscart/uninstall.rb +1 -0
- data/tasks/deployment.rake +34 -0
- data/tasks/environment.rake +7 -0
- data/tasks/website.rake +17 -0
- data/test/test_helper.rb +2 -0
- data/test/test_railscart.rb +11 -0
- data/website/index.html +93 -0
- data/website/index.txt +39 -0
- data/website/javascripts/rounded_corners_lite.inc.js +285 -0
- data/website/stylesheets/screen.css +138 -0
- data/website/template.rhtml +48 -0
- metadata +557 -0
@@ -0,0 +1,116 @@
|
|
1
|
+
module AuthenticatedSystem
|
2
|
+
protected
|
3
|
+
# Returns true or false if the user is logged in.
|
4
|
+
# Preloads @current_user with the user model if they're logged in.
|
5
|
+
def logged_in?
|
6
|
+
current_user != :false
|
7
|
+
end
|
8
|
+
|
9
|
+
# Accesses the current user from the session. Set it to :false if login fails
|
10
|
+
# so that future calls do not hit the database.
|
11
|
+
def current_user
|
12
|
+
@current_user ||= (login_from_session || login_from_basic_auth || login_from_cookie || :false)
|
13
|
+
end
|
14
|
+
|
15
|
+
# Store the given user id in the session.
|
16
|
+
def current_user=(new_user)
|
17
|
+
session[:user_id] = (new_user.nil? || new_user.is_a?(Symbol)) ? nil : new_user.id
|
18
|
+
@current_user = new_user || :false
|
19
|
+
end
|
20
|
+
|
21
|
+
# Check if the user is authorized
|
22
|
+
#
|
23
|
+
# Override this method in your controllers if you want to restrict access
|
24
|
+
# to only a few actions or if you want to check if the user
|
25
|
+
# has the correct rights.
|
26
|
+
#
|
27
|
+
# Example:
|
28
|
+
#
|
29
|
+
# # only allow nonbobs
|
30
|
+
# def authorized?
|
31
|
+
# current_user.login != "bob"
|
32
|
+
# end
|
33
|
+
def authorized?
|
34
|
+
logged_in?
|
35
|
+
end
|
36
|
+
|
37
|
+
# Filter method to enforce a login requirement.
|
38
|
+
#
|
39
|
+
# To require logins for all actions, use this in your controllers:
|
40
|
+
#
|
41
|
+
# before_filter :login_required
|
42
|
+
#
|
43
|
+
# To require logins for specific actions, use this in your controllers:
|
44
|
+
#
|
45
|
+
# before_filter :login_required, :only => [ :edit, :update ]
|
46
|
+
#
|
47
|
+
# To skip this in a subclassed controller:
|
48
|
+
#
|
49
|
+
# skip_before_filter :login_required
|
50
|
+
#
|
51
|
+
def login_required
|
52
|
+
authorized? || access_denied
|
53
|
+
end
|
54
|
+
|
55
|
+
# Redirect as appropriate when an access request fails.
|
56
|
+
#
|
57
|
+
# The default action is to redirect to the login screen.
|
58
|
+
#
|
59
|
+
# Override this method in your controllers if you want to have special
|
60
|
+
# behavior in case the user is not authorized
|
61
|
+
# to access the requested action. For example, a popup window might
|
62
|
+
# simply close itself.
|
63
|
+
def access_denied
|
64
|
+
respond_to do |format|
|
65
|
+
format.html do
|
66
|
+
store_location
|
67
|
+
redirect_to :controller => '/session', :action => 'new'
|
68
|
+
end
|
69
|
+
format.xml do
|
70
|
+
request_http_basic_authentication 'Web Password'
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
# Store the URI of the current request in the session.
|
76
|
+
#
|
77
|
+
# We can return to this location by calling #redirect_back_or_default.
|
78
|
+
def store_location
|
79
|
+
session[:return_to] = request.request_uri
|
80
|
+
end
|
81
|
+
|
82
|
+
# Redirect to the URI stored by the most recent store_location call or
|
83
|
+
# to the passed default.
|
84
|
+
def redirect_back_or_default(default)
|
85
|
+
redirect_to(session[:return_to] || default)
|
86
|
+
session[:return_to] = nil
|
87
|
+
end
|
88
|
+
|
89
|
+
# Inclusion hook to make #current_user and #logged_in?
|
90
|
+
# available as ActionView helper methods.
|
91
|
+
def self.included(base)
|
92
|
+
base.send :helper_method, :current_user, :logged_in?
|
93
|
+
end
|
94
|
+
|
95
|
+
# Called from #current_user. First attempt to login by the user id stored in the session.
|
96
|
+
def login_from_session
|
97
|
+
self.current_user = User.find(session[:user_id]) if session[:user_id]
|
98
|
+
end
|
99
|
+
|
100
|
+
# Called from #current_user. Now, attempt to login by basic authentication information.
|
101
|
+
def login_from_basic_auth
|
102
|
+
authenticate_with_http_basic do |username, password|
|
103
|
+
self.current_user = User.authenticate(username, password)
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
# Called from #current_user. Finaly, attempt to login by an expiring token in the cookie.
|
108
|
+
def login_from_cookie
|
109
|
+
user = cookies[:auth_token] && User.find_by_remember_token(cookies[:auth_token])
|
110
|
+
if user && user.remember_token?
|
111
|
+
user.remember_me
|
112
|
+
cookies[:auth_token] = { :value => user.remember_token, :expires => user.remember_token_expires_at }
|
113
|
+
self.current_user = user
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
module AuthenticatedTestHelper
|
2
|
+
# Sets the current user in the session from the user fixtures.
|
3
|
+
def login_as(user)
|
4
|
+
@request.session[:user_id] = user ? users(user).id : nil
|
5
|
+
end
|
6
|
+
|
7
|
+
def authorize_as(user)
|
8
|
+
@request.env["HTTP_AUTHORIZATION"] = user ? ActionController::HttpAuthentication::Basic.encode_credentials(users(user).login, 'test') : nil
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
# Hijacker class
|
2
|
+
#
|
3
|
+
# This class is used by RoleRequirementTestHelper to temporarily hijack a controller action for testing
|
4
|
+
#
|
5
|
+
# It can be used for other tests as well.
|
6
|
+
#
|
7
|
+
# You can contract the author with questions
|
8
|
+
# Tim C. Harper - irb(main):001:0> ( 'tim_see_harperATgmail._see_om'.gsub('_see_', 'c').gsub('AT', '@') )
|
9
|
+
#
|
10
|
+
#
|
11
|
+
# Example usage:
|
12
|
+
# hijacker = Hijacker.new(ListingsController)
|
13
|
+
# hijacker.hijack_instance_method("index", "render :text => 'hello world!'" )
|
14
|
+
# get :index # will return "hello world"
|
15
|
+
# hijacker.restore # put things back the way you found it
|
16
|
+
|
17
|
+
class Hijacker
|
18
|
+
def initialize(klass)
|
19
|
+
@target_klass = klass
|
20
|
+
@method_stores = {}
|
21
|
+
end
|
22
|
+
|
23
|
+
def hijack_class_method(method_name, eval_string = nil, arg_names = [], &block)
|
24
|
+
hijack_method(class_self_instance, method_name, eval_string, arg_names, &block )
|
25
|
+
end
|
26
|
+
|
27
|
+
def hijack_instance_method(method_name, eval_string = nil, arg_names = [], &block)
|
28
|
+
hijack_method(@target_klass, method_name, eval_string, arg_names, &block )
|
29
|
+
end
|
30
|
+
|
31
|
+
# restore all
|
32
|
+
def restore
|
33
|
+
@method_stores.each_pair{|klass, method_stores|
|
34
|
+
method_stores.reverse_each{ |method_name, method|
|
35
|
+
klass.send :undef_method, method_name
|
36
|
+
klass.send :define_method, method_name, method if method
|
37
|
+
}
|
38
|
+
}
|
39
|
+
@method_stores.clear
|
40
|
+
true
|
41
|
+
rescue
|
42
|
+
false
|
43
|
+
end
|
44
|
+
|
45
|
+
protected
|
46
|
+
|
47
|
+
def class_self_instance
|
48
|
+
@target_klass.send :eval, "class << self; self; end;"
|
49
|
+
end
|
50
|
+
|
51
|
+
def hijack_method(klass, method_name, eval_string = nil, arg_names = [], &block)
|
52
|
+
method_name = method_name.to_s
|
53
|
+
# You have got love ruby! What other language allows you to pillage and plunder a class like this?
|
54
|
+
|
55
|
+
(@method_stores[klass]||=[]) << [
|
56
|
+
method_name,
|
57
|
+
klass.instance_methods.include?(method_name) && klass.instance_method(method_name)
|
58
|
+
]
|
59
|
+
|
60
|
+
klass.send :undef_method, method_name
|
61
|
+
if Symbol === eval_string
|
62
|
+
klass.send :define_method, method_name, klass.instance_methods(eval_string)
|
63
|
+
elsif String === eval_string
|
64
|
+
klass.class_eval <<-EOF
|
65
|
+
def #{method_name}(#{arg_names * ','})
|
66
|
+
#{eval_string}
|
67
|
+
end
|
68
|
+
EOF
|
69
|
+
elsif block_given?
|
70
|
+
klass.send :define_method, method_name, block
|
71
|
+
end
|
72
|
+
|
73
|
+
true
|
74
|
+
rescue
|
75
|
+
false
|
76
|
+
end
|
77
|
+
|
78
|
+
end
|
@@ -0,0 +1,142 @@
|
|
1
|
+
# Main module for authentication.
|
2
|
+
# Include this in ApplicationController to activate RoleRequirement
|
3
|
+
#
|
4
|
+
# See RoleSecurityClassMethods for some methods it provides.
|
5
|
+
module RoleRequirementSystem
|
6
|
+
def self.included(klass)
|
7
|
+
klass.send :class_inheritable_array, :role_requirements
|
8
|
+
klass.send :include, RoleSecurityInstanceMethods
|
9
|
+
klass.send :extend, RoleSecurityClassMethods
|
10
|
+
klass.send :helper_method, :url_options_authenticate?
|
11
|
+
|
12
|
+
klass.send :role_requirements=, []
|
13
|
+
|
14
|
+
end
|
15
|
+
|
16
|
+
module RoleSecurityClassMethods
|
17
|
+
|
18
|
+
def reset_role_requirements!
|
19
|
+
self.role_requirements.clear
|
20
|
+
end
|
21
|
+
|
22
|
+
# Add this to the top of your controller to require a role in order to access it.
|
23
|
+
# Example Usage:
|
24
|
+
#
|
25
|
+
# require_role "contractor"
|
26
|
+
# require_role "admin", :only => :destroy # don't allow contractors to destroy
|
27
|
+
# require_role "admin", :only => :update, :unless => "current_user.authorized_for_listing?(params[:id]) "
|
28
|
+
#
|
29
|
+
# Valid options
|
30
|
+
#
|
31
|
+
# * :only - Only require the role for the given actions
|
32
|
+
# * :except - Require the role for everything but
|
33
|
+
# * :if - a Proc or a string to evaluate. If it evaluates to true, the role is required.
|
34
|
+
# * :unless - The inverse of :if
|
35
|
+
#
|
36
|
+
def require_role(roles, options = {})
|
37
|
+
options.assert_valid_keys(:if, :unless,
|
38
|
+
:for, :only,
|
39
|
+
:for_all_except, :except
|
40
|
+
)
|
41
|
+
|
42
|
+
# only declare that before filter once
|
43
|
+
unless (@before_filter_declared||=false)
|
44
|
+
@before_filter_declared=true
|
45
|
+
before_filter :check_roles
|
46
|
+
end
|
47
|
+
|
48
|
+
# convert to an array if it isn't already
|
49
|
+
roles = [roles] unless Array===roles
|
50
|
+
|
51
|
+
options[:only] ||= options[:for] if options[:for]
|
52
|
+
options[:except] ||= options[:for_all_except] if options[:for_all_except]
|
53
|
+
|
54
|
+
# convert any actions into symbols
|
55
|
+
for key in [:only, :except]
|
56
|
+
if options.has_key?(key)
|
57
|
+
options[key] = [options[key]] unless Array === options[key]
|
58
|
+
options[key] = options[key].compact.collect{|v| v.to_sym}
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
self.role_requirements||=[]
|
63
|
+
self.role_requirements << {:roles => roles, :options => options }
|
64
|
+
end
|
65
|
+
|
66
|
+
# This is the core of RoleRequirement. Here is where it discerns if a user can access a controller or not./
|
67
|
+
def user_authorized_for?(user, params = {}, binding = self.binding)
|
68
|
+
return true unless Array===self.role_requirements
|
69
|
+
self.role_requirements.each{| role_requirement|
|
70
|
+
roles = role_requirement[:roles]
|
71
|
+
options = role_requirement[:options]
|
72
|
+
# do the options match the params?
|
73
|
+
|
74
|
+
# check the action
|
75
|
+
if options.has_key?(:only)
|
76
|
+
next unless options[:only].include?( (params[:action]||"index").to_sym )
|
77
|
+
end
|
78
|
+
|
79
|
+
if options.has_key?(:except)
|
80
|
+
next if options[:except].include?( (params[:action]||"index").to_sym)
|
81
|
+
end
|
82
|
+
|
83
|
+
if options.has_key?(:if)
|
84
|
+
# execute the proc. if the procedure returns false, we don't need to authenticate these roles
|
85
|
+
next unless ( String===options[:if] ? eval(options[:if], binding) : options[:if].call(params) )
|
86
|
+
end
|
87
|
+
|
88
|
+
if options.has_key?(:unless)
|
89
|
+
# execute the proc. if the procedure returns true, we don't need to authenticate these roles
|
90
|
+
next if ( String===options[:unless] ? eval(options[:unless], binding) : options[:unless].call(params) )
|
91
|
+
end
|
92
|
+
|
93
|
+
# check to see if they have one of the required roles
|
94
|
+
passed = false
|
95
|
+
roles.each { |role|
|
96
|
+
passed = true if user.has_role?(role)
|
97
|
+
} unless (user==:false || user==false)
|
98
|
+
|
99
|
+
return false unless passed
|
100
|
+
}
|
101
|
+
|
102
|
+
return true
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
module RoleSecurityInstanceMethods
|
107
|
+
def self.included(klass)
|
108
|
+
raise "Because role_requirement extends acts_as_authenticated, You must include AuthenticatedSystem first before including RoleRequirementSystem!" unless klass.included_modules.include?(AuthenticatedSystem)
|
109
|
+
end
|
110
|
+
|
111
|
+
def access_denied
|
112
|
+
if logged_in?
|
113
|
+
render :nothing => true, :status => 401
|
114
|
+
return false
|
115
|
+
else
|
116
|
+
super
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
def check_roles
|
121
|
+
return access_denied unless self.class.user_authorized_for?(current_user, params, binding)
|
122
|
+
|
123
|
+
true
|
124
|
+
end
|
125
|
+
|
126
|
+
protected
|
127
|
+
# receives a :controller, :action, and :params. Finds the given controller and runs user_authorized_for? on it.
|
128
|
+
# This can be called in your views, and is for advanced users only. If you are using :if / :unless eval expressions,
|
129
|
+
# then this may or may not work (eval strings use the current binding to execute, not the binding of the target
|
130
|
+
# controller)
|
131
|
+
def url_options_authenticate?(params = {})
|
132
|
+
params = params.symbolize_keys
|
133
|
+
if params[:controller]
|
134
|
+
# find the controller class
|
135
|
+
klass = eval("#{params[:controller]}_controller".classify)
|
136
|
+
else
|
137
|
+
klass = self.class
|
138
|
+
end
|
139
|
+
klass.user_authorized_for?(current_user, params, binding)
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
@@ -0,0 +1,86 @@
|
|
1
|
+
# Include this is test_helper.rb to enable test-case helper support for RoleRequirement via:
|
2
|
+
# include RoleRequirementTestHelper
|
3
|
+
#
|
4
|
+
# RoleRequirementTestHelper uses the power of ruby to temporarily "hijack" your target action. (don't worry, it puts things back the way it was after it runs)
|
5
|
+
# This means that the only thing that will be tested is whether or not the action can be accessed with a given circumstances.
|
6
|
+
# Any authentication you implement inside of your action will be ignored.
|
7
|
+
#
|
8
|
+
module RoleRequirementTestHelper
|
9
|
+
|
10
|
+
# Makes sure a user can access the given action
|
11
|
+
#
|
12
|
+
# Example:
|
13
|
+
#
|
14
|
+
# assert_user_can_access(:quentin, "index")
|
15
|
+
#
|
16
|
+
def assert_user_can_access(user, actions, params = {})
|
17
|
+
assert_user_access_check(true, user, actions, params)
|
18
|
+
end
|
19
|
+
|
20
|
+
# Makes sure a user cant access the given action
|
21
|
+
#
|
22
|
+
# Example:
|
23
|
+
#
|
24
|
+
# assert_user_cant_access(:quentin, "destroy", :listing_id => 1)
|
25
|
+
#
|
26
|
+
def assert_user_cant_access(user, actions, params = {})
|
27
|
+
assert_user_access_check(false, user, actions, params)
|
28
|
+
end
|
29
|
+
|
30
|
+
# Check a list of users against a set of actions with parameters.
|
31
|
+
#
|
32
|
+
# Parameters:
|
33
|
+
# users_access_list - a hash where the key is the label for a fixture, and the value is a boolean.
|
34
|
+
# actions - a list of actions to test against
|
35
|
+
# params - a hash containing the parameters to pass to each test call to the controller.
|
36
|
+
#
|
37
|
+
# Example:
|
38
|
+
# assert_user_access(
|
39
|
+
# {:admin => true, :quentin => false },
|
40
|
+
# [:show, :edit],
|
41
|
+
# {:listing_id => 1})
|
42
|
+
def assert_users_access(users_access_list, actions, params = {})
|
43
|
+
users_access_list.each_pair {|user, access|
|
44
|
+
assert_user_access_check(access, user, actions, params)
|
45
|
+
}
|
46
|
+
end
|
47
|
+
|
48
|
+
alias :assert_user_cannot_access :assert_user_cant_access
|
49
|
+
|
50
|
+
private
|
51
|
+
def assert_user_access_check(should_access, user, actions, params = {})
|
52
|
+
params = HashWithIndifferentAccess.new(params)
|
53
|
+
|
54
|
+
(Array===actions ? actions : [actions]).each { |action|
|
55
|
+
# reset the controller, request, and response
|
56
|
+
@controller = @controller.class.new
|
57
|
+
@request = @request.class.new
|
58
|
+
@response = @response.class.new
|
59
|
+
login_as user
|
60
|
+
if should_access
|
61
|
+
assert request_passes_role_security_system?(action, params), "request to #{@controller.class}##{action} with user #{user} and params #{params.inspect} should have passed "
|
62
|
+
else
|
63
|
+
assert ! request_passes_role_security_system?(action, params), "request to #{@controller.class}##{action} with user #{user} and params #{params.inspect} should have been denied"
|
64
|
+
end
|
65
|
+
}
|
66
|
+
end
|
67
|
+
|
68
|
+
# This is the core of the test system.
|
69
|
+
def request_passes_role_security_system?(action, params)
|
70
|
+
did_it_pass = false
|
71
|
+
|
72
|
+
action = action.to_s
|
73
|
+
hijacker = Hijacker.new(@controller.class)
|
74
|
+
|
75
|
+
begin
|
76
|
+
assert hijacker.hijack_instance_method(action, "@last_action_passed='#{action}'; render :text => 'passed'"), "unable to hijack method '#{action}'. Are you sure the action exists?"
|
77
|
+
get action, params
|
78
|
+
rescue
|
79
|
+
assert false, "error occurred while trying to access action '#{action}' -- #{$!.to_s}.\nCheck to make sure that you are passing needed parameters.\n#{$!.backtrace * "\n"} "
|
80
|
+
ensure
|
81
|
+
hijacker.restore
|
82
|
+
end
|
83
|
+
|
84
|
+
did_it_pass = (action.to_s == assigns(:last_action_passed)) # make sure it actually made it through
|
85
|
+
end
|
86
|
+
end
|