Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -265,3 +265,7 @@ Naming/RescuedExceptionsVariableName:

Rails/RakeEnvironment:
Enabled: false

Rails/TimeZone:
Exclude:
- 'test/**/*'
Comment thread
josemigallas marked this conversation as resolved.
Outdated
165 changes: 0 additions & 165 deletions app/assets/stylesheets/provider/_services.scss

This file was deleted.

1 change: 0 additions & 1 deletion app/assets/stylesheets/provider/_theme.scss
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
@forward 'provider/buttons';
@forward 'provider/links';
@forward 'provider/footer';
@forward 'provider/services';
@forward 'provider/plans';
@forward 'provider/tables';
@forward 'provider/utilization';
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.pf-c-card {
/* Custom class. PF4 don't offer md sized icons in pf-list */
.pf-c-list.pf-m-icon-md {
--pf-c-list__item-icon--FontSize: var(--pf-c-card__body--FontSize);
}
}
7 changes: 2 additions & 5 deletions app/controllers/api/services_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class Api::ServicesController < Api::BaseController

load_and_authorize_resource :service, through: :current_user, through_association: :accessible_services, except: [:create]

decorates_assigned :service
helper_method :presenter

def index
Expand All @@ -25,9 +26,7 @@ def index
end
end

def show
@service = @service.decorate
end
def show; end

def new
activate_menu :products
Expand Down Expand Up @@ -87,8 +86,6 @@ def destroy

private

attr_reader :service

def integration_settings_updater_service
ApiIntegration::SettingsUpdaterService.new(service: service, proxy: service.proxy)
end
Expand Down
24 changes: 24 additions & 0 deletions app/decorators/alert_decorator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# frozen_string_literal: true

class AlertDecorator < ApplicationDecorator
def icon
variant = case utilization_range
when 50 then :info
when 80, 90 then :warning
else :danger
end
h.pf_alert_icon variant, colored: true
end

def link_to_app
if cinstance
h.link_to(cinstance.name, h.provider_admin_application_path(cinstance))
else
h.tag.span '(deleted app)'
end
end

def utilization_range
@utilization_range ||= h.utilization_range(level)
end
end
52 changes: 52 additions & 0 deletions app/decorators/service_decorator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,58 @@ def as_json(options = {})
super.deep_transform_keys { |key| key.to_s.camelize(:lower).to_sym }
end

def top_metrics
@top_metrics ||= metrics.top_level.limit(5)
end

def refresh_service_discovery_link
url = service_discovery_usable? ? h.provider_admin_service_discovery_service_path(self) : service_discovery_presenter.authorize_url
Comment thread
josemigallas marked this conversation as resolved.
Outdated

confirm = t('.refresh_service.confirm', name: name)
label = t('.refresh_service.label')
Comment thread
josemigallas marked this conversation as resolved.
Outdated
action_link_to(:refresh, url, label:,
Comment thread
josemigallas marked this conversation as resolved.
Outdated
data: { confirm: },
method: :put)
end

def latest_alerts
@latest_alerts ||= account.alerts.by_service(self).latest.decorate
end

def latest_applications
@latest_applications ||= cinstances.latest
end

def traffic?
cinstances.where.not(first_traffic_at: nil).exists?
end

def human_backend
{
"1" => "API key",
"2" => "App Id",
"oauth" => "OAuth",
"oidc" => "OpenID Connect"
}[service.proxy_authentication_method]
end

# :reek:NilCheck
def friendly_service_settings
%i[buyers_manage_keys buyers_manage_apps buyer_plan_change_permission buyer_can_select_plan].map do |setting|
value = object.send(setting)
next if value.nil?

subkey = case setting
when :buyer_plan_change_permission
value.to_sym
else
value ? :enabled : :disabled
end

I18n.t("api.services.cards.settings.friendly_service_setting.#{setting}.#{subkey}").html_safe
end.compact
end

private

def backend_api?
Expand Down
48 changes: 0 additions & 48 deletions app/helpers/api/services_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,56 +4,8 @@ def link_to_service service
link_to service.name, admin_service_path(service)
end

def list_items_or_empty collection, empty_message, &block
if collection.empty?
content_tag(:li, empty_message, :class => 'item empty')
else
collection.each do |item|
yield(item)
end
nil
end
end

def friendly_service_setting service, setting
value = service.send setting
message, value = case setting
when :custom_keys_enabled
['Custom application keys are VALUE', value ? 'enabled' : 'disabled']
when :buyers_manage_keys
['Users VALUE manage application keys', value ? 'can' : "cannot"]
when :buyer_can_select_plan
['Users VALUE when creating an application', value ? 'can select a plan' : "cannot select a plan"]
when :buyer_plan_change_permission
value = case value.to_sym
when :request
"request plan change"
when :direct
"directly change plans"
when :none
"not change plans"
end
['Users can VALUE', value]
when :buyers_manage_apps
['Users VALUE manage applications', value ? 'can' : "can't"]
else
["Setting #{setting} - VALUE", value]
end

return unless message && value

message.gsub('VALUE', content_tag(:strong, value)).html_safe
end

def delete_service_link(service, options = {})
msg = t('api.services.forms.definition_settings.delete_confirmation', name: j(service.name))
delete_link_for(admin_service_path(service), {data: { confirm: msg }, class: 'pf-c-button pf-m-danger', method: :delete}.merge(options) )
end

def refresh_service_link(service, options = {})
url = service_discovery_usable? ? provider_admin_service_discovery_service_path(service) : service_discovery_presenter.authorize_url

msg = t('api.services.forms.definition_settings.refresh_confirmation', name: h(service.name))
action_link_to(:refresh, url, {data: { confirm: msg }, method: :put}.merge(options) )
end
end
8 changes: 0 additions & 8 deletions app/helpers/buyers/cinstances_helper.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,4 @@
module Buyers::CinstancesHelper
def link_to_cinstance_or_deleted(cinstance)
if cinstance
link_to(cinstance.name, provider_admin_application_path(cinstance))
else
content_tag(:span, '(deleted app)', :class => 'deleted')
end
end

def link_to_plan_edit(plan)
if can?(:manage, :plans)
link_to(plan.name, edit_polymorphic_path([:admin, plan]))
Expand Down
Loading