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
data/Gemfile CHANGED
@@ -15,7 +15,7 @@ gem 'rack-cache', :require => 'rack/cache'
15
15
  gem 'rails', '~> 3.0'
16
16
 
17
17
  group :test do
18
- gem 'shoulda'
18
+ gem 'shoulda-context'
19
19
  gem 'mocha' # Make sure mocha is loaded at the end ...
20
20
  end
21
21
 
@@ -39,6 +39,13 @@ group :development, :test do
39
39
 
40
40
  end
41
41
 
42
+ # MongoDB support is still in "beta" mode, so I'm not testing it for the moment.
43
+ group :production do
44
+ # MongoDB support
45
+ gem 'mongoid', '2.0.0.rc.7'
46
+ gem 'bson_ext'
47
+ end
48
+
42
49
  group :production do
43
50
 
44
51
  platforms :jruby do
data/README.md CHANGED
@@ -17,8 +17,8 @@ Français, Magyar, Italiano, Portuguese, Russian, 中文)
17
17
  - Customizable and extensible templates.
18
18
  - Integrated [paperclip][1] and [dragonfly][2] attachments viewer.
19
19
  - Low memory footprint.
20
- - Works with `Rails 3.0`.
21
- - Tested with `Ruby 1.8.7-p300` and `Ruby 1.9.2-p136` and `JRuby 1.5.6`.
20
+ - Works with `Rails 3.0.5`.
21
+ - Tested with `ruby-1.8.7-p334`, `ree-1.8.7-2011.03` and `ruby-1.9.2-p180` and `jruby-1.5.6`.
22
22
  - Tested with `SQLite`, `MySQL` and `PostgreSQL`.
23
23
  - MIT License, the same as Rails.
24
24
 
data/Rakefile CHANGED
@@ -15,7 +15,6 @@ Rake::TestTask.new(:test) do |t|
15
15
  t.verbose = true
16
16
  end
17
17
 
18
- =begin
19
18
  desc 'Generate plugin documentation.'
20
19
  Rake::RDocTask.new(:rdoc) do |rdoc|
21
20
  rdoc.rdoc_dir = 'rdoc'
@@ -24,39 +23,32 @@ Rake::RDocTask.new(:rdoc) do |rdoc|
24
23
  rdoc.rdoc_files.include('README.rdoc')
25
24
  rdoc.rdoc_files.include('lib/**/*.rb')
26
25
  end
27
- =end
28
26
 
27
+ desc "Deploy test/fixtures/rails_app"
29
28
  task :deploy do
30
29
  system "cd test/fixtures/rails_app && cap deploy"
31
30
  end
32
31
 
33
- RUBIES = ["ruby-1.8.7-p330", "ruby-1.9.2-p136", "ree-1.8.7-2010.02", "jruby-1.5.6"]
32
+ RUBIES = %w[1.8.7 ree 1.9.2 jruby].join(",")
34
33
 
35
34
  namespace :setup do
36
35
 
37
36
  desc "Setup test environment"
38
37
  task :test_environment do
39
- RUBIES.each { |ruby| system "rvm install #{ruby}" }
38
+ system "rvm install #{RUBIES}"
40
39
  end
41
40
 
42
41
  desc "Setup CI Joe"
43
42
  task :cijoe do
44
- system "git config --replace-all cijoe.runner 'rake test:all'"
43
+ system "git config --replace-all cijoe.runner 'rake test:rubies'"
45
44
  end
46
45
 
47
46
  end
48
47
 
49
48
  namespace :test do
50
49
 
51
- task :all do
52
- RUBIES.each do |ruby|
53
- system "rvm use #{ruby}"
54
- system "rm -f Gemfile.lock"
55
- system "bundle install"
56
- system "rake"
57
- # system "rake DB=postgresql"
58
- # system "rake DB=mysql"
59
- end
50
+ task :rubies do
51
+ system "rvm #{RUBIES} rake"
60
52
  end
61
53
 
62
54
  end
@@ -25,7 +25,7 @@ class Admin::BaseController < ActionController::Base
25
25
  end
26
26
 
27
27
  def set_locale
28
- I18n.locale = admin_user.locale
28
+ I18n.locale = admin_user.locale if admin_user.respond_to?(:locale)
29
29
  end
