faalis 0.20.0 → 0.21.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5b6bebb09df183b7dee476937557f6891913cb06
4
- data.tar.gz: 7641a768cd23e508dd287ab678301916716259f8
3
+ metadata.gz: e7d77be09881beddd4d13f35ae2ad54576a8ecaf
4
+ data.tar.gz: 95fac973732a6d0be6cd34a359e71b1d58592201
5
5
  SHA512:
6
- metadata.gz: 25e2961ee63d2a0e48fa2419246207f3345dcc25a27bbc216b677752dc89400400e53f81e81316e6cf3c5cecabd1755ffad90355df42db71c3f5a6735915c4c8
7
- data.tar.gz: 6e02192d12bc51edbe48c1dd46db63a9818c90d31698aa24a13c153148504f7f1bd91c701f1c82709cc378cac10409d24bec37a1aeffa05ab645e9484866fc27
6
+ metadata.gz: da3e1dbe6d99f4954ca6a7774bb97159b95ffc7feab3c849ce5526f62b1df1404ec0e9896b05670253a5f97cd0b5009b591d4fcc058d3ea5d524425321a2989c
7
+ data.tar.gz: f75f7d92eac57912f2c4a917ef6bbc67876097c04248c2814cd0e1d3015d1ddcc7261b673bb4f4e743ddb1211e602e96e27fda534a9be52c65e06f7f4a064105
@@ -19,19 +19,26 @@
19
19
  require_dependency "faalis/api_controller"
20
20
 
21
21
 
22
+ # This class is the base class of all API controllers in any **Faalis**
23
+ # host applications. Each host Rails application should have an `APIController`
24
+ # which inherit from this class.
22
25
  class Faalis::APIController < Faalis::ApplicationController
26
+
27
+ @@allowed_fields = []
28
+
29
+ # Only support `json` format
23
30
  respond_to :json
24
31
 
25
- before_filter :authenticate_user!
32
+ # Authenticate user before any action take place
33
+ before_filter :authenticate
26
34
 
27
35
  protect_from_forgery
28
36
 
37
+ # Set csrf cookie after any action
29
38
  after_filter :set_csrf_cookie_for_ng
30
39
 
31
- def set_csrf_cookie_for_ng
32
- cookies['XSRF-TOKEN'] = form_authenticity_token if protect_against_forgery?
33
- end
34
-
40
+ # Rescue from any access denied exception raised from cancan and
41
+ # returns a useful error message in json
35
42
  rescue_from CanCan::AccessDenied do |exception|
36
43
 
37
44
  render :status => 403, :json => {
@@ -41,11 +48,91 @@ class Faalis::APIController < Faalis::ApplicationController
41
48
  }
42
49
  end
43
50
 
