diff --git a/app/assets/javascripts/admins/glcc_pr_check.js b/app/assets/javascripts/admins/glcc_pr_check.js new file mode 100644 index 000000000..dee720fac --- /dev/null +++ b/app/assets/javascripts/admins/glcc_pr_check.js @@ -0,0 +1,2 @@ +// Place all the behaviors and hooks related to the matching controller here. +// All this logic will automatically be available in application.js. diff --git a/app/assets/stylesheets/admins/glcc_pr_check.scss b/app/assets/stylesheets/admins/glcc_pr_check.scss new file mode 100644 index 000000000..7dfa6e7cf --- /dev/null +++ b/app/assets/stylesheets/admins/glcc_pr_check.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the admins/glcc_pr_check controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/controllers/admins/glcc_pr_check_controller.rb b/app/controllers/admins/glcc_pr_check_controller.rb new file mode 100644 index 000000000..1d79ba802 --- /dev/null +++ b/app/controllers/admins/glcc_pr_check_controller.rb @@ -0,0 +1,32 @@ +class Admins::GlccPrCheckController < Admins::BaseController + def index + params[:sort_by] = params[:sort_by].presence || 'created_on' + params[:sort_direction] = params[:sort_direction].presence || 'desc' + examine_materials = Admins::GlccExamineMaterial.call(params) + @examine_materials = paginate examine_materials.includes(:glcc_student) + end + + def send_mail + year = if params[:date].present? + params[:date][:year] + end + if year.nil? + return redirect_to admins_glcc_pr_check_index_path + flash[:error] = "时间不能为空" + end + if params[:term].blank? + return redirect_to admins_glcc_pr_check_index_path + flash[:error] = "考核选项不能为空" + end + + examine_materials = GlccMediumTermExamineMaterial.where(\ + term: params[:term], + created_on: [Time.now.change(year:year).beginning_of_year .. Time.now.change(year:year).end_of_year] + ) + examine_materials.map{ |e| + e.send_mail + } + flash[:danger] = "#{year} 年 #{params[:term].to_i == 1 ? "中期考核": "结项考核"} PR 检测邮件已全部发送完毕,一共#{examine_materials.count}封邮件" + redirect_to admins_glcc_pr_check_index_path + end +end diff --git a/app/helpers/admins/glcc_pr_check_helper.rb b/app/helpers/admins/glcc_pr_check_helper.rb new file mode 100644 index 000000000..9934b83bf --- /dev/null +++ b/app/helpers/admins/glcc_pr_check_helper.rb @@ -0,0 +1,2 @@ +module Admins::GlccPrCheckHelper +end diff --git a/app/mailers/user_mailer.rb b/app/mailers/user_mailer.rb index 28bbccf63..a99948879 100644 --- a/app/mailers/user_mailer.rb +++ b/app/mailers/user_mailer.rb @@ -30,4 +30,11 @@ class UserMailer < ApplicationMailer def feedback_email(mail, title, content) mail(to: mail, subject: title, content_type: "text/html", body: content) end + + def glcc_pr_check_email(mail, title, name, content) + @content = content + @name = name + mail(to: mail, subject: title) + end + end diff --git a/app/models/glcc_medium_term_examine_material.rb b/app/models/glcc_medium_term_examine_material.rb new file mode 100644 index 000000000..70bed6b9a --- /dev/null +++ b/app/models/glcc_medium_term_examine_material.rb @@ -0,0 +1,85 @@ +# == Schema Information +# +# Table name: ignores +# +# student_reg_id +# task_id +# defence_video_url +# code_or_pr_url +# PPT_attachment_id +# term +# created_on +# updated_on +# is_delete +# round + +class GlccMediumTermExamineMaterial < ActiveRecord::Base + self.table_name = "glcc_medium_term_examine_material" + belongs_to :glcc_student, :class_name => :GlccRegistrationStudent, :foreign_key => "student_reg_id" + + def check_pr_url + state = [] + # code_or_pr_url = "https://www.gitlink.org.cn/Gitlink/forgeplus/pulls/337" + url_array = code_or_pr_url.split("/") + gitlink_index = url_array.index("www.gitlink.org.cn") || url_array.index("gitlink.org.cn") + pull_index = url_array.index("pulls") + + #发送没有在gitlink上提交PR的邮件 + unless gitlink_index.present? + state << 1 + end + + # 输入的地址有问题邮件内容 + unless pull_index == 5 + state << 2 + end + + project = Project.find_by(identifier: url_array[4]) + pr = PullRequest.where(project:project, gitea_number:url_array[6]) + + unless pr.present? + state << 3 + end + state + end + + + def send_mail + gcs = glcc_student + mail = gcs.mail + return if mail.nil? || code_or_pr_url.nil? + + state = check_pr_url + return unless state.present? + title = "2023年GitLink确实开源GLCC开源夏令营#{term == 1 ? "中期考核" : "结项考核"}提醒" + content = "" + state.map{|e| + content = content + number_to_content(e) + } + puts content + UserMailer.glcc_pr_check_email(mail,title, gcs.student_name, content).deliver_now + end + + def state_to_html + gcs = glcc_student + mail = gcs.mail + return "数据异常PR连接为空" if mail.nil? || code_or_pr_url.nil? + state = check_pr_url + content = "" + state.map{|e| + content = content + number_to_content(e) + } + content + end + + def number_to_content(num) + case num + when 1 + "

