rails_apps_pages 0.5.5 → 0.5.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.textile +4 -0
- data/lib/generators/pages/authorized/authorized_generator.rb +15 -6
- data/lib/generators/pages/authorized/templates/{user_policy.rb → devise/user_policy.rb} +0 -0
- data/lib/generators/pages/authorized/templates/{users_controller.rb → devise/users_controller.rb} +0 -0
- data/lib/generators/pages/authorized/templates/omniauth/user_policy.rb +17 -0
- data/lib/generators/pages/authorized/templates/omniauth/users_controller.rb +34 -0
- data/lib/generators/pages/authorized/templates/pundit.rb +22 -0
- data/lib/rails_apps_pages/version.rb +1 -1
- metadata +6 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2666de6172f8535a6a2f744f46aaec5efa3300e8
|
4
|
+
data.tar.gz: ff175f2895625425321ae15cf3147c9071eeb650
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d00e4ea4ef71c36ea4599f7855384ce1d833964fd93a804a76f8d4eba02e200853d6b61ceeb7111574404ba0b9c06b4bfb3b8565c1a7b523989a942ba93898bb
|
7
|
+
data.tar.gz: c24152b386a11a645d580e9c1875efbeeb1d0513f1f6fb2b75781647700ecefb8343e8d9072fbd4944f2da20d6f82dd98ff2859623ac40e6b386bf0324767078
|
data/CHANGELOG.textile
CHANGED
@@ -5,14 +5,23 @@ module Pages
|
|
5
5
|
class AuthorizedGenerator < ::Rails::Generators::Base
|
6
6
|
source_root File.expand_path("../templates", __FILE__)
|
7
7
|
|
8
|
-
desc "
|
8
|
+
desc "Add Pundit for authorization. A User model with roles must be available."
|
9
9
|
|
10
|
-
def
|
11
|
-
|
12
|
-
### assumes we are using Pundit for authorization
|
10
|
+
def add_pundit
|
11
|
+
copy_file 'pundit.rb', 'config/initializers/pundit.rb'
|
13
12
|
copy_file 'users/_user.html.erb', 'app/views/users/_user.html.erb'
|
14
|
-
|
15
|
-
|
13
|
+
end
|
14
|
+
|
15
|
+
def add_if_devise
|
16
|
+
return unless File.exists?('config/initializers/devise.rb')
|
17
|
+
copy_file 'devise/users_controller.rb', 'app/controllers/users_controller.rb'
|
18
|
+
copy_file 'devise/user_policy.rb', 'app/policies/user_policy.rb'
|
19
|
+
end
|
20
|
+
|
21
|
+
def add_if_omniauth
|
22
|
+
return unless File.exists?('config/initializers/omniauth.rb')
|
23
|
+
copy_file 'omniauth/users_controller.rb', 'app/controllers/users_controller.rb'
|
24
|
+
copy_file 'omniauth/user_policy.rb', 'app/policies/user_policy.rb'
|
16
25
|
end
|
17
26
|
|
18
27
|
end
|
File without changes
|
data/lib/generators/pages/authorized/templates/{users_controller.rb → devise/users_controller.rb}
RENAMED
File without changes
|
@@ -0,0 +1,17 @@
|
|
1
|
+
class UserPolicy
|
2
|
+
attr_reader :current_user, :model
|
3
|
+
|
4
|
+
def initialize(current_user, model)
|
5
|
+
@current_user = current_user
|
6
|
+
@user = model
|
7
|
+
end
|
8
|
+
|
9
|
+
def index?
|
10
|
+
@current_user.admin?
|
11
|
+
end
|
12
|
+
|
13
|
+
def show?
|
14
|
+
@current_user.admin? or @current_user == @user
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
class UsersController < ApplicationController
|
2
|
+
before_filter :authenticate_user!
|
3
|
+
before_filter :correct_user?, :except => [:index]
|
4
|
+
|
5
|
+
def index
|
6
|
+
@users = User.all
|
7
|
+
authorize User
|
8
|
+
end
|
9
|
+
|
10
|
+
def edit
|
11
|
+
@user = User.find(params[:id])
|
12
|
+
end
|
13
|
+
|
14
|
+
def update
|
15
|
+
@user = User.find(params[:id])
|
16
|
+
if @user.update_attributes(secure_params)
|
17
|
+
redirect_to @user
|
18
|
+
else
|
19
|
+
render :edit
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def show
|
24
|
+
@user = User.find(params[:id])
|
25
|
+
authorize @user
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def secure_params
|
31
|
+
params.require(:user).permit(:email)
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# config/initializers/pundit.rb
|
2
|
+
# Extends the ApplicationController to add Pundit for authorization.
|
3
|
+
# Modify this file to change the behavior of a 'not authorized' error.
|
4
|
+
# Be sure to restart your server when you modify this file.
|
5
|
+
module PunditHelper
|
6
|
+
extend ActiveSupport::Concern
|
7
|
+
|
8
|
+
included do
|
9
|
+
include Pundit
|
10
|
+
rescue_from Pundit::NotAuthorizedError, with: :user_not_authorized
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
def user_not_authorized
|
16
|
+
flash[:alert] = "Access denied."
|
17
|
+
redirect_to (request.referrer || root_path)
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
|
22
|
+
ApplicationController.send :include, PunditHelper
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails_apps_pages
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Kehoe
|
@@ -60,9 +60,12 @@ files:
|
|
60
60
|
- lib/generators/pages/about/templates/about.html.erb
|
61
61
|
- lib/generators/pages/about/templates/about_page_spec.rb
|
62
62
|
- lib/generators/pages/authorized/authorized_generator.rb
|
63
|
-
- lib/generators/pages/authorized/templates/user_policy.rb
|
63
|
+
- lib/generators/pages/authorized/templates/devise/user_policy.rb
|
64
|
+
- lib/generators/pages/authorized/templates/devise/users_controller.rb
|
65
|
+
- lib/generators/pages/authorized/templates/omniauth/user_policy.rb
|
66
|
+
- lib/generators/pages/authorized/templates/omniauth/users_controller.rb
|
67
|
+
- lib/generators/pages/authorized/templates/pundit.rb
|
64
68
|
- lib/generators/pages/authorized/templates/users/_user.html.erb
|
65
|
-
- lib/generators/pages/authorized/templates/users_controller.rb
|
66
69
|
- lib/generators/pages/home/home_generator.rb
|
67
70
|
- lib/generators/pages/home/templates/home_page_spec.rb
|
68
71
|
- lib/generators/pages/home/templates/index.html.erb
|