Merge branch 'dev_aliyun' of https://bdgit.educoder.net/Hjqreturn/educoder into dev_aliyun

dev_newshixunModel
hjm 5 years ago
commit 289766cbd8

@ -0,0 +1,4 @@
$(document).on('turbolinks:load', function() {
if ($('body.admins-schools-index-page').length > 0) {
}
});

@ -0,0 +1,3 @@
.admins-schools-index-page {
}

@ -0,0 +1,30 @@
class Admins::SchoolsController < Admins::BaseController
def index
params[:sort_by] ||= 'created_at'
params[:sort_direction] ||= 'desc'
schools = Admins::SchoolQuery.call(params)
@schools = paginate schools
school_ids = @schools.map(&:id)
@department_count = Department.where(school_id: school_ids).group(:school_id).count
end
def destroy
users = User.joins(:user_extension).where(user_extensions: { school_id: current_school.id })
ActiveRecord::Base.transaction do
users.update_all(profile_completed: false)
current_school.destroy!
end
render_delete_success
end
private
def current_school
@_current_school ||= School.find(params[:id])
end
end

@ -14,6 +14,7 @@ class ApplicationController < ActionController::Base
#before_action :check_account #before_action :check_account
DCODES = %W(2 3 4 5 6 7 8 9 a b c f e f g h i j k l m n o p q r s t u v w x y z) DCODES = %W(2 3 4 5 6 7 8 9 a b c f e f g h i j k l m n o p q r s t u v w x y z)
OPENKEY = "79e33abd4b6588941ab7622aed1e67e8"
helper_method :current_user helper_method :current_user
@ -246,6 +247,16 @@ class ApplicationController < ActionController::Base
User.current = find_current_user User.current = find_current_user
uid_logger("user_setup: " + (User.current.logged? ? "#{User.current.try(:login)} (id=#{User.current.try(:id)})" : "anonymous")) uid_logger("user_setup: " + (User.current.logged? ? "#{User.current.try(:login)} (id=#{User.current.try(:id)})" : "anonymous"))
# 开放课程通过链接访问的用户
if !User.current.logged? && !params[:chinaoocTimestamp].blank? && !params[:websiteName].blank? && !params[:chinaoocKey].blank?
content = "#{OPENKEY}#{params[:websiteName]}#{params[:chinaoocTimestamp]}"
if Digest::MD5.hexdigest(content) == params[:chinaoocKey]
user = User.open_class_user
start_user_session(user) if user
User.current = user
end
end
if !User.current.logged? && Rails.env.development? if !User.current.logged? && Rails.env.development?
User.current = User.find 1 User.current = User.find 1
end end

@ -18,10 +18,18 @@ module Util::FileManage
File.exist?(disk_filename(source_type, source_id)) File.exist?(disk_filename(source_type, source_id))
end end
def exists?(source)
File.exist?(disk_filename(source.class, source.id))
end
def disk_file_url(source_type, source_id) def disk_file_url(source_type, source_id)
File.join('/images', relative_path, "#{source_type}", "#{source_id}") File.join('/images', relative_path, "#{source_type}", "#{source_id}")
end end
def source_disk_file_url(source)
File.join('/images', relative_path, "#{source.class}", "#{source.id}")
end
def disk_auth_filename(source_type, source_id, type) def disk_auth_filename(source_type, source_id, type)
File.join(storage_path, "#{source_type}", "#{source_id}#{type}") File.join(storage_path, "#{source_type}", "#{source_id}#{type}")
end end

@ -5,7 +5,7 @@ class Department < ApplicationRecord
has_many :member_users, through: :department_members, source: :user has_many :member_users, through: :department_members, source: :user
has_many :user_extensions, dependent: :nullify has_many :user_extensions, dependent: :nullify
has_many :apply_add_departments has_many :apply_add_departments, dependent: :destroy
scope :without_deleted, -> { where(is_delete: false) } scope :without_deleted, -> { where(is_delete: false) }

@ -17,6 +17,7 @@ class School < ApplicationRecord
has_many :partners, dependent: :destroy has_many :partners, dependent: :destroy
has_many :apply_add_departments, dependent: :destroy has_many :apply_add_departments, dependent: :destroy
has_many :user_extensions, dependent: :nullify
# 学校管理员 # 学校管理员
def manager?(user) def manager?(user)

@ -610,6 +610,29 @@ class User < ApplicationRecord
admin? || business? admin? || business?
end end
# 149课程的评审用户数据创建包含创建课堂学生
def open_class_user
user = User.find_by(login: "OpenClassUser")
unless user
ActiveRecord::Base.transaction do
user_params = {status: 1, login: "OpenClassUser", lastname: "开放课程",
nickname: "开放课程", professional_certification: 1, certification: 1, grade: 0,
password: "12345678", phone: "11122223333", profile_completed: 1}
user = User.create!(user_params)
UserExtension.create!(user_id: user.id, gender: 0, school_id: 117, :identity => 1, :student_id => "openclassuser")
subject = Subject.find_by(id: 149)
if subject
subject.courses.each do |course|
CourseMember.create!(course_id: course.id, role: 4, user_id: user.id) if !course.course_students.exists?(user_id: user.id)
end
end
end
end
user
end
protected protected
def validate_password_length def validate_password_length
# 管理员的初始密码是5位 # 管理员的初始密码是5位

