wagn 1.16.12 → 1.16.13

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a8a5c9af5235141f4ef6f81f6dca6e05def44baf
4
- data.tar.gz: 0376a58be561c3112cb676df7012d3a5a6f6ae36
3
+ metadata.gz: 8e473eb9550da267709664cbb3ce08fb40c90c92
4
+ data.tar.gz: edcbe05bf48a8f157f0f7df766b5351d80bcfdbd
5
5
  SHA512:
6
- metadata.gz: 3255637d5a475147379c807e142027f68de266e0c10ef196c22cf1c46eb0390569ea9f30f95ce08f5255657052abad14ea444ba2fbfa443fc2f2eef55a20ba4c
7
- data.tar.gz: 225a726263a50c739563566f1d8a7d592114a4b0cb009a2363693ca4f47189ae6a145da480f980e810396b2675d18d8a84c64a69aaf10465594a815ef40a77df
6
+ metadata.gz: 26ece38ec313b7ccc52fc38f920cb2a67293fec2b56c5274c90107ad3202b5ab1076597d74b5e935fa97ca70ffd7224d4b5376f4bb4b6b657cf65ac6fa5b6a99
7
+ data.tar.gz: fde98b8b4bb6e5b8fc45ec4da9df60899bdcf6d775ffe8129376de31cf8997674892862661718f5b10536347b265762dfb70219aee996d1e12faec368bccc270
@@ -222,15 +222,23 @@ class WagnGenerator < Rails::Generators::AppBase
222
222
 
223
223
  def database_gemfile_entry
224
224
  return [] if options[:skip_active_record]
225
- gem_name = gem_for_database
226
- gem_version = gem_name == 'mysql2' ? '0.3.20' : nil
227
- GemfileEntry.version gem_name, gem_version,
228
- "Use #{options[:database]} as the database for Active Record"
225
+ gem_name, gem_version = gem_for_database
226
+ if gem_name == 'mysql2'
227
+ # && Gem.loaded_specs['rails'].version < Gem::Version.new('4.2.5')
228
+ # Rails update from 4.2.4 to 4.2.5 didn't help.
229
+ # Current mysql2 gem (0.4.1) is still causing trouble.
230
+ # Maybe with the next Rails release?
231
+ # Could also be that ruby 1.9.3 is the problem.
232
+ gem_version = '0.3.20'
233
+ end
234
+ msg = "Use #{options[:database]} as the database for Active Record"
235
+ GemfileEntry.version gem_name, gem_version, msg
229
236
  end
230
237
 
231
238
  protected
239
+
232
240
  def self.banner
233
- "wagn new #{self.arguments.map(&:usage).join(' ')} [options]"
241
+ "wagn new #{arguments.map(&:usage).join(' ')} [options]"
234
242
  end
235
243
 
236
244
  def mysql_socket
@@ -10,17 +10,11 @@ class CardController < ActionController::Base
10
10
  include Card::Location
11
11
  include Recaptcha::Verify
12
12
 
13
- before_filter :per_request_setup, except: [:asset]
14
- before_filter :load_id, only: [:read]
15
- before_filter :load_card, except: [:asset]
16
- before_filter :refresh_card, only: [:create, :update, :delete, :rollback]
17
-
18
13
  layout nil
19
-
20
14
  attr_reader :card
21
15
 
22
16
  # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
23
- # CORE METHODS
17
+ # PUBLIC METHODS
24
18
 
25
19
  def create
26
20
  handle { card.save }
@@ -38,93 +32,129 @@ class CardController < ActionController::Base
38
32
  handle { card.delete }
39
33
  end
40
34
 
35
+ # DEPRECATED
41
36
  def asset
42
37
  Rails.logger.info 'Routing assets through Card. Recommend symlink from ' \
43
38
  'Deck to Card gem using "rake wagn:update_assets_symlink"'
44
39
  asset_path = Decko::Engine.paths['gem-assets'].existent.first
45
40
  filename = [params[:filename], params[:format]].join('.')
46
- send_file_inside asset_path, filename, x_sendfile: true
41
+ send_asset asset_path, filename, x_sendfile: true
47
42
  end
48
43
 
