add ActiveAdmin

This commit is contained in:
Lee Lawlor
2014-03-22 13:21:45 -04:00
parent f21dea069f
commit 156f4147ef
80 changed files with 912 additions and 241 deletions

View File

@ -3,7 +3,7 @@ class ApplicationController < ActionController::Base
# include all helpers for controllers
helper :all
# include these helper methods for views
helper_method :current_user_session, :current_user, :logged_in?, :is_admin?, :get_header_value, :to_bytes
helper_method :current_user_session, :current_user, :logged_in?, :get_header_value, :to_bytes
protect_from_forgery
before_filter :allow_cross_domain_access, :set_variables
before_filter :configure_permitted_parameters, if: :devise_controller?
@ -47,8 +47,14 @@ class ApplicationController < ActionController::Base
params[:sum] = '1440' if params[:sum] == 'daily'
end
# change default devise sign_in page
def after_sign_in_path_for(resource); channels_path; end
# change default devise sign_in page; make admins sign in work correctly
def after_sign_in_path_for(resource)
if resource.is_a?(AdminUser)
admin_dashboard_path
else
channels_path
end
end
# get the locale, but don't fail if header value doesn't exist
def get_locale
@ -106,15 +112,6 @@ class ApplicationController < ActionController::Base
true if current_user
end
# check that user's email address matches admin
def is_admin?
current_user.present? && ADMIN_EMAILS.include?(current_user.email)
end
def set_admin_menu
@menu = 'admin'
end
# converts a string to a byte string for c output
def to_bytes(input, separator='.', prefix='')
return '' if input == nil
@ -160,7 +157,7 @@ class ApplicationController < ActionController::Base
end
def require_admin
unless current_user && is_admin?
unless current_admin_user.present?
render :nothing => true, :status => 403 and return
false
end
@ -194,8 +191,10 @@ class ApplicationController < ActionController::Base
end
# domain for the api
def api_domain
(Rails.env == 'production') ? API_DOMAIN : domain
def api_domain(ssl=false)
output = (Rails.env == 'production') ? API_DOMAIN : domain
output = output.sub(/http:/, 'https:') if ssl == true
return output
end
# ssl domain for the api

View File

@ -55,8 +55,8 @@ class ChartsController < ApplicationController
params[:bgcolor] = fix_color(params[:bgcolor])
# set ssl
@ssl = (get_header_value('x_ssl') == 'true')
@domain = domain(@ssl)
ssl = (get_header_value('x_ssl') == 'true')
@domain = domain(ssl)
# should data be pushed off the end in dynamic chart
@push = (params[:push] and params[:push] == 'false') ? false : true

View File

@ -0,0 +1,16 @@
class SessionsController < Devise::SessionsController
before_filter :fix_params, :only => :create
# don't modify default devise controllers
def create; super; end
def new; super; end
private
# fixes password reset params so that devise config.reset_password_keys can be set to email for activeadmin
def fix_params
params[:user][:login] = params[:user][:email]
end
end

View File

@ -1,5 +1,5 @@
class PipesController < ApplicationController
before_filter :require_admin, :set_admin_menu
before_filter :require_admin
def index
@pipes = Pipe.paginate :page => params[:page], :order => 'created_at DESC'
@ -14,3 +14,4 @@ class PipesController < ApplicationController
end
end

View File

@ -4,7 +4,7 @@ class RegistrationsController < Devise::RegistrationsController
# use defaults from devise
def new; super; end
def new; super; end
def edit; super; end
def create; super; end
private