Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
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
10 changes: 10 additions & 0 deletions app/assets/stylesheets/provider/admin/apiconfig/services/show.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
.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);
}

.pf-c-list li a:first-child {
font-weight: var(--pf-global--FontWeight--bold);
}
}
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
4 changes: 4 additions & 0 deletions app/decorators/plan_base_decorator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,8 @@ def index_table_actions
def contracts_path
raise NoMethodError, "#{__method__} not implemented in #{self.class}"
end

def link_to_edit
raise NoMethodError, "#{__method__} not implemented in #{self.class}"
end
end
56 changes: 56 additions & 0 deletions app/decorators/service_decorator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ def published_application_plans
ApplicationPlanDecorator.decorate_collection(application_plans.stock.published, context: { service: self })
end

def published_service_plans
ServicePlanDecorator.decorate_collection(service_plans.published)
end

def service_path
if h.can?(:manage, :plans)
h.admin_service_path(object)
Expand Down Expand Up @@ -76,6 +80,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 = h.service_discovery_usable? ? h.provider_admin_service_discovery_service_path(self) : h.service_discovery_presenter.authorize_url

confirm = I18n.t('api.services.forms.definition_settings.refresh.confirmation', name: name)
label = I18n.t('api.services.forms.definition_settings.refresh.label')
h.action_link_to(:refresh, url, label:,
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
8 changes: 8 additions & 0 deletions app/decorators/service_plan_decorator.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
# frozen_string_literal: true

class ServicePlanDecorator < PlanBaseDecorator
def link_to_edit
h.link_to(name, h.edit_admin_service_plan_path(self))
end

def total_contracts
I18n.t('api.services.cards.service_plans.contracts', count: contracts.size)
end

private

def contracts_path
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
Loading