faalis 1.0.0.alpha4 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (98) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/javascripts/faalis/angular-manifest.js +1 -0
  3. data/app/assets/javascripts/faalis/dashboard/app.js +1 -2
  4. data/app/assets/javascripts/faalis/dashboard/controllers/group.js.coffee +9 -7
  5. data/app/assets/javascripts/faalis/dashboard/controllers/user.js +11 -0
  6. data/app/assets/javascripts/faalis/dashboard/functions.js.erb +36 -0
  7. data/app/assets/javascripts/faalis/dashboard/lib/controllers/generic_index_controller.js.coffee +13 -6
  8. data/app/assets/javascripts/faalis/dashboard/lib/fields/has_many_field.js.coffee +0 -2
  9. data/app/assets/javascripts/faalis/dashboard/lib/resource.js.coffee +17 -4
  10. data/app/assets/javascripts/faalis/dashboard/modules/auth/user.js +0 -96
  11. data/app/assets/javascripts/faalis/dashboard/modules/fake.js +41 -0
  12. data/app/assets/javascripts/faalis/dashboard/modules/fields/datetime.js +4 -1
  13. data/app/assets/javascripts/faalis/dashboard/resources/group_resource.js.coffee +1 -0
  14. data/app/assets/javascripts/faalis/dashboard/resources/user_resource.js.coffee +0 -0
  15. data/app/assets/javascripts/faalis/dashboard/services/api.js.coffee +8 -6
  16. data/app/assets/javascripts/faalis/dashboard/services/user.js.coffee +0 -4
  17. data/app/assets/javascripts/faalis/dashboard/variables.js.erb +2 -1
  18. data/app/assets/stylesheets/faalis/dashboard/ltr/application.css +4 -2
  19. data/app/assets/stylesheets/faalis/dashboard/rtl/application.css +2 -0
  20. data/app/controllers/faalis/api/v1/permissions_controller.rb +2 -1
  21. data/app/controllers/faalis/api_controller.rb +0 -3
  22. data/app/controllers/faalis/application_controller.rb +3 -0
  23. data/app/controllers/faalis/dashboard/groups_controller.rb +80 -0
  24. data/app/controllers/faalis/dashboard/users_controller.rb +100 -0
  25. data/app/controllers/faalis/dashboard_controller.rb +5 -1
  26. data/app/helpers/faalis/users_helper.rb +4 -0
  27. data/app/models/faalis/concerns/user/permission.rb +5 -0
  28. data/app/models/faalis/group.rb +14 -0
  29. data/app/models/faalis/permission.rb +3 -0
  30. data/app/views/angular/auth/groups/details.html +2 -21
  31. data/app/views/angular/auth/groups/index.html +2 -5
  32. data/app/views/angular/auth/groups/new.html +2 -47
  33. data/app/views/faalis/api/v1/groups/index.json.jbuilder +4 -4
  34. data/app/views/faalis/api/v1/permissions/index.json.jbuilder +1 -1
  35. data/app/views/faalis/dashboard/groups/_form.html.slim +72 -0
  36. data/app/views/faalis/dashboard/groups/create.js.erb +3 -0
  37. data/app/views/faalis/dashboard/groups/edit.html.slim +3 -0
  38. data/app/views/faalis/dashboard/groups/errors.js.erb +3 -0
  39. data/app/views/faalis/dashboard/groups/new.html.slim +2 -0
  40. data/app/views/faalis/dashboard/groups/update.js.erb +3 -0
  41. data/app/views/faalis/dashboard/users/_form.html.slim +80 -0
  42. data/app/views/faalis/dashboard/users/_password_form.html.slim +37 -0
  43. data/app/views/faalis/dashboard/users/create.js.erb +3 -0
  44. data/app/views/faalis/dashboard/users/edit.html.slim +3 -0
  45. data/app/views/faalis/dashboard/users/edit_password.html.slim +1 -0
  46. data/app/views/faalis/dashboard/users/errors.js.erb +3 -0
  47. data/app/views/faalis/dashboard/users/index.html.slim +67 -0
  48. data/app/views/faalis/dashboard/users/new.html.slim +2 -0
  49. data/app/views/faalis/dashboard/users/show.html.slim +6 -0
  50. data/app/views/faalis/dashboard/users/update.js.erb +3 -0
  51. data/app/views/faalis/dashboard/users/update_password.js.erb +3 -0
  52. data/db/migrate/20131013091000_devise_create_faalis_users.rb +0 -3
  53. data/lib/faalis.rb +2 -0
  54. data/lib/faalis/action_dispatch.rb +3 -0
  55. data/lib/faalis/configuration.rb +25 -0
  56. data/lib/faalis/engine.rb +2 -0
  57. data/lib/faalis/fake_assets.rb +1 -0
  58. data/lib/faalis/route.rb +73 -2
  59. data/lib/faalis/version.rb +3 -3
  60. data/lib/faalis_application.rb +10 -6
  61. data/lib/faalis_plugin.rb +5 -4
  62. data/lib/generators/faalis/install_generator.rb +1 -0
  63. data/lib/generators/faalis/js/list_view_generator.rb +4 -0
  64. data/lib/generators/faalis/scaffold_generator.rb +98 -72
  65. data/lib/generators/faalis/templates/angularjs/new.html.erb +10 -10
  66. data/lib/generators/faalis/templates/js/list_view/new.html.erb +10 -10
  67. data/lib/generators/faalis/templates/js/list_view/partials/add_controller.js.erb +4 -4
  68. data/lib/generators/faalis/templates/js/list_view/partials/config.js.erb +11 -8
  69. data/lib/generators/faalis/templates/js/list_view/partials/index_controller.js.erb +5 -5
  70. data/lib/generators/faalis/templates/policy/application_policy.rb +2 -0
  71. data/lib/generators/faalis/templates/policy/policy.rb.erb +2 -0
  72. data/spec/dummy/db/development.sqlite3 +0 -0
  73. data/spec/dummy/db/migrate/{20150121060012_create_application_models.model_discovery_engine.rb → 20150723215115_create_application_models.model_discovery_engine.rb} +0 -0
  74. data/spec/dummy/db/migrate/20150725103007_devise_create_faalis_users.faalis.rb +63 -0
  75. data/spec/dummy/db/migrate/20150725103008_create_faalis_groups.faalis.rb +13 -0
  76. data/spec/dummy/db/migrate/20150725103009_create_faalis_permissions.faalis.rb +13 -0
  77. data/spec/dummy/db/migrate/20150725103010_add_permissions_groups_table.faalis.rb +9 -0
  78. data/spec/dummy/db/migrate/20150725103011_add_users_groups_table.faalis.rb +9 -0
  79. data/spec/dummy/db/schema.rb +5 -2
  80. data/spec/dummy/db/seeds.rb +1 -0
  81. data/spec/dummy/db/test.sqlite3 +0 -0
  82. data/spec/dummy/log/development.log +6474 -466
  83. data/spec/dummy/log/test.log +23493 -9554
  84. data/spec/dummy/tmp/app/assets/javascripts/controlpanel/application.js +22 -0
  85. data/spec/dummy/tmp/app/assets/stylesheets/dashboard/ltr/application.css +3 -0
  86. data/spec/dummy/tmp/app/assets/stylesheets/dashboard/rtl/application.css +3 -0
  87. data/spec/dummy/tmp/app/assets/stylesheets/ltr/application.css +3 -0
  88. data/spec/dummy/tmp/app/assets/stylesheets/rtl/application.css +3 -0
  89. data/spec/dummy/tmp/app/controllers/api_controller.rb +2 -0
  90. data/spec/dummy/tmp/app/controllers/application_controller.rb +0 -0
  91. data/spec/dummy/tmp/app/policies/application_policy.rb +2 -0
  92. data/spec/dummy/tmp/config/initializers/devise.rb +251 -0
  93. data/spec/dummy/tmp/config/initializers/faalis.rb +13 -0
  94. data/spec/dummy/tmp/config/initializers/fast_gettext.rb +4 -0
  95. data/spec/dummy/tmp/config/initializers/formstatic.rb +76 -0
  96. data/spec/dummy/tmp/config/routes.rb +0 -0
  97. data/spec/dummy/tmp/db/seeds.rb +1 -0
  98. metadata +73 -7
