faalis 0.26.3 → 1.0.0.alpha0

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.
Files changed (87) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +35 -6
  3. data/Rakefile +2 -25
  4. data/app/assets/javascripts/faalis/angular-manifest.js +8 -2
  5. data/app/assets/javascripts/faalis/application.js +0 -3
  6. data/app/assets/javascripts/faalis/dashboard/application.js.erb +0 -5
  7. data/app/assets/javascripts/faalis/dashboard/functions.js.erb +9 -0
  8. data/app/assets/javascripts/faalis/dashboard/init.js +1 -1
  9. data/app/assets/javascripts/faalis/dashboard/modules/auth/group.js +0 -6
  10. data/app/assets/javascripts/faalis/dashboard/modules/fields/fields.js +1 -1
  11. data/app/assets/javascripts/faalis/dashboard/modules/fields/image.js +115 -0
  12. data/app/assets/javascripts/faalis/dashboard/modules/fields/tag.js +76 -0
  13. data/app/assets/javascripts/faalis/dashboard/variables.js.erb +1 -1
  14. data/app/assets/locale/templates.pot +282 -0
  15. data/app/assets/stylesheets/faalis/dashboard/dashboard.css.scss +4 -0
  16. data/app/assets/stylesheets/faalis/dashboard/ltr/application.css +4 -4
  17. data/app/assets/stylesheets/faalis/dashboard/rtl/application.css +4 -4
  18. data/app/assets/stylesheets/faalis/dashboard/rtl/base.css.scss.erb +2 -2
  19. data/app/controllers/faalis/api/v1/permissions_controller.rb +8 -39
  20. data/app/controllers/faalis/api/v1/users_controller.rb +7 -7
  21. data/app/models/ability.rb +4 -6
  22. data/app/models/faalis/concerns/assignment.rb +2 -2
  23. data/app/models/faalis/group.rb +18 -4
  24. data/app/models/faalis/permission.rb +11 -2
  25. data/app/models/faalis/permissions/auth.rb +3 -2
  26. data/app/models/faalis/user.rb +27 -73
  27. data/app/models/faalis/user/auth_definitions.rb +94 -0
  28. data/app/models/faalis/user/mongoid_fields.rb +76 -0
  29. data/app/models/faalis/user/permission.rb +21 -0
  30. data/app/views/angularjs_templates/auth/groups/new.html +0 -20
  31. data/app/views/angularjs_templates/fields/image/image.html +1 -0
  32. data/app/views/angularjs_templates/fields/relation/relation.html +3 -1
  33. data/app/views/angularjs_templates/fields/tag/tag.html +1 -0
  34. data/app/views/angularjs_templates/nav.html.erb +0 -1
  35. data/app/views/faalis/api/v1/users/index.json.jbuilder +1 -1
  36. data/app/views/layouts/faalis/application.html.erb +2 -0
  37. data/app/views/layouts/faalis/dashboard.html.erb +1 -0
  38. data/app/views/layouts/faalis/simple.html.erb +1 -0
  39. data/config/initializers/devise.rb +0 -7
  40. data/db/migrate/20131013091000_devise_create_faalis_users.rb +3 -2
  41. data/db/migrate/20140613120923_add_users_groups_table.rb +8 -0
  42. data/db/migrate/20140617124019_faalis_groups_users.rb +4 -0
  43. data/db/seeds.rb +39 -11
  44. data/lib/faalis.rb +5 -4
  45. data/lib/faalis/concerns.rb +7 -0
  46. data/lib/faalis/concerns/authorizable.rb +76 -0
  47. data/lib/faalis/discovery.rb +8 -0
  48. data/lib/faalis/discovery/permissions.rb +51 -0
  49. data/lib/faalis/engine.rb +19 -5
  50. data/lib/faalis/extensions.rb +18 -0
  51. data/lib/faalis/extensions/base.rb +29 -0
  52. data/lib/faalis/fake_assets.rb +7 -0
  53. data/lib/faalis/generators/dashboard_scaffold.rb +23 -5
  54. data/lib/faalis/omniauth.rb +3 -0
  55. data/lib/faalis/orm.rb +29 -0
  56. data/lib/faalis/{active_record.rb → patches/models.rb} +1 -3
  57. data/lib/faalis/version.rb +1 -1
  58. data/lib/generators/faalis/install_generator.rb +7 -3
  59. data/lib/{faalis/plugins.rb → generators/faalis/js/install_i18n_generator.rb} +20 -17
  60. data/lib/generators/faalis/scaffold_generator.rb +139 -0
  61. data/lib/generators/faalis/templates/application.js +1 -1
  62. data/lib/generators/faalis/templates/i18n/Gruntfile.js.erb +30 -0
  63. data/lib/generators/faalis/templates/i18n/README +13 -0
  64. data/lib/generators/faalis/templates/i18n/fa.js +3 -0
  65. data/lib/generators/faalis/templates/js/list_view/README +1 -1
  66. data/lib/tasks/faalis_tasks.rake +26 -20
  67. data/lib/tasks/grunt/Gruntfile.js +7 -2
  68. data/spec/dummy/config/initializers/faalis.rb +40 -0
  69. metadata +134 -44
  70. data/app/assets/javascripts/faalis/dashboard/lib/angular-gettext.js +0 -202
  71. data/app/assets/javascripts/faalis/dashboard/lib/ng-grid.js +0 -3260
  72. data/app/assets/javascripts/faalis/dashboard/lib/ng-quick-date.js +0 -297
  73. data/app/assets/javascripts/faalis/dashboard/lib/restangular.js +0 -1066
  74. data/app/assets/javascripts/faalis/dashboard/lib/select2.js +0 -3255
  75. data/app/assets/javascripts/faalis/dashboard/lib/ui.select2.js +0 -217
  76. data/app/assets/stylesheets/faalis/dashboard/ng-grid.css.scss +0 -442
  77. data/app/assets/stylesheets/faalis/dashboard/ng-quick-date-default-theme.css.scss +0 -20
  78. data/app/assets/stylesheets/faalis/dashboard/ng-quick-date.css.scss +0 -19
  79. data/app/assets/stylesheets/faalis/dashboard/select2.css.scss.erb +0 -618
  80. data/app/controllers/faalis/api/v1/#conversations_controller.rb# +0 -120
  81. data/app/models/faalis/workflow.rb +0 -4
  82. data/db/migrate/20140413180202_create_faalis_workflows.rb +0 -9
  83. data/lib/faalis/permissions.rb +0 -72
  84. data/lib/faalis/workflows.rb +0 -7
  85. data/lib/faalis/workflows/base.rb +0 -70
  86. data/lib/faalis/workflows/discovery.rb +0 -42
  87. data/lib/generators/faalis/js_scaffold_generator.rb +0 -113
@@ -0,0 +1,76 @@
1
+ module Faalis
2
+ # This module contains all the **Mongoid** related definitions
3
+ module User::MongoidFields
4
+ extend ActiveSupport::Concern
5
+
6
+ included do
7
+
8
+ field :first_name, type: String, default: ''
9
+ field :last_name, type: String, default: ''
10
+ field :email, type: String, default: ''
11
+ field :encrypted_password, type: String, default: ''
12
+
13
+ ## Recoverable
14
+ field :reset_password_token, type: String
15
+ field :reset_password_sent_at, type: Time
16
+
17
+ ## Recoverable
18
+ field :remember_created_at, type: Time
19
+
20
+ ## Trackable
21
+ field :sign_in_count, type: Integer, default: 0
22
+ field :current_sign_in_at, type: Time
23
+ field :last_sign_in_at, type: Time
24
+ field :current_sign_in_ip, type: String
25
+ field :last_sign_in_ip, type: String
26
+
27
+
28
+ ## Confirmable
29
+ # field :confirmation_token, type: String
30
+ # field :confirmed_at, type: Time
31
+ # field :confirmation_sent_at, type: Time
32
+ # field :unconfirmed_email, type: String # Only if using reconfirmable
33
+
34
+ # Lockable
35
+ field :failed_attempts, type: Integer, default: 0 # Only if lock strategy is :failed_attempts
36
+ field :unlock_token, type: String # Only if unlock strategy is :email or :both
37
+ field :locked_at, type: Time
38
+
39
+ # Token authenticatable
40
+ field :authentication_token, type: String
41
+
42
+ # run 'rake db:mongoid:create_indexes' to create indexes
43
+ if not Devise.omniauth_providers.empty?
44
+ # Service
45
+ field :provider, type: String, default: ''
46
+ field :uid, type: String
47
+ end
48
+
49
+ if Rails.env.production?
50
+ # Confirmable
51
+ field :confirmation_token, type: String
52
+ field :confirmed_at, type: Time
53
+ field :confirmation_sent_at, type: Time
54
+
55
+ # Only if using reconfirmable
56
+ field :unconfirmed_email, type: String
57
+ end
58
+
59
+
60
+ index({ email: 1 },
61
+ { unique: true, background: true })
62
+ index({ reset_password_token: 1 },
63
+ { unique: true, background: true })
64
+ index({ unlock_token: 1 },
65
+ { unique: true, background: true })
66
+ index({ authentication_token: 1 },
67
+ { unique: true, background: true })
68
+
69
+ if Rails.env.production?
70
+ index({ confirmation_token: 1 },
71
+ { unique: true, background: true })
72
+ end
73
+
74
+ end
75
+ end
76
+ end
@@ -0,0 +1,21 @@
1
+ module Faalis
2
+ # This concern contains all the permission related methods
3
+ # to use within `Faalis::User`
4
+ module User::Permission
5
+
6
+ # Return all the user permissions
7
+ def permissions
8
+ perms = []
9
+
10
+ groups.each do |group|
11
+ group.permissions.each do |perm|
12
+ # It's obvious isn't it ?
13
+ yield perm if block_given?
14
+ perms << perm
15
+ end
16
+ end
17
+
18
+ perms
19
+ end
20
+ end
21
+ end
@@ -15,26 +15,6 @@
15
15
  </div>
16
16
  </fieldset>
17
17
 
18
- <fieldset>
19
- <legend translate>Workflows</legend>
20
- <div class="row">
21
- <div class="small-12 columns">
22
- <p translate>Choose any workflow which you want to allow user to have access to.</p>
23
- </div>
24
- </div>
25
- <div class="row">
26
- <div class="small-2 columns text-center" ng-repeat="workflow in workflows">
27
-
28
- <span class="fa-stack fa-2x" ng-if="workflow.have_icon == true">
29
- <i class="fa fa-circle fa-stack-2x"></i>
30
- <i class="{{ workflow.icon }} fa-stack-1x fa-inverse"></i>
31
- </span>
32
- <img ng-src="workflow.image" ng-if="workflow.have_iamge == true"/>
33
- <span>{{ workflow.title }}</span>
34
- </div>
35
- </div>
36
- </fieldset>
37
-
38
18
  <fieldset>
39
19
  <legend translate>Advance Permissions</legend>
40
20
  <div class="row">
@@ -0,0 +1 @@
1
+ <input type="file" />
@@ -24,7 +24,9 @@
24
24
  </div>
25
25
  <div class="float-right relation_links" ng-if="((field.type === 'belongs_to') || (field.type === 'has_many')) && show_buttons() ">
26
26
 
27
- <span ng-click="help_btn_clicked()" ng-if="show_help_btn">
27
+
28
+ <!-- Add and Refresh buttons -->
29
+ <span ng-click="help_btn_clicked()" ng-if="show_help_btnn">
28
30
  <i class="fa fa-question"></i>
29
31
  </span>
30
32
  <span>
@@ -0,0 +1 @@
1
+ <input ui-select2="options" type="hidden" ng-model="model" ng-required="required" data-dtr="{{ model }}"/>
@@ -1,6 +1,5 @@
1
1
  <div ng-controller="NavigationController as controller">
2
2
  <div class="row">
3
-
4
3
  <ul class="small-6 columns">
5
4
  <li><h1 translate>Dashboard</h1></li>
6
5
  <li>
@@ -1,4 +1,4 @@
1
1
  json.array! @users do |user|
2
2
  json.extract! user, :id, :email, :first_name, :last_name, :name
3
- json.group user.group, :id, :name
3
+ json.groups user.groups, :id, :name
4
4
  end
@@ -77,5 +77,7 @@
77
77
  </div>
78
78
  </footer>
79
79
  <%= javascript_include_tag "faalis/application" %>
80
+ <%= javascript_include_tag "locale/#{::I18n.locale}" %>
81
+
80
82
  </body>
81
83
  </html>
@@ -16,5 +16,6 @@
16
16
  <p class="notice"><%= notice %></p>
17
17
  <p class="alert"><%= alert %></p>
18
18
  </div>
19
+ <%= javascript_include_tag "locale/#{::I18n.locale}" %>
19
20
  </body>
20
21
  </html>
@@ -33,5 +33,6 @@
33
33
  </div>
34
34
 
35
35
  <%= javascript_include_tag "faalis/application" %>
36
+ <%= javascript_include_tag "locale/#{::I18n.locale}" %>
36
37
  </body>
37
38
  </html>
@@ -2,13 +2,6 @@
2
2
  # Many of these configuration options can be set straight in your model.
