typus 0.9.39 → 1.0.0.pre
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +104 -0
- data/Gemfile +17 -0
- data/Gemfile.lock +96 -0
- data/MIT-LICENSE +1 -1
- data/README.rdoc +45 -0
- data/Rakefile +19 -48
- data/app/controllers/admin/account_controller.rb +54 -0
- data/app/controllers/admin/dashboard_controller.rb +7 -0
- data/app/controllers/admin/resource_controller.rb +8 -0
- data/app/controllers/admin/resources_controller.rb +307 -0
- data/app/controllers/admin/session_controller.rb +38 -0
- data/app/controllers/admin_controller.rb +26 -0
- data/app/helpers/admin/dashboard_helper.rb +38 -0
- data/app/helpers/admin/filters_helper.rb +81 -0
- data/app/helpers/admin/form_helper.rb +68 -261
- data/app/helpers/admin/preview_helper.rb +48 -0
- data/app/helpers/admin/relationships_helper.rb +192 -0
- data/app/helpers/admin/resources_helper.rb +80 -0
- data/app/helpers/admin/search_helper.rb +19 -0
- data/app/helpers/admin/sidebar_helper.rb +32 -210
- data/app/helpers/admin/table_helper.rb +207 -200
- data/app/helpers/admin_helper.rb +56 -0
- data/app/mailers/admin/mailer.rb +13 -0
- data/app/models/admin/fake_user.rb +38 -0
- data/app/views/admin/account/forgot_password.html.erb +21 -0
- data/app/views/admin/account/new.html.erb +21 -0
- data/app/views/admin/dashboard/_sidebar.html.erb +3 -3
- data/app/views/admin/dashboard/show.html.erb +16 -0
- data/app/views/admin/dashboard/styles.html.erb +154 -0
- data/app/views/admin/helpers/_apps.html.erb +6 -0
- data/app/views/admin/helpers/_flash_message.html.erb +3 -0
- data/app/views/admin/helpers/_header.html.erb +7 -0
- data/app/views/admin/helpers/_login_info.html.erb +4 -0
- data/app/views/admin/helpers/_preview.html.erb +13 -0
- data/app/views/admin/helpers/dashboard/_applications.html.erb +32 -0
- data/app/views/admin/helpers/dashboard/_resources.html.erb +16 -0
- data/app/views/admin/helpers/filters/_filters.html.erb +31 -0
- data/app/views/admin/helpers/resources/_display_link_to_previous.html.erb +3 -0
- data/app/views/admin/helpers/resources/_pagination.html.erb +28 -0
- data/app/views/admin/helpers/search/_search.html.erb +12 -0
- data/app/views/admin/helpers/sidebar/_sidebar.html.erb +17 -0
- data/app/views/admin/helpers/table/_table.html.erb +22 -0
- data/app/views/{typus_mailer/reset_password_link.erb → admin/mailer/reset_password_link.text.erb} +2 -2
- data/{test/config/broken/empty.yml → app/views/admin/resources/_edit.html.erb} +0 -0
- data/app/views/admin/resources/_form.html.erb +26 -0
- data/{test/config/broken/empty_roles.yml → app/views/admin/resources/_index.html.erb} +0 -0
- data/{test/config/empty/empty_01.yml → app/views/admin/resources/_new.html.erb} +0 -0
- data/{test/config/empty/empty_01_roles.yml → app/views/admin/resources/_show.html.erb} +0 -0
- data/app/views/admin/resources/edit.html.erb +23 -21
- data/app/views/admin/resources/index.html.erb +31 -18
- data/app/views/admin/resources/new.html.erb +20 -18
- data/app/views/admin/resources/show.html.erb +29 -20
- data/app/views/admin/session/new.html.erb +26 -0
- data/app/views/admin/templates/_belongs_to.html.erb +4 -0
- data/app/views/admin/templates/_boolean.html.erb +4 -8
- data/app/views/admin/templates/_date.html.erb +9 -2
- data/app/views/admin/templates/_datetime.html.erb +9 -2
- data/app/views/admin/templates/_file.html.erb +20 -5
- data/app/views/admin/templates/_has_many.html.erb +24 -0
- data/app/views/admin/templates/_has_n.html.erb +17 -0
- data/{test/config/empty/empty_02.yml → app/views/admin/templates/_has_one.html.erb} +0 -0
- data/app/views/admin/templates/_password.html.erb +4 -2
- data/app/views/admin/templates/_relate_form.html.erb +4 -0
- data/app/views/admin/templates/_selector.html.erb +6 -18
- data/app/views/admin/templates/_string.html.erb +11 -10
- data/app/views/admin/templates/_text.html.erb +9 -2
- data/app/views/admin/templates/_time.html.erb +9 -2
- data/app/views/admin/templates/_tree.html.erb +4 -0
- data/app/views/layouts/admin/session.html.erb +44 -0
- data/app/views/layouts/admin.html.erb +45 -39
- data/config/available_locales/ca.yml +124 -0
- data/config/available_locales/ca_models.yml +16 -0
- data/config/{locales → available_locales}/de.yml +108 -89
- data/config/available_locales/de_models.yml +13 -0
- data/config/available_locales/es.yml +124 -0
- data/config/available_locales/es_models.yml +13 -0
- data/config/available_locales/fr.yml +124 -0
- data/config/available_locales/fr_models.yml +13 -0
- data/config/available_locales/hu.yml +124 -0
- data/config/available_locales/hu_models.yml +13 -0
- data/config/available_locales/it.yml +136 -0
- data/config/available_locales/it_models.yml +15 -0
- data/config/available_locales/language.yml.template +122 -0
- data/config/available_locales/language_models.yml.template +13 -0
- data/config/{locales → available_locales}/pt-BR.yml +97 -74
- data/config/available_locales/pt-BR_models.yml +13 -0
- data/config/{locales → available_locales}/ru.yml +107 -85
- data/config/available_locales/ru_models.yml +13 -0
- data/config/routes.rb +18 -11
- data/lib/generators/templates/config/initializers/typus.rb +26 -0
- data/lib/generators/templates/config/initializers/typus_authentication.rb +18 -0
- data/lib/generators/templates/config/initializers/typus_resources.rb +30 -0
- data/{generators/typus → lib/generators}/templates/config/typus/README +34 -16
- data/lib/generators/templates/config/typus/application.yml +5 -0
- data/lib/generators/templates/config/typus/application_roles.yml +6 -0
- data/lib/generators/templates/config/typus/typus.yml +17 -0
- data/lib/generators/templates/config/typus/typus_roles.yml +6 -0
- data/lib/generators/templates/controller.rb +4 -0
- data/lib/generators/templates/functional_test.rb +21 -0
- data/{generators/typus/templates/db/create_typus_users.rb → lib/generators/templates/migration.rb} +4 -4
- data/lib/generators/templates/model.rb +8 -0
- data/lib/generators/templates/model.yml +10 -0
- data/{generators/typus/templates/public/images/admin → lib/generators/templates/public/admin/images}/ui-icons.png +0 -0
- data/lib/generators/templates/public/admin/javascripts/application.js +6 -0
- data/lib/generators/templates/public/admin/javascripts/jquery-1.4.2.min.js +154 -0
- data/lib/generators/templates/public/admin/javascripts/jquery.rails.js +126 -0
- data/lib/generators/templates/public/admin/javascripts/jquery.searchField.js +91 -0
- data/lib/generators/templates/public/admin/stylesheets/application.css +11 -0
- data/lib/generators/templates/public/admin/stylesheets/screen.css +356 -0
- data/lib/generators/templates/public/admin/vendor/fancybox/blank.gif +0 -0
- data/lib/generators/templates/public/admin/vendor/fancybox/fancy_close.png +0 -0
- data/lib/generators/templates/public/admin/vendor/fancybox/fancy_loading.png +0 -0
- data/lib/generators/templates/public/admin/vendor/fancybox/fancy_nav_left.png +0 -0
- data/lib/generators/templates/public/admin/vendor/fancybox/fancy_nav_right.png +0 -0
- data/lib/generators/templates/public/admin/vendor/fancybox/fancy_shadow_e.png +0 -0
- data/lib/generators/templates/public/admin/vendor/fancybox/fancy_shadow_n.png +0 -0
- data/lib/generators/templates/public/admin/vendor/fancybox/fancy_shadow_ne.png +0 -0
- data/lib/generators/templates/public/admin/vendor/fancybox/fancy_shadow_nw.png +0 -0
- data/lib/generators/templates/public/admin/vendor/fancybox/fancy_shadow_s.png +0 -0
- data/lib/generators/templates/public/admin/vendor/fancybox/fancy_shadow_se.png +0 -0
- data/lib/generators/templates/public/admin/vendor/fancybox/fancy_shadow_sw.png +0 -0
- data/lib/generators/templates/public/admin/vendor/fancybox/fancy_shadow_w.png +0 -0
- data/lib/generators/templates/public/admin/vendor/fancybox/fancy_title_left.png +0 -0
- data/lib/generators/templates/public/admin/vendor/fancybox/fancy_title_main.png +0 -0
- data/lib/generators/templates/public/admin/vendor/fancybox/fancy_title_over.png +0 -0
- data/{generators/typus/templates/public/images/admin → lib/generators/templates/public/admin/vendor}/fancybox/fancy_title_right.png +0 -0
- data/lib/generators/templates/public/admin/vendor/fancybox/fancybox-x.png +0 -0
- data/lib/generators/templates/public/admin/vendor/fancybox/fancybox-y.png +0 -0
- data/lib/generators/templates/public/admin/vendor/fancybox/fancybox.png +0 -0
- data/lib/generators/templates/public/admin/vendor/fancybox/jquery.easing-1.3.pack.js +72 -0
- data/lib/generators/templates/public/admin/vendor/fancybox/jquery.fancybox-1.3.1.css +363 -0
- data/lib/generators/templates/public/admin/vendor/fancybox/jquery.fancybox-1.3.1.js +1077 -0
- data/lib/generators/templates/public/admin/vendor/fancybox/jquery.fancybox-1.3.1.pack.js +44 -0
- data/lib/generators/templates/public/admin/vendor/fancybox/jquery.mousewheel-3.0.2.pack.js +13 -0
- data/lib/generators/templates/view.html.erb +9 -0
- data/lib/generators/typus/migration_generator.rb +85 -0
- data/lib/generators/typus/typus_generator.rb +190 -0
- data/lib/generators/typus/views_generator.rb +27 -0
- data/lib/support/active_record.rb +60 -0
- data/lib/support/array.rb +13 -0
- data/lib/{typus → support}/hash.rb +2 -2
- data/lib/{typus → support}/object.rb +2 -2
- data/lib/support/string.rb +47 -0
- data/lib/tasks/typus.rake +19 -0
- data/lib/typus/authentication.rb +146 -40
- data/lib/typus/configuration.rb +14 -49
- data/lib/typus/engine.rb +6 -0
- data/lib/typus/format.rb +41 -18
- data/lib/typus/orm/active_record.rb +378 -0
- data/lib/typus/resources.rb +57 -0
- data/lib/typus/user.rb +54 -37
- data/lib/typus/version.rb +3 -0
- data/lib/typus.rb +118 -80
- data/lib/vendor/paginator.rb +2 -2
- data/test/factories/assets.rb +5 -0
- data/test/factories/categories.rb +3 -0
- data/test/factories/comments.rb +6 -0
- data/test/factories/pages.rb +5 -0
- data/test/factories/pictures.rb +7 -0
- data/test/factories/posts.rb +6 -0
- data/test/factories/typus_users.rb +8 -0
- data/test/{config → fixtures/config}/broken/application.yml +0 -0
- data/test/{config → fixtures/config}/broken/application_roles.yml +0 -0
- data/test/{config/empty/empty_02_roles.yml → fixtures/config/broken/empty.yml} +0 -0
- data/test/fixtures/config/broken/empty_roles.yml +0 -0
- data/test/{config → fixtures/config}/broken/undefined.yml +0 -0
- data/test/{config → fixtures/config}/broken/undefined_roles.yml +0 -0
- data/test/{config → fixtures/config}/default/typus.yml +2 -1
- data/{generators/typus/templates/config/typus → test/fixtures/config/default}/typus_roles.yml +0 -0
- data/test/fixtures/config/empty/empty_01.yml +0 -0
- data/test/fixtures/config/empty/empty_01_roles.yml +0 -0
- data/test/fixtures/config/empty/empty_02.yml +0 -0
- data/test/fixtures/config/empty/empty_02_roles.yml +0 -0
- data/test/{config → fixtures/config}/locales/es.yml +0 -0
- data/test/fixtures/config/namespaced/application.yml +5 -0
- data/test/fixtures/config/namespaced/application_roles.yml +2 -0
- data/test/{config → fixtures/config}/ordered/001_roles.yml +0 -0
- data/test/{config → fixtures/config}/ordered/002_roles.yml +0 -0
- data/test/{config → fixtures/config}/unordered/app_one_roles.yml +0 -0
- data/test/{config → fixtures/config}/unordered/app_two_roles.yml +0 -0
- data/test/fixtures/config/working/application.yml +73 -0
- data/test/fixtures/config/working/application_roles.yml +24 -0
- data/{generators/typus/templates/config/typus → test/fixtures/config/working}/typus.yml +2 -1
- data/test/{config/default → fixtures/config/working}/typus_roles.yml +0 -0
- data/test/fixtures/rails_app/README +244 -0
- data/test/fixtures/rails_app/Rakefile +7 -0
- data/test/fixtures/rails_app/app/controllers/admin/assets_controller.rb +2 -0
- data/test/fixtures/rails_app/app/controllers/admin/categories_controller.rb +2 -0
- data/test/fixtures/rails_app/app/controllers/admin/comments_controller.rb +2 -0
- data/test/fixtures/rails_app/app/controllers/admin/pages_controller.rb +2 -0
- data/test/fixtures/rails_app/app/controllers/admin/pictures_controller.rb +2 -0
- data/test/fixtures/rails_app/app/controllers/admin/posts_controller.rb +2 -0
- data/test/fixtures/rails_app/app/controllers/admin/status_controller.rb +2 -0
- data/test/fixtures/rails_app/app/controllers/admin/typus_users_controller.rb +2 -0
- data/test/fixtures/rails_app/app/controllers/admin/watch_dog_controller.rb +2 -0
- data/test/fixtures/rails_app/app/controllers/application_controller.rb +4 -0
- data/test/fixtures/rails_app/app/helpers/application_helper.rb +2 -0
- data/test/fixtures/{app → rails_app/app}/models/asset.rb +1 -1
- data/test/fixtures/{app → rails_app/app}/models/category.rb +2 -2
- data/test/fixtures/{app → rails_app/app}/models/comment.rb +1 -1
- data/test/fixtures/{app → rails_app/app}/models/custom_user.rb +1 -1
- data/test/fixtures/{app → rails_app/app}/models/delayed/task.rb +2 -2
- data/test/fixtures/rails_app/app/models/page.rb +9 -0
- data/test/fixtures/rails_app/app/models/picture.rb +6 -0
- data/test/fixtures/{app → rails_app/app}/models/post.rb +6 -6
- data/test/fixtures/rails_app/app/models/typus_user.rb +8 -0
- data/test/fixtures/{app → rails_app/app}/models/view.rb +1 -1
- data/test/fixtures/rails_app/app/views/admin/categories/_form.html.erb +1 -0
- data/test/fixtures/rails_app/app/views/admin/dashboard/_sidebar.html.erb +1 -0
- data/test/fixtures/rails_app/app/views/admin/mailer/reset_password_link.text.erb +6 -0
- data/test/fixtures/rails_app/app/views/admin/posts/_edit.html.erb +1 -0
- data/test/fixtures/rails_app/app/views/admin/posts/_index.html.erb +1 -0
- data/test/fixtures/rails_app/app/views/admin/posts/_new.html.erb +1 -0
- data/test/fixtures/rails_app/app/views/admin/posts/_show.html.erb +1 -0
- data/test/fixtures/rails_app/app/views/admin/posts/_sidebar.html.erb +1 -0
- data/test/fixtures/rails_app/app/views/admin/resources/_sidebar.html.erb +1 -0
- data/test/fixtures/rails_app/app/views/admin/status/index.html.erb +1 -0
- data/test/fixtures/rails_app/app/views/admin/templates/_datepicker.html.erb +1 -0
- data/test/fixtures/rails_app/app/views/layouts/application.html.erb +14 -0
- data/test/fixtures/rails_app/config/application.rb +50 -0
- data/test/fixtures/rails_app/config/boot.rb +13 -0
- data/test/fixtures/rails_app/config/database.yml +22 -0
- data/test/fixtures/rails_app/config/environment.rb +5 -0
- data/test/fixtures/rails_app/config/environments/development.rb +19 -0
- data/test/fixtures/rails_app/config/environments/production.rb +42 -0
- data/test/fixtures/rails_app/config/environments/test.rb +34 -0
- data/test/fixtures/rails_app/config/initializers/acts_as_list.rb +258 -0
- data/test/fixtures/rails_app/config/initializers/acts_as_tree.rb +98 -0
- data/test/fixtures/rails_app/config/initializers/backtrace_silencers.rb +7 -0
- data/test/fixtures/rails_app/config/initializers/inflections.rb +10 -0
- data/test/fixtures/rails_app/config/initializers/mime_types.rb +5 -0
- data/test/fixtures/rails_app/config/initializers/secret_token.rb +7 -0
- data/test/fixtures/rails_app/config/initializers/session_store.rb +8 -0
- data/test/fixtures/rails_app/config/initializers/typus.rb +6 -0
- data/test/fixtures/rails_app/config/locales/en.yml +5 -0
- data/test/fixtures/rails_app/config/routes.rb +8 -0
- data/test/{config/working → fixtures/rails_app/config/typus}/application.yml +11 -9
- data/test/{config/working → fixtures/rails_app/config/typus}/application_roles.yml +0 -0
- data/{generators/typus_update_schema_to_01/templates/config → test/fixtures/rails_app/config/typus}/typus.yml +0 -0
- data/test/{config/working → fixtures/rails_app/config/typus}/typus_roles.yml +0 -0
- data/test/fixtures/rails_app/config.ru +4 -0
- data/test/fixtures/rails_app/db/seeds.rb +7 -0
- data/test/fixtures/rails_app/db/test.sqlite3 +0 -0
- data/test/fixtures/rails_app/log/test.log +4268 -0
- data/test/fixtures/rails_app/public/404.html +26 -0
- data/test/fixtures/rails_app/public/422.html +26 -0
- data/test/fixtures/rails_app/public/500.html +26 -0
- data/test/fixtures/rails_app/public/favicon.ico +0 -0
- data/test/fixtures/rails_app/public/images/rails.png +0 -0
- data/test/fixtures/rails_app/public/index.html +279 -0
- data/test/fixtures/rails_app/public/javascripts/application.js +2 -0
- data/test/fixtures/rails_app/public/javascripts/controls.js +965 -0
- data/test/fixtures/rails_app/public/javascripts/dragdrop.js +974 -0
- data/test/fixtures/rails_app/public/javascripts/effects.js +1123 -0
- data/test/fixtures/rails_app/public/javascripts/prototype.js +4874 -0
- data/test/fixtures/rails_app/public/javascripts/rails.js +118 -0
- data/test/fixtures/rails_app/public/robots.txt +5 -0
- data/test/fixtures/rails_app/script/rails +9 -0
- data/test/fixtures/rails_app/tmp/export-posts-20100902120447.csv +2 -0
- data/test/fixtures/rails_app/tmp/export-posts-20100902120700.csv +2 -0
- data/test/functional/admin/account_controller_test.rb +90 -0
- data/test/functional/admin/dashboard_controller_http_basic_test.rb +24 -0
- data/test/functional/admin/dashboard_controller_none_test.rb +18 -0
- data/test/functional/admin/dashboard_controller_test.rb +106 -0
- data/test/functional/admin/resources_controller_assets_relationships.rb +59 -0
- data/test/functional/admin/resources_controller_categories_before_test.rb +10 -0
- data/test/functional/admin/resources_controller_categories_lists_test.rb +44 -0
- data/test/functional/admin/resources_controller_categories_views_test.rb +10 -0
- data/test/functional/admin/resources_controller_comments_toggle_test.rb +21 -0
- data/test/functional/admin/{master_controller_posts_before_test.rb → resources_controller_posts_before_test.rb} +3 -3
- data/test/functional/admin/resources_controller_posts_crud_custom_test.rb +27 -0
- data/test/functional/admin/resources_controller_posts_crud_test.rb +44 -0
- data/test/functional/admin/resources_controller_posts_formats_test.rb +39 -0
- data/test/functional/admin/resources_controller_posts_forms_test.rb +58 -0
- data/test/functional/admin/resources_controller_posts_permissions_test.rb +100 -0
- data/test/functional/admin/{master_controller_posts_relationships_test.rb → resources_controller_posts_relationships_test.rb} +25 -20
- data/test/functional/admin/resources_controller_posts_roles.rb +52 -0
- data/test/functional/admin/resources_controller_posts_views_test.rb +143 -0
- data/test/functional/admin/resources_controller_tableless_resource_test.rb +51 -0
- data/test/functional/admin/resources_controller_typus_users_test.rb +159 -0
- data/test/functional/admin/session_controller_test.rb +85 -0
- data/test/helpers/admin/dashboard_helper_test.rb +42 -0
- data/test/helpers/admin/form_helper_test.rb +52 -276
- data/test/helpers/admin/resources_helper_test.rb +52 -0
- data/test/helpers/admin/sidebar_helper_test.rb +133 -224
- data/test/helpers/admin/table_helper_test.rb +136 -144
- data/test/helpers/admin_helper_test.rb +69 -0
- data/test/lib/support/active_record_test.rb +35 -0
- data/test/lib/support/array_test.rb +15 -0
- data/test/lib/support/hash_test.rb +11 -0
- data/test/lib/support/string_test.rb +48 -0
- data/test/lib/typus/active_record_test.rb +385 -0
- data/test/lib/typus/configuration_test.rb +52 -0
- data/test/lib/typus/resource_test.rb +17 -0
- data/test/lib/typus/routes_test.rb +29 -0
- data/test/lib/typus_test.rb +72 -40
- data/test/{vendor → lib/vendor}/paginator_test.rb +7 -4
- data/test/schema.rb +28 -3
- data/test/test_helper.rb +29 -0
- data/test/unit/admin/mailer_test.rb +32 -0
- data/test/unit/typus_user_roles_test.rb +69 -61
- data/test/unit/typus_user_test.rb +56 -143
- data/typus.gemspec +18 -276
- metadata +305 -231
- data/.gitignore +0 -1
- data/AUTHORS.md +0 -34
- data/CHANGES +0 -3
- data/README.md +0 -75
- data/VERSION +0 -1
- data/app/controllers/admin/master_controller.rb +0 -394
- data/app/controllers/typus_controller.rb +0 -152
- data/app/helpers/admin/master_helper.rb +0 -104
- data/app/helpers/admin/public_helper.rb +0 -27
- data/app/helpers/typus_helper.rb +0 -181
- data/app/models/typus_mailer.rb +0 -14
- data/app/models/typus_user.rb +0 -5
- data/app/views/admin/shared/_feedback.html.erb +0 -6
- data/app/views/admin/shared/_footer.html.erb +0 -2
- data/app/views/admin/shared/_pagination.html.erb +0 -28
- data/app/views/admin/templates/_tiny_mce.html.erb +0 -2
- data/app/views/layouts/typus.html.erb +0 -29
- data/app/views/typus/dashboard.html.erb +0 -9
- data/app/views/typus/recover_password.html.erb +0 -7
- data/app/views/typus/reset_password.html.erb +0 -15
- data/app/views/typus/sign_in.html.erb +0 -9
- data/app/views/typus/sign_up.html.erb +0 -7
- data/config/locales/es.yml +0 -105
- data/config/locales/fr.yml +0 -98
- data/config/locales/language.yml.template +0 -106
- data/generators/typus/templates/auto/index.html.erb +0 -11
- data/generators/typus/templates/auto/resource_controller.rb.erb +0 -15
- data/generators/typus/templates/auto/resource_controller_test.rb.erb +0 -11
- data/generators/typus/templates/auto/resources_controller.rb.erb +0 -37
- data/generators/typus/templates/config/initializers/typus.rb +0 -34
- data/generators/typus/templates/config/typus/application.yml +0 -6
- data/generators/typus/templates/config/typus/application_roles.yml +0 -23
- data/generators/typus/templates/lib/tasks/typus_tasks.rake +0 -32
- data/generators/typus/templates/public/images/admin/fancybox/fancy_closebox.png +0 -0
- data/generators/typus/templates/public/images/admin/fancybox/fancy_left.png +0 -0
- data/generators/typus/templates/public/images/admin/fancybox/fancy_progress.png +0 -0
- data/generators/typus/templates/public/images/admin/fancybox/fancy_right.png +0 -0
- data/generators/typus/templates/public/images/admin/fancybox/fancy_shadow_e.png +0 -0
- data/generators/typus/templates/public/images/admin/fancybox/fancy_shadow_n.png +0 -0
- data/generators/typus/templates/public/images/admin/fancybox/fancy_shadow_ne.png +0 -0
- data/generators/typus/templates/public/images/admin/fancybox/fancy_shadow_nw.png +0 -0
- data/generators/typus/templates/public/images/admin/fancybox/fancy_shadow_s.png +0 -0
- data/generators/typus/templates/public/images/admin/fancybox/fancy_shadow_se.png +0 -0
- data/generators/typus/templates/public/images/admin/fancybox/fancy_shadow_sw.png +0 -0
- data/generators/typus/templates/public/images/admin/fancybox/fancy_shadow_w.png +0 -0
- data/generators/typus/templates/public/images/admin/fancybox/fancy_title_left.png +0 -0
- data/generators/typus/templates/public/images/admin/fancybox/fancy_title_main.png +0 -0
- data/generators/typus/templates/public/javascripts/admin/application.js +0 -14
- data/generators/typus/templates/public/javascripts/admin/jquery-1.3.2.min.js +0 -19
- data/generators/typus/templates/public/javascripts/admin/jquery.fancybox-1.2.1.min.js +0 -9
- data/generators/typus/templates/public/stylesheets/admin/jquery.fancybox.css +0 -315
- data/generators/typus/templates/public/stylesheets/admin/reset.css +0 -68
- data/generators/typus/templates/public/stylesheets/admin/screen.css +0 -361
- data/generators/typus/typus_generator.rb +0 -191
- data/generators/typus_update_schema_to_01/templates/migration.rb +0 -11
- data/generators/typus_update_schema_to_01/typus_update_schema_to_01_generator.rb +0 -19
- data/generators/typus_update_schema_to_02/templates/migration.rb +0 -11
- data/generators/typus_update_schema_to_02/typus_update_schema_to_02_generator.rb +0 -11
- data/lib/typus/active_record.rb +0 -323
- data/lib/typus/extensions/routes.rb +0 -15
- data/lib/typus/extensions/routes_hack.rb +0 -15
- data/lib/typus/preferences.rb +0 -11
- data/lib/typus/preview.rb +0 -76
- data/lib/typus/quick_edit.rb +0 -40
- data/lib/typus/reloader.rb +0 -14
- data/lib/typus/string.rb +0 -27
- data/lib/vendor/active_record.rb +0 -15
- data/lib/vendor/rss_parser.rb +0 -20
- data/rails/init.rb +0 -3
- data/tasks/typus_tasks.rake +0 -32
- data/test/config/working/typus.yml +0 -12
- data/test/fixtures/app/controllers/admin/assets_controller.rb +0 -2
- data/test/fixtures/app/controllers/admin/categories_controller.rb +0 -2
- data/test/fixtures/app/controllers/admin/comments_controller.rb +0 -2
- data/test/fixtures/app/controllers/admin/pages_controller.rb +0 -2
- data/test/fixtures/app/controllers/admin/posts_controller.rb +0 -2
- data/test/fixtures/app/controllers/admin/status_controller.rb +0 -6
- data/test/fixtures/app/controllers/admin/typus_users_controller.rb +0 -2
- data/test/fixtures/app/controllers/admin/watch_dog_controller.rb +0 -6
- data/test/fixtures/app/models/page.rb +0 -5
- data/test/fixtures/app/views/admin/dashboard/_content.html.erb +0 -1
- data/test/fixtures/app/views/admin/dashboard/_sidebar.html.erb +0 -1
- data/test/fixtures/app/views/admin/posts/_edit.html.erb +0 -1
- data/test/fixtures/app/views/admin/posts/_index.html.erb +0 -1
- data/test/fixtures/app/views/admin/posts/_new.html.erb +0 -1
- data/test/fixtures/app/views/admin/posts/_show.html.erb +0 -1
- data/test/fixtures/app/views/admin/posts/_sidebar.html.erb +0 -1
- data/test/fixtures/app/views/admin/resources/_sidebar.html.erb +0 -1
- data/test/fixtures/app/views/admin/shared/_footer.html.erb +0 -1
- data/test/fixtures/app/views/admin/status/index.html.erb +0 -1
- data/test/fixtures/app/views/admin/templates/_datepicker.html.erb +0 -1
- data/test/fixtures/assets.yml +0 -11
- data/test/fixtures/categories.yml +0 -14
- data/test/fixtures/comments.yml +0 -27
- data/test/fixtures/pages.yml +0 -41
- data/test/fixtures/posts.yml +0 -37
- data/test/fixtures/typus_users.yml +0 -59
- data/test/functional/admin/master_controller_assets_relationships.rb +0 -66
- data/test/functional/admin/master_controller_categories_lists_test.rb +0 -64
- data/test/functional/admin/master_controller_posts_crud_test.rb +0 -97
- data/test/functional/admin/master_controller_posts_formats_test.rb +0 -53
- data/test/functional/admin/master_controller_posts_permissions_test.rb +0 -127
- data/test/functional/admin/master_controller_posts_roles.rb +0 -50
- data/test/functional/admin/master_controller_posts_toggle_test.rb +0 -35
- data/test/functional/admin/master_controller_posts_views_test.rb +0 -209
- data/test/functional/admin/master_controller_tableless_resource_test.rb +0 -36
- data/test/functional/admin/master_controller_typus_users_test.rb +0 -211
- data/test/functional/typus_controller_test.rb +0 -342
- data/test/helper.rb +0 -51
- data/test/helpers/admin/master_helper_test.rb +0 -70
- data/test/helpers/admin/public_helper_test.rb +0 -26
- data/test/helpers/typus_helper_test.rb +0 -96
- data/test/lib/active_record_test.rb +0 -377
- data/test/lib/configuration_test.rb +0 -95
- data/test/lib/hash_test.rb +0 -11
- data/test/lib/routes_test.rb +0 -71
- data/test/lib/string_test.rb +0 -55
- data/test/unit/typus_mailer_test.rb +0 -29
- data/test/unit/typus_test.rb +0 -17
- data/test/vendor/active_record_test.rb +0 -18
@@ -0,0 +1,378 @@
|
|
1
|
+
module Typus
|
2
|
+
|
3
|
+
module Orm
|
4
|
+
|
5
|
+
module ClassMethods
|
6
|
+
|
7
|
+
# Model fields as an <tt>ActiveSupport::OrderedHash</tt>.
|
8
|
+
def model_fields
|
9
|
+
hash = ActiveSupport::OrderedHash.new
|
10
|
+
columns.map { |u| hash[u.name.to_sym] = u.type.to_sym }
|
11
|
+
return hash
|
12
|
+
end
|
13
|
+
|
14
|
+
# Model relationships as an <tt>ActiveSupport::OrderedHash</tt>.
|
15
|
+
def model_relationships
|
16
|
+
hash = ActiveSupport::OrderedHash.new
|
17
|
+
reflect_on_all_associations.map { |i| hash[i.name] = i.macro }
|
18
|
+
return hash
|
19
|
+
end
|
20
|
+
|
21
|
+
# Model description for admin panel.
|
22
|
+
def typus_description
|
23
|
+
Typus::Configuration.config[self.name]['description']
|
24
|
+
end
|
25
|
+
|
26
|
+
# Form and list fields
|
27
|
+
def typus_fields_for(filter)
|
28
|
+
|
29
|
+
fields_with_type = ActiveSupport::OrderedHash.new
|
30
|
+
|
31
|
+
begin
|
32
|
+
fields = Typus::Configuration.config[name]['fields'][filter.to_s]
|
33
|
+
fields = fields.extract_settings.collect { |f| f.to_sym }
|
34
|
+
rescue
|
35
|
+
return [] if filter == 'default'
|
36
|
+
filter = 'default'
|
37
|
+
retry
|
38
|
+
end
|
39
|
+
|
40
|
+
begin
|
41
|
+
|
42
|
+
fields.each do |field|
|
43
|
+
|
44
|
+
attribute_type = model_fields[field]
|
45
|
+
|
46
|
+
if reflect_on_association(field)
|
47
|
+
attribute_type = reflect_on_association(field).macro
|
48
|
+
end
|
49
|
+
|
50
|
+
if typus_field_options_for(:selectors).include?(field)
|
51
|
+
attribute_type = :selector
|
52
|
+
end
|
53
|
+
|
54
|
+
# Custom field_type depending on the attribute name.
|
55
|
+
case field.to_s
|
56
|
+
when 'parent', 'parent_id' then attribute_type = :tree
|
57
|
+
when /password/ then attribute_type = :password
|
58
|
+
when 'position' then attribute_type = :position
|
59
|
+
when /\./ then attribute_type = :transversal
|
60
|
+
end
|
61
|
+
|
62
|
+
if respond_to?(:attachment_definitions) && attachment_definitions.try(:has_key?, field)
|
63
|
+
attribute_type = :file
|
64
|
+
end
|
65
|
+
|
66
|
+
# And finally insert the field and the attribute_type
|
67
|
+
# into the fields_with_type ordered hash.
|
68
|
+
fields_with_type[field.to_s] = attribute_type
|
69
|
+
|
70
|
+
end
|
71
|
+
|
72
|
+
rescue
|
73
|
+
fields = Typus::Configuration.config[name]['fields']['default'].extract_settings
|
74
|
+
retry
|
75
|
+
end
|
76
|
+
|
77
|
+
return fields_with_type
|
78
|
+
|
79
|
+
end
|
80
|
+
|
81
|
+
# Typus sidebar filters.
|
82
|
+
def typus_filters
|
83
|
+
|
84
|
+
fields_with_type = ActiveSupport::OrderedHash.new
|
85
|
+
|
86
|
+
data = Typus::Configuration.config[name]['filters']
|
87
|
+
return [] unless data
|
88
|
+
fields = data.extract_settings.collect { |i| i.to_sym }
|
89
|
+
|
90
|
+
fields.each do |field|
|
91
|
+
attribute_type = model_fields[field.to_sym]
|
92
|
+
if reflect_on_association(field.to_sym)
|
93
|
+
attribute_type = reflect_on_association(field.to_sym).macro
|
94
|
+
end
|
95
|
+
fields_with_type[field.to_s] = attribute_type
|
96
|
+
end
|
97
|
+
|
98
|
+
return fields_with_type
|
99
|
+
|
100
|
+
end
|
101
|
+
|
102
|
+
def typus_actions
|
103
|
+
return [] if Typus::Configuration.config[name]['actions'].nil?
|
104
|
+
Typus::Configuration.config[name]['actions'].keys.map do |key|
|
105
|
+
Typus::Configuration.config[name]['actions'][key].extract_settings
|
106
|
+
end.flatten
|
107
|
+
rescue
|
108
|
+
[]
|
109
|
+
end
|
110
|
+
|
111
|
+
# Extended actions for this model on Typus.
|
112
|
+
def typus_actions_on(filter)
|
113
|
+
Typus::Configuration.config[name]['actions'][filter.to_s].extract_settings
|
114
|
+
rescue
|
115
|
+
[]
|
116
|
+
end
|
117
|
+
|
118
|
+
# Used for +search+, +relationships+
|
119
|
+
def typus_defaults_for(filter)
|
120
|
+
data = Typus::Configuration.config[name][filter.to_s]
|
121
|
+
return (!data.nil?) ? data.extract_settings : []
|
122
|
+
end
|
123
|
+
|
124
|
+
def typus_search_fields
|
125
|
+
data = Typus::Configuration.config[name]["search"]
|
126
|
+
return [] if data.nil?
|
127
|
+
|
128
|
+
search = {}
|
129
|
+
|
130
|
+
data.extract_settings.each do |field|
|
131
|
+
if field.starts_with?("=")
|
132
|
+
field.slice!(0)
|
133
|
+
search[field] = "="
|
134
|
+
elsif field.starts_with?("^")
|
135
|
+
field.slice!(0)
|
136
|
+
search[field] = "^"
|
137
|
+
else
|
138
|
+
search[field] = "@"
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
return search
|
143
|
+
|
144
|
+
end
|
145
|
+
|
146
|
+
#--
|
147
|
+
# TODO: Test method.
|
148
|
+
#++
|
149
|
+
def typus_application
|
150
|
+
Typus::Configuration.config[name]["application"] || "Unknown"
|
151
|
+
end
|
152
|
+
|
153
|
+
def typus_field_options_for(filter)
|
154
|
+
Typus::Configuration.config[name]['fields']['options'][filter.to_s].extract_settings.collect { |i| i.to_sym }
|
155
|
+
rescue
|
156
|
+
[]
|
157
|
+
end
|
158
|
+
|
159
|
+
#--
|
160
|
+
# Options are defined for all resources on the initializer:
|
161
|
+
#
|
162
|
+
# Typus::Resources.setup do |config|
|
163
|
+
# config.per_page = 15
|
164
|
+
# end
|
165
|
+
#
|
166
|
+
# But sometimes we need to define theme by model:
|
167
|
+
#
|
168
|
+
# Post:
|
169
|
+
# ...
|
170
|
+
# options:
|
171
|
+
# per_page: 15
|
172
|
+
#++
|
173
|
+
def typus_options_for(filter)
|
174
|
+
|
175
|
+
data = Typus::Configuration.config[name]
|
176
|
+
unless data['options'].nil?
|
177
|
+
value = data['options'][filter.to_s] unless data['options'][filter.to_s].nil?
|
178
|
+
end
|
179
|
+
|
180
|
+
return (!value.nil?) ? value : Typus::Resources.send(filter)
|
181
|
+
|
182
|
+
end
|
183
|
+
|
184
|
+
def typus_export_formats
|
185
|
+
data = Typus::Configuration.config[name]
|
186
|
+
!data['export'].nil? ? data['export'].extract_settings : []
|
187
|
+
end
|
188
|
+
|
189
|
+
# Used for `order_by`.
|
190
|
+
def typus_order_by
|
191
|
+
|
192
|
+
fields = typus_defaults_for(:order_by)
|
193
|
+
|
194
|
+
if fields.empty?
|
195
|
+
"#{table_name}.#{primary_key} ASC"
|
196
|
+
else
|
197
|
+
fields.map do |field|
|
198
|
+
field.include?('-') ? "#{table_name}.#{field.delete('-')} DESC" : "#{table_name}.#{field} ASC"
|
199
|
+
end.join(', ')
|
200
|
+
end
|
201
|
+
|
202
|
+
end
|
203
|
+
|
204
|
+
#--
|
205
|
+
# Define our own boolean mappings.
|
206
|
+
#
|
207
|
+
# Post:
|
208
|
+
# fields:
|
209
|
+
# default: title, status
|
210
|
+
# options:
|
211
|
+
# booleans:
|
212
|
+
# status: "Published", "Not published"
|
213
|
+
#
|
214
|
+
#++
|
215
|
+
def typus_boolean(attribute = :default)
|
216
|
+
|
217
|
+
begin
|
218
|
+
boolean = Typus::Configuration.config[name]['fields']['options']['booleans'][attribute.to_s]
|
219
|
+
rescue
|
220
|
+
boolean = 'true, false'
|
221
|
+
end
|
222
|
+
|
223
|
+
return nil if boolean.nil?
|
224
|
+
|
225
|
+
hash = ActiveSupport::OrderedHash.new
|
226
|
+
|
227
|
+
mapping = boolean.kind_of?(Array) ? boolean : boolean.extract_settings
|
228
|
+
hash[:true], hash[:false] = mapping.first, mapping.last
|
229
|
+
hash.map { |k, v| hash[k] = v.humanize }
|
230
|
+
|
231
|
+
return hash
|
232
|
+
|
233
|
+
end
|
234
|
+
|
235
|
+
#--
|
236
|
+
# Custom date formats.
|
237
|
+
#++
|
238
|
+
def typus_date_format(attribute = :default)
|
239
|
+
Typus::Configuration.config[name]['fields']['options']['date_formats'][attribute.to_s].to_sym
|
240
|
+
rescue
|
241
|
+
:db
|
242
|
+
end
|
243
|
+
|
244
|
+
#--
|
245
|
+
# This is user to use custome templates for attribute:
|
246
|
+
#
|
247
|
+
# Post:
|
248
|
+
# fields:
|
249
|
+
# form: title, body, status
|
250
|
+
# options:
|
251
|
+
# templates:
|
252
|
+
# body: rich_text
|
253
|
+
#
|
254
|
+
# Templates are stored on <tt>app/views/admin/templates</tt>.
|
255
|
+
#++
|
256
|
+
def typus_template(attribute)
|
257
|
+
Typus::Configuration.config[name]['fields']['options']['templates'][attribute.to_s]
|
258
|
+
rescue
|
259
|
+
nil
|
260
|
+
end
|
261
|
+
|
262
|
+
#--
|
263
|
+
# Sidebar filters:
|
264
|
+
#
|
265
|
+
# - Booleans: true, false
|
266
|
+
# - Datetime: today, last_few_days, last_7_days, last_30_days
|
267
|
+
# - Integer & String: *_id and "selectors" (p.ej. category_id)
|
268
|
+
#++
|
269
|
+
def build_conditions(params)
|
270
|
+
|
271
|
+
conditions, joins = merge_conditions, []
|
272
|
+
|
273
|
+
query_params = params.dup
|
274
|
+
%w(action controller).each { |param| query_params.delete(param) }
|
275
|
+
|
276
|
+
# Remove from params those with empty string.
|
277
|
+
query_params.delete_if { |k, v| v.empty? }
|
278
|
+
|
279
|
+
# If a search is performed.
|
280
|
+
if query_params[:search]
|
281
|
+
query = ActiveRecord::Base.connection.quote_string(query_params[:search].downcase)
|
282
|
+
search = []
|
283
|
+
typus_search_fields.each do |key, value|
|
284
|
+
_query = case value
|
285
|
+
when "=" then query
|
286
|
+
when "^" then "#{query}%"
|
287
|
+
when "@" then "%#{query}%"
|
288
|
+
end
|
289
|
+
search << "#{key} LIKE '#{_query}'"
|
290
|
+
end
|
291
|
+
conditions = merge_conditions(conditions, search.join(" OR "))
|
292
|
+
end
|
293
|
+
|
294
|
+
query_params.each do |key, value|
|
295
|
+
|
296
|
+
filter_type = model_fields[key.to_sym] || model_relationships[key.to_sym]
|
297
|
+
|
298
|
+
case filter_type
|
299
|
+
when :boolean
|
300
|
+
condition = { key => (value == 'true') ? true : false }
|
301
|
+
conditions = merge_conditions(conditions, condition)
|
302
|
+
when :datetime
|
303
|
+
interval = case value
|
304
|
+
when 'today' then Time.new.midnight..Time.new.midnight.tomorrow
|
305
|
+
when 'last_few_days' then 3.days.ago.midnight..Time.new.midnight.tomorrow
|
306
|
+
when 'last_7_days' then 6.days.ago.midnight..Time.new.midnight.tomorrow
|
307
|
+
when 'last_30_days' then Time.new.midnight.prev_month..Time.new.midnight.tomorrow
|
308
|
+
end
|
309
|
+
condition = ["#{key} BETWEEN ? AND ?", interval.first.to_s(:db), interval.last.to_s(:db)]
|
310
|
+
conditions = merge_conditions(conditions, condition)
|
311
|
+
when :date
|
312
|
+
if value.is_a?(Hash)
|
313
|
+
date_format = Date::DATE_FORMATS[typus_date_format(key)]
|
314
|
+
|
315
|
+
begin
|
316
|
+
unless value["from"].blank?
|
317
|
+
date_from = Date.strptime(value["from"], date_format)
|
318
|
+
conditions = merge_conditions(conditions, ["#{key} >= ?", date_from])
|
319
|
+
end
|
320
|
+
|
321
|
+
unless value["to"].blank?
|
322
|
+
date_to = Date.strptime(value["to"], date_format)
|
323
|
+
conditions = merge_conditions(conditions, ["#{key} <= ?", date_to])
|
324
|
+
end
|
325
|
+
rescue
|
326
|
+
end
|
327
|
+
else
|
328
|
+
# TODO: Improve and test filters.
|
329
|
+
interval = case value
|
330
|
+
when 'today' then nil
|
331
|
+
when 'last_few_days' then 3.days.ago.to_date..Date.tomorrow
|
332
|
+
when 'last_7_days' then 6.days.ago.midnight..Date.tomorrow
|
333
|
+
when 'last_30_days' then (Date.today << 1)..Date.tomorrow
|
334
|
+
end
|
335
|
+
if interval
|
336
|
+
condition = ["#{key} BETWEEN ? AND ?", interval.first, interval.last]
|
337
|
+
elsif value == 'today'
|
338
|
+
condition = ["#{key} = ?", Date.today]
|
339
|
+
end
|
340
|
+
conditions = merge_conditions(conditions, condition)
|
341
|
+
end
|
342
|
+
when :integer, :string
|
343
|
+
condition = { key => value }
|
344
|
+
conditions = merge_conditions(conditions, condition)
|
345
|
+
when :has_and_belongs_to_many
|
346
|
+
condition = { key => { :id => value } }
|
347
|
+
conditions = merge_conditions(conditions, condition)
|
348
|
+
joins << key.to_sym
|
349
|
+
end
|
350
|
+
|
351
|
+
end
|
352
|
+
|
353
|
+
return conditions, joins
|
354
|
+
|
355
|
+
end
|
356
|
+
|
357
|
+
def typus_user_id?
|
358
|
+
columns.map { |u| u.name }.include?(Typus.user_fk)
|
359
|
+
end
|
360
|
+
|
361
|
+
end
|
362
|
+
|
363
|
+
module InstanceMethods
|
364
|
+
|
365
|
+
def owned_by?(user)
|
366
|
+
send(Typus.user_fk) == user.id
|
367
|
+
end
|
368
|
+
|
369
|
+
end
|
370
|
+
|
371
|
+
end
|
372
|
+
|
373
|
+
end
|
374
|
+
|
375
|
+
if defined?(ActiveRecord)
|
376
|
+
ActiveRecord::Base.extend Typus::Orm::ClassMethods
|
377
|
+
ActiveRecord::Base.send :include, Typus::Orm::InstanceMethods
|
378
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
module Typus
|
2
|
+
|
3
|
+
module Resources
|
4
|
+
|
5
|
+
# Setup Typus::Resources. This should be run from an initializer.
|
6
|
+
#
|
7
|
+
# Typus::Resources.setup do |config|
|
8
|
+
# config.default_action_on_item = "index"
|
9
|
+
# end
|
10
|
+
#
|
11
|
+
def self.setup
|
12
|
+
yield self
|
13
|
+
end
|
14
|
+
|
15
|
+
# Defines the default_action_on_item.
|
16
|
+
mattr_accessor :default_action_on_item
|
17
|
+
@@default_action_on_item = "edit"
|
18
|
+
|
19
|
+
# Defines the end_year.
|
20
|
+
mattr_accessor :end_year
|
21
|
+
@@end_year = nil
|
22
|
+
|
23
|
+
# Defines the form_rows.
|
24
|
+
mattr_accessor :form_rows
|
25
|
+
@@form_rows = 15
|
26
|
+
|
27
|
+
# Defines the action_after_save.
|
28
|
+
mattr_accessor :action_after_save
|
29
|
+
@@action_after_save = "edit"
|
30
|
+
|
31
|
+
# Defines the minute step.
|
32
|
+
mattr_accessor :minute_step
|
33
|
+
@@minute_step = 5
|
34
|
+
|
35
|
+
# Defines nil.
|
36
|
+
mattr_accessor :human_nil
|
37
|
+
@@human_nil = "nil"
|
38
|
+
|
39
|
+
# Defines only_user_items.
|
40
|
+
mattr_accessor :only_user_items
|
41
|
+
@@only_user_items = false
|
42
|
+
|
43
|
+
# Defines per_page
|
44
|
+
mattr_accessor :per_page
|
45
|
+
@@per_page = 15
|
46
|
+
|
47
|
+
# Defines start year
|
48
|
+
mattr_accessor :start_year
|
49
|
+
@@start_year = nil
|
50
|
+
|
51
|
+
def self.method_missing(*args)
|
52
|
+
nil
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
data/lib/typus/user.rb
CHANGED
@@ -26,7 +26,6 @@ module Typus
|
|
26
26
|
validates_presence_of :role
|
27
27
|
|
28
28
|
before_save :initialize_salt, :encrypt_password, :initialize_token
|
29
|
-
before_save :set_preferences
|
30
29
|
|
31
30
|
serialize :preferences
|
32
31
|
|
@@ -38,14 +37,6 @@ module Typus
|
|
38
37
|
|
39
38
|
module ClassMethodsMixin
|
40
39
|
|
41
|
-
def role
|
42
|
-
Typus::Configuration.roles.keys.sort
|
43
|
-
end
|
44
|
-
|
45
|
-
def language
|
46
|
-
Typus.locales
|
47
|
-
end
|
48
|
-
|
49
40
|
def authenticate(email, password)
|
50
41
|
user = find_by_email_and_status(email, true)
|
51
42
|
user && user.authenticated?(password) ? user : nil
|
@@ -53,10 +44,15 @@ module Typus
|
|
53
44
|
|
54
45
|
def generate(*args)
|
55
46
|
options = args.extract_options!
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
47
|
+
|
48
|
+
options[:password] ||= ActiveSupport::SecureRandom.hex(4)
|
49
|
+
options[:role] ||= Typus.master_role
|
50
|
+
|
51
|
+
new :email => options[:email],
|
52
|
+
:password => options[:password],
|
53
|
+
:password_confirmation => options[:password],
|
54
|
+
:role => options[:role],
|
55
|
+
:preferences => { :locale => I18n.default_locale.to_s }
|
60
56
|
end
|
61
57
|
|
62
58
|
end
|
@@ -64,7 +60,15 @@ module Typus
|
|
64
60
|
module InstanceMethods
|
65
61
|
|
66
62
|
def name
|
67
|
-
|
63
|
+
if !first_name.blank? and !last_name.blank?
|
64
|
+
"#{first_name} #{last_name}"
|
65
|
+
elsif !first_name.blank? and last_name.blank?
|
66
|
+
first_name
|
67
|
+
elsif first_name.blank? and !last_name.blank?
|
68
|
+
last_name
|
69
|
+
else
|
70
|
+
email
|
71
|
+
end
|
68
72
|
end
|
69
73
|
|
70
74
|
def authenticated?(password)
|
@@ -75,51 +79,64 @@ module Typus
|
|
75
79
|
Typus::Configuration.roles[role].compact
|
76
80
|
end
|
77
81
|
|
78
|
-
|
82
|
+
#--
|
83
|
+
# TODO: Rename action to mapping and refactor the _action case
|
84
|
+
# statement.
|
85
|
+
#++
|
86
|
+
def can?(action, resource, options = {})
|
79
87
|
|
80
|
-
#
|
88
|
+
# Sometimes we are getting a Class, so we need to convert it
|
89
|
+
# to string.
|
81
90
|
resource = resource.to_s
|
82
91
|
|
83
92
|
return false if !resources.include?(resource)
|
84
|
-
return true if resources[resource].include?(
|
93
|
+
return true if resources[resource].include?("all")
|
85
94
|
|
86
95
|
_action = if options[:special]
|
87
96
|
action
|
88
97
|
else
|
89
98
|
case action
|
90
|
-
when
|
91
|
-
when
|
92
|
-
when
|
93
|
-
|
94
|
-
|
95
|
-
when
|
99
|
+
when "new", "create" then "create"
|
100
|
+
when "index", "show" then "read"
|
101
|
+
when "edit", "update",
|
102
|
+
"position", "toggle",
|
103
|
+
"relate", "unrelate", "detach" then "update"
|
104
|
+
when "destroy" then "delete"
|
96
105
|
else action
|
97
106
|
end
|
98
107
|
end
|
99
108
|
|
100
|
-
resources[resource].
|
109
|
+
resources[resource].extract_settings.include?(_action)
|
110
|
+
|
111
|
+
end
|
101
112
|
|
113
|
+
def cannot?(*args)
|
114
|
+
!can?(*args)
|
102
115
|
end
|
103
116
|
|
104
117
|
def is_root?
|
105
|
-
role == Typus
|
118
|
+
role == Typus.master_role
|
106
119
|
end
|
107
120
|
|
108
|
-
|
121
|
+
def is_not_root?
|
122
|
+
!is_root?
|
123
|
+
end
|
109
124
|
|
110
125
|
def language
|
111
|
-
preferences[:locale]
|
126
|
+
preferences[:locale]
|
127
|
+
rescue
|
128
|
+
I18n.default_locale.to_s
|
112
129
|
end
|
113
130
|
|
114
131
|
def language=(locale)
|
115
|
-
|
132
|
+
options = { :locale => locale }
|
133
|
+
self.preferences.merge!(options)
|
134
|
+
rescue
|
135
|
+
self.preferences = {}
|
136
|
+
retry
|
116
137
|
end
|
117
138
|
|
118
|
-
|
119
|
-
if self.preferences.nil? || self.preferences[:locale].nil? || self.preferences[:locale].blank?
|
120
|
-
self.preferences = { :locale => Typus::Configuration.options[:default_locale] }
|
121
|
-
end
|
122
|
-
end
|
139
|
+
protected
|
123
140
|
|
124
141
|
def generate_hash(string)
|
125
142
|
Digest::SHA1.hexdigest(string)
|
@@ -131,11 +148,11 @@ module Typus
|
|
131
148
|
end
|
132
149
|
|
133
150
|
def encrypt(string)
|
134
|
-
generate_hash("--#{salt}--#{string}")
|
151
|
+
generate_hash("--#{salt}--#{string}--")
|
135
152
|
end
|
136
153
|
|
137
154
|
def initialize_salt
|
138
|
-
self.salt = generate_hash("--#{Time.now.utc.to_s}--#{email}--") if new_record?
|
155
|
+
self.salt = generate_hash("--#{Time.now.utc.to_s(:number)}--#{email}--") if new_record?
|
139
156
|
end
|
140
157
|
|
141
158
|
def initialize_token
|
@@ -143,7 +160,7 @@ module Typus
|
|
143
160
|
end
|
144
161
|
|
145
162
|
def generate_token
|
146
|
-
self.token = encrypt("--#{Time.now.utc.to_s}--#{password}--").first(12)
|
163
|
+
self.token = encrypt("--#{Time.now.utc.to_s(:number)}--#{password}--").first(12)
|
147
164
|
end
|
148
165
|
|
149
166
|
def password_required?
|
@@ -156,4 +173,4 @@ module Typus
|
|
156
173
|
|
157
174
|
end
|
158
175
|
|
159
|
-
ActiveRecord::Base.send :include, Typus::EnableAsTypusUser
|
176
|
+
ActiveRecord::Base.send :include, Typus::EnableAsTypusUser
|