usman 0.1.0
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 +7 -0
- data/MIT-LICENSE +20 -0
- data/README.md +38 -0
- data/Rakefile +37 -0
- data/app/assets/config/usman_manifest.js +2 -0
- data/app/assets/javascripts/usman/application.js +13 -0
- data/app/assets/stylesheets/usman/application.css +15 -0
- data/app/controllers/usman/admin/base_controller.rb +24 -0
- data/app/controllers/usman/admin/dashboard_controller.rb +18 -0
- data/app/controllers/usman/admin/features_controller.rb +86 -0
- data/app/controllers/usman/admin/permissions_controller.rb +76 -0
- data/app/controllers/usman/admin/resource_controller.rb +11 -0
- data/app/controllers/usman/admin/users_controller.rb +117 -0
- data/app/controllers/usman/application_controller.rb +13 -0
- data/app/controllers/usman/sessions_controller.rb +84 -0
- data/app/helpers/usman/application_helper.rb +4 -0
- data/app/helpers/usman/authentication_helper.rb +120 -0
- data/app/jobs/usman/application_job.rb +4 -0
- data/app/mailers/usman/application_mailer.rb +6 -0
- data/app/models/feature.rb +112 -0
- data/app/models/image/base.rb +30 -0
- data/app/models/image/feature_image.rb +3 -0
- data/app/models/image/profile_picture.rb +3 -0
- data/app/models/permission.rb +28 -0
- data/app/models/user.rb +247 -0
- data/app/models/usman/application_record.rb +5 -0
- data/app/services/usman/authentication_service.rb +45 -0
- data/app/uploaders/feature_image_uploader.rb +14 -0
- data/app/uploaders/image_uploader.rb +90 -0
- data/app/uploaders/profile_picture_uploader.rb +14 -0
- data/app/views/layouts/kuppayam/_footer.html.erb +25 -0
- data/app/views/layouts/kuppayam/_header.html.erb +43 -0
- data/app/views/layouts/kuppayam/_navbar.html.erb +55 -0
- data/app/views/layouts/kuppayam/_sidebar.html.erb +78 -0
- data/app/views/usman/admin/dashboard/index.html.erb +52 -0
- data/app/views/usman/admin/features/_action_buttons.html.erb +11 -0
- data/app/views/usman/admin/features/_form.html.erb +19 -0
- data/app/views/usman/admin/features/_index.html.erb +79 -0
- data/app/views/usman/admin/features/_row.html.erb +55 -0
- data/app/views/usman/admin/features/_show.html.erb +48 -0
- data/app/views/usman/admin/features/create.js.erb +16 -0
- data/app/views/usman/admin/features/destroy.js.erb +16 -0
- data/app/views/usman/admin/features/edit.js.erb +7 -0
- data/app/views/usman/admin/features/index.html.erb +25 -0
- data/app/views/usman/admin/features/index.js.erb +8 -0
- data/app/views/usman/admin/features/new.js.erb +7 -0
- data/app/views/usman/admin/features/row.js.erb +10 -0
- data/app/views/usman/admin/features/show.js.erb +8 -0
- data/app/views/usman/admin/features/update.js.erb +16 -0
- data/app/views/usman/admin/permissions/_action_buttons.html.erb +11 -0
- data/app/views/usman/admin/permissions/_form.html.erb +70 -0
- data/app/views/usman/admin/permissions/_index.html.erb +56 -0
- data/app/views/usman/admin/permissions/_row.html.erb +27 -0
- data/app/views/usman/admin/permissions/_show.html.erb +48 -0
- data/app/views/usman/admin/permissions/create.js.erb +17 -0
- data/app/views/usman/admin/permissions/destroy.js.erb +16 -0
- data/app/views/usman/admin/permissions/edit.js.erb +7 -0
- data/app/views/usman/admin/permissions/index.html.erb +25 -0
- data/app/views/usman/admin/permissions/index.js.erb +8 -0
- data/app/views/usman/admin/permissions/new.js.erb +7 -0
- data/app/views/usman/admin/permissions/row.js.erb +10 -0
- data/app/views/usman/admin/permissions/show.js.erb +8 -0
- data/app/views/usman/admin/permissions/update.js.erb +16 -0
- data/app/views/usman/admin/users/_action_buttons.html.erb +11 -0
- data/app/views/usman/admin/users/_form.html.erb +36 -0
- data/app/views/usman/admin/users/_index.html.erb +120 -0
- data/app/views/usman/admin/users/_row.html.erb +92 -0
- data/app/views/usman/admin/users/_show.html.erb +132 -0
- data/app/views/usman/admin/users/create.js.erb +16 -0
- data/app/views/usman/admin/users/destroy.js.erb +16 -0
- data/app/views/usman/admin/users/edit.js.erb +7 -0
- data/app/views/usman/admin/users/index.html.erb +40 -0
- data/app/views/usman/admin/users/index.js.erb +8 -0
- data/app/views/usman/admin/users/new.js.erb +7 -0
- data/app/views/usman/admin/users/row.js.erb +10 -0
- data/app/views/usman/admin/users/show.js.erb +8 -0
- data/app/views/usman/admin/users/update.js.erb +16 -0
- data/app/views/usman/sessions/_form.html.erb +48 -0
- data/app/views/usman/sessions/_sign_in.js.erb +3 -0
- data/app/views/usman/sessions/sign_in.html.erb +63 -0
- data/config/locales/usman.en.yml +61 -0
- data/config/routes.rb +45 -0
- data/db/migrate/20131108102728_create_images.rb +12 -0
- data/db/migrate/20140402113213_create_users.rb +57 -0
- data/db/migrate/20140402113214_create_features.rb +24 -0
- data/lib/tasks/usman_tasks.rake +4 -0
- data/lib/usman/engine.rb +14 -0
- data/lib/usman/version.rb +3 -0
- data/lib/usman.rb +5 -0
- metadata +418 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: 7f31f9f21333b58b50c216a35e54eb18ad8d059f
|
|
4
|
+
data.tar.gz: 2b4a5159166004dd7d74b919642dab7f04f28e6a
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 0d684c162f0cf90dc506b1d22d7674683469a5b3aec60c47effaddb0c07719f30fecc88c1fdd1ef0152a2591a51aee20f5fe04fd873478344cbfe9ed270e6be9
|
|
7
|
+
data.tar.gz: c20a39d2ef4d2d689cdb1ce6097117cca6d38fe892e18e2ea4d6ab5a9e92160a732ce2e93c0c42b1f4cf3db7f95e62fff61338a69be2788d59de9ca10011b254
|
data/MIT-LICENSE
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
Copyright 2017 Prasad V
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
4
|
+
a copy of this software and associated documentation files (the
|
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
9
|
+
the following conditions:
|
|
10
|
+
|
|
11
|
+
The above copyright notice and this permission notice shall be
|
|
12
|
+
included in all copies or substantial portions of the Software.
|
|
13
|
+
|
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# Usman
|
|
2
|
+
Short description and motivation.
|
|
3
|
+
|
|
4
|
+
## Usage
|
|
5
|
+
How to use my plugin.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
Add this line to your application's Gemfile:
|
|
9
|
+
|
|
10
|
+
```ruby
|
|
11
|
+
gem 'usman'
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
And then execute:
|
|
15
|
+
```bash
|
|
16
|
+
$ bundle
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
Or install it yourself as:
|
|
20
|
+
```bash
|
|
21
|
+
$ gem install usman
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## Contributing
|
|
25
|
+
Contribution directions go here.
|
|
26
|
+
|
|
27
|
+
## License
|
|
28
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
|
29
|
+
|
|
30
|
+
# Installation Instructions
|
|
31
|
+
|
|
32
|
+
# in main application.rb
|
|
33
|
+
|
|
34
|
+
config.autoload_paths << "app/services"
|
|
35
|
+
config.railties_order = [:main_app, Usman::Engine, Kuppayam::Engine, :all]
|
|
36
|
+
|
|
37
|
+
# add config/initializers/uptime.rb
|
|
38
|
+
Dummy::BOOTED_AT = Time.now
|
data/Rakefile
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
begin
|
|
2
|
+
require 'bundler/setup'
|
|
3
|
+
rescue LoadError
|
|
4
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
require 'rdoc/task'
|
|
8
|
+
|
|
9
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
|
10
|
+
rdoc.rdoc_dir = 'rdoc'
|
|
11
|
+
rdoc.title = 'Usman'
|
|
12
|
+
rdoc.options << '--line-numbers'
|
|
13
|
+
rdoc.rdoc_files.include('README.md')
|
|
14
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__)
|
|
18
|
+
load 'rails/tasks/engine.rake'
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
load 'rails/tasks/statistics.rake'
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
require 'bundler/gem_tasks'
|
|
26
|
+
|
|
27
|
+
require 'rake/testtask'
|
|
28
|
+
|
|
29
|
+
Rake::TestTask.new(:test) do |t|
|
|
30
|
+
t.libs << 'lib'
|
|
31
|
+
t.libs << 'spec'
|
|
32
|
+
t.pattern = 'spec/**/*_test.rb'
|
|
33
|
+
t.verbose = false
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
task default: :test
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// This is a manifest file that'll be compiled into application.js, which will include all the files
|
|
2
|
+
// listed below.
|
|
3
|
+
//
|
|
4
|
+
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
|
|
5
|
+
// or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
|
|
6
|
+
//
|
|
7
|
+
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
|
|
8
|
+
// compiled file. JavaScript code in this file should be added after the last require_* statement.
|
|
9
|
+
//
|
|
10
|
+
// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
|
|
11
|
+
// about supported directives.
|
|
12
|
+
//
|
|
13
|
+
//= require_tree .
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* This is a manifest file that'll be compiled into application.css, which will include all the files
|
|
3
|
+
* listed below.
|
|
4
|
+
*
|
|
5
|
+
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
|
|
6
|
+
* or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
|
|
7
|
+
*
|
|
8
|
+
* You're free to add application-wide styles to this file and they'll appear at the bottom of the
|
|
9
|
+
* compiled file so the styles you add here take precedence over styles defined in any other CSS/SCSS
|
|
10
|
+
* files in this directory. Styles in this file should be added after the last require_* statement.
|
|
11
|
+
* It is generally better to create a new file per style scope.
|
|
12
|
+
*
|
|
13
|
+
*= require_tree .
|
|
14
|
+
*= require_self
|
|
15
|
+
*/
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
module Usman
|
|
2
|
+
module Admin
|
|
3
|
+
class BaseController < ApplicationController
|
|
4
|
+
|
|
5
|
+
layout 'kuppayam/admin'
|
|
6
|
+
|
|
7
|
+
before_action :require_user
|
|
8
|
+
|
|
9
|
+
private
|
|
10
|
+
|
|
11
|
+
def set_default_title
|
|
12
|
+
set_title("Usman Admin | User Management Module")
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def configure_filter_param_mapping
|
|
16
|
+
@filter_param_mapping = default_filter_param_mapping
|
|
17
|
+
@filter_param_mapping[:super_admin] = :sa
|
|
18
|
+
@filter_param_mapping[:user] = :us
|
|
19
|
+
@filter_param_mapping[:feature] = :ft
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
module Usman
|
|
2
|
+
module Admin
|
|
3
|
+
class FeaturesController < ResourceController
|
|
4
|
+
|
|
5
|
+
def index
|
|
6
|
+
@heading = "Manage Features"
|
|
7
|
+
@description = "Listing all features"
|
|
8
|
+
@links = [{name: "Dashboard", link: admin_dashboard_path, icon: 'fa-home'},
|
|
9
|
+
{name: "Manage Features", link: admin_features_path, icon: 'fa-user', active: true}]
|
|
10
|
+
super
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def create
|
|
14
|
+
@feature = Feature.new
|
|
15
|
+
@feature.assign_attributes(permitted_params)
|
|
16
|
+
save_resource(@feature)
|
|
17
|
+
get_collections
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def update_status
|
|
21
|
+
@feature = Feature.find(params[:id])
|
|
22
|
+
@feature.update_attribute(:status, params[:status])
|
|
23
|
+
render :row
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
private
|
|
27
|
+
|
|
28
|
+
def get_collections
|
|
29
|
+
@relation = Feature.where("")
|
|
30
|
+
|
|
31
|
+
parse_filters
|
|
32
|
+
apply_filters
|
|
33
|
+
|
|
34
|
+
@features = @relation.includes(:feature_image).page(@current_page).per(@per_page)
|
|
35
|
+
|
|
36
|
+
return true
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def apply_filters
|
|
40
|
+
@relation = @relation.search(@query) if @query
|
|
41
|
+
@relation = @relation.status(@status) if @status
|
|
42
|
+
|
|
43
|
+
@order_by = "created_at desc" unless @order_by
|
|
44
|
+
@relation = @relation.order(@order_by)
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def configure_filter_settings
|
|
48
|
+
@filter_settings = {
|
|
49
|
+
string_filters: [
|
|
50
|
+
{ filter_name: :query },
|
|
51
|
+
{ filter_name: :status }
|
|
52
|
+
],
|
|
53
|
+
boolean_filters: [],
|
|
54
|
+
reference_filters: [],
|
|
55
|
+
variable_filters: [],
|
|
56
|
+
}
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def configure_filter_ui_settings
|
|
60
|
+
@filter_ui_settings = {
|
|
61
|
+
status: {
|
|
62
|
+
object_filter: false,
|
|
63
|
+
select_label: "Select Status",
|
|
64
|
+
display_hash: Feature::STATUS,
|
|
65
|
+
current_value: @status,
|
|
66
|
+
values: Feature::STATUS_REVERSE,
|
|
67
|
+
current_filters: @filters,
|
|
68
|
+
filters_to_remove: [],
|
|
69
|
+
filters_to_add: {},
|
|
70
|
+
url_method_name: 'admin_users_url',
|
|
71
|
+
show_all_filter_on_top: true
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
def permitted_params
|
|
77
|
+
params.require(:feature).permit(:name)
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
def set_navs
|
|
81
|
+
set_nav("admin/features")
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
end
|
|
85
|
+
end
|
|
86
|
+
end
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
module Usman
|
|
2
|
+
module Admin
|
|
3
|
+
class PermissionsController < ResourceController
|
|
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
|
+
def create
|
|
14
|
+
@permission = Permission.where(" user_id = ? AND feature_id = ? ", permitted_params[:user_id], permitted_params[:feature_id]).first || Permission.new
|
|
15
|
+
@permission.assign_attributes(permitted_params)
|
|
16
|
+
save_resource(@permission)
|
|
17
|
+
|
|
18
|
+
get_collections
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def update
|
|
22
|
+
@permission = Permission.find_by_id(params[:id])
|
|
23
|
+
# The form will not submit can_create 0 if it is not selected
|
|
24
|
+
# hence making it false by default and letting it update by itself.
|
|
25
|
+
@permission.assign_attributes({"can_create": "0", "can_read": "0", "can_update": "0", "can_delete": "0"})
|
|
26
|
+
@permission.assign_attributes(permitted_params)
|
|
27
|
+
save_resource(@permission)
|
|
28
|
+
get_collections
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
private
|
|
32
|
+
|
|
33
|
+
def get_collections
|
|
34
|
+
@relation = Permission.where("")
|
|
35
|
+
|
|
36
|
+
parse_filters
|
|
37
|
+
apply_filters
|
|
38
|
+
|
|
39
|
+
@permissions = @relation.includes(:user, :feature).page(@current_page).per(@per_page)
|
|
40
|
+
|
|
41
|
+
return true
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def apply_filters
|
|
45
|
+
@relation = @relation.search(@query) if @query
|
|
46
|
+
@order_by = "user_id DESC, created_at DESC" unless @order_by
|
|
47
|
+
@relation = @relation.order(@order_by)
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def configure_filter_settings
|
|
51
|
+
@filter_settings = {
|
|
52
|
+
string_filters: [{ filter_name: :query }],
|
|
53
|
+
boolean_filters: [],
|
|
54
|
+
reference_filters: [
|
|
55
|
+
{ filter_name: :user, filter_class: User },
|
|
56
|
+
{ filter_name: :feature, filter_class: Feature },
|
|
57
|
+
],
|
|
58
|
+
variable_filters: [],
|
|
59
|
+
}
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def configure_filter_ui_settings
|
|
63
|
+
@filter_ui_settings = {}
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def permitted_params
|
|
67
|
+
params.require(:permission).permit(:user_id, :feature_id, :can_create, :can_read, :can_update, :can_delete)
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
def set_navs
|
|
71
|
+
set_nav("admin/permissions")
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
end
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
module Usman
|
|
2
|
+
module Admin
|
|
3
|
+
class UsersController < ResourceController
|
|
4
|
+
|
|
5
|
+
def index
|
|
6
|
+
@heading = "Manage Users"
|
|
7
|
+
@description = "Listing all users"
|
|
8
|
+
@links = [{name: "Dashboard", link: admin_dashboard_path, icon: 'fa-home'},
|
|
9
|
+
{name: "Manage Users", link: admin_users_path, icon: 'fa-user', active: true}]
|
|
10
|
+
super
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def create
|
|
14
|
+
@user = User.new
|
|
15
|
+
@user.assign_attributes(permitted_params)
|
|
16
|
+
#@user.assign_default_password
|
|
17
|
+
save_resource(@user)
|
|
18
|
+
get_collections
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def make_super_admin
|
|
22
|
+
@user = User.find(params[:id])
|
|
23
|
+
@user.update_attribute(:super_admin, true)
|
|
24
|
+
render :row
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def remove_super_admin
|
|
28
|
+
@user = User.find(params[:id])
|
|
29
|
+
@user.update_attribute(:super_admin, false)
|
|
30
|
+
render :row
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def update_status
|
|
34
|
+
@user = User.find(params[:id])
|
|
35
|
+
@user.update_attribute(:status, params[:status])
|
|
36
|
+
render :row
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def masquerade
|
|
40
|
+
@user = User.find(params[:id])
|
|
41
|
+
masquerade_as_user(@user)
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
private
|
|
45
|
+
|
|
46
|
+
def get_collections
|
|
47
|
+
# Fetching the users
|
|
48
|
+
@relation = User.where("")
|
|
49
|
+
|
|
50
|
+
parse_filters
|
|
51
|
+
apply_filters
|
|
52
|
+
|
|
53
|
+
@users = @relation.includes(:profile_picture).page(@current_page).per(@per_page)
|
|
54
|
+
|
|
55
|
+
return true
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def apply_filters
|
|
59
|
+
@relation = @relation.search(@query) if @query
|
|
60
|
+
@relation = @relation.status(@status) if @status
|
|
61
|
+
|
|
62
|
+
# Normal users should not be able to view super admins
|
|
63
|
+
# He should not be seeing admins even while searching
|
|
64
|
+
if @current_user.is_super_admin?
|
|
65
|
+
@relation = @relation.where("super_admin IS #{@super_admin.to_s.upcase}") if @super_admin.nil? == false && @query.nil?
|
|
66
|
+
else
|
|
67
|
+
@relation = @relation.where("super_admin IS FALSE")
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
@order_by = "created_at desc" unless @order_by
|
|
71
|
+
@relation = @relation.order(@order_by)
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
def configure_filter_settings
|
|
75
|
+
@filter_settings = {
|
|
76
|
+
string_filters: [
|
|
77
|
+
{ filter_name: :query },
|
|
78
|
+
{ filter_name: :status }
|
|
79
|
+
],
|
|
80
|
+
|
|
81
|
+
boolean_filters: [
|
|
82
|
+
{ filter_name: :super_admin, options: {default: false }}
|
|
83
|
+
],
|
|
84
|
+
|
|
85
|
+
reference_filters: [],
|
|
86
|
+
variable_filters: [],
|
|
87
|
+
}
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
def configure_filter_ui_settings
|
|
91
|
+
@filter_ui_settings = {
|
|
92
|
+
status: {
|
|
93
|
+
object_filter: false,
|
|
94
|
+
select_label: "Select Status",
|
|
95
|
+
display_hash: User::STATUS,
|
|
96
|
+
current_value: @status,
|
|
97
|
+
values: User::STATUS_REVERSE,
|
|
98
|
+
current_filters: @filters,
|
|
99
|
+
filters_to_remove: [],
|
|
100
|
+
filters_to_add: {},
|
|
101
|
+
url_method_name: 'admin_users_url',
|
|
102
|
+
show_all_filter_on_top: true
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
def permitted_params
|
|
108
|
+
params.require(:user).permit(:name, :username, :email, :designation, :phone, :password, :password_confirmation)
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
def set_navs
|
|
112
|
+
set_nav("admin/users")
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
end
|
|
116
|
+
end
|
|
117
|
+
end
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
module Usman
|
|
2
|
+
class SessionsController < Usman::ApplicationController
|
|
3
|
+
|
|
4
|
+
layout 'kuppayam/blank'
|
|
5
|
+
|
|
6
|
+
before_action :require_user, :only => :sign_out
|
|
7
|
+
skip_before_action :set_navs
|
|
8
|
+
|
|
9
|
+
def sign_in
|
|
10
|
+
redirect_to_appropriate_page_after_sign_in if @current_user && !@current_user.token_expired?
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def create_session
|
|
14
|
+
@registration_details = Usman::AuthenticationService.new(params)
|
|
15
|
+
if @registration_details.error
|
|
16
|
+
set_notification_messages(@registration_details.error, :error)
|
|
17
|
+
redirect_or_popup_to_default_sign_in_page
|
|
18
|
+
return
|
|
19
|
+
else
|
|
20
|
+
@user = @registration_details.user
|
|
21
|
+
session[:id] = @user.id
|
|
22
|
+
@current_user = @user
|
|
23
|
+
set_notification_messages("authentication.logged_in", :success)
|
|
24
|
+
redirect_to_appropriate_page_after_sign_in
|
|
25
|
+
return
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def sign_out
|
|
30
|
+
set_notification_messages("authentication.logged_out", :success)
|
|
31
|
+
@current_user.end_session
|
|
32
|
+
session.delete(:id)
|
|
33
|
+
restore_last_user
|
|
34
|
+
redirect_after_unsuccessful_authentication
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def forgot_password_form
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def forgot_password
|
|
41
|
+
@user = User.find_by_email(params[:email])
|
|
42
|
+
if @user.present?
|
|
43
|
+
@user.generate_reset_password_token
|
|
44
|
+
@user.save
|
|
45
|
+
UsersMailer.forgot_password(@user).deliver
|
|
46
|
+
else
|
|
47
|
+
end
|
|
48
|
+
flash[:notice] = "A password reset link will be send to your email if the records matches."
|
|
49
|
+
redirect_to root_path
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def reset_password_form
|
|
53
|
+
@user = User.find(params[:id])
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def reset_password_update
|
|
57
|
+
@user = User.find(params[:id])
|
|
58
|
+
if @user.reset_password_token == user_params[:reset_password_token] && @user.update(user_params)
|
|
59
|
+
@user.reset_password_token = nil
|
|
60
|
+
@user.save
|
|
61
|
+
flash[:success] = "Password updated successfully"
|
|
62
|
+
redirect_to root_path
|
|
63
|
+
else
|
|
64
|
+
flash[:error] = "Unable to update password please try again later"
|
|
65
|
+
render "reset_password_form"
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
private
|
|
70
|
+
|
|
71
|
+
def user_params
|
|
72
|
+
params[:user].permit(:password, :password_confirmation, :reset_password_token)
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
def stylesheet_filename
|
|
76
|
+
@stylesheet_filename = "kuppayam"
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
def javascript_filename
|
|
80
|
+
@javascript_filename = "kuppayam"
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
end
|
|
84
|
+
end
|