adeia 0.0.1 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Rakefile +1 -23
- data/app/assets/javascripts/adeia/application.js +13 -0
- data/app/assets/stylesheets/adeia/application.css +15 -0
- data/app/controllers/adeia/application_controller.rb +4 -0
- data/app/helpers/adeia/application_helper.rb +4 -0
- data/app/models/adeia/action.rb +5 -0
- data/app/models/adeia/action_permission.rb +6 -0
- data/app/models/adeia/element.rb +3 -0
- data/app/models/adeia/group.rb +3 -0
- data/app/models/adeia/group_user.rb +4 -0
- data/app/models/adeia/permission.rb +4 -0
- data/app/models/adeia/token.rb +5 -0
- data/config/locales/en.yml +6 -0
- data/config/locales/fr.yml +6 -0
- data/config/routes.rb +2 -2
- data/db/migrate/20151003144041_create_adeia_elements.rb +9 -0
- data/db/migrate/20151003144208_create_adeia_permissions.rb +16 -0
- data/db/migrate/20151003144650_create_adeia_groups.rb +9 -0
- data/db/migrate/20151003144706_create_adeia_group_users.rb +10 -0
- data/db/migrate/20151003150524_create_adeia_tokens.rb +12 -0
- data/db/migrate/20151003150747_create_adeia_actions.rb +9 -0
- data/db/migrate/20151003150806_create_adeia_action_permissions.rb +10 -0
- data/lib/adeia/authorization.rb +48 -0
- data/lib/adeia/controller_methods.rb +43 -0
- data/lib/adeia/controller_resource.rb +84 -0
- data/lib/adeia/database.rb +52 -0
- data/lib/adeia/engine.rb +8 -0
- data/lib/adeia/exceptions.rb +33 -0
- data/lib/adeia/version.rb +1 -1
- data/test/dummy/app/assets/javascripts/sessions.js +2 -0
- data/test/dummy/app/assets/stylesheets/scaffold.css +56 -0
- data/test/dummy/app/assets/stylesheets/sessions.css +4 -0
- data/test/dummy/app/controllers/application_controller.rb +2 -0
- data/test/dummy/app/controllers/articles_controller.rb +55 -0
- data/test/dummy/app/controllers/sessions_controller.rb +22 -0
- data/test/dummy/app/helpers/sessions_helper.rb +32 -0
- data/test/dummy/app/models/article.rb +3 -0
- data/test/dummy/app/models/user.rb +13 -0
- data/test/dummy/app/views/articles/_form.html.erb +25 -0
- data/test/dummy/app/views/articles/edit.html.erb +6 -0
- data/test/dummy/app/views/articles/index.html.erb +31 -0
- data/test/dummy/app/views/articles/new.html.erb +5 -0
- data/test/dummy/app/views/articles/show.html.erb +19 -0
- data/test/dummy/app/views/layouts/application.html.erb +8 -0
- data/test/dummy/app/views/sessions/new.html.erb +19 -0
- data/test/dummy/config/routes.rb +6 -51
- data/test/dummy/db/development.sqlite3 +0 -0
- data/test/dummy/db/migrate/20150930161522_create_users.rb +11 -0
- data/test/dummy/db/migrate/20150930161532_create_articles.rb +11 -0
- data/test/dummy/db/migrate/20151003145900_create_adeia_elements.adeia.rb +10 -0
- data/test/dummy/db/migrate/20151003145901_create_adeia_permissions.adeia.rb +17 -0
- data/test/dummy/db/migrate/20151003145902_create_adeia_groups.adeia.rb +10 -0
- data/test/dummy/db/migrate/20151003145903_create_adeia_group_users.adeia.rb +11 -0
- data/test/dummy/db/migrate/20151003150941_create_adeia_tokens.adeia.rb +13 -0
- data/test/dummy/db/migrate/20151003150942_create_adeia_actions.adeia.rb +10 -0
- data/test/dummy/db/migrate/20151003150943_create_adeia_action_permissions.adeia.rb +11 -0
- data/test/dummy/db/schema.rb +100 -0
- data/test/dummy/lib/tasks/init.rake +8 -0
- data/test/dummy/log/development.log +4656 -0
- data/test/dummy/test/controllers/articles_controller_test.rb +49 -0
- data/test/dummy/test/controllers/sessions_controller_test.rb +7 -0
- data/test/dummy/test/controllers/users_controller_test.rb +49 -0
- data/test/dummy/test/fixtures/articles.yml +11 -0
- data/test/dummy/test/fixtures/users.yml +9 -0
- data/test/{integration/navigation_test.rb → dummy/test/models/article_test.rb} +1 -2
- data/test/dummy/test/models/user_test.rb +7 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/v3.0/007YZnzCZDb7P0xbxiEkmAM6-xSsxmYu_W7vnrvcDOs.cache +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/v3.0/1GiUoKAP-7ewZyzr_eCTMX0R8ML5Z_VN2bfQ05RAW30.cache +1 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/v3.0/5Lly_CA8DZvPhQV2jDQx-Y6P_y3Ygra9t5jfSlGhHDA.cache +2 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/v3.0/6n6yNyR4eQhIVjw5Anxur-SLgdDc_rzuMuZKj6Q4FqE.cache +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/v3.0/80nWjD2uxLBuIN1R5NawmTsgZWCB6nln8WXf_5gHri4.cache +1 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/v3.0/9Fw_WnCC15QnXUQZ4eYTYLOBv20at5Z5gL-WJx_QsR4.cache +1 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/v3.0/D4VyPOMG_wXgPRZtj-mbRdONJXbdgOZKcuwSm-lNNIA.cache +2 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/v3.0/DmmfrCpXtt74Hr6NO54lxyOCDv6klnDyBqeDFR7oDU8.cache +2 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/v3.0/HggfmBmV-rmvrvzJjqvjmDpwB2BTEQvh6krp0CcrI0U.cache +1 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/v3.0/OI6uxGcnsKavdWTtwDAasU3wPx8QXhzBgV0X2n1KjMQ.cache +2 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/v3.0/P1NOTKHlk-FIwqlw0wiyLanpgNyubwQi850S1aonsbQ.cache +1 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/v3.0/PKcbfub75wwU6UzvVnSMFn_6wsaaPUoXMtWTnyyh5jM.cache +1 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/v3.0/S4dXPkh6wlupsMUb-GvZ2Q5PwAZmplTCkViWCnVWWw0.cache +2 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/v3.0/UuBE6kIOXtWOmnrnywPI98bzHE-L84SteUEfzexxVtA.cache +1 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/v3.0/Xa5LZJIrW7sSuOWWFwCAhDkDQ71pA_cHp6H5kiTZS6E.cache +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/v3.0/eQqoU12FSWEA4BsL-PjwTnIUr1bZsu27SOzFHPomG4c.cache +1 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/v3.0/f3V_hqqK4rH7Z51LFX1Wk9hrWGjYABTZmgSeYvWKgLs.cache +2 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/v3.0/gXIpNlfbH4G7-D0grgt2EuWuwHwTymznc1rlxJ1-C0A.cache +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/v3.0/hX4wt6FzyI47gW66iiVyl2C722yfwvx3KafFEYkreEY.cache +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/v3.0/hZi1k6tpxxCGYxRe7zY74ItcOI8gZrREOpGuA8JSpGg.cache +2 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/v3.0/nZCCAAO-XWnPS2Xr9yss0VhSONvnR3emOuEIc_b-1OY.cache +1 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/v3.0/pEhaat2KBd5SrT7szC_8R1_6hK17FTpvoRFkmCRSD3M.cache +2 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/v3.0/r5qzpye5vWgzwRnRhhSYkUslyNZ11pyYXQZqGe8o930.cache +1 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/v3.0/t0GCJAJcd_7X2F172TjwwDZ6rfNJc2FRbDTV5-jSqY0.cache +1 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/v3.0/t92Y0f7B0gH-r5W-iNadtkzgjm8gxyEyttnY6AWpdmw.cache +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/v3.0/tYGZjTIGEDMySqV7qHf43dq0_aB7TuSEhhZtN_9xW54.cache +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/v3.0/wMjI0_cDi3gmsOV5xXr-QPQOfHCB_qea8St_udeflhE.cache +2 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/v3.0/z2mRCA3647ZviK5pXi1_qLwdxkiCaoIfZj7jHoMfLiI.cache +1 -0
- metadata +179 -12
- data/README.rdoc +0 -3
- data/lib/tasks/adeia_tasks.rake +0 -3
- data/test/adeia_test.rb +0 -7
- data/test/dummy/README.rdoc +0 -28
- data/test/test_helper.rb +0 -20
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4532656038bf240c25749082f7be357f05f7e355
|
4
|
+
data.tar.gz: f0df2615b74907c8fa22038531358c040726a0a2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3d14df596215915a2101d4cdeb2d8ef7138a76aa3ce9371cb44ff3e09ba1f2521e4a028c9abea9550f3bcdeea9799e07bef822790f543bfbfc383c634fdcfb4d
|
7
|
+
data.tar.gz: a90b37a268eaf2eba9c7bcd22deda19378450d7bbfc292ca7d2999bd106b4313c11d43cfafeef8bfbfc00afee53fe41a421982d7a771691d70f772eba9afda79
|
data/Rakefile
CHANGED
@@ -4,15 +4,6 @@ rescue LoadError
|
|
4
4
|
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
5
5
|
end
|
6
6
|
|
7
|
-
require 'rdoc/task'
|
8
|
-
|
9
|
-
RDoc::Task.new(:rdoc) do |rdoc|
|
10
|
-
rdoc.rdoc_dir = 'rdoc'
|
11
|
-
rdoc.title = 'Adeia'
|
12
|
-
rdoc.options << '--line-numbers'
|
13
|
-
rdoc.rdoc_files.include('README.rdoc')
|
14
|
-
rdoc.rdoc_files.include('lib/**/*.rb')
|
15
|
-
end
|
16
7
|
|
17
8
|
APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__)
|
18
9
|
load 'rails/tasks/engine.rake'
|
@@ -21,17 +12,4 @@ load 'rails/tasks/engine.rake'
|
|
21
12
|
load 'rails/tasks/statistics.rake'
|
22
13
|
|
23
14
|
|
24
|
-
|
25
|
-
Bundler::GemHelper.install_tasks
|
26
|
-
|
27
|
-
require 'rake/testtask'
|
28
|
-
|
29
|
-
Rake::TestTask.new(:test) do |t|
|
30
|
-
t.libs << 'lib'
|
31
|
-
t.libs << 'test'
|
32
|
-
t.pattern = 'test/**/*_test.rb'
|
33
|
-
t.verbose = false
|
34
|
-
end
|
35
|
-
|
36
|
-
|
37
|
-
task default: :test
|
15
|
+
Bundler::GemHelper.install_tasks
|
@@ -0,0 +1,13 @@
|
|
1
|
+
// This is a manifest file that'll be compiled into application.js, which will include all the files
|
2
|
+
// listed below.
|
3
|
+
//
|
4
|
+
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
|
5
|
+
// or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
|
6
|
+
//
|
7
|
+
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
|
8
|
+
// compiled file.
|
9
|
+
//
|
10
|
+
// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
|
11
|
+
// about supported directives.
|
12
|
+
//
|
13
|
+
//= require_tree .
|
@@ -0,0 +1,15 @@
|
|
1
|
+
/*
|
2
|
+
* This is a manifest file that'll be compiled into application.css, which will include all the files
|
3
|
+
* listed below.
|
4
|
+
*
|
5
|
+
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
|
6
|
+
* or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
|
7
|
+
*
|
8
|
+
* You're free to add application-wide styles to this file and they'll appear at the bottom of the
|
9
|
+
* compiled file so the styles you add here take precedence over styles defined in any styles
|
10
|
+
* defined in the other CSS/SCSS files in this directory. It is generally better to create a new
|
11
|
+
* file per style scope.
|
12
|
+
*
|
13
|
+
*= require_tree .
|
14
|
+
*= require_self
|
15
|
+
*/
|
data/config/routes.rb
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
|
2
|
-
end
|
1
|
+
Adeia::Engine.routes.draw do
|
2
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
class CreateAdeiaPermissions < ActiveRecord::Migration
|
2
|
+
def change
|
3
|
+
create_table :adeia_permissions do |t|
|
4
|
+
t.references :owner, polymorphic: true, index: true
|
5
|
+
t.references :element, index: true, foreign_key: true
|
6
|
+
t.integer :permission_type
|
7
|
+
t.boolean :read_right
|
8
|
+
t.boolean :create_right
|
9
|
+
t.boolean :update_right
|
10
|
+
t.boolean :destroy_right
|
11
|
+
t.integer :resource_id
|
12
|
+
|
13
|
+
t.timestamps null: false
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
class CreateAdeiaGroupUsers < ActiveRecord::Migration
|
2
|
+
def change
|
3
|
+
create_table :adeia_group_users do |t|
|
4
|
+
t.references :group, index: true, foreign_key: true
|
5
|
+
t.references :user, index: true, foreign_key: true
|
6
|
+
|
7
|
+
t.timestamps null: false
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
class CreateAdeiaTokens < ActiveRecord::Migration
|
2
|
+
def change
|
3
|
+
create_table :adeia_tokens do |t|
|
4
|
+
t.string :token
|
5
|
+
t.boolean :valid
|
6
|
+
t.references :permission, index: true, foreign_key: true
|
7
|
+
t.date :exp_at
|
8
|
+
|
9
|
+
t.timestamps null: false
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
class CreateAdeiaActionPermissions < ActiveRecord::Migration
|
2
|
+
def change
|
3
|
+
create_table :adeia_action_permissions do |t|
|
4
|
+
t.references :action, index: true, foreign_key: true
|
5
|
+
t.references :permission, index: true, foreign_key: true
|
6
|
+
|
7
|
+
t.timestamps null: false
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'adeia/database'
|
2
|
+
require 'adeia/exceptions'
|
3
|
+
|
4
|
+
module Adeia
|
5
|
+
|
6
|
+
class Authorization < Database
|
7
|
+
|
8
|
+
def authorize!
|
9
|
+
@rights = token_rights(right_name)
|
10
|
+
raise LoginRequired if @rights.empty? && @user.nil?
|
11
|
+
@rights.push(send("#{right_name}_rights")) if @user
|
12
|
+
raise AccessDenied unless authorize?
|
13
|
+
end
|
14
|
+
|
15
|
+
def can?
|
16
|
+
@rights = token_rights.push(send("#{right_name}_rights"))
|
17
|
+
authorize?
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def authorize?
|
23
|
+
all_entries? || on_ownerships? || on_entry?
|
24
|
+
end
|
25
|
+
|
26
|
+
def all_entries?
|
27
|
+
@rights.any? { |r| r.permission_type == "all_entries" }
|
28
|
+
end
|
29
|
+
|
30
|
+
def on_ownerships?
|
31
|
+
@rights.any? { |r| r.permission_type == "on_ownerships" } && @user && @resource.try(:user) == @user
|
32
|
+
end
|
33
|
+
|
34
|
+
def on_entry?
|
35
|
+
@rights.pluck(:resource_id).compact.include? @resource.try(:id)
|
36
|
+
end
|
37
|
+
|
38
|
+
def right_names
|
39
|
+
{read: [:index, :show], create: [:new, :create], update: [:edit, :update], destroy: [:destroy]}
|
40
|
+
end
|
41
|
+
|
42
|
+
def right_name
|
43
|
+
right_names.select { |k, v| v.include? @action.to_sym }.keys[0] || :action
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'adeia/controller_resource'
|
2
|
+
|
3
|
+
module Adeia
|
4
|
+
|
5
|
+
module ControllerMethods
|
6
|
+
|
7
|
+
module ClassMethods
|
8
|
+
|
9
|
+
def load_and_authorize(**args)
|
10
|
+
ControllerResource.add_before_filter(self, :load_resoure_or_records_and_authorize, **args)
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.included(base)
|
16
|
+
base.extend ClassMethods
|
17
|
+
base.helper_method :can?
|
18
|
+
end
|
19
|
+
|
20
|
+
def load_and_authorize!(**args)
|
21
|
+
controller_resource = ControllerResource.new(self, **args)
|
22
|
+
resource = controller_resource.load_resource
|
23
|
+
controller_resource.authorize!
|
24
|
+
return resource
|
25
|
+
end
|
26
|
+
|
27
|
+
def authorize_and_load_records!(**args)
|
28
|
+
controller_resource = ControllerResource.new(self, **args)
|
29
|
+
controller_resource.authorize!
|
30
|
+
return controller_resource.load_records
|
31
|
+
end
|
32
|
+
|
33
|
+
def authorize!(**args)
|
34
|
+
ControllerResource.new(self, **args).authorize!
|
35
|
+
end
|
36
|
+
|
37
|
+
def can?(action, controller=nil, resource=nil)
|
38
|
+
args = { action: action, controller: controller, resource: resource }
|
39
|
+
ControllerResource.new(self, **args).can?
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
@@ -0,0 +1,84 @@
|
|
1
|
+
require 'adeia/authorization'
|
2
|
+
require 'adeia/exceptions'
|
3
|
+
|
4
|
+
module Adeia
|
5
|
+
|
6
|
+
class ControllerResource
|
7
|
+
|
8
|
+
def self.add_before_filter(controller_class, method, **args)
|
9
|
+
controller_class.send(:before_action, args.slice(:only, :except, :if, :unless)) do |controller|
|
10
|
+
ControllerResource.send(method, controller)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.load_resoure_or_records_and_authorize(controller)
|
15
|
+
if controller.action_name == "index"
|
16
|
+
controller.authorize_and_load_records!
|
17
|
+
else
|
18
|
+
controller.load_and_authorize!
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def initialize(controller, **args)
|
23
|
+
@controller = controller
|
24
|
+
@action_name = args.fetch(:action, @controller.action_name)
|
25
|
+
@controller_name = args.fetch(:controller, @controller.controller_path)
|
26
|
+
@token = args.fetch(:token, @controller.params[:token])
|
27
|
+
@resource = args[:resource]
|
28
|
+
@user = @controller.current_user
|
29
|
+
end
|
30
|
+
|
31
|
+
def load_resource
|
32
|
+
begin
|
33
|
+
@resource = resource_class.find(@controller.params.fetch(:id))
|
34
|
+
@controller.instance_variable_set("@#{resource_name}", @resource)
|
35
|
+
rescue KeyError
|
36
|
+
raise MissingParams.new(:id)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def load_records
|
41
|
+
rights = authorization.read_rights + authorization.token_rights
|
42
|
+
resource_ids = rights.pluck(:resource_id).compact
|
43
|
+
@records ||= if rights.any? { |r| r.permission_type == "all_entries" }
|
44
|
+
resource_class.all
|
45
|
+
elsif rights.any? { |r| r.permission_type == "on_ownerships" }
|
46
|
+
resource_class.where(user_id: @user.id, id: resource_ids)
|
47
|
+
elsif rights.any? { |r| r.permission_type == "on_entry" }
|
48
|
+
resource_class.where(id: resource_ids)
|
49
|
+
else
|
50
|
+
resource_class.none
|
51
|
+
end
|
52
|
+
@controller.instance_variable_set("@#{resource_name.pluralize}", @records)
|
53
|
+
end
|
54
|
+
|
55
|
+
def authorization
|
56
|
+
@authorization ||= Authorization.new(@controller_name, @action_name, @token, @resource, @user)
|
57
|
+
end
|
58
|
+
|
59
|
+
|
60
|
+
def authorize!
|
61
|
+
authorization.authorize!
|
62
|
+
end
|
63
|
+
|
64
|
+
def can?
|
65
|
+
authorization.can?
|
66
|
+
end
|
67
|
+
|
68
|
+
private
|
69
|
+
|
70
|
+
def resource_class
|
71
|
+
begin
|
72
|
+
@controller.controller_path.classify.constantize
|
73
|
+
rescue NameError
|
74
|
+
@controller.controller_name.classify.constantize
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
def resource_name
|
79
|
+
resource_class.model_name.element
|
80
|
+
end
|
81
|
+
|
82
|
+
end
|
83
|
+
|
84
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
module Adeia
|
2
|
+
|
3
|
+
class Database
|
4
|
+
|
5
|
+
def initialize(controller, action, token, resource, user)
|
6
|
+
@controller = controller
|
7
|
+
@action = action
|
8
|
+
@token = token
|
9
|
+
@resource = resource
|
10
|
+
@user = user
|
11
|
+
end
|
12
|
+
|
13
|
+
def read_rights
|
14
|
+
@read_rights ||= Adeia::Permission.joins(:element).where(owner: owners, read_right: true, elements: {name: @controller})
|
15
|
+
end
|
16
|
+
|
17
|
+
def create_rights
|
18
|
+
@create_rights ||= Adeia::Permission.joins(:element).where(owner: owners, create_right: true, elements: {name: @controller})
|
19
|
+
end
|
20
|
+
|
21
|
+
def update_rights
|
22
|
+
@update_rights ||= Adeia::Permission.joins(:element).where(owner: owners, update_right: true, elements: {name: @controller})
|
23
|
+
end
|
24
|
+
|
25
|
+
def destroy_rights
|
26
|
+
@destroy_rights ||= Adeia::Permission.joins(:element).where(owner: owners, destroy_right: true, elements: {name: @controller})
|
27
|
+
end
|
28
|
+
|
29
|
+
def action_rights
|
30
|
+
@action_rights ||= Adeia::Permission.joins(:actions, :element).where(owner: owners, elements: {name: @controller}, actions: {name: @action})
|
31
|
+
end
|
32
|
+
|
33
|
+
def token_rights(right_name)
|
34
|
+
@permission_token ||= Adeia::Token.find_by_token(@token)
|
35
|
+
if @permission_token && @permission_token.valid
|
36
|
+
@token_rights ||= Adeia::Permission.joins(:element).where("ownerships.id = ? AND elements.name = ? AND #{right_name}_right = ?", @permission_token.permission_id, @controller, true)
|
37
|
+
else
|
38
|
+
@token_rights ||= Adeia::Permission.none
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def user_groups
|
43
|
+
@user_groups ||= Adeia::Group.joins(:group_users).where(adeia_group_users: { user_id: @user.id })
|
44
|
+
end
|
45
|
+
|
46
|
+
def owners
|
47
|
+
@owners ||= user_groups.push @user
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
data/lib/adeia/engine.rb
CHANGED
@@ -0,0 +1,33 @@
|
|
1
|
+
module Adeia
|
2
|
+
|
3
|
+
class Error < StandardError; end
|
4
|
+
|
5
|
+
class LoginRequired < Error
|
6
|
+
|
7
|
+
def to_s
|
8
|
+
I18n.t("exceptions.messages.login_required")
|
9
|
+
end
|
10
|
+
|
11
|
+
end
|
12
|
+
|
13
|
+
class AccessDenied < Error
|
14
|
+
|
15
|
+
def to_s
|
16
|
+
I18n.t("exceptions.messages.access_denied")
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
class MissingParams < Error
|
22
|
+
|
23
|
+
def initialize(params)
|
24
|
+
@params = params
|
25
|
+
end
|
26
|
+
|
27
|
+
def to_s
|
28
|
+
I18n.t("exceptions.messages.missing_params", params: @params)
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
data/lib/adeia/version.rb
CHANGED
@@ -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
|
+
}
|
@@ -0,0 +1,55 @@
|
|
1
|
+
class ArticlesController < ApplicationController
|
2
|
+
before_action :set_article, only: [:show, :edit, :update, :destroy]
|
3
|
+
load_and_authorize
|
4
|
+
|
5
|
+
def index
|
6
|
+
#@articles = Article.all
|
7
|
+
#authorize_and_load_records!
|
8
|
+
end
|
9
|
+
|
10
|
+
def show
|
11
|
+
#load_and_authorize!
|
12
|
+
end
|
13
|
+
|
14
|
+
def new
|
15
|
+
#authorize!
|
16
|
+
@article = Article.new
|
17
|
+
end
|
18
|
+
|
19
|
+
def edit
|
20
|
+
#load_and_authorize!
|
21
|
+
end
|
22
|
+
|
23
|
+
def create
|
24
|
+
@article = Article.new(article_params)
|
25
|
+
@article.user = current_user
|
26
|
+
if @article.save
|
27
|
+
redirect_to @article, notice: 'Article was successfully created.'
|
28
|
+
else
|
29
|
+
render :new
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def update
|
34
|
+
if @article.update(article_params)
|
35
|
+
redirect_to @article, notice: 'Article was successfully updated.'
|
36
|
+
else
|
37
|
+
render :edit
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def destroy
|
42
|
+
@article.destroy
|
43
|
+
redirect_to articles_url, notice: 'Article was successfully destroyed.'
|
44
|
+
end
|
45
|
+
|
46
|
+
private
|
47
|
+
|
48
|
+
def set_article
|
49
|
+
@article = Article.find(params[:id])
|
50
|
+
end
|
51
|
+
|
52
|
+
def article_params
|
53
|
+
params.require(:article).permit(:title, :content)
|
54
|
+
end
|
55
|
+
end
|