admin_data 1.0.2 → 1.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. data/History.txt +10 -0
  2. data/app/controllers/admin_data/base_controller.rb +9 -16
  3. data/app/controllers/admin_data/feed_controller.rb +1 -1
  4. data/app/controllers/admin_data/main_controller.rb +4 -8
  5. data/app/controllers/admin_data/search_controller.rb +1 -1
  6. data/app/views/admin_data/main/new.html.erb +3 -1
  7. data/app/views/admin_data/search/search/_errors.html.erb +3 -3
  8. data/app/views/admin_data/search/search/_listing.html.erb +0 -1
  9. data/lib/admin_data/chelper.rb +2 -2
  10. data/lib/admin_data/railtie.rb +2 -3
  11. data/lib/admin_data/settings.rb +2 -2
  12. data/lib/admin_data/version.rb +1 -1
  13. data/lib/admin_data.rb +2 -0
  14. data/test/functional/main_controller_authorization_test.rb +96 -0
  15. data/test/functional/main_controller_test.rb +0 -2
  16. data/test/rails_root/db/test.sqlite3 +0 -0
  17. data/test/rails_root/log/test.log +2289 -0
  18. metadata +7 -25
  19. data/app/controllers/admin_data/diagnostic_controller.rb +0 -28
  20. data/app/controllers/admin_data/validate_model_controller.rb +0 -106
  21. data/app/views/admin_data/diagnostic/index.html.erb +0 -17
  22. data/app/views/admin_data/diagnostic/missing_index.html.erb +0 -26
  23. data/app/views/admin_data/validate_model/_bad.html.erb +0 -1
  24. data/app/views/admin_data/validate_model/tid.html.erb +0 -2
  25. data/app/views/admin_data/validate_model/validate.html.erb +0 -67
  26. data/lib/css/vendor/images/ui-bg_diagonals-thick_75_f3d8d8_40x40.png +0 -0
  27. data/lib/css/vendor/images/ui-bg_dots-small_65_a6a6a6_2x2.png +0 -0
  28. data/lib/css/vendor/images/ui-bg_flat_0_333333_40x100.png +0 -0
  29. data/lib/css/vendor/images/ui-bg_flat_65_ffffff_40x100.png +0 -0
  30. data/lib/css/vendor/images/ui-bg_flat_75_ffffff_40x100.png +0 -0
  31. data/lib/css/vendor/images/ui-bg_glass_55_fbf8ee_1x400.png +0 -0
  32. data/lib/css/vendor/images/ui-bg_highlight-hard_100_eeeeee_1x100.png +0 -0
  33. data/lib/css/vendor/images/ui-bg_highlight-hard_100_f6f6f6_1x100.png +0 -0
  34. data/lib/css/vendor/images/ui-bg_highlight-soft_15_cc0000_1x100.png +0 -0
  35. data/lib/css/vendor/images/ui-icons_004276_256x240.png +0 -0
  36. data/lib/css/vendor/images/ui-icons_cc0000_256x240.png +0 -0
  37. data/lib/css/vendor/images/ui-icons_ffffff_256x240.png +0 -0
  38. data/lib/css/vendor/qunit.css +0 -119
  39. data/lib/tasks/admin_data_tasks.rake +0 -7
  40. data/lib/tasks/validate_models_bg.rake +0 -23
data/History.txt CHANGED
@@ -1,3 +1,13 @@
1
+ === 2010-08-17 v1.0.3
2
+ * added more tests
3
+ * fixed a bug related to :is_allowed_to_view_klass
4
+
5
+
6
+ === 2010-08-16
7
+ * released as a gem
8
+ * version 1.0.2
9
+ * only works with rails3
10
+
1
11
  === 2010-04-14
2
12
 
3
13
  * JavaScript code refactoring
@@ -8,10 +8,9 @@ class AdminData::BaseController < ApplicationController
8
8
 
9
9
  include AdminData::Chelper
10
10
 
11
- before_filter :rails3_hack, :build_klasses, :build_drop_down_for_klasses, :check_page_parameter, :prepare_drop_down_klasses
11
+ before_filter :build_klasses, :build_drop_down_for_klasses, :check_page_parameter, :prepare_drop_down_klasses
12
12
 
13
- attr_reader :klass
14
- attr_reader :model
13
+ attr_reader :klass, :model
15
14
 
16
15
  private
17
16
 
@@ -24,8 +23,8 @@ class AdminData::BaseController < ApplicationController
24
23
  render :text => '<h2>not authorized</h2>', :status => :unauthorized unless admin_data_is_allowed_to_view?
25
24
  end
26
25
 
27
- def ensure_is_allowed_to_view_model
28
- render :text => 'not authorized', :status => :unauthorized unless admin_data_is_allowed_to_view_model?
26
+ def ensure_is_allowed_to_view_klass
27
+ render :text => 'not authorized', :status => :unauthorized unless admin_data_is_allowed_to_view_klass?
29
28
  end
30
29
 
31
30
  def ensure_is_allowed_to_update
@@ -58,20 +57,18 @@ class AdminData::BaseController < ApplicationController
58
57
  model_names = Dir.chdir(model_dir) { Dir["**/*.rb"] }
59
58
  klasses = get_klass_names(model_names)
60
59
  filtered_klasses = remove_klasses_without_table(klasses).sort_by {|r| r.name.underscore}
61
- klasses_with_security_clearance = filtered_klasses.select do |klass_local|
60
+ klasses_with_security_clearance = filtered_klasses.compact.select do |klass_local|
62
61
  @klass = klass_local
63
- admin_data_is_allowed_to_view_model?
62
+ admin_data_is_allowed_to_view_klass?
64
63
  end
65
64
  #TODO remove global constant. it is not thread safe
66
65
  $admin_data_klasses = klasses_with_security_clearance
67
- puts $admin_data_klasses.inspect
68
66
  end
69
67
  @klasses = $admin_data_klasses
70
68
  end
71
69
 
72
70
  def remove_klasses_without_table(klasses)
73
- klasses.select { |k| k.ancestors.include?(ActiveRecord::Base) &&
74
- k.connection.table_exists?(k.table_name) }
71
+ klasses.select { |k| k.ancestors.include?(ActiveRecord::Base) && k.connection.table_exists?(k.table_name) }
75
72
  end
76
73
 
77
74
  def get_klass_names(model_names)
@@ -98,7 +95,8 @@ class AdminData::BaseController < ApplicationController
98
95
  end
99
96
 
100
97
  def check_page_parameter
101
- # Got hoptoad error because of url like http://localhost:3000/admin_data/User/advance_search?page=http://201.134.249.164/intranet/on.txt?
98
+ # Got hoptoad error because of url like
99
+ # http://localhost:3000/admin_data/User/advance_search?page=http://201.134.249.164/intranet/on.txt?
102
100
  if params[:page].blank? || (params[:page] =~ /\A\d+\z/)
103
101
  # proceed
104
102
  else
@@ -106,9 +104,4 @@ class AdminData::BaseController < ApplicationController
106
104
  end
107
105
  end
108
106
 
109
- def rails3_hack
110
- #require_dependency File.join(Rails.root, 'vendor', 'plugins', 'admin_data', 'lib', 'admin_data', 'settings.rb')
111
- #AdminData::Config.initialize_defaults
112
- end
113
-
114
107
  end
@@ -5,7 +5,7 @@ class AdminData::FeedController < AdminData::BaseController
5
5
  before_filter :ensure_is_allowed_to_view_feed
6
6
 
7
7
  def index
8
- render :text => "usage: http://localhost:3000/admin_data/feed/user" and return if params[:klasss].blank?
8
+ render :text => "Usage: http://localhost:3000/admin_data/feed/<model name>" and return if params[:klasss].blank?
9
9
 
10
10
  begin
11
11
  @klass = AdminData::Util.camelize_constantize(params[:klasss])
@@ -8,7 +8,7 @@ class AdminData::MainController < AdminData::BaseController
8
8
 
9
9
  before_filter :get_model_and_verify_it, :only => [:destroy, :del, :edit, :update, :show]
10
10
 
11
- before_filter :ensure_is_allowed_to_view_model, :except => [:all_models, :index]
11
+ before_filter :ensure_is_allowed_to_view_klass, :except => [:all_models, :index]
12
12
 
13
13
  before_filter :ensure_is_allowed_to_update, :only => [:destroy, :del, :edit, :update, :create]
14
14
 
@@ -110,13 +110,9 @@ class AdminData::MainController < AdminData::BaseController
110
110
  conditional_id = params[:id] =~ /^(\d+)-.*/ ? params[:id].to_i : params[:id]
111
111
  condition = {primary_key => conditional_id}
112
112
 
