mno-enterprise-api 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (208) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +1 -0
  3. data/Rakefile +12 -0
  4. data/app/assets/javascripts/mno_enterprise/angular/loading-page.app.js.coffee +156 -0
  5. data/app/assets/javascripts/mno_enterprise/application.js +13 -0
  6. data/app/controllers/devise/password_expired_controller.rb +55 -0
  7. data/app/controllers/mno_enterprise/auth/confirmations_controller.rb +5 -0
  8. data/app/controllers/mno_enterprise/auth/omniauth_callbacks_controller.rb +30 -0
  9. data/app/controllers/mno_enterprise/auth/passwords_controller.rb +5 -0
  10. data/app/controllers/mno_enterprise/auth/registrations_controller.rb +5 -0
  11. data/app/controllers/mno_enterprise/auth/sessions_controller.rb +7 -0
  12. data/app/controllers/mno_enterprise/auth/unlocks_controller.rb +5 -0
  13. data/app/controllers/mno_enterprise/deletion_requests_controller.rb +5 -0
  14. data/app/controllers/mno_enterprise/impersonate_controller.rb +48 -0
  15. data/app/controllers/mno_enterprise/jpi/v1/admin/audit_events_controller.rb +16 -0
  16. data/app/controllers/mno_enterprise/jpi/v1/admin/base_resource_controller.rb +5 -0
  17. data/app/controllers/mno_enterprise/jpi/v1/admin/cloud_apps_controller.rb +46 -0
  18. data/app/controllers/mno_enterprise/jpi/v1/admin/invoices_controller.rb +47 -0
  19. data/app/controllers/mno_enterprise/jpi/v1/admin/organizations_controller.rb +27 -0
  20. data/app/controllers/mno_enterprise/jpi/v1/admin/tenant_invoices_controller.rb +14 -0
  21. data/app/controllers/mno_enterprise/jpi/v1/admin/users_controller.rb +63 -0
  22. data/app/controllers/mno_enterprise/jpi/v1/app_instances_controller.rb +24 -0
  23. data/app/controllers/mno_enterprise/jpi/v1/app_instances_sync_controller.rb +36 -0
  24. data/app/controllers/mno_enterprise/jpi/v1/base_resource_controller.rb +32 -0
  25. data/app/controllers/mno_enterprise/jpi/v1/current_users_controller.rb +5 -0
  26. data/app/controllers/mno_enterprise/jpi/v1/deletion_requests_controller.rb +5 -0
  27. data/app/controllers/mno_enterprise/jpi/v1/impac/dashboards_controller.rb +5 -0
  28. data/app/controllers/mno_enterprise/jpi/v1/impac/kpis_controller.rb +80 -0
  29. data/app/controllers/mno_enterprise/jpi/v1/impac/widgets_controller.rb +63 -0
  30. data/app/controllers/mno_enterprise/jpi/v1/industry_bundle_controller.rb +25 -0
  31. data/app/controllers/mno_enterprise/jpi/v1/marketplace_controller.rb +22 -0
  32. data/app/controllers/mno_enterprise/jpi/v1/organizations_controller.rb +5 -0
  33. data/app/controllers/mno_enterprise/jpi/v1/shopping_cart_controller.rb +93 -0
  34. data/app/controllers/mno_enterprise/jpi/v1/teams_controller.rb +88 -0
  35. data/app/controllers/mno_enterprise/org_invites_controller.rb +5 -0
  36. data/app/controllers/mno_enterprise/pages_controller.rb +5 -0
  37. data/app/controllers/mno_enterprise/provision_controller.rb +5 -0
  38. data/app/controllers/mno_enterprise/status_controller.rb +27 -0
  39. data/app/controllers/mno_enterprise/webhook/o_auth_controller.rb +5 -0
  40. data/app/mailers/mno_enterprise/system_notification_mailer.rb +5 -0
  41. data/app/models/mno_enterprise/health_check.rb +16 -0
  42. data/app/views/devise/password_expired/show.html.haml +32 -0
  43. data/app/views/mno_enterprise/auth/confirmations/default/_form.html.haml +49 -0
  44. data/app/views/mno_enterprise/auth/confirmations/default/_lounge.html.haml +34 -0
  45. data/app/views/mno_enterprise/auth/confirmations/default/_show.html.haml +10 -0
  46. data/app/views/mno_enterprise/auth/confirmations/lounge.html.haml +4 -0
  47. data/app/views/mno_enterprise/auth/confirmations/material/_form.html.haml +44 -0
  48. data/app/views/mno_enterprise/auth/confirmations/material/_lounge.html.haml +18 -0
  49. data/app/views/mno_enterprise/auth/confirmations/material/_show.html.haml +21 -0
  50. data/app/views/mno_enterprise/auth/confirmations/new.html.haml +31 -0
  51. data/app/views/mno_enterprise/auth/confirmations/show.html.haml +4 -0
  52. data/app/views/mno_enterprise/auth/mailer/confirmation_instructions.html.haml +4 -0
  53. data/app/views/mno_enterprise/auth/mailer/reset_password_instructions.html.haml +6 -0
  54. data/app/views/mno_enterprise/auth/mailer/unlock_instructions.html.haml +5 -0
  55. data/app/views/mno_enterprise/auth/passwords/edit.html.haml +53 -0
  56. data/app/views/mno_enterprise/auth/passwords/new.html.haml +34 -0
  57. data/app/views/mno_enterprise/auth/registrations/default/_form.html.haml +35 -0
  58. data/app/views/mno_enterprise/auth/registrations/default/_new.html.haml +11 -0
  59. data/app/views/mno_enterprise/auth/registrations/material/_form.html.haml +30 -0
  60. data/app/views/mno_enterprise/auth/registrations/material/_new.html.haml +10 -0
  61. data/app/views/mno_enterprise/auth/registrations/new.html.haml +4 -0
  62. data/app/views/mno_enterprise/auth/sessions/default/_form.html.haml +17 -0
  63. data/app/views/mno_enterprise/auth/sessions/default/_new.html.haml +11 -0
  64. data/app/views/mno_enterprise/auth/sessions/material/_form.html.haml +26 -0
  65. data/app/views/mno_enterprise/auth/sessions/material/_new.html.haml +11 -0
  66. data/app/views/mno_enterprise/auth/sessions/new.html.haml +4 -0
  67. data/app/views/mno_enterprise/auth/shared/_links.html.haml +24 -0
  68. data/app/views/mno_enterprise/auth/unlocks/new.html.haml +10 -0
  69. data/app/views/mno_enterprise/deletion_requests/show.html.haml +131 -0
  70. data/app/views/mno_enterprise/jpi/v1/admin/audit_events/_audit_event.json.jbuilder +5 -0
  71. data/app/views/mno_enterprise/jpi/v1/admin/audit_events/index.json.jbuilder +4 -0
  72. data/app/views/mno_enterprise/jpi/v1/admin/cloud_apps/_cloud_app.json.jbuilder +1 -0
  73. data/app/views/mno_enterprise/jpi/v1/admin/cloud_apps/index.json.jbuilder +1 -0
  74. data/app/views/mno_enterprise/jpi/v1/admin/cloud_apps/show.json.jbuilder +1 -0
  75. data/app/views/mno_enterprise/jpi/v1/admin/invoices/_invoice.json.jbuilder +2 -0
  76. data/app/views/mno_enterprise/jpi/v1/admin/invoices/index.json.jbuilder +1 -0
  77. data/app/views/mno_enterprise/jpi/v1/admin/invoices/show.json.jbuilder +2 -0
  78. data/app/views/mno_enterprise/jpi/v1/admin/organizations/_credit_card.json.jbuilder +7 -0
  79. data/app/views/mno_enterprise/jpi/v1/admin/organizations/_invoices.json.jbuilder +8 -0
  80. data/app/views/mno_enterprise/jpi/v1/admin/organizations/_member.json.jbuilder +14 -0
  81. data/app/views/mno_enterprise/jpi/v1/admin/organizations/_organization.json.jbuilder +1 -0
  82. data/app/views/mno_enterprise/jpi/v1/admin/organizations/in_arrears.json.jbuilder +8 -0
  83. data/app/views/mno_enterprise/jpi/v1/admin/organizations/index.json.jbuilder +7 -0
  84. data/app/views/mno_enterprise/jpi/v1/admin/organizations/show.json.jbuilder +11 -0
  85. data/app/views/mno_enterprise/jpi/v1/admin/tenant_invoices/_tenant_invoice.json.jbuilder +5 -0
  86. data/app/views/mno_enterprise/jpi/v1/admin/tenant_invoices/index.json.jbuilder +1 -0
  87. data/app/views/mno_enterprise/jpi/v1/admin/tenant_invoices/show.json.jbuilder +1 -0
  88. data/app/views/mno_enterprise/jpi/v1/admin/users/_user.json.jbuilder +1 -0
  89. data/app/views/mno_enterprise/jpi/v1/admin/users/index.json.jbuilder +2 -0
  90. data/app/views/mno_enterprise/jpi/v1/admin/users/show.json.jbuilder +9 -0
  91. data/app/views/mno_enterprise/jpi/v1/app_instances/_resource.json.jbuilder +23 -0
  92. data/app/views/mno_enterprise/jpi/v1/app_instances/index.json.jbuilder +9 -0
  93. data/app/views/mno_enterprise/jpi/v1/app_instances/show.json.jbuilder +3 -0
  94. data/app/views/mno_enterprise/jpi/v1/billing/index.json.jbuilder +0 -0
  95. data/app/views/mno_enterprise/jpi/v1/current_users/show.json.jbuilder +37 -0
  96. data/app/views/mno_enterprise/jpi/v1/impac/dashboards/_dashboard.json.jbuilder +9 -0
  97. data/app/views/mno_enterprise/jpi/v1/impac/dashboards/index.json.jbuilder +1 -0
  98. data/app/views/mno_enterprise/jpi/v1/impac/dashboards/show.json.jbuilder +1 -0
  99. data/app/views/mno_enterprise/jpi/v1/impac/kpis/_kpi.json.jbuilder +1 -0
  100. data/app/views/mno_enterprise/jpi/v1/impac/kpis/show.json.jbuilder +1 -0
  101. data/app/views/mno_enterprise/jpi/v1/impac/widgets/_widget.json.jbuilder +6 -0
  102. data/app/views/mno_enterprise/jpi/v1/impac/widgets/show.json.jbuilder +1 -0
  103. data/app/views/mno_enterprise/jpi/v1/marketplace/_app.json.jbuilder +14 -0
  104. data/app/views/mno_enterprise/jpi/v1/marketplace/index.json.jbuilder +3 -0
  105. data/app/views/mno_enterprise/jpi/v1/marketplace/show.json.jbuilder +3 -0
  106. data/app/views/mno_enterprise/jpi/v1/organizations/_arrears.json.jbuilder +11 -0
  107. data/app/views/mno_enterprise/jpi/v1/organizations/_billing.json.jbuilder +4 -0
  108. data/app/views/mno_enterprise/jpi/v1/organizations/_credit_card.json.jbuilder +7 -0
  109. data/app/views/mno_enterprise/jpi/v1/organizations/_current_user.json.jbuilder +5 -0
  110. data/app/views/mno_enterprise/jpi/v1/organizations/_invoices.json.jbuilder +8 -0
  111. data/app/views/mno_enterprise/jpi/v1/organizations/_member.json.jbuilder +13 -0
  112. data/app/views/mno_enterprise/jpi/v1/organizations/_organization.json.jbuilder +13 -0
  113. data/app/views/mno_enterprise/jpi/v1/organizations/credit_card.json.jbuilder +1 -0
  114. data/app/views/mno_enterprise/jpi/v1/organizations/index.json.jbuilder +1 -0
  115. data/app/views/mno_enterprise/jpi/v1/organizations/members.json.jbuilder +3 -0
  116. data/app/views/mno_enterprise/jpi/v1/organizations/show.json.jbuilder +15 -0
  117. data/app/views/mno_enterprise/jpi/v1/organizations/show_reduced.json.jbuilder +3 -0
  118. data/app/views/mno_enterprise/jpi/v1/shopping_cart/organizations.json.jbuilder +5 -0
  119. data/app/views/mno_enterprise/jpi/v1/shopping_cart/show.json.jbuilder +59 -0
  120. data/app/views/mno_enterprise/jpi/v1/shopping_cart/show_item.json.jbuilder +34 -0
  121. data/app/views/mno_enterprise/jpi/v1/teams/_team.json.jbuilder +20 -0
  122. data/app/views/mno_enterprise/jpi/v1/teams/index.json.jbuilder +1 -0
  123. data/app/views/mno_enterprise/jpi/v1/teams/show.json.jbuilder +3 -0
  124. data/app/views/mno_enterprise/pages/app_access_unauthorized.html.haml +19 -0
  125. data/app/views/mno_enterprise/pages/app_logout.html.haml +18 -0
  126. data/app/views/mno_enterprise/pages/billing_details_required.html.haml +19 -0
  127. data/app/views/mno_enterprise/pages/loading.html.erb +69 -0
  128. data/app/views/mno_enterprise/provision/_provision_apps.html.haml +42 -0
  129. data/app/views/mno_enterprise/provision/_select_organization.html.haml +17 -0
  130. data/app/views/mno_enterprise/provision/new.html.haml +4 -0
  131. data/app/views/mno_enterprise/webhook/o_auth/authorize.html.haml +26 -0
  132. data/app/views/mno_enterprise/webhook/o_auth/providers/myob.html.haml +29 -0
  133. data/app/views/mno_enterprise/webhook/o_auth/providers/xero.html.haml +34 -0
  134. data/config/initializers/devise.rb +273 -0
  135. data/config/initializers/devise_extension.rb +9 -0
  136. data/config/initializers/devise_log.rb +12 -0
  137. data/config/initializers/health_check.rb +35 -0
  138. data/config/initializers/main_app_version.rb +6 -0
  139. data/config/routes.rb +152 -0
  140. data/lib/mno-enterprise-api.rb +1 -0
  141. data/lib/mno_enterprise/api.rb +14 -0
  142. data/lib/mno_enterprise/api/engine.rb +9 -0
  143. data/lib/mno_enterprise/concerns/controllers/deletion_requests_controller.rb +108 -0
  144. data/lib/mno_enterprise/concerns/controllers/jpi/v1/admin/base_resource_controller.rb +34 -0
  145. data/lib/mno_enterprise/concerns/controllers/jpi/v1/current_users_controller.rb +58 -0
  146. data/lib/mno_enterprise/concerns/controllers/jpi/v1/deletion_requests_controller.rb +69 -0
  147. data/lib/mno_enterprise/concerns/controllers/jpi/v1/impac/dashboards_controller.rb +76 -0
  148. data/lib/mno_enterprise/concerns/controllers/jpi/v1/organizations_controller.rb +180 -0
  149. data/lib/mno_enterprise/concerns/controllers/org_invites_controller.rb +44 -0
  150. data/lib/mno_enterprise/concerns/controllers/pages_controller.rb +78 -0
  151. data/lib/mno_enterprise/concerns/controllers/provision_controller.rb +71 -0
  152. data/lib/mno_enterprise/concerns/controllers/webhook/o_auth_controller.rb +107 -0
  153. data/lib/mno_enterprise/concerns/mailers/system_notification_mailer.rb +158 -0
  154. data/lib/mno_enterprise/event_logger.rb +32 -0
  155. data/spec/controllers/mno_enterprise/auth/confirmation_controller_spec.rb +68 -0
  156. data/spec/controllers/mno_enterprise/deletion_requests_controller_spec.rb +141 -0
  157. data/spec/controllers/mno_enterprise/impersonate_controller_spec.rb +48 -0
  158. data/spec/controllers/mno_enterprise/jpi/v1/admin/audit_events_controller_spec.rb +51 -0
  159. data/spec/controllers/mno_enterprise/jpi/v1/admin/cloud_apps_controller_spec.rb +92 -0
  160. data/spec/controllers/mno_enterprise/jpi/v1/admin/invoices_controller_spec.rb +159 -0
  161. data/spec/controllers/mno_enterprise/jpi/v1/admin/organizations_controller_spec.rb +116 -0
  162. data/spec/controllers/mno_enterprise/jpi/v1/admin/tenant_invoices_controller_spec.rb +92 -0
  163. data/spec/controllers/mno_enterprise/jpi/v1/admin/users_controller_spec.rb +136 -0
  164. data/spec/controllers/mno_enterprise/jpi/v1/app_instances_controller_spec.rb +76 -0
  165. data/spec/controllers/mno_enterprise/jpi/v1/app_instances_sync_controller_spec.rb +94 -0
  166. data/spec/controllers/mno_enterprise/jpi/v1/current_users_controller_spec.rb +128 -0
  167. data/spec/controllers/mno_enterprise/jpi/v1/deletion_requests_controller_spec.rb +72 -0
  168. data/spec/controllers/mno_enterprise/jpi/v1/impac/kpis_controller_spec.rb +80 -0
  169. data/spec/controllers/mno_enterprise/jpi/v1/marketplace_controller_spec.rb +115 -0
  170. data/spec/controllers/mno_enterprise/jpi/v1/organizations_controller_spec.rb +516 -0
  171. data/spec/controllers/mno_enterprise/jpi/v1/team_controller_spec.rb +86 -0
  172. data/spec/controllers/mno_enterprise/org_invites_controller_spec.rb +29 -0
  173. data/spec/controllers/mno_enterprise/pages_controller_spec.rb +49 -0
  174. data/spec/controllers/mno_enterprise/provision_controller_spec.rb +94 -0
  175. data/spec/controllers/mno_enterprise/status_controller_spec.rb +34 -0
  176. data/spec/controllers/mno_enterprise/webhook/o_auth_controller_spec.rb +104 -0
  177. data/spec/lib/mno_enterprise/event_logger_spec.rb +28 -0
  178. data/spec/mailer/mno_enterprise/system_notification_mailer_spec.rb +132 -0
  179. data/spec/rails_helper.rb +94 -0
  180. data/spec/requests/devise/authentication_spec.rb +43 -0
  181. data/spec/requests/devise/registration_spec.rb +64 -0
  182. data/spec/routing/devise/confirmation_routing_spec.rb +20 -0
  183. data/spec/routing/devise/passwords_routing_spec.rb +24 -0
  184. data/spec/routing/devise/registrations_routing_spec.rb +16 -0
  185. data/spec/routing/devise/sessions_routing_spec.rb +20 -0
  186. data/spec/routing/mno_enterprise/deletion_requests_controller_routing_spec.rb +20 -0
  187. data/spec/routing/mno_enterprise/impersonate_controller_routing.spec.rb +15 -0
  188. data/spec/routing/mno_enterprise/jpi/v1/admin/audit_events_controller_routing_spec.rb +11 -0
  189. data/spec/routing/mno_enterprise/jpi/v1/admin/cloud_apps_controller_routing_spec.rb +24 -0
  190. data/spec/routing/mno_enterprise/jpi/v1/admin/invoices_controller_routing_spec.rb +37 -0
  191. data/spec/routing/mno_enterprise/jpi/v1/admin/organizations_controller_routing_spec.rb +20 -0
  192. data/spec/routing/mno_enterprise/jpi/v1/admin/tenant_invoices_controller_routing_spec.rb +16 -0
  193. data/spec/routing/mno_enterprise/jpi/v1/admin/users_controller_routing_spec.rb +24 -0
  194. data/spec/routing/mno_enterprise/jpi/v1/app_instances_controller_routing_spec.rb +12 -0
  195. data/spec/routing/mno_enterprise/jpi/v1/app_instances_sync_controller_routing_spec.rb +15 -0
  196. data/spec/routing/mno_enterprise/jpi/v1/current_users_controller_routing_spec.rb +28 -0
  197. data/spec/routing/mno_enterprise/jpi/v1/deletion_requests_controller_routing_spec.rb +24 -0
  198. data/spec/routing/mno_enterprise/jpi/v1/impac/kpis_controller_routing_spec.rb +22 -0
  199. data/spec/routing/mno_enterprise/jpi/v1/marketplace_controller_routing_spec.rb +16 -0
  200. data/spec/routing/mno_enterprise/jpi/v1/organizations_controller_routing_spec.rb +44 -0
  201. data/spec/routing/mno_enterprise/jpi/v1/teams_controller_routing_spec.rb +36 -0
  202. data/spec/routing/mno_enterprise/org_invites_controller_routing_spec.rb +12 -0
  203. data/spec/routing/mno_enterprise/pages_controller_routing_spec.rb +29 -0
  204. data/spec/routing/mno_enterprise/provision_controller_routing_spec.rb +15 -0
  205. data/spec/routing/mno_enterprise/status_controller_routing_spec.rb +19 -0
  206. data/spec/routing/mno_enterprise/webhook/o_auth_controller_routing_spec.rb +27 -0
  207. data/spec/spec_helper.rb +88 -0
  208. metadata +402 -0