51
+ def set_csrf_cookie_for_ng
52
+ cookies['XSRF-TOKEN'] = form_authenticity_token if protect_against_forgery?
53
+ end
54
+
55
+ # User authentication for API services take place here. By default
56
+ # **Faalis** uses the authentication method of **Devise** to authenticate
57
+ # access to API service.
58
+ #
59
+ # If you want to change authentication method ? just override this method
60
+ # in you **APIController**
61
+ def authenticate
62
+ authenticate_user!
63
+ end
64
+
65
+ # Load resource by using parameters specified in querystring.
66
+ def load_resource_by_query
67
+ # If any query string parameter provided and allow fields specified
68
+ if not request.query_parameters.empty? and not allowed_fields.empty?
69
+ #load_resource
70
+
71
+ # Iterate over parameters in query string
72
+ request.query_parameters.each do |key, value|
73
+ # each key can be like filename[__querytype]=value
74
+ # which `querytype` is string that specify the query type scope
75
+ # to use in model. For example these is a query type scope called
76
+ # `gt` which mean the mentioned field should be greater than the
77
+ # value
78
+ field, query_type = key.split("__")
79
+
80
+ if allowed_fields.include? field
81
+ # If field name is in the allowed list
82
+ # If no query type specified we will use assignment scope.
83
+ if query_type.nil?
84
+ query_type = "assignment"
85
+ end
86
+
87
+ # If model have an scope with the "#{query_type}_query" name.
88
+ # Otherwise skip
89
+ if model_class.respond_to? "#{query_type}_query"
90
+
91
+ # If resource already loaded. If there was a instnace variable
92
+ # with the plural name of the resource exists then resource
93
+ # already loaded and we should chain new conditions
94
+ if instance_variable_defined? "@#{controller_name}"
95
+ instance_variable_get("@#{controller_name}").send("#{query_type}_query".to_sym, field, value)
96
+ else
97
+ # Resource did not loaded we make first query
98
+ # (without touching database) and set the corresponding
99
+ # instance variables
100
+ relation_object = model_class.send("#{query_type}_query".to_sym, field, value)
101
+ instance_variable_set("@#{controller_name}", relation_object)
102
+ end
103
+
104
+ else
105
+ logger.info "There is no `#{query_type}_query` in `#{model_class.to_s}` model."
106
+ end
107
+ else
108
+ logger.warn "`#{field}` in not in allowed list for `#{self.class.to_s}`."
109
+ end
110
+
111
+ end
112
+ end
113
+ end
114
+
115
+ # An array of allowed fields for query loading
116
+ def allowed_fields
117
+ @@allowed_fields
118
+ end
119
+
120
+ # Using this query you can activate the query loading system
121
+ # and specify fields which you want to use in query loading
122
+ def self.allow_query_on(*args)
123
+ @@allowed_fields = args.to_a.collect { |x| x.to_s }
124
+ end
125
+
126
+
44
127
  protected
45
128
 
129
+ # Model class related to this controller.
130
+ def model_class
131
+ controller_name.singularize.classify.constantize
132
+ end
133
+
46
134
  def verified_request?
47
135
  super || form_authenticity_token == request.headers['X-XSRF-TOKEN']
48
136
  end
49
137
 
50
-
51
138
  end
@@ -52,7 +52,12 @@ module Faalis
52
52
  devise *@@devise_options
53
53
 
54
54
  def name
55
- "#{first_name} #{last_name}"
55
+ if first_name or last_name
56
+ "#{first_name} #{last_name}"
57
+ else
58
+ email
59
+ end
60
+
56
61
  end
57
62
 
58
63
  def full_name
@@ -1,4 +1,4 @@
1
1
  json.array! @users do |user|
2
- json.extract! user, :id, :email, :first_name, :last_name
2
+ json.extract! user, :id, :email, :first_name, :last_name, :name
3
3
  json.group user.group, :id, :name
4
4
  end
@@ -1,6 +1,12 @@
1
1
  module Faalis
2
2
  module Generators
3
3
  module Concerns
4
+
5
+ # This **Concern** looks for `raw_path` and `path` in scaffold
6
+ # json file which both of them are optional.
7
+ # Using `raw_path` you can override the full path of generate file.
8
+ # and with `path` you can override the directory name inside
9
+ # `app/assets/javascripts`.
4
10
  module Angular
5
11
 
6
12
  def self.included(base)
@@ -13,7 +19,7 @@ module Faalis
13
19
 
14
20
  private
15
21
 
16
-
22
+ # return the relative path to place where scaffold shoud be created.
17
23
  def angularjs_app_path
18
24
  if not resource_data["raw_path"].blank?
19
25
  resource_data["raw_path"]
@@ -1,6 +1,20 @@
1
1
  module Faalis
2
2
  module Generators
3
3
  module Concerns
4
+
5
+ # This **Concern** adds support of dependencies to scaffold using
6
+ # `deps` key in json file. You can provide a list of scaffold dependencies
7
+ # which should mention as dependecy of **Angularjs** module of scaffold.
8
+ # Example:
9
+ #
10
+ #```javascript
11
+ # ....
12
+ # "deps": [
13
+ # "module1",
14
+ # "module2"
15
+ # ],
16
+ # ...
17
+ #```
4
18
  module Dependency
5
19
 
6
20
  def self.included(base)
