faalis 0.26.3 → 1.0.0.alpha0

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -239,4 +239,8 @@ fieldset {
239
239
  }
240
240
  }
241
241
  }
242
+ }
243
+
244
+ .select2-container {
245
+ width: 100%;
242
246
  }
@@ -20,10 +20,10 @@
20
20
  *= require faalis/dashboard/dashboard
21
21
  *= require faalis/dashboard/sidebar
22
22
  *= require faalis/dashboard/list_view
23
- *= require faalis/dashboard/ng-quick-date
24
- *= require faalis/dashboard/ng-quick-date-default-theme
25
- *= require faalis/dashboard/ng-grid
26
- *= require faalis/dashboard/select2
23
+ *= require ngQuickDate/ng-quick-date
24
+ *= require ngQuickDate/ng-quick-date-default-theme
25
+ *= require ng-grid/ng-grid
26
+ *= require select2/select2
27
27
  *= require_tree ../share/
28
28
 
29
29
  */
@@ -19,9 +19,9 @@
19
19
  *= require faalis/dashboard/dashboard
20
20
  *= require faalis/dashboard/sidebar
21
21
  *= require faalis/dashboard/list_view
22
- *= require faalis/dashboard/ng-quick-date
23
- *= require faalis/dashboard/ng-quick-date-default-theme
24
- *= require faalis/dashboard/ng-grid
25
- *= require faalis/dashboard/select2
22
+ *= require ngQuickDate/ng-quick-date
23
+ *= require ngQuickDate/ng-quick-date-default-theme
24
+ *= require ng-grid/ng-grid
25
+ *= require select2/select2
26
26
  *= require_tree ../share/
27
27
  */
@@ -3,12 +3,12 @@
3
3
 
4
4
  @font-face {
5
5
  font-family: 'Droid Arabic Naskh';
6
- src: url(<%= asset_path("DroidNaskh-Regular.ttf")%>) format('truetype'); /* Saf3—5, Chrome4+, FF3.5, Opera 10+ */
6
+ src: url(<%= asset_path("DroidNaskh-Regular.ttf")%>) format('truetype'); /* Chrome4+, FF3.5, Opera 10+ */
7
7
  }
8
8
 
9
9
 
10
10
  :not(.fa){
11
- font-family: 'Droid Arabic Naskh', tahome, serif !important;
11
+ font-family: 'Droid Arabic Naskh', tahome, serif;
12
12
  }
13
13
 
