Merge pull request #2962 from evazion/fix-services-not-implemented
Fail gracefully when attempting to use unconfigured features (#2954)
This commit is contained in:
@@ -84,6 +84,13 @@ class ApplicationController < ActionController::Base
|
||||
elsif exception.is_a?(::ActiveRecord::RecordNotFound)
|
||||
@error_message = "That record was not found"
|
||||
render :template => "static/error", :status => 404
|
||||
elsif exception.is_a?(NotImplementedError)
|
||||
flash[:notice] = "This feature isn't available: #{@exception.message}"
|
||||
respond_to do |fmt|
|
||||
fmt.html { redirect_to :back }
|
||||
fmt.json { render template: "static/error", status: 501 }
|
||||
fmt.xml { render template: "static/error", status: 501 }
|
||||
end
|
||||
else
|
||||
render :template => "static/error", :status => 500
|
||||
end
|
||||
|
||||
@@ -1,25 +0,0 @@
|
||||
module SavedSearches
|
||||
module CheckAvailability
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
included do
|
||||
before_filter :check_availability
|
||||
end
|
||||
|
||||
def check_availability
|
||||
if !SavedSearch.enabled?
|
||||
respond_to do |format|
|
||||
format.html do
|
||||
flash[:notice] = "Listbooru service is not configured. Saved searches are not available."
|
||||
redirect_to :back
|
||||
end
|
||||
format.json do
|
||||
render json: {success: false, reason: "Listbooru service is not configured"}.to_json, status: 501
|
||||
end
|
||||
end
|
||||
|
||||
return false
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -4,8 +4,7 @@ class IqdbQueriesController < ApplicationController
|
||||
|
||||
def create
|
||||
if !Danbooru.config.iqdbs_server
|
||||
render :nothing => true
|
||||
return
|
||||
raise NotImplementedError.new("the IQDBs service isn't configured. Similarity searches are not available.")
|
||||
end
|
||||
|
||||
if params[:url]
|
||||
@@ -32,4 +31,4 @@ protected
|
||||
@results = @download.matches
|
||||
render :layout => false, :action => "create_by_post"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -29,17 +29,7 @@ private
|
||||
|
||||
def check_availabililty
|
||||
if !PoolArchive.enabled?
|
||||
respond_to do |format|
|
||||
format.html do
|
||||
flash[:notice] = "Archive service is not configured. Pool versions are not saved."
|
||||
redirect_to :back
|
||||
end
|
||||
format.json do
|
||||
render json: {success: false, reason: "Archive service is not configured"}.to_json, status: 501
|
||||
end
|
||||
end
|
||||
|
||||
return false
|
||||
raise NotImplementedError.new("Archive service is not configured. Pool versions are not saved.")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
class PostVersionsController < ApplicationController
|
||||
before_filter :member_only
|
||||
before_filter :check_availabililty
|
||||
respond_to :html, :xml, :json
|
||||
|
||||
def index
|
||||
@@ -25,4 +26,12 @@ class PostVersionsController < ApplicationController
|
||||
format.js
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def check_availabililty
|
||||
if !PostArchive.enabled?
|
||||
raise NotImplementedError.new("Archive service is not configured. Post versions are not saved.")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
class SavedSearchesController < ApplicationController
|
||||
include SavedSearches::CheckAvailability
|
||||
|
||||
before_filter :member_only
|
||||
before_filter :check_availability
|
||||
respond_to :html, :xml, :json, :js
|
||||
|
||||
def index
|
||||
@@ -56,4 +55,10 @@ private
|
||||
def saved_searches
|
||||
CurrentUser.user.saved_searches
|
||||
end
|
||||
|
||||
def check_availability
|
||||
if !SavedSearch.enabled?
|
||||
raise NotImplementedError.new("Listbooru service is not configured. Saved searches are not available.")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -2,6 +2,14 @@ require "big_query"
|
||||
|
||||
module GoogleBigQuery
|
||||
class Base
|
||||
def self.enabled?
|
||||
File.exists?(Danbooru.config.google_api_json_key_path)
|
||||
end
|
||||
|
||||
def initialize
|
||||
raise NotImplementedError.new("Google Big Query is not configured.") unless GoogleBigQuery::Base.enabled?
|
||||
end
|
||||
|
||||
def query(q)
|
||||
client.query(q)
|
||||
end
|
||||
|
||||
@@ -1,5 +1,15 @@
|
||||
# queries reportbooru to find missed post searches
|
||||
class MissedSearchService
|
||||
def self.enabled?
|
||||
Danbooru.config.reportbooru_server.present?
|
||||
end
|
||||
|
||||
def initialize
|
||||
if !MissedSearchService.enabled?
|
||||
raise NotImplementedError.new("the Reportbooru service isn't configured. Missed searches are not available.")
|
||||
end
|
||||
end
|
||||
|
||||
def each_search(&block)
|
||||
fetch_data.scan(/(.+?) (\d+)\.0\n/).each(&block)
|
||||
end
|
||||
|
||||
@@ -2,7 +2,15 @@
|
||||
class PopularSearchService
|
||||
attr_reader :date, :scale
|
||||
|
||||
def self.enabled?
|
||||
Danbooru.config.reportbooru_server.present?
|
||||
end
|
||||
|
||||
def initialize(date, scale)
|
||||
if !PopularSearchService.enabled?
|
||||
raise NotImplementedError.new("the Reportbooru service isn't configured. Popular searches are not available.")
|
||||
end
|
||||
|
||||
@date = date
|
||||
@scale = scale
|
||||
end
|
||||
|
||||
@@ -24,7 +24,7 @@ module Reports
|
||||
end
|
||||
|
||||
def fetch_similar_user_ids(endpoint = "user_similarity")
|
||||
return NotImplementedError unless Danbooru.config.reportbooru_server
|
||||
raise NotImplementedError.new("the Reportbooru service isn't configured. User similarity is not available.") unless Danbooru.config.reportbooru_server
|
||||
|
||||
params = {
|
||||
"key" => Danbooru.config.reportbooru_key,
|
||||
|
||||
@@ -43,7 +43,7 @@ class PoolArchive < ActiveRecord::Base
|
||||
def self.queue(pool)
|
||||
# queue updates to sqs so that if archives goes down for whatever reason it won't
|
||||
# block pool updates
|
||||
raise "Archive service is not configured" if !enabled?
|
||||
raise NotImplementedError.new("Archive service is not configured.") if !enabled?
|
||||
|
||||
json = {
|
||||
pool_id: pool.id,
|
||||
|
||||
@@ -35,7 +35,7 @@ class PoolVersion < ActiveRecord::Base
|
||||
extend SearchMethods
|
||||
|
||||
def self.export_to_archives(starting_version_id = 0)
|
||||
raise "SQS URL not setup" if Danbooru.config.aws_sqs_archives_url.nil?
|
||||
raise NotImplementedError.new("SQS URL not setup") if Danbooru.config.aws_sqs_archives_url.nil?
|
||||
|
||||
credentials = Aws::Credentials.new(
|
||||
Danbooru.config.aws_access_key_id,
|
||||
|
||||
@@ -60,7 +60,7 @@ class PostArchive < ActiveRecord::Base
|
||||
def queue(post)
|
||||
# queue updates to sqs so that if archives goes down for whatever reason it won't
|
||||
# block post updates
|
||||
raise "Archive service is not configured" if !enabled?
|
||||
raise NotImplementedError.new("Archive service is not configured") if !enabled?
|
||||
|
||||
json = {
|
||||
"post_id" => post.id,
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<li id="secondary-links-posts-upload" class="nonessential"><%= link_to "Upload", new_upload_path %></li>
|
||||
<li id="secondary-links-posts-popular"><%= link_to "Popular", popular_explore_posts_path %></li>
|
||||
<li id="secondary-links-posts-hot"><%= link_to "Hot", posts_path(:tags => "order:rank") %></li>
|
||||
<% if Danbooru.config.reportbooru_server %>
|
||||
<% if PopularSearchService.enabled? %>
|
||||
<li id="secondary-links-posts-searches"><%= link_to "Searches", searches_explore_posts_path %></li>
|
||||
<% end %>
|
||||
<% unless CurrentUser.is_anonymous? %>
|
||||
|
||||
Reference in New Issue
Block a user