30
30
 
31
31
  end
@@ -1,7 +1,6 @@
1
1
  class Admin::DashboardController < Admin::BaseController
2
2
 
3
3
  def show
4
- raise "Run `rails generate typus` to create configuration files." if Typus.applications.empty?
5
4
  end
6
5
 
7
6
  end
@@ -6,13 +6,13 @@ class Admin::ResourcesController < Admin::BaseController
6
6
  include Typus::Controller::Filters
7
7
  include Typus::Controller::Format
8
8
 
9
+ Whitelist = [:edit, :update, :destroy, :toggle, :position, :relate, :unrelate]
10
+
9
11
  before_filter :get_model
10
12
  before_filter :set_scope
11
- before_filter :get_object, :only => [:show, :edit, :update, :destroy, :toggle, :position, :relate, :unrelate]
12
- before_filter :check_resource_ownership, :only => [:edit, :update, :destroy, :toggle, :position, :relate, :unrelate ]
13
+ before_filter :get_object, :only => Whitelist + [:show]
14
+ before_filter :check_resource_ownership, :only => Whitelist
13
15
  before_filter :check_if_user_can_perform_action_on_resources
14
- before_filter :set_order, :only => [:index]
15
- before_filter :set_fields, :only => [:index, :new, :edit, :create, :update, :show]
16
16
 
17
17
  ##
18
18
  # This is the main index of the model. With filters, conditions and more.
@@ -89,7 +89,6 @@ class Admin::ResourcesController < Admin::BaseController
89
89
  respond_to do |format|
90
90
  if @item.update_attributes(attributes)
91
91
  set_attributes_on_update
92
- reload_locales
93
92
  format.html { redirect_on_success }
94
93
  format.json { render :json => @item }
95
94
  else
@@ -119,10 +118,7 @@ class Admin::ResourcesController < Admin::BaseController
119
118
  end
120
119
  format.json { render :json => @item }
121
120
  else
122
- format.html do
123
- set_fields
124
- render :edit
125
- end
121
+ format.html { render :edit }
126
122
  format.json { render :json => @item.errors, :status => :unprocessable_entity }
127
123
  end
128
124
  end
@@ -239,9 +235,10 @@ class Admin::ResourcesController < Admin::BaseController
239
235
  @resource = @resource.order(set_order).includes(eager_loading)
240
236
  end
241
237
 
242
- def set_fields
243
- @fields = @resource.typus_fields_for(params[:action].action_mapper)
238
+ def fields
239
+ @resource.typus_fields_for(params[:action])
244
240
  end
241
+ helper_method :fields
245
242
 
246
243
  def set_order
247
244
  params[:sort_order] ||= "desc"
@@ -2,7 +2,6 @@ class Admin::SessionController < Admin::BaseController
2
2
 
3
3
  skip_before_filter :reload_config_and_roles
4
4
  skip_before_filter :authenticate
5
- skip_before_filter :set_locale
6
5
 
7
6
  before_filter :create_an_account?, :only => [:new, :create]
8
7
 
@@ -23,9 +22,7 @@ class Admin::SessionController < Admin::BaseController
23
22
  end
24
23
 
25
24
  def destroy
26
- session[:typus_user_id] = nil
27
- I18n.locale = I18n.default_locale
28
- redirect_to :action => :new
25
+ deauthenticate
29
26
  end
30
27
 
31
28
  private
@@ -34,4 +31,8 @@ class Admin::SessionController < Admin::BaseController
34
31
  redirect_to new_admin_account_path if Typus.user_class.count.zero?
35
32
  end
36
33
 
34
+ def set_locale
35
+ I18n.locale = I18n.default_locale
36
+ end
37
+
37
38
  end
@@ -1,5 +1,4 @@
1
1
  module Admin
2
-
3
2
  module BaseHelper
4
3
 
5
4
  def title(page_title)
@@ -24,6 +23,15 @@ module Admin
24
23
  end
25
24
  end
26
25
 
26
+ def admin_sign_out_path
27
+ case Typus.authentication
28
+ when :devise
29
+ send("destroy_#{Typus.user_class_name.underscore}_session")
30
+ else
31
+ destroy_admin_session_path
32
+ end
33
+ end
34
+
27
35
  def display_flash_message(message = flash)
