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,86 @@
1
+ require 'rails_helper'
2
+
3
+ module MnoEnterprise
4
+ describe Jpi::V1::TeamsController, type: :controller do
5
+ include MnoEnterprise::TestingSupport::JpiV1TestHelper
6
+
7
+ render_views
8
+ routes { MnoEnterprise::Engine.routes }
9
+ before { request.env["HTTP_ACCEPT"] = 'application/json' }
10
+
11
+ def users_for_team(team)
12
+ team.users.map do |user|
13
+ {
14
+ 'id' => user.id,
15
+ 'name' => user.name,
16
+ 'surname' => user.surname,
17
+ 'email' => user.email,
18
+ 'role' => nil
19
+ }
20
+ end
21
+ end
22
+
23
+ def apps_for_team(team)
24
+ team.app_instances.map do |app_instance|
25
+ {
26
+ 'id' => app_instance.id,
27
+ 'name' => app_instance.name,
28
+ 'logo' => app_instance.app.logo
29
+ }
30
+ end
31
+ end
32
+
33
+ def hash_for_team(team)
34
+ {
35
+ 'team' => {
36
+ id: team.id,
37
+ name: team.name,
38
+ users: users_for_team(team),
39
+ app_instances: apps_for_team(team)
40
+ }
41
+ }
42
+ end
43
+
44
+ #===============================================
45
+ # Assignments
46
+ #===============================================
47
+ # Stub controller ability
48
+ let!(:ability) { stub_ability }
49
+ before { allow(ability).to receive(:can?).with(any_args).and_return(true) }
50
+
51
+ # Stub user and user call
52
+ let(:user) { build(:user, :with_organizations) }
53
+ let(:user2) { build(:user, :with_organizations, name: "Joe") }
54
+ let(:organization) { build(:organization) }
55
+ let(:team) { build(:team, organization: organization) }
56
+ let(:app_instance) { build(:app_instance) }
57
+ before do
58
+ api_stub_for(get: "/users/#{user.id}", response: from_api(user))
59
+ api_stub_for(get: "/users/#{user.id}/organizations", response: from_api(organization))
60
+ api_stub_for(post: "/organizations", response: from_api(organization))
61
+ api_stub_for(get: "/organizations/#{organization.id}/users", response: from_api([user]))
62
+ api_stub_for(post: "/organizations/#{organization.id}/users", response: from_api(user))
63
+ api_stub_for(get: "/organizations/#{organization.id}/teams", response: from_api([team]))
64
+ api_stub_for(get: "/teams/#{team.id}", response: from_api(team))
65
+ api_stub_for(get: "/teams/#{team.id}/app_instances", response: from_api([app_instance]))
66
+ api_stub_for(get: "/teams/#{team.id}/users", response: from_api([user, user2]))
67
+ sign_in user
68
+ end
69
+
70
+ #===============================================
71
+ # Specs
72
+ #===============================================
73
+ describe 'PUT #add_users' do
74
+ subject { put :add_users, id: team.id }
75
+
76
+ context 'success' do
77
+ before { subject }
78
+
79
+ it 'returns a list of teams' do
80
+ expect(response).to be_success
81
+ expect(JSON.parse(response.body)).to eq(JSON.parse(hash_for_team(team).to_json))
82
+ end
83
+ end
84
+ end
85
+ end
86
+ end
@@ -0,0 +1,29 @@
1
+ require 'rails_helper'
2
+
3
+ module MnoEnterprise
4
+ describe OrgInvitesController, type: :controller do
5
+ render_views
6
+ routes { MnoEnterprise::Engine.routes }
7
+
8
+ let(:user) { build(:user) }
9
+ #before { api_stub_for(get: "/users/#{user.id}", response: from_api(user)) }
10
+ #before { api_stub_for(put: "/users/#{user.id}", response: from_api(user)) }
11
+
12
+ describe "GET #show" do
13
+ before { sign_in user }
14
+ subject { get :show }
15
+
16
+ # it_behaves_like "a navigatable protected user action"
17
+ #
18
+ # it "assigns the right meta information" do
19
+ # get :myspace
20
+ # meta = {}
21
+ # meta[:title] = "Dashboard"
22
+ # meta[:description] = "Dashboard"
23
+ # assigns(:meta).should == meta
24
+ # end
25
+ end
26
+
27
+ end
28
+
29
+ end
@@ -0,0 +1,49 @@
1
+ require 'rails_helper'
2
+
3
+ module MnoEnterprise
4
+ describe PagesController, type: :controller do
5
+ render_views
6
+ routes { MnoEnterprise::Engine.routes }
7
+
8
+ let(:user) { build(:user) }
9
+ let(:app_instance) { build(:app_instance) }
10
+
11
+ before do
12
+ api_stub_for(get: "/users/#{user.id}", response: from_api(user))
13
+ api_stub_for(put: "/users/#{user.id}", response: from_api(user))
14
+ api_stub_for(get: "/app_instances", response: from_api([app_instance]))
15
+ end
16
+
17
+ describe 'GET #launch' do
18
+ let(:app_instance) { build(:app_instance) }
19
+ before { sign_in user }
20
+ subject { get :launch, id: app_instance.uid }
21
+
22
+ it_behaves_like "a navigatable protected user action"
23
+
24
+ it 'redirect to the mno enterprise launch page with a web token' do
25
+ subject
26
+ expect(response).to redirect_to(MnoEnterprise.router.launch_url(app_instance.uid, wtk: MnoEnterprise.jwt({user_id: user.uid})))
27
+ end
28
+ end
29
+
30
+ describe 'GET #app_access_unauthorized' do
31
+ subject { get :app_access_unauthorized }
32
+ before { subject }
33
+ it { expect(response).to be_success }
34
+ end
35
+
36
+ describe 'GET #billing_details_required' do
37
+ subject { get :billing_details_required }
38
+ before { subject }
39
+ it { expect(response).to be_success }
40
+ end
41
+
42
+ describe 'GET #app_logout' do
43
+ subject { get :app_logout }
44
+ before { subject }
45
+ it { expect(response).to be_success }
46
+ end
47
+
48
+ end
49
+ end
@@ -0,0 +1,94 @@
1
+ require 'rails_helper'
2
+
3
+ module MnoEnterprise
4
+ describe ProvisionController, type: :controller do
5
+ render_views
6
+ routes { MnoEnterprise::Engine.routes }
7
+
8
+ # Create user and organization + mutual associations
9
+ let(:organization) { build(:organization) }
10
+ let(:user) { build(:user, :admin) }
11
+
12
+ let!(:ability) { stub_ability }
13
+
14
+ before do
15
+ api_stub_for(get: "/users/#{user.id}", response: from_api(user))
16
+ allow(organization).to receive(:users).and_return([user])
17
+ allow_any_instance_of(User).to receive(:organizations).and_return([organization])
18
+ end
19
+
20
+ describe 'GET #new' do
21
+ let(:params_org_id) { organization.id }
22
+ let(:params) { {apps: ['vtiger'], organization_id: params_org_id} }
23
+ subject { get :new, params }
24
+
25
+ describe 'guest' do
26
+ before { subject }
27
+ it { expect(response).to redirect_to(new_user_registration_path) }
28
+ end
29
+
30
+ # TODO: ability to add app instances for an organization
31
+ describe 'signed in and missing organization with multiple organizations available' do
32
+ let(:params_org_id) { nil }
33
+ let(:authorized) { true }
34
+ before do
35
+ allow_any_instance_of(User).to receive(:organizations).and_return([organization, organization])
36
+ sign_in user
37
+ allow(ability).to receive(:can?).with(any_args).and_return(authorized)
38
+ subject
39
+ end
40
+
41
+ it { expect(response).to render_template('mno_enterprise/provision/_select_organization') }
42
+
43
+ describe "unauthorized" do
44
+ let(:authorized) { false }
45
+ it { expect(response).to redirect_to(root_path) }
46
+ end
47
+ end
48
+
49
+ describe 'signed in and missing organization with one organization available' do
50
+ let(:params_org_id) { nil }
51
+ let(:authorized) { true }
52
+ before do
53
+ sign_in user
54
+ allow(ability).to receive(:can?).with(any_args).and_return(authorized)
55
+ subject
56
+ end
57
+
58
+ it { expect(response).to render_template('mno_enterprise/provision/_provision_apps') }
59
+ describe "unauthorized" do
60
+ let(:authorized) { false }
61
+ it { expect(response).to redirect_to(root_path) }
62
+ end
63
+ end
64
+ end
65
+
66
+ describe 'POST #create' do
67
+ let(:params_org_id) { organization.id }
68
+ let(:app_instance) { build(:app_instance) }
69
+ let(:params) { {apps: ['vtiger'], organization_id: params_org_id} }
70
+ subject { post :create, params }
71
+ before do
72
+ api_stub_for(get: "/organizations/#{params_org_id}/app_instances", response: from_api([app_instance]))
73
+ api_stub_for(post: "/organizations/#{params_org_id}/app_instances", response: from_api(app_instance))
74
+ end
75
+
76
+ describe 'guest' do
77
+ before { subject }
78
+ it { expect(response).to_not be_success }
79
+ end
80
+
81
+ describe 'signed in' do
82
+ let(:authorized) { true }
83
+ before do
84
+ sign_in user
85
+ allow(ability).to receive(:can?).with(any_args).and_return(authorized)
86
+ subject
87
+ end
88
+
89
+ it { expect(response).to be_success }
90
+ end
91
+ end
92
+
93
+ end
94
+ end
@@ -0,0 +1,34 @@
1
+ require 'rails_helper'
2
+
3
+ module MnoEnterprise
4
+ describe StatusController, type: :controller do
5
+ routes { MnoEnterprise::Engine.routes }
6
+
7
+ describe 'GET #ping' do
8
+ before { get :ping }
9
+
10
+ it { is_expected.to respond_with(200) }
11
+ it { expect(response.body).to eq({status: 'Ok'}.to_json) }
12
+ end
13
+
14
+ describe 'GET #version' do
15
+ before { get :version }
16
+ let(:data) { JSON.parse(response.body) }
17
+
18
+ it { is_expected.to respond_with(200) }
19
+
20
+ it 'returns the main app version' do
21
+ puts MnoEnterprise::APP_VERSION
22
+ expect(data['app-version']).to eq(MnoEnterprise::APP_VERSION)
23
+ end
24
+
25
+ it 'returns the mnoe-version' do
26
+ expect(data['mno-enteprise-version']).to eq(MnoEnterprise::VERSION)
27
+ end
28
+
29
+ it 'returns the environment' do
30
+ expect(data['env']).to eq('test')
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,104 @@
1
+ require 'rails_helper'
2
+
3
+ def main_app
4
+ Rails.application.class.routes.url_helpers
5
+ end
6
+
7
+ module MnoEnterprise
8
+ describe Webhook::OAuthController, type: :controller do
9
+ render_views
10
+ routes { MnoEnterprise::Engine.routes }
11
+
12
+ # Stub controller ability
13
+ let!(:ability) { stub_ability }
14
+ let(:extra_params) { {some: 'param'} }
15
+ before { allow(ability).to receive(:can?).with(any_args).and_return(true) }
16
+
17
+ # Stub model calls
18
+ let(:user) { build(:user) }
19
+ let(:organization) { build(:organization) }
20
+ let(:app) { build(:app) }
21
+ let(:app_instance) { build(:app_instance) }
22
+ before { api_stub_for(get: "/users/#{user.id}", response: from_api(user)) }
23
+ before { api_stub_for(get: "/app_instances", response: from_api([app_instance])) }
24
+ before { allow_any_instance_of(MnoEnterprise::AppInstance).to receive(:app).and_return(app) }
25
+
26
+ describe 'GET #authorize' do
27
+ let(:redir_params) { extra_params.reject { |k, v| k.to_sym == :perform } }
28
+ let(:redirect_url) { MnoEnterprise.router.authorize_oauth_url(app_instance.uid, redir_params.merge(wtk: MnoEnterprise.jwt(user_id: user.uid))) }
29
+ subject { get :authorize, extra_params.merge(id: app_instance.uid) }
30
+ before { sign_in user }
31
+
32
+ it_behaves_like 'a navigatable protected user action'
33
+ it_behaves_like 'a user protected resource'
34
+
35
+ it { subject; expect(response).to be_success }
36
+ it { subject; expect(assigns(:redirect_to)).to eq(redirect_url) }
37
+
38
+ Webhook::OAuthController::PROVIDERS_WITH_OPTIONS.each do |provider|
39
+ describe "#{provider.capitalize} provider" do
40
+ let(:app) { build(:app, nid: provider.parameterize) }
41
+ it { subject; expect(response).to render_template("providers/#{provider.parameterize}") }
42
+
43
+ context 'with perform=true' do
44
+ let(:extra_params) { {perform: true} }
45
+ it { subject; expect(assigns(:redirect_to)).to eq(redirect_url) }
46
+ end
47
+ end
48
+ end
49
+ end
50
+
51
+ describe 'GET #callback' do
52
+ subject { get :callback, id: app_instance.uid }
53
+
54
+ context 'when session has redirect_path' do
55
+ before { session[:redirect_path] = 'http://www.example.com/redirect' }
56
+
57
+ it { subject; expect(response).to redirect_to('http://www.example.com/redirect') }
58
+ end
59
+
60
+ context 'when there is on oauth error' do
61
+ subject { get :callback, id: app_instance.uid, oauth: {error: :unauthorized} }
62
+
63
+ let(:fragment) { "#?#{URI.encode_www_form([['flash', {msg: 'We could not validate your credentials, please try again', type: :error}.to_json]])}" }
64
+
65
+ it { subject; expect(response).to redirect_to(main_app.root_path + fragment) }
66
+ end
67
+
68
+ it { subject; expect(response).to redirect_to(main_app.root_path) }
69
+ end
70
+
71
+ describe 'GET #disconnect' do
72
+ let(:redirect_url) { MnoEnterprise.router.disconnect_oauth_url(app_instance.uid, extra_params.merge(wtk: MnoEnterprise.jwt(user_id: user.uid))) }
73
+ subject { get :disconnect, extra_params.merge(id: app_instance.uid) }
74
+ before { sign_in user }
75
+
76
+ it_behaves_like 'a navigatable protected user action'
77
+ it_behaves_like 'a user protected resource'
78
+
79
+ it { subject; expect(response).to redirect_to(redirect_url) }
80
+ end
81
+
82
+ describe 'GET #sync' do
83
+ let(:redirect_url) { MnoEnterprise.router.sync_oauth_url(app_instance.uid, extra_params.merge(wtk: MnoEnterprise.jwt(user_id: user.uid))) }
84
+ before { sign_in user }
85
+ subject { get :sync, extra_params.merge(id: app_instance.uid) }
86
+
87
+ it_behaves_like 'a navigatable protected user action'
88
+ it_behaves_like 'a user protected resource'
89
+
90
+ it { subject; expect(response).to redirect_to(redirect_url) }
91
+ end
92
+
93
+ describe '#add_param_to_fragment' do
94
+ let(:controller) { described_class.new }
95
+
96
+ it { expect(subject.send(:add_param_to_fragment, '/#/platform/accounts', 'foo', 'bar')).to eq('/#/platform/accounts?foo=bar') }
97
+ it { expect(subject.send(:add_param_to_fragment, '/', 'foo', 'bar')).to eq('/#?foo=bar') }
98
+ it { expect(subject.send(:add_param_to_fragment, '/#/platform/dashboard/he/43?en=690', 'foo', 'bar')).to eq('/#/platform/dashboard/he/43?en=690&foo=bar') }
99
+ it { expect(subject.send(:add_param_to_fragment, '/#/platform/dashboard/he/43?en=690', 'foo', [{msg: 'yolo'}])).to eq('/#/platform/dashboard/he/43?en=690&foo=%7B%3Amsg%3D%3E%22yolo%22%7D') }
100
+
101
+ end
102
+
103
+ end
104
+ end
@@ -0,0 +1,28 @@
1
+ require 'rails_helper'
2
+
3
+ module MnoEnterprise
4
+ RSpec.describe EventLogger do
5
+
6
+ def info_data(user)
7
+ {
8
+ data: {
9
+ key: 'user_update_password',
10
+ user_id: user.id,
11
+ description: 'User password change',
12
+ metadata: user.email,
13
+ subject_type: user.class.name,
14
+ subject_id: user.id
15
+ }
16
+ }
17
+ end
18
+
19
+ let(:user) { build(:user) }
20
+
21
+ describe "#info" do
22
+ subject { MnoEnterprise::EventLogger.info('user_update_password', user.id, "User password change", user.email, user) }
23
+
24
+ it { expect(subject.code).to eq(200) }
25
+ it { expect(subject.request.options[:body]).to eq(info_data(user)) }
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,132 @@
1
+ require 'rails_helper'
2
+
3
+ module MnoEnterprise
4
+ RSpec.describe SystemNotificationMailer do
5
+ subject { SystemNotificationMailer }
6
+ before { MnoEnterprise::Engine.routes.default_url_options = {host: 'http://localhost:3000'} }
7
+ let(:routes) { MnoEnterprise::Engine.routes.url_helpers }
8
+ let(:user) { build(:user) }
9
+ let(:token) { "1sd5f323S1D5AS" }
10
+ let(:deletion_request) { build(:deletion_request) }
11
+
12
+ # Commonly used mandrill variables
13
+ def user_vars(user)
14
+ { first_name: user.name, last_name: user.surname, full_name: "#{user.name} #{user.surname}".strip }
15
+ end
16
+
17
+ def invite_vars(org_invite)
18
+ new_user = !org_invite.user.confirmed?
19
+
20
+ {
21
+ organization: org_invite.organization.name,
22
+ team: org_invite.team ? org_invite.team.name : nil,
23
+ ref_first_name: org_invite.referrer.name,
24
+ ref_last_name: org_invite.referrer.surname,
25
+ ref_full_name: "#{org_invite.referrer.name} #{org_invite.referrer.surname}".strip,
26
+ ref_email: org_invite.referrer.email,
27
+ invitee_first_name: new_user ? nil : org_invite.user.name,
28
+ invitee_last_name: new_user ? nil : org_invite.user.surname,
29
+ invitee_full_name: new_user ? nil : "#{org_invite.user.name} #{org_invite.user.surname}".strip,
30
+ invitee_email: org_invite.user.email,
31
+ }
32
+ end
33
+
34
+ describe 'confirmation_instructions' do
35
+ describe 'new user' do
36
+ it 'sends the right email' do
37
+ expect(MandrillClient).to receive(:deliver).with('confirmation-instructions',
38
+ SystemNotificationMailer::DEFAULT_SENDER,
39
+ { name: "#{user.name} #{user.surname}".strip, email: user.email },
40
+ user_vars(user).merge(confirmation_link: routes.user_confirmation_url(confirmation_token: token))
41
+ )
42
+
43
+ subject.confirmation_instructions(user,token).deliver_now
44
+ end
45
+ end
46
+
47
+ describe 'existing user with new email address' do
48
+ before { allow_any_instance_of(MnoEnterprise::User).to receive(:confirmed?).and_return(true) }
49
+ before { allow_any_instance_of(MnoEnterprise::User).to receive(:unconfirmed_email?).and_return(true) }
50
+
51
+ it 'sends the right email' do
52
+ expect(MandrillClient).to receive(:deliver).with('reconfirmation-instructions',
53
+ SystemNotificationMailer::DEFAULT_SENDER,
54
+ { name: "#{user.name} #{user.surname}".strip, email: user.email },
55
+ user_vars(user).merge(confirmation_link: routes.user_confirmation_url(confirmation_token: token))
56
+ )
57
+
58
+ subject.confirmation_instructions(user,token).deliver_now
59
+ end
60
+ end
61
+
62
+ end
63
+
64
+ describe 'reset_password_instructions' do
65
+ it 'sends the right email' do
66
+ expect(MandrillClient).to receive(:deliver).with('reset-password-instructions',
67
+ SystemNotificationMailer::DEFAULT_SENDER,
68
+ { name: "#{user.name} #{user.surname}".strip, email: user.email },
69
+ user_vars(user).merge(reset_password_link: routes.edit_user_password_url(reset_password_token: token))
70
+ )
71
+
72
+ subject.reset_password_instructions(user,token).deliver_now
73
+ end
74
+ end
75
+
76
+ describe 'unlock_instructions' do
77
+ it 'sends the right email' do
78
+ expect(MandrillClient).to receive(:deliver).with('unlock-instructions',
79
+ SystemNotificationMailer::DEFAULT_SENDER,
80
+ { name: "#{user.name} #{user.surname}".strip, email: user.email },
81
+ user_vars(user).merge(unlock_link: routes.user_unlock_url(unlock_token: token))
82
+ )
83
+
84
+ subject.unlock_instructions(user,token).deliver_now
85
+ end
86
+ end
87
+
88
+ describe 'organization_invite' do
89
+ let(:invitee) { build(:user) }
90
+ let(:org_invite) { build(:org_invite, user: invitee, referrer: user) }
91
+
92
+ context 'when invitee is a confirmed user' do
93
+ it 'sends the right email' do
94
+ expect(MandrillClient).to receive(:deliver).with('organization-invite-existing-user',
95
+ SystemNotificationMailer::DEFAULT_SENDER,
96
+ { name: "#{invitee.name} #{invitee.surname}".strip, email: invitee.email },
97
+ invite_vars(org_invite).merge(confirmation_link: routes.org_invite_url(id: org_invite.id, token: org_invite.token))
98
+ )
99
+
100
+ subject.organization_invite(org_invite).deliver_now
101
+ end
102
+ end
103
+
104
+ context 'when inviteee is an unconfirmed user' do
105
+ let(:invitee) { build(:user, :unconfirmed) }
106
+
107
+ it 'sends the right email' do
108
+ expect(MandrillClient).to receive(:deliver).with('organization-invite-new-user',
109
+ SystemNotificationMailer::DEFAULT_SENDER,
110
+ { email: invitee.email },
111
+ invite_vars(org_invite).merge(confirmation_link: routes.user_confirmation_url(confirmation_token: invitee.confirmation_token))
112
+ )
113
+
114
+ subject.organization_invite(org_invite).deliver_now
115
+ end
116
+ end
117
+
118
+ end
119
+
120
+ describe 'deletion_request_instructions' do
121
+ it 'sends the correct email' do
122
+ expect(MandrillClient).to receive(:deliver).with('deletion-request-instructions',
123
+ SystemNotificationMailer::DEFAULT_SENDER,
124
+ { name: "#{user.name} #{user.surname}".strip, email: user.email },
125
+ user_vars(user).merge(terminate_account_link: routes.deletion_request_url(deletion_request))
126
+ )
127
+
128
+ subject.deletion_request_instructions(user,deletion_request).deliver_now
129
+ end
130
+ end
131
+ end
132
+ end