Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Filters added to this controller apply to all controllers in the application.
- # Likewise, all the methods added will be available for all controllers.
- class ApplicationController < ActionController::Base
- include Ssl
- include Service::Helper
- helper :all
- protect_from_forgery
- filter_parameter_logging :password
- layout :admin_or_home
- before_filter :basic_auth
- before_filter :basic_auth_if_https
- before_filter :set_redhat_user,:require_ssl_only_if_is_logged_in#,:registered_vendor
- before_filter :require_admin_or_vendor
- before_filter :set_origin
- before_filter :redirect_to_public_page_if_http_protocol
- def admin_or_home
- request.path =~ /admin/ ? 'admin': 'public'
- end
- protected
- def ecosystems
- @ecosystems||=Ecosystem.all(:select=>'id,name,path')#,:order=>"level>0,level=0,level<0,updated_At asc")
- end
- def ecosystem
- @ecosystem ||= ecosystems.detect{|e| e.path==params[:ecosystem]} if params[:ecosystem]
- end
- def ecosystem_tags
- ecosystem ? ecosystem.versions.all(:joins=>[:tags],:select=>'versions.id,tags.id,tags.name') : []
- end
- def promotion
- @promotion||=ecosystem.promotions.first
- end
- def require_ssl_only_if_is_logged_in
- ssl_required if service.logged_in?(cookies)
- end
- def set_redhat_user
- set_rh_user if logged_in?
- end
- def require_admin_or_vendor
- if vendor?
- redirect_to root_url,:notice=>'You are\'t registered as Market Place ISV. Please request to Red Hat.' unless current_vendor
- elsif !admin?
- redirect_to root_path,:status=>:forbidden
- end
- end
- def current_vendor
- @current_vendor ||= Vendor.find_by_red_hat_id(authenticate_and_roles['username'],:select=>'id,red_hat_id,name')
- end
- def check_if_version_is_submitted(version)
- unless version.new?
- unless admin?
- raise Version::UnAuthorized
- end
- end
- end
- def set_origin
- cookies[:origin] = params[:origin] if params[:origin]
- end
- rescue_from Version::UnAuthorized do |exception|
- redirect_to admin_root_url,:notice=>"This Version is submitted"
- end
- rescue_from Vendor::NoVendorRegistered do |exception|
- redirect_to root_url,:notice=>'You are\'t registered as Market Place ISV. Please request to Red Hat.'
- end
- def redirect_to_public_page_if_http_protocol
- redirect_to eco_url(:rhev) unless request.ssl?
- end
- def basic_auth
- authenticate_or_request_with_http_basic do |username, password|
- @success = username == "redhat" && password == "Luavvekma"
- end
- end
- def basic_auth_if_https
- basic_auth if request.ssl? && !@success
- end
- helper_method :ecosystems,:ecosystem,:promotion,:ecosystem_tags,:logged_in?,
- :ecosystem_sidebar,:admin?,:vendor?,:current_vendor,:admin_or_vendor?,:require_admin_or_vendor
- end
Add Comment
Please, Sign In to add comment