typus 3.0.8 → 3.0.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (102) hide show
  1. data/Gemfile +8 -1
  2. data/README.md +2 -2
  3. data/Rakefile +6 -14
  4. data/app/controllers/admin/base_controller.rb +1 -1
  5. data/app/controllers/admin/dashboard_controller.rb +0 -1
  6. data/app/controllers/admin/resources_controller.rb +8 -11
  7. data/app/controllers/admin/session_controller.rb +5 -4
  8. data/app/helpers/admin/base_helper.rb +9 -2
  9. data/app/helpers/admin/dashboard_helper.rb +0 -6
  10. data/app/helpers/admin/display_helper.rb +1 -0
  11. data/app/helpers/admin/file_preview_helper.rb +0 -2
  12. data/app/helpers/admin/filters_helper.rb +6 -3
  13. data/app/helpers/admin/form_helper.rb +2 -4
  14. data/app/helpers/admin/list_helper.rb +1 -3
  15. data/app/helpers/admin/relationships_helper.rb +2 -4
  16. data/app/helpers/admin/resources_helper.rb +0 -2
  17. data/app/helpers/admin/search_helper.rb +0 -2
  18. data/app/helpers/admin/sidebar_helper.rb +0 -2
  19. data/app/helpers/admin/table_helper.rb +3 -6
  20. data/app/views/admin/account/forgot_password.html.erb +2 -2
  21. data/app/views/admin/account/new.html.erb +3 -7
  22. data/app/views/admin/{helpers/dashboard → dashboard}/_applications.html.erb +0 -0
  23. data/app/views/admin/dashboard/_sidebar.html.erb +1 -1
  24. data/app/views/admin/dashboard/show.html.erb +7 -1
  25. data/app/views/admin/helpers/base/_apps.html.erb +1 -1
  26. data/app/views/admin/helpers/base/_login_info.html.erb +2 -2
  27. data/app/views/admin/helpers/filters/_filters.html.erb +3 -1
  28. data/app/views/admin/resources/_form.html.erb +5 -2
  29. data/app/views/admin/resources/edit.html.erb +1 -1
  30. data/app/views/admin/resources/index.html.erb +1 -1
  31. data/app/views/admin/resources/show.html.erb +2 -2
  32. data/app/views/admin/session/new.html.erb +3 -7
  33. data/app/views/admin/templates/_belongs_to.html.erb +8 -1
  34. data/app/views/admin/templates/_belongs_to_with_autocomplete.html.erb +1 -1
  35. data/app/views/admin/templates/_relate_form.html.erb +1 -1
  36. data/app/views/admin/templates/_relate_form_with_autocomplete.html.erb +3 -1
  37. data/app/views/admin/templates/_string.html.erb +1 -1
  38. data/app/views/admin/templates/_text.html.erb +1 -1
  39. data/app/views/layouts/admin/base.html.erb +2 -0
  40. data/app/views/layouts/admin/headless.html.erb +2 -0
  41. data/app/views/layouts/admin/session.html.erb +6 -0
  42. data/config/routes.rb +4 -1
  43. data/lib/support/active_record.rb +0 -10
  44. data/lib/support/fake_user.rb +4 -6
  45. data/lib/support/object.rb +4 -0
  46. data/lib/support/string.rb +0 -8
  47. data/lib/typus.rb +2 -3
  48. data/lib/typus/authentication/base.rb +0 -1
  49. data/lib/typus/authentication/session.rb +22 -29
  50. data/lib/typus/orm/active_record.rb +5 -5
  51. data/lib/typus/orm/active_record/admin_user_v1.rb +93 -0
  52. data/lib/typus/orm/active_record/admin_user_v2.rb +49 -0
  53. data/lib/typus/orm/active_record/class_methods.rb +23 -143
  54. data/lib/typus/orm/active_record/user/instance_methods.rb +64 -0
  55. data/lib/typus/orm/base.rb +170 -0
  56. data/lib/typus/orm/mongo/class_methods.rb +11 -0
  57. data/lib/typus/resources.rb +2 -1
  58. data/lib/typus/version.rb +1 -1
  59. data/test/app/controllers/admin/account_controller_test.rb +4 -2
  60. data/test/app/controllers/admin/assets_controller_test.rb +12 -12
  61. data/test/app/controllers/admin/categories_controller_test.rb +5 -12
  62. data/test/app/controllers/admin/comments_controller_test.rb +1 -1
  63. data/test/app/controllers/admin/image_holders_controller_test.rb +1 -1
  64. data/test/app/controllers/admin/invoices_controller_test.rb +1 -1
  65. data/test/app/controllers/admin/posts_controller_test.rb +32 -32
  66. data/test/app/controllers/admin/projects_controller_test.rb +1 -1
  67. data/test/app/controllers/admin/typus_users_controller_test.rb +13 -17
  68. data/test/app/controllers/admin/users_controller_test.rb +9 -9
  69. data/test/app/helpers/admin/list_helper_test.rb +17 -0
  70. data/test/app/models/admin_user_test.rb +5 -0
  71. data/test/app/models/typus_user_roles_test.rb +1 -0
  72. data/test/app/models/typus_user_test.rb +45 -11
  73. data/test/factories.rb +1 -1
  74. data/test/fixtures/rails_app/app/controllers/admin/hits_controller.rb +40 -0
  75. data/test/fixtures/rails_app/app/controllers/admin_user.rb +3 -0
  76. data/test/fixtures/rails_app/app/models/asset.rb +0 -6
  77. data/test/fixtures/rails_app/app/models/hit.rb +27 -0
  78. data/test/fixtures/rails_app/app/views/admin/hits/_edit.html.erb +7 -0
  79. data/test/fixtures/rails_app/app/views/admin/hits/_index.html.erb +3 -0
  80. data/test/fixtures/rails_app/app/views/admin/hits/index.html.erb +28 -0
  81. data/test/fixtures/rails_app/config/boot.rb +3 -10
  82. data/test/fixtures/rails_app/config/deploy.rb +1 -1
  83. data/test/fixtures/rails_app/config/mongoid.yml +20 -0
  84. data/test/fixtures/rails_app/config/typus/crud_extended.yml +2 -0
  85. data/test/fixtures/rails_app/config/typus/mongo_db.yml +4 -0
  86. data/test/fixtures/rails_app/config/typus/mongo_db_roles.yml +2 -0
  87. data/test/fixtures/rails_app/db/schema.rb +11 -0
  88. data/test/lib/support/fake_user_test.rb +4 -0
  89. data/test/lib/support/string_test.rb +0 -18
  90. data/test/lib/typus/orm/active_record/class_methods_test.rb +14 -2
  91. data/test/lib/typus/orm/active_record/search_test.rb +1 -1
  92. data/test/lib/typus_test.rb +2 -1
  93. data/typus.gemspec +1 -1
  94. metadata +32 -45
  95. data/lib/typus/orm/active_record/instance_methods.rb +0 -13
  96. data/lib/typus/orm/active_record/user.rb +0 -157
  97. data/test/fixtures/rails_app/public/javascripts/application.js +0 -2
  98. data/test/fixtures/rails_app/public/javascripts/controls.js +0 -965
  99. data/test/fixtures/rails_app/public/javascripts/dragdrop.js +0 -974
  100. data/test/fixtures/rails_app/public/javascripts/effects.js +0 -1123
  101. data/test/fixtures/rails_app/public/javascripts/prototype.js +0 -6001
  102. data/test/fixtures/rails_app/public/javascripts/rails.js +0 -175
