admin_data 1.0.22 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +23 -16
- data/README.md +1 -1
- data/Rakefile +2 -2
- data/app/controllers/admin_data/application_controller.rb +111 -0
- data/app/controllers/admin_data/crud_controller.rb +100 -0
- data/app/controllers/admin_data/feed_controller.rb +38 -16
- data/app/controllers/admin_data/home_controller.rb +11 -0
- data/app/controllers/admin_data/migration_controller.rb +12 -12
- data/app/controllers/admin_data/public_controller.rb +29 -19
- data/app/controllers/admin_data/search_controller.rb +99 -103
- data/app/controllers/admin_data/table_structure_controller.rb +25 -0
- data/app/helpers/admin_data/application_helper.rb +287 -0
- data/app/views/admin_data/crud/association/_association_info.html.erb +11 -0
- data/app/views/admin_data/crud/association/_belongs_to_info.html.erb +7 -0
- data/app/views/admin_data/{main → crud}/association/_habtm_info.html.erb +3 -3
- data/app/views/admin_data/{main → crud}/association/_has_many_info.html.erb +3 -3
- data/app/views/admin_data/crud/association/_has_one_info.html.erb +6 -0
- data/app/views/admin_data/{main → crud}/edit.html.erb +9 -9
- data/app/views/admin_data/{main → crud}/misc/_form.html.erb +6 -6
- data/app/views/admin_data/{main → crud}/misc/_modify_record.html.erb +4 -4
- data/app/views/admin_data/{main → crud}/new.html.erb +7 -7
- data/app/views/admin_data/{main → crud}/show.html.erb +10 -10
- data/app/views/admin_data/{main → home}/index.html.erb +2 -2
- data/app/views/admin_data/migration/index.html.erb +3 -3
- data/app/views/admin_data/search/_search_base.html.erb +5 -5
- data/app/views/admin_data/search/quick_search.html.erb +4 -4
- data/app/views/admin_data/search/search/_listing.html.erb +11 -9
- data/app/views/admin_data/search/search/_sortby.html.erb +4 -3
- data/app/views/admin_data/search/search/_title.html.erb +7 -7
- data/app/views/admin_data/shared/_breadcrum.html.erb +11 -5
- data/app/views/admin_data/shared/_header.html.erb +6 -6
- data/app/views/admin_data/shared/_secondary_navigation.html.erb +13 -14
- data/app/views/admin_data/{main/table_structure.html.erb → table_structure/index.html.erb} +11 -11
- data/app/views/layouts/admin_data.html.erb +15 -15
- data/config/routes.rb +3 -3
- data/lib/admin_data.rb +29 -6
- data/lib/admin_data/active_record_util.rb +38 -6
- data/lib/admin_data/configuration.rb +113 -0
- data/lib/admin_data/deprecation.rb +31 -0
- data/lib/admin_data/railtie.rb +2 -7
- data/lib/admin_data/search.rb +1 -1
- data/lib/admin_data/util.rb +74 -161
- data/lib/admin_data/version.rb +1 -1
- data/test/rails_root/app/controllers/application_controller.rb +3 -0
- data/test/rails_root/app/helpers/application_helper.rb +5 -0
- data/test/rails_root/app/models/city.rb +22 -0
- data/test/rails_root/app/models/club.rb +3 -0
- data/test/rails_root/app/models/newspaper.rb +4 -0
- data/test/rails_root/app/models/phone_number.rb +3 -0
- data/test/rails_root/app/models/user.rb +17 -0
- data/test/rails_root/app/models/website.rb +3 -0
- data/test/rails_root/config/application.rb +42 -0
- data/test/rails_root/config/boot.rb +13 -0
- data/test/rails_root/config/environment.rb +5 -0
- data/test/rails_root/config/environments/development.rb +22 -0
- data/test/rails_root/config/environments/production.rb +49 -0
- data/test/rails_root/config/environments/test.rb +35 -0
- data/test/rails_root/config/initializers/admin_data.rb +22 -0
- data/test/rails_root/config/initializers/backtrace_silencers.rb +7 -0
- data/test/rails_root/config/initializers/empty_spaces_to_nil.rb +10 -0
- data/test/rails_root/config/initializers/inflections.rb +10 -0
- data/test/rails_root/config/initializers/mime_types.rb +5 -0
- data/test/rails_root/config/initializers/secret_token.rb +7 -0
- data/test/rails_root/config/initializers/session_store.rb +8 -0
- data/test/rails_root/config/routes.rb +9 -0
- data/test/rails_root/db/migrate/20091030202259_create_users.rb +55 -0
- data/test/rails_root/db/schema.rb +63 -0
- data/test/rails_root/db/seeds.rb +40 -0
- data/test/rails_root/features/step_definitions/advance_search_steps.rb +13 -0
- data/test/rails_root/features/step_definitions/app_steps.rb +40 -0
- data/test/rails_root/features/step_definitions/async.rb +18 -0
- data/test/rails_root/features/step_definitions/crud_show_steps.rb +37 -0
- data/test/rails_root/features/step_definitions/feed_steps.rb +3 -0
- data/test/rails_root/features/step_definitions/quick_search_steps.rb +65 -0
- data/test/rails_root/features/step_definitions/util.rb +86 -0
- data/test/rails_root/features/step_definitions/web_steps.rb +219 -0
- data/test/rails_root/features/support/env.rb +68 -0
- data/test/rails_root/features/support/paths.rb +33 -0
- data/test/rails_root/test/factories.rb +30 -0
- data/test/rails_root/test/performance/browsing_test.rb +9 -0
- data/test/rails_root/test/test_helper.rb +13 -0
- metadata +100 -49
- data/app/controllers/admin_data/base_controller.rb +0 -112
- data/app/controllers/admin_data/main_controller.rb +0 -141
- data/app/views/admin_data/main/association/_association_info.html.erb +0 -11
- data/app/views/admin_data/main/association/_belongs_to_info.html.erb +0 -7
- data/app/views/admin_data/main/association/_has_one_info.html.erb +0 -6
- data/lib/admin_data/chelper.rb +0 -37
- data/lib/admin_data/helpers.rb +0 -271
- data/lib/admin_data/settings.rb +0 -67
- data/lib/css/base.css +0 -1108
- data/lib/css/vendor/jquery-ui-1.7.2.custom.css +0 -406
- data/lib/js/advance_search/act_on_result.js +0 -45
- data/lib/js/advance_search/advance_search.js +0 -83
- data/lib/js/advance_search/advance_search_structure.js +0 -79
- data/lib/js/advance_search/ajaxify_advance_search.js +0 -28
- data/lib/js/advance_search/build_first_row.js +0 -8
- data/lib/js/advance_search/event_bindings.js +0 -76
- data/lib/js/advance_search/global_ajax_setting.js +0 -10
- data/lib/js/advance_search/trigger_submit_on_domready.js +0 -6
- data/lib/js/misc/drop_down_change.js +0 -8
- data/lib/js/misc/js_util.js +0 -58
- data/lib/js/misc/quick_search_input_focus.js +0 -6
- data/lib/js/test/act_on_result.js +0 -120
- data/lib/js/test/advance_search.js +0 -80
- data/lib/js/test/ajaxify_advance_search.js +0 -29
- data/lib/js/test/build_first_row.js +0 -10
- data/lib/js/test/event_bindings.js +0 -100
- data/lib/js/vendor/jack.js +0 -903
- data/lib/js/vendor/jquery-1.4.2.js +0 -6240
- data/lib/js/vendor/jquery-ui-1.7.2.custom.min.js +0 -298
- data/lib/js/vendor/jquery.ba-isjquery.js +0 -21
- data/lib/js/vendor/jquery.form.js +0 -814
- data/lib/js/vendor/log.js +0 -9
- data/lib/js/vendor/qunit.js +0 -1043
- data/lib/js/vendor/rails.js +0 -132
data/History.txt
CHANGED
@@ -1,3 +1,10 @@
|
|
1
|
+
=== 2010-12-07
|
2
|
+
* new router api
|
3
|
+
* new configuration api. It is not backward compatible. However the error message is nice.
|
4
|
+
* cucumber tests are inside the repo
|
5
|
+
* support for column_headers
|
6
|
+
* support for column_settings
|
7
|
+
|
1
8
|
=== 2010-11-08 v1.0.20
|
2
9
|
* support for habtm
|
3
10
|
* do not get the list of nested models. It breaks routing. Comprehensive nested models fix coming soon.
|
@@ -38,7 +45,7 @@
|
|
38
45
|
* fix for options defined in ~/config/initializers/admin_data_settings.rb not taking effect
|
39
46
|
|
40
47
|
=== 2010-08-17 v1.0.3
|
41
|
-
* added more tests
|
48
|
+
* added more tests
|
42
49
|
* fixed a bug related to :is_allowed_to_view_klass
|
43
50
|
|
44
51
|
|
@@ -116,7 +123,7 @@
|
|
116
123
|
|
117
124
|
=== 0.0.26 2009-11-04
|
118
125
|
|
119
|
-
* cleaning up History.txt file
|
126
|
+
* cleaning up History.txt file
|
120
127
|
|
121
128
|
=== 0.0.25 2009-11-03
|
122
129
|
|
@@ -139,7 +146,7 @@
|
|
139
146
|
|
140
147
|
=== 0.0.21 2009-10-26
|
141
148
|
|
142
|
-
* fixed the formatting issue while displaying missing index in diagnostic section
|
149
|
+
* fixed the formatting issue while displaying missing index in diagnostic section
|
143
150
|
* by passing additional parameter called 'attr' editing of a record would display
|
144
151
|
only one field to avoid any accidental change.
|
145
152
|
|
@@ -154,7 +161,7 @@ override the sql that is built by admin_data
|
|
154
161
|
|
155
162
|
=== 0.0.18 2009-10-16
|
156
163
|
|
157
|
-
* changed theme from warehouse to dark because the association info on the right
|
164
|
+
* changed theme from warehouse to dark because the association info on the right
|
158
165
|
hand side was not appearing correctly
|
159
166
|
* homepage should have main tab selected
|
160
167
|
* changed urls to support models that override to_param to other than id
|
@@ -164,14 +171,14 @@ as A,Q,B instead of A,B,Q.
|
|
164
171
|
=== 0.0.17 2009-10-08
|
165
172
|
|
166
173
|
* drop down of klasses is now available at the center of home page
|
167
|
-
* current model will be selected in the drop down
|
174
|
+
* current model will be selected in the drop down
|
168
175
|
|
169
176
|
=== 0.0.16 2009-10-07
|
170
177
|
|
171
178
|
* form UI foreign keys are dropdown (display name attribute if it exists and id otherwise)
|
172
179
|
* form UI date fields use date_select (with free text year since we cannot guess a good range)
|
173
180
|
* form UI refactored to use form_for instead of form_tag and hadcoded html
|
174
|
-
|
181
|
+
|
175
182
|
=== 0.0.15 2009-10-06
|
176
183
|
|
177
184
|
* cache the list of models
|
@@ -182,21 +189,21 @@ as A,Q,B instead of A,B,Q.
|
|
182
189
|
|
183
190
|
=== 0.0.14 2009-10-05
|
184
191
|
|
185
|
-
* while editing match was being done for hard coded value id. Now it looks for klass.primary_key
|
192
|
+
* while editing match was being done for hard coded value id. Now it looks for klass.primary_key
|
186
193
|
|
187
194
|
=== 0.0.13 2009-10-04
|
188
195
|
|
189
|
-
* fixed IE7 bug
|
196
|
+
* fixed IE7 bug
|
190
197
|
|
191
198
|
=== 0.0.12 2009-10-04
|
192
199
|
|
193
|
-
* fixed bug regarding integer values not appearning in listing
|
200
|
+
* fixed bug regarding integer values not appearning in listing
|
194
201
|
* better indentation
|
195
202
|
|
196
203
|
=== 0.0.11 2009-10-01
|
197
204
|
|
198
|
-
* Major contribution in this release by Alex Rothenberg. http://github.com/alexrothenberg
|
199
|
-
* this plugin now treats each model as a restful resource.
|
205
|
+
* Major contribution in this release by Alex Rothenberg. http://github.com/alexrothenberg
|
206
|
+
* this plugin now treats each model as a restful resource.
|
200
207
|
* security fix and test for it
|
201
208
|
* commented out offending code for has_one relationship
|
202
209
|
* has_one and habtm relationships along with test would be taken up in next release
|
@@ -210,7 +217,7 @@ as A,Q,B instead of A,B,Q.
|
|
210
217
|
|
211
218
|
=== 0.0.10 2009-09-18
|
212
219
|
|
213
|
-
* fixed listing and has_many association info for namespaced model
|
220
|
+
* fixed listing and has_many association info for namespaced model
|
214
221
|
|
215
222
|
=== 0.0.9 2009-09-18
|
216
223
|
|
@@ -224,7 +231,7 @@ as A,Q,B instead of A,B,Q.
|
|
224
231
|
|
225
232
|
=== 0.0.7 2009-09-17
|
226
233
|
|
227
|
-
* fixed test for Vehicle::Car
|
234
|
+
* fixed test for Vehicle::Car
|
228
235
|
|
229
236
|
=== 0.0.6 2009-09-09
|
230
237
|
|
@@ -242,9 +249,9 @@ as A,Q,B instead of A,B,Q.
|
|
242
249
|
|
243
250
|
* changed the way security configiruation is passed to the plugin
|
244
251
|
|
245
|
-
* users can configure number of records in a page. Default is 50
|
252
|
+
* users can configure number of records in a page. Default is 50
|
246
253
|
|
247
|
-
* fixed bug associated with advance search
|
254
|
+
* fixed bug associated with advance search
|
248
255
|
|
249
256
|
* added link to report bug in footer
|
250
257
|
|
@@ -253,7 +260,7 @@ as A,Q,B instead of A,B,Q.
|
|
253
260
|
=== 0.0.4 2009-08-28
|
254
261
|
|
255
262
|
* storing serialized array in string causing problem in truncate method. more at
|
256
|
-
http://github.com/neerajdotname/admin_data/issues#issue/3.
|
263
|
+
http://github.com/neerajdotname/admin_data/issues#issue/3.
|
257
264
|
|
258
265
|
=== 0.0.3 2009-08-10
|
259
266
|
|
data/README.md
CHANGED
@@ -14,7 +14,7 @@
|
|
14
14
|
|
15
15
|
#Test#
|
16
16
|
|
17
|
-
|
17
|
+
cd _test/rails_app_ and read the instructions mentioned at README.md there.
|
18
18
|
|
19
19
|
|
20
20
|
### License
|
data/Rakefile
CHANGED
@@ -17,7 +17,7 @@ Rake::RDocTask.new(:rdoc) do |rdoc|
|
|
17
17
|
rdoc.rdoc_dir = 'rdoc'
|
18
18
|
rdoc.title = 'AdminData'
|
19
19
|
rdoc.options << '--line-numbers' << '--inline-source'
|
20
|
-
rdoc.rdoc_files.include('README.
|
20
|
+
rdoc.rdoc_files.include('README.md')
|
21
21
|
rdoc.rdoc_files.include('lib/**/*.rb')
|
22
22
|
end
|
23
23
|
|
@@ -31,7 +31,7 @@ begin
|
|
31
31
|
s.email = "neerajdotname@gmail.com"
|
32
32
|
s.homepage = "http://github.com/neerajdotname/admin_data"
|
33
33
|
s.authors = ['Neeraj Singh']
|
34
|
-
s.files = FileList["[A-Z]*", "{app,config,lib
|
34
|
+
s.files = FileList["[A-Z]*", "{app,config,lib}/**/*", 'init.rb']
|
35
35
|
|
36
36
|
s.add_dependency('will_paginate', '>= 3.0.pre2')
|
37
37
|
|
@@ -0,0 +1,111 @@
|
|
1
|
+
module AdminData
|
2
|
+
|
3
|
+
class ApplicationController < ::ApplicationController
|
4
|
+
|
5
|
+
before_filter :ensure_is_allowed_to_view
|
6
|
+
|
7
|
+
helper_method :is_allowed_to_update?
|
8
|
+
|
9
|
+
layout 'admin_data'
|
10
|
+
|
11
|
+
before_filter :build_klasses, :build_drop_down_for_klasses, :check_page_parameter, :prepare_drop_down_klasses
|
12
|
+
|
13
|
+
attr_reader :klass, :model
|
14
|
+
|
15
|
+
protected
|
16
|
+
|
17
|
+
self.config.asset_path = lambda {|asset| "/admin_data/public#{asset}"}
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def prepare_drop_down_klasses
|
22
|
+
k = params[:klass] || ''
|
23
|
+
@drop_down_url = "http://#{request.host_with_port}/admin_data/quick_search/#{CGI.escape(k)}"
|
24
|
+
end
|
25
|
+
|
26
|
+
def ensure_is_allowed_to_view
|
27
|
+
render :text => 'not authorized' unless is_allowed_to_view?
|
28
|
+
end
|
29
|
+
|
30
|
+
def ensure_is_allowed_to_update
|
31
|
+
render :text => 'not authorized' unless is_allowed_to_update?
|
32
|
+
end
|
33
|
+
|
34
|
+
def get_class_from_params
|
35
|
+
begin
|
36
|
+
@klass = Util.camelize_constantize(params[:klass])
|
37
|
+
rescue TypeError => e # in case no params[:klass] is supplied
|
38
|
+
render :text => 'wrong params[:klass] was supplied' and return
|
39
|
+
rescue NameError # in case wrong params[:klass] is supplied
|
40
|
+
render :text => 'wrong params[:klass] was supplied' and return
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def build_klasses
|
45
|
+
@klasses = _build_all_klasses
|
46
|
+
end
|
47
|
+
|
48
|
+
def _build_all_klasses
|
49
|
+
if defined? $admin_data_all_klasses
|
50
|
+
return $admin_data_all_klasses
|
51
|
+
else
|
52
|
+
model_dir = File.join(Rails.root, 'app', 'models')
|
53
|
+
model_names = Dir.chdir(model_dir) { Dir["*.rb"] }
|
54
|
+
klasses = get_klass_names(model_names)
|
55
|
+
$admin_data_all_klasses = remove_klasses_without_table(klasses).sort_by {|r| r.name.underscore}
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def _build_custom_klasses
|
60
|
+
_build_all_klasses.compact.select do |klass_local|
|
61
|
+
@klass = klass_local
|
62
|
+
is_allowed_to_view_klass?
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def remove_klasses_without_table(klasses)
|
67
|
+
klasses.select { |k| k.ancestors.include?(ActiveRecord::Base) && k.connection.table_exists?(k.table_name) }
|
68
|
+
end
|
69
|
+
|
70
|
+
def get_klass_names(model_names)
|
71
|
+
model_names.inject([]) do |output, model_name|
|
72
|
+
klass_name = model_name.sub(/\.rb$/,'').camelize
|
73
|
+
begin
|
74
|
+
output << Util.constantize_klass(klass_name)
|
75
|
+
rescue Exception => e
|
76
|
+
Rails.logger.debug e.message
|
77
|
+
end
|
78
|
+
output
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
def build_drop_down_for_klasses
|
83
|
+
@drop_down_for_klasses = @klasses.inject([]) do |result, klass|
|
84
|
+
result << [klass.name.underscore, admin_data_search_url(:klass => klass.name.underscore)]
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
def check_page_parameter
|
89
|
+
# Got hoptoad error because of url like
|
90
|
+
# http://localhost:3000/admin_data/User/advance_search?page=http://201.134.249.164/intranet/on.txt?
|
91
|
+
if params[:page].blank? || (params[:page] =~ /\A\d+\z/)
|
92
|
+
# proceed
|
93
|
+
else
|
94
|
+
render :text => 'Invalid params[:page]', :status => :unprocessable_entity
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
def per_page
|
99
|
+
AdminData.config.number_of_records_per_page
|
100
|
+
end
|
101
|
+
|
102
|
+
def is_allowed_to_view?
|
103
|
+
AdminData.config.is_allowed_to_view.call(self)
|
104
|
+
end
|
105
|
+
|
106
|
+
def is_allowed_to_update?
|
107
|
+
AdminData.config.is_allowed_to_update.call(self)
|
108
|
+
end
|
109
|
+
|
110
|
+
end
|
111
|
+
end
|
@@ -0,0 +1,100 @@
|
|
1
|
+
module AdminData
|
2
|
+
|
3
|
+
class CrudController < ApplicationController
|
4
|
+
|
5
|
+
before_filter :get_class_from_params, :only => [:show, :destroy, :del, :edit, :new, :update, :create]
|
6
|
+
|
7
|
+
before_filter :get_model_and_verify_it, :only => [:destroy, :del, :edit, :update, :show]
|
8
|
+
|
9
|
+
before_filter :ensure_is_allowed_to_update, :only => [:destroy, :del, :edit, :update, :create]
|
10
|
+
|
11
|
+
def show
|
12
|
+
@page_title = "#{@klass.name.underscore}:#{@model.id}"
|
13
|
+
respond_to {|format| format.html}
|
14
|
+
end
|
15
|
+
|
16
|
+
def destroy
|
17
|
+
@klass.send(:destroy, params[:id])
|
18
|
+
redirect_to admin_data_search_path(:klass => @klass.name.underscore)
|
19
|
+
end
|
20
|
+
|
21
|
+
def del
|
22
|
+
@klass.send(:delete, params[:id])
|
23
|
+
flash[:success] = 'Record was deleted'
|
24
|
+
redirect_to admin_data_search_path(:klass => @klass.name.underscore)
|
25
|
+
end
|
26
|
+
|
27
|
+
def edit
|
28
|
+
@page_title = "edit #{@klass.name.underscore}:#{@model.id}"
|
29
|
+
@columns = columns_list
|
30
|
+
respond_to {|format| format.html}
|
31
|
+
end
|
32
|
+
|
33
|
+
def new
|
34
|
+
@page_title = "new #{@klass.name.underscore}"
|
35
|
+
@model = @klass.send(:new)
|
36
|
+
@columns = columns_list
|
37
|
+
respond_to {|format| format.html}
|
38
|
+
end
|
39
|
+
|
40
|
+
def update
|
41
|
+
model_attrs = params[@klass.name.underscore]
|
42
|
+
@columns = columns_list
|
43
|
+
|
44
|
+
respond_to do |format|
|
45
|
+
if @model.update_attributes(model_attrs)
|
46
|
+
format.html do
|
47
|
+
flash[:success] = "Record was updated"
|
48
|
+
redirect_to admin_data_path(:id => @model, :klass => @klass.name.underscore)
|
49
|
+
end
|
50
|
+
format.js { render :json => {:success => true}}
|
51
|
+
else
|
52
|
+
format.html { render :action => 'edit' }
|
53
|
+
format.js { render :json => {:error => @model.errors.full_messages.join } }
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def create
|
59
|
+
model_attrs = params[@klass.name.underscore]
|
60
|
+
@model = @klass.create(model_attrs)
|
61
|
+
@columns = columns_list
|
62
|
+
|
63
|
+
respond_to do |format|
|
64
|
+
if @model.errors.any?
|
65
|
+
format.html { render :action => 'new' }
|
66
|
+
format.js { render :json => {:error => @model.errors.full_messages.join() }}
|
67
|
+
else
|
68
|
+
format.html do
|
69
|
+
flash[:success] = "Record was created"
|
70
|
+
redirect_to admin_data_path(:id => @model, :klass => @klass.name.underscore)
|
71
|
+
end
|
72
|
+
format.js { render :json => {} }
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
private
|
78
|
+
|
79
|
+
def get_model_and_verify_it
|
80
|
+
primary_key = @klass.primary_key.intern
|
81
|
+
conditional_id = params[:id] =~ /^(\d+)-.*/ ? params[:id].to_i : params[:id]
|
82
|
+
condition = {primary_key => conditional_id}
|
83
|
+
|
84
|
+
_proc = AdminData.config.find_conditions[@klass.name]
|
85
|
+
if _proc && find_conditions = _proc.call(params)
|
86
|
+
condition = find_conditions.fetch(:conditions) if find_conditions.has_key?(:conditions)
|
87
|
+
end
|
88
|
+
|
89
|
+
unless @model = @klass.find(:first, :conditions => condition)
|
90
|
+
render :text => "#{@klass.name} not found: #{params[:id]}"
|
91
|
+
return
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
def columns_list
|
96
|
+
params[:attr].blank? ? @klass.columns : @klass.columns.find_all {|col| params[:attr] == col.name}
|
97
|
+
end
|
98
|
+
|
99
|
+
end
|
100
|
+
end
|
@@ -1,26 +1,48 @@
|
|
1
|
-
|
1
|
+
module AdminData
|
2
2
|
|
3
|
-
|
3
|
+
class FeedController < ApplicationController
|
4
4
|
|
5
|
-
|
5
|
+
def index
|
6
|
+
render :text => "Usage: http://localhost:3000/admin_data/feed/<model name>" and return if params[:klasss].blank?
|
6
7
|
|
7
|
-
|
8
|
-
|
8
|
+
begin
|
9
|
+
@klass = Util.camelize_constantize(params[:klasss])
|
10
|
+
@title = "Feeds from admin_data #{@klass.name}"
|
11
|
+
@description = "feeds from AdminData #{@klass.name}"
|
12
|
+
@records = @klass.find(:all, :order => "#{@klass.primary_key} desc", :limit => 100)
|
13
|
+
rescue NameError => e
|
14
|
+
render :text => "No constant was found with name #{params[:klasss]}" and return
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
9
19
|
|
10
|
-
|
11
|
-
|
12
|
-
@title = "Feeds from admin_data #{@klass.name}"
|
13
|
-
@description = "feeds from AdminData #{@klass.name}"
|
14
|
-
@records = @klass.find(:all, :order => "#{@klass.primary_key} desc", :limit => 100)
|
15
|
-
rescue NameError => e
|
16
|
-
render :text => "No constant was found with name #{params[:klasss]}" and return
|
20
|
+
def ensure_is_allowed_to_view_feed
|
21
|
+
render :text => 'not authorized' unless is_allowed_to_view_feed?(self)
|
17
22
|
end
|
18
|
-
end
|
19
23
|
|
20
|
-
|
24
|
+
def is_allowed_to_view_feed?(controller)
|
25
|
+
return true if Rails.env.development?
|
26
|
+
|
27
|
+
if AdminData.config.feed_authentication_user_id.blank?
|
28
|
+
Rails.logger.info 'No user id has been supplied for feed'
|
29
|
+
return false
|
30
|
+
elsif AdminData.config.feed_authentication_password.blank?
|
31
|
+
Rails.logger.info 'No password has been supplied for feed'
|
32
|
+
return false
|
33
|
+
end
|
34
|
+
|
35
|
+
stored_userid = AdminData.config.feed_authentication_user_id
|
36
|
+
stored_password = AdminData.config.feed_authentication_password
|
37
|
+
perform_basic_authentication(stored_userid, stored_password, controller)
|
38
|
+
end
|
39
|
+
|
40
|
+
def perform_basic_authentication(stored_userid, stored_password, controller)
|
41
|
+
controller.authenticate_or_request_with_http_basic do |input_userid, input_password|
|
42
|
+
(input_userid == stored_userid) && (input_password == stored_password)
|
43
|
+
end
|
44
|
+
end
|
21
45
|
|
22
|
-
def ensure_is_allowed_to_view_feed
|
23
|
-
render :text => 'not authorized' unless AdminData::Util.is_allowed_to_view_feed?(self)
|
24
46
|
end
|
25
47
|
|
26
48
|
end
|
@@ -1,18 +1,18 @@
|
|
1
|
-
|
1
|
+
module AdminData
|
2
|
+
class MigrationController < ApplicationController
|
2
3
|
|
3
|
-
|
4
|
+
before_filter :ensure_is_allowed_to_view
|
4
5
|
|
5
|
-
|
6
|
+
def index
|
7
|
+
@page_title = 'migration information'
|
8
|
+
@data = ActiveRecord::Base.connection.select_all('select * from schema_migrations')
|
9
|
+
respond_to {|format| format.html}
|
10
|
+
end
|
6
11
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
end
|
12
|
+
def jstest
|
13
|
+
@page_title = 'jstest'
|
14
|
+
respond_to {|format| format.html { render :layout => false}}
|
15
|
+
end
|
12
16
|
|
13
|
-
def jstest
|
14
|
-
@page_title = 'jstest'
|
15
|
-
respond_to {|format| format.html { render :layout => false}}
|
16
17
|
end
|
17
|
-
|
18
18
|
end
|