moxify 0.1.7.2 → 0.1.7.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.
@@ -1,5 +1,7 @@
1
- ::Refinery::Application.routes.draw do
2
- match '/refinery(/*path)', :to => redirect {|params, request|
3
- "/admin#{"/#{params[:path]}" unless params[:path].blank?}"
4
- }
1
+ if RefinerySetting.find_or_set(:rewrite_refinery_paths, true)
2
+ ::Refinery::Application.routes.draw do
3
+ match '/refinery(/*path)', :to => redirect {|params, request|
4
+ "/#{RefinerySetting.find_or_set(:rewrite_refinery_paths_to, "admin")}#{"/#{params[:path]}" unless params[:path].blank?}"
5
+ }
6
+ end
5
7
  end
@@ -32,16 +32,18 @@ module Moxify
32
32
  Rails.application.routes.routes.each do |route|
33
33
  match = false
34
34
 
35
- if route.path =~ /refinery/ and
35
+ if RefinerySetting.find_or_set(:rewrite_refinery_paths, true) and
36
+ route.path =~ /refinery/ and
36
37
  not route.path =~ /^\/refinery\(\/\*path\)/ # this is our catch all route
37
38
 
38
- route.instance_variable_set "@path", route.path.gsub(/refinery/, "admin")
39
+ route.instance_variable_set "@path", route.path.gsub(/refinery/, RefinerySetting.find_or_set(:rewrite_refinery_paths_to, "admin"))
39
40
  match = true
40
41
 
41
- elsif route.path =~ /^\/users/ and
42
+ elsif RefinerySetting.find_or_set(:rewrite_user_paths, true) and
43
+ route.path =~ /^\/users/ and
42
44
  route.name =~ /user\_/
43
45
 
44
- route.instance_variable_set "@path", route.path.gsub(/users/, "admin")
46
+ route.instance_variable_set "@path", route.path.gsub(/users/, RefinerySetting.find_or_set(:rewrite_user_paths_to, "admin"))
45
47
  match = true
46
48
 
47
49
  end
@@ -76,4 +78,4 @@ module Moxify
76
78
 
77
79
  end
78
80
 
79
- end
81
+ end
@@ -1,19 +1,48 @@
1
1
  module Moxify
2
+ require 'mime/types'
3
+ require 'openssl'
4
+ require 'open-uri'
5
+
2
6
  class URLTempfile < Tempfile
7
+ attr :content_type
3
8
 
4
9
  def initialize(url)
5
10
  @url = URI.parse(url)
6
11
 
12
+ # see if we can get a filename
13
+ raise "Unable to determine filename for URL uploaded file." unless original_filename
14
+
7
15
  begin
8
- super('url', Dir.tmpdir, :encoding => 'ascii-8bit')
16
+ # HACK to get around inability to set VERIFY_NONE with open-uri
17
+ old_verify_peer_value = OpenSSL::SSL::VERIFY_PEER
18
+ openssl_verify_peer = OpenSSL::SSL::VERIFY_NONE
9
19
 
10
- Net::HTTP.start(@url.host) do |http|
11
- resp = http.get(@url.path)
12
- self.write resp.body
20
+ super('urlupload', Dir.tmpdir, :encoding => 'ascii-8bit')
21
+ Kernel.open(url) do |file|
22
+ @content_type = file.content_type
23
+ raise "Unable to determine MIME type for URL uploaded file." unless content_type
24
+
25
+ self.write file.read
26
+ self.flush
13
27
  end
14
28
  ensure
29
+ openssl_verify_peer = old_verify_peer_value
15
30
  end
16
31
  end
17
32
 
33
+ def original_filename
34
+ # Take the URI path and strip off everything after last slash, assume this
35
+ # to be filename (URI path already removes any query string)
36
+ match = @url.path.match(/^.*\/(.+)$/)
37
+ return (match ? match[1] : nil)
38
+ end
39
+
40
+ protected
41
+
42
+ def openssl_verify_peer=(value)
43
+ silence_warnings do
44
+ OpenSSL::SSL.const_set("VERIFY_PEER", value)
45
+ end
46
+ end
18
47
  end
19
48
  end
@@ -1,3 +1,3 @@
1
1
  module Moxify
2
- VERSION = "0.1.7.2"
2
+ VERSION = "0.1.7.3"
3
3
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: moxify
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.1.7.2
5
+ version: 0.1.7.3
6
6
  platform: ruby
7
7
  authors:
8
8
  - Marian Andre
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-05-02 00:00:00 +02:00
13
+ date: 2011-05-09 00:00:00 +02:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency