Merge branch 'develop' of http://git.trustie.net/jasder/forgeplus into develop

This commit is contained in:
sylor_huang@126.com 2020-04-16 09:45:18 +08:00
commit 599060e538
8 changed files with 56 additions and 37 deletions

View File

@ -14,6 +14,7 @@ class Admins::BaseController < ApplicationController
private
def require_login
User.current = User.find 1
return if User.current.logged?
redirect_to "/login?back_url=#{CGI::escape(request.fullpath)}"
@ -42,4 +43,4 @@ class Admins::BaseController < ApplicationController
def setup_laboratory
Laboratory.current = Laboratory.find_by_subdomain(request.subdomain) || Laboratory.find(1)
end
end
end

View File

@ -3,7 +3,7 @@ class Admins::LaboratoriesController < Admins::BaseController
default_sort('id', 'desc')
laboratories = Admins::LaboratoryQuery.call(params)
@laboratories = paginate laboratories.preload(:school, :laboratory_users)
@laboratories = paginate laboratories.preload(:laboratory_users)
end
def create
@ -82,4 +82,4 @@ class Admins::LaboratoriesController < Admins::BaseController
def setting_params
params.permit(:sync_course, :sync_subject, :sync_shixun)
end
end
end

46
app/models/school.rb Normal file
View File

@ -0,0 +1,46 @@
class School < ApplicationRecord
has_many :departments, dependent: :destroy
has_many :shixun_schools, :dependent => :destroy
has_many :shixuns, :through => :shixun_schools
has_many :ec_school_users, :dependent => :destroy
has_many :users, :through => :ec_school_users
has_many :ec_major_schools, :dependent => :destroy
has_many :ec_majors, :through => :ec_major_schools
has_many :school_daily_reports, dependent: :destroy
has_many :courses
has_many :customers, dependent: :destroy
has_one :partner, dependent: :destroy
has_many :apply_add_departments, dependent: :destroy
has_many :user_extensions, dependent: :nullify
after_create do
SyncTrustieJob.perform_later("school", 1) if allow_sync_to_trustie? #同步到trustie
end
# 学校管理员
def manager?(user)
ec_school_users.exists?(user_id: user.id)
end
# 专业管理员
def major_manager?(user)
relations = ec_major_schools.not_template.joins(:ec_major_school_users)
relations.exists?(ec_major_school_users: { user_id: user.id })
end
# 课程管理员
def course_manager?(user)
relations = ec_major_schools.not_template.joins(ec_years: :ec_course_users)
relations.exists?(ec_course_users: { user_id: user.id })
end
def manage_permission?(user)
manager?(user) || major_manager?(user) || course_manager?(user)
end
end

View File

@ -3,7 +3,7 @@ class UserExtension < ApplicationRecord
enum identity: { teacher: 0, student: 1, professional: 2, developer: 3, enterprise: 4, unselect: -1 }
belongs_to :user, touch: true
# belongs_to :school, optional: true
belongs_to :school, optional: true
# belongs_to :department, optional: true
# before_save :set_laboratory_school

View File

@ -1,4 +1,4 @@
<% school = laboratory.school %>
<% school = laboratory&.school %>
<td><%= list_index_no((params[:page] || 1).to_i, index) %></td>
<td class="text-left"><%= school&.name || 'EduCoder主站' %></td>
<td class="text-left">
@ -66,4 +66,4 @@
<% end %>
</div>
</div>
</td>
</td>

View File

@ -26,4 +26,4 @@
</tbody>
</table>
<%= render partial: 'admins/shared/paginate', locals: { objects: laboratories } %>
<%= render partial: 'admins/shared/paginate', locals: { objects: laboratories } %>

View File