@@ -8,6 +22,7 @@ module Faalis
8
22
  #base.class_option :deps, :type => :string, :default => "", :desc => "Dependencies of Angularjs module, comma separated"
9
23
  end
10
24
 
25
+ # Return a list of dependencies.
11
26
  def deps
12
27
  resource_data[:deps]
13
28
  end
@@ -6,9 +6,8 @@ module Faalis
6
6
  module Concerns
7
7
  # This module Provide an argument for generator which
8
8
  # is needed by other `Concerns`.
9
- #
10
- # Each Concern will have its own
11
-
9
+ # Each Concern will have its own entry in scaffold json
10
+ # file. For documentation on each entry checkout its concern class
12
11
  module JsonInput
13
12
 
14
13
  def self.included(base)
@@ -18,11 +17,14 @@ module Faalis
18
17
 
19
18
  private
20
19
 
20
+ # Read the json file and returns its raw data
21
21
  def json_file_data
22
22
  path = File.expand_path(jsonfile)
23
23
  File.read(path)
24
24
  end
25
25
 
26
+ # Return the hash related to json structure from cache or by
27
+ # reading file.
26
28
  def resource_data
27
29
  if @data
28
30
  @data
@@ -1,6 +1,18 @@
1
1
  module Faalis
2
2
  module Generators
3
3
  module Concerns
4
+ # This **concern** adds support of side menu to scaffold and `menu` key
5
+ # to jsonfile. `menu` key is an array which each element represent a menu
6
+ # entry and should be and object with following keys:
7
+ #
8
+ # `title`: Title of submenu
9
+ #
10
+ # `url`: Url of submenu link
11
+ #
12
+ # `action`: Permissions related action to check on resource model.
13
+ #
14
+ # `model`: Model of related resource which permission action should be check
15
+ # against.
4
16
  module Menu
5
17
 
6
18
  def self.included(base)
@@ -1,6 +1,9 @@
1
1
  module Faalis
2
2
  module Generators
3
3
  module Concerns
4
+ # This **concern** adds support for `model` key inside jsonfile which
5
+ # allow you to override the name of resource default model name.
6
+ # Resource model name is used in some processes like permission system.
4
7
  module Model
5
8
 
6
9
  def self.included(base)
@@ -11,10 +14,12 @@ module Faalis
11
14
 
12
15
  private
13
16
 
17
+ # Does an alternative `model` is specified ?
14
18
  def model_specified?
15
19
  resource_data.include? "model"
16
20
  end
17
21
 
22
+ # Name of alternative `model`
18
23
  def model
19
24
  if model_specified?
20
25
  resource_data["model"]
@@ -1,6 +1,32 @@
1
1
  module Faalis
2
2
  module Generators
3
3
  module Concerns
4
+
5
+ # This **concern** adds the methods needed to support nested resource
6
+ # in any dashboad generators. This module adds `parents` key to jsonfile
7
+ # which is an array of resource parents in right order.
8
+ # For example if we have a nested resource like:
9
+ #
10
+ # ```ruby
11
+ # resources :blogs do
12
+ # resources :categories do
13
+ # resources :posts
14
+ # end
15
+ # end
16
+ # ```
17
+ #
18
+ # And we want to create an dashboard scaffold for `post` resource we have
19
+ # to add `parent` key to our json file like this:
20
+ #
21
+ # ```json
22
+ # ...
23
+ # "parents": [
24
+ # "blog",
25
+ # "category"
26
+ # ]
27
+ # ...
28
+ # ```
29
+ # Please pay attention to singular form of name of parents in json defination
4
30
  module Parent
5
31
 
6
32
  def self.included(base)
@@ -12,8 +38,10 @@ module Faalis
12
38
 
13
39
  # check for parent
14
40
  def parent?
15
- unless resource_data["parents"].empty?
16
- return true
41
+ unless resource_data. include? "parents"
42
+ unless resource_data["parents"].nil?
43
+ return true
44
+ end
17
45
  end
18
46
  false
19
47
  end
