mno-enterprise-api 3.1.4 → 3.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (139) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/javascripts/mno_enterprise/config.js.coffee.erb +7 -1
  3. data/app/controllers/mno_enterprise/auth/omniauth_callbacks_controller.rb +3 -27
  4. data/app/controllers/mno_enterprise/auth/sessions_controller.rb +1 -3
  5. data/app/controllers/mno_enterprise/jpi/v1/admin/app_answers_controller.rb +26 -0
  6. data/app/controllers/mno_enterprise/jpi/v1/admin/app_comments_controller.rb +28 -0
  7. data/app/controllers/mno_enterprise/jpi/v1/admin/app_instances_controller.rb +16 -0
  8. data/app/controllers/mno_enterprise/jpi/v1/admin/app_reviews_controller.rb +30 -0
  9. data/app/controllers/mno_enterprise/jpi/v1/admin/invites_controller.rb +1 -1
  10. data/app/controllers/mno_enterprise/jpi/v1/admin/organizations_controller.rb +55 -37
  11. data/app/controllers/mno_enterprise/jpi/v1/app_answers_controller.rb +22 -0
  12. data/app/controllers/mno_enterprise/jpi/v1/app_comments_controller.rb +22 -0
  13. data/app/controllers/mno_enterprise/jpi/v1/app_feedbacks_controller.rb +14 -0
  14. data/app/controllers/mno_enterprise/jpi/v1/app_instances_controller.rb +1 -20
  15. data/app/controllers/mno_enterprise/jpi/v1/app_questions_controller.rb +25 -0
  16. data/app/controllers/mno_enterprise/jpi/v1/app_reviews_controller.rb +94 -0
  17. data/app/controllers/mno_enterprise/jpi/v1/base_resource_controller.rb +12 -0
  18. data/app/controllers/mno_enterprise/jpi/v1/impac/alerts_controller.rb +5 -0
  19. data/app/controllers/mno_enterprise/jpi/v1/impac/kpis_controller.rb +1 -76
  20. data/app/controllers/mno_enterprise/jpi/v1/marketplace_controller.rb +1 -18
  21. data/app/controllers/mno_enterprise/jpi/v1/teams_controller.rb +1 -83
  22. data/app/jobs/mno_enterprise/event_logger_job.rb +10 -0
  23. data/app/views/mno_enterprise/auth/confirmations/new.html.haml +6 -6
  24. data/app/views/mno_enterprise/auth/passwords/new.html.haml +8 -8
  25. data/app/views/mno_enterprise/auth/registrations/new.html.haml +1 -0
  26. data/app/views/mno_enterprise/auth/sessions/new.html.haml +1 -0
  27. data/app/views/mno_enterprise/auth/shared/_links.html.haml +0 -5
  28. data/app/views/mno_enterprise/auth/shared/_omniauth.html.haml +10 -0
  29. data/app/views/mno_enterprise/jpi/v1/admin/app_answers/show.json.jbuilder +15 -0
  30. data/app/views/mno_enterprise/jpi/v1/admin/app_comments/show.json.jbuilder +15 -0
  31. data/app/views/mno_enterprise/jpi/v1/admin/app_reviews/_app_review.json.jbuilder +13 -0
  32. data/app/views/mno_enterprise/jpi/v1/admin/app_reviews/index.json.jbuilder +1 -0
  33. data/app/views/mno_enterprise/jpi/v1/admin/app_reviews/show.json.jbuilder +3 -0
  34. data/app/views/mno_enterprise/jpi/v1/admin/organizations/show.json.jbuilder +1 -0
  35. data/app/views/mno_enterprise/jpi/v1/admin/users/_user.json.jbuilder +1 -1
  36. data/app/views/mno_enterprise/jpi/v1/app_answers/_resource.json.jbuilder +4 -0
  37. data/app/views/mno_enterprise/jpi/v1/app_answers/index.json.jbuilder +5 -0
  38. data/app/views/mno_enterprise/jpi/v1/app_answers/show.json.jbuilder +3 -0
  39. data/app/views/mno_enterprise/jpi/v1/app_comments/_resource.json.jbuilder +3 -0
  40. data/app/views/mno_enterprise/jpi/v1/app_comments/index.json.jbuilder +5 -0
  41. data/app/views/mno_enterprise/jpi/v1/app_comments/show.json.jbuilder +3 -0
  42. data/app/views/mno_enterprise/jpi/v1/app_feedbacks/_comment.json.jbuilder +10 -0
  43. data/app/views/mno_enterprise/jpi/v1/app_feedbacks/_resource.json.jbuilder +7 -0
  44. data/app/views/mno_enterprise/jpi/v1/app_feedbacks/index.json.jbuilder +5 -0
  45. data/app/views/mno_enterprise/jpi/v1/app_feedbacks/show.json.jbuilder +4 -0
  46. data/app/views/mno_enterprise/jpi/v1/app_instances/_resource.json.jbuilder +9 -0
  47. data/app/views/mno_enterprise/jpi/v1/app_questions/_answer.json.jbuilder +3 -0
  48. data/app/views/mno_enterprise/jpi/v1/app_questions/_resource.json.jbuilder +8 -0
  49. data/app/views/mno_enterprise/jpi/v1/app_questions/index.json.jbuilder +5 -0
  50. data/app/views/mno_enterprise/jpi/v1/app_questions/show.json.jbuilder +3 -0
  51. data/app/views/mno_enterprise/jpi/v1/app_reviews/_resource.json.jbuilder +13 -0
  52. data/app/views/mno_enterprise/jpi/v1/app_reviews/index.json.jbuilder +5 -0
  53. data/app/views/mno_enterprise/jpi/v1/app_reviews/show.json.jbuilder +4 -0
  54. data/app/views/mno_enterprise/jpi/v1/base_resource/_app_review.json.jbuilder +17 -0
  55. data/app/views/mno_enterprise/jpi/v1/current_users/show.json.jbuilder +9 -1
  56. data/app/views/mno_enterprise/jpi/v1/impac/alerts/_alert.json.jbuilder +7 -0
  57. data/app/views/mno_enterprise/jpi/v1/impac/alerts/index.json.jbuilder +1 -0
  58. data/app/views/mno_enterprise/jpi/v1/impac/alerts/show.json.jbuilder +1 -0
  59. data/app/views/mno_enterprise/jpi/v1/impac/dashboards/_dashboard.json.jbuilder +8 -3
  60. data/app/views/mno_enterprise/jpi/v1/impac/kpis/_kpi.json.jbuilder +4 -1
  61. data/app/views/mno_enterprise/jpi/v1/impac/widgets/_widget.json.jbuilder +1 -1
  62. data/app/views/mno_enterprise/jpi/v1/impac/widgets/index.json.jbuilder +3 -0
  63. data/app/views/mno_enterprise/jpi/v1/marketplace/_app.json.jbuilder +4 -0
  64. data/app/views/mno_enterprise/jpi/v1/marketplace/index.json.jbuilder +1 -2
  65. data/app/views/mno_enterprise/jpi/v1/marketplace/show.json.jbuilder +1 -1
  66. data/app/views/mno_enterprise/jpi/v1/organizations/_current_user.json.jbuilder +1 -1
  67. data/app/views/mno_enterprise/jpi/v1/organizations/_invoices.json.jbuilder +3 -2
  68. data/app/views/mno_enterprise/jpi/v1/organizations/_member.json.jbuilder +2 -2
  69. data/app/views/mno_enterprise/jpi/v1/organizations/_organization.json.jbuilder +2 -2
  70. data/app/views/mno_enterprise/jpi/v1/teams/_team.json.jbuilder +11 -5
  71. data/app/views/mno_enterprise/pages/terms.html.haml +219 -0
  72. data/app/views/mno_enterprise/provision/_select_organization.html.haml +6 -2
  73. data/config/initializers/devise.rb +31 -9
  74. data/config/initializers/devise_log.rb +4 -4
  75. data/config/routes.rb +41 -6
  76. data/lib/mno_enterprise/api.rb +1 -0
  77. data/lib/mno_enterprise/audit_events_listener.rb +28 -0
  78. data/lib/mno_enterprise/concerns/controllers/jpi/v1/app_instances_controller.rb +45 -0
  79. data/lib/mno_enterprise/concerns/controllers/jpi/v1/current_users_controller.rb +14 -4
  80. data/lib/mno_enterprise/concerns/controllers/jpi/v1/impac/alerts_controller.rb +76 -0
  81. data/lib/mno_enterprise/concerns/controllers/jpi/v1/impac/dashboards_controller.rb +49 -23
  82. data/lib/mno_enterprise/concerns/controllers/jpi/v1/impac/kpis_controller.rb +167 -0
  83. data/lib/mno_enterprise/concerns/controllers/jpi/v1/impac/widgets_controller.rb +33 -17
  84. data/lib/mno_enterprise/concerns/controllers/jpi/v1/marketplace_controller.rb +32 -0
  85. data/lib/mno_enterprise/concerns/controllers/jpi/v1/organizations_controller.rb +68 -28
  86. data/lib/mno_enterprise/concerns/controllers/jpi/v1/teams_controller.rb +92 -0
  87. data/lib/mno_enterprise/concerns/controllers/pages_controller.rb +17 -3
  88. data/lib/mno_enterprise/concerns/controllers/provision_controller.rb +17 -2
  89. data/lib/mno_enterprise/concerns/mailers/system_notification_mailer.rb +27 -3
  90. data/lib/mno_enterprise/event_logger.rb +34 -16
  91. data/lib/mno_enterprise/intercom_events_listener.rb +96 -0
  92. data/spec/controllers/mno_enterprise/auth/confirmation_controller_spec.rb +28 -0
  93. data/spec/controllers/mno_enterprise/auth/omniauth_callback_controller_spec.rb +34 -0
  94. data/spec/controllers/mno_enterprise/jpi/v1/admin/app_answers_controller_spec.rb +45 -0
  95. data/spec/controllers/mno_enterprise/jpi/v1/admin/app_comments_controller_spec.rb +45 -0
  96. data/spec/controllers/mno_enterprise/jpi/v1/admin/app_instances_controller_spec.rb +31 -0
  97. data/spec/controllers/mno_enterprise/jpi/v1/admin/app_reviews_controller_spec.rb +103 -0
  98. data/spec/controllers/mno_enterprise/jpi/v1/admin/audit_events_controller_spec.rb +4 -15
  99. data/spec/controllers/mno_enterprise/jpi/v1/admin/cloud_apps_controller_spec.rb +12 -3
  100. data/spec/controllers/mno_enterprise/jpi/v1/admin/invites_controller_spec.rb +4 -0
  101. data/spec/controllers/mno_enterprise/jpi/v1/admin/invoices_controller_spec.rb +15 -0
  102. data/spec/controllers/mno_enterprise/jpi/v1/admin/organizations_controller_spec.rb +17 -1
  103. data/spec/controllers/mno_enterprise/jpi/v1/admin/tenant_invoices_controller_spec.rb +5 -0
  104. data/spec/controllers/mno_enterprise/jpi/v1/admin/users_controller_spec.rb +30 -16
  105. data/spec/controllers/mno_enterprise/jpi/v1/app_answers_controller_spec.rb +74 -0
  106. data/spec/controllers/mno_enterprise/jpi/v1/app_comments_controller_spec.rb +74 -0
  107. data/spec/controllers/mno_enterprise/jpi/v1/app_feedbacks_controller_spec.rb +84 -0
  108. data/spec/controllers/mno_enterprise/jpi/v1/app_instances_controller_spec.rb +36 -22
  109. data/spec/controllers/mno_enterprise/jpi/v1/app_questions_controller_spec.rb +80 -0
  110. data/spec/controllers/mno_enterprise/jpi/v1/app_reviews_controller_spec.rb +107 -0
  111. data/spec/controllers/mno_enterprise/jpi/v1/current_users_controller_spec.rb +16 -1
  112. data/spec/controllers/mno_enterprise/jpi/v1/impac/alerts_controller_spec.rb +82 -0
  113. data/spec/controllers/mno_enterprise/jpi/v1/impac/kpis_controller_spec.rb +147 -10
  114. data/spec/controllers/mno_enterprise/jpi/v1/impac/widgets_controller_spec.rb +39 -0
  115. data/spec/controllers/mno_enterprise/jpi/v1/marketplace_controller_spec.rb +19 -26
  116. data/spec/controllers/mno_enterprise/jpi/v1/organizations_controller_spec.rb +248 -303
  117. data/spec/controllers/mno_enterprise/jpi/v1/team_controller_spec.rb +4 -1
  118. data/spec/controllers/mno_enterprise/pages_controller_spec.rb +21 -0
  119. data/spec/controllers/mno_enterprise/provision_controller_spec.rb +65 -22
  120. data/spec/controllers/mno_enterprise/webhook/o_auth_controller_spec.rb +1 -1
  121. data/spec/jobs/mno_enterprise/event_logger_job_spec.rb +11 -0
  122. data/spec/lib/mno_enterprise/audit_events_listener_spec.rb +28 -0
  123. data/spec/lib/mno_enterprise/intercom_events_listener_spec.rb +110 -0
  124. data/spec/mailer/mno_enterprise/system_notification_mailer_spec.rb +81 -46
  125. data/spec/routing/mno_enterprise/jpi/v1/admin/app_instances_controller_routing_spec.rb +11 -0
  126. data/spec/routing/mno_enterprise/jpi/v1/admin/app_reviews_controller_routing_spec.rb +19 -0
  127. data/spec/routing/mno_enterprise/jpi/v1/app_instances_controller_routing_spec.rb +9 -2
  128. data/spec/routing/mno_enterprise/jpi/v1/app_reviews_controller_routing_spec.rb +15 -0
  129. data/spec/routing/mno_enterprise/jpi/v1/current_users_controller_routing_spec.rb +5 -0
  130. data/spec/routing/mno_enterprise/jpi/v1/impac/alerts_controller_routing_spec.rb +24 -0
  131. data/spec/routing/mno_enterprise/jpi/v1/impac/dashboards_controller_routing_spec.rb +28 -0
  132. data/spec/routing/mno_enterprise/jpi/v1/impac/kpis_controller_routing_spec.rb +17 -11
  133. data/spec/routing/mno_enterprise/jpi/v1/impac/widgets_controller_routing_spec.rb +24 -0
  134. data/spec/routing/mno_enterprise/jpi/v1/marketplace_controller_routing_spec.rb +2 -2
  135. data/spec/routing/mno_enterprise/pages_controller_routing_spec.rb +4 -0
  136. metadata +178 -9
  137. data/app/controllers/mno_enterprise/jpi/v1/industry_bundle_controller.rb +0 -25
  138. data/app/controllers/mno_enterprise/jpi/v1/shopping_cart_controller.rb +0 -93
  139. data/spec/lib/mno_enterprise/event_logger_spec.rb +0 -28
@@ -1,5 +1,9 @@
1
- .banners.promo.dark.darkblue
1
+ .banners
2
+ .spacer1
2
3
  .container
4
+ .row
5
+ .col-md-6.text-center.col-md-offset-3
6
+ = image_tag 'mno_enterprise/main-logo.png', class: 'top-picture'
3
7
  .row
4
8
  %h2= t('mno_enterprise.provision.select_organization.title')
5
9
  .banners.promo
@@ -14,4 +18,4 @@
14
18
  = hidden_field_tag 'apps[]', app
15
19
  = select_tag :organization_id, options_for_select(@organizations.map { |o| [o.name, o.id]} )
16
20
  = submit_tag t('mno_enterprise.provision.select_organization.submit'), class: 'btn'
17
- .spacer4
21
+ .spacer4
@@ -19,7 +19,7 @@ Devise.setup do |config|
19
19
  # Load and configure the ORM. Supports :active_record (default) and
20
20
  # :mongoid (bson_ext recommended) by default. Other ORMs may be
21
21
  # available as additional gems.
22
- require 'devise/orm/active_record'
22
+ # require 'devise/orm/active_record'
23
23
 
24
24
  # ==> Configuration for any authentication mechanism
25
25
  # Configure which keys are used when authenticating a user. The default is
@@ -99,6 +99,9 @@ Devise.setup do |config|
99
99
  # Setup a pepper to generate the encrypted password.
100
100
  # config.pepper = '11ab398be280e434b1dc50197d359577c1bc52efd28a07d081e397c7c11dcf8d1ad80f40188d58421830c20351f5af8c1217b39397ca95ee33809c74b028972f'
101
101
 
102
+ # Send a notification email when the user's password is changed
103
+ config.send_password_change_notification = true
104
+
102
105
  # ==> Configuration for :confirmable
103
106
  # A period that the user is allowed to access the website even without
104
107
  # confirming their account. For instance, if set to 2.days, the user will be
@@ -233,7 +236,26 @@ Devise.setup do |config|
233
236
  # ==> OmniAuth
234
237
  # Add a new OmniAuth provider. Check the wiki for more information on setting
235
238
  # up on your models and hooks.
236
- # config.omniauth :github, 'APP_ID', 'APP_SECRET', scope: 'user,public_repo'
239
+ if defined?(OmniAuth::OpenID) && !Rails.env.test?
240
+ require 'openid-store-redis'
241
+ config.omniauth :open_id,
242
+ store: OpenID::Store::Redis.new,
243
+ name: 'intuit',
244
+ identifier: 'https://openid.intuit.com/openid/xrds',
245
+ require: 'omniauth-openid'
246
+ end
247
+ if ENV['OAUTH_LINKEDIN_KEY'] && ENV['OAUTH_LINKEDIN_SECRET']
248
+ require 'omniauth-linkedin-oauth2'
249
+ config.omniauth :linkedin, ENV['OAUTH_LINKEDIN_KEY'], ENV['OAUTH_LINKEDIN_SECRET']
250
+ end
251
+ if ENV['OAUTH_GOOGLE_KEY'] && ENV['OAUTH_GOOGLE_SECRET']
252
+ require 'omniauth-google-oauth2'
253
+ config.omniauth :google_oauth2, ENV['OAUTH_GOOGLE_KEY'], ENV['OAUTH_GOOGLE_SECRET'], name: :google
254
+ end
255
+ if ENV['OAUTH_FACEBOOK_KEY'] && ENV['OAUTH_FACEBOOK_SECRET']
256
+ require 'omniauth-facebook'
257
+ config.omniauth :facebook, ENV['OAUTH_FACEBOOK_KEY'], ENV['OAUTH_FACEBOOK_SECRET'], secure_image_url: true
258
+ end
237
259
 