3
3
  Devise.setup do |config|
4
4
 
5
- # ==> ORM configuration
6
- # Load and configure the ORM. Supports :active_record (default) and
7
- # :mongoid (bson_ext recommended) by default. Other ORMs may be
8
- # available as additional gems.
9
- require 'devise/orm/active_record'
10
-
11
-
12
5
  config.secret_key = '04671846f794e5df0e032abb7d3d3876016f1cf0a1ced726429b2807c798de67f08035cc45e953eca23e08661a7f8030f4bcaec91ef184d89f4c721b5925d36b'
13
6
 
14
7
 
@@ -38,6 +38,9 @@ class DeviseCreateFaalisUsers < ActiveRecord::Migration
38
38
  t.datetime :confirmed_at
39
39
  t.datetime :confirmation_sent_at
40
40
  t.string :unconfirmed_email # Only if using reconfirmable
41
+
42
+ # Token authenticatable
43
+ t.string :authentication_token
41
44
  end
42
45
 
43
46
  ## Lockable
@@ -45,8 +48,6 @@ class DeviseCreateFaalisUsers < ActiveRecord::Migration
45
48
  t.string :unlock_token # Only if unlock strategy is :email or :both
46
49
  t.datetime :locked_at
47
50
 
48
- ## Token authenticatable
49
- # t.string :authentication_token
50
51
 
51
52
 
52
53
  t.timestamps
@@ -0,0 +1,8 @@
1
+ class AddUsersGroupsTable < ActiveRecord::Migration
2
+ def change
3
+ create_table :faalis_groups_users do |t|
4
+ t.belongs_to :user
5
+ t.belongs_to :group
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,4 @@
1
+ class FaalisGroupsUsers < ActiveRecord::Migration
2
+ def change
3
+ end
4
+ end
@@ -2,20 +2,48 @@
2
2
 
3
3
  ModelDiscovery::Engine.load_seed
4
4
 
5
- Faalis::Workflows::Discovery.build_table_list
5
+ #Faalis::Workflows::Discovery.build_table_list
6
+ Faalis::Discovery::Permissions.create_all_permissions
6
7
 
7
- Faalis::Group.create({:name => 'Admin'})
8
+ case Faalis::ORM.current
9
+ when 'active_record'
10
+ admin_group = Faalis::Group.create(name: 'Admin')
8
11
 
9
- Faalis::User.create({:email => 'admin@example.com',
10
- :group_id => 1,
11
- :password => '123123123',
12
- :password_confirmation => '123123123'})
12
+ admin_group.permissions = Faalis::Permission.all
13
13
 
14
+ admin = Faalis::User.create(email: 'admin@example.com',
15
+ password: '123123123',
16
+ password_confirmation: '123123123')
17
+ admin.groups << admin_group
14
18
 
15
- Faalis::Group.create({:name => 'Guest', :id => 2})
19
+ guest_group = Faalis::Group.create(name: 'Guest', id: 2)
16
20
 
17
21
 
18
- Faalis::User.create({:email => 'user@example.com',
19
- :group_id => 2,
20
- :password => '123123123',
21
- :password_confirmation => '123123123'})
22
+ user = Faalis::User.create(email: 'user@example.com',
23
+ password: '123123123',
24
+ password_confirmation: '123123123')
25
+ user.groups << guest_group
26
+
27
+ when 'mongoid'
28
+ admin = Faalis::User.create(email: 'admin@example.com',
29
+ password: '123123123',
30
+ password_confirmation: '123123123')
31
+
32
+ admin_group = Faalis::Group.create(name: 'Admin')
33
+
34
+ Faalis::Permission.each do |perm|
35
+ admin_group.permissions << perm
36
+ end
37
+ admin_group.save!
38
+
39
+ admin.groups << admin_group
40
+
41
+ user = Faalis::User.create(email: 'user@example.com',
42
+ password: '123123123',
43
+ password_confirmation: '123123123')
44
+ guest_group = Faalis::Group.new(name: 'Guest')
45
+ user.groups = [guest_group]
46
+ end
47
+
48
+ admin.save
49
+ user.save
@@ -24,13 +24,14 @@ module Faalis
24
24
  end
25
25
 
26
26
  require 'faalis/engine'
27
- require 'faalis/permissions'
27
+ require 'faalis/orm'
28
+ require 'faalis/concerns'
28
29
  require 'faalis/dashboard'
30
+ require 'faalis/extensions'
29
31
  require 'faalis/omniauth'
