Merge branch 'nccu_master' into demo_site

Conflicts:
	Gemfile
	app/assets/javascripts/tinymce_orbit.js.erb
	app/assets/stylesheets/style.css.erb
	app/controllers/admin/assets_controller.rb
	app/controllers/admin/module_apps_new_interface_controller.rb
	app/controllers/admin/page_parts_controller.rb
	app/jobs/sync_db.rb
	app/models/page.rb
	app/models/page_part.rb
	app/models/user/user.rb
	app/uploaders/image_uploader.rb
	app/views/admin/assets/create.js.erb
	app/views/admin/module_apps/reload_frontend_pages.js.erb
	app/views/layouts/_orbit_bar.html.erb
	app/views/layouts/_side_bar.html.erb
	app/views/layouts/_users_checkbox_ary.html.erb
	app/views/shared/_privilege_user.html.erb
	config/mongoid.yml
	lib/parsers/parser_common.rb
	vendor/built_in_modules/announcement/announcement.json
	vendor/built_in_modules/announcement/app/controllers/panel/announcement/front_end/bulletins_controller.rb
	vendor/built_in_modules/announcement/app/controllers/panel/announcement/widget/bulletins_controller.rb
	vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/bulletins/_form_bulletin_link.html.erb
	vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/fact_checks/_privilege_user.html.erb
	vendor/built_in_modules/announcement/app/views/panel/announcement/front_end/bulletins/index.html.erb
	vendor/built_in_modules/announcement/app/views/panel/announcement/widget/bulletins/_index.html.erb
This commit is contained in:
chris committed 2012-08-22 18:07:49 +08:00
commit 7d5531bf01
432 files changed
+8773 -17035

No files matched your search