238
260
  # ==> Warden configuration
239
261
  # If you want to use other strategies, that are not supported by Devise, or
@@ -258,16 +280,16 @@ Devise.setup do |config|
258
280
  # The router that invoked `devise_for`, in the example above, would be:
259
281
  # config.router_name = :my_engine
260
282
  config.router_name = :mno_enterprise
261
-
262
- #
263
- # When using omniauth, Devise cannot automatically set Omniauth path,
264
- # so you need to do it manually. For the users scope, it would be:
265
- # config.omniauth_path_prefix = '/my_engine/users/auth'
266
- #
283
+
267
284
  # When using omniauth, Devise cannot automatically set Omniauth path,
268
285
  # so you need to do it manually. For the users scope, it would be:
269
286
  # config.omniauth_path_prefix = '/my_engine/users/auth'
270
- #
287
+
271
288
  # Inherit from engine ApplicationController
272
289
  config.parent_controller = 'MnoEnterprise::ApplicationController'
290
+
291
+ Rails.application.config.after_initialize do
292
+ config.omniauth_path_prefix = '/mnoe/users/auth'
293
+ ::OmniAuth::config.path_prefix = config.omniauth_path_prefix if defined?(OmniAuth)
294
+ end
273
295
  end
@@ -1,12 +1,12 @@
1
1
  Warden::Manager.after_authentication do |user, auth, opts|
