From 59ff646a4ff4f240835ff6beead4278fe0f8cc87 Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Sat, 13 Apr 2019 11:25:28 +0800 Subject: [PATCH 01/12] =?UTF-8?q?=E6=9C=AC=E5=9C=B0=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E5=88=9D=E5=A7=8B=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/welcome_controller.rb | 11 +++++++++++ config/routes.rb | 1 + 2 files changed, 12 insertions(+) diff --git a/app/controllers/welcome_controller.rb b/app/controllers/welcome_controller.rb index c6fa78d9..06602a5c 100644 --- a/app/controllers/welcome_controller.rb +++ b/app/controllers/welcome_controller.rb @@ -30,6 +30,17 @@ class WelcomeController < ApplicationController require 'simple_xlsx_reader' 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) + def local_init + LocalShixun.delete_all + LocalMirrorRepository.delete_all + LocalShixunTagRepertoire.delete_all + LocalChallenge.delete_all + LocalTestSet.delete_all + LocalChallengeTag.delete_all + render :json => {status: 0, message: "success"} + end + + def shixun_to_local identifiers = params[:identifiers].split(",") shixuns = Shixun.where(identifier: identifiers) diff --git a/config/routes.rb b/config/routes.rb index ea70b6a2..47a052db 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -283,6 +283,7 @@ RedmineApp::Application.routes.draw do ## oauth相关 get 'welcome/ccf' => 'welcome#ccf' get 'welcome/shixun_to_local' => 'welcome#shixun_to_local' get 'welcome/local_to_shixun' => 'welcome#local_to_shixun' + get 'welcome/local_init' => 'welcome#local_init' # get 'competitions/home' => 'competitions#home' # get 'competitions/hn' => 'competitions#index' From 98c5bcca6e3b200e7901faa9c8cfe30000492753 Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Sat, 13 Apr 2019 18:26:07 +0800 Subject: [PATCH 02/12] local to shixun --- app/controllers/welcome_controller.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/app/controllers/welcome_controller.rb b/app/controllers/welcome_controller.rb index 06602a5c..00bab5b6 100644 --- a/app/controllers/welcome_controller.rb +++ b/app/controllers/welcome_controller.rb @@ -73,7 +73,7 @@ class WelcomeController < ApplicationController if shixun.challenges.present? shixun.challenges.each do |challenge| new_challenge = LocalChallenge.new - new_challenge.attributes = challenge.attributes.dup.except("id","shixun_id","user_id") + new_challenge.attributes = challenge.attributes.dup.except("id","shixun_id","user_id", "test_set_score") new_challenge.local_shixun_id = local_shixun.id new_challenge.save! # 评测题,选择题暂时不考虑 @@ -109,6 +109,7 @@ class WelcomeController < ApplicationController def local_to_shixun ActiveRecord::Base.transaction do + shixun_list = [] LocalShixun.find_each do |local_shixun| identifier = generate_identifier shixun = Shixun.create!(name: local_shixun.name, description: local_shixun.description, user_id: User.current.id, @@ -177,8 +178,9 @@ class WelcomeController < ApplicationController end end end - render :json => {status: 0, message: "success", identifier: shixun.identifier} + shixun_list << shixun.identifier end + render :json => {status: 0, message: "success", identifier: shixun_list} end end From a3e3fa096566e648e729a68b21b94c61b9200d79 Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Sat, 13 Apr 2019 18:30:00 +0800 Subject: [PATCH 03/12] .. --- app/controllers/welcome_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/welcome_controller.rb b/app/controllers/welcome_controller.rb index 00bab5b6..c9d41c0a 100644 --- a/app/controllers/welcome_controller.rb +++ b/app/controllers/welcome_controller.rb @@ -153,7 +153,7 @@ class WelcomeController < ApplicationController if local_challenges.present? local_challenges.each do |local_challenge| new_challenge = Challenge.new - new_challenge.attributes = local_challenge.attributes.dup.except("id","local_shixun_id","user_id") + new_challenge.attributes = local_challenge.attributes.dup.except("id","local_shixun_id","user_id", "test_set_score") new_challenge.user_id = User.current.id new_challenge.shixun_id = shixun.id new_challenge.save! From 83f0ec016b4134c2ba60189b8f8168130963adf3 Mon Sep 17 00:00:00 2001 From: huang Date: Mon, 15 Apr 2019 10:01:27 +0800 Subject: [PATCH 04/12] =?UTF-8?q?=E6=B5=8B=E8=AF=95=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/tasks/users.rake | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/tasks/users.rake b/lib/tasks/users.rake index d8ae770e..bfa0678c 100644 --- a/lib/tasks/users.rake +++ b/lib/tasks/users.rake @@ -89,7 +89,7 @@ task :add_test_users => :environment do (1..1000).each do |i| no = sprintf("%04d", i) - phone = "1560731#{no}" + phone = "5160731#{no}" us = UsersService.new user = us.register phone: phone, password: 'edu12345678' @@ -109,7 +109,7 @@ task :add_test_users => :environment do lastname: lastname, nickname: '', sex: 0, - mail: "educoder#{no}@qq.com", + mail: "00educoder#{no}@qq.com", identity: 1, te_technical_title: 0, pro_technical_title: 0, From 52af31be38f369835361ae057112f5f4b632f432 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Mon, 22 Apr 2019 09:59:50 +0800 Subject: [PATCH 05/12] =?UTF-8?q?=E8=B6=85=E7=BA=A7=E7=AE=A1=E7=90=86?= =?UTF-8?q?=E5=91=98=E7=9A=84=E5=AF=BC=E5=87=BA=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/managements_controller.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/controllers/managements_controller.rb b/app/controllers/managements_controller.rb index b7e1bd56..11796cb0 100644 --- a/app/controllers/managements_controller.rb +++ b/app/controllers/managements_controller.rb @@ -3345,7 +3345,7 @@ end end @users = User.where(:id => user_id).where("#{sql}").includes(:apply_actions, user_extensions: [:department, :school]).order("last_login_on desc") - @xls_users = @users.reorder("created_on desc").limit(1000) #导出excel用户 + @xls_users = @users.reorder("created_on desc").limit(3000) #导出excel用户 @page = (params['page'] || 1).to_i @users_count = @users.count @limit = 20 @@ -4176,7 +4176,7 @@ end sheet1 = book.create_worksheet :name => "course" blue = Spreadsheet::Format.new :color => :blue, :weight => :bold, :size => 10 sheet1.row(0).default_format = blue - sheet1.row(0).concat(["ID","课堂名称","成员","资源","普通作业"," 实训作业","试卷","私有","状态","创建者单位","创建者","动态时间"]) + sheet1.row(0).concat(["ID","课堂名称","成员","资源","普通作业"," 实训作业","试卷","私有","状态","创建者单位","创建者","动态时间","创建时间"]) count_row = 1 courses.each do |course| school = course.teacher.try(:user_extensions).try(:school).try(:name).blank? ? "--" : course.teacher.school_name @@ -4193,6 +4193,7 @@ end sheet1[count_row,9] = school sheet1[count_row,10] = teacher_name sheet1[count_row,11] = format_time(course.updatetime) + sheet1[count_row,12] = format_time(course.created_at) count_row += 1 end book.write xls_report From f82c7b26f8e403e4832eca8c6f40d1df94f13396 Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Wed, 24 Apr 2019 11:22:19 +0800 Subject: [PATCH 06/12] =?UTF-8?q?=E6=9C=AC=E5=9C=B0=E7=89=88=E4=BC=98?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/welcome_controller.rb | 2 +- app/views/layouts/_logined_header.html.erb | 83 ++++++------------- app/views/layouts/_unlogin_header.html.erb | 11 --- app/views/layouts/base_local.html.erb | 31 +++++++ .../javascripts/educoder/edu_application.js | 12 --- 5 files changed, 58 insertions(+), 81 deletions(-) create mode 100644 app/views/layouts/base_local.html.erb diff --git a/app/controllers/welcome_controller.rb b/app/controllers/welcome_controller.rb index c9d41c0a..729a9564 100644 --- a/app/controllers/welcome_controller.rb +++ b/app/controllers/welcome_controller.rb @@ -218,7 +218,7 @@ class WelcomeController < ApplicationController @tea_users = User.where(homepage_teacher: 1).includes(:user_extensions).limit(10).order("experience desc") @stu_users = User.includes(:user_extensions).where(user_extensions: {identity: 1}).limit(10).order("experience desc") - render :layout => 'educoder' + render :layout => 'base_local' end # 自动导入用户 diff --git a/app/views/layouts/_logined_header.html.erb b/app/views/layouts/_logined_header.html.erb index 0cfd2916..9068a95b 100644 --- a/app/views/layouts/_logined_header.html.erb +++ b/app/views/layouts/_logined_header.html.erb @@ -6,25 +6,8 @@
  • "><%= link_to "翻转课堂", courses_path %>
  • "><%= link_to "开发社区", shixuns_path %>
  • - - <% careers = Career.published.order("created_at asc") %> - <% if careers.present? %> -
  • " style="cursor: auto;"> -

    职业路径

    - -
  • - <% end %>
  • "><%= link_to "竞赛", competitions_path %>
  • "><%= link_to "问答", forums_path %>
  • - <% if User.current.ec_school.present? %> -
  • " id="ec_banner"> - <%= link_to "认证", department_ecs_path(:school_id => User.current.ec_school) %> -
  • - <% end %> -
    - <%= link_to (image_tag(url_to_avatar(User.current), :width =>"34", :height => "34", :class => "radius mt13", :nhname => "avatar_image", :alt=>"头像", :id => "nh_user_logo")), user_path(User.current),:class => "fl" %> -
      - <%= User.current.show_name %> -
    • <%= link_to '我的课堂', user_path(User.current) %>
    • -
    • <%= link_to '我的实训', user_path(User.current, :type => 'a_shixun') %>
    • -
    • <%= link_to '我的实训课程', user_path(User.current, :type => 'a_path') %>
    • - <% if User.current.partner.present? %> -
    • <%= link_to '客户管理', partner_list_cooperate_path(User.current.partner) %>
    • - <% end %> -
    • <%= link_to '我的项目', user_path(User.current, :type => 'a_project') %>
    • + <% if User.current.logged? %> +
      + <%= link_to (image_tag(url_to_avatar(User.current), :width =>"34", :height => "34", :class => "radius mt13", :nhname => "avatar_image", :alt=>"头像", :id => "nh_user_logo")), user_path(User.current),:class => "fl" %> +
        + <%= User.current.show_name %> +
      • <%= link_to '我的课堂', user_path(User.current) %>
      • +
      • <%= link_to '我的实训', user_path(User.current, :type => 'a_shixun') %>
      • +
      • <%= link_to '我的实训课程', user_path(User.current, :type => 'a_path') %>
      • +
      • <%= link_to '我的项目', user_path(User.current, :type => 'a_project') %>
      • +
      • <%= link_to '账号管理', my_account_path %>
      • +
      • <%= link_to '退出', signout_path %>
      • +
      +
      + <% else %> + + <%= link_to '登录', signin_path, :class => "mr5 color-white" %> + + <%= link_to '注册', user_join_path, :class => "ml5 color-white" %> + + <% end %> - <% if User.current.department_members.count > 0 %> -
    • <%= link_to '学院统计', statistics_college_path(User.current.department_members.first.try(:department)) %>
    • - <% end %> -
    • <%= link_to '账号管理', my_account_path %>
    • -
    • <%= link_to '退出', signout_path %>
    • -
    -
    - -
    - - - - - <% new_tidings_count = User.current.tidings.where("created_at > '#{User.current.onclick_time.onclick_time}'").count %> - <% new_pri_message_count = User.current.private_messages.where("created_at > '#{User.current.onclick_time.onclick_time}'").count %> - <% count = new_tidings_count + new_pri_message_count %> - <% if count > 0 %> - <%= count > 99 ? "99+" : count %> - - <% end %> -
    @@ -126,11 +95,11 @@ <% notice = SystemUpdateNotice.last %> <% if @noticed_update || ((User.current.certification == 1 || params[:controller] != "welcome") && notice.present? && notice.end_time > Time.now && notice.start_time >= (Time.now - 21600) && User.current.user_system_notices.where(:notice_type => notice.notice_type).count == 0) %> - var htmlvalue = "<%= escape_javascript(render :partial => 'account/user_update_notice', :locals => {:notice => notice})%>"; - pop_box_new(htmlvalue, 500, 380); - <% UserSystemNotice.create(:user_id => User.current.id, :notice_type => notice.notice_type) %> + var htmlvalue = "<%= escape_javascript(render :partial => 'account/user_update_notice', :locals => {:notice => notice})%>"; + pop_box_new(htmlvalue, 500, 380); + <% UserSystemNotice.create(:user_id => User.current.id, :notice_type => notice.notice_type) %> <%# elsif notice.present? && notice.end_time < Time.now %> - <%# notice.destroy %> + <%# notice.destroy %> <% end %> }); diff --git a/app/views/layouts/_unlogin_header.html.erb b/app/views/layouts/_unlogin_header.html.erb index d970fffc..72dd2731 100644 --- a/app/views/layouts/_unlogin_header.html.erb +++ b/app/views/layouts/_unlogin_header.html.erb @@ -8,17 +8,6 @@
  • "><%= link_to "开发社区", shixuns_path %>
  • - <% careers = Career.published.order("created_at asc") %> - <% if careers.present? %> -
  • " style="cursor: auto;"> -

    职业路径

    - -
  • - <% end %>
  • "><%= link_to "竞赛", competitions_path %>
  • "><%= link_to "问答", forums_path %>
  • diff --git a/app/views/layouts/base_local.html.erb b/app/views/layouts/base_local.html.erb new file mode 100644 index 00000000..5ce69147 --- /dev/null +++ b/app/views/layouts/base_local.html.erb @@ -0,0 +1,31 @@ + + + + + <%= h html_title %> + + + <%= csrf_meta_tag %> + <%= favicon %> + <%= javascript_edu_index_heads %> + <%= stylesheet_link_tag 'educoder/edu-main', 'educoder/edu-all', 'educoder/magic-check' %> + + + +
    +
    + <%= render 'layouts/logined_header' %> +
    +
    + <%= yield %> +
    + <%= render :partial => 'layouts/footer' %> +
    + + + +<%= javascript_include_tag 'educoder/edu_application','educoder/jquery.raty' %> + + diff --git a/public/javascripts/educoder/edu_application.js b/public/javascripts/educoder/edu_application.js index 862f9d41..a94d72c2 100644 --- a/public/javascripts/educoder/edu_application.js +++ b/public/javascripts/educoder/edu_application.js @@ -15,18 +15,6 @@ $(function(){ var searchText = result[1] $('#search-input').val(searchText) } - // 未报名用户登录时弹框 - // console.log(Cookies.get('enroll_status')); - // if(Cookies.get('enroll_status') == 0){ - // Cookies.remove('enroll_status'); - // var html='
    '+ - // '
    '+ - // ''+ - // ''+ - // '立即报名'+ - // '
    '; - // $(".newContainer").append(html); - // } }); function CloseBox(){ From cdfda26c99586006eea5da7fd36302350bdef5d5 Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Wed, 24 Apr 2019 15:28:01 +0800 Subject: [PATCH 07/12] =?UTF-8?q?=E7=99=BB=E5=BD=95=E9=A1=B5=E9=9D=A2?= =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/account/login.html.erb | 9 --------- app/views/layouts/login.html.erb | 18 ++---------------- 2 files changed, 2 insertions(+), 25 deletions(-) diff --git a/app/views/account/login.html.erb b/app/views/account/login.html.erb index a4af9782..83b6b152 100644 --- a/app/views/account/login.html.erb +++ b/app/views/account/login.html.erb @@ -73,15 +73,6 @@ <% end %> - - <%= render :partial => "account/copyright_info" %> diff --git a/app/views/layouts/login.html.erb b/app/views/layouts/login.html.erb index 818ba099..e8ad5ae9 100644 --- a/app/views/layouts/login.html.erb +++ b/app/views/layouts/login.html.erb @@ -7,23 +7,9 @@ <%= csrf_meta_tag %> <%= favicon %> - <%= stylesheet_link_tag 'jquery/jquery-ui-1.9.2','educoder/edu-main','educoder/edu-all', 'css/font-awesome','educoder/magic-check.css' %> - <%#= javascript_heads %> - <%= javascript_include_tag 'jquery-1.8.3-ui-1.9.2-ujs-2.0.3', 'jquery.colorbox-min', 'edu/application', 'educoder/edu_application','educoder/edu_account','educoder/avatars' %> - <%#= stylesheet_link_tag 'css/edu-showpage','css/edu-index', 'css/font-awesome', 'css/edu-common', 'css/edu-login', 'css/edu-public', 'css/edu-popup' %> - <%#= javascript_include_tag 'edu/application', "bigdata" %> - - -
    From 978fbf47e54abe40c64a6b1df10ebb87d05350b9 Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Wed, 24 Apr 2019 16:04:14 +0800 Subject: [PATCH 08/12] =?UTF-8?q?=E4=B8=AA=E4=BA=BA=E4=B8=BB=E9=A1=B5?= =?UTF-8?q?=E7=9A=84=E4=B8=80=E4=BA=9B=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/layouts/base_edu_user.html.erb | 23 +++-------------------- 1 file changed, 3 insertions(+), 20 deletions(-) diff --git a/app/views/layouts/base_edu_user.html.erb b/app/views/layouts/base_edu_user.html.erb index 293b9426..6143c8ca 100644 --- a/app/views/layouts/base_edu_user.html.erb +++ b/app/views/layouts/base_edu_user.html.erb @@ -7,31 +7,13 @@ <%= csrf_meta_tag %> <%= favicon %> - <%= stylesheet_link_tag 'jquery/jquery-ui-1.9.2','css/font-awesome','educoder/edu-main','educoder/edu-all','educoder/magic-check.css','/assets/iconfont/iconfont.css', :media => 'all' %> <%= javascript_heads %> - <%= javascript_include_tag 'edu/application', 'educoder/edu_application','educoder/edu_account',"educoder/edu_user" %> - <%= yield :header_tags -%> - - - -
    - <% if User.current.logged? %> - <%= render :partial => 'layouts/logined_header' %> - <% else%> - <%= render :partial => 'layouts/unlogin_header' %> - <% end%> + <%= render :partial => 'layouts/logined_header' %>
    @@ -55,4 +37,5 @@
    +<%= javascript_include_tag 'educoder/edu_application','educoder/edu_account',"educoder/edu_user" %> \ No newline at end of file From 085e1ec44d817b348c557b84e6ad19e895760720 Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Fri, 26 Apr 2019 09:56:27 +0800 Subject: [PATCH 09/12] =?UTF-8?q?=E9=A6=96=E9=A1=B5=E7=9A=84=E4=B8=80?= =?UTF-8?q?=E4=BA=9B=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/helpers/application_helper.rb | 11 ++++++++++- app/views/layouts/base_edu_user.html.erb | 17 ++++++++--------- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 707ff571..ede8c6b6 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -3990,7 +3990,7 @@ module ApplicationHelper # Returns the javascript tags that are included in the html layout head def javascript_heads - tags = javascript_include_tag('jquery-1.8.3-ui-1.9.2-ujs-2.0.3', 'application', 'jquery.colorbox-min', 'baiduTemplate') + tags = javascript_include_tag('jquery-1.8.3-ui-1.9.2-ujs-2.0.3', 'jquery.colorbox-min', 'baiduTemplate') unless User.current.pref.warn_on_leaving_unsaved == '0' tags << "\n".html_safe + javascript_tag("$(window).load(function(){ warnLeavingUnsaved('#{escape_javascript l(:text_warn_on_leaving_unsaved)}'); });") end @@ -4004,6 +4004,15 @@ module ApplicationHelper tags end + # 临时本地版 + def javascript_heads_local + tags = javascript_include_tag('jquery-1.8.3-ui-1.9.2-ujs-2.0.3', 'jquery.colorbox-min') + unless User.current.pref.warn_on_leaving_unsaved == '0' + tags << "\n".html_safe + javascript_tag("$(window).load(function(){ warnLeavingUnsaved('#{escape_javascript l(:text_warn_on_leaving_unsaved)}'); });") + end + tags + end + def hubspot_head tags = javascript_include_tag('hubspot/messenger.min', 'hubspot/messenger-theme-future') tags << stylesheet_link_tag('hubspot/messenger', 'hubspot/messenger-theme-future', 'hubspot/messenger-theme-flat') diff --git a/app/views/layouts/base_edu_user.html.erb b/app/views/layouts/base_edu_user.html.erb index 6143c8ca..37ba85ca 100644 --- a/app/views/layouts/base_edu_user.html.erb +++ b/app/views/layouts/base_edu_user.html.erb @@ -7,25 +7,23 @@ <%= csrf_meta_tag %> <%= favicon %> - <%= stylesheet_link_tag 'jquery/jquery-ui-1.9.2','css/font-awesome','educoder/edu-main','educoder/edu-all','/assets/iconfont/iconfont.css', :media => 'all' %> - + <%= stylesheet_link_tag 'css/font-awesome','educoder/edu-main','educoder/edu-all','/assets/iconfont/iconfont.css', :media => 'all' %> -
    -
    +
    +
    <%= render :partial => 'layouts/logined_header' %>
    -
    +
    <%= yield %>
    - + <%= render :partial => 'users/returnTop_btn' %>
    - - <%#= render :partial => 'layouts/public_left_info' %> + <%= render :partial => 'layouts/footer' %>
    @@ -37,5 +35,6 @@
    -<%= javascript_include_tag 'educoder/edu_application','educoder/edu_account',"educoder/edu_user" %> +<%= javascript_heads_local %> +<%= javascript_include_tag 'edu/application', 'educoder/edu_application',"educoder/edu_user" %> \ No newline at end of file From c140b70818685e7409c13550a1dfcd917bccb9a9 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Fri, 26 Apr 2019 10:07:27 +0800 Subject: [PATCH 10/12] =?UTF-8?q?=E5=90=88=E4=BD=9C=E4=BC=99=E4=BC=B4?= =?UTF-8?q?=E6=94=B9=E7=89=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/managements_controller.rb | 49 ++++++++++--------- app/models/customer.rb | 5 +- app/models/partner.rb | 5 +- app/models/partner_customer.rb | 5 ++ app/models/school.rb | 4 +- .../_partner_customer_list.html.erb | 2 +- app/views/managements/_partner_list.html.erb | 8 ++- app/views/managements/delete_partner.js.erb | 1 + app/views/managements/partners.html.erb | 6 +-- config/routes.rb | 1 + ...20190425072918_create_partner_customers.rb | 9 ++++ ...90425073328_modify_partner_and_customer.rb | 29 +++++++++++ spec/factories/partner_customers.rb | 5 ++ spec/models/partner_customer_spec.rb | 5 ++ 14 files changed, 97 insertions(+), 37 deletions(-) create mode 100644 app/models/partner_customer.rb create mode 100644 app/views/managements/delete_partner.js.erb create mode 100644 db/migrate/20190425072918_create_partner_customers.rb create mode 100644 db/migrate/20190425073328_modify_partner_and_customer.rb create mode 100644 spec/factories/partner_customers.rb create mode 100644 spec/models/partner_customer_spec.rb diff --git a/app/controllers/managements_controller.rb b/app/controllers/managements_controller.rb index b7e1bd56..1c454424 100644 --- a/app/controllers/managements_controller.rb +++ b/app/controllers/managements_controller.rb @@ -1191,7 +1191,7 @@ end if params[:search].blank? @partners = Partner.includes(:school).order("partners.created_at desc") else - @partners = Partner.where("name like ? ", "%#{params[:search]}%").includes(:school).order("partners.created_at desc") + @partners = Partner.includes(:school).where("schools.name like ? ", "%#{params[:search]}%").order("partners.created_at desc") end @current_partner = nil @@ -1212,6 +1212,14 @@ end end + def delete_partner + partner = Partner.find params[:partner_id] + partner.destroy + @partners = Partner.includes(:school).order("partners.created_at desc") + @current_partner = nil + end + + # 添加客户 def customers_list @search = params[:search] @@ -1219,11 +1227,10 @@ end partner_id = params[:partner_id] @partner = Partner.find partner_id @customers = @partner.customers - if @customers.present? - @schools = School.where("(partner_id != ? or partner_id is NULL) and customer_id is NULL", @partner.id) - else - @schools = School.where("customer_id is null and (partner_id != ? or partner_id is NULL)", @partner.id) - end + existed_school_ids = @customers.pluck(:school_id) + existed_school_ids = existed_school_ids.present? ? existed_school_ids.join(",") : -1 + @schools = School.where("id not in (#{existed_school_ids})") + if params[:search] @schools = @schools.where("name like ?", "%#{@search}%") end @@ -1247,13 +1254,14 @@ end def add_customers school_ids = params[:school_ids] - if school_ids.length > 0 + partner_id = params[:partner_id] + if school_ids.length > 0 && partner_id.present? school_ids.each do |s| school = School.where("id = ?",s).first if school.present? - customer = Customer.new(partner_id: params[:partner_id]) + customer = Customer.new(school_id: s) customer.save! - school.update_attributes(:customer_id => customer.id) + PartnerCustomer.create(partner_id: partner_id,customer_id: customer.id ) end end render :json => {status: 1, message: "创建成功!"} @@ -1262,17 +1270,20 @@ end def delete_customers if params[:customer] - customer = Customer.where(id: params[:customer]).first - @current_partner = customer.partner - customer.school.update_attributes(:customer_id => nil) + customer = Customer.find(params[:customer]) + @current_partner = Partner.find(params[:partner_id]) customer.destroy end end + # 添加合作伙伴弹框数据 def all_partners @search = params[:search] @province = params[:province] - @schools = School.where("partner_id IS NULL") + # 已经选过的合作伙伴不能再再列表中显示 + used_school_ids = Partner.pluck(:school_id) + used_school_ids = used_school_ids.blank? ? -1 : used_school_ids.join(",") + @schools = School.where("id not in (#{used_school_ids})") if params[:search] @schools = @schools.where("name like ?", "%#{@search}%") @@ -1296,26 +1307,20 @@ end end end - def add_partner school_ids = params[:school_ids] if school_ids.length > 0 school_ids.each do |s| - school = School.where("id = ?",s).first - if school.present? && school.partner_id.nil? - partner = Partner.new(name: school.name) + old_partner = Partner.where(:school_id => s) + if old_partner.blank? + partner = Partner.new(school_id: s) partner.save - school.update_attributes(:partner_id => partner.id) end end end render :json => {status: 1, message: "创建成功!"} end - - - - # 删除部门管理员 def delete_depart_member DepartmentMember.where(:department_id => params[:depart], :user_id => params[:user_id]).destroy_all diff --git a/app/models/customer.rb b/app/models/customer.rb index 673acd20..14b4d710 100644 --- a/app/models/customer.rb +++ b/app/models/customer.rb @@ -1,6 +1,7 @@ class Customer < ActiveRecord::Base default_scope :order => 'customers.created_at desc' - belongs_to :partner - has_one :school + has_many :partners, :through => :partner_customers + has_many :partner_customers, :dependent => :destroy + belongs_to :school has_many :users end diff --git a/app/models/partner.rb b/app/models/partner.rb index 217bc1a7..31920e53 100644 --- a/app/models/partner.rb +++ b/app/models/partner.rb @@ -2,7 +2,8 @@ class Partner < ActiveRecord::Base # attr_accessible :name, :active attr_accessor :active - has_one :school - has_many :customers + belongs_to :school + has_many :customers, :through => :partner_customers + has_many :partner_customers, :dependent => :destroy has_many :users end diff --git a/app/models/partner_customer.rb b/app/models/partner_customer.rb new file mode 100644 index 00000000..c9894cc9 --- /dev/null +++ b/app/models/partner_customer.rb @@ -0,0 +1,5 @@ +class PartnerCustomer < ActiveRecord::Base + # attr_accessible :title, :body + belongs_to :partner + belongs_to :customer +end diff --git a/app/models/school.rb b/app/models/school.rb index 8d377e97..021048fb 100644 --- a/app/models/school.rb +++ b/app/models/school.rb @@ -16,8 +16,8 @@ class School < ActiveRecord::Base has_many :ec_majors, :through => :ec_major_schools has_many :ec_major_schools, :dependent => :destroy - belongs_to :partner - belongs_to :customer + has_many :partners, :dependent => :destroy + has_many :customers, :dependent => :destroy # banner图片信息 has_many :school_images, :dependent => :destroy diff --git a/app/views/managements/_partner_customer_list.html.erb b/app/views/managements/_partner_customer_list.html.erb index e8f643fd..bbdb2ea8 100644 --- a/app/views/managements/_partner_customer_list.html.erb +++ b/app/views/managements/_partner_customer_list.html.erb @@ -10,7 +10,7 @@ <%= index + 1 %> <%= customer.school.name %> - 删除 diff --git a/app/views/managements/_partner_list.html.erb b/app/views/managements/_partner_list.html.erb index 0ee0a60f..cddf4e9d 100644 --- a/app/views/managements/_partner_list.html.erb +++ b/app/views/managements/_partner_list.html.erb @@ -1,14 +1,12 @@ <% @partners.each_with_index do |partner,index| %>
  • - <%= link_to "#{partner.name}", partners_managements_path(:partner => partner), :class => "#{partner.id == @current_partner.id ? 'active' : ''} fl" %> - <% if false %> + <%= link_to "#{partner.school.name}", partners_managements_path(:partner => partner), :class => "#{@current_partner && partner.id == @current_partner.id ? 'active' : ''} fl" %> - <% end %>
  • <% end %> diff --git a/app/views/managements/delete_partner.js.erb b/app/views/managements/delete_partner.js.erb new file mode 100644 index 00000000..276ae32b --- /dev/null +++ b/app/views/managements/delete_partner.js.erb @@ -0,0 +1 @@ +$("#partner_list").html("<%= j(render :partial => "partner_list") %>") \ No newline at end of file diff --git a/app/views/managements/partners.html.erb b/app/views/managements/partners.html.erb index 153ab505..06ac63b0 100644 --- a/app/views/managements/partners.html.erb +++ b/app/views/managements/partners.html.erb @@ -6,7 +6,7 @@
    - <%= link_to "+添加",all_partners_managements_path,remote:true,class:"color-blue addOperation" %> + <%= link_to "+添加", all_partners_managements_path,remote:true,class:"color-blue addOperation" %>
      <%= render :partial => "partner_list" %>
    @@ -31,7 +31,7 @@ } - function delPartners(){ - delete_confirm_box_2("","确定删除合作伙伴?"); + function delPartners(url){ + delete_confirm_box_2(url,"确定删除合作伙伴?"); } \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 9c70df82..73cbadc6 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -719,6 +719,7 @@ RedmineApp::Application.routes.draw do ## oauth相关 post 'update_level_for_subject' post :add_customers delete :delete_customers + delete :delete_partner get :customers_list get :school_report, controller: 'managements::schools', action: 'statistics' end diff --git a/db/migrate/20190425072918_create_partner_customers.rb b/db/migrate/20190425072918_create_partner_customers.rb new file mode 100644 index 00000000..69d13714 --- /dev/null +++ b/db/migrate/20190425072918_create_partner_customers.rb @@ -0,0 +1,9 @@ +class CreatePartnerCustomers < ActiveRecord::Migration + def change + create_table :partner_customers do |t| + t.references :partner + t.references :customer + t.timestamps + end + end +end diff --git a/db/migrate/20190425073328_modify_partner_and_customer.rb b/db/migrate/20190425073328_modify_partner_and_customer.rb new file mode 100644 index 00000000..c4f7b97a --- /dev/null +++ b/db/migrate/20190425073328_modify_partner_and_customer.rb @@ -0,0 +1,29 @@ +class ModifyPartnerAndCustomer < ActiveRecord::Migration + def up + add_column :customers, :school_id, :integer + add_column :partners, :school_id, :integer + + schools = School.where("customer_id is not null or partner_id is not null") + + schools.each do |school| + if school.customer_id + customer = Customer.find_by_id(school.customer_id) + customer.update_column(:school_id, school.id) if customer + end + if school.partner_id + partner = Partner.find_by_id(school.partner_id) + partner.update_column(:school_id, school.id) if partner + end + end + + # 迁移关联关系 + customers = Customer.where(nil) + customers.each do |customer| + PartnerCustomer.create(partner_id: customer.partner_id, customer_id: customer.id) + end + + end + + def down + end +end diff --git a/spec/factories/partner_customers.rb b/spec/factories/partner_customers.rb new file mode 100644 index 00000000..6327b7ca --- /dev/null +++ b/spec/factories/partner_customers.rb @@ -0,0 +1,5 @@ +FactoryGirl.define do + factory :partner_customer do + + end +end diff --git a/spec/models/partner_customer_spec.rb b/spec/models/partner_customer_spec.rb new file mode 100644 index 00000000..6dc614cf --- /dev/null +++ b/spec/models/partner_customer_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe PartnerCustomer, :type => :model do + pending "add some examples to (or delete) #{__FILE__}" +end From 95e1bc759c099be0faecded8adcecf7b0611f78b Mon Sep 17 00:00:00 2001 From: Alec Zhou Date: Fri, 26 Apr 2019 16:49:48 +0800 Subject: [PATCH 11/12] =?UTF-8?q?=E5=AE=8C=E6=88=90=E4=BA=86openi=E5=8D=95?= =?UTF-8?q?=E7=82=B9=E7=99=BB=E5=BD=95=E7=9A=84=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Gemfile | 2 + app/controllers/application_controller.rb | 21 ++++++++ app/controllers/oauth_controller.rb | 58 +++++++++++++++++++++- app/controllers/shixuns_controller.rb | 2 + app/controllers/subjects_controller.rb | 2 + app/models/openi.rb | 8 +++ config/routes.rb | 3 ++ db/migrate/20190426072359_create_openis.rb | 15 ++++++ spec/factories/openis.rb | 11 ++++ spec/models/openi_spec.rb | 5 ++ 10 files changed, 126 insertions(+), 1 deletion(-) create mode 100644 app/models/openi.rb create mode 100644 db/migrate/20190426072359_create_openis.rb create mode 100644 spec/factories/openis.rb create mode 100644 spec/models/openi_spec.rb diff --git a/Gemfile b/Gemfile index a5bf637a..b9e1b4e2 100644 --- a/Gemfile +++ b/Gemfile @@ -60,6 +60,8 @@ gem 'kaminari' gem 'elasticsearch-model' gem 'elasticsearch-rails' +gem 'oauth2' + #Ruby 2.2+ has removed test/unit from the core library. if RUBY_VERSION>='2.2' gem 'test-unit', '~> 3.0' diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 5e107d39..22888abb 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1120,4 +1120,25 @@ class ApplicationController < ActionController::Base Time.now < Time.new(2019, 4, 23, 2) end + # 获取Oauth Client + def get_client(site) + client_id = Redmine::Configuration['client_id'] + client_secret = Redmine::Configuration['client_secret'] + + OAuth2::Client.new(client_id, client_secret, site: site) + end + + def handle_openi_request + site = Redmine::Configuration['openi_domain'] + root_url = Redmine::Configuration['educoder_domain'] + get_code_url = "/oauth/get_code" + original_url = request.original_url + + client = get_client(site) + redirect_uri = "#{root_url}#{get_code_url}" + authorize_url = client.auth_code.authorize_url(redirect_uri: redirect_uri) + authorize_url = authorize_url + "&gen_code=true&state=1&original_url=#{original_url}" + + redirect_to authorize_url + end end diff --git a/app/controllers/oauth_controller.rb b/app/controllers/oauth_controller.rb index 54f15c43..64867d55 100644 --- a/app/controllers/oauth_controller.rb +++ b/app/controllers/oauth_controller.rb @@ -1,6 +1,5 @@ #encoding: utf-8 class OauthController < ApplicationController - require include ApplicationHelper before_filter :user_setup @@ -152,8 +151,65 @@ class OauthController < ApplicationController render json: user_info.to_json end + ####--Start-- 获取Openi的授权码,access_token,以及用户信息。为在openi登录的用户创建相关的educoder用户 #### + IDENTITY_SITE = Redmine::Configuration['openi_domain'] + ROOT_URL = Redmine::Configuration['educoder_domain'] + DEFAULT_PASSWORD = "a12345678" + TOKEN_CALL_BACK = "/oauth/get_token_callback" + USER_INFO = "/oauth/userinfo" + + def get_code + # 从OpenI发过来的回调中获取授权码 + code = params[:code] + + # 利用授权码从OpenI这里获取access_token + client = get_client(IDENTITY_SITE) + redirect_uri = "#{ROOT_URL}#{TOKEN_CALL_BACK}" + access_token_hash = client.auth_code.get_token(code, redirect_uri: redirect_uri).to_hash + + # 利用access_token获取OpenI的用户信息 + access_token = access_token_hash[:access_token] + get_info_url = "#{IDENTITY_SITE}#{USER_INFO}?access_token=#{access_token}" + response = HTTParty.get(get_info_url) + body_json = JSON.parse response.body + + openi_user_id = body_json['token'] + avatar_url = body_json['avatar_url'] + login = body_json['login'] + name = body_json['name'] + email = body_json['email'] + + # 根据获取的用户信息来查询数据库,如已经存在对应的Educoder用户,则直接访问用户要访问的实训页面,否则为其创建用户后再访问实训页面 + openi = Openi.find_by_login(login) + unless openi + ActiveRecord::Base.transaction do + user = User.new(lastname: name, mail: email, mail_notification: email) + user.login = custom_openi_login(login) + user.password = DEFAULT_PASSWORD + user.save! + + UserExtensions.create!(user_id: user.id, school_id: School.first.id, identity: 4, gender: 0) + + UserDayCertification.create!(user_id: user.id, status: 1) + + openi = Openi.create!(user_id: user.id, openi_user_id: openi_user_id, avatar_url: avatar_url, login: login, name: name, email: email) + end + end + + self.logged_user = openi.user + original_url = params[:original_url] + redirect_to original_url + end + + def get_token_callback + end + ####--End-- 获取Openi的授权码,access_token,以及用户信息。为在openi登录的用户创建相关的educoder用户 #### private + # 为了保证新创建的用户用户名不与系统中已存在的用户冲突,加上 _openi 后缀 + def custom_openi_login(login) + login + "_openi" + end def require_login require "base64" diff --git a/app/controllers/shixuns_controller.rb b/app/controllers/shixuns_controller.rb index b2761b60..0572f8fa 100644 --- a/app/controllers/shixuns_controller.rb +++ b/app/controllers/shixuns_controller.rb @@ -2,6 +2,8 @@ # REDO: 创建版本库权限控制 class ShixunsController < ApplicationController layout 'base_shixun' + # 如要添加或修改before_filter时,请将handle_openi_request这个before_filter放至第一位 + before_filter :handle_openi_request, if: -> {URI(request.referer).host == 'openi.org.cn' && !current_user.logged?} before_filter :require_login, :except => [:ghook, :download_file, :show, :index] before_filter :check_authentication, :except => [:ghook, :download_file, :show, :index] before_filter :find_shixun, :except => [ :index, :new, :create, :index, :search, :shixun_courses, :new_disscuss, :shixun_migrate, :qrcode, :download_file, :departments, :get_mirror_script, :send_message_to_administrator] diff --git a/app/controllers/subjects_controller.rb b/app/controllers/subjects_controller.rb index a59747aa..2db71ee7 100644 --- a/app/controllers/subjects_controller.rb +++ b/app/controllers/subjects_controller.rb @@ -1,6 +1,8 @@ # encoding: utf-8 class SubjectsController < ApplicationController layout 'base_subject' + # 如要添加或修改before_filter时,请将handle_openi_request这个before_filter放至第一位 + before_filter :handle_openi_request, if: -> {URI(request.referer).host == 'openi.org.cn' && !current_user.logged?} before_filter :require_login, :except => [:show, :index] before_filter :check_authentication, :except => [:show, :index] before_filter :find_subject, :except => [:index, :new, :create, :create_subject, :new_subject, :append_to_stage, :send_to_course] diff --git a/app/models/openi.rb b/app/models/openi.rb new file mode 100644 index 00000000..44e7ac83 --- /dev/null +++ b/app/models/openi.rb @@ -0,0 +1,8 @@ +class Openi < ActiveRecord::Base + attr_accessible :allow, :avatar_url, :email, :login, :name, :openi_user_id, :user_id + belongs_to :user + + def self.find_by_login(login) + Openi.where(login: login).first + end +end diff --git a/config/routes.rb b/config/routes.rb index 73cbadc6..9e0879e7 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -33,6 +33,9 @@ RedmineApp::Application.routes.draw do ## oauth相关 match 'oauth/cb', to: 'oauth#test_callback', :via => :get match 'oauth/userinfo', to: 'oauth#get_userinfo', :via => :get + match 'oauth/get_code', to: 'oauth#get_code', :via => :get + match 'oauth/get_token_callback', to: 'oauth#get_token_callback', :via => :get + get 'ecloud/ecloud_login', to: 'ecloud#ecloud_login_callback' post 'ecloud/bs_new', to: 'ecloud#bs_new' post 'ecloud/bs_update', to: 'ecloud#bs_update' diff --git a/db/migrate/20190426072359_create_openis.rb b/db/migrate/20190426072359_create_openis.rb new file mode 100644 index 00000000..501b3fe7 --- /dev/null +++ b/db/migrate/20190426072359_create_openis.rb @@ -0,0 +1,15 @@ +class CreateOpenis < ActiveRecord::Migration + def change + create_table :openis do |t| + t.integer :user_id + t.integer :openi_user_id + t.string :login + t.string :avatar_url + t.string :name + t.string :email + t.integer :allow + + t.timestamps + end + end +end diff --git a/spec/factories/openis.rb b/spec/factories/openis.rb new file mode 100644 index 00000000..06f8944d --- /dev/null +++ b/spec/factories/openis.rb @@ -0,0 +1,11 @@ +FactoryGirl.define do + factory :openi do + user_id 1 + openi_user_id 1 + login "MyString" + avatar_url "MyString" + name "MyString" + email "MyString" + allow 1 + end +end diff --git a/spec/models/openi_spec.rb b/spec/models/openi_spec.rb new file mode 100644 index 00000000..96e0c489 --- /dev/null +++ b/spec/models/openi_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe Openi, :type => :model do + pending "add some examples to (or delete) #{__FILE__}" +end From 7104eee0c5d331168c30c0b458a5ca8202e6ebe4 Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Fri, 26 Apr 2019 16:55:44 +0800 Subject: [PATCH 12/12] =?UTF-8?q?=E8=BF=90=E8=90=A5=E4=BA=BA=E5=91=98?= =?UTF-8?q?=E6=9D=83=E9=99=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/application_controller.rb | 7 +++++++ app/controllers/courses_controller.rb | 2 +- app/controllers/managements_controller.rb | 3 +-- app/controllers/shixuns_controller.rb | 1 + app/controllers/users_controller.rb | 2 +- app/models/open_source_project.rb | 7 ------- app/services/games_service.rb | 2 +- db/migrate/20190426020414_add_business_to_user.rb | 5 +++++ 8 files changed, 17 insertions(+), 12 deletions(-) create mode 100644 db/migrate/20190426020414_add_business_to_user.rb diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 5e107d39..5bbe534e 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -362,6 +362,13 @@ class ApplicationController < ActionController::Base true end + # 运营人员 + def require_business + unless (User.current.business? || User.current.admin?) + render_403 + end + end + def deny_access User.current.logged? ? render_403 : require_login end diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index b65f2219..421e5da3 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -1635,7 +1635,7 @@ class CoursesController < ApplicationController @course_modules = @course.course_modules.where(:hidden => 0) course_module_type = @course_modules.map(&:module_type) - @is_teacher = User.current.allowed_to?(:as_teacher,@course) || User.current.admin? + @is_teacher = User.current.allowed_to?(:as_teacher,@course) || User.current.admin? || User.current.business? if User.current.member_of_course?(@course) && !@is_teacher member = @course.members.where(:user_id => User.current.id).first if member.try(:course_group_id).to_i == 0 diff --git a/app/controllers/managements_controller.rb b/app/controllers/managements_controller.rb index 11796cb0..cc883b9c 100644 --- a/app/controllers/managements_controller.rb +++ b/app/controllers/managements_controller.rb @@ -1,6 +1,6 @@ # encoding: utf-8 class ManagementsController < ApplicationController - before_filter :require_admin + before_filter :require_business layout 'base_management' include ManagementsHelper include SortHelper @@ -63,7 +63,6 @@ class ManagementsController < ApplicationController # 工程认证视频导入模板 def ec_template @template = EcTemplate.where(nil) - end def add_template diff --git a/app/controllers/shixuns_controller.rb b/app/controllers/shixuns_controller.rb index b2761b60..f6578f18 100644 --- a/app/controllers/shixuns_controller.rb +++ b/app/controllers/shixuns_controller.rb @@ -10,6 +10,7 @@ class ShixunsController < ApplicationController before_filter :view_allow, :only => [:collaborators, :propaedeutics, :shixun_discuss, :ranking_list] before_filter :require_manager, :only => [ :settings, :add_script, :publish, :collaborators_delete, :shixun_members_added, :add_collaborators, :update, :destroy] before_filter :validation_email, :only => [:new] + before_filter :require_admin, :only => [:destroy] # 移动云ToC模式权限控制 # before_filter :ecloud_auth, :except => [:show, :index] diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index d13db006..df2ce0cd 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -274,7 +274,7 @@ class UsersController < ApplicationController # 私信 def private_messages - if User.current == @user || User.current.admin? + if User.current == @user || User.current.admin? || User.current.business? @onclick_time = User.current.onclick_time.onclick_time User.current.onclick_time.update_attribute(:onclick_time, Time.now) @messages = PrivateMessage.find_by_sql("SELECT ui.* FROM (SELECT * FROM private_messages WHERE STATUS != 2 AND user_id = #{@user.id} ORDER BY id DESC) ui GROUP BY ui.target_id ORDER BY ui.send_time DESC") diff --git a/app/models/open_source_project.rb b/app/models/open_source_project.rb index 0adc0957..93b91fbb 100644 --- a/app/models/open_source_project.rb +++ b/app/models/open_source_project.rb @@ -121,13 +121,6 @@ class OpenSourceProject < ActiveRecord::Base ApplyProjectMaster.delete_all "apply_type = '#{self.class}' AND apply_id = #{self.id} AND user_id = #{user.id}" end - def admin?(user) - if user.admin? or ApplyProjectMaster.find(:all, :conditions => ["user_id = ? and apply_type = 'OpenSourceProject' and apply_id = ? and status = ?", user.id, self.id, 2]).present? - return true - else - return false - end - end def reset_counters! self.class.reset_counters!(id) diff --git a/app/services/games_service.rb b/app/services/games_service.rb index 8573c683..bddb03b7 100644 --- a/app/services/games_service.rb +++ b/app/services/games_service.rb @@ -17,7 +17,7 @@ class GamesService myshixun = Myshixun.min.find(game.myshixun_id) shixun = Shixun.min.find(myshixun.shixun_id) - unless (myshixun.user_id == current_user.id || current_user.admin? || current_user.id == shixun.try(:user_id) || current_user.is_certification_teacher) + unless (myshixun.user_id == current_user.id || current_user.admin? || current_user.business? || current_user.id == shixun.try(:user_id) || current_user.is_certification_teacher) return{:status => 403} end game_challenge = Challenge.min.find(game.challenge_id) diff --git a/db/migrate/20190426020414_add_business_to_user.rb b/db/migrate/20190426020414_add_business_to_user.rb new file mode 100644 index 00000000..c9ab35ca --- /dev/null +++ b/db/migrate/20190426020414_add_business_to_user.rb @@ -0,0 +1,5 @@ +class AddBusinessToUser < ActiveRecord::Migration + def change + add_column :users, :business, :boolean, :default => false + end +end