usman 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (100) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +51 -10
  3. data/app/controllers/usman/admin/dashboard_controller.rb +9 -1
  4. data/app/controllers/usman/admin/features_controller.rb +16 -22
  5. data/app/controllers/usman/admin/permissions_controller.rb +15 -0
  6. data/app/controllers/usman/admin/resource_controller.rb +4 -0
  7. data/app/controllers/usman/admin/roles_controller.rb +66 -0
  8. data/app/controllers/usman/admin/users_controller.rb +44 -31
  9. data/app/controllers/usman/sessions_controller.rb +14 -3
  10. data/app/helpers/usman/authentication_helper.rb +23 -17
  11. data/app/models/feature.rb +50 -4
  12. data/app/models/permission.rb +49 -1
  13. data/app/models/role.rb +62 -0
  14. data/app/models/user.rb +112 -3
  15. data/app/models/usman/application_record.rb +2 -2
  16. data/app/views/layouts/kuppayam/_sidebar.html.erb +8 -4
  17. data/app/views/usman/admin/dashboard/index.html.erb +1 -1
  18. data/app/views/usman/admin/features/_action_buttons.html.erb +0 -11
  19. data/app/views/usman/admin/features/_index.html.erb +3 -3
  20. data/app/views/usman/admin/features/_row.html.erb +3 -3
  21. data/app/views/usman/admin/features/_show.html.erb +5 -1
  22. data/app/views/usman/admin/features/index.html.erb +8 -1
  23. data/app/views/usman/admin/features/temp/create.js.erb +29 -0
  24. data/app/views/usman/admin/features/{index.js.erb → temp/index.js.erb} +1 -1
  25. data/app/views/usman/admin/permissions/_action_buttons.html.erb +0 -11
  26. data/app/views/usman/admin/permissions/index.html.erb +8 -1
  27. data/app/views/usman/admin/permissions/temp/create.js.erb +29 -0
  28. data/app/views/usman/admin/permissions/temp/destroy.js.erb +22 -0
  29. data/app/views/usman/admin/permissions/temp/edit.js.erb +4 -0
  30. data/app/views/usman/admin/permissions/{index.js.erb → temp/index.js.erb} +9 -3
  31. data/app/views/usman/admin/permissions/temp/new.js.erb +4 -0
  32. data/app/views/usman/admin/permissions/temp/row.js.erb +24 -0
  33. data/app/views/usman/admin/permissions/temp/show.js.erb +13 -0
  34. data/app/views/usman/admin/permissions/temp/update.js.erb +29 -0
  35. data/app/views/usman/admin/roles/_form.html.erb +23 -0
  36. data/app/views/usman/admin/roles/_index.html.erb +48 -0
  37. data/app/views/usman/admin/roles/_row.html.erb +24 -0
  38. data/app/views/usman/admin/roles/_show.html.erb +72 -0
  39. data/app/views/usman/admin/roles/index.html.erb +32 -0
  40. data/app/views/usman/admin/users/_form.html.erb +5 -2
  41. data/app/views/usman/admin/users/_index.html.erb +22 -41
  42. data/app/views/usman/admin/users/_row.html.erb +21 -41
  43. data/app/views/usman/admin/users/_show.html.erb +198 -131
  44. data/app/views/usman/admin/users/index.html.erb +25 -1
  45. data/app/views/usman/sessions/_sign_in.js.erb +2 -2
  46. data/config/locales/kuppayam/authentication.ar.yml +25 -0
  47. data/config/locales/kuppayam/authentication.en.yml +25 -0
  48. data/config/routes.rb +4 -9
  49. data/db/import_data/dummy/features.csv +10 -0
  50. data/db/import_data/dummy/images/users/guna.neweast.png +0 -0
  51. data/db/import_data/dummy/images/users/junaid.ramzan.jpg +0 -0
  52. data/db/import_data/dummy/images/users/kpvarma.png +0 -0
  53. data/db/import_data/dummy/images/users/stephen.price.png +0 -0
  54. data/db/import_data/dummy/images/users/vinodh.jpg +0 -0
  55. data/db/import_data/dummy/permissions.csv +60 -0
  56. data/db/import_data/dummy/users.csv +7 -0
  57. data/db/import_data/features.csv +10 -0
  58. data/db/import_data/images/users/junaid.ramzan.jpg +0 -0
  59. data/db/import_data/images/users/kpvarma.png +0 -0
  60. data/db/import_data/images/users/vinodh.jpg +0 -0
  61. data/db/import_data/permissions.csv +30 -0
  62. data/db/import_data/users.csv +4 -0
  63. data/db/migrate/20170000000102_create_roles.rb +18 -0
  64. data/lib/tasks/usman/all.rake +49 -0
  65. data/lib/tasks/usman/features.rake +26 -0
  66. data/lib/tasks/usman/permissions.rake +26 -0
  67. data/lib/tasks/usman/users.rake +26 -0
  68. data/lib/usman/engine.rb +12 -1
  69. data/lib/usman/extras/import_error_handler.rb +79 -0
  70. data/lib/usman/version.rb +1 -1
  71. metadata +65 -55
  72. data/app/models/image/base.rb +0 -30
  73. data/app/views/usman/admin/features/create.js.erb +0 -16
  74. data/app/views/usman/admin/permissions/create.js.erb +0 -17
  75. data/app/views/usman/admin/permissions/destroy.js.erb +0 -16
  76. data/app/views/usman/admin/permissions/edit.js.erb +0 -7
  77. data/app/views/usman/admin/permissions/new.js.erb +0 -7
  78. data/app/views/usman/admin/permissions/row.js.erb +0 -10
  79. data/app/views/usman/admin/permissions/show.js.erb +0 -8
  80. data/app/views/usman/admin/permissions/update.js.erb +0 -16
  81. data/app/views/usman/admin/users/_action_buttons.html.erb +0 -11
  82. data/app/views/usman/admin/users/create.js.erb +0 -16
  83. data/app/views/usman/admin/users/destroy.js.erb +0 -16
  84. data/app/views/usman/admin/users/edit.js.erb +0 -7
  85. data/app/views/usman/admin/users/index.js.erb +0 -8
  86. data/app/views/usman/admin/users/new.js.erb +0 -7
  87. data/app/views/usman/admin/users/row.js.erb +0 -10
  88. data/app/views/usman/admin/users/show.js.erb +0 -8
  89. data/app/views/usman/admin/users/update.js.erb +0 -16
  90. data/config/locales/usman.en.yml +0 -61
  91. data/db/migrate/20131108102728_create_images.rb +0 -12
  92. data/lib/tasks/usman_tasks.rake +0 -4
  93. /data/app/views/usman/admin/features/{destroy.js.erb → temp/destroy.js.erb} +0 -0
  94. /data/app/views/usman/admin/features/{edit.js.erb → temp/edit.js.erb} +0 -0
  95. /data/app/views/usman/admin/features/{new.js.erb → temp/new.js.erb} +0 -0
  96. /data/app/views/usman/admin/features/{row.js.erb → temp/row.js.erb} +0 -0
  97. /data/app/views/usman/admin/features/{show.js.erb → temp/show.js.erb} +0 -0
  98. /data/app/views/usman/admin/features/{update.js.erb → temp/update.js.erb} +0 -0
  99. /data/db/migrate/{20140402113213_create_users.rb → 20170000000100_create_users.rb} +0 -0
  100. /data/db/migrate/{20140402113214_create_features.rb → 20170000000101_create_features.rb} +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7f31f9f21333b58b50c216a35e54eb18ad8d059f