14
14
  input[type="integer"] {
@@ -10,24 +10,8 @@ module Faalis
10
10
  # @api GET permissions
11
11
  # @return All permissions
12
12
  def index
13
- @permissions = []
14
-
15
- ::ApplicationModels.all.each do |m|
16
-
17
- model = m.model.constantize
18
- if model.respond_to? :permission_strings
19
- @permissions.concat(model.permission_strings(model))
20
- end
21
- end
22
-
23
- Faalis::Engine.models_with_permission.each do |m|
24
- model = m.constantize
25
- if model.respond_to? :permission_strings
26
- @permissions.concat(model.permission_strings(model))
27
- end
28
- end
29
-
30
- respond_with(@permissions.uniq)
13
+ @permissions = Faalis::Discovery::Permissions.all_permissions
14
+ respond_with(@permissions)
31
15
  end
32
16
 
33
17
  # @api GET permissions/user
@@ -35,28 +19,13 @@ module Faalis
35
19
  def user_permissions
36
20
  @permissions = {}
37
21
  perms = []
38
- if current_user.group_id == 1
39
- # Generate all possible permissions for admin group
40
- ::ApplicationModels.all.each do |model|
41
- model.model.constantize.possible_permissions.each do |p|
42
- perm = DummyPerm.new
43
- perm.model = model.model
44
- perm.permission_type = p
45
- perms << perm
46
- end
47
- end
48
- Faalis::Engine.models_with_permission.each do |m|
49
- m.constantize.possible_permissions.each do |p|
50
- perm = DummyPerm.new
51
- perm.model = m
52
- perm.permission_type = p
53
- perms << perm
54
- end
55
- end
56
- perms.uniq!
57
- else
58
- perms = current_user.group.permissions
22
+ current_user.permissions do |perm|
23
+ tmp = DummyPerm.new
24
+ tmp.model = perm.model
25
+ tmp.permission_type = perm.permission_type
26
+ perms << tmp
59
27
  end
28
+ perms.uniq!
60
29
 
61
30
  # Generate a suitable Hash for permissions
62
31
  perms.each do |perm|
@@ -4,8 +4,8 @@ module Faalis
4
4
  class API::V1::UsersController < ::APIController
5
5
 
6
6
  def index
7
- @users = User.joins(:group).all
8
- authorize! :read, @users
7
+ @users = User.joins(:groups).all
8
+ #authorize! :read, @users
9
9
  respond_with(@users)
10
10
  end
11
11
 
@@ -35,8 +35,8 @@ module Faalis
35
35
  user_fields[:password] = params[:password]
36
36
  end
37
37
 
38
- if params.include? :group and params[:group]
39
- user_fields[:group] = Group.find(params[:group]) || nil
38
+ if params.include? :groups and params[:groups]
39
+ user_fields[:groups] = Group.find(params[:groups]) || nil
40
40
  end
41
41
 
42
42
  if @user.update(user_fields)
@@ -58,9 +58,9 @@ module Faalis
58
58
  password: params[:password],
59
59
  })
60
60
 
61
- if params.include? :group
62
- group = Group.find(params[:group]) || nil
63
- @user.group = group
61
+ if params.include? :groups
62
+ group = Group.find(params[:groups]) || nil
63
+ @user.groups = group
64
64
  end
65
65
 
66
66
  if @user.save
@@ -31,12 +31,10 @@ class Ability
31
31
 
32
32
  # IMPORTANT: Remove this snippet with more suitable one
33
33
  # TODO: Remove this snippet with more suitable one
34
- user.group.permissions.each do |permission|
35
- can permission.permission_type.to_sym, permission.model.constantize
36
- end
37
-
38
- if user and user.group_id == 1
39
- can :manage, :all
34
+ user.groups.each do |group|
35
+ group.permissions.each do |permission|
36
+ can permission.permission_type.to_sym, permission.model.constantize
37
+ end
40
38
  end
41
39
  end
42
40
  end
@@ -6,9 +6,9 @@ module Faalis
6
6
  module Assignment
7
7
 
8
8
  def self.included(base)
9
- base.scope :assignment_query, -> (field, value) do
9
+ base.scope :assignment_query, ->(field, value) do
10
10
  base.where(field => value)
11
- end
11
+ end
12
12
  end
13
13
 
14
14
  end
@@ -18,10 +18,24 @@
18
18
  # -----------------------------------------------------------------------------
19
19
 
20
20
  module Faalis
21
- class Group < ActiveRecord::Base
22
- validates :name, :presence => true
21
+ # **Group** model for **Faalis** platform
22
+ class Group < Faalis::ORM.proper_base_class
23
23
 
24
- has_and_belongs_to_many :permissions
25
- has_many :users
24
+ # Make this model authorizable
25
+ include Faalis::Concerns::Authorizable
26
+
27
+ # Define **Group** fields if current ORM was **Mongoid**
28
+ if Faalis::ORM.mongoid?
29
+ include Mongoid::Document
30
+ include Mongoid::Timestamps
31
+
32
+ field :name, type: String
33
+ end
34
+
35
+ has_and_belongs_to_many :users, class_name: 'Faalis::User'
36
+ has_and_belongs_to_many :permissions, class_name: 'Faalis::Permission'
37
+
38
+ # Validations
39
+ validates :name, presence: true
26
40
  end
27
41
  end
@@ -1,7 +1,16 @@
1
1
  module Faalis
