Complete for 229 check.
This commit is contained in:
parent
678f1eabef
commit
3209f9aa27
1
Gemfile
1
Gemfile
|
@ -14,6 +14,7 @@ gem 'kaminari'
|
|||
|
||||
gem 'mini_magick'
|
||||
gem 'mongoid'
|
||||
gem 'mysql2'
|
||||
gem 'radius'
|
||||
gem 'rake'
|
||||
gem 'ruby-debug19'
|
||||
|
|
|
@ -95,6 +95,8 @@ GEM
|
|||
mongo (~> 1.3)
|
||||
tzinfo (~> 0.3.22)
|
||||
multi_json (1.0.4)
|
||||
mysql2 (0.3.11)
|
||||
mysql2 (0.3.11-x86-mingw32)
|
||||
net-ldap (0.3.1)
|
||||
orm_adapter (0.0.6)
|
||||
polyglot (0.3.3)
|
||||
|
@ -217,6 +219,7 @@ DEPENDENCIES
|
|||
kaminari
|
||||
mini_magick
|
||||
mongoid
|
||||
mysql2
|
||||
net-ldap (~> 0.3.1)
|
||||
radius
|
||||
rails (>= 3.1.0, < 3.2.0)
|
||||
|
|
|
@ -17,7 +17,8 @@ class SessionsController < Devise::SessionsController
|
|||
if ldap.bind
|
||||
result = ldap.bind_as(:base => ldap_base,:filter => ldap_filter,:password=> login_password)
|
||||
if result
|
||||
resource = User.find_or_initialize_by( nccu_ldap_uid: login_uid )
|
||||
nccu_id = get_nccu_id_from_mid_site(login_uid)
|
||||
resource = User.first(conditions:{ nccu_id: 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?
|
||||
|
@ -33,5 +34,21 @@ class SessionsController < Devise::SessionsController
|
|||
render :action => "new"
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
def get_nccu_id_from_mid_site(ldap_id)
|
||||
nccu_id = MID_CLIENT.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_CLIENT.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
|
|
@ -22,6 +22,9 @@ class User
|
|||
has_and_belongs_to_many :sub_roles
|
||||
accepts_nested_attributes_for :attribute_values, :allow_destroy => true
|
||||
|
||||
scope :remote_account, where(:nccu_id.ne => nil)
|
||||
|
||||
|
||||
def avb_apps
|
||||
sub_role_ids_ary=self.sub_roles.collect{|t| t.id}
|
||||
query1 = AppAuth.any_in({sub_role_ids: sub_role_ids_ary}).excludes(blocked_user_ids: self.id)
|
||||
|
|
|
@ -141,7 +141,4 @@ Devise.setup do |config|
|
|||
# end
|
||||
# manager.default_strategies(:scope => :user).unshift :twitter_oauth
|
||||
# end
|
||||
config.warden do |manager|
|
||||
manager.default_strategies.unshift :check_nccu_ldap
|
||||
end
|
||||
end
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
#encoding: utf-8
|
||||
|
||||
require 'mysql2'
|
||||
|
||||
|
||||
mid_host = {
|
||||
:host => '127.0.0.1', #mruling.nccu.edu.tw
|
||||
:port => 8005,
|
||||
:username => "root",
|
||||
:password => "a3G6yWd9",
|
||||
:database => "RSS23_NCCU_MIDDLE",
|
||||
:encoding => "UTF8"
|
||||
}
|
||||
MID_CLIENT = Mysql2::Client.new(mid_host)
|
|
@ -0,0 +1,106 @@
|
|||
# encoding: utf-8
|
||||
|
||||
namespace :mid_site do
|
||||
attr_from_mid = %w{nccu_id psn_nam ut_chi_m eml_adr off_tel_ext sta_num}
|
||||
officer_posgrp_code = %w{02 06 10 05} #from RSS2
|
||||
admin_role = nil
|
||||
sub_role = nil
|
||||
|
||||
task :sync => :environment do
|
||||
users_from_mid = MID_CLIENT.query("SELECT #{attr_from_mid.join(',')} FROM rss_pautlst_ut WHERE posgrp_cod IN (#{officer_posgrp_code.join(',')})")
|
||||
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
|
||||
local_need_remove.each{|user_id| (User.find user_id).destroy}
|
||||
|
||||
#starting update user
|
||||
users_from_mid.each do |mid_user|
|
||||
local_user = User.find_or_initialize_by(:nccu_id => mid_user["nccu_id"])
|
||||
local_user.update_attributes(mid_user)
|
||||
local_user.save!
|
||||
end
|
||||
end
|
||||
|
||||
task :install_admin => :before_instll_admin do
|
||||
admins_nccu_id = '2772'
|
||||
# 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_CLIENT.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
|
||||
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_id => 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])
|
||||
|
||||
# local_user.role = admin_role
|
||||
# local_user.sub_roles <<
|
||||
AttributeValue.create( :user => local_user, :attribute_field => info_profile.attribute_fields[0], :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 )
|
||||
#AttributeValue.create( :user_id => local_user.id, :attribute_field_id => sr_1_2.attribute_fields[0].id, :key => 'field', :en => 'Computer Architecture', :zh_tw => '計算機系統結構' )
|
||||
#AttributeValue.create( :user_id => local_user.id, :attribute_field_id => sr_1_2.attribute_fields[1].id, :key => 'department', :en => user_from_mid["ut_chi_m"], :zh_tw => user_from_mid["ut_chi_m"] )
|
||||
#AttributeValue.create( :user_id => local_user.id, :attribute_field_id => sr_1_2.attribute_fields[2].id, :key => 'speciality', :en => 'HSR', :zh_tw => '高鐵' )
|
||||
|
||||
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_CLIENT.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_id => 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 => local_user, :attribute_field => info_profile.attribute_fields[0], :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 = I18nVariable.find_or_create_by( :document_class => 'Role', :key => 'administrator', :en => 'Administrator', :zh_tw => '管理員' )
|
||||
var_1_1 = I18nVariable.find_or_create_by( :document_class => 'SubRole', :key => 'computer_center', :en => 'Computer Center', :zh_tw => '計算機中心', :parent_id => var_1.id )
|
||||
|
||||
admin_role = Role.find_or_create_by( :key => 'administrator',:built_in => true)
|
||||
admin_role.i18n_variable =var_1
|
||||
admin_role.save!
|
||||
|
||||
sub_role = admin_role.sub_roles.find_or_create_by(:key => 'computer_center', :built_in => true)
|
||||
sub_role.i18n_variable =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_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
|
|
@ -0,0 +1,14 @@
|
|||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<ul class="list">
|
||||
<li><%= link_to t('bulletin.announcement_list'), panel_announcement_back_end_bulletins_path if is_manager?%></li>
|
||||
<li><%= link_to t('bulletin.new_announcement_class'), panel_announcement_back_end_bulletin_categorys_path if is_manager?%></li>
|
||||
<li><%= link_to t('bulletin.fact_check_for_manager'), panel_announcement_back_end_fact_checks_path if is_manager?%></li>
|
||||
|
||||
<li><%= link_to t('bulletin.my_announcement'), panel_announcement_back_end_list_mine_path if is_sub_manager? %></li>
|
||||
<li><%= link_to t('bulletin.new_announcement'), new_panel_announcement_back_end_bulletin_path if is_sub_manager? %></li>
|
||||
|
||||
</ul>
|
|
@ -0,0 +1,15 @@
|
|||
<h1><%= bulletin_category.key %></h1>
|
||||
<table>
|
||||
<tr>
|
||||
<th><%= t('bulletin.status') %></th>
|
||||
<th><%= t('bulletin.category') %></th>
|
||||
<th><%= t('bulletin.title') %></th>
|
||||
<th><%= t('bulletin.postdate') %></th>
|
||||
<th><%= t('bulletin.deadline') %></th>
|
||||
<th><%= t('bulletin.action') %></th>
|
||||
</tr>
|
||||
|
||||
<% bulletin_category.bulletins.each do |post| %>
|
||||
<%= render :partial => 'panel/announcement/back_end/bulletins/bulletins', :locals => {:post => post,:fact_check_allow=>false} %>
|
||||
<% end %>
|
||||
</table>
|
|
@ -0,0 +1,12 @@
|
|||
<% content_for :secondary do %>
|
||||
<%= render :partial => '/panel/announcement/back_end/announcement_secondary' %>
|
||||
<% end -%>
|
||||
|
||||
<%= flash_messages %>
|
||||
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<%= render :partial => "list_table", :collection => @bulletin_categorys ,:as => :bulletin_category%>
|
Loading…
Reference in New Issue