28
36
  if message.compact.any?
29
37
  render "admin/helpers/base/flash_message",
@@ -33,5 +41,4 @@ module Admin
33
41
  end
34
42
 
35
43
  end
36
-
37
44
  end
@@ -1,16 +1,10 @@
1
1
  module Admin
2
-
3
2
  module DashboardHelper
4
3
 
5
- def applications
6
- render "admin/helpers/dashboard/applications"
7
- end
8
-
9
4
  def resources(admin_user)
10
5
  available = Typus.resources.delete_if { |r| !(admin_user.is_a?(FakeUser) || admin_user.resources.include?(r)) }
11
6
  render "admin/helpers/dashboard/resources", :resources => available
12
7
  end
13
8
 
14
9
  end
15
-
16
10
  end
@@ -45,6 +45,7 @@ module Admin
45
45
  alias_method :display_text, :display_string
46
46
  alias_method :display_position, :display_string
47
47
  alias_method :display_integer, :display_string
48
+ alias_method :display_decimal, :display_string
48
49
 
49
50
  end
50
51
  end
@@ -1,5 +1,4 @@
1
1
  module Admin
2
-
3
2
  module FilePreviewHelper
4
3
 
5
4
  def get_type_of_attachment(attachment)
@@ -64,5 +63,4 @@ module Admin
64
63
  end
65
64
 
66
65
  end
67
-
68
66
  end
@@ -1,5 +1,4 @@
1
1
  module Admin
2
-
3
2
  module FiltersHelper
4
3
 
5
4
  def build_filters(resource = @resource, params = params)
@@ -80,7 +79,12 @@ module Admin
80
79
  end
81
80
 
82
81
  def string_filter(filter)
83
- values = @resource::const_get(filter.to_s.upcase).to_a
82
+ values = if @resource.const_defined?(filter.to_s.upcase)
83
+ @resource::const_get(filter.to_s.upcase).to_a
84
+ else
85
+ @resource.send(filter.to_s).to_a
86
+ end
87
+
84
88
  items = [[Typus::I18n.t("Show by %{attribute}", :attribute => @resource.human_attribute_name(filter).downcase), ""]]
85
89
  array = values.first.is_a?(Array) ? values : values.map { |i| [i, i] }
86
90
  items += array
@@ -91,5 +95,4 @@ module Admin
91
95
  end
92
96
 
93
97
  end
94
-
95
98
  end
@@ -1,5 +1,4 @@
1
1
  module Admin
2
-
3
2
  module FormHelper
4
3
 
5
4
  def build_form(fields, form)
@@ -19,7 +18,7 @@ module Admin
19
18
  typus_template_field(key, :string, form)
20
19
  end
21
20
  end
22
- end
21
+ end.html_safe
23
22
  end
24
23
 
25
24
  def typus_tree_field(attribute, form)
@@ -38,7 +37,7 @@ module Admin
38
37
  next if admin_user.cannot?('read', association.class_name.typus_constantize)
39
38
  html << send("typus_form_#{association.macro}", relationship)
40
39
  end
41
- end
40
+ end.html_safe
42
41
  end
43
42
 
44
43
  def typus_template_field(attribute, template, form)
@@ -74,5 +73,4 @@ module Admin
74
73
  end
75
74
 
76
75
  end
77
-
78
76
  end
@@ -1,5 +1,4 @@
1
1
  module Admin
2
-
3
2
  module ListHelper
4
3
 
5
4
  def resources_actions
@@ -12,7 +11,7 @@ module Admin
12
11
  path = params.dup.merge!(url).compact.cleanup
13
12
  link_to Typus::I18n.t(body), path, options
14
13
  end
15
- end.join(" / ").html_safe
14
+ end.compact.join(" / ").html_safe
16
15
  end
17
16
 
18
17
  #--
@@ -27,5 +26,4 @@ module Admin
27
26
  end
28
27
 
29
28
  end
30
-
31
29
  end
@@ -1,5 +1,4 @@
1
1
  module Admin
2
-
3
2
  module RelationshipsHelper
4
3
 
5
4
  def setup_relationship(field)
