faalis 1.0.0.alpha1 → 1.0.0.alpha2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +11 -10
- data/Rakefile +6 -2
- data/app/assets/javascripts/faalis/angular-manifest.js +3 -0
- data/app/assets/javascripts/faalis/application.js +0 -1
- data/app/assets/javascripts/faalis/dashboard/app.js +20 -6
- data/app/assets/javascripts/faalis/dashboard/application.js.erb +5 -1
- data/app/assets/javascripts/faalis/dashboard/controllers/group.js.coffee +42 -0
- data/app/assets/javascripts/faalis/dashboard/functions.js.erb +20 -0
- data/app/assets/javascripts/faalis/dashboard/init.js +1 -1
- data/app/assets/javascripts/faalis/dashboard/lib/button.js.coffee +17 -0
- data/app/assets/javascripts/faalis/dashboard/lib/controllers.js.coffee +11 -0
- data/app/assets/javascripts/faalis/dashboard/lib/controllers/base_controller.js.coffee +14 -0
- data/app/assets/javascripts/faalis/dashboard/lib/controllers/generic_add_controller.js.coffee +33 -0
- data/app/assets/javascripts/faalis/dashboard/lib/controllers/generic_index_controller.js.coffee +85 -0
- data/app/assets/javascripts/faalis/dashboard/lib/fields/base.js.coffee +6 -0
- data/app/assets/javascripts/faalis/dashboard/lib/fields/has_many_field.js.coffee +4 -0
- data/app/assets/javascripts/faalis/dashboard/lib/fields/string_field.js.coffee +2 -0
- data/app/assets/javascripts/faalis/dashboard/lib/resource.js.coffee +147 -0
- data/app/assets/javascripts/faalis/dashboard/modules/auth/auth.js +5 -3
- data/app/assets/javascripts/faalis/dashboard/modules/auth/profile.js +6 -5
- data/app/assets/javascripts/faalis/dashboard/modules/auth/user.js +12 -10
- data/app/assets/javascripts/faalis/dashboard/modules/conversations.js +2 -1
- data/app/assets/javascripts/faalis/dashboard/modules/fields/#image.js# +43 -0
- data/app/assets/javascripts/faalis/dashboard/modules/fields/date.js +51 -0
- data/app/assets/javascripts/faalis/dashboard/modules/fields/datetime.js +26 -15
- data/app/assets/javascripts/faalis/dashboard/modules/fields/fields.js +3 -1
- data/app/assets/javascripts/faalis/dashboard/modules/fields/file.js +43 -0
- data/app/assets/javascripts/faalis/dashboard/modules/fields/image.js +33 -46
- data/app/assets/javascripts/faalis/dashboard/modules/fields/relation.js +7 -4
- data/app/assets/javascripts/faalis/dashboard/modules/fields/tag.js +5 -11
- data/app/assets/javascripts/faalis/dashboard/modules/fields/time.js +34 -122
- data/app/assets/javascripts/faalis/dashboard/modules/logs.js +5 -4
- data/app/assets/javascripts/faalis/dashboard/modules/permissions.js.coffee +38 -0
- data/app/assets/javascripts/faalis/dashboard/resources/group_resource.js.coffee +8 -0
- data/app/assets/javascripts/faalis/dashboard/resources/permission_resource.js.coffee +6 -0
- data/app/assets/javascripts/faalis/dashboard/services/api.js.coffee +73 -0
- data/app/assets/javascripts/faalis/dashboard/services/resource_factory.js.coffee +48 -0
- data/app/assets/javascripts/faalis/dashboard/services/user.js.coffee +4 -0
- data/app/assets/javascripts/faalis/dashboard/variables.js.erb +5 -0
- data/app/assets/javascripts/faalis/{locales → locale}/en.json +0 -0
- data/app/assets/javascripts/faalis/{locales → locale}/fa.json +0 -0
- data/app/assets/javascripts/faalis/{locales → locale}/translations.fa.js +0 -0
- data/app/controllers/faalis/api/v1/groups_controller.rb +53 -57
- data/app/controllers/faalis/api/v1/permissions_controller.rb +29 -12
- data/app/controllers/faalis/api_controller.rb +19 -12
- data/app/controllers/faalis/application_controller.rb +8 -7
- data/app/controllers/faalis/dashboard_controller.rb +5 -11
- data/app/models/faalis/{user → concerns/user}/auth_definitions.rb +6 -1
- data/app/models/faalis/{user → concerns/user}/mongoid_fields.rb +8 -2
- data/app/models/faalis/concerns/user/permission.rb +24 -0
- data/app/models/faalis/concerns/user/user_roles.rb +20 -0
- data/app/models/faalis/group.rb +13 -15
- data/app/models/faalis/permission.rb +15 -1
- data/app/models/faalis/user.rb +44 -20
- data/app/policies/faalis/admin_only_policy.rb +66 -0
- data/app/policies/faalis/application_policy.rb +40 -0
- data/app/policies/faalis/group_policy.rb +8 -0
- data/app/policies/faalis/user_policy.rb +9 -0
- data/app/views/{angularjs_templates → angular}/auth/groups/details.html +0 -0
- data/app/views/{angularjs_templates → angular}/auth/groups/index.html +0 -0
- data/app/views/{angularjs_templates → angular}/auth/groups/new.html +0 -0
- data/app/views/{angularjs_templates → angular}/auth/index.html +0 -0
- data/app/views/{angularjs_templates → angular}/auth/profile/edit.html +0 -0
- data/app/views/{angularjs_templates → angular}/auth/users/details.html +0 -0
- data/app/views/{angularjs_templates → angular}/auth/users/index.html +0 -0
- data/app/views/{angularjs_templates → angular}/auth/users/new.html +0 -0
- data/app/views/{angularjs_templates → angular}/conversations/details.html +0 -0
- data/app/views/{angularjs_templates → angular}/conversations/index.html +0 -0
- data/app/views/{angularjs_templates → angular}/conversations/new.html +0 -0
- data/app/views/{angularjs_templates → angular}/conversations/show.html +0 -0
- data/app/views/{angularjs_templates → angular}/conversations/show_details.html +0 -0
- data/app/views/angular/faalis/views/generic_add_view.html.slim +5 -0
- data/app/views/{angularjs_templates → angular}/fields/boolean/boolean.html +0 -0
- data/app/views/{angularjs_templates → angular}/fields/control-combo/control-list.html +0 -0
- data/app/views/{angularjs_templates → angular}/fields/datetime/datetime.html +0 -0
- data/app/views/{angularjs_templates → angular}/fields/datetime/time.html +0 -0
- data/app/views/angular/fields/file/file.html.slim +0 -0
- data/app/views/{angularjs_templates → angular}/fields/float/float.html +0 -0
- data/app/views/{angularjs_templates → angular}/fields/image/image.html +0 -0
- data/app/views/{angularjs_templates → angular}/fields/integer/integer.html +0 -0
- data/app/views/{angularjs_templates → angular}/fields/relation/relation.html +0 -0
- data/app/views/{angularjs_templates → angular}/fields/string/string.html +0 -0
- data/app/views/{angularjs_templates → angular}/fields/tag/tag.html +0 -0
- data/app/views/{angularjs_templates → angular}/fields/text/text.html +0 -0
- data/app/views/{angularjs_templates → angular}/filter/index.html +0 -0
- data/app/views/{angularjs_templates → angular}/index.html +0 -0
- data/app/views/{angularjs_templates → angular}/locale/fa.po +0 -0
- data/app/views/{angularjs_templates → angular}/locale/templates.pot +0 -0
- data/app/views/{angularjs_templates → angular}/logs/index.html +0 -0
- data/app/views/angular/modules.html +0 -0
- data/app/views/{angularjs_templates → angular}/nav.html.erb +0 -0
- data/app/views/faalis/api/v1/groups/index.json.jbuilder +1 -1
- data/app/views/faalis/api/v1/permissions/index.json.jbuilder +1 -1
- data/app/views/faalis/dashboard/index.html.erb +1 -1
- data/app/views/layouts/faalis/application.html.erb +1 -1
- data/config/routes.rb +1 -7
- data/config/spring.rb +1 -0
- data/db/migrate/20131013091000_devise_create_faalis_users.rb +4 -4
- data/db/migrate/20131020124701_create_faalis_groups.rb +3 -0
- data/db/migrate/20131021170923_create_faalis_permissions.rb +2 -0
- data/db/seeds.rb +15 -13
- data/lib/faalis.rb +2 -2
- data/lib/faalis/concerns/authorizable.rb +1 -0
- data/lib/faalis/engine.rb +15 -16
- data/lib/faalis/{extensions.rb → extension.rb} +1 -1
- data/lib/faalis/{extensions → extension}/base.rb +0 -0
- data/lib/faalis/fake_assets.rb +2 -0
- data/lib/faalis/generators/concerns.rb +1 -1
- data/lib/faalis/generators/concerns/angular.rb +1 -1
- data/lib/faalis/generators/concerns/bulk.rb +1 -2
- data/lib/faalis/generators/concerns/input_file.rb +49 -0
- data/lib/faalis/generators/concerns/resource_fields.rb +4 -0
- data/lib/faalis/generators/concerns/tabs.rb +1 -1
- data/lib/faalis/generators/dashboard_scaffold.rb +3 -1
- data/lib/faalis/i18n.rb +1 -0
- data/lib/faalis/route.rb +26 -9
- data/lib/faalis/version.rb +1 -1
- data/lib/faalis_application.rb +442 -0
- data/lib/generators/faalis/install_generator.rb +4 -2
- data/lib/generators/faalis/js/list_view_generator.rb +3 -22
- data/lib/generators/faalis/scaffold_generator.rb +7 -10
- data/lib/generators/faalis/templates/README +0 -7
- data/lib/generators/faalis/templates/angularjs/module.js.erb +4 -1
- data/lib/generators/faalis/templates/api/controller.rb.erb +18 -21
- data/lib/generators/faalis/templates/application.js +14 -1
- data/lib/generators/faalis/templates/faalis.rb +3 -1
- data/lib/generators/faalis/templates/i18n/Gruntfile.js.erb +2 -2
- data/lib/generators/faalis/templates/js/list_view/partials/add_controller.js.erb +3 -3
- data/lib/generators/faalis/views_generator.rb +1 -1
- data/lib/tasks/docs.rake +6 -0
- data/lib/tasks/faalis_tasks.rake +1 -0
- data/lib/tasks/grunt/Gruntfile.js +3 -3
- data/spec/dummy/app/controllers/api_controller.rb +5 -0
- data/spec/dummy/config/initializers/faalis.rb +3 -3
- data/spec/dummy/db/development.sqlite3 +0 -0
- data/spec/dummy/db/migrate/20150121060012_create_application_models.model_discovery_engine.rb +10 -0
- data/spec/dummy/db/schema.rb +71 -0
- data/spec/dummy/db/test.sqlite3 +0 -0
- data/spec/dummy/log/development.log +544 -0
- data/spec/dummy/log/test.log +12354 -0
- data/spec/factories/faalis/groups.rb +31 -0
- data/spec/factories/faalis/permissions.rb +16 -0
- data/spec/factories/faalis/users.rb +23 -0
- data/spec/models/faalis/group_spec.rb +32 -0
- data/spec/models/faalis/permission_spec.rb +15 -0
- data/spec/models/faalis/user_spec.rb +100 -0
- data/spec/policies/faalis/admin_only_policy_spec.rb +39 -0
- data/spec/policies/faalis/application_policy_spec.rb +49 -0
- data/spec/spec_helper.rb +26 -5
- data/spec/support/factory_girl.rb +3 -0
- metadata +225 -102
- data/app/assets/javascripts/faalis/dashboard/modules/auth/group.js +0 -155
- data/app/assets/javascripts/faalis/dashboard/modules/permissions.js +0 -52
- data/app/controllers/faalis/#api_controller.rb# +0 -51
- data/app/controllers/faalis/#dashboard_controller.rb# +0 -65
- data/app/models/ability.rb +0 -40
- data/app/models/faalis/user/permission.rb +0 -21
- data/app/views/angularjs_templates/modules.html +0 -17
- data/db/migrate/20140617124019_faalis_groups_users.rb +0 -4
- data/lib/faalis/generators/concerns/json_input.rb +0 -41
- data/lib/faalis/generators/fields/#relation.rb# +0 -61
- data/lib/faalis/patches/models.rb +0 -7
@@ -0,0 +1,48 @@
|
|
1
|
+
Resource = angular.module "Faalis.ResourceFactory", []
|
2
|
+
|
3
|
+
Resource.provider "Resources", [->
|
4
|
+
|
5
|
+
# resources should be an array of resource factories
|
6
|
+
@resources = undefined
|
7
|
+
|
8
|
+
# This field will specify the main resource class
|
9
|
+
# for current functionality. First element of
|
10
|
+
# @resource will be used if `main_resource` was undefined
|
11
|
+
@main_resource = undefined
|
12
|
+
|
13
|
+
|
14
|
+
this.$get = [->
|
15
|
+
|
16
|
+
main_resource = @main_resources || @resources[0]
|
17
|
+
resources = @resources
|
18
|
+
|
19
|
+
# Public injector to inject required services into
|
20
|
+
# resources `initialize` method.
|
21
|
+
|
22
|
+
#deps = window.STATIC_REQUIREMENTS.concat(window.dashboard_dependencies)
|
23
|
+
#$injector = angular.injector(deps)
|
24
|
+
$injector = angular.injector(['ng', 'Errors', 'gettext'])
|
25
|
+
|
26
|
+
obj = {}
|
27
|
+
|
28
|
+
for resource in resources
|
29
|
+
unless resource.__name__?
|
30
|
+
throw "Resource '" + resource + "' does not have a 'name'"
|
31
|
+
|
32
|
+
unless resource.__init__?
|
33
|
+
throw "Resource '" + resource.name + "' does not have '__init__' method."
|
34
|
+
|
35
|
+
Faalis.$injector.invoke(resource.__init__, resource)
|
36
|
+
|
37
|
+
obj[resource.__name__.underscore()] = resource
|
38
|
+
|
39
|
+
obj.main_resource = ->
|
40
|
+
return main_resource
|
41
|
+
|
42
|
+
obj.all = ->
|
43
|
+
return resources
|
44
|
+
|
45
|
+
return obj
|
46
|
+
]
|
47
|
+
return
|
48
|
+
]
|
@@ -17,3 +17,8 @@ window.templates_path = "/templates/";
|
|
17
17
|
// Any element of this queue will be appear as error after load event
|
18
18
|
window.ErrorQueue = [];
|
19
19
|
window.DashboardURL = "<%= url.modules_path %>";
|
20
|
+
window.Faalis = {};
|
21
|
+
|
22
|
+
window.STATIC_REQUIREMENTS = ["gettext", "Modules", "ui.select2", 'Errors',
|
23
|
+
"ngAnimate", "ui.router", "restangular", "ngQuickDate",
|
24
|
+
"Errors", "Profile", "Permissions", 'ng'];
|
File without changes
|
File without changes
|
File without changes
|
@@ -1,75 +1,71 @@
|
|
1
|
-
require_dependency
|
1
|
+
require_dependency 'faalis/api_controller'
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
# TODO: implement authorization
|
3
|
+
class Faalis::API::V1::GroupsController < ::APIController
|
4
|
+
# TODO: Use strong params
|
5
|
+
after_action :verify_authorized, :except => :index
|
7
6
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
def create
|
16
|
-
authorize! :create, Faalis::Group
|
7
|
+
# GET /api/v1/groups
|
8
|
+
def index
|
9
|
+
@groups = Faalis::Group.includes(:permissions).all
|
10
|
+
authorize @groups
|
11
|
+
respond_with(@groups)
|
12
|
+
end
|
17
13
|
|
18
|
-
|
14
|
+
def create
|
19
15
|
|
20
|
-
|
21
|
-
|
22
|
-
permission = Permission.find_or_create_by_model_and_permission_type(model, perm)
|
23
|
-
permissions << permission
|
24
|
-
end
|
16
|
+
authorize Faalis::Group, :create?
|
17
|
+
permissions = [];
|
25
18
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
if @group.save
|
31
|
-
respond_with(@group)
|
32
|
-
else
|
33
|
-
respond_to do |format|
|
34
|
-
format.json { render :json => {:fields => @group.errors}, :status => :unprocessable_entity }
|
35
|
-
end
|
36
|
-
end
|
19
|
+
(params[:permissions] || []).each do |perm_string|
|
20
|
+
perm, model = perm_string.split "|"
|
21
|
+
permission = Faalis::Permission.find_or_create_by_model_and_permission_type(model, perm)
|
22
|
+
permissions << permission
|
37
23
|
end
|
38
24
|
|
39
|
-
|
40
|
-
|
41
|
-
|
25
|
+
@group = Faalis::Group.new({ name: params[:name],
|
26
|
+
permissions: permissions })
|
27
|
+
if @group.save
|
42
28
|
respond_with(@group)
|
29
|
+
else
|
30
|
+
respond_to do |format|
|
31
|
+
format.json { render json: { fields: @group.errors },
|
32
|
+
status: :unprocessable_entity }
|
33
|
+
end
|
43
34
|
end
|
35
|
+
end
|
44
36
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
37
|
+
def show
|
38
|
+
@group = Faalis::Group.find(params[:id])
|
39
|
+
authorize @group
|
40
|
+
respond_with(@group)
|
41
|
+
end
|
49
42
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
permission = Permission.find_or_create_by_model_and_permission_type(model, perm)
|
54
|
-
permissions << permission
|
55
|
-
end
|
43
|
+
def update
|
44
|
+
@group = Faalis::Group.find(params[:id])
|
45
|
+
authorize @group
|
56
46
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
format.json { render :json => {:fields => @group.errors}, :status => :unprocessable_entity }
|
63
|
-
end
|
64
|
-
end
|
47
|
+
permissions = [];
|
48
|
+
(params[:permissions] || []).each do |perm_string|
|
49
|
+
perm, model = perm_string.split '|'
|
50
|
+
permission = Faalis::Permission.find_or_create_by_model_and_permission_type(model, perm)
|
51
|
+
permissions << permission
|
65
52
|
end
|
66
53
|
|
67
|
-
|
68
|
-
|
69
|
-
@
|
70
|
-
|
71
|
-
|
54
|
+
if @group.update(:name => params[:name],
|
55
|
+
:permissions => permissions)
|
56
|
+
respond_with(@group)
|
57
|
+
else
|
58
|
+
respond_to do |format|
|
59
|
+
format.json { render json: { fields: @group.errors },
|
60
|
+
status: :unprocessable_entity }
|
61
|
+
end
|
72
62
|
end
|
73
63
|
end
|
74
64
|
|
65
|
+
def destroy
|
66
|
+
ids = params[:id].split(",")
|
67
|
+
@groups = Faalis::Group.where(:id => ids)
|
68
|
+
authorize @groups
|
69
|
+
@groups.destroy_all
|
70
|
+
end
|
75
71
|
end
|
@@ -3,29 +3,46 @@ require_dependency "faalis/application_controller"
|
|
3
3
|
module Faalis
|
4
4
|
class API::V1::PermissionsController < ::APIController
|
5
5
|
|
6
|
+
respond_to :json
|
7
|
+
|
6
8
|
class DummyPerm
|
7
9
|
attr_accessor :model, :permission_type
|
8
10
|
end
|
9
11
|
|
10
|
-
#
|
11
|
-
#
|
12
|
+
# api GET permissions
|
13
|
+
# return All permissions
|
12
14
|
def index
|
13
|
-
@permissions =
|
15
|
+
@permissions = {}
|
16
|
+
|
17
|
+
Faalis::Permission.each do |perm|
|
18
|
+
if @permissions.include? perm.model
|
19
|
+
@permissions[perm.model] << perm.action
|
20
|
+
else
|
21
|
+
@permissions[perm.model] = [perm.action]
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
14
25
|
respond_with(@permissions)
|
15
26
|
end
|
16
27
|
|
17
|
-
#
|
18
|
-
#
|
28
|
+
# api GET permissions/user
|
29
|
+
# return current user permissions
|
19
30
|
def user_permissions
|
31
|
+
|
20
32
|
@permissions = {}
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
33
|
+
current_user.permissions.each do |perm|
|
34
|
+
if @permissions.include? perm.model
|
35
|
+
@permissions[perm.model] << perm.action
|
36
|
+
else
|
37
|
+
@permissions[perm.model] = [perm.action]
|
38
|
+
end
|
27
39
|
end
|
28
|
-
|
40
|
+
|
41
|
+
respond_with(@permissions)
|
42
|
+
return
|
43
|
+
|
44
|
+
@permissions = {}
|
45
|
+
perms = []
|
29
46
|
|
30
47
|
# Generate a suitable Hash for permissions
|
31
48
|
perms.each do |perm|
|
@@ -24,30 +24,34 @@ module Faalis
|
|
24
24
|
# which inherit from this class.
|
25
25
|
class APIController < Faalis::ApplicationController
|
26
26
|
|
27
|
+
|
28
|
+
include Pundit
|
29
|
+
|
27
30
|
# Only support `json` format
|
28
31
|
respond_to :json
|
29
32
|
|
33
|
+
protect_from_forgery
|
34
|
+
skip_before_action :verify_authenticity_token, if: :api_request?
|
35
|
+
|
30
36
|
# Authenticate user before any action take place
|
31
|
-
|
37
|
+
before_action :authenticate_filter
|
32
38
|
|
33
39
|
# Check for any presence of filtering query, In querystring and load
|
34
40
|
# resource using them
|
35
|
-
|
36
|
-
|
37
|
-
protect_from_forgery
|
41
|
+
before_action :load_resource_by_query, :only => [:index]
|
38
42
|
|
39
43
|
# Set csrf cookie after any action
|
40
|
-
|
44
|
+
after_action :set_csrf_cookie_for_ng
|
41
45
|
|
42
46
|
# Rescue from any access denied exception raised from cancan and
|
43
47
|
# returns a useful error message in json
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
48
|
+
# rescue_from CanCan::AccessDenied do |exception|
|
49
|
+
# render :status => 403, :json => {
|
50
|
+
# :error => _('You don\'t have access to this page'),
|
51
|
+
# :orig_msg => exception.message,
|
52
|
+
# :action => exception.action
|
53
|
+
# }
|
54
|
+
# end
|
51
55
|
|
52
56
|
def set_csrf_cookie_for_ng
|
53
57
|
cookies['XSRF-TOKEN'] = form_authenticity_token if protect_against_forgery?
|
@@ -143,5 +147,8 @@ module Faalis
|
|
143
147
|
super || form_authenticity_token == request.headers['X-XSRF-TOKEN']
|
144
148
|
end
|
145
149
|
|
150
|
+
def api_request?
|
151
|
+
request.format.json?
|
152
|
+
end
|
146
153
|
end
|
147
154
|
end
|
@@ -18,16 +18,17 @@
|
|
18
18
|
# -----------------------------------------------------------------------------
|
19
19
|
class Faalis::ApplicationController < ActionController::Base
|
20
20
|
include FastGettext::Translation
|
21
|
+
|
21
22
|
before_filter :set_locale
|
22
23
|
|
23
24
|
def set_locale
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
25
|
+
FastGettext.add_text_domain 'faalis', :path => "#{Faalis::Engine.root}/config/locales", :type => :po
|
26
|
+
# All languages you want to allow
|
27
|
+
FastGettext.default_available_locales = Faalis::Engine.locales
|
28
|
+
FastGettext.default_text_domain = 'faalis'
|
28
29
|
|
29
|
-
|
30
|
-
|
31
|
-
|
30
|
+
lang = request.env['lang'] || params[:locale] || session[:locale] || I18n.default_locale
|
31
|
+
FastGettext.set_locale(lang.to_s)
|
32
|
+
session[:locale] = I18n.locale = :"#{lang}"
|
32
33
|
end
|
33
34
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require_dependency
|
1
|
+
require_dependency 'faalis/application_controller'
|
2
2
|
|
3
3
|
|
4
4
|
module Faalis
|
@@ -13,29 +13,23 @@ module Faalis
|
|
13
13
|
|
14
14
|
def jstemplate
|
15
15
|
if user_signed_in?
|
16
|
-
render :
|
16
|
+
render template: "angular/#{params[:path]}", layout: nil
|
17
17
|
else
|
18
18
|
render :login_required_page
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
22
22
|
def index
|
23
|
-
if params.include? :signin
|
24
|
-
redirect_to dashboard_path
|
25
|
-
end
|
23
|
+
redirect_to dashboard_path if params.include? :signin
|
26
24
|
@jstemplates_path = '/templates'
|
27
25
|
end
|
28
26
|
|
29
27
|
def modules
|
30
28
|
dashboard_modules = []
|
31
29
|
Faalis::Engine.dashboard_modules.each do |module_name, attrs|
|
32
|
-
if not attrs.include? :title
|
33
|
-
attrs[:title] = _(module_name.to_s)
|
34
|
-
end
|
35
30
|
|
36
|
-
if not attrs.include? :
|
37
|
-
|
38
|
-
end
|
31
|
+
attrs[:title] = _(module_name.to_s) if not attrs.include? :title
|
32
|
+
attrs[:resource] = module_name.to_s if not attrs.include? :resource
|
39
33
|
|
40
34
|
# If class did not given by user in settings
|
41
35
|
# Faalis tries to guess the class name
|
@@ -1,5 +1,5 @@
|
|
1
1
|
module Faalis
|
2
|
-
module User::AuthDefinitions
|
2
|
+
module Concerns::User::AuthDefinitions
|
3
3
|
|
4
4
|
def self.included(base)
|
5
5
|
|
@@ -29,6 +29,10 @@ module Faalis
|
|
29
29
|
name
|
30
30
|
end
|
31
31
|
|
32
|
+
def admin?
|
33
|
+
# TODO: Find a better way to 'admin?'
|
34
|
+
groups.where(role: 'admin').exists?
|
35
|
+
end
|
32
36
|
|
33
37
|
# Confirmation not required when using omniauth
|
34
38
|
def confirmation_required?
|
@@ -43,6 +47,7 @@ module Faalis
|
|
43
47
|
end
|
44
48
|
end
|
45
49
|
|
50
|
+
# Omniauth users does not need password
|
46
51
|
def password_required?
|
47
52
|
# TODO: nil? is not suitable for here we should use empty? or blink?
|
48
53
|
if Devise.omniauth_configs.any?
|
@@ -1,6 +1,6 @@
|
|
1
1
|
module Faalis
|
2
2
|
# This module contains all the **Mongoid** related definitions
|
3
|
-
module User::MongoidFields
|
3
|
+
module Concerns::User::MongoidFields
|
4
4
|
extend ActiveSupport::Concern
|
5
5
|
|
6
6
|
included do
|
@@ -43,7 +43,7 @@ module Faalis
|
|
43
43
|
if not Devise.omniauth_providers.empty?
|
44
44
|
# Service
|
45
45
|
field :provider, type: String, default: ''
|
46
|
-
field :uid,
|
46
|
+
field :uid, type: String
|
47
47
|
end
|
48
48
|
|
49
49
|
if Rails.env.production?
|
@@ -66,6 +66,12 @@ module Faalis
|
|
66
66
|
index({ authentication_token: 1 },
|
67
67
|
{ unique: true, background: true })
|
68
68
|
|
69
|
+
# To fix the issue with new mongo
|
70
|
+
#def self.serialize_from_session(key, salt)
|
71
|
+
# record = to_adapter.get(key[0]["$oid"])
|
72
|
+
# record if record && record.authenticatable_salt == salt
|
73
|
+
#end
|
74
|
+
|
69
75
|
if Rails.env.production?
|
70
76
|
index({ confirmation_token: 1 },
|
71
77
|
{ unique: true, background: true })
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Faalis
|
2
|
+
# This concern contains all the permission related methods
|
3
|
+
# to use within `Faalis::User`
|
4
|
+
module Concerns::User::Permission
|
5
|
+
extend ActiveSupport::Concern
|
6
|
+
|
7
|
+
def have_permission? action, obj
|
8
|
+
perm = self.groups.includes(:permissions)
|
9
|
+
.where(faalis_permissions: { model: obj, permission_type: action })
|
10
|
+
.count
|
11
|
+
perm == 1
|
12
|
+
end
|
13
|
+
|
14
|
+
def can_not? action, obj
|
15
|
+
!have_permission? action, obj
|
16
|
+
end
|
17
|
+
|
18
|
+
alias_method :can?, :have_permission?
|
19
|
+
|
20
|
+
def permissions
|
21
|
+
groups.includes(:permissions).map(&:permissions).flatten.uniq
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|