From 32bb3c60442e692f6e778e07098e01d8271e1fd7 Mon Sep 17 00:00:00 2001 From: p31729568 Date: Fri, 16 Aug 2019 15:05:09 +0800 Subject: [PATCH 1/8] video feature add teacher check --- app/controllers/users/base_controller.rb | 6 ++++++ app/controllers/users/video_auths_controller.rb | 2 +- app/controllers/users/videos_controller.rb | 2 +- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/app/controllers/users/base_controller.rb b/app/controllers/users/base_controller.rb index 706b77802..7dd5ae024 100644 --- a/app/controllers/users/base_controller.rb +++ b/app/controllers/users/base_controller.rb @@ -26,6 +26,12 @@ class Users::BaseController < ApplicationController render_forbidden end + def require_auth_teacher! + return if user.admin_or_business? || observed_user.certification_teacher? + + render_forbidden + end + def page_value params[:page].to_i <= 0 ? 1 : params[:page].to_i end diff --git a/app/controllers/users/video_auths_controller.rb b/app/controllers/users/video_auths_controller.rb index d7950f873..0eec4dffb 100644 --- a/app/controllers/users/video_auths_controller.rb +++ b/app/controllers/users/video_auths_controller.rb @@ -1,5 +1,5 @@ class Users::VideoAuthsController < Users::BaseController - before_action :private_user_resources! + before_action :private_user_resources!, :require_auth_teacher! def create result = Videos::CreateAuthService.call(observed_user, create_params) diff --git a/app/controllers/users/videos_controller.rb b/app/controllers/users/videos_controller.rb index e4dffec23..1df726c0c 100644 --- a/app/controllers/users/videos_controller.rb +++ b/app/controllers/users/videos_controller.rb @@ -1,5 +1,5 @@ class Users::VideosController < Users::BaseController - before_action :private_user_resources! + before_action :private_user_resources!, :require_auth_teacher! helper_method :current_video From 43d8f62f0fcec73b1872d90bafc6133fce3b6602 Mon Sep 17 00:00:00 2001 From: p31729568 Date: Fri, 16 Aug 2019 15:28:24 +0800 Subject: [PATCH 2/8] fix --- app/controllers/users/base_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/users/base_controller.rb b/app/controllers/users/base_controller.rb index 7dd5ae024..eb6b98048 100644 --- a/app/controllers/users/base_controller.rb +++ b/app/controllers/users/base_controller.rb @@ -27,7 +27,7 @@ class Users::BaseController < ApplicationController end def require_auth_teacher! - return if user.admin_or_business? || observed_user.certification_teacher? + return if current_user.admin_or_business? || observed_user.certification_teacher? render_forbidden end From 965f9b65f86f800465a12c1062cd5a6383c0cad3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=A8=E6=A0=91=E6=98=8E?= <775174143@qq.com> Date: Fri, 16 Aug 2019 15:50:33 +0800 Subject: [PATCH 3/8] =?UTF-8?q?=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- public/react/config/webpack.config.dev.js | 2 +- .../modules/courses/Resource/Fileslistitem.js | 25 ++++++++++++++----- .../courses/coursesPublic/Showoldfiles.js | 19 ++++++++++++-- 3 files changed, 37 insertions(+), 9 deletions(-) diff --git a/public/react/config/webpack.config.dev.js b/public/react/config/webpack.config.dev.js index 6e78fd410..510bcaa4f 100644 --- a/public/react/config/webpack.config.dev.js +++ b/public/react/config/webpack.config.dev.js @@ -29,7 +29,7 @@ const env = getClientEnvironment(publicUrl); module.exports = { // You may want 'eval' instead if you prefer to see the compiled output in DevTools. // See the discussion in https://github.com/facebookincubator/create-react-app/issues/343.s - devtool: "cheap-module-eval-source-map", + // devtool: "cheap-module-eval-source-map", // 开启调试 // These are the "entry points" to our application. // This means they will be the "root" imports that are included in JS bundle. diff --git a/public/react/src/modules/courses/Resource/Fileslistitem.js b/public/react/src/modules/courses/Resource/Fileslistitem.js index f0aec7f64..5832770f1 100644 --- a/public/react/src/modules/courses/Resource/Fileslistitem.js +++ b/public/react/src/modules/courses/Resource/Fileslistitem.js @@ -36,7 +36,16 @@ class Fileslistitem extends Component{ course_id:coursesId }, }).then((result)=>{ - if(result.data.attachment_histories.length===0){ + + if(result.data.attachment_histories.length===0){ + if(result.data.is_pdf===true){ + axios.get(result.data.url).then((result)=>{ + var binaryData = []; + binaryData.push(result.data); + this.url =window.URL.createObjectURL(new Blob(binaryData, {type:"application/pdf"})); + window.open(this.url); + }) + }else{ let link = document.createElement('a'); document.body.appendChild(link); link.href = result.data.url; @@ -46,12 +55,15 @@ class Fileslistitem extends Component{ evt.initEvent("click", false, false); link.dispatchEvent(evt); document.body.removeChild(link); + } }else{ - this.setState({ - Showoldfiles:true, - allfiles:result.data - }) - } + this.setState({ + Showoldfiles:true, + allfiles:result.data + }) + } + + }).catch((error)=>{ console.log(error) }) @@ -144,6 +156,7 @@ class Fileslistitem extends Component{ loadtype={this.state.Loadtype} />:""} { + axios.get(url).then((result)=>{ + var binaryData = []; + binaryData.push(result.data); + this.url =window.URL.createObjectURL(new Blob(binaryData, {type:"application/pdf"})); + window.open(this.url); + }) + } render(){ let {visible,allfiles}=this.props; @@ -175,7 +183,10 @@ class Showoldfiles extends Component{
  • - {allfiles.title} + {allfiles.is_pdf===false? + {allfiles.title}: + this.showfiless(allfiles.url)} >{allfiles.title} + } 当前版本
  • @@ -191,7 +202,11 @@ class Showoldfiles extends Component{
  • - {item.title} + + {allfiles.is_pdf===false? + {item.title}: + this.showfiless(item.url)} >{item.title} + }
  • From 7b99a1a5c5f85a8adf74c9430f05cd2bfedd8307 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Fri, 16 Aug 2019 15:55:22 +0800 Subject: [PATCH 4/8] =?UTF-8?q?=E8=B5=84=E6=BA=90=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E9=99=84=E4=BB=B6=E7=9A=84pdf=E5=88=A4=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/files_controller.rb | 7 +------ app/models/attachment.rb | 11 +++++++++++ .../_attachment_history.json.jbuilder | 1 + app/views/attachments/_attachment_small.json.jbuilder | 3 ++- app/views/files/histories.json.jbuilder | 2 +- 5 files changed, 16 insertions(+), 8 deletions(-) diff --git a/app/controllers/files_controller.rb b/app/controllers/files_controller.rb index bcfed25dd..2cfa61cc9 100644 --- a/app/controllers/files_controller.rb +++ b/app/controllers/files_controller.rb @@ -260,12 +260,7 @@ class FilesController < ApplicationController return normal_status(-2, "该课程下没有id为 #{params[:id]}的资源") if @file.nil? return normal_status(403, "您没有权限进行该操作") if @user != @file.author && !@user.teacher_of_course?(@course) && !@file.public? - @is_pdf = false - file_content_type = @file.content_type - file_ext_type = File.extname(@file.filename).strip.downcase[1..-1] - if (file_content_type.present? && file_content_type.downcase.include?("pdf")) || (file_ext_type.present? && file_ext_type.include?("pdf")) - @is_pdf = true - end + @attachment_histories = @file.attachment_histories end diff --git a/app/models/attachment.rb b/app/models/attachment.rb index bdd749108..3a512278a 100644 --- a/app/models/attachment.rb +++ b/app/models/attachment.rb @@ -115,4 +115,15 @@ class Attachment < ApplicationRecord end end + #判断是否为pdf文件 + def is_pdf? + is_pdf = false + file_content_type = content_type + file_ext_type = File.extname(filename).strip.downcase[1..-1] + if (file_content_type.present? && file_content_type.downcase.include?("pdf")) || (file_ext_type.present? && file_ext_type.include?("pdf")) + is_pdf = true + end + is_pdf + end + end diff --git a/app/views/attachment_histories/_attachment_history.json.jbuilder b/app/views/attachment_histories/_attachment_history.json.jbuilder index 37b8b95c1..65ca1e887 100644 --- a/app/views/attachment_histories/_attachment_history.json.jbuilder +++ b/app/views/attachment_histories/_attachment_history.json.jbuilder @@ -7,3 +7,4 @@ json.quotes attachment.quotes_count json.downloads_count attachment.downloads_count json.created_on attachment.created_on json.url attachment_path(attachment, type: 'history') +json.is_pdf attachment.is_pdf? diff --git a/app/views/attachments/_attachment_small.json.jbuilder b/app/views/attachments/_attachment_small.json.jbuilder index d9a976bde..97cbee120 100644 --- a/app/views/attachments/_attachment_small.json.jbuilder +++ b/app/views/attachments/_attachment_small.json.jbuilder @@ -2,4 +2,5 @@ json.id attachment.id json.title attachment.title json.filesize number_to_human_size(attachment.filesize) json.url download_url(attachment) -json.created_on attachment.created_on \ No newline at end of file +json.created_on attachment.created_on +json.is_pdf attachment.is_pdf? \ No newline at end of file diff --git a/app/views/files/histories.json.jbuilder b/app/views/files/histories.json.jbuilder index 9dfec4fd4..7039752e7 100644 --- a/app/views/files/histories.json.jbuilder +++ b/app/views/files/histories.json.jbuilder @@ -1,3 +1,3 @@ -json.is_pdf @is_pdf + json.partial! 'attachments/attachment_small', attachment: @file json.partial! "attachment_histories/list", attachment_histories: @attachment_histories From 1677cea34dbf1a5b24a20dddbecc5d885f3da78b Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Fri, 16 Aug 2019 16:01:22 +0800 Subject: [PATCH 5/8] =?UTF-8?q?=E6=B3=A8=E5=86=8C=E8=80=81=E5=B8=88?= =?UTF-8?q?=E6=97=B6=EF=BC=8C=E8=87=AA=E5=8A=A8=E5=8A=A0=E5=85=A5=E7=A4=BA?= =?UTF-8?q?=E4=BE=8B=E8=AF=BE=E5=A0=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/services/users/update_account_service.rb | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/app/services/users/update_account_service.rb b/app/services/users/update_account_service.rb index c8ba6da61..3f0aa8cc8 100644 --- a/app/services/users/update_account_service.rb +++ b/app/services/users/update_account_service.rb @@ -51,8 +51,10 @@ class Users::UpdateAccountService < ApplicationService if first_full_reward RewardGradeService.call(user, container_id: user.id, container_type: 'Account', score: 500) - - sms_notify_admin(user.lastname) if user.user_extension.teacher? + if user.user_extension.teacher? + join_course(user.id,1309, 2) + sms_notify_admin(user.lastname) + end end user @@ -73,4 +75,11 @@ class Users::UpdateAccountService < ApplicationService rescue => ex Util.logger_error(ex) end + + def join_course(user_id, course_id, identity) + course = Course.find_by(id: course_id) + return unless course + attr = {course_id: course_id, role: identity, user_id: user_id} + CourseMember.create!(attr) + end end \ No newline at end of file From 653fb5191d595711dbc9fc8b8deedf532f43bf00 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Fri, 16 Aug 2019 16:09:32 +0800 Subject: [PATCH 6/8] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=88=A4=E6=96=ADpdf?= =?UTF-8?q?=E7=9A=84=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/attachment_history.rb | 10 ++++++++++ .../_attachment_history.json.jbuilder | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/app/models/attachment_history.rb b/app/models/attachment_history.rb index 220f92535..c19146b95 100644 --- a/app/models/attachment_history.rb +++ b/app/models/attachment_history.rb @@ -20,4 +20,14 @@ class AttachmentHistory < ApplicationRecord is_public == 1 end + def is_history_pdf? + is_pdf = false + file_content_type = content_type + file_ext_type = File.extname(filename).strip.downcase[1..-1] + if (file_content_type.present? && file_content_type.downcase.include?("pdf")) || (file_ext_type.present? && file_ext_type.include?("pdf")) + is_pdf = true + end + is_pdf + end + end diff --git a/app/views/attachment_histories/_attachment_history.json.jbuilder b/app/views/attachment_histories/_attachment_history.json.jbuilder index 65ca1e887..8930e1b2d 100644 --- a/app/views/attachment_histories/_attachment_history.json.jbuilder +++ b/app/views/attachment_histories/_attachment_history.json.jbuilder @@ -7,4 +7,4 @@ json.quotes attachment.quotes_count json.downloads_count attachment.downloads_count json.created_on attachment.created_on json.url attachment_path(attachment, type: 'history') -json.is_pdf attachment.is_pdf? +json.is_pdf attachment.is_history_pdf? From de93d52d8cdc9a818e48fb9db5c1e377dc388683 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=A8=E6=A0=91=E6=98=8E?= <775174143@qq.com> Date: Fri, 16 Aug 2019 16:35:38 +0800 Subject: [PATCH 7/8] =?UTF-8?q?=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- public/react/src/modules/courses/Resource/Fileslistitem.js | 2 +- .../react/src/modules/courses/coursesPublic/Showoldfiles.js | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/public/react/src/modules/courses/Resource/Fileslistitem.js b/public/react/src/modules/courses/Resource/Fileslistitem.js index 5832770f1..c26f390cf 100644 --- a/public/react/src/modules/courses/Resource/Fileslistitem.js +++ b/public/react/src/modules/courses/Resource/Fileslistitem.js @@ -48,7 +48,7 @@ class Fileslistitem extends Component{ }else{ let link = document.createElement('a'); document.body.appendChild(link); - link.href = result.data.url; + link.href = "/api"+result.data.url; link.download = result.data.title; //兼容火狐浏览器 let evt = document.createEvent("MouseEvents"); diff --git a/public/react/src/modules/courses/coursesPublic/Showoldfiles.js b/public/react/src/modules/courses/coursesPublic/Showoldfiles.js index 8f1e7a29f..4bf98fb4f 100644 --- a/public/react/src/modules/courses/coursesPublic/Showoldfiles.js +++ b/public/react/src/modules/courses/coursesPublic/Showoldfiles.js @@ -184,7 +184,7 @@ class Showoldfiles extends Component{
  • {allfiles.is_pdf===false? - {allfiles.title}: + {allfiles.title}: this.showfiless(allfiles.url)} >{allfiles.title} } 当前版本 @@ -203,8 +203,8 @@ class Showoldfiles extends Component{
  • - {allfiles.is_pdf===false? - {item.title}: + {item.is_pdf===false? + {item.title}: this.showfiless(item.url)} >{item.title} }
  • From 31cae1194bbc03b16a4c2e802049725ac84f7720 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Fri, 16 Aug 2019 16:36:51 +0800 Subject: [PATCH 8/8] =?UTF-8?q?=E8=BF=87=E6=BB=A4=E9=99=84=E4=BB=B6?= =?UTF-8?q?=E7=9A=84api?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/helpers/application_helper.rb | 2 +- .../attachment_histories/_attachment_history.json.jbuilder | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 099d45406..e6f2e1720 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -258,7 +258,7 @@ module ApplicationHelper end def download_url attachment - attachment_path(attachment) + attachment_path(attachment).gsub("/api","") end # 耗时:天、小时、分、秒 diff --git a/app/views/attachment_histories/_attachment_history.json.jbuilder b/app/views/attachment_histories/_attachment_history.json.jbuilder index 8930e1b2d..afb359e08 100644 --- a/app/views/attachment_histories/_attachment_history.json.jbuilder +++ b/app/views/attachment_histories/_attachment_history.json.jbuilder @@ -6,5 +6,5 @@ json.publish_time attachment.publish_time json.quotes attachment.quotes_count json.downloads_count attachment.downloads_count json.created_on attachment.created_on -json.url attachment_path(attachment, type: 'history') +json.url attachment_path(attachment, type: 'history').gsub("/api","") json.is_pdf attachment.is_history_pdf?