@ -15,15 +15,6 @@
<ul class="list-unstyled components">
<li><%= sidebar_item(admins_path, '概览', icon: 'dashboard', controller: 'admins-dashboards') %></li>
<li>
<%= sidebar_item_group('#course-submenu', '课堂管理', icon: 'book') do %>
<li><%= sidebar_item(admins_course_lists_path, '课程列表', icon: 'list', controller: 'admins-course_lists') %></li>
<li><%= sidebar_item(admins_courses_path, '课堂列表', icon: 'clone', controller: 'admins-courses') %></li>
<!-- <li><%#= sidebar_item(admins_mirror_repositories_path, '镜像管理', icon: 'cubes', controller: 'admins-mirror_repositories') %></li>-->
<li><%= sidebar_item(admins_projects_path, '项目列表', icon: 'database', controller: 'admins-projects') %></li>
<% end %>
</li>
<li>
<%= sidebar_item_group('#schools-submenu', '单位管理', icon: 'building') do %>
<li><%= sidebar_item(admins_schools_path, '单位列表', icon: 'university', controller: 'admins-schools') %></li>
@ -45,13 +36,7 @@
<li><%= sidebar_item(admins_professional_authentications_path, '职业认证', icon: 'drivers-license', controller: 'admins-professional_authentications') %></li>
<li><%= sidebar_item(admins_department_applies_path, '部门审批', icon: 'newspaper-o', controller: 'admins-department_applies') %></li>
<li><%= sidebar_item(admins_unit_applies_path, '单位审批', icon: 'building-o', controller: 'admins-unit_applies') %></li>
<li><%= sidebar_item(admins_shixun_authorizations_path, '实训发布', icon: 'object-ungroup', controller: 'admins-shixun_authorizations') %></li>
<li><%= sidebar_item(admins_subject_authorizations_path, '实践课程发布', icon: 'object-group', controller: 'admins-subject_authorizations') %></li>
<li><%= sidebar_item(admins_library_applies_path, '教学案例发布', icon: 'language', controller: 'admins-library_applies') %></li>
<li><%= sidebar_item(admins_project_package_applies_path, '众包需求发布', icon: 'joomla', controller: 'admins-project_package_applies') %></li>
<li><%= sidebar_item(admins_video_applies_path, '视频发布', icon: 'film', controller: 'admins-video_applies') %></li>
<li><%= sidebar_item(admins_item_authentications_path, '试题发布', icon: 'question', controller: 'admins-item_authentications') %></li>
<li><%= sidebar_item(admins_examination_authentications_path, '试卷发布', icon: 'file-text-o', controller: 'admins-examination_authentications') %></li>
<% end %>
</li>
@ -77,8 +62,6 @@
<%= sidebar_item_group('#major-identification-submenu', '工程认证', icon: 'anchor') do %>
<li><%= sidebar_item(admins_major_informations_path, '本科专业目录', icon: 'outdent', controller: 'admins-major_informations') %></li>
<li><%= sidebar_item(admins_auth_schools_path, '认证单位列表', icon: 'th', controller: 'admins-auth_schools') %></li>
<li><%= sidebar_item(admins_graduation_standards_path, '毕业要求通用标准', icon: 'file-word-o', controller: 'admins-graduation_standards') %></li>
<li><%= sidebar_item(admins_ec_templates_path, '导入模板管理', icon: 'file-excel-o', controller: 'admins-ec_templates') %></li>
<% end %>
</li>

View File

@ -88,18 +88,7 @@
</div>
</div>
<div class="form-row">
<%= f.input :school_id, as: :hidden %>
<%= f.input :department_id, as: :hidden %>
<div class="form-group select optional col-md-2">
<%= f.label :school_name, label: '所属学校/单位' %>
<%= f.select :school_name, [@user.school_id], {}, class: 'form-control school-select optional' %>
</div>
<div class="form-group select optional col-md-2">
<%= f.label :department_name, label: '所属学院/部门' %>
<%= f.select :department_name, [@user.department_id], {}, class: 'form-control department-select optional' %>
</div>
</div>
</div>
<div class="mt-4"><h6>管理</h6></div>
@ -135,4 +124,4 @@
<%= link_to '取消', admins_users_path, class: 'btn btn-secondary px-4' %>
</div>
<% end %>
</div>
</div>