-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor controllers into base and admin namespaces
- Loading branch information
Showing
58 changed files
with
2,096 additions
and
2,215 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
module Admin | ||
module Authenticatable | ||
|
||
extend ActiveSupport::Concern | ||
|
||
included do | ||
before_action :require_admin | ||
end | ||
|
||
private | ||
|
||
def require_admin | ||
require_authentication | ||
if current_user && !current_user.admin? | ||
render json: { errors: 'Forbidden' }, status: :forbidden | ||
end | ||
end | ||
|
||
# In admin section, a user MUST be authenticated by a REMOTE_USER header | ||
def fetch_current_user | ||
User.from_remote(*remote_user_params) | ||
end | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 5 additions & 5 deletions
10
...rollers/v1/playback_formats_controller.rb → ...lers/admin/playback_formats_controller.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 5 additions & 5 deletions
10
app/controllers/v1/profiles_controller.rb → app/controllers/admin/profiles_controller.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
module Admin | ||
class ShowsController < CrudController | ||
|
||
include Admin::Authenticatable | ||
|
||
self.search_columns = %w(name details) | ||
|
||
crud_swagger_paths(route_prefix: '/admin', | ||
data_class: 'Admin::Show', | ||
tags: [:admin]) | ||
|
||
private | ||
|
||
def fetch_entries | ||
super.includes(:profile) | ||
end | ||
|
||
# Only allow a trusted parameter "white list" through. | ||
def model_params | ||
attrs = nested_param(:data, :attributes) || ActionController::Parameters.new | ||
profile_id = nested_param(:data, :relationships, :profile, :data, :id) | ||
attrs[:profile_id] = profile_id if profile_id | ||
attrs.permit(:name, :details, :profile_id) | ||
end | ||
|
||
def nested_param(*keys) | ||
value = params | ||
keys.each { |key| value = value[key] if value } | ||
value | ||
end | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
module Admin | ||
class UsersController < CrudController | ||
|
||
include Admin::Authenticatable | ||
|
||
self.permitted_attrs = [:username, :first_name, :last_name, :groups] | ||
|
||
self.search_columns = %w(username first_name last_name) | ||
|
||
crud_swagger_paths(route_prefix: '/admin', | ||
data_class: 'Admin::User', | ||
tags: [:admin], | ||
query_params: [:q]) | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
class ApidocsController < ApplicationController | ||
|
||
# A list of all classes that have swagger_* declarations. | ||
SWAGGERED_CLASSES = [ | ||
# paths | ||
self, | ||
AudioFilesController, | ||
BroadcastsController, | ||
LoginController, | ||
ShowsController, | ||
Admin::ArchiveFormatsController, | ||
Admin::AudioEncodingsController, | ||
Admin::DowngradeActionsController, | ||
Admin::PlaybackFormatsController, | ||
Admin::ProfilesController, | ||
Admin::ShowsController, | ||
Admin::UsersController, | ||
# entities | ||
AudioFileSerializer, | ||
BroadcastSerializer, | ||
ShowSerializer, | ||
UnprocessableEntitySerializer, | ||
UserSerializer, | ||
Admin::ArchiveFormatSerializer, | ||
Admin::AudioEncodingSerializer, | ||
Admin::DowngradeActionSerializer, | ||
Admin::PlaybackFormatSerializer, | ||
Admin::ProfileSerializer, | ||
Admin::ShowSerializer, | ||
Admin::UserSerializer | ||
].freeze | ||
|
||
swagger_root do | ||
key :swagger, '2.0' | ||
info do | ||
key :version, '1.0' | ||
key :title, 'RAAR Radio Archive API' | ||
key :description, | ||
'RAAR Radio Archive API. ' \ | ||
'Some endpoints are public, other are restricted to admins.' | ||
license name: 'AGPL' | ||
end | ||
key :consumes, ['application/vnd.api+json'] | ||
key :produces, ['application/vnd.api+json'] | ||
|
||
security_definition :http_token do | ||
key :type, :basic | ||
key :description, | ||
'API token is passed as HTTP token authentication header: ' \ | ||
'`Authorization: Token token="abc"`' | ||
end | ||
security_definition :api_token do | ||
key :type, :apiKey | ||
key :name, :api_token | ||
key :in, :query | ||
key :description, 'API token is passed as a query parameter' | ||
end | ||
|
||
response :unprocessable_entity do | ||
key :description, 'unprocessable entity' | ||
schema do | ||
property :errors, type: :array do | ||
items '$ref' => 'UnprocessableEntity' | ||
end | ||
end | ||
end | ||
|
||
parameter :page_number do | ||
key :name, 'page[number]' | ||
key :in, :query | ||
key :description, 'The page number of the list.' | ||
key :required, false | ||
key :type, :integer | ||
end | ||
|
||
parameter :page_size do | ||
key :name, 'page[size]' | ||
key :in, :query | ||
key :description, | ||
'Maximum number of entries that are returned per page. Defaults to 50, maximum is 500.' | ||
key :required, false | ||
key :type, :integer | ||
end | ||
|
||
parameter :sort do | ||
key :name, 'sort' | ||
key :in, :query | ||
key :description, | ||
'Name of the sort field, optionally prefixed with a `-` for descending order.' | ||
key :required, false | ||
key :type, :string | ||
end | ||
|
||
parameter :q do | ||
key :name, :q | ||
key :in, :query | ||
key :description, 'Query string to search for.' | ||
key :required, false | ||
key :type, :string | ||
end | ||
end | ||
|
||
def index | ||
render json: root_json | ||
end | ||
|
||
private | ||
|
||
def root_json | ||
Swagger::Blocks.build_root_json(SWAGGERED_CLASSES).merge(host_info) | ||
end | ||
|
||
def host_info | ||
secrets = Rails.application.secrets | ||
{}.tap do |hash| | ||
hash['host'] = secrets.host_name if secrets.host_name.present? | ||
hash['basePath'] = secrets.base_path if secrets.base_path.present? | ||
end | ||
end | ||
|
||
end |
Oops, something went wrong.