lyb_devise_admin 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +30 -0
- data/MIT-LICENSE +20 -0
- data/README.rdoc +17 -0
- data/Rakefile +25 -0
- data/app/controllers/authorized_controller.rb +34 -0
- data/app/controllers/users_controller.rb +44 -0
- data/app/controllers/users_controller.rb~ +33 -0
- data/app/views/users/_collection_table.html.haml +21 -0
- data/app/views/users/_collection_table.html.haml~ +16 -0
- data/app/views/users/_form.html.haml +11 -0
- data/app/views/users/_resource_detail.html.haml +9 -0
- data/app/views/users/index.html.haml +21 -0
- data/app/views/users/show.html.haml +8 -0
- data/config/locales/lyb_devise_admin.yml +15 -0
- data/config/routes.rb +10 -0
- data/config/routes.rb~ +10 -0
- data/lib/lyb_devise_admin.rb +1 -0
- data/lib/lyb_devise_admin.rb~ +2 -0
- data/lib/lyb_devise_admin/railtie.rb +7 -0
- data/lib/lyb_devise_admin/railtie.rb~ +7 -0
- metadata +82 -0
data/Gemfile
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# Settings
|
2
|
+
# ========
|
3
|
+
source :rubygems
|
4
|
+
|
5
|
+
gemspec
|
6
|
+
|
7
|
+
# Test
|
8
|
+
# ====
|
9
|
+
group :test do
|
10
|
+
gem "rspec", "~> 2.0"
|
11
|
+
gem "rspec-rails", "~> 2.0"
|
12
|
+
gem "capybara", "~> 0.4"
|
13
|
+
end
|
14
|
+
|
15
|
+
# Rails
|
16
|
+
# =====
|
17
|
+
gem 'rails', '~> 3.0.0'
|
18
|
+
|
19
|
+
# Authentication
|
20
|
+
gem 'devise', '~> 1.1'
|
21
|
+
|
22
|
+
# Authorization
|
23
|
+
gem 'cancan'
|
24
|
+
|
25
|
+
# CRUD helpers
|
26
|
+
gem 'inherited_resources'
|
27
|
+
gem 'inherited_resources_views'
|
28
|
+
gem 'has_scope'
|
29
|
+
|
30
|
+
gem 'i18n_rails_helpers', '~> 0.9'
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2011 YOURNAME
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
= LybDeviseAdmin
|
2
|
+
|
3
|
+
LybDeviseAdmin provides a ready-to-use admin interface for device.
|
4
|
+
|
5
|
+
= Install
|
6
|
+
|
7
|
+
In Rails 3, simply add
|
8
|
+
|
9
|
+
gem 'lyb_devise_admin'
|
10
|
+
|
11
|
+
to your Gemfile.
|
12
|
+
|
13
|
+
= License
|
14
|
+
|
15
|
+
Copyright (c) 2011 Simon Hürlimann <simon.huerlimann@cyt.ch>
|
16
|
+
|
17
|
+
Released under the MIT license.
|
data/Rakefile
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
require 'rubygems'
|
3
|
+
begin
|
4
|
+
require 'bundler/setup'
|
5
|
+
rescue LoadError
|
6
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
7
|
+
end
|
8
|
+
|
9
|
+
require 'rake'
|
10
|
+
require 'rake/rdoctask'
|
11
|
+
|
12
|
+
require 'rspec/core'
|
13
|
+
require 'rspec/core/rake_task'
|
14
|
+
|
15
|
+
RSpec::Core::RakeTask.new(:spec)
|
16
|
+
|
17
|
+
task :default => :spec
|
18
|
+
|
19
|
+
Rake::RDocTask.new(:rdoc) do |rdoc|
|
20
|
+
rdoc.rdoc_dir = 'rdoc'
|
21
|
+
rdoc.title = 'LybDeviseAdmin'
|
22
|
+
rdoc.options << '--line-numbers' << '--inline-source'
|
23
|
+
rdoc.rdoc_files.include('README.rdoc')
|
24
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
25
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
class AuthorizedController < InheritedResources::Base
|
2
|
+
# Authorization
|
3
|
+
authorize_resource
|
4
|
+
|
5
|
+
rescue_from CanCan::AccessDenied do |exception|
|
6
|
+
flash[:alert] = t('cancan.access_denied')
|
7
|
+
|
8
|
+
if user_signed_in?
|
9
|
+
if request.env["HTTP_REFERER"]
|
10
|
+
# Show error on referring page for logged in users
|
11
|
+
redirect_to :back
|
12
|
+
else
|
13
|
+
redirect_to root_path
|
14
|
+
end
|
15
|
+
else
|
16
|
+
# Redirect to login page otherwise
|
17
|
+
redirect_to new_user_session_path
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
# Responders
|
22
|
+
respond_to :html, :js
|
23
|
+
|
24
|
+
# Flash helpers
|
25
|
+
def created_flash(resource)
|
26
|
+
render_to_string(:partial => 'layouts/created_flash', :resource => resource)
|
27
|
+
end
|
28
|
+
|
29
|
+
# Resource setup
|
30
|
+
protected
|
31
|
+
def collection
|
32
|
+
instance_eval("@#{controller_name.pluralize} ||= end_of_association_chain.accessible_by(current_ability, :list).paginate(:page => params[:page], :per_page => params[:per_page] || 25)")
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# Users Controller
|
2
|
+
#
|
3
|
+
# Provides a user/account management interface.
|
4
|
+
class UsersController < AuthorizedController
|
5
|
+
# Scopes
|
6
|
+
has_scope :tagged_with
|
7
|
+
|
8
|
+
# def create
|
9
|
+
# @user = User.new(params[:user])
|
10
|
+
# @user.person = Person.create(:type => params[:user]['role_texts'].first.to_s.camelcase) if params[:user]['role_texts'].first
|
11
|
+
#
|
12
|
+
# create!{ users_path }
|
13
|
+
# end
|
14
|
+
|
15
|
+
# Actions
|
16
|
+
def update
|
17
|
+
@user = resource
|
18
|
+
|
19
|
+
# Preset role_texts to ensure it clears roles.
|
20
|
+
params[:user][:role_texts] ||= []
|
21
|
+
|
22
|
+
# Test if user is allowed to change roles
|
23
|
+
params[:user].delete(:role_texts) unless can? :manage, Role
|
24
|
+
|
25
|
+
# Don't try to update password if not provided
|
26
|
+
if params[:user][:password].blank?
|
27
|
+
[:password, :password_confirmation, :current_password].collect{|p| params[:user].delete(p) }
|
28
|
+
end
|
29
|
+
|
30
|
+
update!
|
31
|
+
end
|
32
|
+
|
33
|
+
def unlock
|
34
|
+
@user = resource
|
35
|
+
|
36
|
+
@user.unlock_access!
|
37
|
+
|
38
|
+
redirect_to users_path, :notice => t('crud.flash.unlocked', :user => @user.to_s)
|
39
|
+
end
|
40
|
+
|
41
|
+
def current
|
42
|
+
redirect_to current_user
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# Users Controller
|
2
|
+
#
|
3
|
+
# Provides a user/account management interface.
|
4
|
+
class UsersController < AuthorizedController
|
5
|
+
# Scopes
|
6
|
+
has_scope :tagged_with
|
7
|
+
|
8
|
+
# Actions
|
9
|
+
def update
|
10
|
+
# Preset role_texts to ensure it clears roles.
|
11
|
+
params[:user][:role_texts] ||= []
|
12
|
+
|
13
|
+
@user = User.find(params[:id])
|
14
|
+
|
15
|
+
# Don't try to update password if not provided
|
16
|
+
if params[:user][:password].blank?
|
17
|
+
[:password, :password_confirmation, :current_password].collect{|p| params[:user].delete(p) }
|
18
|
+
end
|
19
|
+
|
20
|
+
update!
|
21
|
+
end
|
22
|
+
|
23
|
+
def unlock
|
24
|
+
@user = resource
|
25
|
+
@user.unlock_access!
|
26
|
+
|
27
|
+
redirect_to users_path, :notice => t('crud.flash.unlocked', :user => @user.to_s)
|
28
|
+
end
|
29
|
+
|
30
|
+
def current
|
31
|
+
redirect_to current_user
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
= contextual_links
|
2
|
+
|
3
|
+
%h2= t_title
|
4
|
+
|
5
|
+
= paginated_section collection do
|
6
|
+
- @attributes = ['name', 'email', 'role_texts', 'created_at', 'locked']
|
7
|
+
%table.list{:class => "#{collection.first.class.to_s.downcase.pluralize} collection"}
|
8
|
+
%thead
|
9
|
+
%tr
|
10
|
+
- @attributes.each do |field|
|
11
|
+
%th= t_attr field, collection.first.class
|
12
|
+
%th.action-links
|
13
|
+
%tbody
|
14
|
+
- collection.each do |r|
|
15
|
+
%tr
|
16
|
+
- @attributes.each do |field|
|
17
|
+
%td= r.send(field) if r.respond_to?(field)
|
18
|
+
%td.action-links
|
19
|
+
=link_to t_action(:show), resource_url(r), 'data-href-container' => 'tr'
|
20
|
+
=link_to t_action(:edit), edit_resource_url(r)
|
21
|
+
=link_to t_action(:delete), resource_url(r), :confirm => t_confirm_delete(r), :method => :delete
|
@@ -0,0 +1,16 @@
|
|
1
|
+
%table.list{:class => "#{collection.first.class.to_s.downcase.pluralize} collection"}
|
2
|
+
%thead
|
3
|
+
%tr
|
4
|
+
- ['name', 'email', 'roles', 'created_at', 'locked'].each do |field|
|
5
|
+
%th= t_attr field, collection.first.class
|
6
|
+
%th.action-links
|
7
|
+
%tbody
|
8
|
+
- collection.each do |r|
|
9
|
+
%tr
|
10
|
+
- r.attributes.each_pair do |field, value|
|
11
|
+
- next if ['id', 'created_at', 'updated_at'].include?(field)
|
12
|
+
%td= value
|
13
|
+
%td.action-links
|
14
|
+
=link_to "Show", resource_url(r), 'data-href-container' => 'tr'
|
15
|
+
=link_to "Edit", edit_resource_url(r)
|
16
|
+
=link_to "Destroy", resource_url(r), :confirm => 'Are you sure?', :method => :delete
|
@@ -0,0 +1,11 @@
|
|
1
|
+
= semantic_form_for @user do |f|
|
2
|
+
= f.semantic_errors
|
3
|
+
= f.inputs do
|
4
|
+
= f.input :email
|
5
|
+
= f.input :password, :hint => !f.object.new_record?, :input_html => {:autocomplete => "off"}
|
6
|
+
= f.input :password_confirmation
|
7
|
+
-# f.input :current_password, :required => true unless can?(:manage, User)
|
8
|
+
= f.input :role_texts, :as => :select, :collection => Ability.roles_for_collection, :include_blank => false, :input_html => {:multiple => 'multiple'}, :required => true if can?(:manage, Role)
|
9
|
+
|
10
|
+
= f.buttons do
|
11
|
+
= f.commit_button
|
@@ -0,0 +1,21 @@
|
|
1
|
+
= contextual_links
|
2
|
+
|
3
|
+
%h2= t_title
|
4
|
+
|
5
|
+
= paginated_section collection do
|
6
|
+
- @attributes = ['name', 'email', 'role_texts', 'created_at', 'locked']
|
7
|
+
%table.list{:class => "#{collection.first.class.to_s.downcase.pluralize} collection"}
|
8
|
+
%thead
|
9
|
+
%tr
|
10
|
+
- @attributes.each do |field|
|
11
|
+
%th= t_attr field, collection.first.class
|
12
|
+
%th.action-links
|
13
|
+
%tbody
|
14
|
+
- collection.each do |r|
|
15
|
+
%tr
|
16
|
+
- @attributes.each do |field|
|
17
|
+
%td= r.send(field) if r.respond_to?(field)
|
18
|
+
%td.action-links
|
19
|
+
=link_to t_action(:show), resource_url(r), 'data-href-container' => 'tr'
|
20
|
+
=link_to t_action(:edit), edit_resource_url(r)
|
21
|
+
=link_to t_action(:delete), resource_url(r), :confirm => t_confirm_delete(r), :method => :delete
|
@@ -0,0 +1,15 @@
|
|
1
|
+
de:
|
2
|
+
activerecord:
|
3
|
+
models:
|
4
|
+
attributes:
|
5
|
+
user:
|
6
|
+
email: E-Mail
|
7
|
+
password: Passwort
|
8
|
+
password_confirmation: Passwort Bestätigung
|
9
|
+
current_password: Aktuelles Passwort
|
10
|
+
remember_me: Angemeldet bleiben
|
11
|
+
created_at: Registriert seit
|
12
|
+
roles: Rollen
|
13
|
+
role_texts: Rollen
|
14
|
+
locked: Gesperrt
|
15
|
+
name: Name
|
data/config/routes.rb
ADDED
data/config/routes.rb~
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'lyb_devise_admin/railtie' if defined?(::Rails::Railtie)
|
metadata
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: lyb_devise_admin
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 1
|
8
|
+
- 0
|
9
|
+
version: 0.1.0
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- "Simon H\xC3\xBCrlimann (CyT)"
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2011-02-22 00:00:00 +01:00
|
18
|
+
default_executable:
|
19
|
+
dependencies: []
|
20
|
+
|
21
|
+
description: LybDeviseAdmin .
|
22
|
+
email:
|
23
|
+
- simon.huerlimann@cyt.ch
|
24
|
+
executables: []
|
25
|
+
|
26
|
+
extensions: []
|
27
|
+
|
28
|
+
extra_rdoc_files: []
|
29
|
+
|
30
|
+
files:
|
31
|
+
- app/views/users/index.html.haml
|
32
|
+
- app/views/users/_collection_table.html.haml
|
33
|
+
- app/views/users/_collection_table.html.haml~
|
34
|
+
- app/views/users/_form.html.haml
|
35
|
+
- app/views/users/show.html.haml
|
36
|
+
- app/views/users/_resource_detail.html.haml
|
37
|
+
- app/controllers/authorized_controller.rb
|
38
|
+
- app/controllers/users_controller.rb~
|
39
|
+
- app/controllers/users_controller.rb
|
40
|
+
- lib/lyb_devise_admin.rb~
|
41
|
+
- lib/lyb_devise_admin/railtie.rb~
|
42
|
+
- lib/lyb_devise_admin/railtie.rb
|
43
|
+
- lib/lyb_devise_admin.rb
|
44
|
+
- config/routes.rb
|
45
|
+
- config/routes.rb~
|
46
|
+
- config/locales/lyb_devise_admin.yml
|
47
|
+
- MIT-LICENSE
|
48
|
+
- Rakefile
|
49
|
+
- Gemfile
|
50
|
+
- README.rdoc
|
51
|
+
has_rdoc: true
|
52
|
+
homepage:
|
53
|
+
licenses: []
|
54
|
+
|
55
|
+
post_install_message:
|
56
|
+
rdoc_options: []
|
57
|
+
|
58
|
+
require_paths:
|
59
|
+
- lib
|
60
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
61
|
+
requirements:
|
62
|
+
- - ">="
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
segments:
|
65
|
+
- 0
|
66
|
+
version: "0"
|
67
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
68
|
+
requirements:
|
69
|
+
- - ">="
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
segments:
|
72
|
+
- 0
|
73
|
+
version: "0"
|
74
|
+
requirements: []
|
75
|
+
|
76
|
+
rubyforge_project:
|
77
|
+
rubygems_version: 1.3.6
|
78
|
+
signing_key:
|
79
|
+
specification_version: 3
|
80
|
+
summary: LybDeviseAdmin provides a ready-to-use admin interface for device.
|
81
|
+
test_files: []
|
82
|
+
|