@@ -8,18 +8,14 @@
8
8
  <ul>
9
9
 
10
10
  <li>
11
- <%= form.label :email, Typus.user_class.human_attribute_name(:email), :for => 'autofocus' %>
12
- <%= form.text_field :email, :size => 20, :class => "text", :id => 'autofocus', :autofocus => 'autofocus' %>
11
+ <%= form.label :email, Typus.user_class.human_attribute_name(:email) %>
12
+ <%= form.text_field :email, :size => 20, :class => "text", :autofocus => 'autofocus' %>
13
13
  </li>
14
14
 
15
15
  <li>
16
- <%= submit_tag Typus::I18n.t("Sign up"), :class => "button" %>
16
+ <%= submit_tag Typus::I18n.t("Sign up"), :class => "button", :disable_with => Typus::I18n.t("Sending data ...") %>
17
17
  </li>
18
18
 
19
19
  </ul>
20
20
 
21
- <script type="text/javascript">
22
- (function() { document.getElementById('autofocus').focus(); })();
23
- </script>
24
-
25
21
  <% end %>
@@ -4,4 +4,4 @@
4
4
 
5
5
  <p>Replace this sidebar dropping a file named <code>_sidebar.html.erb</code> on the <code>app/views/admin/dashboard</code> folder.</p>