113
- # http://neerajdotname.github.com/admin_data/#override_find_condition
114
- find_conditions_proc = AdminData::Config.setting[:find_conditions] ? AdminData::Config.setting[:find_conditions][@klass.name] : nil
115
- if find_conditions_proc && find_conditions = find_conditions_proc.call(params)
116
-
117
- if find_conditions.has_key?(:conditions)
118
- condition = find_conditions.fetch(:conditions)
119
- end
113
+ _proc = AdminData::Config.setting[:find_conditions] ? AdminData::Config.setting[:find_conditions][@klass.name] : nil
114
+ if _proc && find_conditions = _proc.call(params)
115
+ condition = find_conditions.fetch(:conditions) if find_conditions.has_key?(:conditions)
120
116
  end
121
117
 
122
118
  @model = @klass.send('find', :first, :conditions => condition)
@@ -8,7 +8,7 @@ class AdminData::SearchController < AdminData::BaseController
8
8
 
9
9
  before_filter :get_class_from_params
10
10
  before_filter :ensure_is_allowed_to_view
11
- before_filter :ensure_is_allowed_to_view_model
11
+ before_filter :ensure_is_allowed_to_view_klass
12
12
  before_filter :ensure_valid_children_klass, :only => [:quick_search]
13
13
  before_filter :ensure_is_authorized_for_update_opration, :only => [:advance_search]
14
14
  before_filter :set_collection_of_columns, :only => [:advance_search]
@@ -13,7 +13,9 @@
13
13
  <div class="content rounded">
14
14
  <div class="inner umbrella">
15
15
  <h1>Create a new record</h1>
16
- <%= form_for @model, :as => @klass.name.underscore.to_sym, :url => admin_data_on_k_index_path(:klass => @klass.name), :html => {:class => 'form', :method => :post} do |f| %>
16
+ <%= form_for @model, :as => @klass.name.underscore.to_sym,
17
+ :url => admin_data_on_k_index_path(:klass => @klass.name),
18
+ :html => {:class => 'form', :method => :post} do |f| %>
17
19
  <%= render 'admin_data/shared/flash_message', :model => @model %>
18
20
  <%= render 'admin_data/main/misc/form', :klass => @klass, :f => f %>
19
21
  <% end %>
@@ -1,5 +1,5 @@
1
1
  <div>
2
- <% errors.each do |error| %>
3
- <p class='error'><%= error %></p>
4
- <% end %>
2
+ <% errors.each do |error| %>
3
+ <p class='error'><%= error %></p>
4
+ <% end %>
5
5
  </div>
@@ -37,4 +37,3 @@
37
37
  </div>
38
38
 
39
39
  <div class='clear'></div>
40
-
@@ -9,9 +9,9 @@ module AdminData::Chelper
9
9
  AdminData::Config.setting[:is_allowed_to_view].call(self)
10
10
  end
11
11
 
12
- def admin_data_is_allowed_to_view_model?
12
+ def admin_data_is_allowed_to_view_klass?
13
13
  return true if Rails.env.development?
14
- AdminData::Config.setting[:is_allowed_to_view_model].call(self)
14
+ AdminData::Config.setting[:is_allowed_to_view_klass].call(self)
15
15
  end
16
16
 
17
17
  def admin_data_is_allowed_to_update?
@@ -14,8 +14,7 @@ module AdminData
14
14
  end
15
15
 
16
16
  rake_tasks do
17
- load 'tasks/admin_data_tasks.rake'
18
- load 'tasks/validate_models_bg.rake'
17
+ #
19
18
  end
20
19
  end
21
- end
20
+ end
@@ -12,7 +12,7 @@ class AdminData::Config
12
12
  is_allowed_to_view_feed
13
13
  feed_authentication_user_id
14
14
  feed_authentication_password
15
- is_allowed_to_view_model
15
+ is_allowed_to_view_klass
16
16
  is_allowed_to_update
17
17
  is_allowed_to_update_model
18
18
  column_settings
@@ -49,7 +49,7 @@ class AdminData::Config
49
49
 
50
50
  :is_allowed_to_update => lambda {|controller| return true if Rails.env.development? },
51
51
 
52
- :is_allowed_to_view_model => lambda {|controller| return true },
52
+ :is_allowed_to_view_klass => lambda {|controller| return true },
53
53
 
54
54
  :is_allowed_to_update_model => lambda {|controller| return true },
55
55
 
@@ -1,3 +1,3 @@
1
1
  module AdminData
2
- VERSION = '1.0.2'
2
+ VERSION = '1.0.3'
3
3
  end
data/lib/admin_data.rb CHANGED
@@ -23,7 +23,9 @@ else
23
23
  raise "Please see documentation at http://neerajdotname.github.com/admin_data to find out how to use this plugin with rails 2.3"
24
24
  end
25
25
 
26
+ # move date_validation to inside admin_data
26
27
  require 'admin_data_date_validation'
28
+
27
29
  require 'admin_data/helpers'
28
30
  require 'admin_data/chelper'
29
31
  require 'admin_data/compatibility'
@@ -0,0 +1,96 @@
1
+ require 'test_helper'
2
+
3
+ pwd = File.dirname(__FILE__)
4
+ f = File.join(pwd, '..', '..', 'app', 'views')
5
+ AdminData::MainController.prepend_view_path(f)
6
+
7
+ class AdminData::MainControllerAuthorizationTest < ActionController::TestCase
8
+
9
+ def setup
10
+ @controller = AdminData::MainController.new
11
+ @request = ActionController::TestRequest.new
12
+ @response = ActionController::TestResponse.new
13
+ @article = Factory(:article)
14
+ @car = Factory(:car, :year => 2000, :brand => 'bmw')
15
+ grant_read_only_access
16
+ grant_update_access
17
+ end
18
+
19
+ context 'is not allowed to view' do
20
+ setup do
21
+ revoke_read_only_access
22
+ get :table_structure, {:klass => Article.name.underscore}
23
+ end
24
+ should_respond_with(401)
25
+ should 'have text index' do
26
+ assert_tag(:content => 'not authorized')
27
+ end
28
+ end
29
+
30
+ context 'is allowed to view klass' do
31
+ context 'negative case' do
32
+ setup do
33
+ AdminData::Config.set = {
34
+ :is_allowed_to_view_klass => lambda {|controller| controller.instance_variable_get('@klass').name != 'Article' }
35
+ }
36
+ get :show, {:id => @article.id, :klass => Article.name.underscore }
37
+ end
38
+ should_respond_with(401)
39
+ should 'have text index' do
40
+ assert_tag(:content => 'not authorized')
41
+ end
42
+ end
43
+ context 'positive case' do
44
+ setup do
45
+ AdminData::Config.set = {
46
+ :is_allowed_to_view_klass => lambda {|controller| controller.instance_variable_get('@klass').name == 'Article' }
47
+ }
48
+ get :show, {:id => @article.id, :klass => Article.name.underscore }
49
+ end
50
+ should_respond_with :success
51
+ end
52
+ end
53
+
54
+ context 'is allowed to update' do
55
+ context 'for edit' do
56
+ setup do
57
+ AdminData::Config.set = { :is_allowed_to_update => lambda {|controller| false } }
58
+ get :edit, {:id => @article.id, :klass => @article.class.name, :attr => 'title', :data => 'Hello World' }
59
+ end
60
+ should_respond_with(401)
61
+ end
62
+
63
+ context 'for destroy' do
64
+ setup do
65
+ AdminData::Config.set = { :is_allowed_to_update => lambda {|controller| false } }
66
+ delete :destroy, {:id => @article.id, :klass => @article.class.name.underscore}
67
+ end
68
+ should_respond_with(401)
69
+ end
70
+
71
+ context 'for delete' do
72
+ setup do
73
+ AdminData::Config.set = { :is_allowed_to_update => lambda {|controller| false } }
74
+ delete :del, {:id => @article.id, :klass => @article.class.name.underscore }
75
+ end
76
+ should_respond_with(401)
77
+ end
78
+
79
+ context 'for update' do
80
+ setup do
81
+ AdminData::Config.set = { :is_allowed_to_update => lambda {|controller| false } }
82
+ post :update, { :klass => Article.name.underscore, :id => @article, :article => {:title => 'new title'}}
83
+ end
84
+ should_respond_with(401)
85
+ end
86
+
87
+ context 'for create' do
88
+ setup do
89
+ AdminData::Config.set = { :is_allowed_to_update => lambda {|controller| false } }
90
+ post :create, { :klass => Article.name.underscore, 'article' => {:title => 'hello', :body => 'hello world'}}
91
+ end
92
+ should_respond_with(401)
93
+ end
94
+ end
95
+
96
+ end
@@ -16,8 +16,6 @@ class AdminData::MainControllerTest < ActionController::TestCase
16
16
  grant_update_access
17
17
  end
18
18
 
19
- #TODO write tests for all before filters
20
-
21
19
  context 'get table_structure' do
22
20
  setup do
23
21
  get :table_structure, {:klass => Article.name.underscore}
Binary file