30
- require 'faalis/active_record'
31
32
  require 'faalis/i18n'
32
- require 'faalis/plugins'
33
33
  require 'faalis/generators/concerns'
34
34
  require 'faalis/generators'
35
- require 'faalis/workflows'
36
35
  require 'faalis/route'
36
+ require 'faalis/discovery'
37
+ require 'faalis/fake_assets'
@@ -0,0 +1,7 @@
1
+ module Faalis
2
+ # Faalis Concerns module
3
+ module Concerns
4
+ end
5
+ end
6
+
7
+ require 'faalis/concerns/authorizable'
@@ -0,0 +1,76 @@
1
+ module Faalis
2
+ module Concerns
3
+ # Authorizable modules of Faalis which each resource model should
4
+ # includes this concern. Without this concern, models can not be authorized
5
+ module Authorizable
6
+ extend ActiveSupport::Concern
7
+
8
+ # Class methods which will add to model by including
9
+ # `Faalis::Concerns::Authorizable`
10
+ module ClassMethods
11
+ # Default permission hash
12
+ @@permissions = {
13
+ read: nil,
14
+ update: nil,
15
+ create: nil,
16
+ destroy: nil,
17
+ }
18
+
19
+ @@only_owner = false
20
+
21
+ # Return an array of strings representation of permissions
22
+ def permission_strings(model)
23
+ strings = []
24
+ model_name = model.to_s
25
+ humanize_name = ActiveModel::Name.new(model).human
26
+ if model.respond_to? :model_name
27
+ model_name = model.model_name
28
+ humanize_name = model_name.human
29
+ end
30
+ @@permissions.each do |key, value|
31
+ strings << {
32
+ name: "#{key}|#{model_name}",
33
+ string: _("can %s %s") % [_(key.to_s), humanize_name]
34
+ }
35
+ end
36
+ strings
37
+ end
38
+
39
+ def possible_permissions
40
+ @@permissions.keys
41
+ end
42
+
43
+ # Define permissions using this method
44
+ def permissions(*args)
45
+
46
+ args.each do |permission|
47
+ if permission.class == Symbol
48
+ if not @@permissions.include? permission
49
+ @@permission[permission] = nil
50
+
51
+ elsif permission.class == Hash
52
+
53
+ permission.each do |key, value|
54
+ @@permissions[key.to_sym] = value
55
+ end
56
+
57
+ end
58
+ end
59
+
60
+
61
+ end
62
+ end
63
+
64
+ # This force user to have access to resources which is his.
65
+ def only_his_objects
66
+ @@only_owner = true
67
+ end
68
+
69
+ def only_his_objects?
70
+ @@only_owner
71
+ end
72
+
73
+ end
74
+ end
75
+ end
76
+ end
@@ -0,0 +1,8 @@
1
+ module Faalis
2
+ # This module contains all the code snippets
3
+ # to discover special entities in project
4
+ module Discovery
5
+ end
6
+ end
7
+
8
+ require 'faalis/discovery/permissions'
@@ -0,0 +1,51 @@
1
+ module Faalis
2
+ module Discovery
3
+ class Permissions
4
+
5
+ # Run the given block fir each object with permissions
6
+ def self.permission_objects(&block)
7
+ objects = []
8
+
9
+ # Walkthrough all models in application by using
10
+ # model_discovery gem and check for `permission_strings`
11
+ # method in models (If `Faalis::Permissions` included in
12
+ # model it has the permission_strings). And concat the
13
+ # permissions to `@permissions` instance method.
14
+ ::ApplicationModels.to_adapter.find_all.each do |m|
15
+ model = m.model.constantize
16
+ if model.respond_to? :permission_strings
17
+ block.call(model)
18
+ end
19
+ end
20
+
21
+ # Check also for entities which don't have a model but
22
+ # we need to use them in our permissions.
23
+ Faalis::Engine.models_with_permission.each do |m|
24
+ model = m.constantize
25
+ if model.respond_to? :permission_strings
26
+ block.call(model)
27
+ end
28
+ end
29
+ end
30
+
31
+ def self.all_permissions
32
+ permissions = []
33
+ permission_objects do |object|
34
+ permissions.concat(object.permission_strings(object))
35
+ end
36
+
37
+ permissions.uniq
38
+ end
39
+
40
+ def self.create_all_permissions
41
+
42
+ permission_objects do |object|
43
+ object.possible_permissions.each do |perm|
44
+ Faalis::Permission.create(model: object.to_s,
45
+ permission_type: perm)
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end