usman 0.1.5 → 0.1.6dev2
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.
- checksums.yaml +4 -4
- data/README.md +48 -16
- data/app/controllers/usman/admin/base_controller.rb +22 -0
- data/app/controllers/usman/admin/dashboard_controller.rb +1 -1
- data/app/controllers/usman/admin/features_controller.rb +4 -1
- data/app/controllers/usman/admin/permissions_controller.rb +9 -15
- data/app/controllers/usman/admin/resource_controller.rb +3 -1
- data/app/controllers/usman/admin/roles_controller.rb +4 -2
- data/app/controllers/usman/admin/user_roles_controller.rb +142 -0
- data/app/controllers/usman/admin/users_controller.rb +5 -2
- data/app/controllers/usman/application_controller.rb +0 -4
- data/app/controllers/usman/sessions_controller.rb +5 -2
- data/app/helpers/usman/authentication_helper.rb +35 -25
- data/app/models/feature.rb +50 -46
- data/app/models/image/feature_image.rb +1 -1
- data/app/models/image/profile_picture.rb +1 -1
- data/app/models/permission.rb +3 -8
- data/app/models/role.rb +4 -7
- data/app/models/user.rb +81 -103
- data/app/models/usman/application_record.rb +3 -0
- data/app/services/usman/authentication_service.rb +4 -3
- data/app/uploaders/profile_picture_uploader.rb +2 -1
- data/app/views/layouts/kuppayam/_header.html.erb +1 -1
- data/app/views/layouts/kuppayam/_navbar.html.erb +1 -1
- data/app/views/layouts/kuppayam/_sidebar.html.erb +8 -7
- data/app/views/usman/admin/dashboard/index.html.erb +0 -1
- data/app/views/usman/admin/features/_form.html.erb +5 -2
- data/app/views/usman/admin/features/_index.html.erb +4 -1
- data/app/views/usman/admin/features/index.html.erb +20 -3
- data/app/views/usman/admin/permissions/_show.html.erb +2 -10
- data/app/views/usman/admin/permissions/index.html.erb +20 -3
- data/app/views/usman/admin/roles/_form.html.erb +1 -1
- data/app/views/usman/admin/roles/_index.html.erb +3 -3
- data/app/views/usman/admin/roles/_row.html.erb +2 -2
- data/app/views/usman/admin/roles/_show.html.erb +41 -7
- data/app/views/usman/admin/roles/index.html.erb +22 -3
- data/app/views/usman/admin/user_roles/_form.html.erb +24 -0
- data/app/views/usman/admin/user_roles/_index.html.erb +59 -0
- data/app/views/usman/admin/user_roles/_row.html.erb +34 -0
- data/app/views/usman/admin/users/_index.html.erb +22 -16
- data/app/views/usman/admin/users/_row.html.erb +4 -4
- data/app/views/usman/admin/users/_show.html.erb +1 -1
- data/app/views/usman/admin/users/index.html.erb +4 -2
- data/app/views/usman/sessions/_form.html.erb +19 -7
- data/app/views/usman/sessions/sign_in.html.erb +1 -1
- data/config/initializers/overide_kuppayam_controllers.rb +74 -0
- data/config/locales/kuppayam/authentication.en.yml +4 -1
- data/config/routes.rb +3 -1
- data/db/import_data/dummy/features.csv +7 -0
- data/db/import_data/dummy/permissions.csv +18 -1
- data/db/import_data/dummy/roles.csv +5 -0
- data/db/import_data/dummy/users.csv +7 -3
- data/db/import_data/features.csv +7 -0
- data/db/import_data/permissions.csv +1 -30
- data/db/import_data/roles.csv +5 -0
- data/db/migrate/20170000000100_create_users.rb +1 -1
- data/db/migrate/20170000000101_create_features.rb +1 -1
- data/db/migrate/20170000000102_create_roles.rb +1 -1
- data/db/migrate/20170728095744_create_otp_registrations.rb +17 -0
- data/lib/tasks/usman/all.rake +34 -10
- data/lib/{tasks/usman → temp}/features.rake +3 -6
- data/lib/{tasks/usman → temp}/permissions.rake +3 -5
- data/lib/temp/roles.rake +24 -0
- data/lib/{tasks/usman → temp}/users.rake +3 -5
- data/lib/usman/engine.rb +2 -3
- data/lib/usman/version.rb +1 -1
- metadata +27 -45
- data/app/views/usman/admin/features/_action_buttons.html.erb +0 -0
- data/app/views/usman/admin/features/temp/create.js.erb +0 -29
- data/app/views/usman/admin/features/temp/destroy.js.erb +0 -16
- data/app/views/usman/admin/features/temp/edit.js.erb +0 -7
- data/app/views/usman/admin/features/temp/index.js.erb +0 -8
- data/app/views/usman/admin/features/temp/new.js.erb +0 -7
- data/app/views/usman/admin/features/temp/row.js.erb +0 -10
- data/app/views/usman/admin/features/temp/show.js.erb +0 -8
- data/app/views/usman/admin/features/temp/update.js.erb +0 -16
- data/app/views/usman/admin/permissions/temp/create.js.erb +0 -29
- data/app/views/usman/admin/permissions/temp/destroy.js.erb +0 -22
- data/app/views/usman/admin/permissions/temp/edit.js.erb +0 -4
- data/app/views/usman/admin/permissions/temp/index.js.erb +0 -14
- data/app/views/usman/admin/permissions/temp/new.js.erb +0 -4
- data/app/views/usman/admin/permissions/temp/row.js.erb +0 -24
- data/app/views/usman/admin/permissions/temp/show.js.erb +0 -13
- data/app/views/usman/admin/permissions/temp/update.js.erb +0 -29
- data/db/import_data/dummy/images/users/guna.neweast.png +0 -0
- data/db/import_data/dummy/images/users/junaid.ramzan.jpg +0 -0
- data/db/import_data/dummy/images/users/kpvarma.png +0 -0
- data/db/import_data/dummy/images/users/stephen.price.png +0 -0
- data/db/import_data/dummy/images/users/vinodh.jpg +0 -0
- data/db/import_data/images/users/junaid.ramzan.jpg +0 -0
- data/db/import_data/images/users/kpvarma.png +0 -0
- data/db/import_data/images/users/vinodh.jpg +0 -0
- data/lib/usman/extras/import_error_handler.rb +0 -79
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 9ec7d0671d92ce351c4882f0bbe8857fdcb18ab2
|
|
4
|
+
data.tar.gz: 81c5d13af42fd0ae271e5c4a68ec6fe117164154
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 67cd7e26738632cc4a3fc1ca72f3cc4c512b2578ee1a988a950f331e746b3510b8a4dee7102bd4a60579f884339691df99edda6a8d5abb00fec7e0cac35a5345
|
|
7
|
+
data.tar.gz: da160eabaa5d3927601dc1b1cd546ff569b07ba47ae773cb1e66efec27c58c25f41a87248f5fd97ea9af82c069aa4245c623c26fdfba3d114c1874e2f9257248
|
data/README.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# Usman
|
|
2
|
-
Simple User & Feature Permission Management
|
|
3
2
|
|
|
4
|
-
|
|
3
|
+
Simple User & Feature Permission Management with APIs.
|
|
4
|
+
|
|
5
5
|
Usman is a mountable plugin and it requires another full pluggin named kuppayam to run. Kuppayam offers usman the UI skin with basic modules for running like Polymorphic Image and Document Models etc.
|
|
6
6
|
|
|
7
7
|
## Installation
|
|
@@ -21,23 +21,19 @@ Or install it yourself as:
|
|
|
21
21
|
$ gem install usman
|
|
22
22
|
```
|
|
23
23
|
|
|
24
|
-
#
|
|
24
|
+
# Usage
|
|
25
25
|
|
|
26
|
-
##
|
|
26
|
+
## Installing the kuppayam & usman migrations
|
|
27
27
|
|
|
28
|
-
|
|
29
|
-
Run the below command
|
|
28
|
+
Usman uses kuppayam skins and hence it requires the basic migrations from kuppayam to run
|
|
29
|
+
Run the below command to copy the migrations from the kuppayam engine.
|
|
30
30
|
|
|
31
31
|
```bash
|
|
32
32
|
$ bundle exec rake railties:install:migrations
|
|
33
33
|
```
|
|
34
34
|
|
|
35
|
-
This will copy migrations from kuppayam and usman engines
|
|
36
|
-
which will have migrations to create images, documents, users, features and permissions respectively.
|
|
37
|
-
|
|
38
|
-
## Create Dummy Data
|
|
35
|
+
This will copy migrations from kuppayam and usman engines which will have migrations to create images, documents, users, features and permissions respectively.
|
|
39
36
|
|
|
40
|
-
run rake task for loading dummy data for users and features to start with.
|
|
41
37
|
|
|
42
38
|
## Mount the engine
|
|
43
39
|
|
|
@@ -49,23 +45,59 @@ mount Usman::Engine => "/"
|
|
|
49
45
|
|
|
50
46
|
open browser and go to /sign_in url
|
|
51
47
|
|
|
48
|
+
## Railties order
|
|
49
|
+
|
|
50
|
+
Specify the railties order if required in main application.rb
|
|
51
|
+
|
|
52
|
+
``
|
|
53
|
+
config.autoload_paths << "app/services"
|
|
54
|
+
config.railties_order = [:main_app, Usman::Engine, Kuppayam::Engine, :all]
|
|
55
|
+
```
|
|
52
56
|
|
|
57
|
+
# Seeding Data
|
|
53
58
|
|
|
59
|
+
run rake task for loading dummy data for users and features to start with.
|
|
54
60
|
|
|
55
61
|
```bash
|
|
56
62
|
$ bundle exec rake usman:import:dummy:all verbose=false
|
|
57
63
|
```
|
|
58
64
|
|
|
65
|
+
["users", "features", "permissions", "roles"]
|
|
59
66
|
|
|
67
|
+
You could also do it individually but the above command will run in the following order - users, features, permissions, roles. This order is important as features need users to be imported first.
|
|
60
68
|
|
|
61
|
-
|
|
69
|
+
```bash
|
|
70
|
+
$ bundle exec rake usman:import:dummy:users verbose=false
|
|
71
|
+
$ bundle exec rake usman:import:dummy:features verbose=false
|
|
72
|
+
$ bundle exec rake usman:import:dummy:permissions verbose=false
|
|
73
|
+
$ bundle exec rake usman:import:dummy:roles verbose=false
|
|
74
|
+
```
|
|
62
75
|
|
|
63
|
-
|
|
76
|
+
# Import Data
|
|
64
77
|
|
|
78
|
+
You could override the seed files with your data.
|
|
79
|
+
just create db/import_data in your project folder and create the following files filled with your data in the required format (checkout the dummy csvs in usman db/import_data/dummy/features.csv) for the columns required
|
|
80
|
+
|
|
81
|
+
for e.g:
|
|
82
|
+
|
|
83
|
+
create users.csv in db/import_data/ foler and fill data in it and run
|
|
84
|
+
|
|
85
|
+
```bash
|
|
86
|
+
$ bundle exec rake usman:import:users verbose=false
|
|
65
87
|
```
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
88
|
+
|
|
89
|
+
## Testing the gem
|
|
90
|
+
|
|
91
|
+
cd spec/dummy
|
|
92
|
+
rails db:create db:migrate
|
|
93
|
+
|
|
94
|
+
rails s -p <port>
|
|
95
|
+
|
|
96
|
+
## Running rspec
|
|
97
|
+
rails db:create db:migrate RAILS_ENV
|
|
98
|
+
|
|
99
|
+
# run rspec from the rails root folder and not from dummy folder as spec helper has been linked to dummy.
|
|
100
|
+
rspec
|
|
69
101
|
|
|
70
102
|
|
|
71
103
|
## Contributing
|
|
@@ -5,6 +5,7 @@ module Usman
|
|
|
5
5
|
layout 'kuppayam/admin'
|
|
6
6
|
|
|
7
7
|
before_action :require_user
|
|
8
|
+
before_action :require_site_admin
|
|
8
9
|
|
|
9
10
|
private
|
|
10
11
|
|
|
@@ -12,6 +13,27 @@ module Usman
|
|
|
12
13
|
set_title("Usman Admin | User Management Module")
|
|
13
14
|
end
|
|
14
15
|
|
|
16
|
+
def require_site_admin
|
|
17
|
+
return true if @current_user && @current_user.super_admin?
|
|
18
|
+
unless @current_user && @current_user.has_role?("Site Admin")
|
|
19
|
+
respond_to do |format|
|
|
20
|
+
format.html {
|
|
21
|
+
#text = "#{I18n.t("authentication.permission_denied.heading")}: #{I18n.t("authentication.permission_denied.message")}"
|
|
22
|
+
#set_flash_message(text, :error, false) if defined?(flash) && flash
|
|
23
|
+
redirect_after_unsuccessful_authentication
|
|
24
|
+
}
|
|
25
|
+
format.js {
|
|
26
|
+
@params_hsh = {}
|
|
27
|
+
@params_hsh[:client_app] = params[:client_app] if params[:client_app]
|
|
28
|
+
@params_hsh[:redirect_back_url] = params[:redirect_back_url] if params[:redirect_back_url]
|
|
29
|
+
@params_hsh[:requested_url] = request.original_url if request.get?
|
|
30
|
+
|
|
31
|
+
render(:partial => 'usman/sessions/sign_in.js.erb', :handlers => [:erb], :formats => [:js])
|
|
32
|
+
}
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
|
|
15
37
|
def configure_filter_param_mapping
|
|
16
38
|
@filter_param_mapping = default_filter_param_mapping
|
|
17
39
|
@filter_param_mapping[:super_admin] = :sa
|
|
@@ -54,6 +54,8 @@ module Usman
|
|
|
54
54
|
|
|
55
55
|
def resource_controller_configuration
|
|
56
56
|
{
|
|
57
|
+
page_title: "Features",
|
|
58
|
+
js_view_path: "/kuppayam/workflows/parrot",
|
|
57
59
|
view_path: "/usman/admin/features"
|
|
58
60
|
}
|
|
59
61
|
end
|
|
@@ -61,9 +63,10 @@ module Usman
|
|
|
61
63
|
def breadcrumbs_configuration
|
|
62
64
|
{
|
|
63
65
|
heading: "Manage Features",
|
|
66
|
+
icon: "lincons-diamond",
|
|
64
67
|
description: "Listing all Features",
|
|
65
68
|
links: [{name: "Home", link: admin_dashboard_path, icon: 'fa-home'},
|
|
66
|
-
{name: "Manage Features", link:
|
|
69
|
+
{name: "Manage Features", link: admin_features_path, icon: 'fa-calendar', active: true}]
|
|
67
70
|
}
|
|
68
71
|
end
|
|
69
72
|
|
|
@@ -2,29 +2,20 @@ module Usman
|
|
|
2
2
|
module Admin
|
|
3
3
|
class PermissionsController < ResourceController
|
|
4
4
|
|
|
5
|
-
def index
|
|
6
|
-
@heading = "Manage Permissions"
|
|
7
|
-
@description = "Listing all permissions"
|
|
8
|
-
@links = [{name: "Dashboard", link: admin_dashboard_path, icon: 'fa-home'},
|
|
9
|
-
{name: "Manage Permissions", link: admin_permissions_path, icon: 'fa-user', active: true}]
|
|
10
|
-
super
|
|
11
|
-
end
|
|
12
|
-
|
|
13
5
|
def create
|
|
14
|
-
@permission = Permission.where(" user_id = ? AND feature_id = ? ", permitted_params[:user_id], permitted_params[:feature_id]).first || Permission.new
|
|
6
|
+
@permission = @r_object = Permission.where(" user_id = ? AND feature_id = ? ", permitted_params[:user_id], permitted_params[:feature_id]).first || Permission.new
|
|
15
7
|
@permission.assign_attributes(permitted_params)
|
|
16
|
-
save_resource
|
|
17
|
-
|
|
8
|
+
save_resource
|
|
18
9
|
get_collections
|
|
19
10
|
end
|
|
20
11
|
|
|
21
12
|
def update
|
|
22
|
-
@permission = Permission.find_by_id(params[:id])
|
|
13
|
+
@permission = @r_object = Permission.find_by_id(params[:id])
|
|
23
14
|
# The form will not submit can_create 0 if it is not selected
|
|
24
15
|
# hence making it false by default and letting it update by itself.
|
|
25
16
|
@permission.assign_attributes({"can_create": "0", "can_read": "0", "can_update": "0", "can_delete": "0"})
|
|
26
17
|
@permission.assign_attributes(permitted_params)
|
|
27
|
-
save_resource
|
|
18
|
+
save_resource
|
|
28
19
|
get_collections
|
|
29
20
|
end
|
|
30
21
|
|
|
@@ -36,7 +27,7 @@ module Usman
|
|
|
36
27
|
parse_filters
|
|
37
28
|
apply_filters
|
|
38
29
|
|
|
39
|
-
@permissions = @relation.includes(:user, :feature).page(@current_page).per(@per_page)
|
|
30
|
+
@permissions = @r_objects = @relation.includes(:user, :feature).page(@current_page).per(@per_page)
|
|
40
31
|
|
|
41
32
|
return true
|
|
42
33
|
end
|
|
@@ -65,13 +56,16 @@ module Usman
|
|
|
65
56
|
|
|
66
57
|
def resource_controller_configuration
|
|
67
58
|
{
|
|
68
|
-
|
|
59
|
+
page_title: "Permissions",
|
|
60
|
+
js_view_path: "/kuppayam/workflows/parrot",
|
|
61
|
+
view_path: "/usman/admin/permissions"
|
|
69
62
|
}
|
|
70
63
|
end
|
|
71
64
|
|
|
72
65
|
def breadcrumbs_configuration
|
|
73
66
|
{
|
|
74
67
|
heading: "Manage Permissions",
|
|
68
|
+
icon: "fa-lock",
|
|
75
69
|
description: "Listing all Permissions",
|
|
76
70
|
links: [{name: "Home", link: admin_dashboard_path, icon: 'fa-home'},
|
|
77
71
|
{name: "Manage Permissions", link: admin_permissions_path, icon: 'fa-calendar', active: true}]
|
|
@@ -18,7 +18,7 @@ module Usman
|
|
|
18
18
|
def apply_filters
|
|
19
19
|
@relation = @relation.search(@query) if @query
|
|
20
20
|
|
|
21
|
-
@order_by = "
|
|
21
|
+
@order_by = "name ASC" unless @order_by
|
|
22
22
|
@relation = @relation.order(@order_by)
|
|
23
23
|
end
|
|
24
24
|
|
|
@@ -39,7 +39,8 @@ module Usman
|
|
|
39
39
|
|
|
40
40
|
def resource_controller_configuration
|
|
41
41
|
{
|
|
42
|
-
|
|
42
|
+
page_title: "Roles",
|
|
43
|
+
js_view_path: "/kuppayam/workflows/peacock",
|
|
43
44
|
view_path: "/usman/admin/roles"
|
|
44
45
|
}
|
|
45
46
|
end
|
|
@@ -47,6 +48,7 @@ module Usman
|
|
|
47
48
|
def breadcrumbs_configuration
|
|
48
49
|
{
|
|
49
50
|
heading: "Manage Roles",
|
|
51
|
+
icon: "fa-lock",
|
|
50
52
|
description: "Listing all Roles",
|
|
51
53
|
links: [{name: "Home", link: admin_dashboard_path, icon: 'fa-home'},
|
|
52
54
|
{name: "Manage Roles", link: admin_roles_path, icon: 'fa-calendar', active: true}]
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
module Usman
|
|
2
|
+
module Admin
|
|
3
|
+
class UserRolesController < ResourceController
|
|
4
|
+
|
|
5
|
+
before_action :get_role
|
|
6
|
+
|
|
7
|
+
def index
|
|
8
|
+
get_collections
|
|
9
|
+
respond_to do |format|
|
|
10
|
+
format.html {}
|
|
11
|
+
format.js {
|
|
12
|
+
js_view_path = @resource_options && @resource_options[:js_view_path] ? "#{@resource_options[:js_view_path]}/index" : :index
|
|
13
|
+
render js_view_path
|
|
14
|
+
}
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def show
|
|
19
|
+
@user = @r_object = @resource_options[:class].find_by_id(params[:id])
|
|
20
|
+
set_notification(false, I18n.t('status.error'), I18n.t('status.not_found', item: default_item_name.titleize)) unless @r_object
|
|
21
|
+
render_accordingly
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def new
|
|
25
|
+
@user = User.new
|
|
26
|
+
render_accordingly
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def create
|
|
30
|
+
@user = @r_object = User.find_by_id(permitted_params[:id])
|
|
31
|
+
if @user.add_role(@role)
|
|
32
|
+
set_notification(true, I18n.t('status.success'), "Role '#{@role.name}' has been assigned to the user '#{@user.name}'")
|
|
33
|
+
else
|
|
34
|
+
set_notification(false, I18n.t('status.success'), "Failed to assign the Role '#{@role.name}'")
|
|
35
|
+
end
|
|
36
|
+
action_name = params[:action].to_s == "create" ? "new" : "edit"
|
|
37
|
+
render_or_redirect(false, resource_url(@r_object), action_name)
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def destroy
|
|
41
|
+
@user = @r_object = User.find_by_id(params[:id])
|
|
42
|
+
if @user
|
|
43
|
+
if @user.remove_role(@role)
|
|
44
|
+
get_collections
|
|
45
|
+
set_flash_message(I18n.t('success.deleted'), :success)
|
|
46
|
+
set_notification(true, I18n.t('status.success'), "Role '#{@role.name}' has been removed for the user '#{@user.name}'")
|
|
47
|
+
@destroyed = true
|
|
48
|
+
else
|
|
49
|
+
message = I18n.t('errors.failed_to_delete', item: default_item_name.titleize)
|
|
50
|
+
set_flash_message(message, :failure)
|
|
51
|
+
set_notification(false, I18n.t('status.success'), "Failed to remove the Role '#{@role.name}'")
|
|
52
|
+
@destroyed = false
|
|
53
|
+
end
|
|
54
|
+
else
|
|
55
|
+
set_notification(false, I18n.t('status.error'), I18n.t('status.not_found', item: default_item_name.titleize))
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
respond_to do |format|
|
|
59
|
+
format.html {}
|
|
60
|
+
format.js {
|
|
61
|
+
js_view_path = @resource_options && @resource_options[:js_view_path] ? "#{@resource_options[:js_view_path]}/destroy" : :destroy
|
|
62
|
+
render js_view_path
|
|
63
|
+
}
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
private
|
|
69
|
+
|
|
70
|
+
def get_role
|
|
71
|
+
@role = Role.find_by_id(params[:role_id])
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
def get_collections
|
|
75
|
+
@relation = @role.users.where("")
|
|
76
|
+
|
|
77
|
+
parse_filters
|
|
78
|
+
apply_filters
|
|
79
|
+
|
|
80
|
+
@users = @r_objects = @relation.page(@current_page).per(@per_page)
|
|
81
|
+
|
|
82
|
+
return true
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
def apply_filters
|
|
86
|
+
@relation = @relation.search(@query) if @query
|
|
87
|
+
|
|
88
|
+
@order_by = "name ASC" unless @order_by
|
|
89
|
+
@relation = @relation.order(@order_by)
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
def configure_filter_settings
|
|
93
|
+
@filter_settings = {
|
|
94
|
+
string_filters: [
|
|
95
|
+
{ filter_name: :query }
|
|
96
|
+
],
|
|
97
|
+
boolean_filters: [],
|
|
98
|
+
reference_filters: [],
|
|
99
|
+
variable_filters: [],
|
|
100
|
+
}
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
def configure_filter_ui_settings
|
|
104
|
+
@filter_ui_settings = {}
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
def resource_url(obj)
|
|
108
|
+
url_for([:admin, @role, obj])
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
def resource_controller_configuration
|
|
112
|
+
{
|
|
113
|
+
collection_name: :users,
|
|
114
|
+
item_name: :user,
|
|
115
|
+
class: User,
|
|
116
|
+
show_modal_after_create: false,
|
|
117
|
+
show_modal_after_update: false,
|
|
118
|
+
page_title: "Manage User Roles",
|
|
119
|
+
js_view_path: "/kuppayam/workflows/parrot",
|
|
120
|
+
view_path: "/usman/admin/user_roles"
|
|
121
|
+
}
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
def breadcrumbs_configuration
|
|
125
|
+
{
|
|
126
|
+
heading: "Manage User Roles",
|
|
127
|
+
description: "Listing all User Roles",
|
|
128
|
+
links: [{name: "Home", link: admin_dashboard_path, icon: 'fa-home'}]
|
|
129
|
+
}
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
def permitted_params
|
|
133
|
+
params.require(:user).permit(:id)
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
def set_navs
|
|
137
|
+
set_nav("admin/roles/user_roles")
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
end
|
|
141
|
+
end
|
|
142
|
+
end
|
|
@@ -59,7 +59,7 @@ module Usman
|
|
|
59
59
|
|
|
60
60
|
# Normal users should not be able to view super admins
|
|
61
61
|
# He should not be seeing admins even while searching
|
|
62
|
-
if @current_user.
|
|
62
|
+
if @current_user.super_admin?
|
|
63
63
|
@relation = @relation.where("super_admin IS #{@super_admin.to_s.upcase}") if @super_admin.nil? == false && @query.nil?
|
|
64
64
|
else
|
|
65
65
|
@relation = @relation.where("super_admin IS FALSE")
|
|
@@ -104,13 +104,16 @@ module Usman
|
|
|
104
104
|
|
|
105
105
|
def resource_controller_configuration
|
|
106
106
|
{
|
|
107
|
-
|
|
107
|
+
page_title: "Users",
|
|
108
|
+
js_view_path: "/kuppayam/workflows/peacock",
|
|
109
|
+
view_path: "/usman/admin/users"
|
|
108
110
|
}
|
|
109
111
|
end
|
|
110
112
|
|
|
111
113
|
def breadcrumbs_configuration
|
|
112
114
|
{
|
|
113
115
|
heading: "Manage Users",
|
|
116
|
+
icon: "fa-user",
|
|
114
117
|
description: "Listing all Users",
|
|
115
118
|
links: [{name: "Home", link: admin_dashboard_path, icon: 'fa-home'},
|
|
116
119
|
{name: "Manage Users", link: admin_users_path, icon: 'fa-user', active: true}]
|
|
@@ -3,17 +3,20 @@ module Usman
|
|
|
3
3
|
|
|
4
4
|
layout 'kuppayam/blank'
|
|
5
5
|
|
|
6
|
+
rescue_from ActionController::InvalidAuthenticityToken, :with => :rescue_from_invalid_authenticity_token
|
|
7
|
+
|
|
6
8
|
before_action :require_user, :only => :sign_out
|
|
7
9
|
skip_before_action :set_navs
|
|
8
10
|
|
|
9
11
|
def sign_in
|
|
10
12
|
set_title("Sign In")
|
|
11
|
-
redirect_to_appropriate_page_after_sign_in if @current_user
|
|
13
|
+
redirect_to_appropriate_page_after_sign_in if @current_user
|
|
12
14
|
end
|
|
13
15
|
|
|
14
16
|
def create_session
|
|
15
17
|
set_title("Sign In")
|
|
16
|
-
|
|
18
|
+
registration_params = { login_handle: params[:login_handle], password: params[:password], remote_ip: request.remote_ip}
|
|
19
|
+
@registration_details = Usman::AuthenticationService.new(registration_params)
|
|
17
20
|
|
|
18
21
|
if @registration_details.error
|
|
19
22
|
|
|
@@ -10,7 +10,14 @@ module Usman
|
|
|
10
10
|
|
|
11
11
|
# Returns the default URL to which the system should redirect the user after successful authentication
|
|
12
12
|
def default_redirect_url_after_sign_in
|
|
13
|
-
|
|
13
|
+
main_app.user_landing_url
|
|
14
|
+
# if @current_user.has_role?("Admin")
|
|
15
|
+
# main_app.admin_dashboard_url
|
|
16
|
+
# elsif @current_user.has_role?("Admin")
|
|
17
|
+
# main_app.store_dashboard_url
|
|
18
|
+
# else
|
|
19
|
+
# main_app.admin_dashboard_url
|
|
20
|
+
# end
|
|
14
21
|
end
|
|
15
22
|
|
|
16
23
|
# Returns the default URL to which the system should redirect the user after an unsuccessful attempt to authorise a resource/page
|
|
@@ -22,11 +29,11 @@ module Usman
|
|
|
22
29
|
# This method should also handle the redirection if it has come through a client appliction for authentication
|
|
23
30
|
# In that case, it should persist the params passed by the client application
|
|
24
31
|
def redirect_after_unsuccessful_authentication
|
|
25
|
-
params_hsh = {}
|
|
26
|
-
params_hsh[:client_app] = params[:client_app] if params[:client_app]
|
|
27
|
-
params_hsh[:redirect_back_url] = params[:redirect_back_url] if params[:redirect_back_url]
|
|
28
|
-
params_hsh[:requested_url] = request.original_url if request.get?
|
|
29
|
-
redirect_to add_query_params(default_sign_in_url, params_hsh)
|
|
32
|
+
@params_hsh = {}
|
|
33
|
+
@params_hsh[:client_app] = params[:client_app] if params[:client_app]
|
|
34
|
+
@params_hsh[:redirect_back_url] = params[:redirect_back_url] if params[:redirect_back_url]
|
|
35
|
+
@params_hsh[:requested_url] = request.original_url if request.get?
|
|
36
|
+
redirect_to add_query_params(default_sign_in_url, @params_hsh)
|
|
30
37
|
return
|
|
31
38
|
end
|
|
32
39
|
|
|
@@ -43,12 +50,30 @@ module Usman
|
|
|
43
50
|
return
|
|
44
51
|
end
|
|
45
52
|
|
|
53
|
+
def rescue_from_invalid_authenticity_token
|
|
54
|
+
text = "#{I18n.t("authentication.session_expired.heading")}"
|
|
55
|
+
set_flash_message(text, :error, false) if defined?(flash) && flash
|
|
56
|
+
respond_to do |format|
|
|
57
|
+
format.html {
|
|
58
|
+
redirect_to add_query_params(default_sign_in_url)
|
|
59
|
+
}
|
|
60
|
+
format.js {
|
|
61
|
+
render(:partial => 'usman/sessions/sign_in.js.erb', :handlers => [:erb], :formats => [:js])
|
|
62
|
+
}
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
|
|
46
66
|
def redirect_or_popup_to_default_sign_in_page
|
|
47
67
|
respond_to do |format|
|
|
48
68
|
format.html {
|
|
49
69
|
redirect_after_unsuccessful_authentication
|
|
50
70
|
}
|
|
51
71
|
format.js {
|
|
72
|
+
@params_hsh = {}
|
|
73
|
+
@params_hsh[:client_app] = params[:client_app] if params[:client_app]
|
|
74
|
+
@params_hsh[:redirect_back_url] = params[:redirect_back_url] if params[:redirect_back_url]
|
|
75
|
+
@params_hsh[:requested_url] = request.original_url if request.get?
|
|
76
|
+
|
|
52
77
|
render(:partial => 'usman/sessions/sign_in.js.erb', :handlers => [:erb], :formats => [:js])
|
|
53
78
|
}
|
|
54
79
|
end
|
|
@@ -65,22 +90,8 @@ module Usman
|
|
|
65
90
|
# This method is usually used as a before filter to secure some of the actions which requires the user to be signed in.
|
|
66
91
|
def require_user
|
|
67
92
|
current_user
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
if @current_user.token_expired?
|
|
71
|
-
@current_user = nil
|
|
72
|
-
session.delete(:id)
|
|
73
|
-
|
|
74
|
-
text = "#{I18n.t("authentication.session_expired.heading")}: #{I18n.t("authentication.session_expired.message")}"
|
|
75
|
-
set_flash_message(text, :error, false) if defined?(flash) && flash
|
|
76
|
-
|
|
77
|
-
redirect_or_popup_to_default_sign_in_page
|
|
78
|
-
return
|
|
79
|
-
else
|
|
80
|
-
@current_user.update_token if @current_user.token_about_to_expire?
|
|
81
|
-
end
|
|
82
|
-
else
|
|
83
|
-
text = "#{I18n.t("authentication.permission_denied.heading")}: #{I18n.t("authentication.permission_denied.message")}"
|
|
93
|
+
unless @current_user
|
|
94
|
+
text = "#{I18n.t("authentication.login_required.heading")}"
|
|
84
95
|
set_flash_message(text, :error, false) if defined?(flash) && flash
|
|
85
96
|
|
|
86
97
|
redirect_or_popup_to_default_sign_in_page
|
|
@@ -90,7 +101,7 @@ module Usman
|
|
|
90
101
|
|
|
91
102
|
# This method is usually used as a before filter from admin controllers to ensure that the logged in user is a super admin
|
|
92
103
|
def require_super_admin
|
|
93
|
-
unless @current_user.
|
|
104
|
+
unless @current_user.super_admin?
|
|
94
105
|
text = "#{I18n.t("authentication.permission_denied.heading")}: #{I18n.t("authentication.permission_denied.message")}"
|
|
95
106
|
set_flash_message(text, :error, false) if defined?(flash) && flash
|
|
96
107
|
|
|
@@ -116,9 +127,8 @@ module Usman
|
|
|
116
127
|
message = translate("authentication.masquerade", user: user.name)
|
|
117
128
|
set_flash_message(message, :success, false)
|
|
118
129
|
session[:last_user_id] = current_user.id if current_user
|
|
119
|
-
user.start_session
|
|
130
|
+
user.start_session(params[:remote_ip])
|
|
120
131
|
session[:id] = user.id
|
|
121
|
-
default_redirect_url_after_sign_in
|
|
122
132
|
redirect_to default_redirect_url_after_sign_in
|
|
123
133
|
end
|
|
124
134
|
|