back_office 0.1.4 → 0.2.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.
- checksums.yaml +4 -4
- data/lib/back_office.rb +2 -4
- data/lib/back_office/auth.rb +3 -7
- data/lib/back_office/{authorization.rb → policy.rb} +1 -5
- data/lib/back_office/rest.rb +0 -12
- data/lib/back_office/version.rb +1 -1
- metadata +3 -5
- data/lib/back_office/cursor.rb +0 -16
- data/lib/back_office/searchable.rb +0 -69
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4f5973d945fd8e5a7061041fc06e2dfd59cf9b07
|
4
|
+
data.tar.gz: eaaeef8494c87eec794e9042cb7403056713c86e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e167fb45820b38c1af60ba4b05fbaf5ccf5123fd9bb94b2e994ee685168b56fdc80ff3bf9d44cd694dfb12fd03a1b83ef3890be730c44dbcd0c9f754d4790033
|
7
|
+
data.tar.gz: 1c758dcb9f969609f6232e42773cba34b69a12b59e500a274f28513b13a38a4132c9f048cb1754437258f482383fa3725cf4a206bc9da8933f6f5ea07fb110a4
|
data/lib/back_office.rb
CHANGED
@@ -1,11 +1,9 @@
|
|
1
1
|
require 'back_office/engine'
|
2
2
|
require 'back_office/auth'
|
3
|
-
require 'back_office/rest'
|
4
|
-
require 'back_office/authorization'
|
5
|
-
require 'back_office/cursor'
|
6
3
|
require 'back_office/password'
|
4
|
+
require 'back_office/policy'
|
7
5
|
require 'back_office/reset'
|
8
|
-
require 'back_office/
|
6
|
+
require 'back_office/rest'
|
9
7
|
|
10
8
|
module BackOffice
|
11
9
|
def self.verifier
|
data/lib/back_office/auth.rb
CHANGED
@@ -5,7 +5,7 @@ module BackOffice
|
|
5
5
|
included do
|
6
6
|
before_action :authorize
|
7
7
|
delegate :current_user, to: :current_device
|
8
|
-
delegate :authorized?, to: :
|
8
|
+
delegate :authorized?, to: :policy
|
9
9
|
helper_method :current_user, :authorized?
|
10
10
|
end
|
11
11
|
|
@@ -46,12 +46,8 @@ module BackOffice
|
|
46
46
|
end
|
47
47
|
end
|
48
48
|
|
49
|
-
def
|
50
|
-
@
|
51
|
-
end
|
52
|
-
|
53
|
-
def authorization_class
|
54
|
-
"#{self.class.parent_name || 'Application'}Authorization".constantize
|
49
|
+
def policy
|
50
|
+
@policy ||= Policy.new(current_user)
|
55
51
|
end
|
56
52
|
|
57
53
|
def resource
|
@@ -1,9 +1,5 @@
|
|
1
1
|
module BackOffice
|
2
|
-
|
3
|
-
def initialize(current_user)
|
4
|
-
raise NotImplementedError
|
5
|
-
end
|
6
|
-
|
2
|
+
module Policy
|
7
3
|
def authorized?(controller, action, resource = nil)
|
8
4
|
if rule = rules.dig(controller.to_sym, action.to_sym)
|
9
5
|
rule == true || resource && rule.call(resource)
|
data/lib/back_office/rest.rb
CHANGED
@@ -2,10 +2,6 @@ module BackOffice
|
|
2
2
|
module Rest
|
3
3
|
extend ActiveSupport::Concern
|
4
4
|
|
5
|
-
def index
|
6
|
-
@cursor = BackOffice::Cursor.new(default_scope, params, cursor_options)
|
7
|
-
end
|
8
|
-
|
9
5
|
def create
|
10
6
|
resource.attributes = resource_params
|
11
7
|
|
@@ -66,14 +62,6 @@ module BackOffice
|
|
66
62
|
{}
|
67
63
|
end
|
68
64
|
|
69
|
-
def default_scope
|
70
|
-
resource_class.order(created_at: :desc)
|
71
|
-
end
|
72
|
-
|
73
|
-
def cursor_options
|
74
|
-
{}
|
75
|
-
end
|
76
|
-
|
77
65
|
def success
|
78
66
|
respond_to do |format|
|
79
67
|
format.js
|
data/lib/back_office/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: back_office
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gustavo Beathyate
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-02-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -51,13 +51,11 @@ files:
|
|
51
51
|
- config/routes.rb
|
52
52
|
- lib/back_office.rb
|
53
53
|
- lib/back_office/auth.rb
|
54
|
-
- lib/back_office/authorization.rb
|
55
|
-
- lib/back_office/cursor.rb
|
56
54
|
- lib/back_office/engine.rb
|
57
55
|
- lib/back_office/password.rb
|
56
|
+
- lib/back_office/policy.rb
|
58
57
|
- lib/back_office/reset.rb
|
59
58
|
- lib/back_office/rest.rb
|
60
|
-
- lib/back_office/searchable.rb
|
61
59
|
- lib/back_office/version.rb
|
62
60
|
- lib/tasks/back_office_tasks.rake
|
63
61
|
homepage: http://goddamnhippie.github.io/back_office
|
data/lib/back_office/cursor.rb
DELETED
@@ -1,16 +0,0 @@
|
|
1
|
-
module BackOffice
|
2
|
-
class Cursor
|
3
|
-
attr_reader :scopes, :params, :options
|
4
|
-
|
5
|
-
def initialize(default_scope, params, options = {})
|
6
|
-
@scopes = Hash.new(default_scope).merge!(options.delete(:scopes) || {})
|
7
|
-
@params = params.permit(:scope, :query, :sort, :page, :filters).to_h
|
8
|
-
@options = options
|
9
|
-
@scope = params[:scope].to_s
|
10
|
-
end
|
11
|
-
|
12
|
-
def results
|
13
|
-
scopes[@scope.to_sym].search(params)
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
@@ -1,69 +0,0 @@
|
|
1
|
-
module BackOffice
|
2
|
-
module Searchable
|
3
|
-
extend ActiveSupport::Concern
|
4
|
-
|
5
|
-
included do
|
6
|
-
include PgSearch
|
7
|
-
searchable_by :id
|
8
|
-
end
|
9
|
-
|
10
|
-
class_methods do
|
11
|
-
def sort_options
|
12
|
-
@sort_options ||= {}
|
13
|
-
end
|
14
|
-
|
15
|
-
def default_searchable_options
|
16
|
-
{
|
17
|
-
against: [],
|
18
|
-
using: { tsearch: { prefix: true } }
|
19
|
-
}
|
20
|
-
end
|
21
|
-
|
22
|
-
def searchable_by(*attrs)
|
23
|
-
options = attrs.extract_options!
|
24
|
-
scope_options = default_searchable_options.deep_merge(options).merge!(against: attrs)
|
25
|
-
|
26
|
-
pg_search_scope(:search_by_query, scope_options)
|
27
|
-
end
|
28
|
-
|
29
|
-
def filterable_by(key, filter_scope = nil)
|
30
|
-
scope("filter_#{key}", filter_scope || ->(filter_param) { where(key => filter_param) })
|
31
|
-
end
|
32
|
-
|
33
|
-
def filter_with(key, value)
|
34
|
-
send("filter_#{key}", value)
|
35
|
-
end
|
36
|
-
|
37
|
-
def sortable_by(key, asc_statement, desc_statement = nil)
|
38
|
-
sort_options[key.to_s] = asc_statement
|
39
|
-
sort_options["-#{key}"] = desc_statement || asc_statement.gsub(/ASC/i, 'DESC')
|
40
|
-
end
|
41
|
-
|
42
|
-
def sort_with(param)
|
43
|
-
sort_statement = sort_options.fetch(param) do
|
44
|
-
sort_parts = param.split('-')
|
45
|
-
sort_direction = sort_parts.length > 1 ? 'DESC' : 'ASC'
|
46
|
-
sort_column = sort_parts.last
|
47
|
-
sort_column = :created_at unless column_names.include?(sort_column)
|
48
|
-
|
49
|
-
"#{table_name}.#{sort_column} #{sort_direction}"
|
50
|
-
end
|
51
|
-
|
52
|
-
reorder(sort_statement)
|
53
|
-
end
|
54
|
-
|
55
|
-
def search(params)
|
56
|
-
results = page(params[:page])
|
57
|
-
|
58
|
-
params.fetch(:filters, {}).each do |filter_name, filter_value|
|
59
|
-
results = results.filter_with(filter_name, filter_value) if filter_value.present?
|
60
|
-
end
|
61
|
-
|
62
|
-
results = results.search_by_query(params[:query]) if params[:query].present?
|
63
|
-
results = results.sort_with(params[:sort]) if params[:sort].present?
|
64
|
-
|
65
|
-
results
|
66
|
-
end
|
67
|
-
end
|
68
|
-
end
|
69
|
-
end
|