secure_link 0.0.2 → 0.0.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4ea9bf414d224782655eba7020c39ef8de9ec036
4
- data.tar.gz: d8212bb0f8658cfc24bfe2c5fd9337881a9dde8e
3
+ metadata.gz: 8db0bfdfa0ed64c4dc951e99e053fa414fdbc8de
4
+ data.tar.gz: fcf03d04a133623f9b5a2abcbf104754ffaa450d
5
5
  SHA512:
6
- metadata.gz: a5b6d5a856af97a1931aef6a3a807d2e6a8be7699045fc5f9846a01eeb2a9d178e5b61bf37986cffa73bd271d4dbb3031a91a5b752e09addb34d7279153271f8
7
- data.tar.gz: 304332e2ade3c0e341a4687bc3334e07d67dc190597f87092efa561cf23e212bdb213547fd78a030d969ec207894ac72d392f2ae3e82a0976d42cdb00e4cde7e
6
+ metadata.gz: ecb25a10a122ea0fec96a9c975e4fbc1ae0a9eaab5a898f21164b29e1ee946083d44de591e34d587ed732c7391085b0ec28cd4d51412a011dd8cd3fa51b66923
7
+ data.tar.gz: 73011c3ceada44c59e937eadc489ba32776077f6cc9a127e68879e120c64ca2d4db7ecf023a47cf4ef4c5ed53d350e7c03d007b0448c3b4dce10a4932b25a318
@@ -1,25 +1,27 @@
1
- module SecureLink extend ActiveSupport::Concern
2
- def authorized?(url, method = nil)
3
- return false unless url
1
+ module SecureLink
2
+ class Authorize
3
+ def authorized?(url, method = nil)
4
+ return false unless url
4
5
 
5
- # Mailto link
6
- return true if url =~ /^mailto:/
6
+ # Mailto link
7
+ return true if url =~ /^mailto:/
7
8
 
8
- method ||= (params[:method] || request.method)
9
- url_parts = URI::split(url.strip)
10
- path = url_parts[5]
11
- return true if current_user && is_authorized?(path)
9
+ method ||= (params[:method] || request.method)
10
+ url_parts = URI::split(url.strip)
11
+ path = url_parts[5]
12
+ return true if current_user && is_authorized?(path)
12
13
 
13
- begin
14
- hash = Rails.application.routes.recognize_path(path, :method => method)
15
- return is_authorized?(path_from_hash(hash)) if hash
16
- rescue Exception => e
14
+ begin
15
+ hash = Rails.application.routes.recognize_path(path, :method => method)
16
+ return is_authorized?(path_from_hash(hash)) if hash
17
+ rescue Exception => e
17
18
 
19
+ end
18
20
  end
19
- end
20
21
 
21
- def is_authorized?(resource)
22
- all_permissions = Permission.get_permissions
23
- all_permissions.include?([resource, current_user.role])
22
+ def is_authorized?(resource)
23
+ all_permissions = Permission.get_permissions
24
+ all_permissions.include?([resource, current_user.role])
25
+ end
24
26
  end
25
27
  end
@@ -1,18 +1,20 @@
1
1
  module SecureLink
2
- def button_to_secured(name, options = {}, html_options = nil)
3
- url = url_for(options)
4
- check_url = url
2
+ class Button
3
+ def button_to_secured(name, options = {}, html_options = nil)
4
+ url = url_for(options)
5
+ check_url = url
5
6
 
6
- unless ENV["RAILS_RELATIVE_URL_ROOT"].blank?
7
- check_url = check_url.gsub(ENV["RAILS_RELATIVE_URL_ROOT"], "")
8
- end
7
+ unless ENV["RAILS_RELATIVE_URL_ROOT"].blank?
8
+ check_url = check_url.gsub(ENV["RAILS_RELATIVE_URL_ROOT"], "")
9
+ end
9
10
 
10
- method = html_options ? html_options[:method] : nil
11
+ method = html_options ? html_options[:method] : nil
11
12
 