@@ -1,2 +1,4 @@
1
+ //= require angular-loading-bar/loading-bar
2
+
1
3
  //= require dashstrap/dashboard/rtl/application
2
4
  //= require dashstrap/rtl/application
@@ -3,6 +3,7 @@ require_dependency "faalis/application_controller"
3
3
  module Faalis
4
4
  class API::V1::PermissionsController < ::APIController
5
5
 
6
+ skip_after_action :verify_authorized
6
7
  respond_to :json
7
8
 
8
9
  class DummyPerm
@@ -14,7 +15,7 @@ module Faalis
14
15
  def index
15
16
  @permissions = {}
16
17
 
17
- Faalis::Permission.each do |perm|
18
+ Faalis::Permission.all.each do |perm|
18
19
  if @permissions.include? perm.model
19
20
  @permissions[perm.model] << perm.action
20
21
  else
@@ -24,9 +24,6 @@ module Faalis
24
24
  # which inherit from this class.
25
25
  class APIController < Faalis::ApplicationController
26
26
 
27
-
28
- include Pundit
29
-
30
27
  # Only support `json` format
31
28
  respond_to :json
32
29
 
@@ -17,6 +17,9 @@
17
17
  # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18
18
  # -----------------------------------------------------------------------------
19
19
  class Faalis::ApplicationController < ActionController::Base