2
- MnoEnterprise::EventLogger.info('user_login', user.id, "User login", user.email, user) if user
2
+ MnoEnterprise::EventLogger.info('user_login', user.id, 'User login', user) if user
3
3
  end
4
4
 
5
5
  Warden::Manager.before_logout do |user, auth, opts|
6
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
7
+ if auth.env['PATH_INFO'] =~ %r{^/auth/users/sign_out}
8
+ MnoEnterprise::EventLogger.info('user_logout', user.id, 'User logout', user) if user
9
9
  else
10
- MnoEnterprise::EventLogger.info('user_timeout', user.id, "User session expired", user.email, user) if user
10
+ MnoEnterprise::EventLogger.info('user_timeout', user.id, 'User session expired', user) if user
11
11
  end
12
12
  end
data/config/routes.rb CHANGED
@@ -5,6 +5,7 @@ MnoEnterprise::Engine.routes.draw do
5
5
  get '/app_access_unauthorized', to: 'pages#app_access_unauthorized'
6
6
  get '/billing_details_required', to: 'pages#billing_details_required'
7
7
  get '/app_logout', to: 'pages#app_logout'
8
+ get '/terms', to: 'pages#terms'
8
9
 
9
10
  # Health Status
10
11
  get '/ping', to: 'status#ping'
@@ -38,9 +39,10 @@ MnoEnterprise::Engine.routes.draw do
38
39
  class_name: "MnoEnterprise::User",
39
40
  module: :devise,
40
41
  path_prefix: 'auth',
42
+ skip: :omniauth_callbacks,
41
43
  controllers: {
42
44
  confirmations: "mno_enterprise/auth/confirmations",
43
- #omniauth_callbacks: "auth/omniauth_callbacks",
45
+ omniauth_callbacks: "mno_enterprise/auth/omniauth_callbacks",
44
46
  passwords: "mno_enterprise/auth/passwords",
45
47
  registrations: "mno_enterprise/auth/registrations",
46
48
  sessions: "mno_enterprise/auth/sessions",
@@ -54,6 +56,19 @@ MnoEnterprise::Engine.routes.draw do
54
56
  get "/auth/users/confirmation/lounge", to: "auth/confirmations#lounge", as: :user_confirmation_lounge
55
57
  patch "/auth/users/confirmation/finalize", to: "auth/confirmations#finalize", as: :user_confirmation_finalize
56
58
  patch "/auth/users/confirmation", to: "auth/confirmations#update"
59
+
60
+ # Patch omniauth routes as per plataformatec/devise#2692
61
+ providers = Regexp.union(Devise.omniauth_providers.map(&:to_s))
62
+ match "/users/auth/:provider",
63
+ constraints: { provider: providers },
64
+ to: "auth/omniauth_callbacks#passthru",
65
+ as: :user_omniauth_authorize,
66
+ via: [:get, :post]
67
+ match "/users/auth/:action/callback",
68
+ constraints: { action: providers },
69
+ controller: "auth/omniauth_callbacks",
70
+ as: :user_omniauth_callback,
71
+ via: [:get, :post]
57
72
  end
58
73
 
59
74
  #============================================================
@@ -76,9 +91,16 @@ MnoEnterprise::Engine.routes.draw do
76
91
  #============================================================
77
92
  namespace :jpi do
78
93
  namespace :v1 do
79
- resources :marketplace, only: [:index, :show]
94
+ resources :marketplace, only: [:index, :show] do
95
+ member do
96
+ %i(app_reviews app_feedbacks app_comments app_questions app_answers).each do |name|
97
+ resources name, except: [:new, :edit], param: :review_id
98
+ end
99
+ end
100
+ end
80
101
  resource :current_user, only: [:show, :update] do
81
102
  put :update_password
103
+ put :register_developer
82
104
  #post :deletion_request, action: :create_deletion_request
83
105
  #delete :deletion_request, action: :cancel_deletion_request
84
106
  end
@@ -92,7 +114,7 @@ MnoEnterprise::Engine.routes.draw do
92
114
  end
93
115
 
94
116
  # AppInstances
95
- resources :app_instances, only: [:index, :destroy], shallow: true
117
+ resources :app_instances, only: [:index, :create, :destroy], shallow: true
96
118
 
97
119
  # Teams
98
120
  resources :teams, only: [:index, :show, :create, :update, :destroy], shallow: true do
@@ -113,8 +135,17 @@ MnoEnterprise::Engine.routes.draw do
113
135
 
114
136
  namespace :impac do
115
137
  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]