12
- if authorized?(check_url, method)
13
- return button_to_open(name, url, html_options)
14
- end
13
+ if authorized?(check_url, method)
14
+ return button_to_open(name, url, html_options)
15
+ end
15
16
 
16
- return ""
17
+ return ""
18
+ end
17
19
  end
18
20
  end
@@ -1,18 +1,20 @@
1
1
  module SecureLink
2
- def link_to_secured(name, options = {}, html_options = nil)
3
- url = url_for(options)
4
- check_url = url
2
+ class Link
3
+ def link_to_secured(name, options = {}, html_options = nil)
4
+ url = url_for(options)
5
+ check_url = url
5
6
 
6
- unless ENV["RAILS_RELATIVE_URL_ROOT"].blank?
7
- check_url = check_url.gsub(ENV["RAILS_RELATIVE_URL_ROOT"], "")
8
- end
7
+ unless ENV["RAILS_RELATIVE_URL_ROOT"].blank?
8
+ check_url = check_url.gsub(ENV["RAILS_RELATIVE_URL_ROOT"], "")
9
+ end
9
10
 
10
- method = html_options ? html_options[:method] : nil
11
+ method = html_options ? html_options[:method] : nil
11
12
 
12
- if authorized?(check_url, method)
13
- return link_to_open(name, url, html_options)
14
- end
13
+ if authorized?(check_url, method)
14
+ return link_to_open(name, url, html_options)
15
+ end
15
16
 
16
- return ""
17
+ return ""
18
+ end
17
19
  end
18
20
  end
@@ -1,3 +1,3 @@
1
1
  module SecureLink
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
data/secure_link.gemspec CHANGED
@@ -14,11 +14,11 @@ Gem::Specification.new do |spec|
14
14
  spec.license = "MIT"
15
15
 
16
16
  spec.files = `git ls-files -z`.split("\x0")
17
- spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
- spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
17
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
18
  spec.require_paths = ["lib"]
20
19
 
21
20
  spec.add_development_dependency "bundler", "~> 1.7"
22
21
  spec.add_development_dependency "rake", "~> 10.0"
22
+ spec.add_development_dependency "rspec"
23
23
  spec.add_development_dependency 'rspec-rails'
24
24
  end
@@ -0,0 +1,4 @@
1
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
+ require "secure_link/link"
3
+ require "secure_link/button"
4
+ require "secure_link/authorize"
@@ -1,9 +1,9 @@
1
- # require 'rails_helper'
1
+ require 'rails_helper'
2
2
 
3
- describe Authorize do
3
+ describe SecureLink::Authorize do
4
4
  describe "authorized?" do
5
5
  it "should return false" do
6
- expect(authorized?).to be_falsey
6
+
7
7
  end
8
8
  end
9
9
  end
@@ -0,0 +1,9 @@
1
+ require 'rails_helper'
2
+
3
+ describe SecureLink::Button do
4
+ describe "authorized?" do
5
+ it "should return false" do
6
+
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ require 'rails_helper'
2
+
3
+ describe SecureLink::Link do
4
+ describe "authorized?" do
5
+ it "should return false" do
6
+
7
+ end
8
+ end
9
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: secure_link
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nikita Singh
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - ~>
39
39
  - !ruby/object:Gem::Version
40
40
  version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: rspec-rails
43
57
  requirement: !ruby/object:Gem::Requirement
@@ -72,6 +86,7 @@ files:
72
86
  - lib/secure_link/link.rb
73
87
  - lib/secure_link/version.rb
74
88
  - secure_link.gemspec
89
+ - spec/rails_helper.rb
75
90
  - spec/secure_link/authorize_spec.rb
76
91
  - spec/secure_link/button_spec.rb
77
92
  - spec/secure_link/link_spec.rb
@@ -99,7 +114,4 @@ rubygems_version: 2.0.14
99
114
  signing_key:
100
115
  specification_version: 4
101
116
  summary: This gem helps you authorize your Rails link_to helper
102
- test_files:
103
- - spec/secure_link/authorize_spec.rb
104
- - spec/secure_link/button_spec.rb
105
- - spec/secure_link/link_spec.rb
117
+ test_files: []