@@ -107,7 +106,7 @@ module Admin
107
106
 
108
107
  def set_condition
109
108
  if @resource.typus_user_id? && admin_user.is_not_root?
110
- @item.owned_by?(admin_user)
109
+ admin_user.owns?(@item)
111
110
  else
112
111
  true
113
112
  end
@@ -152,7 +151,7 @@ module Admin
152
151
  # Pass the resource_id only to edit/update because only there is where
153
152
  # the record actually exists.
154
153
  options.merge!(:resource_id => @item.id) if %w(edit update).include?(params[:action])
155
- message = link_to Typus::I18n.t("Add"), options
154
+ message = link_to Typus::I18n.t("Add new"), options
156
155
  end
157
156
 
158
157
  # Set the template.
@@ -183,5 +182,4 @@ module Admin
183
182
  end
184
183
 
185
184
  end
186
-
187
185
  end
@@ -1,5 +1,4 @@
1
1
  module Admin
2
-
3
2
  module ResourcesHelper
4
3
 
5
4
  include Admin::DisplayHelper
@@ -34,5 +33,4 @@ module Admin
34
33
  end
35
34
 
36
35
  end
37
-
38
36
  end
@@ -1,5 +1,4 @@
1
1
  module Admin
2
-
3
2
  module SearchHelper
4
3
 
5
4
  def search(resource = @resource, params = params)
@@ -14,5 +13,4 @@ module Admin
14
13
  end
15
14
 
16
15
  end
17
-
18
16
  end
@@ -1,5 +1,4 @@
1
1
  module Admin
2
-
3
2
  module SidebarHelper
4
3
 
5
4
  def build_sidebar
@@ -41,5 +40,4 @@ module Admin
41
40
  end
42
41
 
43
42
  end
44
-
45
43
  end
@@ -1,5 +1,4 @@
1
1
  module Admin
2
-
3
2
  module TableHelper
4
3
 
5
4
  def build_table(model, fields, items, link_options = {}, association = nil, association_name = nil)
@@ -15,7 +14,7 @@ module Admin
15
14
  def table_header(model, fields, params = params)
16
15
  fields.map do |key, value|
17
16
 
18
- key = key.gsub(".", " ") if key.match(/\./)
17
+ key = key.gsub(".", " ") if key.to_s.match(/\./)
19
18
  content = model.human_attribute_name(key)
20
19
 
21
20
  if params[:action].eql?('index') && model.typus_options_for(:sortable)
@@ -80,12 +79,10 @@ module Admin
80
79
 
81
80
  alias :table_has_many_field :table_has_and_belongs_to_many_field
82
81
 
83
- def table_string_field(attribute, item)
82
+ def table_text_field(attribute, item)
84
83
  (raw_content = item.send(attribute)).present? ? truncate(raw_content) : "&mdash;".html_safe
85
84
  end
86
85
 
87
- alias :table_text_field :table_string_field
88
-
89
86
  def table_generic_field(attribute, item)
90
87
  (raw_content = item.send(attribute)).present? ? raw_content : "&mdash;".html_safe
91
88
  end
@@ -94,6 +91,7 @@ module Admin
94
91
  alias :table_integer_field :table_generic_field
95
92
  alias :table_decimal_field :table_generic_field
96
93
  alias :table_virtual_field :table_generic_field
94
+ alias :table_string_field :table_generic_field
97
95
 
98
96
  def table_selector_field(attribute, item)
99
97
  item.mapping(attribute)
@@ -159,5 +157,4 @@ module Admin
159
157
  end
160
158
 
161
159
  end
162
-
163
160
  end
@@ -9,11 +9,11 @@
9
9
 
10
10
  <li>
11
11
  <%= form.label :email, Typus.user_class.human_attribute_name(:email) %>
12
- <%= form.text_field :email, :size => 20, :class => "text" %>
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("Submit"), :class => "button" %> <%= link_to Typus::I18n.t("I remember my password"), new_admin_session_path %>
16
+ <%= submit_tag Typus::I18n.t("Submit"), :class => "button", :disable_with => Typus::I18n.t("Sending data ...") %> <%= link_to Typus::I18n.t("I remember my password"), new_admin_session_path %>
17
17
  </li>
18
18
 
19
19
  </ul>