138
+ resources :widgets, shallow: true, only: [:create, :update, :destroy]
139
+ resources :kpis, shallow: true, only: [:show, :create, :update, :destroy] do
140
+ resources :alerts, shallow: true, only: [:create, :update, :destroy]
141
+ end
142
+ end
143
+
144
+ resources :kpis, only: :index
145
+ resources :alerts, only: :index
146
+
147
+ resources :organizations, only: [] do
148
+ resources :widgets, only: :index
118
149
  end
119
150
  end
120
151
 
@@ -124,13 +155,17 @@ MnoEnterprise::Engine.routes.draw do
124
155
  #============================================================
125
156
  namespace :admin, defaults: {format: 'json'} do
126
157
  resources :audit_events, only: [:index]
158
+ resources :app_instances, only: [:destroy], shallow: true
159
+ resources :app_reviews, only: [:index, :show, :update]
160
+ resources :app_comments, only: [:create]
161
+ resources :app_answers, only: [:create]
127
162
  resources :users, only: [:index, :show, :destroy, :update, :create] do
128
163
  collection do
129
164
  get :count
130
165
  post :signup_email
131
166
  end
132
167
  end
133
- resources :organizations, only: [:index, :show, :create] do
168
+ resources :organizations, only: [:index, :show, :update, :create] do
134
169
  collection do
135
170
  get :in_arrears
136
171
  get :count
@@ -1,6 +1,7 @@
1
1
  require 'action_view' # To fix "uninitialized constant Haml::ActionView"
2
2
  require 'jbuilder'
3
3
  require 'haml'
4
+ require 'credit_card_validations'
4
5
 
5
6
  require 'mno_enterprise/core'
6
7
 
@@ -0,0 +1,28 @@
1
+ require 'httparty'
2
+
3
+ module MnoEnterprise
4
+ class AuditEventsListener
5
+ include HTTParty
6
+ base_uri "#{MnoEnterprise.mno_api_private_host || MnoEnterprise.mno_api_host}/api/mnoe/v1/audit_events"
7
+ read_timeout 0.1
8
+ basic_auth MnoEnterprise.tenant_id, MnoEnterprise.tenant_key
9
+
10
+ def info(key, current_user_id, description, subject_type, subject_id, metadata)
11
+ self.class.post('', body: {
12
+ data: {
13
+ key: key,
14
+ user_id: current_user_id,
15
+ description: description,
16
+ metadata: metadata,
17
+ subject_type: subject_type,
18
+ subject_id: subject_id
19
+ }})
20
+ rescue Net::ReadTimeout
21
+ # Meant to fail
22
+ end
23
+
24
+ end
25
+
26
+
27
+ end
28
+
@@ -0,0 +1,45 @@
1
+ module MnoEnterprise::Concerns::Controllers::Jpi::V1::AppInstancesController
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
+ respond_to :json
11
+ end
12
+
13
+ #==================================================================
14
+ # Instance methods
15
+ #==================================================================
16
+ # GET /mnoe/jpi/v1/organization/1/apps.json?timestamp=151452452345
17
+ def index
18
+ @app_instances = parent_organization.app_instances.active.where("updated_at.gt" => Time.at(timestamp)).select do |i|
19
+ # force owner assignment to avoid a refetch in ability can?(:access,i)
20
+ i.owner = parent_organization
21
+ can?(:access,i)
22
+ end
23
+ end
24
+
25
+ # POST /mnoe/jpi/v1/organization/1/app_instances
26
+ def create
27
+ authorize! :manage_app_instances, parent_organization
28
+ app_instance = parent_organization.app_instances.create(product: params[:nid])
29
+ MnoEnterprise::EventLogger.info('app_add', current_user.id, 'App added', app_instance)
30
+ head :created
31
+ end
32
+
33
+ # DELETE /mnoe/jpi/v1/app_instances/1
34
+ def destroy
35
+ app_instance = MnoEnterprise::AppInstance.find(params[:id])
36
+
37
+ if app_instance
38
+ authorize! :manage_app_instances, app_instance.owner
39
+ MnoEnterprise::EventLogger.info('app_destroy', current_user.id, 'App destroyed', app_instance)
40
+ app_instance.terminate
41
+ end
42
+
43
+ head :accepted
44
+ end
45
+ end
@@ -23,11 +23,21 @@ module MnoEnterprise::Concerns::Controllers::Jpi::V1::CurrentUsersController
23
23
  # PUT /mnoe/jpi/v1/current_user