2
- class Permission < ActiveRecord::Base
2
+ class Permission < Faalis::ORM.proper_base_class
3
3
 
4
- has_and_belongs_to_many :groups
4
+ if Faalis::ORM.mongoid?
5
+ include Mongoid::Document
6
+ include Mongoid::Timestamps
7
+
8
+ field :model, type: String
9
+ field :permission_type, type: String
10
+
11
+ end
12
+
13
+ has_and_belongs_to_many :groups, class_name: 'Faalis::Group'
5
14
 
6
15
  def string_repr
7
16
  _("can %s %s") % [_(self.permission_type.to_s), self.model.underscore.humanize]
@@ -1,7 +1,8 @@
1
1
  class Faalis::Permissions::Auth
2
- include Faalis::Permissions
2
+ # Make this model authorizable
3
+ include Faalis::Concerns::Authorizable
3
4
 
4
5
  def self.humanize_class_name
5
- "Auth Module"
6
+ 'Auth Module'
6
7
  end
7
8
  end
@@ -18,85 +18,39 @@
18
18
  # -----------------------------------------------------------------------------
19
19
 
20
20
  module Faalis
21
- class User < ActiveRecord::Base
22
- #acts as messageable for mailboxer
23
- acts_as_messageable
24
-
25
- validates :password, presence: true, length: {minimum: 5, maximum: 120}, on: :create
26
- validates :password, length: {minimum: 5, maximum: 120}, on: :update, allow_blank: true
27
- validates :email, presence: true, length: {minimum: 6}
28
- #validates :password,presence: true, length: { in: 6..20 }
29
- # Include default devise modules. Others available are:
30
- # :token_authenticatable, :confirmable,
31
- # :lockable, :timeoutable and :omniauthable
32
- @@devise_options = [:database_authenticatable,
33
- :registerable,
34
- :recoverable,
35
- :rememberable,
36
- :trackable,
37
- :lockable,
38
- :timeoutable,
39
- :validatable,
40
- :omniauthable]
41
-
42
- if Rails.env.production?
43
- @@devise_options << :confirmable
21
+ # **User** model for **Faalis** platform
22
+ class User < Faalis::ORM.proper_base_class
23
+
24
+ # AuthDefinitions contains all the **Devise** related configurations.
25
+ include Faalis::User::AuthDefinitions
26
+ # Permission related methods for user
27
+ include Faalis::User::Permission
28
+
29
+ # Make this model authorizable
30
+ include Faalis::Concerns::Authorizable
31
+
32
+ # Define **User** fields if current ORM was Mongoid -----------------------
33
+ if Faalis::ORM.mongoid?
34
+ include Mongoid::Document
35
+ include Mongoid::Timestamps
36
+ include Faalis::User::MongoidFields
37
+ # FIXME: Port mailboxer to work with mongoid
44
38
  end
45
39
 
46
- if Devise.omniauth_configs.any?
47
- @@devise_options << :omniauthable
48
- @@devise_options << {:omniauth_providers => Devise.omniauth_configs.keys}
40
+ # Define **User** fields if current ORM was ActiveRecord-------------------
41
+ if Faalis::ORM.active_record?
42
+ # acts as messageable for mailboxer
43
+ #acts_as_messageable
49
44
  end
50
45
 
51
- belongs_to :group
46
+ has_and_belongs_to_many :groups, class_name: 'Faalis::Group'
52
47
 
