admin_data 1.0.8 → 1.0.9

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -5,7 +5,7 @@ require 'rake/rdoctask'
5
5
  desc 'Default: run unit tests.'
6
6
  task :default => :test
7
7
 
8
- desc 'Test admin_data plugin.'
8
+ desc 'Test admin_data gem.'
9
9
  Rake::TestTask.new(:test) do |t|
10
10
  t.libs << 'lib' << 'test'
11
11
  t.pattern = 'test/**/*_test.rb'
@@ -31,8 +31,8 @@ class AdminData::BaseController < ApplicationController
31
31
  render :text => 'not authorized', :status => :unauthorized unless admin_data_is_allowed_to_update?
32
32
  end
33
33
 
34
- def ensure_is_allowed_to_update_model
35
- render :text => 'not authorized', :status => :unauthorized unless admin_data_is_allowed_to_update_model?
34
+ def ensure_is_allowed_to_update_klass
35
+ render :text => 'not authorized', :status => :unauthorized unless admin_data_is_allowed_to_update_klass?
36
36
  end
37
37
 
38
38
 
@@ -49,19 +49,32 @@ class AdminData::BaseController < ApplicationController
49
49
  end
50
50
 
51
51
  def build_klasses
52
- unless defined? $admin_data_klasses
52
+ # if is_allowed_to_view_klass option is passed then golbal constant can't be used since
53
+ # list of klasses need to be built for each user. It will slow down the speed a bit since
54
+ # every single the list needs to be built
55
+ if AdminData::Config.setting[:is_allowed_to_view_klass]
56
+ @klasses = _build_custom_klasses
57
+ else
58
+ @klasses = _build_all_klasses
59
+ end
60
+ end
61
+
62
+ def _build_all_klasses
63
+ if defined? $admin_data_all_klasses
64
+ return $admin_data_all_klasses
65
+ else
53
66
  model_dir = File.join(Rails.root, 'app', 'models')
54
67
  model_names = Dir.chdir(model_dir) { Dir["**/*.rb"] }
55
68
  klasses = get_klass_names(model_names)
56
- filtered_klasses = remove_klasses_without_table(klasses).sort_by {|r| r.name.underscore}
57
- klasses_with_security_clearance = filtered_klasses.compact.select do |klass_local|
58
- @klass = klass_local
59
- admin_data_is_allowed_to_view_klass?
60
- end
61
- #TODO remove global constant. it is not thread safe
62
- $admin_data_klasses = klasses_with_security_clearance
69
+ $admin_data_all_klasses = remove_klasses_without_table(klasses).sort_by {|r| r.name.underscore}
70
+ end
71
+ end
72
+
73
+ def _build_custom_klasses
74
+ _build_all_klasses.compact.select do |klass_local|
75
+ @klass = klass_local
76
+ admin_data_is_allowed_to_view_klass?
63
77
  end
64
- @klasses = $admin_data_klasses
65
78
  end
66
79
 
67
80
  def remove_klasses_without_table(klasses)
@@ -92,7 +105,7 @@ class AdminData::BaseController < ApplicationController
92
105
  end
93
106
 
94
107
  def check_page_parameter
95
- # Got hoptoad error because of url like
108
+ # Got hoptoad error because of url like
96
109
  # http://localhost:3000/admin_data/User/advance_search?page=http://201.134.249.164/intranet/on.txt?
97
110
  if params[:page].blank? || (params[:page] =~ /\A\d+\z/)
98
111
  # proceed
@@ -12,7 +12,7 @@ class AdminData::MainController < AdminData::BaseController
12
12
 
13
13
  before_filter :ensure_is_allowed_to_update, :only => [:destroy, :del, :edit, :update, :create]
14
14
 
15
- before_filter :ensure_is_allowed_to_update_model, :only => [:destroy, :del, :edit, :update, :create]
15
+ before_filter :ensure_is_allowed_to_update_klass, :only => [:destroy, :del, :edit, :update, :create]
16
16
 
17
17
 
18
18
  def table_structure
@@ -10,7 +10,7 @@ module AdminData::Chelper
10
10
  end
11
11
 
12
12
  def admin_data_is_allowed_to_view_klass?