@@ -23,6 +51,7 @@ module Faalis
23
51
  path.gsub(/^\//, "")
24
52
  end
25
53
 
54
+ # Return an array of resource parents
26
55
  def parents
27
56
  if parent?
28
57
  _parents = resource_data["parents"]
@@ -1,6 +1,9 @@
1
1
  module Faalis
2
2
  module Generators
3
3
  module Concerns
4
+
5
+ # Adds `required` key to `fields`. Fields with this key as true will
6
+ # be non optional fields
4
7
  module RequireFields
5
8
 
6
9
  def self.included(base)
@@ -4,6 +4,32 @@ require "faalis/generators/fields/relation"
4
4
  module Faalis
5
5
  module Generators
6
6
  module Concerns
7
+ # This **concern** module is one of the most important **concerns** in
8
+ # dashboard scaffold system. This module adds `fields` key to json file
9
+ # which use for defining the resource fields. `fields` key is an array
10
+ # of objects which each object represent a field. Each field have following
11
+ # attributes:
12
+ #
13
+ # **name**: Name of field
14
+ #
15
+ # **type**: Type of field. some of the most important types are: `string`,
16
+ # `integer`, `flout`, `belongs_to`, `has_many`, `in`, `datetime`.
17
+ # For complete list of types take a look at
18
+ # `app/assets/javascripts/faalis/dashboard/modules/fields/`
19
+ #
20
+ # **to**: This attribute is just for `in`, `has_many` and `belongs_to` field
21
+ # types which define the resource that current resource have dependency
22
+ # with. Bear in mind that `in` type uses `to` attrbute as an array of
23
+ # possible value for field and will render as a combobox.
24
+ #
25
+ # **options**: An object of type related objects. For example a list of
26
+ # current resource parents just like `parent` key.
27
+ #
28
+ # **bulk**: All fields with true as `bulk` value will be used in bulk editor.
29
+ #
30
+ # **tab**: ID of a Tab that this field should be appear on.
31
+ #
32
+ # **required**: Field will be non optional.
7
33
  module ResourceFields
8
34
 
9
35
  def self.included(base)
@@ -19,6 +45,7 @@ module Faalis
19
45
  # [name, type]
20
46
  def fields
21
47
  fields = []
48
+ if have_fields?
22
49
  resource_data["fields"].each do |field|
23
50
  name = field["name"]
24
51
  type = field["type"]
@@ -30,6 +57,7 @@ module Faalis
30
57
  end
31
58
 
32
59
  fields << [name, type]
60
+ end
33
61
  end
34
62
  fields
35
63
  end
@@ -99,6 +127,15 @@ module Faalis
99
127
  def no_filter?
100
128
  resource_data.include? "no_filter" && resource_data["no_filter"]
101
129
  end
130
+
131
+ def have_fields?
132
+ unless resource_data.include? "fields"
133
+ unless resource_data["fields"].nil?
134
+ return true
135
+ end
136
+ end
137
+ false
138
+ end
102
139
  end
103
140
  end
104
141
  end
@@ -1,6 +1,7 @@
1
1
  module Faalis
2
2
  module Generators
3
3
  module Concerns
4
+ # Adds the `name` key to json file which specify the resource name.
4
5
  module ResourceName
5
6
 
6
7
  def self.included(base)
@@ -1,6 +1,11 @@
1
1
  module Faalis
2
2
  module Generators
3
3
  module Concerns
4
+ # Using this **concern** module user can specify an array of tab objects
5
+ # which each one has an `id` and `name` attribute. Tabs will be added to
6
+ # **new** view of resource. Also this concern will a `tab` key to field
7
+ # object. All the fields with same `id` as a tab will be grouped in that
8
+ # tab
4
9
  module Tabs
5
10
 
6
11
  def self.included(base)
@@ -18,5 +18,5 @@
18
18
  # -----------------------------------------------------------------------------
19
19
 
20
20
  module Faalis
21
- VERSION = "0.20.0"
21
+ VERSION = "0.21.0"
22
22
  end
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.20.0
4
+ version: 0.21.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-16 00:00:00.000000000 Z
12
+ date: 2014-03-17 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails