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
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c17e731fc6479dd2463a9a081eec77d50cbfaf5d
4
- data.tar.gz: f791a962650c45dc5c310f4b1a660ab48d2b8bba
3
+ metadata.gz: 98313610cc252efb1e91c0187d397ba299476e9d
4
+ data.tar.gz: 7046190053c32c805db818b9b36d2aad461ffb94
5
5
  SHA512:
6
- metadata.gz: 9590fe9cc0bc61c996216277404caa50b83a6d228ae23c5acab7c06687797a553a57e63e84baaf24d06430d7fdebe86e392e3c8540eff3c83458ace45bdc110d
7
- data.tar.gz: f56f3fef5b4a6447111df480dec04757b6975474ec2cae343d75d449b28c000bbc50870bfcec38d182b4e3ce8e888af996f7cd29caff0c9c00af7cca8b3d06f8
6
+ metadata.gz: f04f1a99e1922cc754a2ec0d3bad296efb151cb40c55f4a3e0ae88baf5a496246cca95697e19025e198d3597cc3761eeab5c4e9ccd19d89c011bb7958e6e5b94
7
+ data.tar.gz: 41c1785557185b19e3dc80d526313e60b7652a9b7147779c0a53892da2148351b05586f557a78fb67b71f24215885be9bb13f262959a3eba3ef846ae12b9cc57
@@ -8,5 +8,11 @@ angular.module('mnoEnterprise.configuration', [])
8
8
  enabled: <%= MnoEnterprise.i18n_enabled %>,
9
9
  available_locales: <%= I18n.available_locales.to_json %>
10
10
  })
11
- .constant('PRICING_CONFIG', <%= Settings.pricing.to_json %>)
11
+ .constant('PRICING_CONFIG', <%= Hash(Settings.pricing).to_json %>)
12
+ .constant('DOCK_CONFIG', <%= Hash(Settings.dock).to_json %>)
13
+ .constant('DEVELOPER_SECTION_CONFIG', <%= Hash(Settings.developer).to_json %>)
14
+ .constant('REVIEWS_CONFIG', <%= Hash(Settings.reviews).to_json %>)
15
+ .constant('MARKETPLACE_CONFIG', <%= Hash(Settings.marketplace).to_json %>)
12
16
  .constant('GOOGLE_TAG_CONTAINER_ID', <%= MnoEnterprise.google_tag_container.to_json %>)
17
+ .constant('INTERCOM_ID', <%= MnoEnterprise.intercom_app_id.to_json %>)
18
+ .constant('APP_NAME', <%= MnoEnterprise.app_name.to_json %>)
@@ -1,30 +1,6 @@
1
1
  module MnoEnterprise
2
2
  class Auth::OmniauthCallbacksController < Devise::OmniauthCallbacksController
3
- # You should configure your model like this:
4
- # devise :omniauthable, omniauth_providers: [:twitter]
5
-
6
- # You should also create an action method in this controller like this:
7
- # def twitter
8
- # end
9
-
10
- # More info at:
11
- # https://github.com/plataformatec/devise#omniauth
12
-
13
- # GET|POST /resource/auth/twitter
14
- # def passthru
15
- # super
16
- # end
17
-
18
- # GET|POST /users/auth/twitter/callback
19
- # def failure
20
- # super
21
- # end
22
-
23
- # protected
24
-
25
- # The path used when omniauth fails
26
- # def after_omniauth_failure_path_for(scope)
27
- # super(scope)
28
- # end
3
+ include MnoEnterprise::Concerns::Controllers::Auth::OmniauthCallbacksController
29
4
  end
30
- end
5
+ end
6
+
@@ -1,7 +1,5 @@
1
1
  module MnoEnterprise
2
2
  class Auth::SessionsController < Devise::SessionsController
3
3
  include MnoEnterprise::Concerns::Controllers::Auth::SessionsController
4
-
5
-
6
4
  end
7
- end
5
+ end
@@ -0,0 +1,26 @@
1
+ module MnoEnterprise
2
+ class Jpi::V1::Admin::AppAnswersController < Jpi::V1::Admin::BaseResourceController
3
+
4
+ # POST /mnoe/jpi/v1/admin/app_answers
5
+ def create
6
+ @app_review = MnoEnterprise::AppAnswer.new(app_answer_params)
7
+
8
+ if @app_review.save
9
+ render :show
10
+ else
11
+ render json: @app_review.errors, status: :bad_request
12
+ end
13
+ end
14
+
15
+ def app_answer_params
16
+ # for an admin, the organization does not matter
17
+ organization_id = current_user.organizations.first.id
18
+ params.require(:app_answer).permit(:description)
19
+ .merge(user_id: current_user.id, question_id: parent.id, organization_id: organization_id, app_id: parent.app_id)
20
+ end
21
+
22
+ def parent
23
+ @parent ||= MnoEnterprise::AppQuestion.find(params[:question_id])
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,28 @@
1
+ module MnoEnterprise
2
+ class Jpi::V1::Admin::AppCommentsController < Jpi::V1::Admin::BaseResourceController
3
+
4
+ # POST /mnoe/jpi/v1/admin/app_comments
5
+ def create
6
+ @app_review = MnoEnterprise::AppComment.new(app_comment_params)
7
+
8
+ if @app_review.save
9
+ render :show
10
+ else
11
+ render json: @app_review.errors, status: :bad_request
12
+ end
13
+ end
14
+
15
+ private
16
+
17
+ def app_comment_params
18
+ # for an admin, the organization does not matter
19
+ organization_id = current_user.organizations.first.id
20
+ params.require(:app_comment).permit(:description)
21
+ .merge(user_id: current_user.id, feedback_id: parent.id, organization_id: organization_id, app_id: parent.app_id)
22
+ end
23
+
24
+ def parent
25
+ @parent ||= MnoEnterprise::AppFeedback.find(params[:feedback_id])
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,16 @@
1
+ module MnoEnterprise
2
+ class Jpi::V1::Admin::AppInstancesController < Jpi::V1::Admin::BaseResourceController
3
+
4
+ # DELETE /mnoe/jpi/v1/app_instances/1
5
+ def destroy
6
+ app_instance = MnoEnterprise::AppInstance.find(params[:id])
7
+
8
+ if app_instance
9
+ MnoEnterprise::EventLogger.info('app_destroy', current_user.id, 'App destroyed', app_instance)
10
+ app_instance.terminate
11
+ end
12
+
13
+ head :accepted
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,30 @@
1
+ module MnoEnterprise
2
+ class Jpi::V1::Admin::AppReviewsController < Jpi::V1::Admin::BaseResourceController
3
+ # GET /mnoe/jpi/v1/admin/app_reviews
4
+ def index
5
+ @app_reviews = MnoEnterprise::AppReview
6
+ @app_reviews = @app_reviews.limit(params[:limit]) if params[:limit]
7
+ @app_reviews = @app_reviews.skip(params[:offset]) if params[:offset]
8
+ @app_reviews = @app_reviews.order_by(params[:order_by]) if params[:order_by]
9
+ @app_reviews = @app_reviews.where(params[:where]) if params[:where]
10
+ @app_reviews = @app_reviews.all.fetch
11
+ response.headers['X-Total-Count'] = @app_reviews.metadata[:pagination][:count]
12
+ end
13
+
14
+ # GET /mnoe/jpi/v1/admin/app_reviews/1
15
+ def show
16
+ @app_review = MnoEnterprise::AppReview.find(params[:id])
17
+ end
18
+
19
+ # PATCH /mnoe/jpi/v1/admin/app_reviews/1
20
+ def update
21
+ @app_review = MnoEnterprise::AppReview.find(params[:id])
22
+ @app_review.update(app_review_params)
23
+ render :show
24
+ end
25
+
26
+ def app_review_params
27
+ params.require(:app_review).permit(:status, :description).merge(user_id: current_user.id)
28
+ end
29
+ end
30
+ end
@@ -14,7 +14,7 @@ module MnoEnterprise::Jpi::V1::Admin
14
14
  send_org_invite(invite)
15
15
  end
16
16
 
17
- MnoEnterprise::EventLogger.info('user_invite', current_user.id, 'User invited', {user_email: user.email, account_name: @organization.name}, user)
17
+ MnoEnterprise::EventLogger.info('user_invite', current_user.id, 'User invited', user, {user_email: user.email, account_name: @organization.name})
18
18
 
19
19
  @user = user.confirmed? ? invite : user.reload
20
20
 
@@ -50,6 +50,18 @@ module MnoEnterprise
50
50
  render 'show'
51
51
  end
52
52
 
53
+ # PATCH /mnoe/jpi/v1/admin/organizations/1
54
+ def update
55
+ # get organization
56
+ @organization = MnoEnterprise::Organization.find(params[:id])
57
+
58
+ update_app_list
59
+
60
+ @organization_active_apps = @organization.app_instances.active
61
+
62
+ render 'show'
63
+ end
64
+
53
65
  # POST /mnoe/jpi/v1/admin/organizations/1/users
54
66
  # Invite a user to the organization (and create it if needed)
55
67
  # This does not send any emails (emails are manually triggered later)
@@ -62,60 +74,66 @@ module MnoEnterprise
62
74
 
63
75
  # Create the invitation
64
76
  invite = @organization.org_invites.create(
65
- user_email: user.email,
66
- user_role: params[:user][:role],
67
- referrer_id: current_user.id,
68
- status: 'staged' # Will be updated to 'accepted' for unconfirmed users
77
+ user_email: user.email,
78
+ user_role: params[:user][:role],
79
+ referrer_id: current_user.id,
80
+ status: 'staged' # Will be updated to 'accepted' for unconfirmed users
69
81
  )
70
82
 
71
83
  @user = user.confirmed? ? invite : user.reload
72
84
  end
73
85
 
74
86
  protected
75
- def organization_permitted_update_params
76
- [:name]
77
- end
78
87
 
79
- def organization_update_params
80
- params.fetch(:organization, {}).permit(*organization_permitted_update_params)
81
- end
88
+ def organization_permitted_update_params
89
+ [:name]
90
+ end
82
91
 
83
- def user_params
84
- params.require(:user).permit(:email, :name, :surname, :phone)
85
- end
92
+ def organization_update_params
93
+ params.fetch(:organization, {}).permit(*organization_permitted_update_params)
94
+ end
86
95
 
87
- # Create an unconfirmed user and skip the confirmation notification
88
- # TODO: monkey patch User#confirmation_required? to simplify this? Use refinements?
89
- def create_unconfirmed_user(user_params)
90
- user = MnoEnterprise::User.new(user_params)
91
- user.skip_confirmation_notification!
92
- user.save
93
-
94
- # Reset the confirmation field so we can track when the invite is send - #confirmation_sent_at is when the confirmation_token was generated (not sent)
95
- # Not ideal as we do 2 saves, and the previous save trigger a call to the backend to validate the token uniqueness
96
- user.assign_attributes(confirmation_sent_at: nil, confirmation_token: nil)
97
- user.save
98
- user
99
- end
96
+ def user_params
97
+ params.require(:user).permit(:email, :name, :surname, :phone)
98
+ end
99
+
100
+ # Create an unconfirmed user and skip the confirmation notification
101
+ # TODO: monkey patch User#confirmation_required? to simplify this? Use refinements?
102
+ def create_unconfirmed_user(user_params)
103
+ user = MnoEnterprise::User.new(user_params)
104
+ user.skip_confirmation_notification!
105
+ user.save
106
+
107
+ # Reset the confirmation field so we can track when the invite is send - #confirmation_sent_at is when the confirmation_token was generated (not sent)
108
+ # Not ideal as we do 2 saves, and the previous save trigger a call to the backend to validate the token uniqueness
109
+ user.assign_attributes(confirmation_sent_at: nil, confirmation_token: nil)
110
+ user.save
111
+ user
112
+ end
100
113
 
101
- # Update App List to match the list passed in params
102
- def update_app_list
103
- # Differentiate between a null app_nids params and no app_nids params
104
- if params[:organization].key?(:app_nids) && (desired_nids = Array(params[:organization][:app_nids]))
114
+ # Update App List to match the list passed in params
115
+ def update_app_list
116
+ # Differentiate between a null app_nids params and no app_nids params
117
+ if params[:organization].key?(:app_nids) && (desired_nids = Array(params[:organization][:app_nids]))
105
118
 
106
- existing_apps = @organization.app_instances.active
119
+ existing_apps = @organization.app_instances.active
107
120
 
108
- existing_apps.each do |app_instance|
109
- desired_nids.delete(app_instance.app.nid) || app_instance.terminate
110
- end
121
+ existing_apps.each do |app_instance|
122
+ desired_nids.delete(app_instance.app.nid) || app_instance.terminate
123
+ end
111
124
 
112
- desired_nids.each do |nid|
125
+ desired_nids.each do |nid|
126
+ begin
113
127
  @organization.app_instances.create(product: nid)
128
+ rescue => e
129
+ Rails.logger.error { "#{e.message} #{e.backtrace.join("\n")}" }
114
130
  end
115
131
 
116
- # Force reload
117
- existing_apps.reload
118
132
  end
133
+
134
+ # Force reload
135
+ existing_apps.reload
119
136
  end
137
+ end
120
138
  end
121
139
  end
@@ -0,0 +1,22 @@
1
+ module MnoEnterprise
2
+ class Jpi::V1::AppAnswersController < Jpi::V1::AppReviewsController
3
+
4
+ private
5
+
6
+ def scope_app_reviews
7
+ @app_reviews.where(question_id: params[:question_id])
8
+ end
9
+
10
+ def after_save
11
+ #do nothing because answers doesn't affect on app rating
12
+ end
13
+
14
+ def review_klass
15
+ MnoEnterprise::AppAnswer
16
+ end
17
+
18
+ def permitted_params
19
+ params.require(:app_answer).permit(:rating, :description, :organization_id, :question_id)
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,22 @@
1
+ module MnoEnterprise
2
+ class Jpi::V1::AppCommentsController < Jpi::V1::AppReviewsController
3
+
4
+ private
5
+
6
+ def scope_app_reviews
7
+ @app_reviews.where(feedback_id: params[:feedback_id])
8
+ end
9
+
10
+ def after_save
11
+ #do nothing because comments doesn't affect on app rating
12
+ end
13
+
14
+ def review_klass
15
+ MnoEnterprise::AppComment
16
+ end
17
+
18
+ def permitted_params
19
+ params.require(:app_comment).permit(:description, :organization_id, :feedback_id)
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,14 @@
1
+ module MnoEnterprise
2
+ class Jpi::V1::AppFeedbacksController < Jpi::V1::AppReviewsController
3
+
4
+ private
5
+
6
+ def permitted_params
7
+ params.require(:app_feedback).permit(:rating, :description, :organization_id)
8
+ end
9
+
10
+ def review_klass
11
+ MnoEnterprise::AppFeedback
12
+ end
13
+ end
14
+ end
@@ -1,24 +1,5 @@
1
1
  module MnoEnterprise
2
2
  class Jpi::V1::AppInstancesController < Jpi::V1::BaseResourceController
3
-
4
- # GET /mnoe/jpi/v1/organization/1/apps.json?timestamp=151452452345
5
- def index
6
- @app_instances = parent_organization.app_instances.select do |i|
7
- i.active? && i.updated_at > Time.at(timestamp) && can?(:access,i)
8
- end
9
- end
10
-
11
- # DELETE /mnoe/jpi/v1/app_instances/1
12
- def destroy
13
- app_instance = MnoEnterprise::AppInstance.find(params[:id])
14
-
15
- if app_instance
16
- authorize! :manage_app_instances, app_instance.owner
17
- MnoEnterprise::EventLogger.info('app_destroy', current_user.id, "App destroyed", app_instance.name,app_instance)
18
- app_instance.terminate
19
- end
20
-
21
- head :accepted
22
- end
3
+ include MnoEnterprise::Concerns::Controllers::Jpi::V1::AppInstancesController
23
4
  end
24
5
  end
@@ -0,0 +1,25 @@
1
+ module MnoEnterprise
2
+ class Jpi::V1::AppQuestionsController < Jpi::V1::AppReviewsController
3
+
4
+ private
5
+
6
+ def scope_app_reviews
7
+ collection = @app_reviews.where(reviewable_id: current_app.id)
8
+ collection = collection.search(params[:search]) if params[:search].present?
9
+
10
+ collection
11
+ end
12
+
13
+ def after_save
14
+ #do nothing because questions doesn't affect on app rating
15
+ end
16
+
17
+ def permitted_params
18
+ params.require(:app_question).permit(:description, :organization_id)
19
+ end
20
+
21
+ def review_klass
22
+ MnoEnterprise::AppQuestion
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,94 @@
1
+ module MnoEnterprise
2
+ class Jpi::V1::AppReviewsController < Jpi::V1::BaseResourceController
3
+ before_action :ensure_app_exists
4
+ before_action :find_review, only: [:update, :destroy]
5
+
6
+ # GET /mnoe/jpi/v1/marketplace/:id/app_reviews
7
+ def index
8
+ @app_reviews = review_klass.approved
9
+ @app_reviews = @app_reviews.limit(params[:limit]) if params[:limit]
10
+ @app_reviews = @app_reviews.skip(params[:offset]) if params[:offset]
11
+ @app_reviews = @app_reviews.order_by(params[:order_by]) if params[:order_by]
12
+ @app_reviews = @app_reviews.where(params[:where]) if params[:where]
13
+
14
+ @app_reviews = scope_app_reviews
15
+
16
+ @app_reviews = @app_reviews.all.fetch
17
+ response.headers['X-Total-Count'] = @app_reviews.metadata[:pagination][:count]
18
+ end
19
+
20
+ # POST /mnoe/jpi/v1/marketplace/:id/app_reviews/:id
21
+ def show
22
+ @app_review = review_klass.find(params[:review_id])
23
+ end
24
+
25
+ # POST /mnoe/jpi/v1/marketplace/:id/app_reviews
26
+ def create
27
+ # TODO: use the has_many associations -> @app.reviews.build
28
+ @app_review = review_klass.new(review_params)
29
+ if @app_review.save
30
+ after_save
31
+ render :show
32
+ else
33
+ render json: @app_review.errors, status: :bad_request
34
+ end
35
+ end
36
+
37
+ def update
38
+ if @app_review.update(permitted_params)
39
+ after_save
40
+ render :show
41
+ else
42
+ render json: @app_review.errors, status: :bad_request
43
+ end
44
+ end
45
+
46
+ def destroy
47
+ @app_review.destroy
48
+ after_save
49
+
50
+ render :show
51
+ end
52
+
53
+ private
54
+
55
+ # scope the app_reviews for the children controller
56
+ # may be overriden
57
+ def scope_app_reviews
58
+ @app_reviews.where(reviewable_id: current_app.id)
59
+ end
60
+
61
+ # perform some additional actions if new review was created
62
+ # may be overriden
63
+ def after_save
64
+ @average_rating = current_app.reload.average_rating
65
+ end
66
+
67
+ def current_app
68
+ @app ||= MnoEnterprise::App.find(params[:id])
69
+ end
70
+
71
+ def ensure_app_exists
72
+ render_not_found('App') unless current_app.present?
73
+ end
74
+
75
+ def find_review
76
+ @app_review = review_klass.find(params[:review_id])
77
+ unless @app_review.user_id == current_user.id
78
+ return render json:{ errors: {message: "Review not found (id=#{params[:review_id]})", code: 404} }, status: :not_found
79
+ end
80
+ end
81
+
82
+ def review_klass
83
+ MnoEnterprise::AppReview
84
+ end
85
+
86
+ def permitted_params
87
+ params.require(:app_review).permit(:rating, :description, :organization_id)
88
+ end
89
+
90
+ def review_params
91
+ permitted_params.merge(app_id: current_app.id, user_id: current_user.id)
92
+ end
93
+ end
94
+ end