20
+
21
+ include Pundit
22
+
20
23
  include FastGettext::Translation
21
24
 
22
25
  before_filter :set_locale
@@ -0,0 +1,80 @@
1
+ class Faalis::Dashboard::GroupsController < ::ApplicationController
2
+ layout false
3
+
4
+ before_action :get_all_permissions, only: [:new, :edit]
5
+
6
+ def new
7
+ authorize Faalis::Group
8
+ @group = Faalis::Group.new
9
+ end
10
+
11
+
12
+ def edit
13
+ @group = Faalis::Group.find(params[:id])
14
+ authorize @group
15
+ end
16
+
17
+ def create
18
+ authorize Faalis::Group
19
+
20
+ name = group_params[:name]
21
+ @group = Faalis::Group.new(name: name, role: name.underscore)
22
+
23
+ @group.permissions = populate_permissions
24
+
25
+ respond_to do |f|
26
+ if @group.save
27
+ f.js
28
+ f.html
29
+ else
30
+ f.js { render :errors }
31
+ f.html
32
+ end
33
+ end
34
+
35
+ end
36
+
37
+ def update
38
+ @group = Faalis::Group.find(params[:id])
39
+ authorize @group
40
+
41
+ @group.permissions = populate_permissions
42
+ @group.name = group_params[:name]
43
+ @group.role = group_params[:name].underscore
44
+
45
+ respond_to do |f|
46
+ if @group.save
47
+ f.js
48
+ f.html
49
+ else
50
+ f.js { render :errors }
51
+ f.html
52
+ end
53
+ end
54
+ end
55
+
56
+ private
57
+
58
+ def populate_permissions
59
+ unless group_params[:permissions].nil?
60
+ # TODO: Fix this for mongoid too.
61
+ ids = group_params[:permissions].keys.map(&:to_i)
62
+ Faalis::Permission.where(id: ids)
63
+ end
64
+ end
65
+
66
+ def group_params
67
+ params.require(:group).permit!
68
+ end
69
+
70
+ def get_all_permissions
71
+ @permissions = {}
72
+ Faalis::Permission.all.each do |perm|
73
+ if @permissions.include? perm.model
74
+ @permissions[perm.model] << [perm.permission_type, perm.id]
75
+ else
76
+ @permissions[perm.model] = [[perm.permission_type, perm.id]]
77
+ end
78
+ end
79
+ end
80
+ end
@@ -0,0 +1,100 @@
1
+ class Faalis::Dashboard::UsersController < ::ApplicationController
2
+ layout false
3
+
4
+ def index
5
+ authorize Faalis::User
6
+ @users = Faalis::User.all
7
+ end
8
+
9
+ def new
10
+ authorize Faalis::User
11
+ @user = Faalis::User.new
12
+ @groups = Faalis::Group.all
13
+ end
14
+
15
+ def show
16
+ @user = Faalis::User.find(params[:id])
17
+ authorize @user
18
+ end
19
+
20
+ def edit
21
+ @user = Faalis::User.find(params[:id])
22
+ @groups = Faalis::Group.all
23
+ authorize @user
24
+ end
25
+
26
+ def create
27
+ authorize Faalis::User
28
+ group_ids = user_params[:groups]
29
+
30
+ @user = Faalis::User.new(user_params)
31
+ @user.groups = Faalis::Group.where(id: group_ids)
32
+
33
+ respond_to do |f|
34
+ if @save.save
35
+ f.js
36
+ f.html
37
+ else
38
+ f.js { render :errors }
39
+ f.html
40
+ end
41
+ end
42
+ end
43
+
44
+ def update
45
+ parameters = user_params
46
+ group_ids = parameters.delete(:groups).map(&:to_i)
47
+
48
+ @user = Faalis::User.find(params[:id])
49
+ authorize @user
50
+
51
+ @user.groups = Faalis::Group.where(id: group_ids)
52
+ @user.save
53
+
54
+ respond_to do |f|
55
+ if @user.update_without_password(parameters)
56
+ f.js
57
+ f.html
58
+ else
59
+ f.js { render :errors }
60
+ f.html
61
+ end
62
+ end
63
+ end
64
+
65
+ def edit_password
66
+ @user = Faalis::User.find(params[:id])
67
+ authorize @user, :update?
68
+ end
69
+
70
+ def update_password
71
+ @user = Faalis::User.find(params[:id])
72
+ authorize @user, :update?
73
+
74
+ respond_to do |f|
75
+ if @user.update(password_params)
76
+ f.js
77
+ f.html
78
+ else
79
+ f.js { render :errors }
80
+ f.html
81
+ end
82
+ end
83
+ end
84
+
85
+ def destroy
86
+ end
87
+
88
+ private
89
+
90
+ def password_params
91
+ params.require(:user).permit(:password, :password_confirmation)
92
+ end
93
+
94
+ def user_params
95
+ params.require(:user).permit(:first_name,
96
+ :last_name,
97
+ :email,
98
+ groups: [])
99
+ end
100
+ end
@@ -13,7 +13,11 @@ module Faalis
13
13
 
