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 +4 -4
- data/lib/secure_link/authorize.rb +19 -17
- data/lib/secure_link/button.rb +13 -11
- data/lib/secure_link/link.rb +13 -11
- data/lib/secure_link/version.rb +1 -1
- data/secure_link.gemspec +2 -2
- data/spec/rails_helper.rb +4 -0
- data/spec/secure_link/authorize_spec.rb +3 -3
- data/spec/secure_link/button_spec.rb +9 -0
- data/spec/secure_link/link_spec.rb +9 -0
- metadata +17 -5
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA1:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 8db0bfdfa0ed64c4dc951e99e053fa414fdbc8de
         | 
| 4 | 
            +
              data.tar.gz: fcf03d04a133623f9b5a2abcbf104754ffaa450d
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: ecb25a10a122ea0fec96a9c975e4fbc1ae0a9eaab5a898f21164b29e1ee946083d44de591e34d587ed732c7391085b0ec28cd4d51412a011dd8cd3fa51b66923
         | 
| 7 | 
            +
              data.tar.gz: 73011c3ceada44c59e937eadc489ba32776077f6cc9a127e68879e120c64ca2d4db7ecf023a47cf4ef4c5ed53d350e7c03d007b0448c3b4dce10a4932b25a318
         | 
| @@ -1,25 +1,27 @@ | |
| 1 | 
            -
            module SecureLink | 
| 2 | 
            -
               | 
| 3 | 
            -
                 | 
| 1 | 
            +
            module SecureLink
         | 
| 2 | 
            +
              class Authorize
         | 
| 3 | 
            +
                def authorized?(url, method = nil)
         | 
| 4 | 
            +
                  return false unless url
         | 
| 4 5 |  | 
| 5 | 
            -
             | 
| 6 | 
            -
             | 
| 6 | 
            +
                  # Mailto link
         | 
| 7 | 
            +
                  return true if url =~ /^mailto:/
         | 
| 7 8 |  | 
| 8 | 
            -
             | 
| 9 | 
            -
             | 
| 10 | 
            -
             | 
| 11 | 
            -
             | 
| 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 | 
            -
             | 
| 14 | 
            -
             | 
| 15 | 
            -
             | 
| 16 | 
            -
             | 
| 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 | 
            -
             | 
| 22 | 
            -
             | 
| 23 | 
            -
             | 
| 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
         | 
    
        data/lib/secure_link/button.rb
    CHANGED
    
    | @@ -1,18 +1,20 @@ | |
| 1 1 | 
             
            module SecureLink
         | 
| 2 | 
            -
               | 
| 3 | 
            -
                 | 
| 4 | 
            -
             | 
| 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 | 
            -
             | 
| 7 | 
            -
             | 
| 8 | 
            -
             | 
| 7 | 
            +
                  unless ENV["RAILS_RELATIVE_URL_ROOT"].blank?
         | 
| 8 | 
            +
                    check_url = check_url.gsub(ENV["RAILS_RELATIVE_URL_ROOT"], "")
         | 
| 9 | 
            +
                  end
         | 
| 9 10 |  | 
| 10 | 
            -
             | 
| 11 | 
            +
                  method = html_options ? html_options[:method] : nil
         | 
| 11 12 |  | 
| 12 | 
            -
             | 
| 13 | 
            -
             | 
| 14 | 
            -
             | 
| 13 | 
            +
                  if authorized?(check_url, method)
         | 
| 14 | 
            +
                    return button_to_open(name, url, html_options)
         | 
| 15 | 
            +
                  end
         | 
| 15 16 |  | 
| 16 | 
            -
             | 
| 17 | 
            +
                  return ""
         | 
| 18 | 
            +
                end
         | 
| 17 19 | 
             
              end
         | 
| 18 20 | 
             
            end
         | 
    
        data/lib/secure_link/link.rb
    CHANGED
    
    | @@ -1,18 +1,20 @@ | |
| 1 1 | 
             
            module SecureLink
         | 
| 2 | 
            -
               | 
| 3 | 
            -
                 | 
| 4 | 
            -
             | 
| 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 | 
            -
             | 
| 7 | 
            -
             | 
| 8 | 
            -
             | 
| 7 | 
            +
                  unless ENV["RAILS_RELATIVE_URL_ROOT"].blank?
         | 
| 8 | 
            +
                    check_url = check_url.gsub(ENV["RAILS_RELATIVE_URL_ROOT"], "")
         | 
| 9 | 
            +
                  end
         | 
| 9 10 |  | 
| 10 | 
            -
             | 
| 11 | 
            +
                  method = html_options ? html_options[:method] : nil
         | 
| 11 12 |  | 
| 12 | 
            -
             | 
| 13 | 
            -
             | 
| 14 | 
            -
             | 
| 13 | 
            +
                  if authorized?(check_url, method)
         | 
| 14 | 
            +
                    return link_to_open(name, url, html_options)
         | 
| 15 | 
            +
                  end
         | 
| 15 16 |  | 
| 16 | 
            -
             | 
| 17 | 
            +
                  return ""
         | 
| 18 | 
            +
                end
         | 
| 17 19 | 
             
              end
         | 
| 18 20 | 
             
            end
         | 
    
        data/lib/secure_link/version.rb
    CHANGED
    
    
    
        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{^ | 
| 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
         | 
    
        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. | 
| 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: []
         |