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

+28
View File
@@ -0,0 +1,28 @@
module OrbitBasis
module BaseModel
extend ActiveSupport::Concern
# included do
# scope :recent, desc(:_id)
# scope :exclude_ids, Proc.new { |ids| where(:_id.nin => ids.map(&:to_i)) }
# scope :by_week, where(:created_at.gte => 7.days.ago.utc)
# end
module ClassMethods
def find_in_batches(opts = {})
batch_size = opts[:batch_size] || 1000
start = opts.delete(:start).to_i || 0
objects = self.limit(batch_size).skip(start)
t = Time.new
while objects.any?
yield objects
start += batch_size
# Rails.logger.debug("processed #{start} records in #{Time.new - t} seconds") if Rails.logger.debug?
break if objects.size < batch_size
objects = self.limit(batch_size).skip(start)
end
end
end
end
end
+44
View File
@@ -0,0 +1,44 @@
module OrbitControllerLib
module DivisionForDisable
# def get_disable_object_by_user(object_class)
# if is_admin? or is_manager?
# object_class.admin_manager_all
# else
# object_class.all
# end
# end
def get_categories_for_index(object_class,id = nil)
class_ref = object_class.constantize
ivar_name = "@#{object_class.to_s.underscore.pluralize}"
instance_variable_set(ivar_name, [])
if(is_manager? || is_admin?)
instance_variable_set(ivar_name, (id ? class_ref.admin_manager_all.find(id).to_a : class_ref.admin_manager_all))
elsif is_sub_manager?
instance_variable_set(ivar_name, (class_ref.all))
end
instance_variable_get(ivar_name)
end
def get_categorys(object_class,id = nil,func_authed_for_sub_manager = 'submit')
class_ref = object_class.constantize
# ivar_name = "@#{object_class.to_s.underscore.pluralize}"
ivar_name = "@#{object_class.to_s.underscore}s"
instance_variable_set(ivar_name, [])
@bulletin_categorys = []
if(is_manager? || is_admin?)
#instance_variable_set(ivar_name, (id ? class_ref.admin_manager_all.find(id).to_a : class_ref.admin_manager_all))
instance_variable_set(ivar_name, (id ? class_ref.all.find(id).to_a : class_ref.all))
elsif is_sub_manager?
instance_variable_set(ivar_name, class_ref.all.authed_for_user(current_user,func_authed_for_sub_manager))
end
if instance_variable_get(ivar_name).empty? && params[:action] != "index"
flash[:alert] = t("announcement.error.no_avilb_cate_for_posting")
redirect_to :action => :index
end
end
end
end
+57 -1
View File
@@ -1,4 +1,60 @@
module OrbitCoreLib
module BelongsToCategoryMayDisable
def self.included(base)
base.instance_eval("belongs_to :#{base::BelongsToCategory.to_s}")
base.instance_eval("
scope :currently_available_by_category, lambda { |category|
check_data = category.to_a.collect{|cate| cate.id}
any_in(#{ base::BelongsToCategory.to_s}_id: check_data)
}
")
base.instance_eval("scope :admin_manager_all,find(:all)")
# base.instance_eval("scope :all,where(disable: false)")
base.instance_eval("
scope :all, lambda {
category = base::BelongsToCategory.to_s.classify.constantize.all
check_data = category.to_a.collect{|cate| cate.id}
any_in(#{ base::BelongsToCategory.to_s}_id: check_data)
}
")
base.class_eval("
def disable?
#{base::BelongsToCategory.to_s}.disable?
end
")
end
# end
end
module ObjectDisable
def self.included(base)
base.instance_eval("field :disable,type: Boolean,:default => false")
base.instance_eval("scope :all,where(disable: false)")
base.instance_eval("scope :admin_manager_all,find(:all)")
base.define_singleton_method :find do |*args|
if args ==[:all]
unscoped
else
res = unscoped.find(args)
res.count == 1 ? res[0] : res
end
end
base.define_singleton_method :first do |*args|
all.first
end
base.define_singleton_method :last do |*args|
all.last
end
end
end
module ObjectAuthable
def self.included(base)
base.instance_eval("has_many :object_auths,as: :obj_authable,dependent: :delete")
@@ -14,7 +70,7 @@ module OrbitCoreLib
query1 = auth_object_space.any_in({sub_role_ids: sub_role_ids_ary}).excludes(blocked_user_ids: user.id)
query2 = auth_object_space.any_of({all: true},{privilege_user_ids: user.id},{role_ids: user.role.id}).excludes(blocked_user_ids: user.id)
result = (query1 + query2).uniq
result.collect{|t| t.obj_authable}
result.collect{|t| t.obj_authable}.delete_if{|val| val==nil}
end
end
+46
View File
@@ -0,0 +1,46 @@
# coding: utf-8
# this is from : https://github.com/jugyo/sunspot_mongoid
# this file is special for mongoid_auto_increment_id
require 'sunspot'
require 'mongoid'
require 'sunspot/rails'
# == Examples:
#
# class Post
# include Mongoid::Document
# field :title
#
# include Sunspot::Mongoid
# searchable do
# text :title
# end
# end
#
module OrbitSearchLib
module ObjectSearchable
def self.included(base)
base.class_eval do
extend Sunspot::Rails::Searchable::ActsAsMethods
Sunspot::Adapters::DataAccessor.register(DataAccessor, base)
Sunspot::Adapters::InstanceAdapter.register(InstanceAdapter, base)
end
end
class InstanceAdapter < Sunspot::Adapters::InstanceAdapter
def id
@instance.id
end
end
class DataAccessor < Sunspot::Adapters::DataAccessor
def load(id)
@clazz.where(:_id => id).first
end
def load_all(ids)
@clazz.where(:_id.in => ids.collect { |id| id.to_i })
end
end
end
end
+1 -1
View File
@@ -17,7 +17,7 @@ module ParserBackEnd
# item = Item.first(:conditions => { :path => tag.attr['name'] })
# ret = ''
# ret << "<a href='"
# ret << eval("admin_#{item._type.downcase}_path(item.id)")
# ret << eval("admin_#{item.class.to_s.downcase}_path(item.id)")
# ret << "' class='nav'>"
# ret << item.i18n_variable[I18n.locale]
# ret << "</a>"
+46 -28
View File
@@ -9,13 +9,14 @@ module ParserCommon
res << "'>"
i = nil
i = 1 if menu.values["li_incremental_#{current}"]
if menu.values['home'] && current == 1
res << menu_li(page, current_page, current, menu, i, edit)
end
page.visible_children.each do |child|
children = current == 1 ? page.visible_children.reverse : page.visible_children
children.each do |child|
res << menu_li(child, current_page, current, menu, i, edit)
i += 1 if i
end
if menu.values['home'] && current == 1
res << menu_li(page, current_page, current, menu, i, edit)
end
res << "</ul>"
end
res
@@ -28,8 +29,8 @@ module ParserCommon
res << " active" if (current_page.id.eql?(page.id) || current_page.descendant_of?(page))
res << "'>"
root = "/"
res << "<a href='#{edit ? root + admin_page_path(page.id) : (page._type.eql?('Page') ? root + page.path : page.url)}'><span>#{page.i18n_variable[I18n.locale]}</span></a>"
if page.visible_children.size > 0 && current <= menu.levels
res << "<a href='#{edit ? root + admin_page_path(page.id) : (page.class.to_s.eql?('Page') ? root + page.path : page.url)}'><span>#{page.title}</span></a>"
if page.visible_children.size > 0 && current < menu.levels
res << "<span class='dot'></span>"
res << menu_level(page, current_page, current + 1, menu, edit)
end unless (page.root? rescue nil)
@@ -43,20 +44,26 @@ module ParserCommon
ad_banner = AdBanner.find(banner["id"]) rescue nil
if ad_banner
res << "<script type='text/javascript'>
$(document).ready(function(){
$('#slideshow-#{ad_banner.title.dehumanize}').cycle({
delay: -1000,
fx: '#{ad_banner.ad_fx.nil? ? 'fade': ad_banner.ad_fx}',
timeoutFn: getTimeout,
pager: '#banner_nav',
pagerAnchorBuilder: function(idx, slide) {
return \"<li><a href='#'>sfdsfsf</a></li>\";
}
jQuery(function( $ ){
$.preload( '#slideshow-#{ad_banner.title.dehumanize} img', {
onFinish:finish,
threshold: 2 //'2' is the default, how many at a time, to load.
});
function finish(){
$('#slideshow-#{ad_banner.title.dehumanize}').cycle({
delay: -1000,
fx: '#{ad_banner.ad_fx.nil? ? 'fade': ad_banner.ad_fx}',
timeoutFn: getTimeout,
pager: '#banner_nav',
pagerAnchorBuilder: function(idx, slide) {
return \"<li><a href='#'></a></li>\";
}
});
};
});
});
</script>"
res << "<ul id='banner_nav' class='clear'></ul>"
res << "<div id='slideshow-#{ad_banner.title.dehumanize}'>"
res << "<div id='slideshow-#{ad_banner.title.dehumanize}' class='slideshow'>"
printable_ad_images = []
ad_banner.ad_images.each do |ad_image|
if ad_image.display?
@@ -66,13 +73,15 @@ module ParserCommon
end
end
printable_ad_images.shuffle!
hide = printable_ad_images.size > 1
printable_ad_images.each do |ad_image| #TODO Need Reflact
res << "<img src='#{ad_image.file}' "
res << "alt='#{ad_image.title[I18n.locale] || ' '}' "
res << "alt='#{ad_image.title || ' '}' "
res << "time_to_next='#{ad_banner.transition_msec}' "
res << "link_open='#{ad_image.link_open}' "
# res << "link_url='#{(ad_image.direct_to_after_click?? ad_image.out_link : ad_banner.context) || ' '}' "
res << "link_url='#{(ad_image.out_link || ad_banner.context || ' ')}' "
res << "link_url='#{(ad_image.out_link)}' "
res << "style='#{'display:none;' if hide} #{'cursor:pointer;' if !ad_image.out_link.blank?}'"
res << "/>"
end
res << "</div>"
@@ -116,12 +125,12 @@ module ParserCommon
res = ''
if menu_page && menu_page.visible_children.size > 0
res << "<div class='category_list'>"
res << "<h3 class='h3'>#{menu_page.i18n_variable[I18n.locale]}</h3>"
res << "<h3 class='h3'>#{menu_page.title}</h3>"
res << "<ul class='list'>"
menu_page.visible_children.each do |child|
res << "<li class='#{page.id.eql?(child.id) ? 'active' : nil}'>"
root = "/"
res << "<a href='#{edit ? root + admin_page_path(child.id) : (child._type.eql?('Page') ? root + child.path : child.url)}'>#{child.i18n_variable[I18n.locale]}</a>"
res << "<a href='#{edit ? root + admin_page_path(child.id) : (child.class.to_s.eql?('Page') ? root + child.path : child.url)}'>#{child.title}</a>"
res << "</li>"
end
res << "</ul>"
@@ -138,7 +147,7 @@ module ParserCommon
page_footer = body.css('.page_footer').first
if page_footer
res = "<div id='#{page_footer['id']}', class='#{page_footer['class']}'>"
res << @site.footer[I18n.locale] rescue nil
res << @site.footer rescue nil
res << "</div>"
fragment = Nokogiri::HTML::DocumentFragment.new(body ,res)
page_footer.swap(fragment) rescue nil
@@ -152,7 +161,7 @@ module ParserCommon
page_sub_menu = body.css('.page_sub_menu').first
if page_sub_menu
res = "<div id='#{page_sub_menu['id']}', class='#{page_sub_menu['class']}'>"
res << @site.sub_menu[I18n.locale] rescue nil
res << @site.sub_menu rescue nil
res << "</div>"
fragment = Nokogiri::HTML::DocumentFragment.new(body ,res)
page_sub_menu.swap(fragment) rescue nil
@@ -161,6 +170,15 @@ module ParserCommon
end
end
# sitemap
def parse_sitemaps(body = nil, page = nil, edit=nil)
sitemap = body.css('sitemap').first
url = admin_site_sitemap_frontend_path(@site)
options = "?inner=true"
fragment = Nokogiri::HTML::DocumentFragment.new(body, "<div class='dymanic_load' path='#{url + options}'></div>")
sitemap.swap(fragment)
end
# page_contents
def parse_contents(body, page, edit=nil)
public_r_tags = []
@@ -171,11 +189,11 @@ module ParserCommon
if (content["main"] == "true" && !page.module_app.nil?)
ret << "<div id='appfrontend' class='dymanic_load' path='/panel/#{page.module_app.key}/front_end/#{page.app_frontend_url}"
ret << "/#{params[:id]}" if params[:id] && !params[:id].eql?(page.id.to_s)
ret << "?inner=true&page_id=#{page.id}&category_id=#{category}&tag_id=#{tag}&preview=#{params[:preview]}&page_main=#{params[:page_main]}"
ret << "?inner=true&page_id=#{page.id}&category_id=#{category}&tag_id=#{tag}&preview=#{params[:preview]}&page_main=#{params[:page_main]}&search_query=#{params[:search_query]}&name=#{params[:name]}"
ret << "'></div>"
else
part = page.page_parts.detect{ |p| p.name.to_s == content['name'].to_s } rescue nil
part_title = part.title[I18n.locale] rescue nil
part_title = part.title rescue nil
if edit
ret << "<div id='#{content['name']}' part_id='#{part.id}' class='editable' style='border:solid 1px; margin:5px; padding:5px;'>" if part
ret << "<div class='edit_link' style='display:none'>"
@@ -184,11 +202,11 @@ module ParserCommon
end
case part.kind
when 'text'
ret << part.i18n_variable[I18n.locale] rescue ''
ret << part.content rescue ''
when 'module_widget'
url = "/panel/#{part.module_app.key}/widget/#{part.widget_path}?inner=true"
options = "&category_id=#{!part[:category].blank? ? part[:category] : category}&tag_id=#{!part[:tag].blank? ? part[:tag] : tag}&page=#{params[:page]}&part_title=#{Rack::Utils.escape(part_title).gsub("+", "%20") rescue nil}&part_id=#{part.id}"
ret << "<div class='dymanic_load' path='#{url + options}'></div>"
options = "&category_id=#{!part[:category].blank? ? part[:category].blank? : category}&tag_id=#{!part[:tag].blank? ? part[:tag] : tag}&page=#{params[:page]}&search_query=#{params[:search_query]}&part_title=#{Rack::Utils.escape(part_title).gsub("+", "%20") rescue nil}&part_id=#{part.id}"
ret << "<div class='dymanic_load widget' path='#{url + options}'></div>"
when 'public_r_tag'
ret << "<r:#{part.public_r_tag} id='#{part.public_r_tag_object_id}'/>"
public_r_tags << part.public_r_tag
+8
View File
@@ -0,0 +1,8 @@
module ResqueExt
#
# ResqueExt.unregister_workers_for_host("ec210-250-192-51")
#
def self.unregister_workers_for_host(host)
Resque.workers.select{|worker| worker.id.split(':').first==host}.each(&:unregister_worker)
end
end
+99
View File
@@ -0,0 +1,99 @@
# encoding: utf-8
require 'resque_scheduler/tasks'
namespace :data_migration do
task :add_order_to_announcement_tag_0703 => :environment do
AnnouncementTag.first({conditions:{ key: 'students' }}).update_attributes(:order=>1)
AnnouncementTag.first({conditions:{ key: 'alumni' }}).update_attributes(:order=>2)
AnnouncementTag.first({conditions:{ key: 'employee' }}).update_attributes(:order=>3)
AnnouncementTag.first({conditions:{ key: 'guest' }}).update_attributes(:order=>4)
end
task :add_archive_func_to_bulletin_category_0704 => :environment do
BulletinCategory.all.each{|bc| bc.disable=false;bc.save!}
end
task :add_archive_func_to_news_bulletin_category_0704 => :environment do
NewsBulletinCategory.all.each{|bc| bc.disable=false;bc.save!}
end
task :add_search_widget_to_news_and_announcement => :environment do
app = ModuleApp.first({:conditions=>{:title => 'news'}})
app.widgets << "news_bulletins_search_block" if !app.widgets.include?("news_bulletins_search_block")
app.save!
app = ModuleApp.first({:conditions=>{:title => 'Announcement'}})
app.widgets << "bulletins_search_block" if !app.widgets.include?("bulletins_search_block")
app.save!
p "==DO NOT FORGET TO RUN: rake redis_search:index"
end
task :add_search_func => :environment do
ModuleApp.create!(:key=>'search',:title => 'search',:enable_frontend=> true,:app_pages=>["full_search","optional_search"])
end
task :rename_test_role_name => :environment do
sr = SubRole.first({conditions:{key: 'good_teacher' }})
sr.i18n_variable[:zh_tw] = '銳論數位'
sr.i18n_variable[:en] = 'RulingCom'
sr.save!
sr = SubRole.first({conditions:{key: 'bad_teacher' }})
sr.i18n_variable[:zh_tw] = '銳論數位'
sr.i18n_variable[:en] = 'RulingCom'
sr.save!
end
task :make_bulletins_and_news_has_language_flag => :environment do
a = []
i = 0
[Bulletin,NewsBulletin].each do |bulletin|
puts "="*10 + bulletin.to_s + "="*10
bulletin.admin_manager_all.each do |bt|
result = if (bt.save(:validate => false) rescue false )
"OK"
else
a << bt.id
'Failed'
end
i += 1
puts((bt.title.to_s rescue '') + "----------#{result}")
end
end
p a
p i
puts("#{'='*10}Finished#{'='*10}")
end
task :make_web_link_has_language_flag => :environment do
a=[]
i=0
WebLink.all.each do |wl|
result = if (wl.save(:validate => false) rescue false )
"OK"
else
a << wl.id
'Failed'
end
i += 1
puts((wl.title.to_s rescue '') + "----------#{result}")
end
p a
p i
puts("#{'='*10}Finished#{'='*10}")
end
task :make_bulletin_save_dept_data => :environment do
Bulletin.all.each{|bt| bt.save!}
end
task :extend_exsisted_app_module_for_dept_search => :environment do
app = ModuleApp.first({:conditions=>{:title => 'news'}})
app.app_pages << "index_by_unit" if !app.widgets.include?("index_by_unit")
app.save!
app = ModuleApp.first({:conditions=>{:title => 'Announcement'}})
app.app_pages << "index_by_unit" if !app.widgets.include?("index_by_unit")
app.save!
end
end
+1 -1
View File
@@ -3,7 +3,7 @@
namespace :items do
task :tree_changes => :environment do
Item.all.each do |item|
item.position -= item.position > 5 ? 2 : 1
item.position -= 1
item.parent_ids = ancestors(item)
item.rename(:full_name, :path)
item.save
+60
View File
@@ -0,0 +1,60 @@
# encoding: UTF-8
namespace :matt_dev do
desc 'Testing Searching'
task :searching_01 => :environment do
a= Redis::Search.query("Bulletin",'我',:conditions =>{:is_checked=>true,:is_hidden=>false})
p a
a= Redis::Search.query("NewsBulletin",'社科院',:conditions =>{:is_checked=>true,:is_hidden=>false})
p a
end
task :searching_02 => :environment do
a= Bulletin.solr_search do #("Bulletin",'我',:conditions =>{:is_checked=>true,:is_hidden=>false})
fulltext '關島'
with(:frontend_search,true)
#with(:is_hidden,true)
end
p a.results
a= NewsBulletin.solr_search do #("NewsBulletin",'社科院',:conditions =>{:is_checked=>true,:is_hidden=>false})
fulltext '社科院'
with(:frontend_search,true)
#with(:is_hidden,true)
end
p a.results
end
task :testing_new_tag_cal do
ranges = [[1],[1,2],[1,2,3],[1,2,3,4],[1,2,3,4,5],[1,2,3,4,5,6],[1,2,3,4,5,6,7],[1,2,3,4,5,6,7,8],[1,2,3,4,5,6,7,8,9],[1,2,3,4,5,6,7,8,9,10],[1,2,3,4,5,6,7,8,9,10,11],[1,2,3,4,5,6,7,8,9,10,11,12],[-1,-2,-3,-4,5,6,7,8,9,10,11,12]]
ranges.each{ |range|
cal(range)
}
end
def cal(range_t)
range = range_t.sort.reverse
puts '='*20
puts range.to_s
puts '='*20
offset_size = range.size+4
section_3 = range.last..range[-(offset_size/4)]
puts(section_3)
section_2 = range[-(offset_size/4)-1]..range[-2*(offset_size/4)] rescue nil
puts(section_2)
section_1 = range[-2*(offset_size/4)-1]..range[1] rescue nil
puts(section_1)
range.each{|num|
result= case num
when range.first
:heading1
when section_1
:heading2
when section_2
:heading3
when section_3
:heading4
end
puts "Num:#{num} Result: #{result}"
}
puts("END")
end
end
+171
View File
@@ -0,0 +1,171 @@
# encoding: utf-8
# require 'ruby-debug'
require "#{Rails.root}/config/initializers/middle_site_connection"
namespace :mid_site do
desc "mid_site Rake task"
attr_from_mid = %w{nccu_id psn_nam ut_cod up_ut_cod eml_adr off_tel_ext sta_num}
officer_posgrp_code = %w{02 06 10 05} #from RSS2
admin_role = nil
sub_role = nil
test_account_ldap_id ='139716'
#MiddleSiteConnection.establish
task :sync => :environment do
info_profile = Info.first(conditions: {:key => 'profile'})
def find_or_create_sub_role(role,ut_query=[],key='')
sub_role = role.sub_roles.get_sub_role_from_key(key)
if sub_role.nil?
ut_data = ut_query.find{|ut_data| ut_data["ut_cod"] == key }
sub_role = role.sub_roles.create!(:key => key)
sub_role.title_translations ={"en" => (ut_data["ut_eng_m"] rescue ''), "zh_tw" => (ut_data["ut_chi_m"] rescue '')}
sub_role.save!
p "Created SubRole(key: #{key}): EN: #{sub_role.title_translations['en']}, CH: #{sub_role.title_translations['zh_tw']} ParentRole(#{role.key}): #{role.title_translations['en']}"
end
sub_role
end
users_from_mid = $mid_site_connection.query("SELECT #{attr_from_mid.join(',')} FROM rss_pautlst_ut WHERE posgrp_cod IN (#{officer_posgrp_code.join(',')})")
ut_data_from_mid = $mid_site_connection.query("SELECT ut_odr, ut_cod, up_ut_cod, ut_chi_m, ut_eng_m FROM rss_paunit WHERE ut_tpe = '1' AND ut_grp != '3' AND up_ut_cod != 'F00' ORDER BY ut_odr, ut_cod")
remote_list = users_from_mid.collect{|t| t["nccu_id"]}
#remove delete user sho has been deleted at remote first
local_need_remove = User.all.collect{|t| t.nccu_id rescue nil}.uniq.delete_if {|x| x == nil} - remote_list
desc "Going to delete User with IDs: #{local_need_remove.inspect}"
local_need_remove = User.excludes(nccu_ldap_uid: test_account_ldap_id ).collect{|t| t.nccu_ldap_uid rescue nil}.uniq.delete_if {|x| x == nil} - remote_list
AppManager.all.collect{|am| am if am.user.nil? }.delete_if {|x| x == nil}.each{|am| am.destroy}
desc "Deletion completed! \n"
#starting update user
desc "Updating and Newing Users"
users_from_mid.each do |mid_user|
ut_item = ut_data_from_mid.find{|ut_data| ut_data["ut_cod"] == mid_user["ut_cod"]}
up_ut_item = ut_data_from_mid.find{|ut_data| ut_data["ut_cod"] == mid_user["up_ut_cod"] }
local_user = User.find_or_initialize_by(:nccu_ldap_uid => mid_user["nccu_id"])
users_name_from_mid = $mid_site_connection.query("SELECT eng_nam_l,eng_nam_f,chi_nam_l,chi_nam_f FROM rss_zzperson_view WHERE nccu_id =#{mid_user["nccu_id"]}").first
first_name = AttributeValue.find_or_create_by( :user_id => local_user.id, :attribute_field_id => info_profile.attribute_fields[0].id, :key => 'first_name')
last_name = AttributeValue.find_or_create_by( :user_id => local_user.id, :attribute_field_id => info_profile.attribute_fields[1].id, :key => 'last_name')
first_name['en'] = users_name_from_mid["eng_nam_f"]
first_name['zh_tw'] = users_name_from_mid["chi_nam_f"]
first_name.save
last_name['en'] = users_name_from_mid["eng_nam_l"]
last_name['zh_tw'] = users_name_from_mid["chi_nam_l"]
last_name.save
user_model_mapper = Hash[:ut_cod => mid_user["ut_cod"] ,:up_ut_cod => mid_user["up_ut_cod"],:email => mid_user["eml_adr"],:off_tel_ext => mid_user["off_tel_ext"],:sta_num => mid_user["sta_num"]]
user_model_mapper[:admin] = false
local_user.update_attributes(user_model_mapper)
local_user.role = Role.find_or_create_by( :key => "department_admin",:build_in => true)
local_user.role.title_translations = {"en" => 'Department Admin', "zh_tw" => '系所使用者' }
unless local_user.ut_cod == local_user.up_ut_cod #if the ut_cod has additions info for up ut
local_user.sub_roles << find_or_create_sub_role(local_user.role,ut_data_from_mid,local_user.up_ut_cod)
end
local_user.sub_roles << find_or_create_sub_role(local_user.role,ut_data_from_mid,local_user.ut_cod)
local_user.save!
end
sys_users = User.all(conditions: {admin: false}).includes(:avatar).to_a
Rails.cache.write('user_setting', sys_users)
end
task :install_admin => :before_instll_admin do
admins_nccu_id = '2772'
info_profile = Info.first(conditions: {:key => 'profile'})
user_from_mid = $mid_site_connection.query("SELECT #{attr_from_mid.join(',')} FROM rss_pautlst_ut WHERE posgrp_cod IN (#{officer_posgrp_code.join(',')}) AND nccu_id = '#{admins_nccu_id}' limit 1")
admin_at_mid = user_from_mid.first
local_user = User.find_or_initialize_by(:nccu_ldap_uid => admin_at_mid["nccu_id"])
local_user.update_attributes(:email => admin_at_mid["eml_adr"], :admin => true, :role_id => admin_role.id, :sub_role_ids => [sub_role.id])
users_name_from_mid = $mid_site_connection.query("SELECT eng_nam_l,eng_nam_f,chi_nam_l,chi_nam_f FROM rss_zzperson_view WHERE nccu_id =#{admin_at_mid["nccu_id"]}").first
first_name = AttributeValue.find_or_create_by( :user_id => local_user.id, :attribute_field_id => info_profile.attribute_fields[0].id, :key => 'first_name')
last_name = AttributeValue.find_or_create_by( :user_id => local_user.id, :attribute_field_id => info_profile.attribute_fields[1].id, :key => 'last_name')
first_name['en'] = users_name_from_mid["eng_nam_f"]
first_name['zh_tw'] = users_name_from_mid["chi_nam_f"]
first_name.save
last_name['en'] = users_name_from_mid["eng_nam_l"]
last_name['zh_tw'] = users_name_from_mid["chi_nam_l"]
last_name.save
end
task :install_test => :before_instll_admin do
admins_nccu_id = '139716'
# admin_role = Role.find_or_create_by( key: 'administrator')
# sub_role = admin_role.sub_roles.find_or_create_by(:key => 'computer_center')
info_profile = Info.first(conditions: {:key => 'profile'})
user_from_mid = $mid_site_connection.query("SELECT #{attr_from_mid.join(',')} FROM rss_pautlst_ut WHERE nccu_id = '#{admins_nccu_id}' limit 1")
admin_at_mid = user_from_mid.first
user_first_name = admin_at_mid["psn_nam"].size > 3 ? admin_at_mid["psn_nam"][3..-1] : admin_at_mid["psn_nam"][1..-1]
user_last_name = admin_at_mid["psn_nam"].size > 3 ? admin_at_mid["psn_nam"][1..2] : admin_at_mid["psn_nam"][0]
local_user = User.find_or_initialize_by(:nccu_ldap_uid => admin_at_mid["nccu_id"])
local_user.update_attributes(:email => admin_at_mid["eml_adr"], :admin => true, :role_id => admin_role.id, :sub_role_ids => [sub_role.id])
AttributeValue.create( :user_id => local_user.id, :attribute_field_id => info_profile.attribute_fields[0].id, :key => 'first_name', :en => user_first_name, :zh_tw => user_first_name )
AttributeValue.create( :user_id => local_user.id, :attribute_field_id => info_profile.attribute_fields[1].id, :key => 'last_name', :en => user_last_name, :zh_tw => user_last_name )
end
task :before_instll_admin => :environment do
var_1 = {"en" => 'Administrator', "zh_tw" => '管理員' }
var_1_1 = {"en" => 'Computer Center', "zh_tw" => '計算機中心'}
admin_role = Role.find_or_create_by( :key => 'administrator',:built_in => true)
admin_role.title_translations =var_1
admin_role.save!
sub_role = admin_role.sub_roles.find_or_create_by(:key => 'computer_center', :built_in => true)
sub_role.title_translations =var_1_1
sub_role.save!
#var_1_1_1 = I18nVariable.create!( :document_class => 'Attribute', :key => 'field', :en => 'Field', :zh_tw => '領域', :parent_id => var_1_1.id )
#var_1_1_2 = I18nVariable.create!( :document_class => 'Attribute', :key => 'department', :en => 'Department', :zh_tw => '學系', :parent_id => var_1_1.id )
end
task :clean_local_account => :environment do
User.remote_account.each{|user| user.destroy}
end
task :claen_cc => [:clean_i18n_vars,:clean_admin_role_and_sub_role] do
end
task :clean_i18n_vars => :environment do
i18ns = I18nVariable.any_in( key: ['administrator','computer_center'])
i18ns.each { |var| var.destroy }
end
task :clean_ldap_users => :environment do
User.where(:nccu_ldap_uid.ne => nil ).each {|t| t.destroy}
end
task :clean_admin_role_and_sub_role => :environment do
data = Role.any_in( key: ['administrator','computer_center'])
data.each { |var| var.destroy }
data = SubRole.any_in( key: ['administrator','computer_center'])
data.each { |var| var.destroy }
end
end
+359
View File
@@ -0,0 +1,359 @@
# encoding: utf-8
namespace :migrate do
task :i18n => :environment do
p 'Start Bulletin'
bulletins = Bulletin.admin_manager_all
i = 1
bulletins.each do |bulletin|
p "#{i}/#{bulletins.size} - #{bulletin.id}"
title = I18nVariable.first(:conditions => {:key => 'title', :language_value_id => bulletin.id, :language_value_type => bulletin.class})
bulletin.title_translations = {'en' => title['en'], 'zh_tw' => title['zh_tw']} if title
subtitle = I18nVariable.first(:conditions => {:key => 'subtitle', :language_value_id => bulletin.id, :language_value_type => bulletin.class})
bulletin.subtitle_translations = {'en' => subtitle['en'], 'zh_tw' => subtitle['zh_tw']} if subtitle
text = I18nVariable.first(:conditions => {:key => 'text', :language_value_id => bulletin.id, :language_value_type => bulletin.class})
bulletin.text_translations = {'en' => text['en'], 'zh_tw' => text['zh_tw']} if text
p bulletin.save(:validate => false)
i += 1
end
p 'End Bulletin'
p '====================================================='
p 'Start BulletinCategory'
categories = BulletinCategory.admin_manager_all
i = 1
categories.each do |category|
p "#{i}/#{categories.size} - #{category.id}"
title = I18nVariable.first(:conditions => {:language_value_id => category.id, :language_value_type => category.class})
category.title_translations = {'en' => title['en'], 'zh_tw' => title['zh_tw']} if title
p category.save(:validate => false)
i += 1
end
p 'End BulletinCategory'
p '====================================================='
p 'Start BulletinFile'
files = BulletinFile.all
i = 1
files.each do |file|
p "#{i}/#{files.size} - #{file.id}"
description = I18nVariable.first(:conditions => {:language_value_id => file.id, :language_value_type => file.class})
file.description_translations = {'en' => description['en'], 'zh_tw' => description['zh_tw']} if description
title = I18nVariable.first(:conditions => {:language_value_id => file.id, :language_value_type => file.class})
file.title_translations = {'en' => title['en'], 'zh_tw' => title['zh_tw']} if title
p file.save(:validate => false)
i += 1
end
p 'End BulletinFile'
p '====================================================='
p 'Start BulletinLink'
links = BulletinLink.all
i = 1
links.each do |link|
p "#{i}/#{links.size} - #{link.id}"
title = I18nVariable.first(:conditions => {:language_value_id => link.id, :language_value_type => link.class})
link.title_translations = {'en' => title['en'], 'zh_tw' => title['zh_tw']} if title
p link.save(:validate => false)
i += 1
end
p 'End BulletinLink'
p '====================================================='
p 'Start UnitListForAnc'
units = UnitListForAnc.all
i = 1
units.each do |unit|
p "#{i}/#{units.size} - #{unit.id}"
title = I18nVariable.first(:conditions => {:language_value_id => unit.id, :language_value_type => unit.class})
unit.title_translations = {'en' => title['en'], 'zh_tw' => title['zh_tw']} if title
p unit.save(:validate => false)
i += 1
end
p 'End UnitListForAnc'
p '====================================================='
p '====================================================='
p 'Start NewsBulletin'
news_bulletins = NewsBulletin.admin_manager_all
i = 1
news_bulletins.each do |news_bulletin|
p "#{i}/#{news_bulletins.size} - #{news_bulletin.id}"
title = I18nVariable.first(:conditions => {:key => 'title', :language_value_id => news_bulletin.id, :language_value_type => news_bulletin.class})
news_bulletin.title_translations = {'en' => title['en'], 'zh_tw' => title['zh_tw']} if title
subtitle = I18nVariable.first(:conditions => {:key => 'subtitle', :language_value_id => news_bulletin.id, :language_value_type => news_bulletin.class})
news_bulletin.subtitle_translations = {'en' => subtitle['en'], 'zh_tw' => subtitle['zh_tw']} if subtitle
text = I18nVariable.first(:conditions => {:key => 'text', :language_value_id => news_bulletin.id, :language_value_type => news_bulletin.class})
news_bulletin.text_translations = {'en' => text['en'], 'zh_tw' => text['zh_tw']} if text
p news_bulletin.save(:validate => false)
i += 1
end
p 'End NewsBulletin'
p '====================================================='
p 'Start NewsBulletinCategory'
categories = NewsBulletinCategory.admin_manager_all
i = 1
categories.each do |category|
p "#{i}/#{categories.size} - #{category.id}"
title = I18nVariable.first(:conditions => {:language_value_id => category.id, :language_value_type => category.class})
category.title_translations = {'en' => title['en'], 'zh_tw' => title['zh_tw']} if title
p category.save(:validate => false)
i += 1
end
p 'End NewsBulletinCategory'
p '====================================================='
p 'Start NewsBulletinFile'
files = NewsBulletinFile.all
i = 1
files.each do |file|
p "#{i}/#{files.size} - #{file.id}"
description = I18nVariable.first(:conditions => {:language_value_id => file.id, :language_value_type => file.class})
file.description_translations = {'en' => description['en'], 'zh_tw' => description['zh_tw']} if description
title = I18nVariable.first(:conditions => {:language_value_id => file.id, :language_value_type => file.class})
file.title_translations = {'en' => title['en'], 'zh_tw' => title['zh_tw']} if title
p file.save(:validate => false)
i += 1
end
p 'End NewsBulletinFile'
p '====================================================='
p 'Start NewsBulletinLink'
links = NewsBulletinLink.all
i = 1
links.each do |link|
p "#{i}/#{links.size} - #{link.id}"
title = I18nVariable.first(:conditions => {:language_value_id => link.id, :language_value_type => link.class})
link.title_translations = {'en' => title['en'], 'zh_tw' => title['zh_tw']} if title
p link.save(:validate => false)
i += 1
end
p 'End NewsBulletinLink'
p '====================================================='
p '====================================================='
p 'Start PageContext'
page_contexts = PageContext.all
i = 1
page_contexts.each do |page_context|
p "#{i}/#{page_contexts.size} - #{page_context.id}"
context = I18nVariable.first(:conditions => {:language_value_id => page_context.id, :language_value_type => page_context.class})
page_context.context_translations = {'en' => context['en'], 'zh_tw' => context['zh_tw']} if context
p page_context.save(:validate => false)
i += 1
end
p 'End PageContext'
p '====================================================='
p '====================================================='
p 'Start WebLink'
links = WebLink.all
i = 1
links.each do |link|
p "#{i}/#{links.size} - #{link.id}"
# the original key was 'name'
title = I18nVariable.first(:conditions => {:key => 'name', :language_value_id => link.id, :language_value_type => link.class})
link.title_translations = {'en' => title['en'], 'zh_tw' => title['zh_tw']} if title
context = I18nVariable.first(:conditions => {:key => 'context', :language_value_id => link.id, :language_value_type => link.class})
link.context_translations = {'en' => context['en'], 'zh_tw' => context['zh_tw']} if context
p link.save(:validate => false)
i += 1
end
p 'End WebLink'
p '====================================================='
p 'Start WebLinkCategory'
categories = WebLinkCategory.admin_manager_all
i = 1
categories.each do |category|
p "#{i}/#{categories.size} - #{category.id}"
title = I18nVariable.first(:conditions => {:language_value_id => category.id, :language_value_type => category.class})
category.title_translations = {'en' => title['en'], 'zh_tw' => title['zh_tw']} if title
p category.save(:validate => false)
i += 1
end
p 'End WebLinkCategory'
p '====================================================='
p '====================================================='
p 'Start Meta'
metas = Meta.all
i = 1
metas.each do |meta|
p "#{i}/#{metas.size} - #{meta.id}"
title = I18nVariable.first(:conditions => {:language_value_id => meta.id, :language_value_type => meta.class})
meta.title_translations = {'en' => title['en'], 'zh_tw' => title['zh_tw']} if title
p meta.save(:validate => false)
i += 1
end
p 'End Meta'
p '====================================================='
p '====================================================='
p 'Start Attribute'
attributes = Attribute.all
i = 1
attributes.each do |attribute|
p "#{i}/#{attributes.size} - #{attribute.id}"
title = I18nVariable.first(:conditions => {:language_value_id => attribute.id, :language_value_type => attribute.class})
attribute.title_translations = {'en' => title['en'], 'zh_tw' => title['zh_tw']} if title
p attribute.save(:validate => false)
i += 1
end
p 'End Attribute'
p '====================================================='
p 'Start AttributeField'
attribute_fields = AttributeField.all
i = 1
attribute_fields.each do |attribute_field|
p "#{i}/#{attribute_fields.size} - #{attribute_field.id}"
title = I18nVariable.first(:conditions => {:language_value_id => attribute_field.id, :language_value_type => attribute_field.class})
attribute_field.title_translations = {'en' => title['en'], 'zh_tw' => title['zh_tw']} if title
p attribute_field.save(:validate => false)
i += 1
end
p 'End AttributeField'
p '====================================================='
p 'Start Role'
roles = Role.all
i = 1
roles.each do |role|
p "#{i}/#{roles.size} - #{role.id}"
title = I18nVariable.first(:conditions => {:language_value_id => role.id, :language_value_type => role.class})
role.title_translations = {'en' => title['en'], 'zh_tw' => title['zh_tw']} if title
p role.save(:validate => false)
i += 1
end
p 'End Role'
p '====================================================='
p '====================================================='
p 'Start AdImage'
ad_images = AdImage.all
i = 1
ad_images.each do |image|
p "#{i}/#{ad_images.size} - #{image.id}"
# no key is set and title = context, this is due to original error in the code
title = I18nVariable.first(:conditions => {:language_value_id => image.id, :language_value_type => image.class})
image.title_translations = {'en' => title['en'], 'zh_tw' => title['zh_tw']} if title
image.context_translations = {'en' => title['en'], 'zh_tw' => title['zh_tw']} if title
p image.save(:validate => false)
i += 1
end
p 'End AdImage'
p '====================================================='
p '====================================================='
p 'Start Asset'
assets = Asset.all
i = 1
assets.each do |asset|
p "#{i}/#{assets.size} - #{asset.id}"
title = I18nVariable.first(:conditions => {:key => 'title', :language_value_id => asset.id, :language_value_type => asset.class})
asset.title_translations = {'en' => title['en'], 'zh_tw' => title['zh_tw']} if title
description = I18nVariable.first(:conditions => {:key => 'description', :language_value_id => asset.id, :language_value_type => asset.class})
asset.description_translations = {'en' => description['en'], 'zh_tw' => description['zh_tw']} if description
p asset.save(:validate => false)
i += 1
end
p 'End Asset'
p '====================================================='
p 'Start AssetCategory'
categories = AssetCategory.all
i = 1
categories.each do |category|
p "#{i}/#{categories.size} - #{category.id}"
title = I18nVariable.first(:conditions => {:language_value_id => category.id, :language_value_type => category.class})
category.title_translations = {'en' => title['en'], 'zh_tw' => title['zh_tw']} if title
p category.save(:validate => false)
i += 1
end
p 'End AssetCategory'
p '====================================================='
p '====================================================='
p 'Start Item'
items = Item.all
i = 1
items.each do |item|
p "#{i}/#{items.size} - #{item.id}"
title = I18nVariable.first(:conditions => {:language_value_id => item.id, :language_value_type => item.class})
item.title_translations = {'en' => title['en'], 'zh_tw' => title['zh_tw']} if title
p item.save(:validate => false)
i += 1
end
p 'End Item'
p '====================================================='
p 'Start Page'
pages = Page.all
i = 1
pages.each do |item|
p "#{i}/#{pages.size} - #{item.id}"
# the key was originally 'title', changed to 'page_title' to avoit conflict with parent
title = I18nVariable.first(:conditions => {:key => 'title', :language_value_id => item.id, :language_value_type => item.class})
item.page_title_translations = {'en' => title['en'], 'zh_tw' => title['zh_tw']} if title
p item.save(:validate => false)
i += 1
end
p 'End Page'
p '====================================================='
p 'Start PagePart'
page_parts = PagePart.all
i = 1
page_parts.each do |part|
p "#{i}/#{page_parts.size} - #{part.id}"
title = I18nVariable.first(:conditions => {:key => 'title', :language_value_id => part.id, :language_value_type => part.class})
part.page_title_translations = {'en' => title['en'], 'zh_tw' => title['zh_tw']} if title
content = I18nVariable.first(:conditions => {:key => 'i18n_variable', :language_value_id => part.id, :language_value_type => part.class})
part.content_translations = {'en' => content['en'], 'zh_tw' => content['zh_tw']} if content
p part.save(:validate => false)
i += 1
end
p 'End PagePart'
p '====================================================='
p '====================================================='
p 'Start Site'
site = Site.first
title = I18nVariable.first(:conditions => {:key => 'title', :language_value_id => site.id, :language_value_type => site.class})
site.title_translations = {'en' => title['en'], 'zh_tw' => title['zh_tw']} if title
footer = I18nVariable.first(:conditions => {:key => 'footer', :language_value_id => site.id, :language_value_type => site.class})
site.footer_translations = {'en' => footer['en'], 'zh_tw' => footer['zh_tw']} if footer
sub_menu = I18nVariable.first(:conditions => {:key => 'sub_menu', :language_value_id => site.id, :language_value_type => site.class})
site.sub_menu_translations = {'en' => sub_menu['en'], 'zh_tw' => sub_menu['zh_tw']} if sub_menu
p site.save(:validate => false)
p 'End Site'
end
end