4
- data.tar.gz: 2b4a5159166004dd7d74b919642dab7f04f28e6a
3
+ metadata.gz: 186410d08ecdc9176c36357015749759ec165feb
4
+ data.tar.gz: 7bc5124cf79f1e4eef9bb961fd07506c37e0c75d
5
5
  SHA512:
6
- metadata.gz: 0d684c162f0cf90dc506b1d22d7674683469a5b3aec60c47effaddb0c07719f30fecc88c1fdd1ef0152a2591a51aee20f5fe04fd873478344cbfe9ed270e6be9
7
- data.tar.gz: c20a39d2ef4d2d689cdb1ce6097117cca6d38fe892e18e2ea4d6ab5a9e92160a732ce2e93c0c42b1f4cf3db7f95e62fff61338a69be2788d59de9ca10011b254
6
+ metadata.gz: d3f4714ec4f68625769e502cafe8b47b04e42fd301d41dd78eb07ebbc246ee38a9d254748d432b8cc1f45bf63d7e363c5d24f0ab9a78782a3f3762f5c4bb9822
7
+ data.tar.gz: c4e5181bc21ed383ca9ebdf0ab6b5fb57e190e0d7b7373313ec6b5f5dbb3c289956b85e76977656456f55bb6e3da1a7c8e1662dfaf817542e1cb63489a6e3e2c
data/README.md CHANGED
@@ -1,8 +1,8 @@
1
1
  # Usman
