spiderfw 0.6.25 → 0.6.26.pre1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. data/CHANGELOG +15 -0
  2. data/VERSION +1 -1
  3. data/apps/core/auth/controllers/login_controller.rb +2 -0
  4. data/apps/core/auth/controllers/mixins/auth_helper.rb +1 -1
  5. data/apps/core/auth/public/css/login.css +49 -0
  6. data/apps/core/auth/views/login.layout.shtml +14 -0
  7. data/apps/core/auth/views/login.shtml +1 -0
  8. data/apps/core/components/public/js/jquery/plugins/jquery.ui.nestedSortable.js +356 -0
  9. data/apps/core/forms/public/date_time.js +1 -1
  10. data/apps/core/forms/public/select.js +1 -1
  11. data/apps/core/forms/tags/element_row.erb +2 -2
  12. data/apps/core/forms/widgets/form/form.rb +34 -22
  13. data/apps/messenger/_init.rb +1 -0
  14. data/apps/messenger/views/admin/index.shtml +1 -1
  15. data/apps/messenger/views/index.shtml +1 -1
  16. data/blueprints/.DS_Store +0 -0
  17. data/blueprints/home/.DS_Store +0 -0
  18. data/blueprints/install/.DS_Store +0 -0
  19. data/data/keys/spider.rsa +27 -0
  20. data/data/keys/spider.rsa.pub +1 -0
  21. data/lib/spiderfw/app.rb +64 -4
  22. data/lib/spiderfw/autoload.rb +0 -1
  23. data/lib/spiderfw/cmd/commands/app.rb +2 -1
  24. data/lib/spiderfw/controller/controller.rb +189 -90
  25. data/lib/spiderfw/controller/dispatcher.rb +13 -3
  26. data/lib/spiderfw/controller/http_controller.rb +18 -4
  27. data/lib/spiderfw/controller/mixins/http_mixin.rb +37 -10
  28. data/lib/spiderfw/controller/mixins/visual.rb +14 -5
  29. data/lib/spiderfw/http/http.rb +5 -0
  30. data/lib/spiderfw/model/base_model.rb +1 -11
  31. data/lib/spiderfw/model/condition.rb +7 -4
  32. data/lib/spiderfw/model/mappers/mapper.rb +2 -2
  33. data/lib/spiderfw/requires.rb +1 -0
  34. data/lib/spiderfw/setup/app_manager.rb +7 -2
  35. data/lib/spiderfw/setup/setup_task.rb +1 -1
  36. data/lib/spiderfw/setup/spider_setup_wizard.rb +1 -1
  37. data/lib/spiderfw/spider.rb +4 -1
  38. data/lib/spiderfw/templates/layout.rb +8 -3
  39. data/lib/spiderfw/templates/template.rb +2 -1
  40. data/lib/spiderfw/test/rack_tester.rb +10 -0
  41. data/lib/spiderfw/widget/widget_plugin.rb +8 -1
  42. metadata +254 -157
  43. data/lib/spiderfw/model/storage/db/connectors/mysql.rb +0 -16
  44. data/lib/spiderfw/model/storage/db/connectors/mysql2.rb +0 -9
@@ -43,10 +43,12 @@ module Spider
43
43
  @request.params = Spider::HTTP.parse_query(@request.env['QUERY_STRING'])
44
44
  @request.get = @request.params
45
45
  end
46
- if @request.env['REQUEST_METHOD'] == 'POST' && @request.env['HTTP_CONTENT_TYPE']
46
+ if ['POST', 'PUT', 'DELETE'].include?(@request.env['REQUEST_METHOD']) && @request.env['HTTP_CONTENT_TYPE']
47
47
  if @request.env['HTTP_CONTENT_TYPE'].include?('application/x-www-form-urlencoded')
48
- @request.post = Spider::HTTP.parse_query(@request.read_body)
49
- @request.params.merge!(@request.post)
48
+ data = Spider::HTTP.parse_query(@request.read_body)
49
+ req_meth = @request.env['REQUEST_METHOD'].downcase
50
+ @request.send(:"#{req_meth}=", data)
51
+ @request.params.merge!(@request.send(:"#{req_meth}"))
50
52
  elsif @request.env['HTTP_CONTENT_TYPE'] =~ Spider::HTTP::MULTIPART_REGEXP
