petergate 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +15 -0
- data/Gemfile +5 -0
- data/LICENSE.txt +22 -0
- data/README.md +31 -0
- data/Rakefile +2 -0
- data/lib/generators/petergate/install_generator.rb +61 -0
- data/lib/generators/petergate/templates/migrations/add_roles_to_users.rb +5 -0
- data/lib/petergate.rb +77 -0
- data/lib/petergate/railtie.rb +10 -0
- data/lib/petergate/version.rb +3 -0
- data/petergate.gemspec +23 -0
- metadata +83 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: be58e156f3920e261b34442492fdda122eba8ae7
|
4
|
+
data.tar.gz: b1a9bc1e1bd3351dc2dfda0fb922f3132335046d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 09489a0a78eb4965edfa6d8850be9a12e209a9d0eeb6dc3e99f93b37535fa02da19cc10cfc99a64a76ae6ad4d25565db67c1133a335ee19f0d3a4583a48072ca
|
7
|
+
data.tar.gz: c968e0e974f0ec017c5855008ec9d749f0f9ba3266346eef01d3de7904c8fa43e4c3bec4aa5373beef7f94ff531c5486998c5cc61ad817aa3ede2fef27216a0c
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Isaac Sloan
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# Petergate
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'petergate'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install petergate
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
TODO: Write usage instructions here
|
24
|
+
|
25
|
+
## Contributing
|
26
|
+
|
27
|
+
1. Fork it ( https://github.com/[my-github-username]/petergate/fork )
|
28
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
29
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
30
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
31
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
require 'securerandom'
|
2
|
+
|
3
|
+
module Petergate
|
4
|
+
module Generators
|
5
|
+
class InstallGenerator < Rails::Generators::Base
|
6
|
+
include Rails::Generators::Migration
|
7
|
+
source_root File.expand_path("../templates", __FILE__)
|
8
|
+
class_option :orm
|
9
|
+
|
10
|
+
desc "Sets up rails project for Petergate Authorizations"
|
11
|
+
def self.next_migration_number(path)
|
12
|
+
sleep 1
|
13
|
+
Time.now.utc.strftime("%Y%m%d%H%M%S")
|
14
|
+
end
|
15
|
+
|
16
|
+
def insert_into_user_model
|
17
|
+
inject_into_file "app/models/user.rb", after: /^\s{2,}devise[^\n]+\n[^\n]+\n/ do
|
18
|
+
<<-'RUBY'
|
19
|
+
|
20
|
+
################################################################################
|
21
|
+
## PeterGate Roles
|
22
|
+
################################################################################
|
23
|
+
|
24
|
+
serialize :roles
|
25
|
+
|
26
|
+
# The :user role is added by default and shouldn't be included in this list.
|
27
|
+
Roles = [:admin]
|
28
|
+
|
29
|
+
after_initialize do
|
30
|
+
self[:roles] = []
|
31
|
+
end
|
32
|
+
|
33
|
+
def roles=(v)
|
34
|
+
self[:roles] = v.map(&:to_sym).to_a.select{|r| r.size > 0 && Roles.include?(r)}
|
35
|
+
end
|
36
|
+
|
37
|
+
def roles
|
38
|
+
self[:roles] + [:user]
|
39
|
+
end
|
40
|
+
|
41
|
+
def role
|
42
|
+
roles.first
|
43
|
+
end
|
44
|
+
|
45
|
+
################################################################################
|
46
|
+
## End PeterGate Roles
|
47
|
+
################################################################################
|
48
|
+
|
49
|
+
RUBY
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def create_migrations
|
54
|
+
Dir["#{self.class.source_root}/migrations/*.rb"].sort.each do |filepath|
|
55
|
+
name = File.basename(filepath)
|
56
|
+
migration_template "migrations/#{name}", "db/migrate/#{name}"
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
data/lib/petergate.rb
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
require "petergate/version"
|
2
|
+
require 'petergate/railtie' if defined?(Rails)
|
3
|
+
|
4
|
+
module Petergate
|
5
|
+
module ControllerMethods
|
6
|
+
AllRest = [:show, :index, :new, :edit, :update, :create, :destroy]
|
7
|
+
|
8
|
+
################################################################################
|
9
|
+
# Start Permissions
|
10
|
+
################################################################################
|
11
|
+
def self.included(base)
|
12
|
+
base.before_filter do
|
13
|
+
unless logged_in?(:admin)
|
14
|
+
message= access
|
15
|
+
if message.is_a?(String) || message == false
|
16
|
+
if user_signed_in?
|
17
|
+
redirect_to (request.referrer || after_sign_in_path_for(current_user)), :notice => message || "Permission Denied"
|
18
|
+
else
|
19
|
+
authenticate_user!
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def access
|
27
|
+
permissions
|
28
|
+
end
|
29
|
+
|
30
|
+
def permissions(rules = {all: [:index, :show], customer: [], wiring: []})
|
31
|
+
# Allows Array's of keys for he same hash.
|
32
|
+
rules = rules.inject({}){|h, (k, v)| k.class == Array ? h.merge(Hash[k.map{|kk| [kk, v]}]) : h.merge(k => v) }
|
33
|
+
case params[:action].to_sym
|
34
|
+
when *(rules[:all]) # checks where the action can be seen by :all
|
35
|
+
true
|
36
|
+
when *(rules[:user]) # checks if the action can be seen for all users
|
37
|
+
user_signed_in?
|
38
|
+
when *(rules[(user_signed_in? ? current_user.role.to_sym : :all)]) # checks if action can be seen by the current_users role. If the user isn't logged in check if it can be seen by :all
|
39
|
+
true
|
40
|
+
else
|
41
|
+
false
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
alias_method :perms, :permissions
|
46
|
+
|
47
|
+
def logged_in?(*roles)
|
48
|
+
current_user && (roles & current_user.roles).any?
|
49
|
+
end
|
50
|
+
|
51
|
+
################################################################################
|
52
|
+
# End Permissions
|
53
|
+
################################################################################
|
54
|
+
end
|
55
|
+
|
56
|
+
module User
|
57
|
+
serialize :roles
|
58
|
+
|
59
|
+
Roles = [:company, :service, :admin, :weak_admin]
|
60
|
+
|
61
|
+
after_initialize do
|
62
|
+
self[:roles] = []
|
63
|
+
end
|
64
|
+
|
65
|
+
def roles=(v)
|
66
|
+
self[:roles] = v.map(&:to_sym).to_a.select{|r| r.size > 0 && Roles.include?(r)}
|
67
|
+
end
|
68
|
+
|
69
|
+
def roles
|
70
|
+
self[:roles] + [:user]
|
71
|
+
end
|
72
|
+
|
73
|
+
def role
|
74
|
+
roles.first
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
# require 'petergate/view_helpers'
|
2
|
+
module Petergate
|
3
|
+
class Railtie < Rails::Railtie
|
4
|
+
initializer "petergate.libs" do
|
5
|
+
ActiveSupport.on_load(:action_controller) do
|
6
|
+
ActionController::Base.send(:include, Petergate::ControllerMethods)
|
7
|
+
end
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
data/petergate.gemspec
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'petergate/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "petergate"
|
8
|
+
spec.version = Petergate::VERSION
|
9
|
+
spec.authors = ["Isaac Sloan"]
|
10
|
+
spec.email = ["isaac@isaacsloan.com"]
|
11
|
+
spec.summary = %q{Authorization system allowing verbose easy read controller syntax.}
|
12
|
+
spec.description = %q{Authorization system.}
|
13
|
+
spec.homepage = "http://RingSeven.com"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
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)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.7"
|
22
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
23
|
+
end
|
metadata
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: petergate
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Isaac Sloan
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-11-11 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.7'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.7'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
description: Authorization system.
|
42
|
+
email:
|
43
|
+
- isaac@isaacsloan.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- ".gitignore"
|
49
|
+
- Gemfile
|
50
|
+
- LICENSE.txt
|
51
|
+
- README.md
|
52
|
+
- Rakefile
|
53
|
+
- lib/generators/petergate/install_generator.rb
|
54
|
+
- lib/generators/petergate/templates/migrations/add_roles_to_users.rb
|
55
|
+
- lib/petergate.rb
|
56
|
+
- lib/petergate/railtie.rb
|
57
|
+
- lib/petergate/version.rb
|
58
|
+
- petergate.gemspec
|
59
|
+
homepage: http://RingSeven.com
|
60
|
+
licenses:
|
61
|
+
- MIT
|
62
|
+
metadata: {}
|
63
|
+
post_install_message:
|
64
|
+
rdoc_options: []
|
65
|
+
require_paths:
|
66
|
+
- lib
|
67
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
68
|
+
requirements:
|
69
|
+
- - ">="
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: '0'
|
72
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - ">="
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
requirements: []
|
78
|
+
rubyforge_project:
|
79
|
+
rubygems_version: 2.2.2
|
80
|
+
signing_key:
|
81
|
+
specification_version: 4
|
82
|
+
summary: Authorization system allowing verbose easy read controller syntax.
|
83
|
+
test_files: []
|