13
- return true if Rails.env.development?
13
+ return true if Rails.env.development? || AdminData::Config.setting[:is_allowed_to_view_klass].blank?
14
14
  AdminData::Config.setting[:is_allowed_to_view_klass].call(self)
15
15
  end
16
16
 
@@ -19,9 +19,9 @@ module AdminData::Chelper
19
19
  AdminData::Config.setting[:is_allowed_to_update].call(self)
20
20
  end
21
21
 
22
- def admin_data_is_allowed_to_update_model?
22
+ def admin_data_is_allowed_to_update_klass?
23
23
  return true if Rails.env.development?
24
- AdminData::Config.setting[:is_allowed_to_update_model].call(self)
24
+ AdminData::Config.setting[:is_allowed_to_update_klass].call(self)
25
25
  end
26
26
 
27
27
  def admin_data_invalid_record_link(klassu, id, error)
@@ -9,17 +9,18 @@ class AdminData::Config
9
9
  find_conditions
10
10
  plugin_dir
11
11
  will_paginate_per_page
12
+
12
13
  is_allowed_to_view
14
+ is_allowed_to_view_klass
15
+ is_allowed_to_update
16
+ is_allowed_to_update_klass
17
+
13
18
  is_allowed_to_view_feed
14
19
  feed_authentication_user_id
15
20
  feed_authentication_password
16
- is_allowed_to_view_klass
17
- is_allowed_to_update
18
- is_allowed_to_update_model
19
21
  column_settings
20
22
  columns_order
21
23
  use_google_hosting_for_jquery
22
- rake_options
23
24
  drop_down_for_associations
24
25
  ignore_column_limit
25
26
  ).collect(&:intern)
@@ -30,13 +31,6 @@ class AdminData::Config
30
31
  self.setting ||= {}
31
32
  self.setting.merge!(input)
32
33
 
33
- unless self.setting[:rake_options].blank?
34
- env = self.setting[:rake_options][:env]
35
- if env.blank? || env.include?(Rails.env.intern)
36
- self.setting[:rake_command] = self.setting[:rake_options][:command]
37
- end
38
- end
39
-
40
34
  end
41
35
 
42
36
  def self.initialize_defaults
@@ -50,9 +44,9 @@ class AdminData::Config
50
44
 
51
45
  :is_allowed_to_update => lambda {|controller| return true if Rails.env.development? },
52
46
 
53
- :is_allowed_to_view_klass => lambda {|controller| return true },
47
+ :is_allowed_to_view_klass => nil,
54
48
 
55
- :is_allowed_to_update_model => lambda {|controller| return true },
49
+ :is_allowed_to_update_klass => lambda {|controller| return true },
56
50
 
57
51
  :find_conditions => nil,
58
52
 
@@ -1,3 +1,3 @@
1
1
  module AdminData
2
- VERSION = '1.0.8'
2
+ VERSION = '1.0.9'
3
3
  end
data/lib/admin_data.rb CHANGED
@@ -3,12 +3,7 @@ begin
3
3
  rescue LoadError => e
4
4
  $stderr.puts %(
5
5
  *************************************************************************************************
6
- * *
7
6
  * gem will_paginate is missing *
8
- * plugin admin_data depends on will_paginate *
9
- * Please install will_paginate by adding following line to Gemfile *
10
- * gem 'will_paginate', :git => 'git://github.com/mislav/will_paginate.git', :branch => 'rails3' *
11
- * *
12
7
  *************************************************************************************************
13
8
  )
14
9
  end
@@ -19,7 +14,7 @@ end
19
14
  if Rails.version >= '3.0'
20
15
  require 'admin_data/railtie'
21
16
  else
22
- raise "Please see documentation at http://neerajdotname.github.com/admin_data to find out how to use this plugin with rails 2.3"
17
+ raise "Please see documentation at http://github.com/neerajdotname/admin_data to find out how to use this gem with rails 2.3"
23
18
  end
24
19
 
25
20
  # move date_validation to inside admin_data
@@ -3,7 +3,6 @@ var AdminData = AdminData || {};
3
3
  AdminData.actOnResult = {
4
4
 
5
5
  action: function(action_type) {
6
- log('has been invoked');
7
6
  var formData = $('#advance_search_form').data('admin_data_form_array'),
8
7
  parameterizedData;
9
8
 
Binary file