51
53
  multipart_params, multipart_files = Spider::HTTP.parse_multipart(@request.body, $1, @request.env['CONTENT_LENGTH'].to_i)
52
54
  @request.params.merge!(multipart_params)
@@ -176,7 +178,7 @@ module Spider
176
178
  end
177
179
 
178
180
  module HTTPRequest
179
- attr_accessor :http_method, :http_host, :domain, :port, :post, :get
181
+ attr_accessor :http_method, :http_host, :domain, :port, :post, :get, :put, :delete
180
182
 
181
183
  # Returns PATH_INFO reversing any proxy mappings if needed.
182
184
  def path
@@ -228,6 +230,10 @@ module Spider
228
230
  def get
229
231
  @get ||= {}
230
232
  end
233
+
234
+ def put
235
+ @put ||= {}
236
+ end
231
237
 
232
238
  def post?
233
239
  self.http_method == :POST
@@ -236,6 +242,14 @@ module Spider
236
242
  def get?
237
243
  self.http_method == :GET
238
244
  end
245
+
246
+ def put?
247
+ self.http_method == :PUT
248
+ end
249
+
250
+ def delete?
251
+ self.http_method == :DELETE
252
+ end
239
253
 
240
254
  end
241
255
 
@@ -12,6 +12,11 @@ module Spider; module ControllerMixins
12
12
  klass.extend(ClassMethods)
13
13
  end
14
14
 
15
+ # Sets the headers to redirect the browser to the given url, and calls
16
+ # {Controller#done} to terminate the execution of the Controller chain
17
+ # @param [String] url
18
+ # @param [Fixnum] code HTTP status to send
19
+ # @return void
15
20
  def redirect(url, code=Spider::HTTP::SEE_OTHER)
16
21
  debug "REDIRECTING TO #{url}"
17
22
  @request.session.persist if @request.session # It might be too late afterwards
@@ -22,30 +27,35 @@ module Spider; module ControllerMixins
22
27
  done
23
28
  end
24
29
 
25
- def self.reverse_proxy_mapping(url)
26
- return '' unless url
30
+ # Takes a url path that the framework would accept, and transforms it
31
+ # into the url path the webserver would send, given the settings in http.proxy_mapping
32
+ # @param [Strint] url_path
33
+ # @return [String] The transformed url path
34
+ def self.reverse_proxy_mapping(url_path)
35
+ return '' unless url_path
27
36
  if (maps = Spider.conf.get('http.proxy_mapping'))
28
37
  maps.each do |proxy, spider|
29
38
  spider ||= ''
30
- return proxy + url[spider.length..-1] if (spider == "" || url[0..spider.length-1] == spider)
39
+ return proxy + url_path[spider.length..-1] if (spider == "" || url_path[0..spider.length-1] == spider)
31
40
  end
32
41
  end
33
- return url
42
+ return url_path
34
43
  end
35
44
 
36
45
  # Returns the http path used to call the current controller & action.
37
46
  # Reverses any proxy mappings to the Controller#request_path.
47
+ # @return [String]
38
48
  def request_path
39
49
  HTTPMixin.reverse_proxy_mapping(super)
40
50
  end
41
51
 
42
- # Returns the request_path prefixed with http:// and the current host.
52
+ # @return [String] the request_path prefixed with http:// and the current host.
43
53
  def request_url
44
54
  return request_path unless @request.env['HTTP_HOST']
45
55
  'http://'+@request.env['HTTP_HOST']+request_path
46
56
  end
47
57
 
48
- # Returns the request_url with query params, if any
58
+ # @return [String] the request_url with query params, if any
49
59
  def request_full_url
50
60
  url = request_url
51
61
  if (@request.env['QUERY_STRING'] && !@request.env['QUERY_STRING'].empty?)
@@ -54,11 +64,18 @@ module Spider; module ControllerMixins
54
64
  return url
55
65
  end
56
66
 
57
- def self.output_charset(val)
67
+ # Sets or returns the charset for the controller
68
+ # @param [String|nil] The charset
69
+ # @return [String] The charset in use
70
+ def self.output_charset(val=nil)
58
71
  @output_charset = val if val
59
72
  @output_charset || Spider.conf.get('http.charset')
60
73
  end
61
74
 
75
+ # Sets a Content type
76
+ # @param [String|Symbol] Content type, or a symbol representing it
77
+ # (Can be :text, :json, :js, :javascript, :html, :xml)
78
+ # @return [String] The value of the "Content-Type" header
62
79
  def content_type(ct)
