moves the admin api inside of the /admin namespace

This commit is contained in:
kikito
2015-09-24 12:11:51 +02:00
parent 471b14835e
commit adc8275f5a
6 changed files with 12 additions and 20 deletions

View File

@@ -0,0 +1,3 @@
class Admin::Api::BaseController < Admin::BaseController
protect_from_forgery with: :null_session
end

View File

@@ -1,4 +1,4 @@
class Api::StatsController < Api::ApiController class Admin::Api::StatsController < Admin::Api::BaseController
def show def show
unless params[:events].present? || params[:visits].present? unless params[:events].present? || params[:visits].present?

View File

@@ -1,13 +0,0 @@
class Api::ApiController < ApplicationController
before_action :authenticate_user!
protect_from_forgery with: :null_session
skip_authorization_check
before_action :verify_administrator
private
def verify_administrator
raise CanCan::AccessDenied unless current_user.try(:administrator?)
end
end

View File

@@ -3,14 +3,14 @@ module StatsHelper
def events_chart_tag(events, opt={}) def events_chart_tag(events, opt={})
events = events.join(',') if events.is_a? Array events = events.join(',') if events.is_a? Array
opt[:data] ||= {} opt[:data] ||= {}
opt[:data][:graph] = api_stats_path(events: events) opt[:data][:graph] = admin_api_stats_path(events: events)
content_tag :div, "", opt content_tag :div, "", opt
end end
def visits_chart_tag(opt={}) def visits_chart_tag(opt={})
events = events.join(',') if events.is_a? Array events = events.join(',') if events.is_a? Array
opt[:data] ||= {} opt[:data] ||= {}
opt[:data][:graph] = api_stats_path(visits: true) opt[:data][:graph] = admin_api_stats_path(visits: true)
content_tag :div, "", opt content_tag :div, "", opt
end end

View File

@@ -115,6 +115,10 @@ Rails.application.routes.draw do
resource :activity, controller: :activity, only: :show resource :activity, controller: :activity, only: :show
resource :stats, only: :show resource :stats, only: :show
namespace :api do
resource :stats, only: :show
end
end end
namespace :moderation do namespace :moderation do
@@ -155,9 +159,7 @@ Rails.application.routes.draw do
end end
end end
namespace :api do
resource :stats, only: [:show]
end
# Example of regular route: # Example of regular route:
# get 'products/:id' => 'catalog#view' # get 'products/:id' => 'catalog#view'

View File

@@ -1,6 +1,6 @@
require 'rails_helper' require 'rails_helper'
describe Api::StatsController do describe Admin::Api::StatsController do
describe 'GET index' do describe 'GET index' do
let(:user) { create(:administrator).user } let(:user) { create(:administrator).user }