summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
Diffstat (limited to 'app')
-rw-r--r--app/controllers/controller_extension/authentication.rb23
-rw-r--r--app/controllers/controller_extension/errors.rb34
-rw-r--r--app/controllers/controller_extension/json_file.rb1
-rw-r--r--app/controllers/controller_extension/token_authentication.rb2
-rw-r--r--app/controllers/v1/configs_controller.rb2
5 files changed, 38 insertions, 24 deletions
diff --git a/app/controllers/controller_extension/authentication.rb b/app/controllers/controller_extension/authentication.rb
index 687bc6e..e2b24f0 100644
--- a/app/controllers/controller_extension/authentication.rb
+++ b/app/controllers/controller_extension/authentication.rb
@@ -26,29 +26,6 @@ module ControllerExtension::Authentication
redirect_to home_url if logged_in?
end
- def access_denied
- respond_to_error :not_authorized, :forbidden, home_url
- end
-
- def login_required
- # Warden will intercept the 401 response and call
- # SessionController#unauthenticated instead.
- respond_to_error :not_authorized_login, :unauthorized, login_url
- end
-
- def respond_to_error(message, status=nil, redirect=nil)
- message = t(message) if message.is_a?(Symbol)
- respond_to do |format|
- format.html do
- redirect_to redirect, alert: message
- end
- format.json do
- status ||= :unprocessable_entity
- render json: {error: message}, status: status
- end
- end
- end
-
def admin?
current_user.is_admin?
end
diff --git a/app/controllers/controller_extension/errors.rb b/app/controllers/controller_extension/errors.rb
new file mode 100644
index 0000000..8f8edde
--- /dev/null
+++ b/app/controllers/controller_extension/errors.rb
@@ -0,0 +1,34 @@
+module ControllerExtension::Errors
+ extend ActiveSupport::Concern
+
+ protected
+
+ def access_denied
+ respond_to_error :not_authorized, :forbidden, home_url
+ end
+
+ def login_required
+ # Warden will intercept the 401 response and call
+ # SessionController#unauthenticated instead.
+ respond_to_error :not_authorized_login, :unauthorized, login_url
+ end
+
+ def not_found
+ respond_to_error :not_found, :not_found, home_url
+ end
+
+
+ def respond_to_error(message, status=nil, redirect=nil)
+ error = message
+ message = t(message) if message.is_a?(Symbol)
+ respond_to do |format|
+ format.html do
+ redirect_to redirect, alert: message
+ end
+ format.json do
+ status ||= :unprocessable_entity
+ render json: {error: error, message: message}, status: status
+ end
+ end
+ end
+end
diff --git a/app/controllers/controller_extension/json_file.rb b/app/controllers/controller_extension/json_file.rb
index 0cb4b6d..6be919a 100644
--- a/app/controllers/controller_extension/json_file.rb
+++ b/app/controllers/controller_extension/json_file.rb
@@ -1,5 +1,6 @@
module ControllerExtension::JsonFile
extend ActiveSupport::Concern
+ include ControllerExtension::Errors
protected
diff --git a/app/controllers/controller_extension/token_authentication.rb b/app/controllers/controller_extension/token_authentication.rb
index 1cb6ffa..4ad1977 100644
--- a/app/controllers/controller_extension/token_authentication.rb
+++ b/app/controllers/controller_extension/token_authentication.rb
@@ -1,6 +1,8 @@
module ControllerExtension::TokenAuthentication
extend ActiveSupport::Concern
+ protected
+
def token
@token ||= authenticate_with_http_token do |token, options|
Token.find_by_token(token)
diff --git a/app/controllers/v1/configs_controller.rb b/app/controllers/v1/configs_controller.rb
index 0b2a64a..accdf5a 100644
--- a/app/controllers/v1/configs_controller.rb
+++ b/app/controllers/v1/configs_controller.rb
@@ -22,7 +22,7 @@ class V1::ConfigsController < ApiController
protected
def service_paths
- Hash[SERVICES.map{|k,v| [k,"/1/configs/#{str}"] } ]
+ Hash[SERVICES.map{|k,v| [k,"/1/configs/#{v}"] } ]
end
def sanitize_filename