@ -0,0 +1,23 @@
class Admins::SchoolQuery < ApplicationQuery
include CustomSortable
attr_reader :params
sort_columns :users_count, :created_at, default_by: :created_at, default_direction: :desc
def initialize(params)
@params = params
end
def call
schools = School.all
keyword = strip_param(:keyword)
schools = schools.where('schools.name LIKE ?', "%#{keyword}%") if keyword
schools = schools.joins(:user_extensions).group(:id)
schools = schools.select('schools.*, COUNT(*) AS users_count')
custom_sort schools, params[:sort_by], params[:sort_direction]
end
end

@ -0,0 +1,16 @@
<% define_admin_breadcrumbs do %>
<% add_admin_breadcrumb('单位列表') %>
<% end %>
<div class="box search-form-container school-list-form">
<%= form_tag(admins_schools_path, method: :get, class: 'form-inline search-form flex-1', remote: true) do %>
<%= text_field_tag(:keyword, params[:keyword], class: 'form-control col-sm-2 ml-3', placeholder: '部门名称检索') %>
<%= submit_tag('搜索', class: 'btn btn-primary ml-3', 'data-disable-with': '搜索中...') %>
<% end %>
<%#= javascript_void_link '新建单位', class: 'btn btn-primary', data: { toggle: 'modal', target: '.admin-create-school-modal' } %>
</div>
<div class="box school-list-container">
<%= render partial: 'admins/schools/shared/list', locals: { schools: @schools } %>
</div>

@ -0,0 +1 @@
$('.school-list-container').html("<%= j(render partial: 'admins/schools/shared/list', locals: { schools: @schools }) %>");

@ -0,0 +1,48 @@
<table class="table table-hover text-center school-list-table">
<thead class="thead-light">
<tr>
<th width="6%">ID</th>
<th width="6%">LOGO</th>
<th width="8%">标识码</th>
<th width="14%" class="text-left">单位名称</th>
<th width="6%">地区</th>
<th width="6%">城市</th>
<th width="16%">详细地址</th>
<th width="6%"><%= sort_tag('用户数', name: 'users_count', path: admins_schools_path) %></th>
<th width="6%">部门数</th>
<th width="12%"><%= sort_tag('创建时间', name: 'created_at', path: admins_schools_path) %></th>
<th width="14%">操作</th>
</tr>
</thead>
<tbody>
<% if schools.present? %>
<% schools.each do |school| %>
<tr class="school-item-<%= school.id %>">
<td><%= school.id %></td>
<td>
<% if Util::FileManage.exists?(school) %>
<%= image_tag(Util::FileManage.source_disk_file_url(school).to_s + "?#{Time.now.to_i}", width: 40, height: 40, class: 'preview-image') %>
<% else %>
<%= content_tag(:span, '--', class: 'text-secondary') %>
<% end %>
</td>
<td><%= display_text school.identifier %></td>
<td class="text-left"><%= school.name %></td>
<td><%= school.province %></td>
<td><%= school.city %></td>
<td class="text-left"><%= school.address %></td>
<td><%= school.users_count %></td>
<td><%= @department_count.fetch(school.id, 0) %></td>
<td><%= school.created_at&.strftime('%Y-%m-%d %H:%M') %></td>
<td>
<%= delete_link '删除', admins_school_path(school, element: ".school-item-#{school.id}"), class: 'delete-school-action' %>
</td>
</tr>
<% end %>
<% else %>
<%= render 'admins/shared/no_data_for_table' %>
<% end %>
</tbody>
</table>
<%= render partial: 'admins/shared/paginate', locals: { objects: schools } %>

@ -31,6 +31,7 @@
<li> <li>
<%= sidebar_item_group('#schools-submenu', '单位管理', icon: 'building') do %> <%= sidebar_item_group('#schools-submenu', '单位管理', icon: 'building') do %>
<li><%= sidebar_item(admins_schools_path, '单位列表', icon: 'university', controller: 'admins-schools') %></li>
<li><%= sidebar_item(admins_departments_path, '部门列表', icon: 'sitemap', controller: 'admins-departments') %></li> <li><%= sidebar_item(admins_departments_path, '部门列表', icon: 'sitemap', controller: 'admins-departments') %></li>
<% end %> <% end %>
</li> </li>

@ -926,6 +926,7 @@ Rails.application.routes.draw do
resources :mirror_scripts, only: [:index, :new, :create, :edit, :update, :destroy] resources :mirror_scripts, only: [:index, :new, :create, :edit, :update, :destroy]
end end
resources :choose_mirror_repositories, only: [:new, :create] resources :choose_mirror_repositories, only: [:new, :create]
resources :schools, only: [:index, :destroy]
resources :departments, only: [:index, :create, :edit, :update, :destroy] do resources :departments, only: [:index, :create, :edit, :update, :destroy] do
resource :department_member, only: [:create, :update, :destroy] resource :department_member, only: [:create, :update, :destroy]
post :merge, on: :collection post :merge, on: :collection

Loading…
Cancel
Save