63
80
  if ct.is_a?(Symbol)
64
81
  ct = {
@@ -73,6 +90,9 @@ module Spider; module ControllerMixins
73
90
  @response.headers["Content-Type"] = "#{ct};charset=utf-8"
74
91
  end
75
92
 
93
+ #
94
+ # @param [String] action
95
+ # @param [*Object] arguments
76
96
  def before(action='', *arguments)
77
97
  return super if self.is_a?(Spider::Widget)
78
98
  # FIXME: the Spider::Widget check
@@ -89,14 +109,17 @@ module Spider; module ControllerMixins
89
109
  super
90
110
  end
91
111
 
112
+ # @return [String] the base URL to which the installation responds
92
113
  def self.base_url
93
114
  HTTPMixin.reverse_proxy_mapping("")
94
115
  end
95
116
 
117
+ # @return [String] the base URL to which the installation responds
96
118
  def base_url
97
119
  HTTPMixin.base_url
98
120
  end
99
121
 
122
+
100
123
  def prepare_scene(scene)
101
124
  scene = super
102
125
  scene.base_url = base_url
@@ -212,13 +235,17 @@ module Spider; module ControllerMixins
212
235
  end
213
236
 
214
237
 
215
- def http_url(action=nil)
216
- return nil unless Spider.site
238
+ def url(action=nil)
239
+ return super unless Spider.site
217
240
  u = "http://#{Spider.site.domain}"
218
241
  u += ":#{Spider.site.port}" unless Spider.site.port == 80
219
- u += HTTPMixin.reverse_proxy_mapping(self.url(action))
242
+ u += HTTPMixin.reverse_proxy_mapping(super(action))
220
243
  u
221
244
  end
245
+
246
+ def http_url(action=nil)
247
+ url(action)
248
+ end
222
249
 
223
250
  end
224
251
 
@@ -39,9 +39,9 @@ module Spider; module ControllerMixins
39
39
  return super unless action_target?
40
40
  format = nil
41
41
  req_format = self.is_a?(Widget) && @is_target && @request.params['_wf'] ? @request.params['_wf'].to_sym : @request.format
42
- if (req_format && self.class.output_formats[@executed_method])
42
+ if req_format && self.class.output_formats[@executed_method]
43
43
  format = req_format if self.class.output_format?(@executed_method, req_format)
44
- if (format)
44
+ if format
45
45
  format_params = self.class.output_format_params(@executed_method, format)
46
46
  end
47
47
  if @executed_method && !format || (format_params && format_params[:widgets] && !target_mode?)
@@ -50,6 +50,11 @@ module Spider; module ControllerMixins
50
50
  end
51
51
  format ||= self.class.output_format(@executed_method)
52
52
  format_params ||= self.class.output_format_params(@executed_method, format)
53
+
54
+ unless !format_params || format_params[:http_method].blank?
55
+ format_params[:http_method] = [format_params[:http_method]] unless format_params[:http_method].is_a?(Enumerable)
56
+ raise Forbidden unless format_params[:http_method].include?(@request.http_method)
57
+ end
53
58
  output_format_headers(format)
54
59
  @executed_format = format
55
60
  @executed_format_params = format_params
@@ -100,7 +105,7 @@ module Spider; module ControllerMixins
100
105
  @is_target = false if target_mode? && !self.is_a?(Spider::Widget)
101
106
  if (self.is_a?(Widget) && @is_target && @request.params['_wp'])
102
107
  params = @request.params['_wp']
103
- elsif (@visual_params.is_a?(Hash) && @visual_params[:params])
108
+ elsif @visual_params.is_a?(Hash) && @visual_params[:params]
104
109
  p_first, p_rest = action.split('/')
105
110
  params = format_params[:params].call(p_rest) if p_rest
106
111
  end
@@ -192,7 +197,11 @@ module Spider; module ControllerMixins
192
197
  template._widget_action = @request.params['_action']
193
198
  else
194
199
  template._action_to = options[:action_to]
195
- template._action = @controller_action
200
+ template_action = @current_action.to_s.split('/')
201
+ if template_action.first == @executed_method.to_s
202
+ template_action = template_action[1..-1]
203
+ end
204
+ template._action = template_action.join('/')
196
205
  end
197
206
  return template
198
207
  end
@@ -462,7 +471,7 @@ module Spider; module ControllerMixins
462
471
  @output_formats[method] << format
463
472
  @output_format_params[method] ||= {}
464
473
  @output_format_params[method][format] = params
465
- controller_actions(method)
474
+ controller_action(method, params)
466
475
  return format
467
476
  end
468
477
  return @default_output_format unless @output_formats[method] && @output_formats[method][0]
@@ -15,6 +15,11 @@ module Spider
15
15
  FILENAME_REGEX = /Content-Disposition:.* filename="?([^\";]*)"?/ni.freeze
16
16
  CRLF = "\r\n".freeze
17
17
  EOL = CRLF
18
+
19
+ METHODS = [
20
+ :GET, :POST, :PUT, :DELETE, :HEAD, :TRACE, :CONNECT,
21
+ :PROPFIND, :PROPPATCH, :MKCOL, :COPY, :MOVE, :LOCK, :UNLOCK
22
+ ]
18
23
 
19
24
  module StatusCodes
20
25
 
@@ -52,6 +52,7 @@ module Spider; module Model
52
52
  # p salmon_lovers[0].name
53
53
  # => 'Cat'
54
54
  class BaseModel
55
+ include App::AppClass
55
56
  include Spider::Logger
56
57
  include DataTypes
57
58
  include Spider::QueryFuncs
@@ -138,17 +139,6 @@ module Spider; module Model
138
139
  @subclasses || []
139
140
  end
140
141
 
141
- # Returns the parent Spider::App of the module
142
- # @return [Spider::App]
143
- def self.app
144
- return @app if @app
145
- app = self
146
- while app && !app.include?(Spider::App)
147
- app = app.parent_module
148
- end
149
- @app = app
150
- end
151
-
152
142
 
153
143
  #######################################
154
144
  # Model definition methods #
@@ -110,6 +110,9 @@ module Spider; module Model
110
110
  @comparisons = {}
111
111
  @subconditions = []
112
112
  params.reject!{ |p| p.nil? }
113
+ if params[0].is_a?(Proc)
114
+ params[0] = params[0].call
115
+ end
113
116
  if (params.length == 1 && params[0].is_a?(Hash) && !params[0].is_a?(Condition))
114
117
  params[0].each do |k, v|
115
118
  set(k, '=', v)
@@ -193,14 +196,14 @@ module Spider; module Model
193
196
  end
194
197
 
195
198
  # Adds a subcondtion.
196
- # @param [Condition] condition
199
+ # @param [Condition|Hash|Proc|String] condition
197
200
  # @return [void]
198
201
  def <<(condition)
199
- if (condition.class == self.class)
202
+ if condition.class == self.class
200
203
  @subconditions << condition
201
- elsif (condition.is_a?(Hash))
204
+ elsif condition.is_a?(Hash) || condition.is_a?(Proc)
202
205
  @subconditions << self.class.new(condition)
203
- elsif (condition.class == String)
206
+ elsif condition.class == String
204
207
  key, val, comparison = parse_comparison(condition)
205
208
  set(key, val, comparison)
206
209
  end
@@ -1113,8 +1113,8 @@ module Spider; module Model
1113
1113
  rescue TypeError => exc
1114
1114
  raise TypeError, "Can't convert #{v} to #{element.type} for element #{k} (#{exc.message})"
1115
1115
  end
1116
- elsif element.type == DateTime && v && !v.is_a?(Date) && !v.is_a?(Time)
1117
- v = DateTime.parse(v)
1116
+ elsif [DateTime, Date].include?(element.type) && v && !v.is_a?(Date) && !v.is_a?(Time)
1117
+ v = element.type.parse(v)
1118
1118
  changed_v = true
1119
1119
  elsif element.model? && v.is_a?(Spider::Model::Condition)
1120
1120
  unless v.primary_keys_only?(element.model)
@@ -27,6 +27,7 @@ require 'spiderfw/utils/http_client'
27
27
  require 'spiderfw/utils/gems'
28
28
  require 'spiderfw/config/configuration'
29
29
  require 'spiderfw/config/configurable'
30
+ require 'spiderfw/app'
30
31
  require 'spiderfw/model/model'
31
32
  require 'spiderfw/home'
32
33
  require 'spiderfw/site'
@@ -90,8 +90,8 @@ module Spider
90
90
  do_update(spec, options)
91
91
  end
92
92
  post_update(specs[:update], options)
93
- rescue => exc
94
- rollback_update
93
+ rescue
94
+ rollback_update unless options[:no_rollback]
95
95
  raise
96
96
  end
97
97
  unless options[:no_activate]
@@ -496,6 +496,11 @@ module Spider
496
496
 
497
497
  private
498
498
 
499
+ def git_command(command)
500
+ #`GIT_SSH='ssh -i #{File.join(Spider.paths[:data], 'keys', 'spider.rsa')}' git #{command}`
501
+ `git #{command}`
502
+ end
503
+
499
504
  def reset_git_env
500
505
  ENV['GIT_WORK_TREE'] = nil
501
506
  ENV["GIT_INDEX_FILE"] = nil
@@ -142,7 +142,7 @@ module Spider
142
142
  def warn(msg)
143
143
  puts msg
144
144
  print "\n"+_("Press any key to continue ")
145
- $stdin.getch
145
+ $stdin.getc
146
146
  print "\n"
147
147
  end
148
148
 
@@ -69,7 +69,7 @@ module Spider
69
69
 
70
70
  print prompt
71
71
 
72
- res = $stdin.gets.strip
72
+ res = $stdin.gets.strip.downcase
73
73
 
74
74
  good = true
75
75
  if options[:type] == Spider::Bool
@@ -154,7 +154,10 @@ module Spider
154
154
  @runmode = nil
155
155
  self.runmode = $SPIDER_RUNMODE if $SPIDER_RUNMODE
156
156
  load_configuration File.join($SPIDER_PATH, 'config')
157
- user_rc = File.join(Etc.getpwuid.dir, '.spider.conf.yml')
157
+ begin
158
+ user_rc = File.join(Etc.getpwuid.dir, '.spider.conf.yml')
159
+ rescue NoMethodError # No getpwuid under windows
160
+ end
158
161
  if File.file?(user_rc)
159
162
  load_configuration_file(user_rc)
160
163
  end
@@ -270,9 +270,14 @@ module Spider
270
270
  compiler.compile(ass[:path], dest)
271
271
  rescue Exception
272
272
  if ext == '.less'
273
- Spider.logger.error("Unable to compile LESS. Please ensure you have a JS backend
274
- (see https://github.com/sstephenson/execjs)")
275
- else
273
+ msg = "Unable to compile LESS file #{ass[:path]}."
274
+ msg += "Please ensure you have a JS backend (see https://github.com/sstephenson/execjs)"
275
+ elsif ext == '.scss' || ext == '.sass'
276
+ msg = "Unable to compile SASS file #{ass[:path]}."
277
+ msg += "Please ensure that you have the 'sass' (and optionally 'compass') gems installed."
278
+ end
279
+ Spider.logger.error(msg)
280
+ unless File.exist?(dest)
276
281
  raise
277
282
  end
278
283
  end
@@ -405,7 +405,8 @@ module Spider
405
405
  ass[:app] = asset_owner.app if asset_owner.respond_to?(:app)
406
406
  # FIXME! @definer_class is not correct for Spider::HomeController
407
407
  raise "Asset type not given for #{src}" unless type
408
- search_classes = [asset_owner, @definer_class]
408
+ search_classes = [asset_owner]
409
+ search_classes << @definer_class if @definer_class
409
410
  dfnr = @definer_class.superclass if @definer_class && @definer_class.respond_to?(:superclass)
410
411
  while dfnr && dfnr < Spider::Widget
411
412
  search_classes << dfnr
@@ -0,0 +1,10 @@
1
+ require 'rack/test'
2
+
3
+ class RackTester
4
+ include Rack::Test::Methods
5
+
6
+ def app
7
+ Spider::HTTP::RackApplication.new
8
+ end
9
+
10
+ end
@@ -50,6 +50,13 @@ module Spider
50
50
  end
51
51
  @controller_actions
52
52
  end
53
+
54
+ def controller_action(method, params)
55
+ @controller_actions ||= []
56
+ @controller_actions << method
57
+ @controller_action_params ||= {}
58
+ @controller_action_params[method] = params
59
+ end
53
60
 
54
61
  def controller_action?(method)
55
62
  @controller_actions && @controller_actions.include?(method)
@@ -59,4 +66,4 @@ module Spider
59
66
 
60
67
  end
61
68
 
62
- end
69
+ end