6
6
 
7
- <p>If you need help you can use the provided <%= link_to "user guide", "user_guide" %>.</p>
7
+ <p>If you need help you can use the provided <%= link_to "user guide", admin_user_guide_path %>.</p>
@@ -11,6 +11,12 @@
11
11
  <%= page_title %>
12
12
  </h2>
13
13
 
14
- <%= applications %>
14
+ <% if admin_user.applications.any? %>
15
+ <%= render 'applications' %>
16
+ <% else %>
17
+ <div class="notice">
18
+ No applications detected.
19
+ </div>
20
+ <% end %>
15
21
 
16
22
  <%= resources(admin_user) %>
@@ -12,7 +12,7 @@
12
12
  %>
13
13
 
14
14
  <%
15
- url = { :controller => apps.first.tableize }
15
+ url = { :controller => "/admin/#{apps.first.tableize}" }
16
16
  html_options = { :class => klass }
17
17
  %>
18
18
 
@@ -1,4 +1,4 @@
1
1
  <ul>
2
- <li><%= Typus::I18n.t("Logged as") %> <%= link_to admin_user.name, { :controller => "/admin/#{Typus.user_class.to_resource}", :action => 'edit', :id => admin_user.id } %></li>
3
- <li><%= link_to Typus::I18n.t("Sign out"), admin_session_path, :confirm => Typus::I18n.t("Are you sure you want to sign out and end your session?"), :method => :delete %></li>
2
+ <li><%= Typus::I18n.t("Logged as") %> <%= link_to admin_user.to_label, { :controller => "/admin/#{Typus.user_class.to_resource}", :action => 'edit', :id => admin_user.id } %></li>
3
+ <li><%= link_to Typus::I18n.t("Sign out"), admin_sign_out_path, :confirm => Typus::I18n.t("Are you sure you want to sign out and end your session?") %></li>
4
4
  </ul>
@@ -10,7 +10,9 @@
10
10
  <%= hidden_field_tag key, value %>
11
11
  <% end %>
12
12
 
13
- <li><%= submit_tag Typus::I18n.t("Filter"), :name => nil %></li>
13
+ <li><%= submit_tag Typus::I18n.t("Filter"),
14
+ :name => nil,
15
+ :disable_with => Typus::I18n.t("Sending data ...") %></li>
14
16
  </ul>
15
17
  </div>
16
18
 
@@ -4,13 +4,16 @@
4
4
 
5
5
  <fieldset class="inputs">
6
6
  <ol>
7
- <%= raw build_form(@fields, form) %>
7
+ <%= build_form(fields, form) %>
8
8
  </ol>
9
9
  </fieldset>
10
10
 
11
11
  <fieldset class="buttons">
12
12
  <ol>