PR链接为非GitLink平台链接

" + when 2 + "

PR链接为GitLink平台非PR链接

" + when 3 + "

PR链接中的PR不存在

" + end + end +end diff --git a/app/models/glcc_registration_student.rb b/app/models/glcc_registration_student.rb new file mode 100644 index 000000000..3ea0c3134 --- /dev/null +++ b/app/models/glcc_registration_student.rb @@ -0,0 +1,22 @@ +# == Schema Information +# +# Table name: ignores +# user_id +# student_name +# school +# profession +# location +# grade +# phone +# mail +# created_on +# is_delete +# prove_attachment_id +# cancel_count +# round +# + +class GlccRegistrationStudent < ActiveRecord::Base + self.table_name = "glcc_registration_student" + has_many :examines, :class_name => :GlccMediumTermExamineMaterial, :foreign_key => "student_reg_id" +end diff --git a/app/queries/admins/glcc_examine_material.rb b/app/queries/admins/glcc_examine_material.rb new file mode 100644 index 000000000..4e8f2bea7 --- /dev/null +++ b/app/queries/admins/glcc_examine_material.rb @@ -0,0 +1,29 @@ +class Admins::GlccExamineMaterial < ApplicationQuery + include CustomSortable + + attr_reader :params + + sort_columns :created_on, default_direction: :desc + + def initialize(params) + @params = params + end + + def call + materials = GlccMediumTermExamineMaterial.all + + # term + term = params[:term] || [1,2] + if term.present? + materials = materials.where(term: term) + end + #year + year = if params[:date] + params[:date][:year] + end + year = year || Time.now.year + date = Time.now.change(year:year) + materials = materials.where(created_on: [date.beginning_of_year..date.end_of_year]) + custom_sort(materials, params[:sort_by], params[:sort_direction]) + end +end \ No newline at end of file diff --git a/app/views/admins/glcc_pr_check/_examine_material.html.erb b/app/views/admins/glcc_pr_check/_examine_material.html.erb new file mode 100644 index 000000000..6daf14546 --- /dev/null +++ b/app/views/admins/glcc_pr_check/_examine_material.html.erb @@ -0,0 +1,34 @@ + + + + + + + + + + + + + + + <% if examine_materials.present? %> + <% examine_materials.each_with_index do |user, index| %> + + + + + + + + + + + <% end %> + <% else %> + <%= render 'admins/shared/no_data_for_table' %> + <% end %> + +
序号昵称邮件地址视频地址PR地址考核阶段检测状态提交时间
<%= list_index_no((params[:page] || 1).to_i, index) %><%= user.glcc_student.student_name %><%= user.glcc_student.mail %> 查看视频 查看PR <%= user.term == 1 ? "中期考核" : "结项考核"%><%= user.state_to_html.html_safe %><%= user.created_on.strftime("%Y-%m-%d %H:%M")%>
+ +<%= render partial: 'admins/shared/paginate', locals: { objects: examine_materials } %> diff --git a/app/views/admins/glcc_pr_check/index.html.erb b/app/views/admins/glcc_pr_check/index.html.erb new file mode 100644 index 000000000..a70a09f6e --- /dev/null +++ b/app/views/admins/glcc_pr_check/index.html.erb @@ -0,0 +1,44 @@ +
+ <%= form_tag(admins_glcc_pr_check_index_path, method: :get, class: 'form-inline search-form flex-1', remote: true) do %> +
+ + <% status_options = [['中期考核',1], ['结项考核', 2]] %> + <%= select_tag(:term, options_for_select(status_options), class: 'form-control') %> +
+ +
+ + <%= select_year(Date.today, {field_name:"year"}, {class:"form-control"})%> + +
+ <%= submit_tag('搜索', class: 'btn btn-primary ml-3', 'data-disable-with': '搜索中...') %> + <% end %> + +
+ + + +
+ <%= render partial: 'examine_material', locals: { examine_materials: @examine_materials } %> +
+ + diff --git a/app/views/admins/glcc_pr_check/index.js.erb b/app/views/admins/glcc_pr_check/index.js.erb new file mode 100644 index 000000000..8bc043f70 --- /dev/null +++ b/app/views/admins/glcc_pr_check/index.js.erb @@ -0,0 +1 @@ +$('.glcc-examine-list-container').html("<%= j( render partial: 'examine_material', locals: { examine_materials: @examine_materials } ) %>"); \ No newline at end of file diff --git a/app/views/admins/shared/_sidebar.html.erb b/app/views/admins/shared/_sidebar.html.erb index fc2fe6068..481676b8f 100644 --- a/app/views/admins/shared/_sidebar.html.erb +++ b/app/views/admins/shared/_sidebar.html.erb @@ -57,6 +57,7 @@ <%= sidebar_item(EduSetting.get("glcc_apply_informations_admin_url"), '报名列表', icon: 'user', controller: 'root') %> <% end %> +
  • <%= sidebar_item(admins_glcc_pr_check_index_path, '考核PR检测', icon: 'edit', controller: 'admins-glcc_pr_check') %>
  • <% end %>
  • diff --git a/app/views/user_mailer/glcc_pr_check_email.html.erb b/app/views/user_mailer/glcc_pr_check_email.html.erb new file mode 100644 index 000000000..aa01d45bf --- /dev/null +++ b/app/views/user_mailer/glcc_pr_check_email.html.erb @@ -0,0 +1,71 @@ + + + + + 验证码发送 + + + + + +
    +
    +
    + + + +
    +
    +
    + +

    + 尊敬的<%=@name%>同学: +

    + +

    +   您好!经过一个多月的开发,GLCC开源编程夏令营终于迎来中期考核。为了确保您能够顺利通过考核,现对您提交的PR链接进行检测,发现存在以下问题: +

    + +
    + <%=@content.html_safe%> +
    + +

    +   您提交的PR链接的真实有效性对于后期的开发和奖金的发放至关重要,请您务必予以重视。请您尽快核查链接的有效性,并按照组委会要求提交中期考核材料。若确认链接无误,请忽略本邮件。​ +

    + +

    +   如有其他问题,请联系:glcc@ccf.org.cn +

    + +

    + GLCC组委会 +

    +

    + <%=Time.now.strftime('%Y年%m月%d日')%> +

    +
    +
    + www.gitlink.org.cn +
    +
    +
    + + diff --git a/config/routes.rb b/config/routes.rb index 0d04c498a..8297f5377 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -789,6 +789,12 @@ Rails.application.routes.draw do resources :glcc_news resources :pinned_forums end + resources :glcc_pr_check do + collection do + post :send_mail + end + end + resources :project_statistics, only: [:index] do collection do get :visits_static diff --git a/spec/controllers/admins/glcc_pr_check_controller_spec.rb b/spec/controllers/admins/glcc_pr_check_controller_spec.rb new file mode 100644 index 000000000..1dfcff7d4 --- /dev/null +++ b/spec/controllers/admins/glcc_pr_check_controller_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe Admins::GlccPrCheckController, type: :controller do + +end diff --git a/spec/helpers/admins/glcc_pr_check_helper_spec.rb b/spec/helpers/admins/glcc_pr_check_helper_spec.rb new file mode 100644 index 000000000..d47be7eda --- /dev/null +++ b/spec/helpers/admins/glcc_pr_check_helper_spec.rb @@ -0,0 +1,15 @@ +require 'rails_helper' + +# Specs in this file have access to a helper object that includes +# the Admins::GlccPrCheckHelper. For example: +# +# describe Admins::GlccPrCheckHelper do +# describe "string concat" do +# it "concats two strings with spaces" do +# expect(helper.concat_strings("this","that")).to eq("this that") +# end +# end +# end +RSpec.describe Admins::GlccPrCheckHelper, type: :helper do + pending "add some examples to (or delete) #{__FILE__}" +end