14
14
  def jstemplate
15
15
  if user_signed_in?
16
- logger.info "#{'JS_TEMPLATE'.yellow}: angular/#{params[:path]}"
16
+
17
+ js_template = 'JS_TEMPLATE'
18
+ js_template.yellow if String.respond_to? :colorize
19
+
20
+ logger.info "#{js_template}: angular/#{params[:path]}"
17
21
  render template: "angular/#{params[:path]}", layout: nil
18
22
  else
19
23
  render :login_required_page
@@ -1,4 +1,8 @@
1
1
  module Faalis
2
2
  module UsersHelper
3
+ def faalisify_url(url)
4
+ dashboard = Faalis::Engine.dashboard_namespace
5
+ return url.gsub("/#{dashboard}/", "/#{dashboard}#/")
6
+ end
3
7
  end
4
8
  end
@@ -4,6 +4,11 @@ module Faalis
4
4
  module Concerns::User::Permission
5
5
  extend ActiveSupport::Concern
6
6
 
7
+ def member_of?(group)
8
+ @group_ids ||= self.groups.all.map(&:id)
9
+ @group_ids.include? group.id
10
+ end
11
+
7
12
  def have_permission? action, obj
8
13
  perm = self.groups.includes(:permissions)
9
14
  .where(faalis_permissions: { model: obj, permission_type: action })
