faalis 0.21.1 → 0.22.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 14da634aef8853abbd8af125b967c93b01c6e193
4
- data.tar.gz: dd943a9315c2d293c90dc709bbd50fd4225a1b11
3
+ metadata.gz: 6e8d41e6694f09b9f411168fdc7c05b22d7c5b8e
4
+ data.tar.gz: b3d20ddff941a3df2083b5626b0ef4debb38498d
5
5
  SHA512:
6
- metadata.gz: 9956fb8de054298606c4e51bd4cb259d140cf75203b3eb85c6f663789f447ad4109fae8745b5c978b4b14c4fd61fcb8d03b230d6622524448d4f821445eba028
7
- data.tar.gz: 8fec4fb4f4858e8ff667c1b42a13833cc34a5b8eee6a60c41d158b491a5f5020a418311e7c5ed225b723d7e578857961afc183214d060ccfc8effc360d749344
6
+ metadata.gz: ef9024980abb5ec1328edf5ebe2a679c2c8651012bc2d68b60e2bd196e25e88c37634d86937303e90bb38c320f1e760afd485802d47cfa1cd5cca5c58f34b65a
7
+ data.tar.gz: bc7b648b808430fcab1809ad3f4d48d54105358af78cded20b5d4d700899d9191b35229ec5f41582d3c19162c4559ea1a36abd47cde9b859e05f98ee1795380e
@@ -0,0 +1,16 @@
1
+ module Faalis
2
+ module Concerns
3
+ # This **concern** provide the default query loading scope for model.
4
+ # Using this, you can make queries like key=value in http request
5
+ # and Model.assignment(key: value) on you model.
6
+ module Assignment
7
+
8
+ def self.included(base)
9
+ base.scope :assignment_query, -> (field, value) do
10
+ base.where(field => value)
11
+ end
12
+ end
13
+
14
+ end
15
+ end
16
+ end
@@ -9,3 +9,4 @@ require "faalis/generators/concerns/angular"
9
9
  require "faalis/generators/concerns/tabs"
10
10
  require "faalis/generators/concerns/model"
11
11
  require "faalis/generators/concerns/json_input"
12
+ require "faalis/generators/concerns/allow_query_on"
@@ -0,0 +1,38 @@
1
+ module Faalis
2
+ module Generators
3
+ module Concerns
4
+ # This module adds `allow_query_on` key to json file which is an array
5
+ # of field name which you want to whitelist for query.
6
+ module AllowQueryOn
7
+
8
+ private
9
+
10
+
11
+ def allowed_fields
12
+ if allowed_fields_provided?
13
+ unless resource_data["allow_query_on"].is_a? Array
14
+ raise Exception.new "value of `allow_query_on` key should be an Array. "
15
+ end
16
+ fields = resource_data["allow_query_on"].collect do |f|
17
+ ":#{f}"
18
+ end
19
+ fields.join(" ,")
20
+ else
21
+ []
22
+ end
23
+ end
24
+
25
+ # Check for any allowed fields in json
26
+ def allowed_fields_provided?
27
+ if resource_data.include? "allow_query_on"
28
+ unless resource_data["allow_query_on"].nil?
29
+ return true
30
+ end
31
+ end
32
+ false
33
+ end
34
+
35
+ end
36
+ end
37
+ end
38
+ end
@@ -14,7 +14,7 @@ module Faalis
14
14
  private
15
15
 
16
16
  def required_fields
17
- fields_with("required", true)
17
+ fields_with("required", true).collect {|x| x["name"]}
18
18
  end
19
19
  end
20
20
  end
@@ -46,17 +46,17 @@ module Faalis
46
46
  def fields
47
47
  fields = []
48
48
  if have_fields?
49
- resource_data["fields"].each do |field|
50
- name = field["name"]
51
- type = field["type"]
52
- to = field["to"]
53
- options = field["options"] || {}
54
-
55
- if ["belongs_to", "has_many", "in"].include? type
56
- type = Relation.new(type, to, options)
57
- end
49
+ resource_data["fields"].each do |field|
50
+ name = field["name"]
51
+ type = field["type"]
52
+ to = field["to"]
53
+ options = field["options"] || {}
54
+
55
+ if ["belongs_to", "has_many", "in"].include? type
56
+ type = Relation.new(type, to, options)
57
+ end
58
58
 