2
- Short description and motivation.
2
+ Simple User & Feature Permission Management
3
3
 
4
4
  ## Usage
5
- How to use my plugin.
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
8
8
  Add this line to your application's Gemfile:
@@ -21,18 +21,59 @@ Or install it yourself as:
21
21
  $ gem install usman
22
22
  ```
23
23
 
24
- ## Contributing
25
- Contribution directions go here.
24
+ # Installation Instructions
26
25
 
27
- ## License
28
- The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
26
+ ## Copy the migrations
27
+
28
+ Copy the migrations from the engines you are using
29
+ Run the below command
30
+
31
+ ```bash
32
+ $ bundle exec rake railties:install:migrations
33
+ ```
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
39
+
40
+ run rake task for loading dummy data for users and features to start with.
41
+
42
+ ## Mount the engine
43
+
44
+ Mount usman engine in your application routes.rb
45
+
46
+ ```
47
+ mount Usman::Engine => "/"
48
+ ```
49
+
50
+ open browser and go to /sign_in url
29
51
 
30
- # Installation Instructions
31
52
 
32
- # in main application.rb
33
53
 
54
+
55
+ ```bash
56
+ $ bundle exec rake usman:import:dummy:all verbose=false
57
+ ```
58
+
59
+
60
+
61
+ ## Specify the railties order if required
62
+
63
+ in main application.rb
64
+
65
+ ```
34
66
  config.autoload_paths << "app/services"
35
67
  config.railties_order = [:main_app, Usman::Engine, Kuppayam::Engine, :all]
