ixtlan-guard 0.1.0 → 0.4.0
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.
- data/MIT-LICENSE +20 -0
- data/lib/generators/active_record/templates/flavor_migration.rb +13 -0
- data/lib/generators/active_record/templates/flavor_model.rb +8 -0
- data/lib/generators/active_record/templates/group_model.rb +43 -0
- data/lib/generators/active_record/templates/group_user_migration.rb +13 -0
- data/lib/generators/active_record/templates/user_model.rb +124 -0
- data/lib/generators/active_record/user_management_models_generator.rb +202 -0
- data/lib/generators/erb/user_management_controller_generator.rb +10 -0
- data/lib/generators/{ixtlan → guard}/controller/USAGE +0 -0
- data/lib/generators/{ixtlan → guard}/controller/controller_generator.rb +2 -2
- data/lib/generators/{ixtlan → guard}/scaffold/USAGE +0 -0
- data/lib/generators/{ixtlan → guard}/scaffold/scaffold_generator.rb +4 -6
- data/lib/generators/guard/scaffold/templates/guard.rb +20 -0
- data/lib/generators/guard/templates/guard.rb +20 -0
- data/lib/generators/ixtlan/maintenance_scaffold/USAGE +8 -0
- data/lib/generators/ixtlan/maintenance_scaffold/maintenance_scaffold_generator.rb +40 -0
- data/lib/generators/ixtlan/permissions_scaffold/USAGE +8 -0
- data/lib/generators/ixtlan/permissions_scaffold/permissions_scaffold_generator.rb +33 -0
- data/lib/generators/ixtlan/user_management_controller/USAGE +8 -0
- data/lib/generators/ixtlan/user_management_controller/user_management_controller_generator.rb +23 -0
- data/lib/generators/ixtlan/user_management_models/USAGE +8 -0
- data/lib/generators/ixtlan/user_management_models/user_management_models_generator.rb +19 -0
- data/lib/generators/ixtlan/user_management_scaffold/user_management_scaffold_generator.rb +13 -0
- data/lib/ixtlan-guard.rb +2 -2
- data/lib/ixtlan/guard.rb +1 -159
- data/lib/ixtlan/guard/controllers/maintenance_controller.rb +45 -0
- data/lib/ixtlan/guard/controllers/permissions_controller.rb +41 -0
- data/lib/ixtlan/guard/guard.rb +245 -0
- data/lib/ixtlan/guard/models/maintenance.rb +55 -0
- data/lib/ixtlan/guard/models/user_update_manager.rb +95 -0
- data/lib/ixtlan/guard/rails_integration.rb +88 -0
- data/lib/ixtlan/guard/railtie.rb +33 -0
- data/lib/ixtlan/guard/spec/user_management_models_spec.rb +193 -0
- data/spec/guard_spec.rb +48 -12
- data/spec/railtie_spec.rb +1 -1
- metadata +75 -52
- data/lib/generators/ixtlan/templates/edit.html.erb +0 -10
- data/lib/generators/ixtlan/templates/guard.rb +0 -13
- data/lib/generators/ixtlan/templates/index.html.erb +0 -35
- data/lib/generators/ixtlan/templates/new.html.erb +0 -7
- data/lib/generators/ixtlan/templates/show.html.erb +0 -16
- data/lib/generators/scaffold/scaffold/scaffold_generator.rb +0 -23
- data/lib/ixtlan/guard_railtie.rb +0 -43
- data/lib/ixtlan/rails_integration.rb +0 -55
@@ -1,10 +0,0 @@
|
|
1
|
-
<h1>Editing <%= singular_table_name %></h1>
|
2
|
-
|
3
|
-
<%%= render 'form' %>
|
4
|
-
|
5
|
-
<%% if allowed?(:<%= table_name %>, :show) %>
|
6
|
-
<%%= link_to 'Show', @<%= singular_table_name %> %> |
|
7
|
-
<%% end %>
|
8
|
-
<%% if allowed?(:<%= table_name %>, :index) %>
|
9
|
-
<%%= link_to 'Back', <%= index_helper %>_path %>
|
10
|
-
<%% end %>
|
@@ -1,13 +0,0 @@
|
|
1
|
-
class <%= guard_class_name %>Guard
|
2
|
-
def initialize(guard)
|
3
|
-
#guard.name = "<%= plural_file_name %>"
|
4
|
-
<% if aliases -%>
|
5
|
-
guard.aliases = <%= aliases.inspect %>
|
6
|
-
<% end -%>
|
7
|
-
guard.action_map= {
|
8
|
-
<% for action in actions -%>
|
9
|
-
:<%= action %> => [],
|
10
|
-
<% end -%>
|
11
|
-
}
|
12
|
-
end
|
13
|
-
end
|
@@ -1,35 +0,0 @@
|
|
1
|
-
<h1>Listing <%= plural_table_name %></h1>
|
2
|
-
|
3
|
-
<table>
|
4
|
-
<tr>
|
5
|
-
<% for attribute in attributes -%>
|
6
|
-
<th><%= attribute.human_name %></th>
|
7
|
-
<% end -%>
|
8
|
-
<th></th>
|
9
|
-
<th></th>
|
10
|
-
<th></th>
|
11
|
-
</tr>
|
12
|
-
|
13
|
-
<%% @<%= plural_table_name %>.each do |<%= singular_table_name %>| %>
|
14
|
-
<tr>
|
15
|
-
<% for attribute in attributes -%>
|
16
|
-
<td><%%= <%= singular_table_name %>.<%= attribute.name %> %></td>
|
17
|
-
<% end -%>
|
18
|
-
<%% if allowed?(:<%= table_name %>, :show) %>
|
19
|
-
<td><%%= link_to 'Show', <%= singular_table_name %> %></td>
|
20
|
-
<%% end %>
|
21
|
-
<%% if allowed?(:<%= table_name %>, :update) %>
|
22
|
-
<td><%%= link_to 'Edit', edit_<%= singular_table_name %>_path(<%= singular_table_name %>) %></td>
|
23
|
-
<%% end %>
|
24
|
-
<%% if allowed?(:<%= table_name %>, :destroy) %>
|
25
|
-
<td><%%= link_to 'Destroy', <%= singular_table_name %>, :confirm => 'Are you sure?', :method => :delete %></td>
|
26
|
-
<%% end %>
|
27
|
-
</tr>
|
28
|
-
<%% end %>
|
29
|
-
</table>
|
30
|
-
|
31
|
-
<br />
|
32
|
-
|
33
|
-
<%% if allowed?(:<%= table_name %>, :create) %>
|
34
|
-
<%%= link_to 'New <%= human_name %>', new_<%= singular_table_name %>_path %>
|
35
|
-
<%% end %>
|
@@ -1,16 +0,0 @@
|
|
1
|
-
<p id="notice"><%%= notice %></p>
|
2
|
-
|
3
|
-
<% for attribute in attributes -%>
|
4
|
-
<p>
|
5
|
-
<b><%= attribute.human_name %>:</b>
|
6
|
-
<%%= @<%= singular_table_name %>.<%= attribute.name %> %>
|
7
|
-
</p>
|
8
|
-
|
9
|
-
<% end -%>
|
10
|
-
|
11
|
-
<%% if allowed?(:<%= table_name %>, :update) %>
|
12
|
-
<%%= link_to 'Edit', edit_<%= singular_table_name %>_path(@<%= singular_table_name %>) %> |
|
13
|
-
<%% end %>
|
14
|
-
<%% if allowed?(:<%= table_name %>, :index) %>
|
15
|
-
<%%= link_to 'Back', <%= index_helper %>_path %>
|
16
|
-
<%% end %>
|
@@ -1,23 +0,0 @@
|
|
1
|
-
# use this extended copy of Rails::Generators::ScaffoldGenerator
|
2
|
-
# since the search path is the following:
|
3
|
-
# ["scaffold:scaffold", "rails:scaffold", "scaffold"]
|
4
|
-
# which allows to override orignal generator
|
5
|
-
# adding a Rails::Generators::ScaffoldGenerator.hook_for did not work
|
6
|
-
# since it looses the ORM config somehow
|
7
|
-
require 'rails/generators/rails/resource/resource_generator'
|
8
|
-
module Rails
|
9
|
-
module Generators
|
10
|
-
class ScaffoldGenerator < ResourceGenerator #metagenerator
|
11
|
-
|
12
|
-
remove_hook_for :resource_controller
|
13
|
-
remove_class_option :actions
|
14
|
-
|
15
|
-
hook_for :scaffold_controller, :required => true, :in => :rails
|
16
|
-
hook_for :stylesheets, :in => :rails
|
17
|
-
|
18
|
-
hook_for :ixtlan, :type => :boolean, :default => true do |controller|
|
19
|
-
invoke controller, [class_name]
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
data/lib/ixtlan/guard_railtie.rb
DELETED
@@ -1,43 +0,0 @@
|
|
1
|
-
require 'rails'
|
2
|
-
require 'ixtlan/guard'
|
3
|
-
require 'logger'
|
4
|
-
|
5
|
-
class GuardRailtie < Rails::Railtie
|
6
|
-
|
7
|
-
config.before_configuration do |app|
|
8
|
-
app.config.class.class_eval do
|
9
|
-
attr_accessor :guard
|
10
|
-
end
|
11
|
-
app.config.guard =
|
12
|
-
Ixtlan::Guard.new(Logger.new(STDERR),
|
13
|
-
:root,
|
14
|
-
File.join(Rails.root, "app", "guards"))
|
15
|
-
end
|
16
|
-
|
17
|
-
config.after_initialize do |app|
|
18
|
-
logger = app.config.logger || Rails.logger || Logger.new(STDERR)
|
19
|
-
app.config.guard.logger = logger
|
20
|
-
begin
|
21
|
-
app.config.guard.setup
|
22
|
-
rescue Ixtlan::GuardException => e
|
23
|
-
logger.warn e.message
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
config.generators do
|
28
|
-
require 'rails/generators'
|
29
|
-
require 'rails/generators/rails/controller/controller_generator'
|
30
|
-
require 'rails/generators/erb/scaffold/scaffold_generator'
|
31
|
-
Rails::Generators::ControllerGenerator.hook_for :ixtlan, :type => :boolean, :default => true do |controller|
|
32
|
-
invoke controller, [ class_name, actions ]
|
33
|
-
end
|
34
|
-
Erb::Generators::ScaffoldGenerator.source_paths.insert(0, File.expand_path('../../generators/ixtlan/templates', __FILE__))
|
35
|
-
#require 'rails/generators/rails/scaffold/scaffold_generator'
|
36
|
-
# somehow the check is before the value is set,
|
37
|
-
# so just ignore the require flag
|
38
|
-
#Rails::Generators::ScaffoldGenerator.class_options[:orm].instance_variable_set(:@required, false)
|
39
|
-
#Rails::Generators::ScaffoldGenerator.hook_for :ixtlan, :as => :scaffold, :type => :boolean, :default => true do |controller|
|
40
|
-
# invoke controller, [class_name]
|
41
|
-
#end
|
42
|
-
end
|
43
|
-
end
|
@@ -1,55 +0,0 @@
|
|
1
|
-
require 'ixtlan/guard'
|
2
|
-
module Ixtlan
|
3
|
-
module ActionController #:nodoc:
|
4
|
-
module Guard #:nodoc:
|
5
|
-
def self.included(base)
|
6
|
-
base.send(:include, InstanceMethods)
|
7
|
-
end
|
8
|
-
module InstanceMethods #:nodoc:
|
9
|
-
|
10
|
-
protected
|
11
|
-
|
12
|
-
def guard
|
13
|
-
Rails.configuration.guard
|
14
|
-
end
|
15
|
-
|
16
|
-
def authorization(&block)
|
17
|
-
resource_authorization(params[:controller], params[:action], &block)
|
18
|
-
end
|
19
|
-
|
20
|
-
def resource_authorization(resource, action, &block)
|
21
|
-
unless guard.check(self, resource, action, &block)
|
22
|
-
raise ::Ixtlan::PermissionDenied.new("permission denied for '#{resource}##{action}'")
|
23
|
-
end
|
24
|
-
true
|
25
|
-
end
|
26
|
-
|
27
|
-
def allowed?(action, &block)
|
28
|
-
guard.check(self, params[:controller], action, &block)
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
module Allowed #:nodoc:
|
35
|
-
# Inclusion hook to make #allowed available as method
|
36
|
-
def self.included(base)
|
37
|
-
base.send(:include, InstanceMethods)
|
38
|
-
end
|
39
|
-
|
40
|
-
module InstanceMethods #:nodoc:
|
41
|
-
def allowed?(resource, action, &block)
|
42
|
-
controller.send(:guard).check(controller, resource, action, &block)
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
ActionController::Base.send(:include, Ixtlan::ActionController::Guard)
|
49
|
-
ActionController::Base.send(:before_filter, :authorization)
|
50
|
-
ActionView::Base.send(:include, Ixtlan::Allowed)
|
51
|
-
module Erector
|
52
|
-
class Widget
|
53
|
-
include Ixtlan::Allowed
|
54
|
-
end
|
55
|
-
end
|