13
- <li><%= submit_tag button, :class => "commit", :onclick => "setConfirmUnload(false);" %></li>
13
+ <li><%= submit_tag button,
14
+ :class => "commit",
15
+ :onclick => "setConfirmUnload(false);",
16
+ :disable_with => Typus::I18n.t("Sending data ...") %></li>
14
17
  </ol>
15
18
  </fieldset>
16
19
 
@@ -23,4 +23,4 @@
23
23
 
24
24
  <%= render :partial => 'form', :locals => { :options => options, :button => button } %>
25
25
 
26
- <%= raw typus_relationships %>
26
+ <%= typus_relationships %>
@@ -28,7 +28,7 @@
28
28
  <% end %>
29
29
 
30
30
  <% if @items.any? -%>
31
- <%= raw build_list(@resource, @fields, @items) %>
31
+ <%= build_list(@resource, fields, @items) %>
32
32
  <%= will_paginate(@items, Typus.pagination) %>
33
33
  <% else %>
34
34
  <p><%= Typus::I18n.t("No %{resources} found.", :resources => @resource.model_name.human.downcase.pluralize) %></p>
@@ -14,10 +14,10 @@
14
14
  <%= render 'show' %>
15
15
 
16
16
  <dl>
17
- <% build_display(@item, @fields).each do |attribute, type| %>
17
+ <% build_display(@item, fields).each do |attribute, type| %>
18
18
  <dt><%= attribute %></dt>
19
19
  <dd><%= type %></dd>
20
20
  <% end %>
21
21
  </dl>
22
22
 
23
- <%= raw typus_relationships %>
23
+ <%= typus_relationships %>
@@ -8,8 +8,8 @@
8
8
  <ul>
9
9
 
10
10
  <li>
11
- <%= form.label :email, Typus.user_class.human_attribute_name(:email), :for => 'autofocus' %>
12
- <%= form.text_field :email, :size => 20, :class => "text", :id => 'autofocus', :autofocus => 'autofocus' %>
11
+ <%= form.label :email, Typus.user_class.human_attribute_name(:email) %>
12
+ <%= form.text_field :email, :size => 20, :class => "text", :autofocus => "autofocus" %>
13
13
  </li>
14
14
 
15
15
  <li>
@@ -18,13 +18,9 @@
18
18
  </li>
19
19
 
20
20
  <li>
21
- <%= submit_tag Typus::I18n.t("Sign in"), :class => "button" %> <%= link_to Typus::I18n.t("Recover password"), forgot_password_admin_account_index_path if Typus.mailer_sender %>
21
+ <%= submit_tag Typus::I18n.t("Sign in"), :class => "button", :disable_with => Typus::I18n.t("Sending data ...") %> <%= link_to Typus::I18n.t("Recover password"), forgot_password_admin_account_index_path if Typus.mailer_sender %>
22
22
  </li>
23
23
 
24
24
  </ul>
25
25
 
26
- <script type="text/javascript">
27
- (function() { document.getElementById('autofocus').focus(); })();
28
- </script>
29
-
30
26
  <% end %>
@@ -1,4 +1,11 @@
1
+ <%
2
+ if @resource.typus_field_options_for(:read_only).include?(attribute.to_sym)
3
+ html_options.merge!(:disabled => 'disabled')
4
+ message = Typus::I18n.t("Read only")
5
+ end
6
+ %>
7
+
1
8
  <li id="<%= attribute %>">
2
- <%= form.label related_fk, raw("#{label_text} <small>#{message}</small>") %>
9
+ <%= form.label related_fk, "#{label_text} <small>#{message}</small>".html_safe %>
3
10
  <%= form.select related_fk, values, options, html_options %>
4
11
  </li>
@@ -1,5 +1,5 @@
1
1
  <li id="<%= attribute %>">
2
- <%= form.label related_fk, raw("#{label_text} <small>#{message}</small>") %>
2
+ <%= form.label related_fk, "#{label_text} <small>#{message}</small>".html_safe %>
3
3
  <%= form.hidden_field related_fk %>
