extreme_aas 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +8 -0
- data/.rvmrc +5 -0
- data/Gemfile +3 -0
- data/Gemfile.lock +134 -0
- data/MIT-LICENSE +20 -0
- data/README.rdoc +3 -0
- data/Rakefile +25 -0
- data/app/models/extreme_aas/application_controller.rb +21 -0
- data/app/models/extreme_aas/extreme_action.rb +21 -0
- data/app/models/extreme_aas/extreme_action_abstract.rb +22 -0
- data/app/models/extreme_aas/extreme_action_edge.rb +6 -0
- data/app/models/extreme_aas/extreme_action_group.rb +33 -0
- data/app/models/extreme_aas/extreme_grant.rb +13 -0
- data/app/models/extreme_aas/extreme_profile.rb +10 -0
- data/app/models/extreme_aas/extreme_simple_action.rb +19 -0
- data/extreme_aas.gemspec +29 -0
- data/lib/extreme_aas/engine.rb +23 -0
- data/lib/extreme_aas/version.rb +3 -0
- data/lib/extreme_aas.rb +25 -0
- data/lib/generators/extreme_aas/extreme_aas_generator.rb +21 -0
- data/lib/generators/extreme_aas/templates/migration.rb +36 -0
- data/lib/tasks/sync.rake +56 -0
- data/spec/dummy/Gemfile.lock +10 -0
- data/spec/dummy/Rakefile +7 -0
- data/spec/dummy/app/assets/javascripts/users.js +2 -0
- data/spec/dummy/app/assets/stylesheets/scaffold.css +56 -0
- data/spec/dummy/app/assets/stylesheets/users.css +4 -0
- data/spec/dummy/app/controllers/application_controller.rb +3 -0
- data/spec/dummy/app/controllers/users_controller.rb +83 -0
- data/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/dummy/app/helpers/users_helper.rb +5 -0
- data/spec/dummy/app/models/user.rb +3 -0
- data/spec/dummy/app/views/layouts/application.html.erb +14 -0
- data/spec/dummy/app/views/users/_form.html.erb +25 -0
- data/spec/dummy/app/views/users/edit.html.erb +6 -0
- data/spec/dummy/app/views/users/index.html.erb +25 -0
- data/spec/dummy/app/views/users/new.html.erb +5 -0
- data/spec/dummy/app/views/users/show.html.erb +15 -0
- data/spec/dummy/config/application.rb +45 -0
- data/spec/dummy/config/boot.rb +10 -0
- data/spec/dummy/config/database.yml +28 -0
- data/spec/dummy/config/database_template.yml +28 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +24 -0
- data/spec/dummy/config/environments/production.rb +49 -0
- data/spec/dummy/config/environments/test.rb +35 -0
- data/spec/dummy/config/extreme_aas_groups.yml +0 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/inflections.rb +10 -0
- data/spec/dummy/config/initializers/mime_types.rb +5 -0
- data/spec/dummy/config/initializers/secret_token.rb +7 -0
- data/spec/dummy/config/initializers/session_store.rb +8 -0
- data/spec/dummy/config/locales/en.yml +5 -0
- data/spec/dummy/config/routes.rb +60 -0
- data/spec/dummy/config.ru +4 -0
- data/spec/dummy/db/migrate/20120404105554_create_users.rb +10 -0
- data/spec/dummy/db/migrate/20120413132357_create_extreme_aas_tables.rb +36 -0
- data/spec/dummy/db/schema.rb +65 -0
- data/spec/dummy/public/401.html +26 -0
- data/spec/dummy/public/404.html +26 -0
- data/spec/dummy/public/422.html +26 -0
- data/spec/dummy/public/500.html +26 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/dummy/public/javascripts/application.js +2 -0
- data/spec/dummy/public/javascripts/controls.js +965 -0
- data/spec/dummy/public/javascripts/dragdrop.js +974 -0
- data/spec/dummy/public/javascripts/effects.js +1123 -0
- data/spec/dummy/public/javascripts/prototype.js +6001 -0
- data/spec/dummy/public/javascripts/rails.js +202 -0
- data/spec/dummy/public/stylesheets/.gitkeep +0 -0
- data/spec/dummy/script/rails +6 -0
- data/spec/factories.rb +26 -0
- data/spec/integration/controller_actions_spec.rb +28 -0
- data/spec/integration/navigation_spec.rb +8 -0
- data/spec/spec_helper.rb +42 -0
- data/spec/support/extreme_aas_groups.yml +8 -0
- data/spec/unit/action_group_spec.rb +65 -0
- data/spec/unit/simple_action_spec.rb +34 -0
- metadata +235 -0
data/.gitignore
ADDED
data/.rvmrc
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,134 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
extreme_aas (0.0.1)
|
5
|
+
capybara (>= 0.4.0)
|
6
|
+
rails (~> 3.2.2)
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: http://rubygems.org/
|
10
|
+
specs:
|
11
|
+
actionmailer (3.2.3)
|
12
|
+
actionpack (= 3.2.3)
|
13
|
+
mail (~> 2.4.4)
|
14
|
+
actionpack (3.2.3)
|
15
|
+
activemodel (= 3.2.3)
|
16
|
+
activesupport (= 3.2.3)
|
17
|
+
builder (~> 3.0.0)
|
18
|
+
erubis (~> 2.7.0)
|
19
|
+
journey (~> 1.0.1)
|
20
|
+
rack (~> 1.4.0)
|
21
|
+
rack-cache (~> 1.2)
|
22
|
+
rack-test (~> 0.6.1)
|
23
|
+
sprockets (~> 2.1.2)
|
24
|
+
activemodel (3.2.3)
|
25
|
+
activesupport (= 3.2.3)
|
26
|
+
builder (~> 3.0.0)
|
27
|
+
activerecord (3.2.3)
|
28
|
+
activemodel (= 3.2.3)
|
29
|
+
activesupport (= 3.2.3)
|
30
|
+
arel (~> 3.0.2)
|
31
|
+
tzinfo (~> 0.3.29)
|
32
|
+
activeresource (3.2.3)
|
33
|
+
activemodel (= 3.2.3)
|
34
|
+
activesupport (= 3.2.3)
|
35
|
+
activesupport (3.2.3)
|
36
|
+
i18n (~> 0.6)
|
37
|
+
multi_json (~> 1.0)
|
38
|
+
arel (3.0.2)
|
39
|
+
builder (3.0.0)
|
40
|
+
capybara (1.1.2)
|
41
|
+
mime-types (>= 1.16)
|
42
|
+
nokogiri (>= 1.3.3)
|
43
|
+
rack (>= 1.0.0)
|
44
|
+
rack-test (>= 0.5.4)
|
45
|
+
selenium-webdriver (~> 2.0)
|
46
|
+
xpath (~> 0.1.4)
|
47
|
+
childprocess (0.3.1)
|
48
|
+
ffi (~> 1.0.6)
|
49
|
+
diff-lcs (1.1.3)
|
50
|
+
erubis (2.7.0)
|
51
|
+
factory_girl (3.0.0)
|
52
|
+
activesupport (>= 3.0.0)
|
53
|
+
factory_girl_rails (3.0.0)
|
54
|
+
factory_girl (~> 3.0.0)
|
55
|
+
railties (>= 3.0.0)
|
56
|
+
ffi (1.0.11)
|
57
|
+
hike (1.2.1)
|
58
|
+
i18n (0.6.0)
|
59
|
+
journey (1.0.3)
|
60
|
+
json (1.6.6)
|
61
|
+
mail (2.4.4)
|
62
|
+
i18n (>= 0.4.0)
|
63
|
+
mime-types (~> 1.16)
|
64
|
+
treetop (~> 1.4.8)
|
65
|
+
mime-types (1.18)
|
66
|
+
multi_json (1.2.0)
|
67
|
+
mysql2 (0.3.11)
|
68
|
+
nokogiri (1.5.2)
|
69
|
+
polyglot (0.3.3)
|
70
|
+
rack (1.4.1)
|
71
|
+
rack-cache (1.2)
|
72
|
+
rack (>= 0.4)
|
73
|
+
rack-ssl (1.3.2)
|
74
|
+
rack
|
75
|
+
rack-test (0.6.1)
|
76
|
+
rack (>= 1.0)
|
77
|
+
rails (3.2.3)
|
78
|
+
actionmailer (= 3.2.3)
|
79
|
+
actionpack (= 3.2.3)
|
80
|
+
activerecord (= 3.2.3)
|
81
|
+
activeresource (= 3.2.3)
|
82
|
+
activesupport (= 3.2.3)
|
83
|
+
bundler (~> 1.0)
|
84
|
+
railties (= 3.2.3)
|
85
|
+
railties (3.2.3)
|
86
|
+
actionpack (= 3.2.3)
|
87
|
+
activesupport (= 3.2.3)
|
88
|
+
rack-ssl (~> 1.3.2)
|
89
|
+
rake (>= 0.8.7)
|
90
|
+
rdoc (~> 3.4)
|
91
|
+
thor (~> 0.14.6)
|
92
|
+
rake (0.9.2.2)
|
93
|
+
rdoc (3.12)
|
94
|
+
json (~> 1.4)
|
95
|
+
rspec (2.9.0)
|
96
|
+
rspec-core (~> 2.9.0)
|
97
|
+
rspec-expectations (~> 2.9.0)
|
98
|
+
rspec-mocks (~> 2.9.0)
|
99
|
+
rspec-core (2.9.0)
|
100
|
+
rspec-expectations (2.9.1)
|
101
|
+
diff-lcs (~> 1.1.3)
|
102
|
+
rspec-mocks (2.9.0)
|
103
|
+
rspec-rails (2.9.0)
|
104
|
+
actionpack (>= 3.0)
|
105
|
+
activesupport (>= 3.0)
|
106
|
+
railties (>= 3.0)
|
107
|
+
rspec (~> 2.9.0)
|
108
|
+
rubyzip (0.9.6.1)
|
109
|
+
selenium-webdriver (2.20.0)
|
110
|
+
childprocess (>= 0.2.5)
|
111
|
+
ffi (~> 1.0)
|
112
|
+
multi_json (~> 1.0)
|
113
|
+
rubyzip
|
114
|
+
sprockets (2.1.2)
|
115
|
+
hike (~> 1.2)
|
116
|
+
rack (~> 1.0)
|
117
|
+
tilt (~> 1.1, != 1.3.0)
|
118
|
+
thor (0.14.6)
|
119
|
+
tilt (1.3.3)
|
120
|
+
treetop (1.4.10)
|
121
|
+
polyglot
|
122
|
+
polyglot (>= 0.3.1)
|
123
|
+
tzinfo (0.3.32)
|
124
|
+
xpath (0.1.4)
|
125
|
+
nokogiri (~> 1.3)
|
126
|
+
|
127
|
+
PLATFORMS
|
128
|
+
ruby
|
129
|
+
|
130
|
+
DEPENDENCIES
|
131
|
+
extreme_aas!
|
132
|
+
factory_girl_rails
|
133
|
+
mysql2
|
134
|
+
rspec-rails (~> 2.5)
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2012 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
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 = 'ExtremeAas'
|
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,21 @@
|
|
1
|
+
module ExtremeAas
|
2
|
+
module ApplicationController
|
3
|
+
private
|
4
|
+
def extreme_aas_permission_denied
|
5
|
+
render "#{Rails.root}/public/404", :format => [:html], :status => :unauthorized
|
6
|
+
end
|
7
|
+
|
8
|
+
def extreme_aas_ask_permission
|
9
|
+
#context profile, controller action
|
10
|
+
simple_action = ExtremeAas::ExtremeSimpleAction.find_action :controller_name =>params[:controller], :action_name => params[:action]
|
11
|
+
extreme_aas_permission_denied unless simple_action && extreme_aas_profile && simple_action.has_permission?(extreme_aas_profile)
|
12
|
+
|
13
|
+
end
|
14
|
+
|
15
|
+
def extreme_aas_profile
|
16
|
+
@extreme_aas_profile ||= ExtremeProfile.last #FIXME
|
17
|
+
|
18
|
+
#@extreme_aas_profile ||= ExtremeProfile.find(session[:extreme_aas_profile_id]) if session[:extreme_aas_profile_id]
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module ExtremeAas
|
2
|
+
class ExtremeAction < ActiveRecord::Base
|
3
|
+
belongs_to :actionable, :polymorphic => true, :dependent => :destroy
|
4
|
+
has_many :grants, :class_name => 'ExtremeGrant', :dependent => :destroy
|
5
|
+
has_many :action_edges, :class_name => 'ExtremeActionEdge', :foreign_key => 'child_action_id', :dependent => :destroy
|
6
|
+
|
7
|
+
def self.parse args={}
|
8
|
+
if args.include? :group
|
9
|
+
return ExtremeActionGroup.find_by_name(args[:group]).super_action
|
10
|
+
end
|
11
|
+
return ExtremeSimpleAction.where(args).first.super_action
|
12
|
+
end
|
13
|
+
|
14
|
+
def method_missing(method, *args, &block)
|
15
|
+
super
|
16
|
+
rescue NoMethodError => e
|
17
|
+
self.actionable.send(method, *args, &block)
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module ExtremeAas
|
2
|
+
module ExtremeActionAbstract
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
included do
|
6
|
+
#put things here
|
7
|
+
after_save :create_action
|
8
|
+
has_one :super_action, :class_name => 'ExtremeAction', :as => 'actionable', :dependent => :destroy
|
9
|
+
end
|
10
|
+
|
11
|
+
private
|
12
|
+
def create_action
|
13
|
+
ExtremeAction.create!(:actionable_id => self.id, :actionable_type => self.class.name)
|
14
|
+
end
|
15
|
+
|
16
|
+
public
|
17
|
+
def has_permission? profile
|
18
|
+
raise NotImplementedError, 'Please check ExtremeActionAbstract module to see which methods are missing'
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,6 @@
|
|
1
|
+
module ExtremeAas
|
2
|
+
class ExtremeActionEdge < ActiveRecord::Base
|
3
|
+
belongs_to :parent_action, :class_name => 'ExtremeActionGroup', :foreign_key => 'parent_action_id'
|
4
|
+
belongs_to :child_action, :class_name => 'ExtremeAction', :foreign_key => 'child_action_id'
|
5
|
+
end
|
6
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module ExtremeAas
|
2
|
+
class ExtremeActionGroup < ActiveRecord::Base
|
3
|
+
include ExtremeActionAbstract
|
4
|
+
|
5
|
+
has_many :action_edges, :class_name => 'ExtremeActionEdge', :foreign_key => 'parent_action_id', :dependent => :destroy
|
6
|
+
has_many :actions, :through => :action_edges, :source => :child_action
|
7
|
+
|
8
|
+
validates_uniqueness_of :name
|
9
|
+
|
10
|
+
def self.export path = "#{Rails.root}/config/extreme_aas_groups.yml"
|
11
|
+
yaml = YAML::load_file(path)
|
12
|
+
if yaml
|
13
|
+
yaml.each do |group_name, actions|
|
14
|
+
group = ExtremeActionGroup.find_or_create_by_name group_name
|
15
|
+
actions.each do |action_yml_params|
|
16
|
+
action_params = {}
|
17
|
+
action_yml_params.each do |key, value|
|
18
|
+
action_params[key.to_sym] = value
|
19
|
+
end
|
20
|
+
action = ExtremeAction.parse action_params
|
21
|
+
if action.nil?
|
22
|
+
raise "Action not found. Parameters #{action_params}"
|
23
|
+
else
|
24
|
+
group.actions << action
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
else
|
29
|
+
puts "Warning: couldn't load file in #{path}"
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module ExtremeAas
|
2
|
+
class ExtremeGrant < ActiveRecord::Base
|
3
|
+
belongs_to :profile, :class_name => 'ExtremeProfile', :foreign_key => 'extreme_profile_id'
|
4
|
+
belongs_to :action, :class_name => 'ExtremeAction', :foreign_key => 'extreme_action_id'
|
5
|
+
|
6
|
+
after_initialize :default_values
|
7
|
+
|
8
|
+
def default_values
|
9
|
+
self.volatile ||= false
|
10
|
+
end
|
11
|
+
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
module ExtremeAas
|
2
|
+
class ExtremeProfile < ActiveRecord::Base
|
3
|
+
has_many :grants, :class_name => 'ExtremeGrant', :dependent => :destroy
|
4
|
+
has_many :granted_actions, :through => :grants, :source => :action
|
5
|
+
|
6
|
+
def give_permission action
|
7
|
+
granted_actions << action
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module ExtremeAas
|
2
|
+
class ExtremeSimpleAction < ActiveRecord::Base
|
3
|
+
include ExtremeActionAbstract
|
4
|
+
|
5
|
+
validates :action_name, :uniqueness => { :scope => :controller_name}
|
6
|
+
|
7
|
+
def self.find_action(context)
|
8
|
+
where(:action_name => context[:action_name], :controller_name => context[:controller_name]).first
|
9
|
+
end
|
10
|
+
|
11
|
+
def has_permission? profile
|
12
|
+
return !super_action.grants.where(:extreme_profile_id => profile.id).empty?
|
13
|
+
end
|
14
|
+
|
15
|
+
def volatile?
|
16
|
+
self.volatile == true
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/extreme_aas.gemspec
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# Provide a simple gemspec so you can easily use your enginex
|
2
|
+
# project in your rails apps through git.
|
3
|
+
require File.expand_path("../lib/extreme_aas/version", __FILE__)
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "extreme_aas"
|
7
|
+
s.summary = "Gem for implementing Authentication Authorization System."
|
8
|
+
s.description = "This gem allows you to specify permissions at controller action or helper methods levels."
|
9
|
+
# s.files = Dir["{app,lib,config}/**/*"] + ["MIT-LICENSE", "Rakefile", "Gemfile", "README.rdoc"]
|
10
|
+
s.authors = ["Luis Cruz","Martina Simicic"]
|
11
|
+
s.homepage = "https://github.com/kiddosware/extreme_aas"
|
12
|
+
s.version = ExtremeAas::VERSION
|
13
|
+
|
14
|
+
#Dependencies
|
15
|
+
s.required_rubygems_version = "> 1.3.6"
|
16
|
+
s.add_dependency "rails" , "~> 3.2.2"
|
17
|
+
s.add_dependency "capybara" , ">= 0.4.0"
|
18
|
+
s.add_development_dependency "rspec-rails", "~> 2.5"
|
19
|
+
s.add_development_dependency "factory_girl_rails"
|
20
|
+
s.add_development_dependency 'mysql2'
|
21
|
+
|
22
|
+
#files
|
23
|
+
s.files = `git ls-files`.split("\n")
|
24
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
25
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
26
|
+
s.require_paths = ["lib"]
|
27
|
+
|
28
|
+
|
29
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module ExtremeAas
|
2
|
+
|
3
|
+
class Engine < Rails::Engine
|
4
|
+
|
5
|
+
initializer "extreme_aas.load_app_instance_data" do |app|
|
6
|
+
ExtremeAas.setup do |config|
|
7
|
+
config.app_root = app.root
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
initializer "extreme_aas.load_static_assets" do |app|
|
12
|
+
app.middleware.use ::ActionDispatch::Static, "#{root}/public"
|
13
|
+
end
|
14
|
+
|
15
|
+
initializer 'extreme_aas.app_controller' do |app|
|
16
|
+
ActiveSupport.on_load(:action_controller) do
|
17
|
+
before_filter :extreme_aas_ask_permission
|
18
|
+
include ExtremeAas::ApplicationController
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
data/lib/extreme_aas.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
require "active_support/dependencies"
|
2
|
+
|
3
|
+
module ExtremeAas
|
4
|
+
# Our host application root path
|
5
|
+
# We set this when the engine is initialized
|
6
|
+
mattr_accessor :app_root
|
7
|
+
|
8
|
+
# Yield self on setup for nice config blocks
|
9
|
+
def self.setup
|
10
|
+
yield self
|
11
|
+
end
|
12
|
+
|
13
|
+
# def self.controllers_actions
|
14
|
+
# controllers = Dir.new("#{Rails.root}/app/controllers").entries
|
15
|
+
# controllers.each do |controller|
|
16
|
+
# if controller =~ /_controller/
|
17
|
+
# p cont = controller.camelize.gsub(".rb","")
|
18
|
+
# p Kernel.const_get(cont).action_methods
|
19
|
+
# end
|
20
|
+
# end
|
21
|
+
# end
|
22
|
+
|
23
|
+
end
|
24
|
+
# Require our engine
|
25
|
+
require "extreme_aas/engine"
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'rails/generators'
|
2
|
+
require 'rails/generators/migration'
|
3
|
+
|
4
|
+
class ExtremeAasGenerator < Rails::Generators::Base
|
5
|
+
include Rails::Generators::Migration
|
6
|
+
def self.source_root
|
7
|
+
@source_root ||= File.join(File.dirname(__FILE__), 'templates')
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.next_migration_number(dirname)
|
11
|
+
if ActiveRecord::Base.timestamped_migrations
|
12
|
+
Time.new.utc.strftime("%Y%m%d%H%M%S")
|
13
|
+
else
|
14
|
+
"%.3d" % (current_migration_number(dirname) + 1)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def create_migration_file
|
19
|
+
migration_template 'migration.rb', 'db/migrate/create_extreme_aas_tables.rb'
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
class CreateExtremeAasTables < ActiveRecord::Migration
|
2
|
+
def change
|
3
|
+
create_table :extreme_profiles do |t|
|
4
|
+
t.timestamps
|
5
|
+
end
|
6
|
+
create_table :extreme_grants do |t|
|
7
|
+
t.references :extreme_profile
|
8
|
+
t.references :extreme_action
|
9
|
+
t.boolean :volatile
|
10
|
+
t.timestamps
|
11
|
+
end
|
12
|
+
create_table :extreme_simple_actions do |t|
|
13
|
+
#--------
|
14
|
+
t.string :controller_name
|
15
|
+
t.string :action_name
|
16
|
+
#--------
|
17
|
+
t.string :helper_name
|
18
|
+
t.string :method_name
|
19
|
+
#--------
|
20
|
+
t.timestamps
|
21
|
+
end
|
22
|
+
create_table :extreme_action_groups do |t|
|
23
|
+
t.string :name
|
24
|
+
t.timestamps
|
25
|
+
end
|
26
|
+
create_table :extreme_actions do |t|
|
27
|
+
t.references :actionable, :polymorphic => true
|
28
|
+
t.timestamps
|
29
|
+
end
|
30
|
+
create_table :extreme_action_edges do |t|
|
31
|
+
t.integer :child_action_id
|
32
|
+
t.integer :parent_action_id
|
33
|
+
t.timestamps
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
data/lib/tasks/sync.rake
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
namespace :extreme_aas do
|
2
|
+
|
3
|
+
desc "Sync application actions with extreme_actions in db"
|
4
|
+
task :sync_simple_actions => :environment do
|
5
|
+
sync_simple_actions
|
6
|
+
end
|
7
|
+
|
8
|
+
desc "Export group actions from the configuration"
|
9
|
+
task :export_group_actions => :environment do
|
10
|
+
ExtremeAas::ExtremeActionGroup.export
|
11
|
+
end
|
12
|
+
|
13
|
+
#task: sync and export groups
|
14
|
+
desc "Update Extreme AAS actions"
|
15
|
+
task :update_actions => :environment do
|
16
|
+
Rake::Task["extreme_aas:sync_simple_actions"].invoke
|
17
|
+
Rake::Task["extreme_aas:export_group_actions"].invoke
|
18
|
+
end
|
19
|
+
|
20
|
+
def sync_simple_actions
|
21
|
+
processed_actions_ids = []
|
22
|
+
#Controllers
|
23
|
+
controllers = Dir.new("#{Rails.root}/app/controllers").entries
|
24
|
+
controllers.each do |controller_file|
|
25
|
+
if controller_file =~ /_controller/
|
26
|
+
controller = controller_file.camelize.gsub(".rb","")
|
27
|
+
puts "Processing controller #{controller}"
|
28
|
+
Kernel.const_get(controller).action_methods.each do |controller_action|
|
29
|
+
simple_action = ExtremeAas::ExtremeSimpleAction.find_action(:action_name => controller_action, :controller_name => controller)
|
30
|
+
if simple_action.nil?
|
31
|
+
simple_action = ExtremeAas::ExtremeSimpleAction.create(:controller_name => controller, :action_name => controller_action)
|
32
|
+
end
|
33
|
+
processed_actions_ids << simple_action.id
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
#Helpers
|
38
|
+
helpers = Dir.new("#{Rails.root}/app/helpers").entries
|
39
|
+
helpers.each do |helper_file|
|
40
|
+
if helper_file =~ /_helper/
|
41
|
+
helper = helper_file.camelize.gsub(".rb","")
|
42
|
+
puts "Processing helper #{helper}"
|
43
|
+
Kernel.const_get(helper).instance_method_names.each do |method_name|
|
44
|
+
simple_action = ExtremeAas::ExtremeSimpleAction.find_action(:helper_name => helper, :method_name => method_name)
|
45
|
+
if simple_action.nil?
|
46
|
+
simple_action = ExtremeAas::ExtremeSimpleAction.create(:helper_name => helper, :method_name => method_name)
|
47
|
+
end
|
48
|
+
processed_actions_ids << simple_action.id
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
ExtremeAas::ExtremeSimpleAction.destroy_all(['id NOT IN (?)', processed_actions_ids])
|
53
|
+
puts "We're done here."
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
data/spec/dummy/Rakefile
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
# Add your own tasks in files placed in lib/tasks ending in .rake,
|
2
|
+
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
|
3
|
+
|
4
|
+
require File.expand_path('../config/application', __FILE__)
|
5
|
+
require 'rake'
|
6
|
+
|
7
|
+
Dummy::Application.load_tasks
|
@@ -0,0 +1,56 @@
|
|
1
|
+
body { background-color: #fff; color: #333; }
|
2
|
+
|
3
|
+
body, p, ol, ul, td {
|
4
|
+
font-family: verdana, arial, helvetica, sans-serif;
|
5
|
+
font-size: 13px;
|
6
|
+
line-height: 18px;
|
7
|
+
}
|
8
|
+
|
9
|
+
pre {
|
10
|
+
background-color: #eee;
|
11
|
+
padding: 10px;
|
12
|
+
font-size: 11px;
|
13
|
+
}
|
14
|
+
|
15
|
+
a { color: #000; }
|
16
|
+
a:visited { color: #666; }
|
17
|
+
a:hover { color: #fff; background-color:#000; }
|
18
|
+
|
19
|
+
div.field, div.actions {
|
20
|
+
margin-bottom: 10px;
|
21
|
+
}
|
22
|
+
|
23
|
+
#notice {
|
24
|
+
color: green;
|
25
|
+
}
|
26
|
+
|
27
|
+
.field_with_errors {
|
28
|
+
padding: 2px;
|
29
|
+
background-color: red;
|
30
|
+
display: table;
|
31
|
+
}
|
32
|
+
|
33
|
+
#error_explanation {
|
34
|
+
width: 450px;
|
35
|
+
border: 2px solid red;
|
36
|
+
padding: 7px;
|
37
|
+
padding-bottom: 0;
|
38
|
+
margin-bottom: 20px;
|
39
|
+
background-color: #f0f0f0;
|
40
|
+
}
|
41
|
+
|
42
|
+
#error_explanation h2 {
|
43
|
+
text-align: left;
|
44
|
+
font-weight: bold;
|
45
|
+
padding: 5px 5px 5px 15px;
|
46
|
+
font-size: 12px;
|
47
|
+
margin: -7px;
|
48
|
+
margin-bottom: 0px;
|
49
|
+
background-color: #c00;
|
50
|
+
color: #fff;
|
51
|
+
}
|
52
|
+
|
53
|
+
#error_explanation ul li {
|
54
|
+
font-size: 12px;
|
55
|
+
list-style: square;
|
56
|
+
}
|