From 4cb1363d9240f238416f25cdeddfb0b4e01905a4 Mon Sep 17 00:00:00 2001 From: Rodrigo Souto Date: Mon, 15 Jun 2015 20:17:32 -0300 Subject: [PATCH] api: expose plugin endpoints only if enabled on the environment --- app/controllers/public/api_controller.rb | 10 ++++++++-- app/views/api/index.html.erb | 2 +- app/views/api/playground.html.erb | 2 +- lib/noosfero/api/api.rb | 23 ++++++++++++++++++++--- lib/noosfero/api/helpers.rb | 8 ++++++++ test/unit/api/api_test.rb | 29 +++++++++++++++++++++++++++++ test/unit/api/helpers_test.rb | 7 +++++++ 7 files changed, 74 insertions(+), 7 deletions(-) create mode 100644 test/unit/api/api_test.rb diff --git a/app/controllers/public/api_controller.rb b/app/controllers/public/api_controller.rb index b7fffcd..cb1404f 100644 --- a/app/controllers/public/api_controller.rb +++ b/app/controllers/public/api_controller.rb @@ -2,12 +2,18 @@ class ApiController < PublicController no_design_blocks + helper_method :endpoints + def index - @api = Noosfero::API.api_class end def playground - @api = Noosfero::API.api_class + end + + private + + def endpoints + Noosfero::API::API.endpoints(environment) end end diff --git a/app/views/api/index.html.erb b/app/views/api/index.html.erb index bdce7c3..3e2e27d 100644 --- a/app/views/api/index.html.erb +++ b/app/views/api/index.html.erb @@ -4,7 +4,7 @@ <%= s_('api-playground|Try the %s') % link_to('API Playground', '/api/playground') %> -<%= @api.endpoints.map do |endpoint| +<%= endpoints.map do |endpoint| app = endpoint.options[:app].to_s unless app.blank? content_tag(:h2, app.split('::').last.to_s, title: app) + diff --git a/app/views/api/playground.html.erb b/app/views/api/playground.html.erb index c953da6..1d0cc57 100644 --- a/app/views/api/playground.html.erb +++ b/app/views/api/playground.html.erb @@ -2,7 +2,7 @@