59
- fields << [name, type]
59
+ fields << [name, type]
60
60
  end
61
61
  end
62
62
  fields
@@ -109,10 +109,20 @@ module Faalis
109
109
  result
110
110
  end
111
111
 
112
+ def raw_fields_data
113
+ if have_fields?
114
+ return resource_data["fields"]
115
+ end
116
+ []
117
+ end
118
+
112
119
  def fields_with(attr, value)
113
- fields.select do |f|
120
+ raw_fields_data.select do |f|
121
+
114
122
  if f.include? attr
123
+
115
124
  if f[attr] == value
125
+
116
126
  true
117
127
  else
118
128
  false
@@ -125,11 +135,11 @@ module Faalis
125
135
  end
126
136
 
127
137
  def no_filter?
128
- resource_data.include? "no_filter" && resource_data["no_filter"]
138
+ resource_data.include?("no_filter") && resource_data["no_filter"]
129
139
  end
130
140
 
131
141
  def have_fields?
132
- unless resource_data.include? "fields"
142
+ if resource_data.include? "fields"
133
143
  unless resource_data["fields"].nil?
134
144
  return true
135
145
  end
@@ -17,6 +17,7 @@ module Faalis
17
17
  include Faalis::Generators::Concerns::Angular
18
18
  include Faalis::Generators::Concerns::Tabs
19
19
  include Faalis::Generators::Concerns::Model
20
+ include Faalis::Generators::Concerns::AllowQueryOn
20
21
 
21
22
 
22
23
  # Do not install specs
@@ -18,5 +18,5 @@
18
18
  # -----------------------------------------------------------------------------
19
19
 
20
20
  module Faalis
21
- VERSION = "0.21.1"
21
+ VERSION = "0.22.0"
22
22
  end
@@ -1,4 +1,5 @@
1
1
  class API::V1::<%= resource.pluralize %>Controller < APIController
2
+ <% if allowed_fields_provided? %>allow_query_on <%= allowed_fields %><% end %>
2
3
  before_filter :build_resource, :only => :create
3
4
  <% if parent? %><% all_parents = parents %><% prev = all_parents.shift %>
4
5
  load_and_authorize_resource :<%= prev.singularize %>, :except => [:destory]
@@ -55,7 +55,7 @@
55
55
  </div>
56
56
  </div>
57
57
  <% end %>
58
- <list-view buttons="buttons" model="'<% if model_specified? %><%= model %><% else %><%= resource %><% end %>'" objects="<%= resource.pluralize.underscore %>" title-attribute="'<%= resource_data["title_field"] %>'" details-template="details_template" item-per-page="10" on_delete="on_delete" column_defs="columns">
58
+ <list-view buttons="buttons" model="'<% if model_specified? %><%= model %><% else %><%= resource %><% end %>'" objects="<%= resource.pluralize.underscore %>" title-attribute="'<%= resource_data["title-field"] %>'" details-template="details_template" item-per-page="10" on_delete="on_delete" column_defs="columns">
59
59
  <div class="small-6 column text-left clearpadding">
60
60
  <h3><i class="fa fa-group"></i> <span translate><%= resource.underscore.pluralize.humanize %></span></h3>
61
61
  </div>
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: faalis
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.21.1
4
+ version: 0.22.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sameer Rahmani
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-03-17 00:00:00.000000000 Z
12
+ date: 2014-03-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -477,6 +477,7 @@ files:
477
477
  - app/helpers/faalis/home_helper.rb
478
478
  - app/helpers/faalis/users_helper.rb
479
479
  - app/models/ability.rb
480
+ - app/models/faalis/concerns/assignment.rb
480
481
  - app/models/faalis/group.rb
481
482
  - app/models/faalis/permission.rb
482
483
  - app/models/faalis/permissions/auth.rb
@@ -590,6 +591,7 @@ files:
590
591
  - lib/faalis/exceptions.rb
591
592
  - lib/faalis/generators.rb
592
593
  - lib/faalis/generators/concerns.rb
594
+ - lib/faalis/generators/concerns/allow_query_on.rb
593
595
  - lib/faalis/generators/concerns/angular.rb
594
596
  - lib/faalis/generators/concerns/bulk.rb
595
597
  - lib/faalis/generators/concerns/dependency.rb