hobo 1.1.0 → 1.3.0.RC
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES.txt +238 -287
- data/Rakefile +14 -31
- data/VERSION +1 -0
- data/{lib/hobo → app/controllers}/dev_controller.rb +6 -6
- data/app/controllers/dryml_support_controller.rb +13 -0
- data/{rails_generators/hobo_front_controller/templates → app/views/dev}/summary.dryml +7 -10
- data/bin/hobo +12 -144
- data/config/initializers/inflections.rb +3 -0
- data/config/routes.rb +6 -0
- data/{doctest → doctests}/hobo/lifecycles.rdoctest +40 -59
- data/{doctest → doctests/hobo}/model.rdoctest +33 -40
- data/{doctest → doctests/hobo}/multi_model_forms.rdoctest +15 -19
- data/{doctest → doctests/hobo}/scopes.rdoctest +27 -41
- data/doctests/prepare_testapp.rb +8 -0
- data/hobo.gemspec +26 -199
- data/lib/generators/hobo/activation_email.rb +11 -0
- data/lib/generators/hobo/admin_subsite/admin_subsite_generator.rb +35 -0
- data/lib/generators/hobo/admin_subsite/templates/admin.css +20 -0
- data/lib/generators/hobo/admin_subsite/templates/admin_tag_injection.erb +10 -0
- data/{rails_generators/hobo_admin_site → lib/generators/hobo/admin_subsite}/templates/application.dryml +0 -0
- data/{rails_generators/hobo_admin_site/templates/controller.rb → lib/generators/hobo/admin_subsite/templates/controller.rb.erb} +5 -5
- data/lib/generators/hobo/admin_subsite/templates/users_index.dryml +7 -0
- data/lib/generators/hobo/assets/assets_generator.rb +18 -0
- data/{rails_generators/hobo → lib/generators/hobo/assets}/templates/application.css +0 -0
- data/lib/generators/hobo/assets/templates/application.dryml.erb +9 -0
- data/{rails_generators/hobo → lib/generators/hobo/assets}/templates/dryml-support.js +2 -2
- data/lib/generators/hobo/assets/templates/dryml_taglibs_initializer.rb +1 -0
- data/lib/generators/hobo/assets/templates/en_injection.yml +19 -0
- data/{rails_generators/hobo → lib/generators/hobo/assets}/templates/guest.rb +1 -1
- data/lib/generators/hobo/controller.rb +35 -0
- data/lib/generators/hobo/controller/controller_generator.rb +6 -0
- data/lib/generators/hobo/controller/templates/controller.rb.erb +7 -0
- data/{rails_generators/hobo_front_controller → lib/generators/hobo/front_controller}/USAGE +0 -0
- data/lib/generators/hobo/front_controller/front_controller_generator.rb +55 -0
- data/{rails_generators/hobo_front_controller/templates/controller.rb → lib/generators/hobo/front_controller/templates/controller.rb.erb} +0 -0
- data/{rails_generators/hobo_front_controller → lib/generators/hobo/front_controller}/templates/index.dryml +6 -12
- data/lib/generators/hobo/i18n/i18n_generator.rb +35 -0
- data/lib/generators/hobo/i18n/templates/app.de.yml +30 -0
- data/lib/generators/hobo/i18n/templates/app.en.yml +25 -0
- data/lib/generators/hobo/i18n/templates/app.es.yml +31 -0
- data/lib/generators/hobo/i18n/templates/app.fr.yml +26 -0
- data/lib/generators/hobo/i18n/templates/app.it.yml +28 -0
- data/lib/generators/hobo/i18n/templates/app.pt-PT.yml +25 -0
- data/lib/generators/hobo/i18n/templates/app.ru.yml +24 -0
- data/lib/generators/hobo/i18n/templates/hobo.de.yml +204 -0
- data/lib/generators/hobo/i18n/templates/hobo.en.yml +195 -0
- data/lib/generators/hobo/i18n/templates/hobo.es.yml +202 -0
- data/lib/generators/hobo/i18n/templates/hobo.fr.yml +195 -0
- data/lib/generators/hobo/i18n/templates/hobo.it.yml +202 -0
- data/lib/generators/hobo/i18n/templates/hobo.pt-PT.yml +196 -0
- data/lib/generators/hobo/i18n/templates/hobo.ru.yml +200 -0
- data/lib/generators/hobo/invite_only.rb +18 -0
- data/lib/generators/hobo/model/USAGE +19 -0
- data/lib/generators/hobo/model/model_generator.rb +11 -0
- data/{rails_generators/hobo_model/templates/model.rb → lib/generators/hobo/model/templates/model_injection.rb.erb} +0 -2
- data/{rails_generators/hobo_rapid → lib/generators/hobo/rapid}/USAGE +0 -0
- data/lib/generators/hobo/rapid/rapid_generator.rb +24 -0
- data/{rails_generators/hobo_rapid → lib/generators/hobo/rapid}/templates/IE7.js +0 -0
- data/{rails_generators/hobo_rapid → lib/generators/hobo/rapid}/templates/blank.gif +0 -0
- data/{rails_generators/hobo_rapid → lib/generators/hobo/rapid}/templates/hobo-rapid.css +0 -0
- data/{rails_generators/hobo_rapid → lib/generators/hobo/rapid}/templates/hobo-rapid.js +65 -65
- data/{rails_generators/hobo_rapid → lib/generators/hobo/rapid}/templates/ie7-recalc.js +21 -21
- data/{rails_generators/hobo_rapid → lib/generators/hobo/rapid}/templates/lowpro.js +31 -31
- data/{rails_generators/hobo_rapid → lib/generators/hobo/rapid}/templates/reset.css +1 -1
- data/lib/generators/hobo/rapid/templates/themes/clean-sidemenu/public/images/100-ACD3E6-DBE1E5-H.png +0 -0
- data/lib/generators/hobo/rapid/templates/themes/clean-sidemenu/public/images/100-DBE1E5-FCFEF5-H.png +0 -0
- data/lib/generators/hobo/rapid/templates/themes/clean-sidemenu/public/images/300-3B5F87-ACD3E6-H.png +0 -0
- data/{rails_generators/hobo_rapid/templates/themes/clean → lib/generators/hobo/rapid/templates/themes/clean-sidemenu}/public/images/spinner.gif +0 -0
- data/lib/generators/hobo/rapid/templates/themes/clean-sidemenu/public/stylesheets/clean-sidemenu.css +81 -0
- data/lib/generators/hobo/rapid/templates/themes/clean-sidemenu/views/clean-sidemenu.dryml +30 -0
- data/{rails_generators/hobo_rapid → lib/generators/hobo/rapid}/templates/themes/clean/public/images/101-3B5F87-ACD3E6.png +0 -0
- data/{rails_generators/hobo_rapid → lib/generators/hobo/rapid}/templates/themes/clean/public/images/30-3E547A-242E42.png +0 -0
- data/{rails_generators/hobo_rapid → lib/generators/hobo/rapid}/templates/themes/clean/public/images/30-DBE1E5-FCFEF5.png +0 -0
- data/{rails_generators/hobo_rapid → lib/generators/hobo/rapid}/templates/themes/clean/public/images/300-ACD3E6-fff.png +0 -0
- data/{rails_generators/hobo_rapid → lib/generators/hobo/rapid}/templates/themes/clean/public/images/50-ACD3E6-fff.png +0 -0
- data/{rails_generators/hobo_rapid → lib/generators/hobo/rapid}/templates/themes/clean/public/images/fieldbg.gif +0 -0
- data/{rails_generators/hobo_rapid → lib/generators/hobo/rapid}/templates/themes/clean/public/images/pencil.png +0 -0
- data/{rails_generators/hobo_rapid → lib/generators/hobo/rapid}/templates/themes/clean/public/images/small_close.png +0 -0
- data/lib/generators/hobo/rapid/templates/themes/clean/public/images/spinner.gif +0 -0
- data/{rails_generators/hobo_rapid → lib/generators/hobo/rapid}/templates/themes/clean/public/stylesheets/clean.css +16 -16
- data/{rails_generators/hobo_rapid → lib/generators/hobo/rapid}/templates/themes/clean/public/stylesheets/rapid-ui.css +3 -3
- data/{rails_generators/hobo_rapid → lib/generators/hobo/rapid}/templates/themes/clean/views/clean.dryml +1 -1
- data/lib/generators/hobo/resource/resource_generator.rb +23 -0
- data/lib/generators/hobo/routes/USAGE +9 -0
- data/lib/generators/hobo/routes/router.rb +115 -0
- data/lib/generators/hobo/routes/routes_generator.rb +40 -0
- data/lib/generators/hobo/routes/templates/hobo_routes.rb.erb +33 -0
- data/lib/generators/hobo/setup_wizard/USAGE +4 -0
- data/lib/generators/hobo/setup_wizard/setup_wizard_generator.rb +274 -0
- data/lib/generators/hobo/subsite.rb +48 -0
- data/lib/generators/hobo/subsite/subsite_generator.rb +16 -0
- data/{rails_generators/hobo_subsite → lib/generators/hobo/subsite}/templates/application.dryml +0 -0
- data/{rails_generators/hobo_subsite/templates/controller.rb → lib/generators/hobo/subsite/templates/controller.rb.erb} +1 -1
- data/lib/generators/hobo/subsite_taglib/subsite_taglib_generator.rb +16 -0
- data/{rails_generators/hobo_admin_site/templates/site_taglib.dryml → lib/generators/hobo/subsite_taglib/templates/taglib.dryml.erb} +9 -10
- data/lib/generators/hobo/taglib.rb +12 -0
- data/lib/generators/hobo/test_framework/test_framework_generator.rb +72 -0
- data/lib/generators/hobo/test_options.rb +19 -0
- data/{rails_generators/hobo_user_controller → lib/generators/hobo/user_controller}/templates/accept_invitation.dryml +0 -0
- data/lib/generators/hobo/user_controller/templates/controller.rb.erb +31 -0
- data/lib/generators/hobo/user_controller/user_controller_generator.rb +25 -0
- data/lib/generators/hobo/user_mailer/templates/activation.erb +9 -0
- data/{rails_generators/hobo_user_model → lib/generators/hobo/user_mailer}/templates/forgot_password.erb +2 -2
- data/{rails_generators/hobo_user_model → lib/generators/hobo/user_mailer}/templates/invite.erb +2 -2
- data/lib/generators/hobo/user_mailer/templates/mailer.rb.erb +25 -0
- data/lib/generators/hobo/user_mailer/user_mailer_generator.rb +33 -0
- data/lib/generators/hobo/user_model/USAGE +12 -0
- data/{rails_generators/hobo_user_model/templates/model.rb → lib/generators/hobo/user_model/templates/model_injection.rb.erb} +40 -20
- data/lib/generators/hobo/user_model/user_model_generator.rb +23 -0
- data/lib/generators/hobo/user_resource/user_resource_generator.rb +27 -0
- data/lib/hobo.rb +29 -129
- data/lib/hobo/controller.rb +37 -47
- data/lib/hobo/controller/authentication_support.rb +109 -0
- data/lib/hobo/{model_controller.rb → controller/model.rb} +71 -79
- data/lib/hobo/{user_controller.rb → controller/user.rb} +59 -49
- data/lib/hobo/engine.rb +80 -0
- data/lib/hobo/extensions/action_controller/hobo_methods.rb +44 -0
- data/lib/hobo/extensions/action_mailer/helper.rb +38 -0
- data/lib/{action_view_extensions/helpers → hobo/extensions/action_view}/tag_helper.rb +5 -2
- data/lib/hobo/extensions/action_view/translation_helper.rb +25 -0
- data/lib/hobo/extensions/active_model/name.rb +16 -0
- data/lib/hobo/extensions/active_model/translation.rb +35 -0
- data/lib/{active_record/association_collection.rb → hobo/extensions/active_record/associations/collection.rb} +8 -17
- data/lib/{active_record/association_proxy.rb → hobo/extensions/active_record/associations/proxy.rb} +6 -7
- data/lib/hobo/extensions/active_record/associations/reflection.rb +23 -0
- data/lib/hobo/extensions/active_record/associations/scope.rb +35 -0
- data/lib/hobo/extensions/active_record/hobo_methods.rb +11 -0
- data/lib/hobo/extensions/active_record/permissions.rb +159 -0
- data/lib/hobo/extensions/active_record/relation_with_origin.rb +28 -0
- data/lib/hobo/extensions/array.rb +27 -0
- data/lib/hobo/extensions/enumerable.rb +12 -0
- data/lib/hobo/extensions/i18n.rb +17 -0
- data/lib/hobo/{hobo_helper.rb → helper.rb} +58 -31
- data/lib/hobo/helper/translations.rb +54 -0
- data/lib/hobo/helper/translations/normalizer.rb +39 -0
- data/lib/hobo/model.rb +61 -95
- data/lib/hobo/model/accessible_associations.rb +178 -0
- data/lib/hobo/{find_for.rb → model/find_for.rb} +17 -17
- data/lib/hobo/model/guest.rb +25 -0
- data/lib/hobo/model/include_in_save.rb +55 -0
- data/lib/hobo/model/lifecycles.rb +119 -0
- data/lib/hobo/model/lifecycles/actions.rb +146 -0
- data/lib/hobo/model/lifecycles/creator.rb +74 -0
- data/lib/hobo/model/lifecycles/lifecycle.rb +243 -0
- data/lib/hobo/model/lifecycles/state.rb +22 -0
- data/lib/hobo/model/lifecycles/transition.rb +70 -0
- data/lib/hobo/model/permissions.rb +448 -0
- data/lib/hobo/model/scopes.rb +38 -0
- data/lib/hobo/model/scopes/apply_scopes.rb +21 -0
- data/lib/hobo/model/scopes/automatic_scopes.rb +428 -0
- data/lib/hobo/model/user_base.rb +184 -0
- data/lib/hobo/model/view_hints.rb +123 -0
- data/{rapid_generators → lib/hobo/rapid/generators}/rapid/cards.dryml.erb +2 -2
- data/{rapid_generators → lib/hobo/rapid/generators}/rapid/forms.dryml.erb +3 -3
- data/{rapid_generators → lib/hobo/rapid/generators}/rapid/pages.dryml.erb +38 -51
- data/lib/hobo/rapid/helper.rb +166 -0
- data/{taglibs → lib/hobo/rapid/taglibs}/rapid.dryml +6 -5
- data/{taglibs → lib/hobo/rapid/taglibs}/rapid_core.dryml +286 -118
- data/{taglibs → lib/hobo/rapid/taglibs}/rapid_document_tags.dryml +2 -2
- data/{taglibs → lib/hobo/rapid/taglibs}/rapid_editing.dryml +45 -45
- data/{taglibs → lib/hobo/rapid/taglibs}/rapid_forms.dryml +190 -158
- data/{taglibs → lib/hobo/rapid/taglibs}/rapid_generics.dryml +12 -9
- data/lib/hobo/rapid/taglibs/rapid_i18n.dryml +107 -0
- data/{taglibs → lib/hobo/rapid/taglibs}/rapid_lifecycles.dryml +7 -7
- data/{taglibs → lib/hobo/rapid/taglibs}/rapid_navigation.dryml +15 -15
- data/{taglibs → lib/hobo/rapid/taglibs}/rapid_pages.dryml +37 -36
- data/{taglibs → lib/hobo/rapid/taglibs}/rapid_plus.dryml +107 -43
- data/{taglibs → lib/hobo/rapid/taglibs}/rapid_summary.dryml +28 -57
- data/{taglibs → lib/hobo/rapid/taglibs}/rapid_support.dryml +9 -9
- data/{taglibs → lib/hobo/rapid/taglibs}/rapid_user_pages.dryml +41 -40
- data/lib/hobo/routes.rb +31 -0
- data/{doctest → test/doctest}/hobo/hobo_helper.rdoctest +11 -11
- data/test/irt/generators/admin_subsite.irt +27 -0
- data/test/irt/generators/assets.irt +16 -0
- data/test/irt/generators/controller.irt +6 -0
- data/test/irt/generators/front_controller.irt +30 -0
- data/test/irt/generators/helper.rb +31 -0
- data/test/irt/generators/model.irt +28 -0
- data/test/irt/generators/partials/_account_user_model_tests.rb +21 -0
- data/test/irt/generators/partials/_accounts_users_controller_tests.rb +15 -0
- data/test/irt/generators/partials/_default_user_model_tests.rb +21 -0
- data/test/irt/generators/partials/_default_users_controller_tests.rb +16 -0
- data/test/irt/generators/partials/_house_controller_tests.rb +15 -0
- data/test/irt/generators/partials/_house_model_tests.rb +18 -0
- data/test/irt/generators/partials/_subsite_taglib_admin.rb +4 -0
- data/test/irt/generators/partials/_subsite_taglib_admin_invite_only.rb +3 -0
- data/test/irt/generators/partials/_subsite_taglib_noopt.rb +4 -0
- data/test/irt/generators/partials/_subsite_taglib_variables.rb +27 -0
- data/test/irt/generators/partials/_user_mailer_tests.rb +19 -0
- data/test/irt/generators/rapid.irt +29 -0
- data/test/irt/generators/resource.irt +8 -0
- data/test/irt/generators/subsite.irt +52 -0
- data/test/irt/generators/subsite_taglib.irt +23 -0
- data/test/irt/generators/test_framework.irt +62 -0
- data/test/irt/generators/user_controller.irt +10 -0
- data/test/irt/generators/user_mailer.irt +20 -0
- data/test/irt/generators/user_model.irt +10 -0
- data/test/irt/generators/user_resource.irt +14 -0
- data/test/irt/readme.txt +7 -0
- data/test/permissions/models/models.rb +27 -24
- data/test/permissions/test_permissions.rb +104 -104
- metadata +239 -217
- data/lib/active_record/association_reflection.rb +0 -20
- data/lib/active_record/viewhints_validations_interceptor.rb +0 -9
- data/lib/hobo/accessible_associations.rb +0 -183
- data/lib/hobo/authentication_support.rb +0 -131
- data/lib/hobo/generator.rb +0 -26
- data/lib/hobo/guest.rb +0 -25
- data/lib/hobo/include_in_save.rb +0 -55
- data/lib/hobo/lifecycles.rb +0 -137
- data/lib/hobo/lifecycles/actions.rb +0 -142
- data/lib/hobo/lifecycles/creator.rb +0 -72
- data/lib/hobo/lifecycles/lifecycle.rb +0 -249
- data/lib/hobo/lifecycles/state.rb +0 -22
- data/lib/hobo/lifecycles/transition.rb +0 -70
- data/lib/hobo/model_router.rb +0 -290
- data/lib/hobo/permissions.rb +0 -451
- data/lib/hobo/permissions/associations.rb +0 -175
- data/lib/hobo/rapid_helper.rb +0 -157
- data/lib/hobo/scopes.rb +0 -43
- data/lib/hobo/scopes/apply_scopes.rb +0 -23
- data/lib/hobo/scopes/association_proxy_extensions.rb +0 -62
- data/lib/hobo/scopes/automatic_scopes.rb +0 -421
- data/lib/hobo/scopes/named_scope_extensions.rb +0 -39
- data/lib/hobo/tasks/rails.rb +0 -4
- data/lib/hobo/translations.rb +0 -93
- data/lib/hobo/undefined_access_error.rb +0 -5
- data/lib/hobo/user.rb +0 -182
- data/lib/hobo/view_hints.rb +0 -115
- data/rails/init.rb +0 -10
- data/rails_generators/hobo/USAGE +0 -4
- data/rails_generators/hobo/hobo_generator.rb +0 -53
- data/rails_generators/hobo/templates/application.dryml +0 -1
- data/rails_generators/hobo/templates/initializer.rb +0 -2
- data/rails_generators/hobo_admin_site/USAGE +0 -16
- data/rails_generators/hobo_admin_site/hobo_admin_site_generator.rb +0 -45
- data/rails_generators/hobo_admin_site/templates/admin.css +0 -2
- data/rails_generators/hobo_admin_site/templates/users_index.dryml +0 -5
- data/rails_generators/hobo_front_controller/hobo_front_controller_generator.rb +0 -95
- data/rails_generators/hobo_front_controller/templates/functional_test.rb +0 -8
- data/rails_generators/hobo_front_controller/templates/helper.rb +0 -2
- data/rails_generators/hobo_model/USAGE +0 -25
- data/rails_generators/hobo_model/hobo_model_generator.rb +0 -43
- data/rails_generators/hobo_model/templates/fixtures.yml +0 -6
- data/rails_generators/hobo_model/templates/hints.rb +0 -7
- data/rails_generators/hobo_model/templates/unit_test.rb +0 -8
- data/rails_generators/hobo_model_controller/USAGE +0 -30
- data/rails_generators/hobo_model_controller/hobo_model_controller_generator.rb +0 -46
- data/rails_generators/hobo_model_controller/templates/controller.rb +0 -7
- data/rails_generators/hobo_model_controller/templates/functional_test.rb +0 -8
- data/rails_generators/hobo_model_controller/templates/helper.rb +0 -2
- data/rails_generators/hobo_model_resource/USAGE +0 -38
- data/rails_generators/hobo_model_resource/hobo_model_resource_generator.rb +0 -73
- data/rails_generators/hobo_model_resource/templates/controller.rb +0 -7
- data/rails_generators/hobo_model_resource/templates/functional_test.rb +0 -8
- data/rails_generators/hobo_model_resource/templates/helper.rb +0 -2
- data/rails_generators/hobo_rapid/hobo_rapid_generator.rb +0 -94
- data/rails_generators/hobo_subsite/USAGE +0 -16
- data/rails_generators/hobo_subsite/hobo_subsite_generator.rb +0 -73
- data/rails_generators/hobo_subsite/templates/site_taglib.dryml +0 -13
- data/rails_generators/hobo_user_controller/USAGE +0 -34
- data/rails_generators/hobo_user_controller/hobo_user_controller_generator.rb +0 -65
- data/rails_generators/hobo_user_controller/templates/controller.rb +0 -29
- data/rails_generators/hobo_user_controller/templates/functional_test.rb +0 -8
- data/rails_generators/hobo_user_controller/templates/helper.rb +0 -2
- data/rails_generators/hobo_user_model/USAGE +0 -16
- data/rails_generators/hobo_user_model/hobo_user_model_generator.rb +0 -46
- data/rails_generators/hobo_user_model/templates/fixtures.yml +0 -19
- data/rails_generators/hobo_user_model/templates/mailer.rb +0 -29
- data/rails_generators/hobo_user_model/templates/unit_test.rb +0 -8
- data/script/destroy +0 -14
- data/script/generate +0 -14
- data/taglibs/rapid_translations.dryml +0 -36
- data/tasks/environments.rake +0 -19
- data/tasks/hobo_tasks.rake +0 -58
- data/test/generators/test_generator_helper.rb +0 -29
- data/test/generators/test_helper.rb +0 -1
- data/test/generators/test_hobo_model_controller_generator.rb +0 -56
@@ -0,0 +1,22 @@
|
|
1
|
+
module Hobo
|
2
|
+
module Model
|
3
|
+
module Lifecycles
|
4
|
+
|
5
|
+
class State < Struct.new(:name, :on_enter, :transitions_out)
|
6
|
+
|
7
|
+
include Actions
|
8
|
+
|
9
|
+
def initialize(*args)
|
10
|
+
super
|
11
|
+
self.transitions_out = []
|
12
|
+
end
|
13
|
+
|
14
|
+
|
15
|
+
def activate!(record)
|
16
|
+
fire_event(record, on_enter)
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
module Hobo
|
2
|
+
module Model
|
3
|
+
module Lifecycles
|
4
|
+
|
5
|
+
class Transition < Struct.new(:lifecycle, :name, :start_states, :end_state, :on_transition, :options)
|
6
|
+
|
7
|
+
include Actions
|
8
|
+
|
9
|
+
|
10
|
+
def initialize(*args)
|
11
|
+
super
|
12
|
+
self.name = name.to_sym
|
13
|
+
start_states.each do |from|
|
14
|
+
state = lifecycle.states[from]
|
15
|
+
raise ArgumentError, "No such state '#{from}' in #{name} transition (#{lifecycle.model.name})" unless state
|
16
|
+
state.transitions_out << self
|
17
|
+
end
|
18
|
+
lifecycle.transitions << self
|
19
|
+
end
|
20
|
+
|
21
|
+
|
22
|
+
def extract_attributes(attributes)
|
23
|
+
model = lifecycle.model
|
24
|
+
params = options.fetch(:params, [])
|
25
|
+
allowed = params.dup
|
26
|
+
params.each do |p|
|
27
|
+
if (refl = model.reflections[p]) && refl.macro == :belongs_to
|
28
|
+
allowed << refl.primary_key_name.to_s
|
29
|
+
allowed << refl.options[:foreign_type] if refl.options[:polymorphic]
|
30
|
+
end
|
31
|
+
end
|
32
|
+
attributes & allowed
|
33
|
+
end
|
34
|
+
|
35
|
+
|
36
|
+
def change_state(record)
|
37
|
+
record.lifecycle.clear_key unless options[:new_key] || options[:keep_key]
|
38
|
+
record.lifecycle.become(get_state(record, end_state))
|
39
|
+
end
|
40
|
+
|
41
|
+
|
42
|
+
def run!(record, user, attributes)
|
43
|
+
current_state = record.lifecycle.state_name
|
44
|
+
unless start_states.include?(current_state)
|
45
|
+
raise Hobo::Model::Lifecycles::LifecycleError, "Transition #{record.class}##{name} cannot be run from the '#{current_state}' state"
|
46
|
+
end
|
47
|
+
record.lifecycle.active_step = self
|
48
|
+
record.with_acting_user(user) do
|
49
|
+
prepare!(record, attributes)
|
50
|
+
if can_run?(record)
|
51
|
+
if change_state(record)
|
52
|
+
fire_event(record, on_transition)
|
53
|
+
end
|
54
|
+
else
|
55
|
+
raise Hobo::PermissionDeniedError
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
|
61
|
+
def parameters
|
62
|
+
options[:params] || []
|
63
|
+
end
|
64
|
+
|
65
|
+
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,448 @@
|
|
1
|
+
module Hobo
|
2
|
+
module Model
|
3
|
+
module Permissions
|
4
|
+
|
5
|
+
|
6
|
+
def self.included(klass)
|
7
|
+
klass.class_eval do
|
8
|
+
extend ClassMethods
|
9
|
+
|
10
|
+
alias_method_chain :create, :hobo_permission_check
|
11
|
+
alias_method_chain :update, :hobo_permission_check
|
12
|
+
alias_method_chain :destroy, :hobo_permission_check
|
13
|
+
class << self
|
14
|
+
alias_method_chain :has_many, :hobo_permission_check
|
15
|
+
alias_method_chain :has_one, :hobo_permission_check
|
16
|
+
alias_method_chain :belongs_to, :hobo_permission_check
|
17
|
+
end
|
18
|
+
|
19
|
+
attr_accessor :acting_user, :origin, :origin_attribute
|
20
|
+
|
21
|
+
bool_attr_accessor :exempt_from_edit_checks
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.find_aliased_name(klass, method_name)
|
26
|
+
# The method +method_name+ will have been aliased. We jump through some hoops to figure out
|
27
|
+
# what it's new name is
|
28
|
+
method_name = method_name.to_sym
|
29
|
+
method = klass.instance_method method_name
|
30
|
+
methods = (klass.private_instance_methods + klass.instance_methods).*.to_sym
|
31
|
+
new_name = methods.select {|m| klass.instance_method(m) == method }.find { |m| m != method_name }
|
32
|
+
end
|
33
|
+
|
34
|
+
module ClassMethods
|
35
|
+
|
36
|
+
def user_find(user, *args)
|
37
|
+
record = find(*args)
|
38
|
+
yield(record) if block_given?
|
39
|
+
record.user_view user
|
40
|
+
record
|
41
|
+
end
|
42
|
+
|
43
|
+
|
44
|
+
def user_new(user, attributes={})
|
45
|
+
new(attributes) do |r|
|
46
|
+
r.set_creator user
|
47
|
+
yield r if block_given?
|
48
|
+
r.user_view(user)
|
49
|
+
r.with_acting_user(user) { r.try.after_user_new }
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
|
54
|
+
def user_create(user, attributes={}, &block)
|
55
|
+
if attributes.is_a?(Array)
|
56
|
+
attributes.map { |attrs| user_create(user, attrs) }
|
57
|
+
else
|
58
|
+
record = user_new(user, attributes, &block)
|
59
|
+
record.user_save(user)
|
60
|
+
record
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
|
65
|
+
def user_create!(user, attributes={}, &block)
|
66
|
+
if attributes.is_a?(Array)
|
67
|
+
attributes.map { |attrs| user_create(user, attrs) }
|
68
|
+
else
|
69
|
+
record = user_new(user, attributes, &block)
|
70
|
+
record.user_save!(user)
|
71
|
+
record
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
def viewable_by?(user, attribute=nil)
|
76
|
+
new.viewable_by?(user, attribute)
|
77
|
+
end
|
78
|
+
|
79
|
+
# ensure active_user gets passed down to :dependent => destroy
|
80
|
+
# associations (Ticket #528)
|
81
|
+
|
82
|
+
def has_many_with_hobo_permission_check(association_id, options = {}, &extension)
|
83
|
+
has_many_without_hobo_permission_check(association_id, options, &extension)
|
84
|
+
reflection = reflections[association_id]
|
85
|
+
if reflection.options[:dependent]==:destroy
|
86
|
+
#overriding dynamic method created in ActiveRecord::Associations#configure_dependency_for_has_many
|
87
|
+
method_name = "has_many_dependent_destroy_for_#{reflection.name}".to_sym
|
88
|
+
define_method(method_name) do
|
89
|
+
send(reflection.name).each { |r| r.is_a?(Hobo::Model) ? r.user_destroy(acting_user) : r.destroy }
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
def has_one_with_hobo_permission_check(association_id, options = {}, &extension)
|
95
|
+
has_one_without_hobo_permission_check(association_id, options, &extension)
|
96
|
+
reflection = reflections[association_id]
|
97
|
+
if reflection.options[:dependent]==:destroy
|
98
|
+
#overriding dynamic method created in ActiveRecord::Associations#configure_dependency_for_has_one
|
99
|
+
method_name = "has_one_dependent_destroy_for_#{reflection.name}".to_sym
|
100
|
+
define_method(method_name) do
|
101
|
+
association = send(reflection.name)
|
102
|
+
unless association.nil?
|
103
|
+
association.is_a?(Hobo::Model) ? association.user_destroy(acting_user) : association.destroy
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
def belongs_to_with_hobo_permission_check(association_id, options = {}, &extension)
|
110
|
+
belongs_to_without_hobo_permission_check(association_id, options, &extension)
|
111
|
+
reflection = reflections[association_id]
|
112
|
+
if reflection.options[:dependent]==:destroy
|
113
|
+
#overriding dynamic method created in ActiveRecord::Associations#configure_dependency_for_belongs_to
|
114
|
+
method_name = "belongs_to_dependent_destroy_for_#{reflection.name}".to_sym
|
115
|
+
define_method(method_name) do
|
116
|
+
association = send(reflection.name)
|
117
|
+
unless association.nil?
|
118
|
+
association.is_a?(Hobo::Model) ? association.user_destroy(acting_user) : association.destroy
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
end
|
125
|
+
|
126
|
+
|
127
|
+
# --- Hook ActiveRecord CRUD actions --- #
|
128
|
+
|
129
|
+
|
130
|
+
def permission_check_required?
|
131
|
+
# Lifecycle steps are exempt from permission checks
|
132
|
+
acting_user && !(self.class.has_lifecycle? && lifecycle.active_step)
|
133
|
+
end
|
134
|
+
|
135
|
+
def create_with_hobo_permission_check(*args, &b)
|
136
|
+
if permission_check_required?
|
137
|
+
create_permitted? or raise PermissionDeniedError, "#{self.class.name}#create"
|
138
|
+
end
|
139
|
+
create_without_hobo_permission_check(*args, &b)
|
140
|
+
end
|
141
|
+
|
142
|
+
def update_with_hobo_permission_check(*args)
|
143
|
+
if permission_check_required?
|
144
|
+
update_permitted? or raise PermissionDeniedError, "#{self.class.name}#update"
|
145
|
+
end
|
146
|
+
update_without_hobo_permission_check(*args)
|
147
|
+
end
|
148
|
+
|
149
|
+
def destroy_with_hobo_permission_check
|
150
|
+
if permission_check_required?
|
151
|
+
destroy_permitted? or raise PermissionDeniedError, "#{self.class.name}#.destroy"
|
152
|
+
end
|
153
|
+
|
154
|
+
destroy_without_hobo_permission_check
|
155
|
+
end
|
156
|
+
|
157
|
+
# -------------------------------------- #
|
158
|
+
|
159
|
+
|
160
|
+
# --- Permissions API --- #
|
161
|
+
|
162
|
+
|
163
|
+
def with_acting_user(user)
|
164
|
+
return yield if user == acting_user
|
165
|
+
old = acting_user
|
166
|
+
self.acting_user = user
|
167
|
+
result = yield
|
168
|
+
self.acting_user = old
|
169
|
+
result
|
170
|
+
end
|
171
|
+
|
172
|
+
def user_save(user, validate = true)
|
173
|
+
with_acting_user(user) { save(:validate => validate) }
|
174
|
+
end
|
175
|
+
|
176
|
+
def user_save!(user)
|
177
|
+
with_acting_user(user) { save! }
|
178
|
+
end
|
179
|
+
|
180
|
+
def user_destroy(user)
|
181
|
+
with_acting_user(user) { destroy }
|
182
|
+
end
|
183
|
+
|
184
|
+
def user_view(user, attribute=nil)
|
185
|
+
raise PermissionDeniedError unless viewable_by?(user, attribute)
|
186
|
+
end
|
187
|
+
|
188
|
+
def user_update_attributes(user, attributes)
|
189
|
+
with_acting_user(user) do
|
190
|
+
self.attributes = attributes
|
191
|
+
save
|
192
|
+
end
|
193
|
+
end
|
194
|
+
|
195
|
+
def user_update_attributes!(user, attributes)
|
196
|
+
with_acting_user(user) do
|
197
|
+
self.attributes = attributes
|
198
|
+
save!
|
199
|
+
end
|
200
|
+
end
|
201
|
+
|
202
|
+
def creatable_by?(user)
|
203
|
+
with_acting_user(user) { create_permitted? }
|
204
|
+
end
|
205
|
+
|
206
|
+
def updatable_by?(user)
|
207
|
+
with_acting_user(user) { update_permitted? }
|
208
|
+
end
|
209
|
+
|
210
|
+
def destroyable_by?(user)
|
211
|
+
with_acting_user(user) { destroy_permitted? }
|
212
|
+
end
|
213
|
+
|
214
|
+
def method_callable_by?(user, method)
|
215
|
+
permission_method = "#{method}_permitted?"
|
216
|
+
respond_to?(permission_method) && with_acting_user(user) { send(permission_method) }
|
217
|
+
end
|
218
|
+
|
219
|
+
def viewable_by?(user, attribute=nil)
|
220
|
+
if attribute
|
221
|
+
attribute = attribute.to_s.sub(/\?$/, '').to_sym
|
222
|
+
return false if attribute && self.class.never_show?(attribute)
|
223
|
+
end
|
224
|
+
with_acting_user(user) { view_permitted?(attribute) }
|
225
|
+
end
|
226
|
+
|
227
|
+
|
228
|
+
def editable_by?(user, attribute=nil)
|
229
|
+
return false if attribute_protected?(attribute)
|
230
|
+
|
231
|
+
return true if exempt_from_edit_checks?
|
232
|
+
|
233
|
+
# Can't view implies can't edit
|
234
|
+
return false unless viewable_by?(user, attribute)
|
235
|
+
|
236
|
+
if attribute
|
237
|
+
attribute = attribute.to_s.sub(/\?$/, '').to_sym
|
238
|
+
|
239
|
+
# Try the attribute-specific edit-permission method if there is one
|
240
|
+
if has_hobo_method?(meth = "#{attribute}_edit_permitted?")
|
241
|
+
return with_acting_user(user) { send(meth) }
|
242
|
+
end
|
243
|
+
|
244
|
+
# No setter = no edit permission
|
245
|
+
return false if !respond_to?("#{attribute}=")
|
246
|
+
|
247
|
+
refl = self.class.reflections[attribute.to_sym]
|
248
|
+
if refl && refl.macro != :belongs_to # a belongs_to is handled the same as a regular attribute
|
249
|
+
return association_editable_by?(user, refl)
|
250
|
+
end
|
251
|
+
end
|
252
|
+
|
253
|
+
with_acting_user(user) { edit_permitted?(attribute) }
|
254
|
+
end
|
255
|
+
|
256
|
+
|
257
|
+
def attribute_protected?(attribute)
|
258
|
+
attribute = attribute.to_s
|
259
|
+
|
260
|
+
return true if self.class.attributes_protected_by_default.include? attribute
|
261
|
+
|
262
|
+
if !self.class.accessible_attributes.empty?
|
263
|
+
return true if !self.class.accessible_attributes.include?(attribute)
|
264
|
+
elsif self.class.protected_attributes
|
265
|
+
return true if self.class.protected_attributes.include?(attribute)
|
266
|
+
end
|
267
|
+
|
268
|
+
# Readonly attributes can be set on creation but not thereafter
|
269
|
+
return self.class.readonly_attributes.include?(attribute) if !new_record? && self.class.readonly_attributes
|
270
|
+
|
271
|
+
false
|
272
|
+
end
|
273
|
+
|
274
|
+
|
275
|
+
def association_editable_by?(user, reflection)
|
276
|
+
# has_one and polymorphic associations are not editable (for now)
|
277
|
+
return false if reflection.macro == :has_one || reflection.options[:polymorphic]
|
278
|
+
|
279
|
+
return false unless reflection.options[:accessible]
|
280
|
+
|
281
|
+
record = if (through = reflection.through_reflection)
|
282
|
+
# For edit permission on a has_many :through,
|
283
|
+
# the user needs create+destroy permission on the join model
|
284
|
+
send(through.name).new_candidate
|
285
|
+
else
|
286
|
+
# For edit permission on a regular has_many,
|
287
|
+
# the user needs create/destroy permission on the member model
|
288
|
+
send(reflection.name).new_candidate
|
289
|
+
end
|
290
|
+
record.creatable_by?(user) && record.destroyable_by?(user)
|
291
|
+
end
|
292
|
+
|
293
|
+
# ----------------------- #
|
294
|
+
|
295
|
+
|
296
|
+
# --- Permission Declaration Helpers --- #
|
297
|
+
|
298
|
+
def only_changed?(*attributes)
|
299
|
+
attributes = attributes.map do |attr|
|
300
|
+
with_attribute_or_belongs_to_keys(attr) { |a, ftype| ftype ? [a, ftype] : a }
|
301
|
+
end.flatten
|
302
|
+
|
303
|
+
changed.all? { |attr| attributes.include?(attr) }
|
304
|
+
end
|
305
|
+
|
306
|
+
def none_changed?(*attributes)
|
307
|
+
attributes = attributes.map do |attr|
|
308
|
+
with_attribute_or_belongs_to_keys(attr) { |a, ftype| ftype ? [a, ftype] : a }
|
309
|
+
end.flatten
|
310
|
+
|
311
|
+
attributes.all? { |attr| !changed.include?(attr) }
|
312
|
+
end
|
313
|
+
|
314
|
+
def any_changed?(*attributes)
|
315
|
+
attributes.any? do |attr|
|
316
|
+
with_attribute_or_belongs_to_keys(attr) do |a, ftype|
|
317
|
+
if ftype
|
318
|
+
changed.include?(a) || changed.include?(ftype)
|
319
|
+
else
|
320
|
+
changed.include?(a)
|
321
|
+
end
|
322
|
+
end
|
323
|
+
end
|
324
|
+
end
|
325
|
+
|
326
|
+
def all_changed?(*attributes)
|
327
|
+
attributes = prepare_attributes_for_change_helpers(attributes)
|
328
|
+
attributes.all? do |attr|
|
329
|
+
with_attribute_or_belongs_to_keys(attr) do |a, ftype|
|
330
|
+
if ftype
|
331
|
+
changed.include?(a) || changed.include?(ftype)
|
332
|
+
else
|
333
|
+
changed.include?(a)
|
334
|
+
end
|
335
|
+
end
|
336
|
+
end
|
337
|
+
end
|
338
|
+
|
339
|
+
def with_attribute_or_belongs_to_keys(attribute)
|
340
|
+
if (refl = self.class.reflections[attribute.to_sym]) && refl.macro == :belongs_to
|
341
|
+
if refl.options[:polymorphic]
|
342
|
+
yield refl.primary_key_name, refl.options[:foreign_type]
|
343
|
+
else
|
344
|
+
yield refl.primary_key_name, nil
|
345
|
+
end
|
346
|
+
else
|
347
|
+
yield attribute.to_s, nil
|
348
|
+
end
|
349
|
+
end
|
350
|
+
|
351
|
+
|
352
|
+
|
353
|
+
# -------------------------------------- #
|
354
|
+
|
355
|
+
|
356
|
+
# --- Default *_permitted? methods --- #
|
357
|
+
|
358
|
+
# Conservative default permissions #
|
359
|
+
def create_permitted?; false end
|
360
|
+
def update_permitted?; false end
|
361
|
+
def destroy_permitted?; false end
|
362
|
+
|
363
|
+
# Allow viewing by default
|
364
|
+
def view_permitted?(attribute) true end
|
365
|
+
|
366
|
+
# By default, attempt to derive edit permission from create/update permission
|
367
|
+
def edit_permitted?(attribute)
|
368
|
+
unknownify_attribute(attribute) if attribute
|
369
|
+
new_record? ? create_permitted? : update_permitted?
|
370
|
+
rescue Hobo::UndefinedAccessError
|
371
|
+
# The permission is dependent on the unknown value
|
372
|
+
# so this attribute is not editable
|
373
|
+
false
|
374
|
+
ensure
|
375
|
+
deunknownify_attribute(attribute) if attribute
|
376
|
+
end
|
377
|
+
|
378
|
+
|
379
|
+
# Add some singleton methods to +record+ to give the effect that +attribute+ is unknown. That is,
|
380
|
+
# attempts to access the attribute will result in a Hobo::UndefinedAccessError
|
381
|
+
def unknownify_attribute(attr)
|
382
|
+
metaclass.class_eval do
|
383
|
+
define_method attr do
|
384
|
+
raise Hobo::UndefinedAccessError
|
385
|
+
end
|
386
|
+
end
|
387
|
+
|
388
|
+
if (refl = self.class.reflections[attr.to_sym]) && refl.macro == :belongs_to
|
389
|
+
# A belongs_to -- also unknownify the underlying fields
|
390
|
+
unknownify_attribute refl.primary_key_name
|
391
|
+
unknownify_attribute refl.options[:foreign_type] if refl.options[:polymorphic]
|
392
|
+
else
|
393
|
+
# A regular field -- hack the dirty tracking methods
|
394
|
+
|
395
|
+
metaclass.class_eval do
|
396
|
+
|
397
|
+
define_method "#{attr}_change" do
|
398
|
+
raise Hobo::UndefinedAccessError
|
399
|
+
end
|
400
|
+
|
401
|
+
define_method "#{attr}_was" do
|
402
|
+
read_attribute attr
|
403
|
+
end
|
404
|
+
|
405
|
+
define_method "#{attr}_changed?" do
|
406
|
+
true
|
407
|
+
end
|
408
|
+
|
409
|
+
def changed?
|
410
|
+
true
|
411
|
+
end
|
412
|
+
|
413
|
+
define_method :changed do
|
414
|
+
changed_attributes.keys | [attr.to_s]
|
415
|
+
end
|
416
|
+
|
417
|
+
def changes
|
418
|
+
raise Hobo::UndefinedAccessError
|
419
|
+
end
|
420
|
+
|
421
|
+
end
|
422
|
+
end
|
423
|
+
end
|
424
|
+
|
425
|
+
# Best. Name. Ever
|
426
|
+
def deunknownify_attribute(attr, remove_globals = true)
|
427
|
+
attr = attr.to_sym
|
428
|
+
|
429
|
+
metaclass.send :remove_method, attr
|
430
|
+
|
431
|
+
if (refl = self.class.reflections[attr]) && refl.macro == :belongs_to
|
432
|
+
# A belongs_to -- restore the underlying fields
|
433
|
+
deunknownify_attribute refl.primary_key_name
|
434
|
+
deunknownify_attribute(refl.options[:foreign_type], false) if refl.options[:polymorphic]
|
435
|
+
else
|
436
|
+
# A regular field -- restore the dirty tracking methods
|
437
|
+
# if remove_globals is false, skip the top-level methods, as we have already removed them
|
438
|
+
to_remove = remove_globals ? [:changed?, :changed, :changes] : []
|
439
|
+
(["#{attr}_change", "#{attr}_was", "#{attr}_changed?"] + to_remove).each do |m|
|
440
|
+
metaclass.send :remove_method, m.to_sym
|
441
|
+
end
|
442
|
+
end
|
443
|
+
end
|
444
|
+
|
445
|
+
end
|
446
|
+
end
|
447
|
+
end
|
448
|
+
|