competition: add manager

dev_auth
p31729568 5 years ago
parent eeb16d7e09
commit c8c6c7701d

@ -136,6 +136,33 @@ $(document).on('turbolinks:load', function(){
$('.sponsor-select').select2(selectOptions);
$('.allow-school-select').select2(selectOptions);
$('.manager-select').select2({
theme: 'bootstrap4',
placeholder: '请输入要添加的管理员姓名',
multiple: true,
minimumInputLength: 1,
ajax: {
delay: 500,
url: '/admins/users',
dataType: 'json',
data: function(params){
return { keyword: params.term };
},
processResults: function(data){
return { results: data.users }
}
},
templateResult: function (item) {
if(!item.id || item.id === '') return item.text;
return $("<span>" + item.real_name + " <span class='font-12'>" + item.school_name + ' ' + item.hidden_phone + "</span></span>");
},
templateSelection: function(item){
if (item.id) {
}
return item.real_name || item.text;
}
});
// 排行榜
//链接

@ -22,7 +22,7 @@ class Admins::CompetitionSettingsController < Admins::BaseController
def basic_form_params
params.permit(:identifier, :name, :sub_title, :start_time, :end_time, :mode,
:identifier, :bonus, :awards_count, :description, :course_id, :teach_start_time,
:teach_end_time, sponsor_schools: [], region_schools: [])
:teach_end_time, sponsor_schools: [], region_schools: [], manager_ids: [])
end
def nav_form_params

@ -5,6 +5,7 @@ class Competitions::CompetitionsController < Competitions::BaseController
before_action :allow_visit, except: [:index]
before_action :require_admin, only: [:update, :update_inform]
before_action :chart_visible, only: [:charts, :chart_rules]
before_action :check_manager_permission!, only: [:update_md_content]
def index
# 已上架 或者 即将上架
@ -152,6 +153,13 @@ class Competitions::CompetitionsController < Competitions::BaseController
render_forbidden unless (chart_module.present? && !chart_module.hidden) || admin_or_business?
end
def check_manager_permission!
return if current_user.admin_or_business?
return if current_competition.nearly_published? && current_competition.manager?(current_user)
render_forbidden
end
# 竞赛成绩导出
def chart_to_xlsx records, competition
@competition_head_cells = []

@ -26,6 +26,9 @@ class Competition < ApplicationRecord
has_many :sponsor_schools, -> { where(source: :sponsor) }, class_name: 'CompetitionSchool' # 主办方
has_many :region_schools, -> { where(source: :region) }, class_name: 'CompetitionSchool' # 开放范围
has_many :competition_managers, dependent: :destroy
has_many :managers, through: :competition_managers, source: :user
after_create :create_competition_modules
def mode_type
@ -75,6 +78,11 @@ class Competition < ApplicationRecord
status?
end
# 即将发布
def nearly_published?
!published? && published_at.present?
end
# 是否为个人赛
def personal?
competition_staffs.sum(:maximum).to_i == 1 || (competition_staffs.nil? && max_num == 1)
@ -134,6 +142,10 @@ class Competition < ApplicationRecord
# competition_awards.pluck(:num)&.sum > 0 ? competition_awards.pluck(:num)&.sum : 20
# end
def manager?(user)
user && competition_managers.exists?(user_id: user.id)
end
private
def get_module_name type

@ -0,0 +1,4 @@
class CompetitionManager < ApplicationRecord
belongs_to :user
belongs_to :competition
end

@ -34,6 +34,18 @@ class Admins::CompetitionBasicSettingService < ApplicationService
setting.save!
end
# 管理员设置
params[:manager_ids] = Array.wrap(params[:manager_ids]).map(&:to_i)
old_manager_ids = competition.competition_managers.pluck(:user_id)
new_manager_ids = params[:manager_ids] - old_manager_ids
delete_manager_ids = old_manager_ids - params[:manager_ids]
CompetitionManager.bulk_insert(*%i[user_id competition_id created_at updated_at]) do |worker|
new_manager_ids.each do |manager_id|
worker.add(user_id: manager_id, competition_id: competition.id)
end
end
competition.competition_managers.where(user_id: delete_manager_ids).delete_all
# 主办方设置
params[:sponsor_schools] = Array.wrap(params[:sponsor_schools]).map(&:to_i)
new_sponsor_school_ids = competition.sponsor_schools.pluck(:school_id)

@ -93,6 +93,16 @@
</div>
</div>
<div class="row align-items-center d-flex mb-2">
<div class="col-1 text-right">
管理员
</div>
<div class="col-5 text-left sponsorPanel">
<% manager_data = @competition.managers.map { |u| [u.name, u.id] } %>
<%= select_tag :manager_ids, options_for_select(manager_data, @competition.managers.map(&:id)), class: 'form-control manager-select', multiple: true %>
</div>
</div>
<div class="row align-items-center d-flex mb-2">
<div class="col-1 text-right">
主办方

@ -30,3 +30,7 @@ if @competition.mode == 2
json.member_of_course @user.member_of_course?(@competition.competition_mode_setting&.course)
end
json.permission do
json.editable @user.admin_or_business? || (@competition.nearly_published? && @competition.manager?(@user))
end

@ -0,0 +1,10 @@
class CreateCompetitionManagers < ActiveRecord::Migration[5.2]
def change
create_table :competition_managers do |t|
t.references :user
t.references :competition
t.timestamps
end
end
end

File diff suppressed because one or more lines are too long

@ -136184,6 +136184,33 @@ $(document).on('turbolinks:load', function(){
$('.sponsor-select').select2(selectOptions);
$('.allow-school-select').select2(selectOptions);
$('.manager-select').select2({
theme: 'bootstrap4',
placeholder: '请输入要添加的管理员姓名',
multiple: true,
minimumInputLength: 1,
ajax: {
delay: 500,
url: '/admins/users',
dataType: 'json',
data: function(params){
return { keyword: params.term };
},
processResults: function(data){
return { results: data.users }
}
},
templateResult: function (item) {
if(!item.id || item.id === '') return item.text;
return $("<span>" + item.real_name + " <span class='font-12'>" + item.school_name + ' ' + item.hidden_phone + "</span></span>");
},
templateSelection: function(item){
if (item.id) {
}
return item.real_name || item.text;
}
});
// 排行榜
//链接
Loading…
Cancel
Save