24
24
  def update
25
25
  @user = current_user
26
-
27
26
  @user.assign_attributes(user_params)
28
27
  changes = @user.changes
29
28
  if @user.update(user_params)
30
- MnoEnterprise::EventLogger.info('user_update', current_user.id, "User update", changes, @user)
29
+ MnoEnterprise::EventLogger.info('user_update', current_user.id, 'User update', @user, changes)
30
+ render :show
31
+ else
32
+ render json: @user.errors, status: :bad_request
33
+ end
34
+ end
35
+
36
+ # PUT /mnoe/jpi/v1/current_user/register_developer
37
+ def register_developer
38
+ @user = current_user
39
+ if @user.update(developer: true)
40
+ MnoEnterprise::EventLogger.info('register_developer', current_user.id, "User developer register", @user)
31
41
  render :show
32
42
  else
33
43
  render json: @user.errors, status: :bad_request
@@ -39,14 +49,14 @@ module MnoEnterprise::Concerns::Controllers::Jpi::V1::CurrentUsersController
39
49
  @user = current_user
40
50
 
41
51
  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)
52
+ MnoEnterprise::EventLogger.info('user_update_password', current_user.id, 'User password change', @user)
43
53
  sign_in @user, bypass: true
44
54
  render :show
45
55
  else
46
56
  render json: @user.errors, status: :bad_request
47
57
  end
48
58
  end
49
-
59
+
50
60
  private
51
61
  def user_params
52
62
  params.require(:user).permit(:name, :surname, :email, :company, :settings, :phone, :website, :phone_country_code, :current_password, :password, :password_confirmation)
@@ -0,0 +1,76 @@
1
+ module MnoEnterprise::Concerns::Controllers::Jpi::V1::Impac::AlertsController
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
+ respond_to :json
11
+ end
12
+
13
+ # GET /jpi/v1/impac/alerts
14
+ def index
15
+ @alerts = current_user.alerts
16
+ end
17
+
18
+ # POST /jpi/v1/impac/kpis/:kpi_id/alerts
19
+ def create
20
+ return render_bad_request('attach alert to kpi', 'no alert specified') unless params.require(:alert)
21
+ return render_not_found('kpi') unless kpi_alert.kpi
22
+
23
+ authorize! :manage_alert, kpi_alert
24
+
25
+ if (@alert = current_user.alerts.create(kpi_alert.attributes))
26
+ render 'show'
27
+ else
28
+ render_bad_request('attach alert to kpi', "impossible to save record: #{@kpi_alert.inspect}")
29
+ end
30
+ end
31
+
32
+ # PUT /jpi/v1/impac/alerts/:id
33
+ def update
34
+ return render_bad_request('update alert attributes', 'no alert hash specified') unless params.require(:alert)
35
+ return render_not_found('alert') unless alert
36
+
37
+ attributes = params.require(:alert).permit(:title, :webhook, :sent)
38
+
39
+ authorize! :manage_alert, alert
40
+
41
+ if alert.update(attributes)
42
+ render 'show'
43
+ else
44
+ render_bad_request('update alert', "unable to save record: #{alert.inspect}")
45
+ end
46
+ end
47
+
48
+ # DELETE /jpi/v1/impac/alerts/:id
49
+ def destroy
50
+ return render_not_found('alert') unless alert
51
+
52
+ authorize! :manage_alert, alert
53
+
54
+ service = alert.service
55
+ if alert.destroy
56
+ render json: { deleted: { service: service } }
57
+ else
58
+ render_bad_request('destroy alert', "impossible to destroy record: #{alert.inspect}")
59
+ end
60
+ end
61
+
62
+
63
+ private
64
+
65
+ def alert
66
+ @alert ||= MnoEnterprise::Impac::Alert.find(params.require(:id))
67
+ end
68
+
69
+ def kpi_alert
70
+ @alert ||= (
71
+ kpi_id = params.require(:kpi_id)
72
+ attributes = params.require(:alert).merge(impac_kpi_id: kpi_id)
73
+ MnoEnterprise::Impac::Alert.new(attributes)
74
+ )
75
+ end
76
+ end
@@ -19,58 +19,84 @@ module MnoEnterprise::Concerns::Controllers::Jpi::V1::Impac::DashboardsControlle
19
19
  end
20
20
 
