diff --git a/app/jobs/connect_app_job.rb b/app/jobs/connect_app_job.rb index a93d0b4001..9645ebd7d5 100644 --- a/app/jobs/connect_app_job.rb +++ b/app/jobs/connect_app_job.rb @@ -20,7 +20,7 @@ class ConnectAppJob < ApplicationJob selector = "#connected-app-discover-regen.enterprise_#{enterprise.id}" html = ApplicationController.render( partial: "admin/enterprises/form/connected_apps/discover_regen", - locals: { enterprise: }, + locals: { enterprise:, connected_app: enterprise.connected_apps.first}, ) cable_ready[channel].morph(selector:, html:).broadcast diff --git a/app/models/connected_app.rb b/app/models/connected_app.rb index 3edc7c4147..71d5908740 100644 --- a/app/models/connected_app.rb +++ b/app/models/connected_app.rb @@ -6,6 +6,11 @@ class ConnectedApp < ApplicationRecord belongs_to :enterprise - scope :connecting, -> { where(data: nil) } - scope :ready, -> { where.not(data: nil) } + def connecting? + data.nil? + end + + def ready? + !connecting? + end end diff --git a/app/views/admin/enterprises/form/_connected_apps.html.haml b/app/views/admin/enterprises/form/_connected_apps.html.haml index b0f8f608b3..5aac9c29c4 100644 --- a/app/views/admin/enterprises/form/_connected_apps.html.haml +++ b/app/views/admin/enterprises/form/_connected_apps.html.haml @@ -1 +1,2 @@ -= render partial: "/admin/enterprises/form/connected_apps/discover_regen", locals: { enterprise: } += render partial: "/admin/enterprises/form/connected_apps/discover_regen", + locals: { enterprise:, connected_app: enterprise.connected_apps.first } diff --git a/app/views/admin/enterprises/form/connected_apps/_discover_regen.html.haml b/app/views/admin/enterprises/form/connected_apps/_discover_regen.html.haml index 2ffbceee81..2b6ef45851 100644 --- a/app/views/admin/enterprises/form/connected_apps/_discover_regen.html.haml +++ b/app/views/admin/enterprises/form/connected_apps/_discover_regen.html.haml @@ -4,11 +4,11 @@ %h3= t ".title" %p= t ".tagline" %div - - if enterprise.connected_apps.empty? + - if connected_app.nil? = button_to t(".enable"), admin_enterprise_connected_apps_path(enterprise.id), method: :post, disabled: !managed_by_user?(enterprise) -# This is only seen by super-admins: %em= t(".need_to_be_manager") unless managed_by_user?(enterprise) - - elsif enterprise.connected_apps.connecting.present? + - elsif connected_app&.connecting? %button{ disabled: true } %i.spinner.fa.fa-spin.fa-circle-o-notch   @@ -17,9 +17,9 @@ = button_to t(".disable"), admin_enterprise_connected_app_path(0, enterprise_id: enterprise.id), method: :delete .connected-app__connection - - if enterprise.connected_apps.ready.present? + - if connected_app&.ready? .connected-app__note - - link = enterprise.connected_apps[0].data["link"] + - link = connected_app.data["link"] %p= t ".note" %div %a{ href: link, target: "_blank", class: "button secondary" }