49
- private
44
+ # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
45
+ # PRIVATE METHODS
50
46
 
51
- # make sure that filename doesn't leave allowed_path using ".."
52
- def send_file_inside allowed_path, filename, options={}
53
- if filename.include? '../'
54
- raise Wagn::BadAddress
55
- else
56
- send_file File.join(allowed_path, filename), options
57
- end
58
- end
47
+ private
59
48
 
60
49
  #-------( FILTERS )
61
50
 
62
- def per_request_setup
51
+ before_filter :setup, except: [:asset]
52
+ before_filter :authenticate, except: [:asset]
53
+ before_filter :load_id, only: [:read]
54
+ before_filter :load_card, except: [:asset]
55
+ before_filter :refresh_card, only: [:create, :update, :delete, :rollback]
56
+
57
+ def setup
63
58
  request.format = :html if !params[:format] # is this used??
64
59
  Card::Cache.renew
65
60
  Card::Env.reset controller: self
66
- Card::Auth.set_current_from_session
61
+ end
67
62
 
68
- if params[:id] && !params[:id].valid_encoding?
69
- # slightly better way to handle encoding issues (than the rescue in
70
- # load_id)
71
- # we should find the place where we produce these bad urls
72
- params[:id] = params[:id].force_encoding('ISO-8859-1').encode('UTF-8')
63
+ def authenticate
64
+ if params[:token]
65
+ ok = Card::Auth.set_current_from_token params[:token], params[:current]
66
+ raise Card::Oops, 'token authentication failed' unless ok
67
+ # arguably should be PermissionDenied; that requires a card object,
68
+ # and that's not loaded yet.
69
+ else
70
+ Card::Auth.set_current_from_session
73
71
  end
74
72
  end
75
73
 
76
74
  def load_id
77
- params[:id] ||=
78
- case
79
- when Card::Auth.needs_setup? && Card::Env.html?
80
- params[:card] = { type_id: Card.default_accounted_type_id }
81
- params[:view] = 'setup'
82
- ''
83
- when params[:card] && params[:card][:name]
84
- params[:card][:name]
85
- when Card::Format.tagged(params[:view], :unknown_ok)
86
- ''
87
- else
88
- Card.setting(:home) || 'Home'
75
+ params[:id] =
76
+ case params[:id]
77
+ when '*previous' then return card_redirect(Card::Env.previous_location)
78
+ when nil then determine_id
79
+ else validate_id_encoding params[:id]
89
80
  end
90
- rescue ArgumentError # less than perfect way to handle encoding issues.
91
- raise Wagn::BadAddress
92
81
  end
93
82
 
94
83
  def load_card
95
- if params[:id] == '*previous'
96
- return card_redirect(Card::Env.previous_location)
97
- end
98
-
99
- opts = card_attr_from_params
100
- @card =
101
- if params[:action] == 'create'
102
- # FIXME: we currently need a "new" card to catch duplicates (otherwise
103
- # save will just act like a normal update)
104
- # I think we may need to create a "#create" instance method that
105
- # handles this checking.
106
- # that would let us get rid of this...
107
- Card.new opts
108
- else
109
- mark = params[:id] || opts[:name]
110
- Card.fetch mark, new: opts
111
- end
84
+ @card = new_or_fetch_card
112
85
  raise Card::NotFound unless @card
113
86
 
114
- @card.select_action_by_params params
87
+ @card.select_action_by_params params #
115
88
  Card::Env[:main_name] = params[:main] || (card && card.name) || ''
116
89
 
117
- render_errors if card.errors.any?
118
- true
90
+ card.errors.any? ? render_errors : true
119
91
  end
120
92
 
121
93
  def refresh_card
122
94
  @card = card.refresh
123
95
  end
124
96
 