21
21
  # GET /mnoe/jpi/v1/impac/dashboards/1
22
+ # -> GET /api/mnoe/v1/users/1/dashboards
22
23
  def show
23
24
  dashboard
24
- render json: { errors: "Dashboard id #{params[:id]} doesn't exist" }, status: :not_found unless @dashboard
25
+ render_not_found('dashboard') unless @dashboard
25
26
  end
26
27
 
27
28
  # POST /mnoe/jpi/v1/impac/dashboards
28
- # -> POST /api/mnoe/v1/users/282/dashboards
29
+ # -> POST /api/mnoe/v1/users/1/dashboards
29
30
  def create
31
+ # TODO: dashboards.build breaks as dashboard.organization_ids returns nil, instead of an
32
+ # empty array. (see MnoEnterprise::Impac::Dashboard #organizations)
33
+ # @dashboard = dashboards.build(dashboard_create_params)
34
+ # TODO: enable authorization
35
+ # authorize! :manage_dashboard, @dashboard
36
+ # if @dashboard.save
30
37
  if @dashboard = dashboards.create(dashboard_create_params)
31
- # authorize! :create, @dashboard
32
- MnoEnterprise::EventLogger.info('dashboard_create', current_user.id, 'Dashboard Creation', nil, @dashboard)
38
+ MnoEnterprise::EventLogger.info('dashboard_create', current_user.id, 'Dashboard Creation', @dashboard)
39
+
33
40
  render 'show'
34
41
  else
35
- render json: @dashboard.errors, status: :bad_request
42
+ render_bad_request('create dashboard', @dashboard.errors)
36
43
  end
37
44
  end
38
45
 
39
46
  # PUT /mnoe/jpi/v1/impac/dashboards/1
47
+ # -> PUT /api/mnoe/v1/dashboards/1
40
48
  def update
49
+ return render_not_found('dashboard') unless dashboard
50
+
51
+ # TODO: enable authorization
52
+ # authorize! :manage_dashboard, dashboard
53
+
41
54
  if dashboard.update(dashboard_update_params)
42
- # dashboard.assign_attributes(attrs)
43
- # authorize! :update, dashboard
44
55
  render 'show'
45
56
  else
46
- render json: @dashboard.errors, status: :bad_request
57
+ render_bad_request('update dashboard', dashboard.errors)
47
58
  end
48
59
  end
49
60
 
50
61
  # DELETE /mnoe/jpi/v1/impac/dashboards/1
62
+ # -> DELETE /api/mnoe/v1/dashboards/1
51
63
  def destroy
52
- # authorize! :destroy, @dashboard
64
+ return render_not_found('dashboard') unless dashboard
65
+
66
+ # TODO: enable authorization
67
+ # authorize! :manage_dashboard, dashboard
68
+
53
69
  if dashboard.destroy
54
- MnoEnterprise::EventLogger.info('dashboard_delete', current_user.id, 'Dashboard Deletion', nil, dashboard)
70
+ MnoEnterprise::EventLogger.info('dashboard_delete', current_user.id, 'Dashboard Deletion', dashboard)
55
71
  head status: :ok
56
72
  else
57
- render json: 'Unable to destroy dashboard', status: :bad_request
73
+ render_bad_request('destroy dashboard', 'Unable to destroy dashboard')
58
74
  end
59
75
  end
60
76
 
61
- protected
77
+ private
62
78
 
63
- def dashboard
64
- @dashboard ||= current_user.dashboards.to_a.find { |d| d.id.to_s == params[:id].to_s }
65
- end
79
+ def dashboard
80
+ @dashboard ||= current_user.dashboards.find(params[:id].to_i)
81
+ end
66
82
 
67
- def dashboards
68
- @dashboards ||= current_user.dashboards
69
- end
83
+ def dashboards
84
+ @dashboards ||= current_user.dashboards
85
+ end
86
+
87
+ def whitelisted_params
88
+ [:name, :currency, {widgets_order: []}, {organization_ids: []}]
89
+ end
90
+
91
+ # Allows all metadata attrs to be permitted, and maps it to :settings
92
+ # for the Her "meta_data" issue.
93
+ def dashboard_params
94
+ params.require(:dashboard).permit(*whitelisted_params).tap do |whitelisted|
95
+ whitelisted[:settings] = params[:dashboard][:metadata] || {}
96
+ end
97
+ .except(:metadata)
98
+ end
99
+ alias :dashboard_update_params :dashboard_params
100
+ alias :dashboard_create_params :dashboard_params
70
101
 
71
- def dashboard_params
72
- params.require(:dashboard).permit(:name, :currency, {widgets_order: []}, {organization_ids: []})
73
- end
74
- alias :dashboard_update_params :dashboard_params
75
- alias :dashboard_create_params :dashboard_params
76
102
  end