课程资源修改为公开的也需登录才能下载

This commit is contained in:
z9hang 2014-11-22 10:06:56 +08:00
parent d1ad7b71c8
commit 36e7b222bb
6 changed files with 17 additions and 9 deletions

View File

@ -267,6 +267,8 @@ class ApplicationController < ActionController::Base
end end
when "contest" when "contest"
return true return true
when "Course"
allowed = User.current.allowed_to?(:course_attachments_download, @course, :global => false)
else else
return true return true
end end

View File

@ -76,7 +76,7 @@ class AttachmentsController < ApplicationController
candown = User.current.member_of?(project) || (project.is_public && @attachment.is_public == 1) candown = User.current.member_of?(project) || (project.is_public && @attachment.is_public == 1)
elsif (@attachment.container.has_attribute?(:course) ||@attachment.container.has_attribute?(:course_id) ) && @attachment.container.course elsif (@attachment.container.has_attribute?(:course) ||@attachment.container.has_attribute?(:course_id) ) && @attachment.container.course
course = @attachment.container.course course = @attachment.container.course
candown= User.current.member_of_course?(course) || (course.is_public==1 && @attachment.is_public == 1) candown = User.current.member_of_course?(course) || (course.is_public==1 && @attachment.is_public == 1)
elsif @attachment.container.is_a?(Course) elsif @attachment.container.is_a?(Course)
course = @attachment.container course = @attachment.container
candown= User.current.member_of_course?(course) || (course.is_public==1 && @attachment.is_public == 1) candown= User.current.member_of_course?(course) || (course.is_public==1 && @attachment.is_public == 1)

View File

@ -72,5 +72,10 @@ module FilesHelper
result result
end end
def get_qute_number attachment
if attachment.copy_from.nil?
return 0
end
count = Attachment.find_by_sql("select count(*) from attachments where copy_from = #{attachment.copy_from}")
end
end end

View File

@ -1,8 +1,8 @@
<% delete_allowed = User.current.allowed_to?(:manage_files, course) %> <% delete_allowed = User.current.allowed_to?(:manage_files, course) %>
<div class="re_con_top"> <div class="re_con_top">
<p class="f_l c_blue f_b f_14">共有&nbsp;<%= User.current.member_of_course?(course) ? all_attachments.count : 0 %>&nbsp;个资源</p> <p class="f_l c_blue f_b f_14">共有&nbsp;<%= User.current.member_of_course?(course) ? all_attachments.count : 0 %>&nbsp;个资源</p>
<!-- <p class="f_r"> <p class="f_r" style="color: #808080">
<#% if @order == "asc" %> <!--<#% if @order == "asc" %>
按&nbsp;<#%= link_to "时间",course_files_path(course,:sort=>"created_on:desc"),:class => "f_b c_grey" %><#%= render partial: 'arrow_show',locals: { sort: sort,order:order,current:"created_on"} %>&nbsp;/&nbsp; 按&nbsp;<#%= link_to "时间",course_files_path(course,:sort=>"created_on:desc"),:class => "f_b c_grey" %><#%= render partial: 'arrow_show',locals: { sort: sort,order:order,current:"created_on"} %>&nbsp;/&nbsp;
<#%= link_to "下载次数",course_files_path(course,:sort=>"downloads:desc"),:class => "f_b c_grey" %><#%= render partial: 'arrow_show',locals: { sort: sort,order:order,current:"downloads"} %>&nbsp;/&nbsp; <#%= link_to "下载次数",course_files_path(course,:sort=>"downloads:desc"),:class => "f_b c_grey" %><#%= render partial: 'arrow_show',locals: { sort: sort,order:order,current:"downloads"} %>&nbsp;/&nbsp;
<a href="#" class="f_b c_grey">引用次数</a>&nbsp;排序 <a href="#" class="f_b c_grey">引用次数</a>&nbsp;排序
@ -10,8 +10,9 @@
按&nbsp;<#%= link_to "时间",course_files_path(course,:sort=>"created_on:asc"),:class => "f_b c_grey" %><#%= render partial: 'arrow_show',locals: { sort: sort,order:order,current:"created_on"} %>&nbsp;/&nbsp; 按&nbsp;<#%= link_to "时间",course_files_path(course,:sort=>"created_on:asc"),:class => "f_b c_grey" %><#%= render partial: 'arrow_show',locals: { sort: sort,order:order,current:"created_on"} %>&nbsp;/&nbsp;
<#%= link_to "下载次数",course_files_path(course,:sort=>"downloads:asc"),:class => "f_b c_grey" %><#%= render partial: 'arrow_show',locals: { sort: sort,order:order,current:"downloads"} %>&nbsp;/&nbsp; <#%= link_to "下载次数",course_files_path(course,:sort=>"downloads:asc"),:class => "f_b c_grey" %><#%= render partial: 'arrow_show',locals: { sort: sort,order:order,current:"downloads"} %>&nbsp;/&nbsp;
<a href="#" class="f_b c_grey">引用次数</a>&nbsp;排序 <a href="#" class="f_b c_grey">引用次数</a>&nbsp;排序
<#% end %> <#% end %>-->
</p>--> 资源列表的多样化排序将在下周上线...
</p>
</div> </div>
<div class="cl"></div> <div class="cl"></div>
<% curse_attachments.each do |file| %> <% curse_attachments.each do |file| %>
@ -40,7 +41,7 @@
<p class="f_l c_grey02 font">文件大小:<%= number_to_human_size(file.filesize) %></p> <p class="f_l c_grey02 font">文件大小:<%= number_to_human_size(file.filesize) %></p>
<%= link_to( l(:button_delete), attachment_path(file), <%= link_to( l(:button_delete), attachment_path(file),
:data => {:confirm => l(:text_are_you_sure)}, :method => :delete,:class => "f_r re_de") if delete_allowed && file.container_id == @course.id && file.container_type == "Course"%> :data => {:confirm => l(:text_are_you_sure)}, :method => :delete,:class => "f_r re_de") if delete_allowed && file.container_id == @course.id && file.container_type == "Course"%>
<p class="f_r c_grey02" ><%= time_tag(file.created_on).html_safe %><%= l(:label_bids_published_ago) %>&nbsp;&nbsp;|&nbsp;&nbsp;下载<%= file.downloads %>&nbsp;&nbsp;|&nbsp;&nbsp;引用0 </p> <p class="f_r c_grey02" ><%= time_tag(file.created_on).html_safe %><%= l(:label_bids_published_ago) %>&nbsp;&nbsp;|&nbsp;&nbsp;下载<%= file.downloads %>&nbsp;&nbsp;|&nbsp;&nbsp;引用<%=get_qute_number file %> </p>
</div> </div>
<div class="cl"></div> <div class="cl"></div>
<div class="tag_h"> <div class="tag_h">

View File

@ -1,8 +1,8 @@
<div id="popbox_upload" style="margin-top: -30px;margin-left: -20px;margin-right: -10px;"> <div id="popbox_upload" style="margin-top: -30px;margin-left: -20px;margin-right: -10px;">
<div class="upload_con"> <div class="upload_con">
<div id="error_show"></div>
<h2>将此课件引入我的课程资源库</h2> <h2>将此课件引入我的课程资源库</h2>
<div class="upload_box"> <div class="upload_box">
<div id="error_show" style="color: red;"></div>
<%= form_tag course_attach_relations_path, <%= form_tag course_attach_relations_path,
method: :post, method: :post,
remote: true, remote: true,