125
- protected
97
+ # ----------( HELPER METHODS ) -------------
98
+
99
+ def new_or_fetch_card
100
+ opts = card_opts
101
+ if params[:action] == 'create'
102
+ # FIXME: we currently need a "new" card to catch duplicates
103
+ # (otherwise save will just act like a normal update)
104
+ # We may need a "#create" instance method to handle this checking?
105
+ Card.new opts
106
+ else
107
+ mark = params[:id] || opts[:name]
108
+ Card.fetch mark, new: opts
109
+ end
110
+ end
111
+
112
+ def card_opts
113
+ opts = (params[:card] || {}).clone
114
+ # clone so that original params remain unaltered. need deeper clone?
115
+ opts[:type] ||= params[:type] if params[:type]
116
+ # for /new/:type shortcut. we should fix and deprecate this.
117
+ opts[:name] ||= params[:id].to_s.tr('_', ' ')
118
+ # move handling to Card::Name?
119
+ opts
120
+ end
126
121
 
127
- # ----------( rendering methods ) -------------
122
+ def determine_id
123
+ case
124
+ when needs_setup?
125
+ prepare_setup_card!
126
+ when params[:card] && params[:card][:name]
127
+ params[:card][:name]
128
+ when Card::Format.tagged(params[:view], :unknown_ok)
129
+ ''
130
+ else
131
+ Card.setting(:home) || 'Home'
132
+ end
133
+ end
134
+
135
+ def needs_setup?
136
+ Card::Auth.needs_setup? && Card::Env.html?
137
+ end
138
+
139
+ def prepare_setup_card!
140
+ params[:card] = { type_id: Card.default_accounted_type_id }
141
+ params[:view] = 'setup'
142
+ ''
143
+ end
144
+
145
+ def validate_id_encoding id
146
+ # we should find the place where we produce these bad urls
147
+ id.valid_encoding? ? id : id.force_encoding('ISO-8859-1').encode('UTF-8')
148
+ end
149
+
150
+ def send_asset path, filename, options={}
151
+ if filename.include? '../'
152
+ # for security, block relative paths
153
+ raise Wagn::BadAddress
154
+ else
155
+ send_file File.join(path, filename), options
156
+ end
157
+ end
128
158
 
129
159
  def card_redirect url
130
160
  url = card_url url # make sure we have absolute url
@@ -203,7 +233,7 @@ class CardController < ActionController::Base
203
233
  case exception
204
234
  ## arguably the view and status should be defined in the error class;
205
235
  ## some are redundantly defined in view
206
- when Card::Oops, Card::Query
236
+ when Card::Oops, Card::BadQuery
207
237
  card.errors.add :exception, exception.message
208
238
  # these error messages are visible to end users and are generally not
209
239
  # treated as bugs.
@@ -242,16 +272,6 @@ class CardController < ActionController::Base
242
272
  Card::Env[:success]
243
273
  end
244
274
 
245
- def card_attr_from_params
246
- # clone so that original params remain unaltered. need deeper clone?
247
- opts = params[:card] ? params[:card].clone : {}
248
- # for /new/:type shortcut. we should fix and deprecate this.
249
- opts[:type] ||= params[:type] if params[:type]
250
- # move handling to Card::Name?
251
- opts[:name] ||= params[:id].to_s.gsub('_', ' ')
252
- opts
253
- end
254
-
255
275
  def format_from_params
256
276
  return :file if params[:explicit_file]
257
277
  format = request.parameters[:format]
@@ -264,7 +284,7 @@ class CardController < ActionController::Base
264
284
  self.params = success.params
265
285
  else
266
286
  # need tests. insure we get slot, main...
267
- self.params.merge! success.params
287
+ params.merge! success.params
268
288
  end
269
289
  end
270
290
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wagn
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.16.12
4
+ version: 1.16.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ethan McCutchen
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2015-11-11 00:00:00.000000000 Z
14
+ date: 2015-11-23 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: rails
@@ -33,14 +33,14 @@ dependencies:
33
33
  requirements:
34
34
  - - '='
35
35
  - !ruby/object:Gem::Version
36
- version: 1.16.12
36
+ version: 1.16.13
37
37
  type: :runtime
38
38
  prerelease: false
39
39
  version_requirements: !ruby/object:Gem::Requirement
40
40
  requirements:
41
41
  - - '='
42
42
  - !ruby/object:Gem::Version
43
- version: 1.16.12
43
+ version: 1.16.13
44
44
  description: a wiki approach to stuctured data, dynamic interaction, and web design
45
45
  email:
46
46
  - info@wagn.org