@@ -35,5 +35,19 @@ module Faalis
35
35
  def self.policy_class
36
36
  GroupPolicy
37
37
  end
38
+
39
+ def include_permission?(perm)
40
+ if perm.is_a? Fixnum
41
+ permission_ids.include? perm
42
+ else
43
+ permission_ids.include? perm.id
44
+ end
45
+ end
46
+
47
+ private
48
+
49
+ def permission_ids
50
+ @permission_ids ||= permissions.map(&:id)
51
+ end
38
52
  end
39
53
  end
@@ -34,5 +34,8 @@ module Faalis
34
34
  "#{self.permission_type.to_s}|#{self.model}"
35
35
  end
36
36
 
37
+ def model_name
38
+ model.underscore.humanize
39
+ end
37
40
  end
38
41
  end
@@ -1,21 +1,2 @@
1
- <div class="details">
2
- <p>
3
- <b translate>Group Name :</b>{{this.object.name}}
4
- </p>
5
-
6
- <p>
7
- <b translate>Permissions :</b>
8
- <ul>
9
- <li ng-repeat="perm in this.object.permissions">{{ perm.string_repr }}</li>
10
- </ul>
11
- </p>
12
-
13
- <ul class="button-group float-right">
14
- <a ng-href="#/auth/groups/{{ this.object.id }}/edit" class="small">
15
- <span class="fa fa-edit"></span> <span translated>Edit</span>
16
- </a>
17
- <!--<a ng-href="#/auth/groups/{{ this.object.id }}" class="small">
18
- <span class="fa fa-eye"></span><span translated>Show</span>-->
19
- </a>
20
- </ul>
21
- </div>
1
+ <h1>TODO: You have to either use a template gem like 'dashstrap' or override this templates in your code base</h1>
2
+ <h2>/auth/groups/details</h2>
@@ -1,5 +1,2 @@
1
- <list-view buttons="buttons" objects="groups" title-attribute="'name'" details-template="details_template" item-per-page="10" on_delete="on_delete">
2
- <div class="small-6 column text-left clearpadding">
3
- <h3><i class="fa fa-group"></i> <span translate>Groups</span></h3>
4
- </div>
5
- </list-view>
1
+ <h1>TODO: You have to either use a template gem like 'dashstrap' or override this templates in your code base</h1>
2
+ <h2>/auth/groups/index</h2>
@@ -1,47 +1,2 @@
1
- <div class="newform">
2
- <form name="from" novalidate>
3
-
4
- <fieldset class="form">
5
-
6
- <legend ng-if="!editing"><span translate>New Group</span></legend>
7
- <legend ng-if="editing"><span translate>Edit Group</span></legend>
8
-
9
- <div class="row">
10
- <div class="small-4 columns">
11
- <label translate>Name :</label>
12
- <input id="id_name" ng-model="new_name" type="text" required>
13
- <small id="id_name_msg"></small>
14
- </div>
15
- </div>
16
- </fieldset>
17
-
18
- <fieldset>
19
- <legend translate>Advance Permissions</legend>
20
- <div class="row">
21
- <label for="permissions" translate>Permissions</label>
22
- </div>
23
-
24
- <div class="small-10 columns permissions">
25
-
26
- <div class="row">
27
- <div id="id_permissions" class="small-8 columns field">
28
- <ul>
29
-
30
- <li ng-repeat="permission in permissions" id="{{permission.name}}" ng-click="select_permission(permission)"> <i ng-show="is_selected(permission)" class="fa fa-check"></i> {{ permission.string }} </li>
31
-
32
- </ul>
33
- </div>
34
- <small id="id_permissions_msg"></small>
35
- </div>
36
- </div>
37
- </fieldset>
38
-
39
- <div class="row">
40
- <div class="small-6 columns">
41
- <button class="btn small green" ng-click="save()" ng-disabled="form.$invalid"><i class="fa fa-check"></i> <span translate>Save</span></button>
42
- <button class="btn small red" ng-click="cancel()"><i class="fa fa-times"></i><span translate>Cansel</span></button>
43
- </div>
44
- </div>
45
- </form>
46
-
47
- </div>
1
+ <h1>TODO: You have to either use a template gem like 'dashstrap' or override this templates in your code base</h1>
2
+ <h2>/auth/groups/new</h2>
@@ -1,6 +1,6 @@
1
- json.array! @groups do |group|
2
- json.extract! group, :id, :name
3
- json.permissions group.permissions do |permission|
4
- json.(permission, :to_s)
1
+ json.cache! ['v1', @groups], expires_in: 1.days do
2
+ json.array! @groups do |group|
3
+ json.extract! group, :id, :name
4
+ json.permissions Hash[group.permissions.group_by(&:model).map { |k, v| [k, v.map(&:permission_type)]}]
5
5
  end
