petergate 1.7.0 → 1.7.1
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/.gitignore +1 -0
- data/README.md +20 -11
- data/assets/logo_square.png +0 -0
- data/assets/petergate.png +0 -0
- data/lib/petergate/version.rb +1 -1
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4f39e620b25e925689c65db95d3b91d5edb8fc46
|
4
|
+
data.tar.gz: 6d3f0b8586c1f2bcacd7eeafdcede60b1a62c4eb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5a0dd02c94ab67329d32a58f3db266a4e0c0991df2593a65108ea703db4f43b7727c03b76ba75f8262de03b25513a4bb668edd5efe6486ffbe542d340c935aae
|
7
|
+
data.tar.gz: d04924e4dbfb248e6ef7027571cbd023c5f64529462b6eeb5f81c4bdb9025ad19831af161a036360900b360277a5adbd221cde7d4cf6eb00e79197cd470c181b
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -12,7 +12,7 @@
|
|
12
12
|
|
13
13
|
Installation
|
14
14
|
------
|
15
|
-
#####Get the gem
|
15
|
+
##### Get the gem
|
16
16
|
Add this line to your application's Gemfile:
|
17
17
|
|
18
18
|
gem 'petergate'
|
@@ -24,7 +24,8 @@ And then execute:
|
|
24
24
|
Or install it yourself as:
|
25
25
|
|
26
26
|
gem install petergate
|
27
|
-
|
27
|
+
|
28
|
+
##### Prerequisites: Setup Authentication (Devise)
|
28
29
|
|
29
30
|
Make sure your user model is defined in
|
30
31
|
app/models/user.rb
|
@@ -37,16 +38,16 @@ If you're using [devise](https://github.com/plataformatec/devise) you're in luck
|
|
37
38
|
after_sign_in_path_for(current_user)
|
38
39
|
authenticate_user!
|
39
40
|
|
40
|
-
#####Run the generators
|
41
|
+
##### Run the generators
|
41
42
|
|
42
43
|
rails g petergate:install
|
43
44
|
rake db:migrate
|
44
|
-
|
45
|
-
This will add a migration and insert petergate into your User model.
|
46
|
-
|
45
|
+
|
46
|
+
This will add a migration and insert petergate into your User model.
|
47
|
+
|
47
48
|
Usage
|
48
49
|
------
|
49
|
-
####User Model
|
50
|
+
#### User Model
|
50
51
|
|
51
52
|
Configure available roles by modifying this block at the top of your user.rb.
|
52
53
|
|
@@ -57,7 +58,7 @@ Configure available roles by modifying this block at the top of your user.rb.
|
|
57
58
|
## The :root_admin can access any page regardless of access settings. Use with caution! ##
|
58
59
|
## The multiple option can be set to true if you need users to have multiple roles. ##
|
59
60
|
petergate(roles: [:admin, :editor], multiple: false) ##
|
60
|
-
############################################################################################
|
61
|
+
############################################################################################
|
61
62
|
```
|
62
63
|
|
63
64
|
##### Instance Methods
|
@@ -71,10 +72,10 @@ user.has_roles?(:admin, :editors) # returns true if user is any of roles passed
|
|
71
72
|
```
|
72
73
|
##### Class Methods
|
73
74
|
|
74
|
-
`User
|
75
|
+
`User.#{role}_editors => #list of editors. Method is created for all roles. Roles [admin, :teacher] will have corresponding methods role_admins, role_teachers, etc.`
|
76
|
+
|
77
|
+
#### Controllers
|
75
78
|
|
76
|
-
####Controllers
|
77
|
-
|
78
79
|
Setup permissions in your controllers the same as you would for a before filter like so:
|
79
80
|
|
80
81
|
```ruby
|
@@ -103,7 +104,15 @@ def roles=(v)
|
|
103
104
|
self[:roles] = v.map(&:to_sym).to_a.select{|r| r.size > 0 && ROLES.include?(r)}
|
104
105
|
end
|
105
106
|
```
|
107
|
+
If you need to deny access you can use the forbidden! method:
|
106
108
|
|
109
|
+
```ruby
|
110
|
+
before_action :check_active_user
|
111
|
+
|
112
|
+
def check_active_user
|
113
|
+
forbidden! unless current_user.active
|
114
|
+
end
|
115
|
+
```
|
107
116
|
If you want to change the `permission denied` message you can add to the access line:
|
108
117
|
|
109
118
|
```ruby
|
Binary file
|
Binary file
|
data/lib/petergate/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: petergate
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.7.
|
4
|
+
version: 1.7.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Isaac Sloan
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-04-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -67,6 +67,8 @@ files:
|
|
67
67
|
- LICENSE.txt
|
68
68
|
- README.md
|
69
69
|
- Rakefile
|
70
|
+
- assets/logo_square.png
|
71
|
+
- assets/petergate.png
|
70
72
|
- lib/generators/petergate/install_generator.rb
|
71
73
|
- lib/generators/petergate/templates/migrations/add_roles_to_users.rb
|
72
74
|
- lib/petergate.rb
|
@@ -97,7 +99,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
97
99
|
version: '0'
|
98
100
|
requirements: []
|
99
101
|
rubyforge_project:
|
100
|
-
rubygems_version: 2.
|
102
|
+
rubygems_version: 2.5.1
|
101
103
|
signing_key:
|
102
104
|
specification_version: 4
|
103
105
|
summary: Authorization system allowing verbose easy read controller syntax.
|