4
4
  <input data-autocomplete="<%= "/admin/#{related.to_resource}/autocomplete" %>"
5
5
  id="autocomplete"
@@ -1,5 +1,5 @@
1
1
  <%= form_tag :action => :relate, :id => @item.id do %>
2
2
  <%= hidden_field :related, :model, :value => model_to_relate %>
3
3
  <%= hidden_field :related, :association_name, :value => association_name %>
4
- <p><%= select :related, :id, items_to_relate.map { |f| [f.to_label, f.id] } %> &nbsp; <%= submit_tag Typus::I18n.t("Add"), :class => "button" %></p>
4
+ <p><%= select :related, :id, items_to_relate.map { |f| [f.to_label, f.id] } %> &nbsp; <%= submit_tag Typus::I18n.t("Assign"), :class => "button", :disable_with => Typus::I18n.t("Sending data ...") %></p>
5
5
  <% end %>
@@ -15,7 +15,9 @@
15
15
  size="30"
16
16
  type="text"
17
17
  value="" />
18
- <%= submit_tag Typus::I18n.t("Add"), :class => "button" %>
18
+ <%= submit_tag Typus::I18n.t("Assign"),
19
+ :class => "button",
20
+ :disable_with => Typus::I18n.t("Sending data ...") %>
19
21
  </li>
20
22
  </ol>
21
23
 
@@ -17,6 +17,6 @@
17
17
  %>
18
18
 
19
19
  <li id="<%= attribute %>">
20
- <%= form.label attribute, raw(label_text) %>
20
+ <%= form.label attribute, label_text.html_safe %>
21
21
  <%= form.text_field attribute, options %>
22
22
  </li>
@@ -11,6 +11,6 @@
11
11
  %>
12
12
 
13
13
  <li id="<%= attribute %>">
14
- <%= form.label attribute, raw(label_text) %>
14
+ <%= form.label attribute, label_text.html_safe %>
15
15
  <%= form.text_area attribute, options %>
16
16
  </li>
@@ -8,6 +8,8 @@
8
8
  <meta name="apple-mobile-web-app-capable" content="yes" />
9
9
  <meta name="generator" content="Typus <%= Typus::VERSION %>" />
10
10
 
11
+ <%= favicon_link_tag %>
12
+
11
13
  <title><%= Typus.admin_title %> &mdash; <%= yield :title %></title>
12
14
 
13
15
  <%= stylesheet_link_tag "/vendor/typus/stylesheets/reset",
@@ -8,6 +8,8 @@
8
8
  <meta name="apple-mobile-web-app-capable" content="yes" />
9
9
  <meta name="generator" content="Typus <%= Typus::VERSION %>" />
10
10
 
11
+ <%= favicon_link_tag %>
12
+
11
13
  <title><%= Typus.admin_title %> &mdash; <%= yield :title %></title>
12
14
 
13
15
  <%= stylesheet_link_tag "/vendor/typus/stylesheets/reset",
@@ -8,12 +8,18 @@
8
8
  <meta name="apple-mobile-web-app-capable" content="yes" />
9
9
  <meta name="generator" content="Typus <%= Typus::VERSION %>" />
10
10
 
11
+ <%= favicon_link_tag %>
12
+
11
13
  <title><%= Typus.admin_title %> &mdash; <%= yield :title %></title>
12
14
 
13
15
  <%= stylesheet_link_tag "/vendor/typus/stylesheets/reset",
14
16
  "/vendor/typus/stylesheets/screen",
15
17
  "/vendor/typus/stylesheets/application" %>
16
18
 
19
+ <%= javascript_include_tag "/vendor/jquery-ui-1.8.9.custom/js/jquery-1.4.4.min.js",
20
+ "/vendor/typus/javascripts/jquery.rails.js",
21
+ "/vendor/typus/javascripts/application" %>
22
+
17
23
  <%= csrf_meta_tag %>