6
6
  end
@@ -1 +1 @@
1
- json.permissions @permissions
1
+ json.array! [{ permissions: @permissions }]
@@ -0,0 +1,72 @@
1
+ div
2
+ = form_tag(form_target, remote: true, method: method) do
3
+ .row
4
+ .col-sm-12.col-lg-9
5
+ .box.box-primary
6
+ .box-header
7
+ .box-title
8
+ - if @group.new_record?
9
+ = _('New Group')
10
+ - else
11
+ = _('Edit Group')
12
+
13
+ .box-body
14
+ .row
15
+ .col-sm-12.col-lg-6
16
+ .form-group data-name="role"
17
+ label for="group_name"
18
+ = ('Group name')
19
+
20
+ input#group_name.form-control[placeholder==(_('Enter the name of group you want to create')) name="group[name]" type="text" required value=(@group.name)]
21
+
22
+
23
+
24
+ .col-sm-12.col-lg-3
25
+ .box
26
+ .box-header
27
+ .box-title
28
+ = _('Groups to use as template')
29
+ .row
30
+ .col-sm-12.col-lg-9
31
+ .box.box-warning
32
+ .box-header
33
+ .box-title
34
+ = _("Permissions")
35
+
36
+ .box-body
37
+ .row
38
+ .col-xs-12
39
+ table.table.table-striped
40
+ tbody
41
+ tr
42
+ th.col-md-4
43
+ = _('Entity Name')
44
+ th.col-md-8
45
+ = _('Permission')
46
+
47
+ - @permissions.each do |perm, actions|
48
+ tr
49
+ td.col-md-4
50
+ = perm.gsub('::',' ').humanize
51
+ td.col-md-8
52
+ - actions.each do |action|
53
+ span.col-sm-3
54
+ - if @group.include_permission? action[1]
55
+ input[type="checkbox" checked name=("group[permissions][#{action[1]}]") label=(_(action[0].humanize()))]
56
+ = action[0].humanize()
57
+ - else
58
+ input[type="checkbox" name=("group[permissions][#{action[1]}]") label=(_(action[0].humanize()))]
59
+ = action[0].humanize()
60
+
61
+ .row
62
+ .col-sm-2
63
+ button.btn.btn-primary.btn-block type="submit"
64
+ i.fa.fa-check
65
+ |
66
+ = _('Save')
67
+
68
+ .col-sm-2
69
+
70
+ div.btn.btn-danger.btn-block onclick=("redirect_to('#{index}')")
71
+ i.fa.fa-times
72
+ = _('Cancel')