+14 -12
View File
@@ -30,17 +30,19 @@ class Admin::AssetsController < OrbitBackendController
def create
@asset = Asset.new(params[:asset])
@asset.filename = @asset.title[I18n.locale] rescue nil
@asset.filename = @asset.title rescue nil
if @asset.filename && @asset.save
respond_to do |format|
format.js {
if params[:uploader]
render "create"
else
render 'js/remove_pop_up_and_reload_content', :locals => {:function => 'replaceWith', :id => "asset_#{@asset.id}", :value => @asset, :values => nil, :partial => 'admin/assets/asset', :locals => nil}
end
}
end
# respond_to do |format|
# format.js {
# if params[:uploader]
# render 'create'
# else
# render 'js/remove_pop_up_and_reload_content', :locals => {:function => 'replaceWith', :id => "asset_#{@asset.id}", :value => @asset, :values => nil, :partial => 'admin/assets/asset', :locals => nil}
# end
# }
# end
# render :json=>{"url"=>@asset.data.url,"title"=>"xxx","desc"=>"sss"}.to_json
render :layout=>false
else
flash[:error] = t(:create_fail)
@asset_categories = AssetCategory.all
@@ -85,8 +87,8 @@ class Admin::AssetsController < OrbitBackendController
end
def delete
if params[:to_delete]
asset = Asset.any_in(:_id => params[:to_delete]).delete_all
if params[:ids]
asset = Asset.any_in(:_id => params[:ids]).delete_all
end
redirect_to assets_url(:filter => params[:filter], :direction => params[:direction], :sort => params[:sort], :sort_options => params[:sort_options])
end
+2 -2
View File
@@ -86,8 +86,8 @@ class Admin::DesignsController < OrbitBackendController
end
def delete
if params[:to_delete]
designs = Design.any_in(:_id => params[:to_delete]).delete_all
if params[:ids]
designs = Design.any_in(:_id => params[:ids]).delete_all
end
redirect_to admin_designs_url(:direction => params[:direction], :sort => params[:sort], :sort_options => params[:sort_options])
end
@@ -10,6 +10,7 @@ class Admin::ModuleAppsController < ApplicationController
def reload_frontend_pages
@categories =[]
@module_app = ModuleApp.find(params[:id])
@frontend_path = @module_app.widgets.keys[0] if ( !@module_app.widgets.blank? && @module_app.widgets[0].blank? )
@@ -39,7 +39,7 @@ class Admin::ModuleAppsNewInterfaceController < OrbitBackendController
def update_setting_by_params
user_sat = []
ma = ModuleApp.find params[:module_app][:id]
user_sat = User.find params[:users].keys if params.has_key? :users
user_sat += User.find params[:users].keys if params.has_key?('users')
users_to_new = user_sat - ma.managing_users
users_to_remove = ma.managing_users - user_sat
@@ -56,7 +56,7 @@ class Admin::ModuleAppsNewInterfaceController < OrbitBackendController
def get_categorys(id = nil)
@bulletin_categorys = []
if(is_manager? || is_admin?)
@bulletin_categorys = (id ? BulletinCategory.find(id).to_a : BulletinCategory.excludes('disabled' => true))
@bulletin_categorys = (id ? BulletinCategory.find(id).to_a : BulletinCategory.all)
elsif is_sub_manager?
@bulletin_categorys = BulletinCategory.authed_for_user(current_user,'submit_new')
end
@@ -49,7 +49,7 @@ class Admin::ObjectAuthsNewInterfaceController < OrbitBackendController
# def get_categorys(id = nil)
# @bulletin_categorys = []
# if(is_manager? || is_admin?)
# @bulletin_categorys = (id ? BulletinCategory.find(id).to_a : BulletinCategory.excludes('disabled' => true))
# @bulletin_categorys = (id ? BulletinCategory.find(id).to_a : BulletinCategory.all)
# elsif is_sub_manager?
# @bulletin_categorys = BulletinCategory.authed_for_user(current_user,'submit_new')
# end
@@ -56,6 +56,12 @@ class Admin::PagePartsController < ApplicationController
if @part.update_attributes(params[:page_part])
set_children_sub_menu(@part) if @part.public_r_tag && @part.public_r_tag.eql?('sub_menu')
flash.now[:notice] = t('admin.update_success_content')
if @part.page.name == 'home'
expire_page '/'
else
expire_page page_path(@part.page.name)
end
respond_to do |format|
format.html {
redirect_to admin_page_url( @part.page )
@@ -76,12 +82,13 @@ class Admin::PagePartsController < ApplicationController
end
def reload_widgets
@categories =[]
@module_app = ModuleApp.find(params[:id])
@widget_path = @module_app.widgets.keys[0] if ( @module_app.widgets[0].blank? )
@widget_style = @module_app.widgets[@widget_path] if ( !@widget_path.blank? )
case @module_app.key
when 'announcement'
@categories = BulletinCategory.all
@@ -93,6 +100,7 @@ class Admin::PagePartsController < ApplicationController
@categories = WebLinkCategory.all
@tags = WebResourceTag.all
end
respond_to do |format|
format.js {}
end
@@ -32,7 +32,7 @@ class Admin::PurchasesController < ApplicationController
public_key = OpenSSL::PKey::RSA.new(File.read(APP_CONFIG['main_public_key']))
encrypted_data = public_key.public_encrypt({:purchase_id => purchase.purchase_id,
:purchase_type => purchase._type,
:purchase_type => purchase.class.to_s,
:roaming_id => Site.find(session[:site]).roaming_id,
:url => url}.to_json)
@@ -43,7 +43,7 @@ class Admin::PurchasesController < ApplicationController
temp_file.write response.body
temp_file.rewind
zip_name = response['content-disposition'].split('filename=')[1].gsub(/[\\\"]|.zip/, '') rescue ''
case purchase._type
case purchase.class.to_s
when 'Pdesign'
unzip_design(temp_file, zip_name)
when 'PModuleApp'
+28 -10
View File
@@ -1,8 +1,8 @@
class Admin::SitesController < ApplicationController
layout "new_admin"
before_filter :authenticate_user!
before_filter :is_admin?
before_filter :authenticate_user!, :except => [:sitemap_frontend]
before_filter :is_admin?, :except => [:sitemap_frontend]
before_filter :get_site
# def index
@@ -19,22 +19,40 @@ class Admin::SitesController < ApplicationController
redirect_to :back
end
def mail_setting
end
def site_info
end
def sitemap
@items = get_homepage.children rescue []
end
def sitemap_frontend
@items = get_homepage.children.excludes(sitemap_enabled: false) rescue []
render :layout => false
end
def sitemap_toggle
@item = Item.find(params[:id])
@item.sitemap_enabled = !@item.sitemap_enabled
@item.save
if params[:parent]
@item.children.each do |child|
child.sitemap_enabled = @item.sitemap_enabled
child.save
end
end
render :nothing => true
end
def system_info
end
def language
end
def mail_setting
end
def ui_theme
end
+21 -1
View File
@@ -101,11 +101,23 @@ class ApplicationController < ActionController::Base
# Render the page
def render_page
if @item
render :text => parse_page_noko(@item), :layout => 'page_layout'
respond_to do |format|
format.html { render :text => parse_page_noko(@item), :layout => 'page_layout' }
format.rss { render_main_rss }
end
else
render :text => '404 Not Found'
end
end
def render_share
object_class = params[:model].classify.constantize
@object = object_class.find(params[:id])
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
@orig_url = "http://#{request.host_with_port}/#{@item.path}?id=#{@object.id}"
render 'shared/render_share', :layout => false
end
protected
@@ -178,4 +190,12 @@ class ApplicationController < ActionController::Base
end
end
def render_main_rss
ret = ''
ret << "/panel/#{@item.module_app.key}/front_end/#{@item.app_frontend_url}.rss"
ret << "/#{params[:id]}" if params[:id] && !params[:id].eql?(@item.id.to_s)
ret << "?inner=true&category_id=#{params[:category]}&tag_id=#{params[:tag]}&page_main=#{params[:page_main]}"
redirect_to ret
end
end
+13 -21
View File
@@ -39,11 +39,10 @@ class OrbitBackendController< ApplicationController
options = [options] if !options.class.eql?(Array)
options.each do |option|
if object_class.fields.include?(option)
case object_class.fields[option].type.to_s
when 'BigDecimal', 'Boolean', 'Date', 'DateTime', 'Float', 'Integer', 'String', 'Symbol', 'Time'
(objects = objects.order_by(option, params[:direction])) rescue nil
when 'Object'
objects = get_objects_from_referenced_objects(object_class.fields[option].options[:class_name].constantize, objects, option)
if object_class.fields[option].type.to_s.eql?('Object') && !object_class.relations[option].nil?
objects = get_objects_from_referenced_objects(object_class.fields[option].options[:class_name].constantize, objects, option)
else
(objects = objects.order_by(option, params[:direction])) rescue nil
end
elsif object_class.relations.include?(option)
case object_class.relations[option].macro
@@ -92,20 +91,11 @@ class OrbitBackendController< ApplicationController
end
def get_string_value_from_object(object)
s = object[I18n.locale] rescue nil
s = object.i18n_variable unless s rescue nil
s = object.name_translations[I18n.locale.to_s] unless s rescue nil
s = object.title_translations[I18n.locale.to_s] unless s rescue nil
s = object.name unless s rescue nil
s = object.title unless s rescue nil
if s
case s.class.to_s
when "String"
s.downcase rescue ''
when "I18nVariable"
s[I18n.locale].downcase rescue ''
else
nil
end
end
s.downcase rescue ''
end
def get_objects_from_referenced_objects(object_class, objects, option)
@@ -113,7 +103,7 @@ class OrbitBackendController< ApplicationController
referenced_objects = object_class.find(referer_ids) rescue nil
if referenced_objects
a = Array.new
referenced_objects.each { |referer| a << [get_string_value_from_object(referer), referer.id] }
referenced_objects.to_a.each { |referer| a << [get_string_value_from_object(referer), referer.id] }
sorted = params[:direction].eql?('asc') ? a.sort : a.sort.reverse!
sorted_objects = sorted.collect {|x| objects.where(option => x[1]).entries }
sorted_objects.flatten!
@@ -154,15 +144,17 @@ class OrbitBackendController< ApplicationController
end
def get_viewable(object_class)
objects = get_objects(object_class).order_by(:created_at, :desc)
def get_viewable(object_class, query=nil)
objects = get_objects(object_class,query).order_by(:created_at, :desc)
Kaminari.paginate_array(objects).page(params[:page]).per(10)
end
def get_objects(object_class, query=nil)
object_class = object_class.classify.constantize
# debugger
# a=1
if query
objects = object_class.all.where(query)
objects = object_class.where(query)
else
objects = object_class.all
end
+37 -12
View File
@@ -1,14 +1,14 @@
class PagesController < ApplicationController
include ApplicationHelper
before_filter :get_item, :only => [:index_from_link, :show_from_link]
# caches_page :index
def index
@item = Page.find_by_name('home')
if @item
impressionist(@item)
render_page
render_page
else
render :text => 'You need a home page'
end
@@ -17,13 +17,13 @@ class PagesController < ApplicationController
def show
#begin
@item = Item.first(:conditions => {:path => params[:page_name]})
if @item && @item.is_published && (@item.enabled_for.nil? ? true : @item.enabled_for.include?(I18n.locale.to_s))
if @item && @item.is_published #&& (@item.enabled_for.nil? ? true : @item.enabled_for.include?(I18n.locale.to_s))
impressionist(@item)
case @item._type
when 'Page'
render_page
case @item.class.to_s
when 'Page'
render_page unless save_from_no_lang_for_page
when 'Link'
redirect_to @item[:url]
redirect_to(@item[:url]) unless save_from_no_lang_for_page
end
else
render :file => "#{Rails.root}/public/404.html", :status => :not_found
@@ -39,14 +39,20 @@ class PagesController < ApplicationController
options << "?page_main=#{params[:page_main]}" unless params[:page_main].blank?
options << "#{options.blank? ? '?' : '&'}category_id=#{params[:category_id]}" unless params[:category_id].blank?
options << "#{options.blank? ? '?' : '&'}tag_id=#{params[:tag_id]}" unless params[:tag_id].blank?
redirect_to url + options
options << "#{options.blank? ? '?' : '&'}search_query=#{params[:search_query]}" unless params[:search_query].blank?
options << "#{options.blank? ? '?' : '&'}name=#{params[:name]}" unless params[:name].blank?
uri = URI::escape(url + options)
#uri = URI::escape("#{url}?" + params.collect{|k,v| "#{k}=#{v}"}.join('&'))
redirect_to(uri)unless save_from_no_lang_for_page
end
def show_from_link
url = "/#{@item.path}?id=#{params[:id]}"
options = ''
options << "#{options.blank? ? '?' : '&'}category_id=#{params[:category_id]}" unless params[:category_id].blank?
options << "#{options.blank? ? '?' : '&'}tag_id=#{params[:tag_id]}" unless params[:tag_id].blank?
options << "&preview=#{params[:preview]}" unless params[:preview].blank?
redirect_to url + options
redirect_to(url + options) unless save_from_no_lang_for_page
end
def load_orbit_bar
@@ -57,7 +63,26 @@ class PagesController < ApplicationController
def get_item
module_app = ModuleApp.first(:conditions => {:key => params[:app_name]})
@item = Item.first(:conditions => {:module_app_id => module_app.id, :app_frontend_url => params[:app_action]})
if !params[:category_id].blank? && !params[:tag_id].blank?
@item = Item.first(:conditions => {:module_app_id => module_app.id, :app_frontend_url => params[:app_action], :category => params[:category_id], :tag => params[:tag_id]})
@item = Item.first(:conditions => {:module_app_id => module_app.id, :app_frontend_url => params[:app_action], :category => params[:category_id], :tag => ''}) unless @item
elsif !params[:category_id].blank?
@item = Item.where(module_app_id: module_app.id,app_frontend_url:params[:app_action],category: params[:category_id]).any_in(tag: [nil,'']).first
elsif !params[:tag_id].blank?
@item = Item.where(module_app_id: module_app.id,app_frontend_url:params[:app_action],tag: params[:tag_id]).any_in(category: [nil,'']).first
end
@item = Item.where(module_app_id: module_app.id,app_frontend_url:params[:app_action]).all_of("tag" => {"$in" => [nil,'']},"category" => { "$in" => [nil,'']}).first unless @item
#TODO 需要做 error handler 處理沒有新增該模組頁面導致錯誤的可能性
end
protected
def save_from_no_lang_for_page
if @item.nil? or !@item.enabled_for_lang(I18n.locale.to_s)
flash[:error] = t('sys.module_page_lang_not_support')
redirect_to '/'
return true
else
return false
end
end
end
+85
View File
@@ -0,0 +1,85 @@
class SessionsController < Devise::SessionsController
prepend_before_filter :require_no_authentication, :only => [ :new, :create ]
include Devise::Controllers::InternalHelpers
# POST /resource/sign_in
def create
# login_password = params[:user][:password]
# login_uid = params[:user][:nccu_ldap_uid]
login_password = params[:user][:password]
login_uid = params[:user][:nccu_ldap_uid]
result = false
ldap_filter = "(uid=#{login_uid})"
if /@rulingcom.com$/.match(login_uid).nil?
MiddleSiteConnection.establish
NccuLdapConnection.establish
if ($nccu_ldap_connection.bind rescue false)
logger.info "=LDAP Binded password ok..."
result =check_auth_with_ldap(login_uid,login_password)
if result && login_password!=''
logger.info "==LDAP password passed..."
nccu_id = get_nccu_id_from_mid_site(login_uid)
resource = nccu_id.nil? ? nil : (User.first(conditions:{ nccu_ldap_uid: nccu_id }))
# resource = env['warden'].authenticate!(:check_nccu_ldap)
# resource = warden.authenticate!(:scope => resource_name, :recall => "#{controller_path}#new")
set_flash_message(:notice, :signed_in) if is_navigational_format?
if (resource.nil? || nccu_id.nil?)
logger.error "===LDAP passed local block... resource:#{resource.inspect}\n nccu_id:#{nccu_id} \t login_uid:#{login_uid}"
flash[:notice] = t('devise.failure.ldap_pass_but_account_not_in_orbit')
render :action => "new"
else
logger.info "===ALL passed"
resource_name = resource.class.to_s.downcase
sign_in(resource_name, resource)
respond_with resource, :location => redirect_location(resource_name, resource)
end
else
logger.error "==password LDAP fail..."
flash[:notice] = t('devise.failure.ldap_invalid')
render :action => "new"
end
else
logger.error "=LDAP fail..."
flash[:notice] = t('devise.failure.ldap_connection_failed')
render :action => "new"
end
else #if rulingcom account
logger.info "=======Rulingcom account======"
resource = User.first(conditions:{email: login_uid})
if resource.valid_password?(login_password)
resource_name = resource.class.to_s.downcase
sign_in(resource_name, resource)
respond_with resource, :location => redirect_location(resource_name, resource)
else
logger.error "==password Local fail..."
flash[:notice] = t('devise.failure.invalid')
render :action => "new"
end
end
logger.info "=======End Debugging======"
end
private
def check_auth_with_ldap(login_uid,login_password)
ldap_filter = "(uid=#{login_uid})"
$nccu_ldap_connection.bind_as(:base => NccuLdapConnection::BASE,:filter => ldap_filter,:password=> login_password) rescue false
end
def get_nccu_id_from_mid_site(ldap_id)
nccu_id = $mid_site_connection.query("SELECT nccu_id FROM rss_aaldap_view WHERE ldap_id='#{ldap_id}' LIMIT 1").first['nccu_id'] rescue nil
#
# if nccu_id.nil?
# #show_error
# p 'account not exist'
# #should return?
# end
# # User.first(conditions: { })
# rss_pautlst_ut = $mid_site_connection.query("SELECT * FROM rss_pautlst_ut WHERE nccu_id='#{nccu_id}' LIMIT 1").first rescue nil
# # rss_paunit = client.query("SELECT * FROM rss_paunit LIMIT 1").first rescue nil
# user = User.find_or_create_by(:nccu_id => nccu_id)
# p user
# # p rss_paunit
#
end
end