18
24
 
19
25
  </head>
@@ -6,7 +6,10 @@ Rails.application.routes.draw do
6
6
  match "user_guide" => "base#user_guide"
7
7
 
8
8
  if Typus.authentication == :session
9
- resource :session, :only => [:new, :create, :destroy], :controller => :session
9
+ resource :session, :only => [:new, :create], :controller => :session do
10
+ get :destroy, :as => "destroy"
11
+ end
12
+
10
13
  resources :account, :only => [:new, :create, :show, :forgot_password] do
11
14
  collection do
12
15
  get :forgot_password
@@ -6,16 +6,6 @@ class ActiveRecord::Base
6
6
  association.macro
7
7
  end
8
8
 
9
- #--
10
- # >> Post.to_resource
11
- # => "posts"
12
- # >> Admin::User.to_resource
13
- # => "admin/users"
14
- #++
15
- def self.to_resource
16
- name.underscore.pluralize
17
- end
18
-
19
9
  #--
20
10
  # On a model:
21
11
  #
@@ -24,12 +24,6 @@ class FakeUser
24
24
  ::I18n.locale
25
25
  end
26
26
 
27
- =begin
28
- def resources
29
- Typus::Configuration.roles[role].compact
30
- end
31
- =end
32
-
33
27
  def applications
34
28
  Typus.applications
35
29
  end
@@ -46,4 +40,8 @@ class FakeUser
46
40
  true
47
41
  end
48
42
 
43
+ def owns?(resource)
44
+ true
45
+ end
46
+
49
47
  end
@@ -1,5 +1,9 @@
1
1
  class Object
2
2
 
3
+ ##
4
+ # TODO: Improve this code, which works, but probably there's a better way
5
+ # to make the verification.
6
+ #
3
7
  # Probably there's a better way to verify if a model responds to an STI
4
8
  # pattern.
5
9
  def self.is_sti?
@@ -16,14 +16,6 @@ class String
16
16
  Typus::Configuration.models_constantized[self]
17
17
  end
18
18
 
19
- def action_mapper
20
- case self
21
- when "index" then :list
22
- when "new", "create", "edit", "update", "toggle" then :form
23
- else self
24
- end
25
- end
26
-
27
19
  def acl_action_mapper
28
20
  case self
29
21
  when "new", "create"
@@ -6,7 +6,7 @@ require "support/object"
6
6
  require "support/string"
7
7
 
8
8
  require "typus/engine"
9
- require "typus/i18n"
9
+ require "typus/orm/base"
10
10
  require "typus/orm/active_record"
11
11
  require "typus/regex"
12
12
  require "typus/version"
@@ -19,16 +19,15 @@ autoload :FakeUser, "support/fake_user"
19
19
  module Typus
20
20
 
21
21
  autoload :Configuration, "typus/configuration"
22
+ autoload :I18n, "typus/i18n"
22
23
  autoload :Resources, "typus/resources"
23
24
 
24
25
  module Controller
25
-
26
26
  autoload :Actions, "typus/controller/actions"
27
27
  autoload :Associations, "typus/controller/associations"
28
28
  autoload :Autocomplete, "typus/controller/autocomplete"
29
29
  autoload :Filters, "typus/controller/filters"
30
30
  autoload :Format, "typus/controller/format"
31
-
32
31
  end
33
32
 
34
33
  module Authentication
@@ -14,7 +14,6 @@ module Typus
14
14
  def check_resources_ownership; end
15
15
  def set_attributes_on_create; end
16
16
  def set_attributes_on_update; end
17
- def reload_locales; end
18
17
 
19
18
  end
20
19
  end
@@ -15,16 +15,21 @@ module Typus
15
15
  end
16
16
  end
17
17
 
