Merge branch 'dev_aliyun' of http://bdgit.educoder.net/Hjqreturn/educoder into dev_aliyun

dev_winse
cxt 6 years ago
commit 12f77e9c7d

@ -263,12 +263,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

@ -26,6 +26,12 @@ class Users::BaseController < ApplicationController
render_forbidden
end
def require_auth_teacher!
return if current_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

@ -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)

@ -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

@ -258,7 +258,7 @@ module ApplicationHelper
end
def download_url attachment
attachment_path(attachment)
attachment_path(attachment).gsub("/api","")
end
# 耗时:天、小时、分、秒

@ -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

@ -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

@ -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

@ -6,4 +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?

@ -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
json.created_on attachment.created_on
json.is_pdf attachment.is_pdf?

@ -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

@ -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.

@ -36,22 +36,34 @@ 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;
link.href = "/api"+result.data.url;
link.download = result.data.title;
//兼容火狐浏览器
let evt = document.createEvent("MouseEvents");
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}
/>:""}
<Showoldfiles
{...this.props}
visible={this.state.Showoldfiles}
allfiles={this.state.allfiles}
closaoldfilesprops={this.closaoldfilesprops}

@ -42,6 +42,14 @@ class Showoldfiles extends Component{
this.props.closaoldfilesprops()
}
showfiless=(url)=>{
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{
<div className="clearfix edu-txt-center lineh-40 bor-bottom-greyE" id={allfiles.id}>
<li className="fl fontlefts">
<a className={"isabox"} href={allfiles.url}>{allfiles.title}</a>
{allfiles.is_pdf===false?
<a className={"isabox"} href={"/api"+allfiles.url} >{allfiles.title}</a>:
<a className={"isabox"} onClick={()=>this.showfiless(allfiles.url)} >{allfiles.title}</a>
}
<span className={"newcolor-orange fl"}>当前版本</span>
</li>
@ -191,7 +202,11 @@ class Showoldfiles extends Component{
<div className="clearfix edu-txt-center lineh-40 bor-bottom-greyE" id={item.id} key={key}>
<li className="fl fontlefts">
<a className={"isabox"} href={item.url}>{item.title}</a>
{item.is_pdf===false?
<a className={"isabox"} href={"/api"+item.url}>{item.title}</a>:
<a className={"isabox"} onClick={()=>this.showfiless(item.url)} >{item.title}</a>
}
</li>
<li className="fl filesves ">

Loading…
Cancel
Save