@@ -0,0 +1,9 @@
1
+ require 'devise_extension'
2
+
3
+ Devise.setup do |config|
4
+ # ==> Security Extension
5
+ # Configure security extension for devise
6
+
7
+ # Should the password expire (e.g 3.months)
8
+ config.expire_password_after = false
9
+ end
@@ -0,0 +1,12 @@
1
+ Warden::Manager.after_authentication do |user, auth, opts|
2
+ MnoEnterprise::EventLogger.info('user_login', user.id, "User login", user.email, user) if user
3
+ end
4
+
5
+ Warden::Manager.before_logout do |user, auth, opts|
6
+ # Determine whether it's a sign out or timeout
7
+ if auth.env['PATH_INFO'] =~ %r{^/auth/users/sign_out.json$}
8
+ MnoEnterprise::EventLogger.info('user_logout', user.id, "User logout", user.email, user) if user
9
+ else
10
+ MnoEnterprise::EventLogger.info('user_timeout', user.id, "User session expired", user.email, user) if user
11
+ end
12
+ end
@@ -0,0 +1,35 @@
1
+ HealthCheck::Engine.routes_manually_defined = true
2
+
3
+ HealthCheck.setup do |config|
4
+
5
+ # Text output upon success
6
+ config.success = 'success'
7
+
8
+ # Timeout in seconds used when checking smtp server
9
+ config.smtp_timeout = 30.0
10
+
11
+ # http status code used when plain text error message is output
12
+ # Set to 200 if you want your want to distinguish between partial (text does not include success) and
13
+ # total failure of rails application (http status of 500 etc)
14
+
15
+ config.http_status_for_error_text = 500
16
+
17
+ # http status code used when an error object is output (json or xml)
18
+ # Set to 200 if you want your want to distinguish between partial (healthy property == false) and
19
+ # total failure of rails application (http status of 500 etc)
20
+
21
+ config.http_status_for_error_object = 500
22
+
23
+ # You can customize which checks happen on a standard health check
24
+ config.standard_checks = [ 'database', 'migrations', 'custom' ]
25
+
26
+ # You can set what tests are run with the 'full' or 'all' parameter
27
+ config.full_checks = ['database', 'migrations', 'cache', 'custom']
28
+
29
+ # Add one or more custom checks that return a blank string if ok, or an error message if there is an error
30
+ config.add_custom_check do
31
+ # any code that returns blank on success and non blank string upon failure
32
+ MnoEnterprise::HealthCheck.perform_mno_hub_check
33
+ end
34
+
35
+ end
@@ -0,0 +1,6 @@
1
+ # Set the application version from the VERSION file in the root folder
2
+ version_file = "#{Rails.root}/BUILD_NUMBER"
3
+ git_version = `git rev-parse --short HEAD`.chomp.presence rescue nil
4
+ build_number = File.new(version_file).read.chomp if File.exists?(version_file)
5
+
6
+ MnoEnterprise::APP_VERSION = [build_number, git_version].compact.join('-')
data/config/routes.rb ADDED
@@ -0,0 +1,152 @@
1
+ MnoEnterprise::Engine.routes.draw do
2
+ # Generic routes
3
+ get '/launch/:id', to: 'pages#launch', constraints: {id: /[\w\-\.:]+/}
4
+ get '/loading/:id', to: 'pages#loading', constraints: {id: /[\w\-\.]+/}
5
+ get '/app_access_unauthorized', to: 'pages#app_access_unauthorized'
6
+ get '/billing_details_required', to: 'pages#billing_details_required'
7
+ get '/app_logout', to: 'pages#app_logout'
8
+
9
+ # Health Status
10
+ get '/ping', to: 'status#ping'
11
+ get '/version', to: 'status#version'
12
+ get 'health_check(/:checks)(.:format)', to: '/health_check/health_check#index'
13
+
14
+ # App Provisioning
15
+ resources :provision, only: [:new, :create]
16
+
17
+ # Organization Invites
18
+ resources :org_invites, only: [:show]
19
+
20
+ resources :deletion_requests, only: [:show] do
21
+ member do
22
+ patch :freeze_account
23
+ patch :checkout
24
+ put :terminate_account
25
+ end
26
+ end
27
+
28
+
29
+ get "/impersonate/user/:user_id", to: "impersonate#create", as: :impersonate_user
30
+ delete "/impersonate/revert", to: "impersonate#destroy", as: :revert_impersonate_user
31
+
32
+
33
+ #============================================================
34
+ # Devise/User Configuration
35
+ #============================================================
36
+ # Main devise configuration
37
+ devise_for :users, {
38
+ class_name: "MnoEnterprise::User",
39
+ module: :devise,
40
+ path_prefix: 'auth',
41
+ controllers: {
42
+ confirmations: "mno_enterprise/auth/confirmations",
43
+ #omniauth_callbacks: "auth/omniauth_callbacks",
44
+ passwords: "mno_enterprise/auth/passwords",
45
+ registrations: "mno_enterprise/auth/registrations",
46
+ sessions: "mno_enterprise/auth/sessions",
47
+ unlocks: "mno_enterprise/auth/unlocks"
48
+ }
49
+ }
50
+
51
+ # Additional devise routes
52
+ # TODO: routing specs
53
+ devise_scope :user do
54
+ get "/auth/users/confirmation/lounge", to: "auth/confirmations#lounge", as: :user_confirmation_lounge
55
+ patch "/auth/users/confirmation/finalize", to: "auth/confirmations#finalize", as: :user_confirmation_finalize
56
+ patch "/auth/users/confirmation", to: "auth/confirmations#update"
57
+ end
58
+
59
+ #============================================================
60
+ # Webhooks
61
+ #============================================================
62
+ namespace :webhook do
63
+ # OAuth Management
64
+ resources :oauth, only: [], constraints: {id: /[\w\-\.:]+/}, controller: "o_auth" do
65
+ member do
66
+ get :authorize
67
+ get :callback
68
+ get :disconnect
69
+ get :sync
70
+ end
71
+ end
72
+ end
73
+
74
+ #============================================================
75
+ # JPI V1
76
+ #============================================================
77
+ namespace :jpi do
78
+ namespace :v1 do
79
+ resources :marketplace, only: [:index, :show]
80
+ resource :current_user, only: [:show, :update] do
81
+ put :update_password
82
+ #post :deletion_request, action: :create_deletion_request
83
+ #delete :deletion_request, action: :cancel_deletion_request
84
+ end
85
+
86
+ resources :organizations, only: [:index, :show, :create, :update, :destroy] do
87
+ member do
88
+ put :update_billing
89
+ put :invite_members
90
+ put :update_member
91
+ put :remove_member
92
+ end
93
+
94
+ # AppInstances
95
+ resources :app_instances, only: [:index, :destroy], shallow: true
96
+
97
+ # Teams
98
+ resources :teams, only: [:index, :show, :create, :update, :destroy], shallow: true do
99
+ member do
100
+ put :add_users
101
+ put :remove_users
102
+ end
103
+ end
104
+
105
+ resources :app_instances_sync, only: [:create, :index]
106
+ end
107
+
108
+ resources :deletion_requests, only: [:show, :create, :destroy] do
109
+ member do
110
+ put :resend
111
+ end
112
+ end
113
+
114
+ namespace :impac do
115
+ resources :dashboards, only: [:index, :show, :create, :update, :destroy] do
116
+ resources :widgets, shallow: true, only: [:create, :destroy, :update]
117
+ resources :kpis, shallow: true, only: [:create, :destroy, :update]
118
+ end
119
+ end
120
+
121
+
122
+ #============================================================
123
+ # Admin
124
+ #============================================================
125
+ namespace :admin, defaults: {format: 'json'} do
126
+ resources :audit_events, only: [:index]
127
+ resources :users, only: [:index, :show, :destroy, :update, :create]
128
+ resources :organizations, only: [:index, :show] do
129
+ collection do
130
+ get :in_arrears
131
+ end
132
+ end
133
+ resources :tenant_invoices, only: [:index, :show]
134
+ resources :invoices, only: [:index, :show] do
135
+ collection do
136
+ get :current_billing_amount
137
+ get :last_invoicing_amount
138
+ get :outstanding_amount
139
+ get :last_commission_amount
140
+ get :last_portfolio_amount
141
+ end
142
+ end
143
+ resources :cloud_apps, only: [:index, :update] do
144
+ member do
145
+ put :regenerate_api_key
146
+ put :refresh_metadata
147
+ end
148
+ end
149
+ end
150
+ end
151
+ end
152
+ end
@@ -0,0 +1 @@
1
+ require 'mno_enterprise/api'
@@ -0,0 +1,14 @@
1
+ require 'action_view' # To fix "uninitialized constant Haml::ActionView"
2
+ require 'jbuilder'
3
+ require 'haml'
4
+
5
+ require 'mno_enterprise/core'
6
+
7
+ module MaestranoEnterprise
8
+ module Api
9
+ require 'mno_enterprise/api/engine'
10
+ end
11
+ end
12
+
13
+ # Needs Rails::Engine to be loaded
14
+ require 'health_check'
@@ -0,0 +1,9 @@
1
+ module MnoEnterprise
2
+ module Api
3
+ class Engine < ::Rails::Engine
4
+ isolate_namespace MnoEnterprise
5
+ # To be able to load lib/mno_enterprise/concerns/...
6
+ config.autoload_paths += Dir["#{config.root}/lib/**/"]
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,108 @@
1
+ # TODO: extract the request check to filter or block?
2
+ module MnoEnterprise::Concerns::Controllers::DeletionRequestsController
3
+ extend ActiveSupport::Concern
4
+
5
+ #==================================================================
6
+ # Included methods
7
+ #==================================================================
8
+ # 'included do' causes the included code to be evaluated in the
9
+ # context where it is included rather than being executed in the module's context
10
+ included do
11
+ before_filter :authenticate_user!
12
+ before_filter :redirect_to_lounge_if_unconfirmed
13
+ before_filter :set_meta
14
+
15
+ def set_meta
16
+ @meta[:title] = "Account Termination"
17
+ @meta[:description] = "Account Termination"
18
+ end
19
+ end
20
+
21
+ #==================================================================
22
+ # Class methods
23
+ #==================================================================
24
+ module ClassMethods
25
+ # def some_class_method
26
+ # 'some text'
27
+ # end
28
+ end
29
+
30
+ #==================================================================
31
+ # Instance methods
32
+ #================================================================
33
+ # GET /deletion_requests/1
34
+ def show
35
+ # authorize! :manage_billing, current_user.organizations.find(@invoice.organization_id)
36
+ @deletion_request = current_user.deletion_request
37
+
38
+ respond_to do |format|
39
+ # Check that the user has a deletion_request in progress
40
+ # and that the token provided (params[:id]) matches the
41
+ # deletion_request token
42
+ if @deletion_request.present? && @deletion_request.token == params[:id]
43
+
44
+ # Contextual assignments
45
+ if ['account_frozen', 'account_checked_out'].include?(@deletion_request.status)
46
+ # @final_invoices = current_user.final_invoices
47
+ @final_invoices = []
48
+ end
49
+
50
+ format.html
51
+ format.json { render json: @deletion_request }
52
+ else
53
+ format.html { redirect_to main_app.root_path, alert: 'This deletion request is invalid or expired' }
54
+ format.json { head :bad_request }
55
+ end
56
+ end
57
+ end
58
+
59
+ # PATCH /deletion_requests/1/freeze_account
60
+ def freeze_account
61
+ @deletion_request = current_user.deletion_request
62
+
63
+ respond_to do |format|
64
+ # Check that the user has a deletion_request in progress
65
+ # and that the token provided (params[:id]) matches the
66
+ # deletion_request token
67
+ if @deletion_request.present? && @deletion_request.token == params[:id]
68
+ # Check that the deletion_request has the right status
69
+ if @deletion_request.status == 'pending'
70
+ @deletion_request.freeze_account!
71
+ format.html { redirect_to @deletion_request, notice: 'Your account has been frozen' }
72
+ else
73
+ format.html { redirect_to @deletion_request, alert: 'Invalid action' }
74
+ end
75
+ else
76
+ format.html { redirect_to main_app.root_path, alert: 'This deletion request is invalid or expired' }
77
+ format.json { head :bad_request }
78
+ end
79
+ end
80
+ end
81
+
82
+ # PATCH /deletion_requests/1/checkout
83
+ def checkout
84
+ @deletion_request = current_user.deletion_request
85
+
86
+ respond_to do |format|
87
+ # Check that the user has a deletion_request in progress
88
+ # and that the token provided (params[:id]) matches the
89
+ # deletion_request token
90
+ if @deletion_request.present? && @deletion_request.token == params[:id]
91
+ # Check that the deletion_request has the right status
92
+ if @deletion_request.status == 'account_frozen'
93
+ # TODO:
94
+ # Attempt to update the credit cards first
95
+ # Finally Perform the checkout
96
+ @deletion_request.status = 'account_checked_out'
97
+ @deletion_request.save
98
+ format.html { redirect_to @deletion_request, notice: 'Checkout has been performed successfully' }
99
+ else
100
+ format.html { redirect_to @deletion_request, alert: 'Invalid action' }
101
+ end
102
+ else
103
+ format.html { redirect_to main_app.root_path, alert: 'This deletion request is invalid or expired' }
104
+ end
105
+ end
106
+ end
107
+
108
+ end
@@ -0,0 +1,34 @@
1
+ module MnoEnterprise::Concerns::Controllers::Jpi::V1::Admin::BaseResourceController
2
+ extend ActiveSupport::Concern
3
+
4
+ #==================================================================
5
+ # Included methods
6
+ #==================================================================
7
+ # 'included do' causes the included code to be evaluated in the
8
+ # context where it is included rather than being executed in the module's context
9
+ included do
10
+ ADMIN_CACHE_DURATION = 12.hours
11
+
12
+ before_filter :check_authorization
13
+ end
14
+
15
+ protected
16
+
17
+ def timestamp
18
+ @timestamp ||= (params[:timestamp] || 0).to_i
19
+ end
20
+
21
+ def parent_organization
22
+ @parent_organization ||= current_user.organizations.to_a.find { |o| o.id.to_s == params[:organization_id].to_s }
23
+ end
24
+
25
+ # Check current user is logged in
26
+ # Check organization is valid if specified
27
+ def check_authorization
28
+ if current_user && current_user.admin_role.present?
29
+ return true
30
+ end
31
+ render nothing: true, status: :unauthorized
32
+ false
33
+ end
34
+ end
@@ -0,0 +1,58 @@
1
+ module MnoEnterprise::Concerns::Controllers::Jpi::V1::CurrentUsersController
2
+ extend ActiveSupport::Concern
3
+
4
+ #==================================================================
5
+ # Included methods
6
+ #==================================================================
7
+ # 'included do' causes the included code to be evaluated in the
8
+ # context where it is included rather than being executed in the module's context
9
+ included do
10
+ before_filter :authenticate_user!, only: [:update, :update_password]
11
+ respond_to :json
12
+ end
13
+
14
+
15
+ #==================================================================
16
+ # Instance methods
17
+ #==================================================================
18
+ # GET /mnoe/jpi/v1/current_user
19
+ def show
20
+ @user = current_user || MnoEnterprise::User.new
21
+ end
22
+
23
+ # PUT /mnoe/jpi/v1/current_user
24
+ def update
25
+ @user = current_user
26
+
27
+ @user.assign_attributes(user_params)
28
+ changes = @user.changes
29
+ if @user.update(user_params)
30
+ MnoEnterprise::EventLogger.info('user_update', current_user.id, "User update", changes, @user)
31
+ render :show
32
+ else
33
+ render json: @user.errors, status: :bad_request
34
+ end
35
+ end
36
+
37
+ # PUT /mnoe/jpi/v1/current_user/update_password
38
+ def update_password
39
+ @user = current_user
40
+
41
+ if @user.update(password_params.merge(current_password_required: true))
42
+ MnoEnterprise::EventLogger.info('user_update_password', current_user.id, "User password change", @user.email, @user)
43
+ sign_in @user, bypass: true
44
+ render :show
45
+ else
46
+ render json: @user.errors, status: :bad_request
47
+ end
48
+ end
49
+
50
+ private
51
+ def user_params
52
+ params.require(:user).permit(:name, :surname, :email, :company, :settings, :phone, :website, :phone_country_code, :current_password, :password, :password_confirmation)
53
+ end
54
+
55
+ def password_params
56
+ params.require(:user).permit(:current_password, :password, :password_confirmation)
57
+ end
58
+ end