2009-05-07 16:53:18 +00:00
|
|
|
class ApplicationController < ActionController::Base
|
2009-06-01 06:20:15 +00:00
|
|
|
protect_from_forgery
|
2010-03-08 08:04:05 +00:00
|
|
|
|
2011-12-23 10:34:21 +00:00
|
|
|
include ParserFrontEnd, ParserBackEnd
|
2011-03-02 09:28:33 +00:00
|
|
|
|
2012-02-19 08:33:22 +00:00
|
|
|
layout :layout_by_resource
|
|
|
|
|
2010-03-08 08:04:05 +00:00
|
|
|
helper :all
|
2011-05-13 01:08:42 +00:00
|
|
|
before_filter :set_locale, :set_site
|
2012-01-05 08:20:51 +00:00
|
|
|
|
2012-05-14 04:34:15 +00:00
|
|
|
def set_current_user
|
|
|
|
User.current = current_user
|
|
|
|
end
|
|
|
|
|
2012-01-05 08:20:51 +00:00
|
|
|
def front_end_available(module_app_title='')
|
2012-01-30 10:12:18 +00:00
|
|
|
app_controller = ModuleApp.first(conditions: {:key => module_app_title} )
|
2012-01-05 08:20:51 +00:00
|
|
|
unless app_controller.enable_frontend?
|
2012-01-18 13:34:26 +00:00
|
|
|
render :nothing => true
|
2012-01-05 08:20:51 +00:00
|
|
|
end
|
|
|
|
end
|
2011-04-13 10:19:51 +00:00
|
|
|
|
2011-10-20 02:06:06 +00:00
|
|
|
def get_all_app_engines
|
2012-01-10 10:29:11 +00:00
|
|
|
ary = ["vender/plugins/new_blog"]
|
2011-10-20 02:06:06 +00:00
|
|
|
app_engines = ary.collect{|t|
|
|
|
|
Rails::Engine.find t
|
|
|
|
}
|
|
|
|
app_engines.each{ |t|
|
|
|
|
# t.
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
def flaten_controller
|
|
|
|
ary=[]
|
|
|
|
Find.find(File.join(Rails.root , 'vendor/plugins/')) { |name|
|
|
|
|
require_dependency(name) if /_controller\.rb$/ =~ name
|
|
|
|
ary << name
|
|
|
|
}
|
|
|
|
ary
|
|
|
|
end
|
|
|
|
|
2011-04-13 10:19:51 +00:00
|
|
|
# Find the parent for the given item
|
|
|
|
def find_parent_item
|
|
|
|
@parent_item = Item.first(:conditions => { :id => BSON::ObjectId(params[:parent_id]) }) rescue nil
|
|
|
|
end
|
2009-06-19 09:31:10 +00:00
|
|
|
|
2012-04-29 19:14:15 +00:00
|
|
|
def auth_failed_in_backend
|
2012-05-01 08:05:05 +00:00
|
|
|
#redirect_to admin_dashboards_url
|
|
|
|
redirect_to root_path
|
2012-04-29 19:14:15 +00:00
|
|
|
end
|
|
|
|
|
2011-04-13 10:19:51 +00:00
|
|
|
# Check if the current_user is admin
|
|
|
|
def is_admin?
|
2012-05-05 09:40:07 +00:00
|
|
|
current_user.admin? ? true : auth_failed_in_backend
|
2012-04-29 19:14:15 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def is_manager?
|
|
|
|
@module_app.managing_users.include?(current_user) || is_admin?
|
|
|
|
end
|
|
|
|
|
|
|
|
def for_admin_only
|
|
|
|
if is_admin?
|
|
|
|
true
|
|
|
|
else
|
2012-04-30 07:51:22 +00:00
|
|
|
flash[:error] = t("admin.access.denied.not_admin")
|
2012-04-29 19:14:15 +00:00
|
|
|
auth_failed_in_backend
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def for_app_manager
|
|
|
|
if is_manager?
|
|
|
|
true
|
|
|
|
else
|
2012-05-05 09:40:07 +00:00
|
|
|
flash[:error] = t("admin.access.denied.app.not_manager")
|
|
|
|
auth_failed_in_backend
|
|
|
|
end
|
2012-04-29 19:14:15 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def for_app_sub_manager
|
|
|
|
if (@module_app.sub_managing_users.include?(current_user) || is_manager?)
|
|
|
|
true
|
|
|
|
else
|
2012-05-05 09:40:07 +00:00
|
|
|
flash[:error] = t("admin.access.denied.app.not_sub_manager")
|
|
|
|
auth_failed_in_backend
|
|
|
|
end
|
2012-04-29 19:14:15 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def for_app_user
|
|
|
|
if (@module_app.app_auth.auth_users.include?(current_user) || for_app_sub_manager )
|
|
|
|
true
|
|
|
|
else
|
2012-05-05 09:40:07 +00:00
|
|
|
flash[:error] = t("admin.access.denied.app.not_authed_user")
|
|
|
|
auth_failed_in_backend
|
|
|
|
end
|
2012-04-29 19:14:15 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def check_object_premission(obj,title)
|
2012-04-30 07:51:22 +00:00
|
|
|
flash[:error] = t("admin.access.denied.object")
|
2012-04-29 19:14:15 +00:00
|
|
|
auth_failed_in_backend unless (obj.get_object_auth_by_title(title).auth_users.include?(current_user) || is_manager? || is_admin? )
|
2011-04-13 10:19:51 +00:00
|
|
|
end
|
|
|
|
|
2011-03-02 09:28:33 +00:00
|
|
|
# Render the page
|
2012-05-13 11:32:05 +00:00
|
|
|
def render_page
|
2011-05-25 06:50:56 +00:00
|
|
|
if @item
|
2012-05-13 11:32:05 +00:00
|
|
|
render :text => parse_page_noko(@item), :layout => 'page_layout'
|
2009-06-01 06:20:15 +00:00
|
|
|
else
|
|
|
|
render :text => '404 Not Found'
|
|
|
|
end
|
|
|
|
end
|
2012-08-07 21:40:50 +00:00
|
|
|
|
|
|
|
def render_share
|
|
|
|
object_class = params[:model].classify.constantize
|
|
|
|
@object = object_class.find(params[:id])
|
2012-08-07 23:46:10 +00:00
|
|
|
module_app = ModuleApp.first(:conditions => {:key => params[:key]})
|
|
|
|
@item = Item.where(module_app_id: module_app.id).all_of("tag" => {"$in" => [nil,'']},"category" => { "$in" => [nil,'']}).first
|
2012-08-08 02:12:21 +00:00
|
|
|
@orig_url = "http://#{request.host_with_port}/#{@item.path}?id=#{@object.id}"
|
2012-08-07 21:40:50 +00:00
|
|
|
render 'shared/render_share', :layout => false
|
|
|
|
end
|
2009-06-01 06:20:15 +00:00
|
|
|
|
2011-08-18 05:43:33 +00:00
|
|
|
protected
|
|
|
|
|
2011-04-13 10:19:51 +00:00
|
|
|
# Set I18n.locale
|
2009-06-19 09:31:10 +00:00
|
|
|
def set_locale
|
|
|
|
# update session if passed
|
2011-04-13 10:19:51 +00:00
|
|
|
session[:locale] = params[:locale] if params[:locale]
|
|
|
|
|
2009-06-19 09:31:10 +00:00
|
|
|
# set locale based on session or default
|
2011-04-13 10:19:51 +00:00
|
|
|
begin
|
|
|
|
# check if locale is valid for non site pages
|
|
|
|
if LIST[:forbidden_item_names].include?(env['PATH_INFO'].split('/')[1].to_s) && !VALID_LOCALES.include?(session[:locale])
|
|
|
|
I18n.locale = I18n.default_locale
|
|
|
|
else
|
|
|
|
I18n.locale = session[:locale]
|
|
|
|
end
|
|
|
|
rescue
|
|
|
|
I18n.locale = I18n.default_locale
|
|
|
|
end
|
2010-01-11 09:09:50 +00:00
|
|
|
end
|
2010-03-08 08:04:05 +00:00
|
|
|
|
2011-04-13 10:19:51 +00:00
|
|
|
# Set the site variables
|
|
|
|
def set_site
|
|
|
|
# set site if exist or create site
|
2011-03-02 09:28:33 +00:00
|
|
|
@site = Site.first || Site.create({:valid_locales => [], :in_use_locales => []})
|
|
|
|
session[:site] = @site.id
|
2012-05-06 16:53:52 +00:00
|
|
|
@site_in_use_locales = site_locales_default_head(@site.in_use_locales)
|
|
|
|
@site_valid_locales = site_locales_default_head(@site.valid_locales)
|
2011-04-13 10:19:51 +00:00
|
|
|
end
|
2011-05-13 01:08:42 +00:00
|
|
|
|
|
|
|
def set_current_item
|
2011-05-25 06:50:56 +00:00
|
|
|
session[:current_page] = params[:id] || @item.id rescue nil
|
2011-05-13 01:08:42 +00:00
|
|
|
end
|
2011-08-18 05:43:33 +00:00
|
|
|
|
|
|
|
def decrypt_data(encrypted_data, encrypted_key, encrypted_iv)
|
|
|
|
site = Site.find(session[:site])
|
|
|
|
if encrypted_data
|
|
|
|
private_key = OpenSSL::PKey::RSA.new(site.private_key)
|
|
|
|
cipher = OpenSSL::Cipher.new('aes-256-cbc')
|
|
|
|
cipher.decrypt
|
|
|
|
cipher.key = private_key.private_decrypt(encrypted_key)
|
|
|
|
cipher.iv = private_key.private_decrypt(encrypted_iv)
|
|
|
|
|
|
|
|
decrypted_data = cipher.update(encrypted_data)
|
|
|
|
decrypted_data << cipher.final
|
|
|
|
else
|
|
|
|
''
|
|
|
|
end
|
|
|
|
end
|
2011-09-01 01:12:41 +00:00
|
|
|
|
|
|
|
def get_homepage
|
2012-05-22 06:45:49 +00:00
|
|
|
Page.root
|
2011-09-01 01:12:41 +00:00
|
|
|
end
|
2011-04-13 10:19:51 +00:00
|
|
|
|
2012-02-19 08:33:22 +00:00
|
|
|
def layout_by_resource
|
|
|
|
if devise_controller?
|
|
|
|
"devise"
|
|
|
|
else
|
|
|
|
"application"
|
|
|
|
end
|
|
|
|
end
|
2011-10-20 02:06:06 +00:00
|
|
|
|
2012-05-06 16:53:52 +00:00
|
|
|
def site_locales_default_head(locales)
|
|
|
|
if locales[0].eql? I18n.locale.to_s
|
|
|
|
locales
|
|
|
|
else
|
|
|
|
a = Array.new(locales)
|
|
|
|
shift_out = a.delete(I18n.locale.to_s)
|
|
|
|
[shift_out] + a
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2009-05-07 16:53:18 +00:00
|
|
|
end
|