18
+ def deauthenticate
19
+ session[:typus_user_id] = nil
20
+ ::I18n.locale = ::I18n.default_locale
21
+ redirect_to new_admin_session_path
22
+ end
23
+
18
24
  #--
19
- # Return the current user. If role does not longer exist on the
20
- # system admin_user will be signed out from Typus.
25
+ # Return the current user. If role does not longer exist on the system
26
+ # admin_user will be signed out from the system.
21
27
  #++
22
28
  def admin_user
23
29
  @admin_user ||= Typus.user_class.find_by_id(session[:typus_user_id])
24
30
 
25
31
  if !@admin_user || !Typus::Configuration.roles.has_key?(@admin_user.role) || !@admin_user.status
26
- session[:typus_user_id] = nil
27
- redirect_to new_admin_session_path
32
+ deauthenticate
28
33
  end
29
34
 
30
35
  @admin_user
@@ -66,9 +71,7 @@ module Typus
66
71
  #++
67
72
  def check_if_user_can_perform_action_on_resource
68
73
  resource = params[:controller].remove_prefix.camelize
69
- unless admin_user.can?(params[:action], resource, { :special => true })
70
- not_allowed
71
- end
74
+ not_allowed if admin_user.cannot?(params[:action], resource, { :special => true })
72
75
  end
73
76
 
74
77
  def not_allowed
@@ -76,18 +79,14 @@ module Typus
76
79
  end
77
80
 
78
81
  #--
79
- # If item is owned by another user, we only can perform a
80
- # show action on the item. Updated item is also blocked.
81
- #
82
- # before_filter :check_resource_ownership, :only => [ :edit, :update, :destroy,
83
- # :toggle, :position,
84
- # :relate, :unrelate ]
82
+ # If item is owned by another user, we only can perform a show action on
83
+ # the item. Updated item is also blocked.
85
84
  #++
86
85
  def check_resource_ownership
87
86
  if admin_user.is_not_root?
88
87
 
89
88
  condition_typus_users = @item.respond_to?(Typus.relationship) && !@item.send(Typus.relationship).include?(admin_user)
90
- condition_typus_user_id = @item.respond_to?(Typus.user_fk) && !@item.owned_by?(admin_user)
89
+ condition_typus_user_id = @item.respond_to?(Typus.user_fk) && !admin_user.owns?(@item)
91
90
 
92
91
  not_allowed if (condition_typus_users || condition_typus_user_id)
93
92
  end
@@ -99,33 +98,27 @@ module Typus
99
98
  #++
100
99
  def check_resources_ownership
101
100
  if admin_user.is_not_root? && @resource.typus_user_id?
102
- condition = { Typus.user_fk => admin_user }
103
- @resource = @resource.where(condition)
101
+ @resource = @resource.where(Typus.user_fk => admin_user)
104
102
  end
105
103
  end
106
104
 
105
+ ##
106
+ # OPTIMIZE: This method should accept args.
107
+ #
107
108
  def set_attributes_on_create
108
- if @resource.typus_user_id?
109
- @item.attributes = { Typus.user_fk => admin_user.id }
110
- end
109
+ @item.send("#{Typus.user_fk}=", admin_user.id) if @resource.typus_user_id?
111
110
  end
112
111
 
112
+ ##
113
+ # OPTIMIZE: This method should accept args and not perform an update
114
+ # because we are updating the attributes twice!
115
+ #
113
116
  def set_attributes_on_update
114
117
  if @resource.typus_user_id? && admin_user.is_not_root?
115
118
  @item.update_attributes(Typus.user_fk => admin_user.id)
116
119
  end
117
120
  end
118
121
 
119
- #--
120
- # Reload admin_user when updating to see flash message in the
121
- # correct locale.
122
- #++
123
- def reload_locales
124
- if @resource.eql?(Typus.user_class)
125
- ::I18n.locale = admin_user.reload.locale
126
- end
127
- end
128
-
129
122
  end
130
123
  end
131
124
  end