rails_apps_pages 0.5.12 → 0.5.13

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d789cbafd132c18ea34015bc4148bdf4e421d33f
4
- data.tar.gz: ea1f04306ec17c6c7a9488d2c48e90a2366c8326
3
+ metadata.gz: 1a6bcd591d8fe575d8a0c3dc2ebea666aab98fcc
4
+ data.tar.gz: 558cef9f9c54be2a00ffee11aa2d8ae0155d6b86
5
5
  SHA512:
6
- metadata.gz: 98ae23aa407cf2ebdd555ba0480c24c27ee2e6bda6377491ae72e9086c46bfe030e6bb783b79e3edcd7e6903b8fd767655a72c7e9b70a4d282a5f106e5c799fc
7
- data.tar.gz: 252357af333a27e34ec50e0994ce5ebd9e3522c7c37dc2a1de4fb068efd04558b984d00a5dd3a6ecd2a78857e2797d76f5a8928530028c06dc0b1a5d29c0cb8a
6
+ metadata.gz: f8b8ee24b49731e914653f39f291720f89994c7c870b97bb74855b5604ba7cd20dbd680785da381742e4bdef6fca168ffd62143a48cea70ef2ac28a435559591
7
+ data.tar.gz: 0233597a6b80694b65cbf4ddb09aa86dfeaeb0c425d79e7d4e0e69519a313008b864197daf10de5ccdb825a07bec2d4ee8d7b4a8de5a70d01144df029cc15bbe
data/CHANGELOG.textile CHANGED
@@ -1,5 +1,9 @@
1
1
  h1. CHANGELOG
2
2
 
3
+ h3. 0.5.13 August 27, 2014
4
+
5
+ * support 'rails-devise-roles' example application
6
+
3
7
  h3. 0.5.12 August 14, 2014
4
8
 
5
9
  * minor change to routes for OmniAuth user pages
@@ -0,0 +1,26 @@
1
+ require 'rails/generators'
2
+
3
+ module Pages
4
+ module Generators
5
+ class RolesGenerator < ::Rails::Generators::Base
6
+ source_root File.expand_path("../templates", __FILE__)
7
+
8
+ desc "Simple role-based authorization. A User model with roles must be available."
9
+
10
+ def add_users_partial
11
+ copy_file 'users/_user.html.erb', 'app/views/users/_user.html.erb'
12
+ end
13
+
14
+ def add_if_devise
15
+ return unless File.exists?('config/initializers/devise.rb')
16
+ copy_file 'devise/users_controller.rb', 'app/controllers/users_controller.rb'
17
+ end
18
+
19
+ def add_if_omniauth
20
+ return unless File.exists?('config/initializers/omniauth.rb')
21
+ copy_file 'omniauth/users_controller.rb', 'app/controllers/users_controller.rb'
22
+ end
23
+
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,45 @@
1
+ class UsersController < ApplicationController
2
+ before_filter :authenticate_user!
3
+ before_filter :admin_only, :except => :show
4
+
5
+ def index
6
+ @users = User.all
7
+ end
8
+
9
+ def show
10
+ @user = User.find(params[:id])
11
+ unless current_user.admin?
12
+ unless @user == current_user
13
+ redirect_to :back, :alert => "Access denied."
14
+ end
15
+ end
16
+ end
17
+
18
+ def update
19
+ @user = User.find(params[:id])
20
+ if @user.update_attributes(secure_params)
21
+ redirect_to users_path, :notice => "User updated."
22
+ else
23
+ redirect_to users_path, :alert => "Unable to update user."
24
+ end
25
+ end
26
+
27
+ def destroy
28
+ user = User.find(params[:id])
29
+ user.destroy
30
+ redirect_to users_path, :notice => "User deleted."
31
+ end
32
+
33
+ private
34
+
35
+ def admin_only
36
+ unless current_user.admin?
37
+ redirect_to :back, :alert => "Access denied."
38
+ end
39
+ end
40
+
41
+ def secure_params
42
+ params.require(:user).permit(:role)
43
+ end
44
+
45
+ end
@@ -0,0 +1,49 @@
1
+ class UsersController < ApplicationController
2
+ before_filter :authenticate_user!
3
+ before_filter :admin_only, :except => :show
4
+
5
+ def index
6
+ @users = User.all
7
+ end
8
+
9
+ def show
10
+ @user = User.find(params[:id])
11
+ unless current_user.admin?
12
+ unless @user == current_user
13
+ redirect_to :back, :alert => "Access denied."
14
+ end
15
+ end
16
+ end
17
+
18
+ def update
19
+ @user = User.find(params[:id])
20
+ if @user.update_attributes(secure_params)
21
+ redirect_to :back, :notice => "User updated."
22
+ else
23
+ redirect_to :back, :alert => "Unable to update user."
24
+ end
25
+ end
26
+
27
+ def destroy
28
+ user = User.find(params[:id])
29
+ user.destroy
30
+ redirect_to users_path, :notice => "User deleted."
31
+ end
32
+
33
+ private
34
+
35
+ def admin_only
36
+ unless current_user.admin?
37
+ redirect_to :back, :alert => "Access denied."
38
+ end
39
+ end
40
+
41
+ def secure_params
42
+ if @user == current_user
43
+ params.require(:user).permit(:email)
44
+ elsif current_user.admin?
45
+ params.require(:user).permit(:role)
46
+ end
47
+ end
48
+
49
+ end
@@ -0,0 +1,12 @@
1
+ <td>
2
+ <%= link_to user.email, user %>
3
+ </td>
4
+ <td>
5
+ <%= form_for(user) do |f| %>
6
+ <%= f.select(:role, User.roles.keys.map {|role| [role.titleize,role]}) %>
7
+ <%= f.submit 'Change Role', :class => 'button-xs' %>
8
+ <% end %>
9
+ </td>
10
+ <td>
11
+ <%= link_to("Delete user", user_path(user), :data => { :confirm => "Are you sure?" }, :method => :delete, :class => 'button-xs') unless user == current_user %>
12
+ </td>
@@ -1,3 +1,3 @@
1
1
  module RailsAppsPages
2
- VERSION = "0.5.12"
2
+ VERSION = "0.5.13"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_apps_pages
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.12
4
+ version: 0.5.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Kehoe
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-08-14 00:00:00.000000000 Z
11
+ date: 2014-08-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -74,6 +74,10 @@ files:
74
74
  - lib/generators/pages/home/templates/home_page_spec.rb
75
75
  - lib/generators/pages/home/templates/index.html.erb
76
76
  - lib/generators/pages/home/templates/visitors_controller.rb
77
+ - lib/generators/pages/roles/roles_generator.rb
78
+ - lib/generators/pages/roles/templates/devise/users_controller.rb
79
+ - lib/generators/pages/roles/templates/omniauth/users_controller.rb
80
+ - lib/generators/pages/roles/templates/users/_user.html.erb
77
81
  - lib/generators/pages/users/templates/devise/devise_permitted_parameters.rb
78
82
  - lib/generators/pages/users/templates/devise/users_controller.rb
79
83
  - lib/generators/pages/users/templates/omniauth/_user.html.erb