53
- devise *@@devise_options
54
-
55
- def name
56
- if first_name or last_name
57
- "#{first_name} #{last_name}"
58
- else
59
- email
60
- end
61
-
62
- end
63
-
64
- def full_name
65
- name
66
- end
67
-
68
- def password_required?
69
- # TODO: nil? is not suitable for here we should use empty? or blink?
70
- if Devise.omniauth_configs.any?
71
- return (provider.nil? || password.nil?) && super
72
- else
73
- password.nil? && super
74
- end
75
- end
76
-
77
- def self.find_from_oauth(auth, signed_in_resource=nil)
78
- user = User.where(:provider => auth.provider, :uid => auth.uid).first
79
-
80
- first_name = auth.info.first_name
81
- last_name = auth.info.last_name
82
-
83
- if first_name.blank?
84
- # With first_name being blank last_name is probably is blank too
85
- name = auth.info.name.split(" ")
86
- first_name = name[0]
87
- last_name = name[1,] || ""
88
- end
89
- unless user
90
- user = User.create(first_name: first_name,
91
- last_name: last_name,
92
- provider: auth.provider,
93
- uid: auth.uid,
94
- email: auth.info.email,
95
- password: Devise.friendly_token[0,20])
96
- end
97
- user
48
+ # Validations
49
+ validates :password, presence: true, length: {minimum: 5, maximum: 120}, on: :create
50
+ validates :password, length: {minimum: 5, maximum: 120}, on: :update, allow_blank: true
51
+ validates :email, presence: true, length: {minimum: 6}
98
52
 
99
- end
53
+ devise *@@devise_options
100
54
 
101
55
  end
102
56
  end
@@ -0,0 +1,94 @@
1
+ module Faalis
2
+ module User::AuthDefinitions
3
+
4
+ def self.included(base)
5
+
6
+ base.class_eval do
7
+ # Include default devise modules. Others available are:
8
+ # :token_authenticatable, :confirmable,
9
+ # :lockable, :timeoutable and :omniauthable
10
+ @@devise_options = [:database_authenticatable,
11
+ :registerable,
12
+ :recoverable,
13
+ :rememberable,
14
+ :trackable,
15
+ :lockable,
16
+ :timeoutable,
17
+ :validatable]
18
+
19
+ if Rails.env.production?
20
+ @@devise_options << :confirmable
21
+ end
22
+
23
+ if Devise.omniauth_configs.any?
24
+ @@devise_options << :omniauthable
25
+ @@devise_options << {:omniauth_providers => Devise.omniauth_configs.keys}
26
+ end
27
+ end
28
+ base.extend ClassMethods
29
+ end
30
+
31
+ def name
32
+ if first_name or last_name
33
+ "#{first_name} #{last_name}"
34
+ else
35
+ email
36
+ end
37
+
38
+ end
39
+
40
+ def full_name
41
+ name
42
+ end
43
+
44
+
45
+ # Confirmation not required when using omniauth
46
+ def confirmation_required?
47
+ super && identities.empty?
48
+ end
49
+
50
+ def update_with_password(params, *options)
51
+ if encrypted_password.blank?
52
+ update_attributes(params, *options)
53
+ else
54
+ super
55
+ end
56
+ end
57
+
58
+ def password_required?
59
+ # TODO: nil? is not suitable for here we should use empty? or blink?
60
+ if Devise.omniauth_configs.any?
61
+ return (provider.nil? || password.nil?) && super
62
+ else
63
+ password.nil? && super
64
+ end
65
+ end
66
+
67
+ module ClassMethods
68
+ def find_from_oauth(auth, signed_in_resource = nil)
69
+ user = User.where(:provider => auth.provider, :uid => auth.uid).first
70
+
71
+ first_name = auth.info.first_name
72
+ last_name = auth.info.last_name
73
+
74
+ if first_name.blank?
75
+ # With first_name being blank last_name is probably is blank too
76
+ name = auth.info.name.split(' ')
77
+ first_name = name[0]
78
+ last_name = name[1,] || ''
79
+ end
80
+ unless user
81
+ user = User.create(first_name: first_name,
82
+ last_name: last_name,
83
+ provider: auth.provider,
84
+ uid: auth.uid,
85
+ email: auth.info.email,
86
+ password: Devise.friendly_token[0,20])
87
+ end
88
+ user
89
+ end
90
+
91
+ end
92
+
93
+ end
94
+ end