-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
25 changed files
with
344 additions
and
125 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,32 @@ | ||
# Test against 3.2 -> 4.2 | ||
# | ||
appraise 'rails-3.2' do | ||
appraise 'rails-3.2-pg' do | ||
gem 'rails', '~> 3.2.0' | ||
gem 'pg' | ||
gem 'activerecord-postgres-json' | ||
end | ||
|
||
appraise 'rails-4.0' do | ||
appraise 'rails-4.0-pg' do | ||
gem 'rails', '~> 4.0.0' | ||
gem 'pg' | ||
end | ||
|
||
appraise 'rails-4.1' do | ||
appraise 'rails-4.1-pg' do | ||
gem 'rails', '~> 4.1.0' | ||
gem 'pg' | ||
end | ||
|
||
appraise 'rails-4.2' do | ||
appraise 'rails-4.2-pg' do | ||
gem 'rails', '~> 4.2.0' | ||
gem 'pg' | ||
end | ||
|
||
appraise 'rails-5.0-pg' do | ||
gem 'rails', '~> 5.0.0' | ||
gem 'pg' | ||
end | ||
|
||
appraise 'rails-4.2-mysql' do | ||
gem 'rails', '~> 4.2.0' | ||
gem 'mysql' | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# This file was generated by Appraisal | ||
|
||
source "https://rubygems.org" | ||
|
||
gem "rails", "~> 4.2.0" | ||
gem "mysql" | ||
|
||
gemspec :path => "../" |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
module Eaco | ||
module Adapters | ||
module ActiveRecord | ||
|
||
## | ||
# Authorized collection extractor on MySQL >= 5.7 and a +json+ | ||
# column named +acl+. | ||
# | ||
# TODO negative authorizations (using a separate column?) | ||
# | ||
# @see ACL | ||
# @see Actor | ||
# @see Resource | ||
# | ||
module MySQLJSON | ||
|
||
## | ||
# Uses +JSON_CONTAINS_PATH()+ to check whether one of the +Actor+'s | ||
# +Designator+ instances exist as keys in the +ACL+ object. | ||
# | ||
# @param actor [Actor] | ||
# | ||
# @return [ActiveRecord::Relation] the authorized collection scope. | ||
# | ||
def accessible_by(actor) | ||
return scoped if actor.is_admin? | ||
|
||
designators = actor.designators.map {|d| sanitize("$.#{d}") } | ||
|
||
column = "#{connection.quote_table_name(table_name)}.acl" | ||
|
||
where("JSON_CONTAINS_PATH(#{column}, 'one', #{designators.join(',')})") | ||
end | ||
|
||
## | ||
# Checks whether the model's data structure fulfills | ||
# the ACL persistance requirements. | ||
# | ||
def self.validate!(model) | ||
return unless model.table_exists? | ||
|
||
column = model.columns_hash.fetch('acl', nil) | ||
|
||
unless column | ||
raise Malformed, "Please define a json column named `acl` on #{model}." | ||
end | ||
|
||
unless column.type == required_column_type | ||
raise Malformed, "The `acl` column on #{model} must be of the JSON type - found: #{column.type}." | ||
end | ||
end | ||
|
||
def self.required_column_type | ||
:json | ||
end | ||
end | ||
|
||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
lib/eaco/adapters/active_record/postgres_jsonb/compatibility.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
module Eaco | ||
module Adapters | ||
module ActiveRecord | ||
module PostgresJSONb | ||
class Compatibility < Eaco::Adapters::ActiveRecord::Compatibility | ||
autoload :V32, 'eaco/adapters/active_record/postgres_jsonb/compatibility/v32.rb' | ||
autoload :V40, 'eaco/adapters/active_record/postgres_jsonb/compatibility/v40.rb' | ||
autoload :V41, 'eaco/adapters/active_record/postgres_jsonb/compatibility/v41.rb' | ||
autoload :V42, 'eaco/adapters/active_record/postgres_jsonb/compatibility/v42.rb' | ||
autoload :V50, 'eaco/adapters/active_record/postgres_jsonb/compatibility/v50.rb' | ||
end | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.