68
+ ```
69
+
70
+
71
+ ## Contributing
72
+
73
+ Visit - https://github.com/right-solutions/usman
74
+ Feel free to submit a patch
75
+
76
+ ## License
77
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
78
+
36
79
 
37
- # add config/initializers/uptime.rb
38
- Dummy::BOOTED_AT = Time.now
@@ -2,12 +2,20 @@ module Usman
2
2
  module Admin
3
3
  class DashboardController < Usman::Admin::BaseController
4
4
 
5
- # GET /dashboard
5
+ # GET /dashboard
6
6
  def index
7
7
  end
8
8
 
9
9
  private
10
10
 
11
+ def breadcrumbs_configuration
12
+ {
13
+ heading: "Usman Dashboard",
14
+ description: "A Quick view of users and roles",
15
+ links: [{name: "Dashboard", link: admin_dashboard_path, icon: 'fa-dashboard'}]
16
+ }
17
+ end
18
+
11
19
  def set_navs
12
20
  set_nav("admin/dashboard")
13
21
  end
@@ -2,27 +2,6 @@ module Usman
2
2
  module Admin
3
3
  class FeaturesController < ResourceController
4
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
5
  private
27
6
 
28
7
  def get_collections
@@ -31,7 +10,7 @@ module Usman
31
10
  parse_filters
32
11
  apply_filters
33
12
 
34
- @features = @relation.includes(:feature_image).page(@current_page).per(@per_page)
13
+ @features = @r_objects = @relation.includes(:feature_image).page(@current_page).per(@per_page)
35
14
 
36
15
  return true
37
16
  end
@@ -73,6 +52,21 @@ module Usman
73
52
  }
74
53
  end
75
54
 
55
+ def resource_controller_configuration
56
+ {
57
+ view_path: "/usman/admin/features"
58
+ }
59
+ end
60
+
61
+ def breadcrumbs_configuration
62
+ {
63
+ heading: "Manage Features",
64
+ description: "Listing all Features",
65
+ links: [{name: "Home", link: admin_dashboard_path, icon: 'fa-home'},
66
+ {name: "Manage Features", link: admin_permissions_path, icon: 'fa-calendar', active: true}]
67
+ }
68
+ end
69
+
76
70
  def permitted_params
77
71
  params.require(:feature).permit(:name)
78
72
  end
@@ -63,6 +63,21 @@ module Usman
63
63
  @filter_ui_settings = {}
64
64
  end
65
65
 
66
+ def resource_controller_configuration
67
+ {
68
+ view_path: "/demo/permissions"
69
+ }
70
+ end
71
+
72
+ def breadcrumbs_configuration
73
+ {
74
+ heading: "Manage Permissions",
75
+ description: "Listing all Permissions",
76
+ links: [{name: "Home", link: admin_dashboard_path, icon: 'fa-home'},
77
+ {name: "Manage Permissions", link: admin_permissions_path, icon: 'fa-calendar', active: true}]
78
+ }
79
+ end
80
+
66
81
  def permitted_params
67
82
  params.require(:permission).permit(:user_id, :feature_id, :can_create, :can_read, :can_update, :can_delete)
68
83
  end
@@ -6,6 +6,10 @@ module Usman
6
6
 
7
7
  before_action :configure_resource_controller
8
8
 
9
+ def resource_url(obj)
10
+ url_for([:admin, obj])
11
+ end
12
+
9
13
  end
10
14
  end
11
15
  end
@@ -0,0 +1,66 @@
1
+ module Usman
2
+ module Admin
3
+ class RolesController < ResourceController
4
+
5
+ private
6
+
7
+ def get_collections
8
+ @relation = Role.where("")
9
+
10
+ parse_filters
11
+ apply_filters
12
+
13
+ @roles = @r_objects = @relation.page(@current_page).per(@per_page)
14
+
15
+ return true
16
+ end
17
+
18
+ def apply_filters
19
+ @relation = @relation.search(@query) if @query
20
+
21
+ @order_by = "created_at desc" unless @order_by
22
+ @relation = @relation.order(@order_by)
23
+ end
24
+
25
+ def configure_filter_settings
26
+ @filter_settings = {
27
+ string_filters: [
28
+ { filter_name: :query }
29
+ ],
30
+ boolean_filters: [],
31
+ reference_filters: [],
32
+ variable_filters: [],
33
+ }
34
+ end
35
+
36
+ def configure_filter_ui_settings
37
+ @filter_ui_settings = {}
38
+ end
39
+
40
+ def resource_controller_configuration
41
+ {
42
+ js_view_path: "/kuppayam/workflows/parrot",
43
+ view_path: "/usman/admin/roles"
44
+ }
45
+ end
46
+
47
+ def breadcrumbs_configuration
48
+ {
49
+ heading: "Manage Roles",
50
+ description: "Listing all Roles",
51
+ links: [{name: "Home", link: admin_dashboard_path, icon: 'fa-home'},
52
+ {name: "Manage Roles", link: admin_roles_path, icon: 'fa-calendar', active: true}]
53
+ }
54
+ end
55
+
56
+ def permitted_params
57
+ params.require(:role).permit(:name)
58
+ end
59
+
60
+ def set_navs
61
+ set_nav("admin/roles")
62
+ end
63
+
64
+ end
65
+ end
66
+ end
@@ -2,42 +2,40 @@ module Usman
2
2
  module Admin
3
3
  class UsersController < ResourceController
4
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
5
  def make_super_admin
22
- @user = User.find(params[:id])
23
- @user.update_attribute(:super_admin, true)
24
- render :row
6
+ @user = @r_object = User.find(params[:id])
7
+ if @user
8
+ @user.super_admin = true
9
+ if @user.valid?
10
+ @user.save
11
+ set_notification(true, I18n.t('status.success'), I18n.t('state.changed', item: default_item_name.titleize, new_state: @user.status))
12
+ else
13
+ set_notification(false, I18n.t('status.error'), I18n.translate("error"), @user.errors.full_messages.join("<br>"))
14
+ end
15
+ else
16
+ set_notification(false, I18n.t('status.not_found'), I18n.t('status.not_found', item: default_item_name.titleize))
17
+ end
18
+ render_row
25
19
  end
26
20
 
27
21
  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
22
+ @user = @r_object = User.find(params[:id])
23
+ if @user
24
+ @user.super_admin = false
25
+ if @user.valid?
26
+ @user.save
27
+ set_notification(true, I18n.t('status.success'), I18n.t('state.changed', item: default_item_name.titleize, new_state: @user.status))
28
+ else
29
+ set_notification(false, I18n.t('status.error'), I18n.translate("error"), @user.errors.full_messages.join("<br>"))
30
+ end
31
+ else
32
+ set_notification(false, I18n.t('status.not_found'), I18n.t('status.not_found', item: default_item_name.titleize))
33
+ end
34
+ render_row
37
35
  end
38
36
 
39
37
  def masquerade
40
- @user = User.find(params[:id])
38
+ @user = @r_object = User.find(params[:id])
41
39
  masquerade_as_user(@user)
42
40
  end
43
41
 
@@ -45,12 +43,12 @@ module Usman
45
43
 
46
44
  def get_collections
47
45
  # Fetching the users
48
- @relation = User.where("")
46
+ @relation = User.includes(:profile_picture).where("")
49
47
 
50
48
  parse_filters
51
49
  apply_filters
52
50
 
53
- @users = @relation.includes(:profile_picture).page(@current_page).per(@per_page)
51
+ @users = @r_objects = @relation.page(@current_page).per(@per_page)
54
52
 
55
53
  return true
56
54
  end
@@ -104,6 +102,21 @@ module Usman
104
102
  }
105
103
  end
106
104
 
105
+ def resource_controller_configuration
106
+ {
107
+ view_path: "usman/admin/users"
108
+ }
109
+ end
110
+
111
+ def breadcrumbs_configuration
112
+ {
113
+ heading: "Manage Users",
114
+ description: "Listing all Users",
115
+ links: [{name: "Home", link: admin_dashboard_path, icon: 'fa-home'},
116
+ {name: "Manage Users", link: admin_users_path, icon: 'fa-user', active: true}]
117
+ }
118
+ end
119
+
107
120
  def permitted_params
108
121
  params.require(:user).permit(:name, :username, :email, :designation, :phone, :password, :password_confirmation)
109
122
  end
@@ -7,27 +7,38 @@ module Usman
7
7
  skip_before_action :set_navs
8
8
 
9
9
  def sign_in
10
+ set_title("Sign In")
10
11
  redirect_to_appropriate_page_after_sign_in if @current_user && !@current_user.token_expired?
11
12
  end
12
13
 
13
14
  def create_session
15
+ set_title("Sign In")
14
16
  @registration_details = Usman::AuthenticationService.new(params)
17
+
15
18
  if @registration_details.error
16
- set_notification_messages(@registration_details.error, :error)
19
+
20
+ text = "#{I18n.t("#{@registration_details.error}.heading")}: #{I18n.t("#{@registration_details.error}.message")}"
21
+ set_flash_message(text, :error, false) if defined?(flash) && flash
22
+
17
23
  redirect_or_popup_to_default_sign_in_page
18
24
  return
19
25
  else
20
26
  @user = @registration_details.user
21
27
  session[:id] = @user.id
22
28
  @current_user = @user
23
- set_notification_messages("authentication.logged_in", :success)
29
+
30
+ text = "#{I18n.t("authentication.logged_in.heading")}: #{I18n.t("authentication.logged_in.message")}"
31
+ set_flash_message(text, :success, false) if defined?(flash) && flash
32
+
24
33
  redirect_to_appropriate_page_after_sign_in
25
34
  return
26
35
  end
27
36
  end
28
37
 
29
38
  def sign_out
30
- set_notification_messages("authentication.logged_out", :success)
39
+ text = "#{I18n.t("authentication.logged_out.heading")}: #{I18n.t("authentication.logged_out.message")}"
40
+ set_flash_message(text, :success, false) if defined?(flash) && flash
41
+
31
42
  @current_user.end_session
32
43
  session.delete(:id)
33
44
  restore_last_user
@@ -10,12 +10,12 @@ 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
- admin_dashboard_url
13
+ usman.admin_dashboard_url
14
14
  end
15
15
 
16
16
  # Returns the default URL to which the system should redirect the user after an unsuccessful attempt to authorise a resource/page
17
17
  def default_sign_in_url
18
- sign_in_url
18
+ usman.sign_in_url
19
19
  end
20
20
 
21
21
  # Method to handle the redirection after unsuccesful authentication
@@ -65,17 +65,24 @@ module Usman
65
65
  # This method is usually used as a before filter to secure some of the actions which requires the user to be signed in.
66
66
  def require_user
67
67
  current_user
68
+
68
69
  if @current_user
69
70
  if @current_user.token_expired?
70
- #binding.pry
71
71
  @current_user = nil
72
72
  session.delete(:id)
73
- set_notification_messages("authentication.session_expired", :error)
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
+
74
77
  redirect_or_popup_to_default_sign_in_page
75
78
  return
79
+ else
80
+ @current_user.update_token if @current_user.token_about_to_expire?
76
81
  end
77
82
  else
78
- set_notification_messages("authentication.permission_denied", :error)
83
+ text = "#{I18n.t("authentication.permission_denied.heading")}: #{I18n.t("authentication.permission_denied.message")}"
84
+ set_flash_message(text, :error, false) if defined?(flash) && flash
85
+
79
86
  redirect_or_popup_to_default_sign_in_page
80
87
  return
81
88
  end
@@ -84,7 +91,9 @@ module Usman
84
91
  # This method is usually used as a before filter from admin controllers to ensure that the logged in user is a super admin
85
92
  def require_super_admin
86
93
  unless @current_user.is_super_admin?
87
- set_notification_messages("authentication.permission_denied", :error)
94
+ text = "#{I18n.t("authentication.permission_denied.heading")}: #{I18n.t("authentication.permission_denied.message")}"
95
+ set_flash_message(text, :error, false) if defined?(flash) && flash
96
+
88
97
  redirect_or_popup_to_default_sign_in_page
89
98
  end
90
99
  end
@@ -95,7 +104,7 @@ module Usman
95
104
  return @last_user if @last_user
96
105
  if session[:last_user_id].present?
97
106
  @last_user = User.find_by_id(session[:last_user_id])
98
- message = translate("users.sign_in_back", user: @last_user.name)
107
+ message = translate("authentication.sign_in_back", user: @last_user.name)
99
108
  set_flash_message(message, :success, false)
100
109
  session.destroy()
101
110
  session[:id] = @last_user.id if @last_user.present?
@@ -104,16 +113,13 @@ module Usman
104
113
  end
105
114
 
106
115
  def masquerade_as_user(user)
107
- #if ["development", "it", "test"].include?(Rails.env)
108
- message = translate("users.masquerade", user: user.name)
109
- set_flash_message(message, :success, false)
110
- session[:last_user_id] = current_user.id if current_user
111
- user.start_session
112
- session[:id] = user.id
113
- default_redirect_url_after_sign_in
114
- url = admin_dashboard_url
115
- redirect_to url
116
- #end
116
+ message = translate("authentication.masquerade", user: user.name)
117
+ set_flash_message(message, :success, false)
118
+ session[:last_user_id] = current_user.id if current_user
119
+ user.start_session
120
+ session[:id] = user.id
121
+ default_redirect_url_after_sign_in
122
+ redirect_to default_redirect_url_after_sign_in
117
123
  end
118
124
 
119
125
  end
@@ -1,7 +1,8 @@
1
- class Feature < ApplicationRecord
1
+ class Feature < Usman::ApplicationRecord
2
+
3
+ require 'import_error_handler.rb'
4
+ extend Usman::ImportErrorHandler
2
5
 
3
- extend KuppayamValidators
4
-
5
6
  # Constants
6
7
  UNPUBLISHED = "unpublished"
7
8
  PUBLISHED = "published"
@@ -25,7 +26,7 @@ class Feature < ApplicationRecord
25
26
  has_one :feature_image, :as => :imageable, :dependent => :destroy, :class_name => "Image::FeatureImage"
26
27
 
27
28
  # Validations
28
- validate_string :name, mandatory: true
29
+ validates :name, presence: true
29
30
  validates :status, :presence => true, :inclusion => {:in => STATUS.keys, :presence_of => :status, :message => "%{value} is not a valid status" }
30
31
 
31
32
  # ------------------
@@ -46,6 +47,51 @@ class Feature < ApplicationRecord
46
47
  scope :published, -> { where(status: PUBLISHED) }
47
48
  scope :disabled, -> { where(status: DISABLED) }
48
49
 
50
+ def self.save_row_data(row, base_path)
51
+
52
+ image_base_path = base_path + "images/"
53
+
54
+ row.headers.each{ |cell| row[cell] = row[cell].to_s.strip }
55
+
56
+ return if row[:name].blank?
57
+
58
+ feature = Feature.find_by_name(row[:name]) || Feature.new
59
+ feature.name = row[:name]
60
+ feature.status = Feature::UNPUBLISHED
61
+
62
+ # Initializing error hash for displaying all errors altogether
63
+ error_object = Usman::ErrorHash.new
64
+
65
+ ## Adding a profile picture
66
+ begin
67
+ image_path = image_base_path + "features/#{feature.name.parameterize}.png"
68
+ image_path = image_base_path + "features/#{feature.name.parameterize}}.jpg" unless File.exists?(image_path)
69
+ if File.exists?(image_path)
70
+ feature.build_feature_image
71
+ feature.feature_image.image = File.open(image_path)
72
+ else
73
+ summary = "Feature Image not found for feature: #{feature.name}"
74
+ details = "#{image_path}/png doesn't exists"
75
+ error_object.warnings << { summary: summary, details: details }
76
+ end
77
+ rescue => e
78
+ summary = "Error during processing: #{$!}"
79
+ details = "Feature: #{feature.name}, Image Path: #{image_path}"
80
+ stack_trace = "Backtrace:\n\t#{e.backtrace.join("\n\t")}"
81
+ error_object.errors << { summary: summary, details: details, stack_trace: stack_trace }
82
+ end if feature.feature_image.blank?
83
+
84
+ if feature.valid? && (feature.feature_image.blank? || feature.feature_image.valid?)
85
+ feature.save!
86
+ else
87
+ summary = "Error while saving feature: #{feature.name}"
88
+ details = "Error! #{feature.errors.full_messages.to_sentence}"
89
+ details << ", #{feature.feature_image.errors.full_messages.to_sentence}" if feature.feature_image
90
+ error_object.errors << { summary: summary, details: details }
91
+ end
92
+ return error_object
93
+ end
94
+
49
95
  # * Return full name
50
96
  # == Examples
51
97
  # >>> feature.display_name
@@ -1,5 +1,8 @@
1
- class Permission < ApplicationRecord
1
+ class Permission < Usman::ApplicationRecord
2
2
 
3
+ require 'import_error_handler.rb'
4
+ extend Usman::ImportErrorHandler
5
+
3
6
  # Associations
4
7
  belongs_to :user
5
8
  belongs_to :feature
@@ -25,4 +28,49 @@ class Permission < ApplicationRecord
25
28
  LOWER(u.username) LIKE LOWER('%#{query}%') OR\
26
29
  LOWER(u.email) LIKE LOWER('%#{query}%') OR\
27
30
  LOWER(f.name) LIKE LOWER('%#{query}%')")}
31
+
32
+
33
+ def self.save_row_data(row, base_path)
34
+
35
+ image_base_path = base_path + "images/"
36
+
37
+ row.headers.each{ |cell| row[cell] = row[cell].to_s.strip }
38
+
39
+ return if row[:user].blank? || row[:feature].blank?
40
+
41
+ # Initializing error hash for displaying all errors altogether
42
+ error_object = Usman::ErrorHash.new
43
+
44
+ user = User.find_by_username(row[:user])
45
+ unless user
46
+ summary = "User '#{row[:user]}' doesn't exist"
47
+ error_object.errors << { summary: summary }
48
+ return error_object
49
+ end
50
+
51
+ feature = Feature.find_by_name(row[:feature])
52
+ unless feature
53
+ summary = "Feature '#{row[:feature]}' doesn't exist"
54
+ error_object.errors << { summary: summary }
55
+ return error_object
56
+ end
57
+
58
+ permission = Permission.where("user_id = ? AND feature_id = ?", user.id, feature.id).first || Permission.new
59
+ permission.user = user
60
+ permission.feature = feature
61
+ permission.can_create = row[:can_create]
62
+ permission.can_read = row[:can_read]
63
+ permission.can_update = row[:can_update]
64
+ permission.can_delete = row[:can_delete]
65
+
66
+ if permission.valid?
67
+ permission.save!
68
+ else
69
+ summary = "Error while saving permission: #{user.name} - #{feature.name}"
70
+ details = "Error! #{permission.errors.full_messages.to_sentence}"
71
+ error_object.errors << { summary: summary, details: details }
72
+ end
73
+ return error_object
74
+ end
75
+
28
76
  end