From 98946b98552be3e4c8ebc6cced2ef16c6c877423 Mon Sep 17 00:00:00 2001 From: cxt Date: Mon, 22 Feb 2016 18:10:20 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AF=BE=E7=A8=8B=E4=B8=8A=E4=BC=A0=E8=B5=84?= =?UTF-8?q?=E6=BA=90=E5=BC=B9=E6=A1=86=E7=9A=84=E5=BB=B6=E8=BF=9F=E5=8F=91?= =?UTF-8?q?=E5=B8=83=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/files_controller.rb | 17 ++++++ app/controllers/users_controller.rb | 14 ++--- app/helpers/courses_helper.rb | 2 +- app/helpers/files_helper.rb | 3 +- app/views/files/_course_list.html.erb | 3 ++ app/views/files/_upload_course_files.erb | 53 ++++++++++++++++--- ...160222064143_add_publish_to_attachments.rb | 21 ++++++++ 7 files changed, 98 insertions(+), 15 deletions(-) create mode 100644 db/migrate/20160222064143_add_publish_to_attachments.rb diff --git a/app/controllers/files_controller.rb b/app/controllers/files_controller.rb index c4932b1b2..e83a13ad9 100644 --- a/app/controllers/files_controller.rb +++ b/app/controllers/files_controller.rb @@ -488,6 +488,23 @@ class FilesController < ApplicationController if !attachments.empty? && !attachments[:files].blank? && Setting.notified_events.include?('file_added') Mailer.run.attachments_added(attachments[:files]) end + if !attachments.empty? && attachments[:files] + attachments[:files].each do |attachment| + if params[:publish_time] + if params[:publish_time] == "" + attachment.publish_time = Date.today + else + attachment.publish_time = params[:publish_time] + end + else + attachment.publish_time = Date.today + end + if attachment.publish_time > Date.today + attachment.is_publish = 0 + end + attachment.save + end + end if params[:course_attachment_type] && params[:course_attachment_type].is_a?(Array) params[:course_attachment_type].each do |type| tag_name = get_tag_name_by_type_number type diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 625a1de74..fb35d8495 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -2144,22 +2144,22 @@ class UsersController < ApplicationController if(params[:type].blank? || params[:type] == "1") #全部 if User.current.id.to_i == params[:id].to_i user_course_ids = User.current.courses.map { |c| c.id} #我的资源库的话,那么应该是我上传的所有资源 加上 我加入的课程的所有资源 - @attachments = Attachment.where("(author_id = #{params[:id]} and container_type in('Project','OrgSubfield','Principal','Course','Issue','Document','Message','News','StudentWorkScore','HomewCommon')) "+ - "or (container_type = 'Course' and container_id in (#{user_course_ids.empty? ? '0': user_course_ids.join(',')}))").order("created_on desc") + @attachments = Attachment.where("(author_id = #{params[:id]} and is_publish = 1 and container_type in('Project','OrgSubfield','Principal','Course','Issue','Document','Message','News','StudentWorkScore','HomewCommon')) "+ + "or (container_type = 'Course' and container_id in (#{user_course_ids.empty? ? '0': user_course_ids.join(',')}) and is_publish = 1)").order("created_on desc") else user_course_ids = User.find(params[:id]).courses.visible.map { |c| c.id} #Ta的资源库的话,应该是他上传的公开资源 加上 他加入的所有我可见课程里的公开资源 - @attachments = Attachment.where("(author_id = #{params[:id]} and is_public = 1 " + + @attachments = Attachment.where("(author_id = #{params[:id]} and is_public = 1 and is_publish = 1 " + "and container_type in('Project','OrgSubfield','Principal','Course','Issue','Document','Message','News','StudentWorkScore','HomewCommon')) " + - "or (container_type = 'Course' and is_public = 1 and container_id in (#{user_course_ids.empty? ? '0': user_course_ids.join(',')}))").order("created_on desc") + "or (container_type = 'Course' and is_public = 1 and container_id in (#{user_course_ids.empty? ? '0': user_course_ids.join(',')}) and is_publish = 1)").order("created_on desc") end elsif params[:type] == "2" #课程资源 if User.current.id.to_i == params[:id].to_i user_course_ids = User.current.courses.map { |c| c.id} - @attachments = Attachment.where("(author_id = #{params[:id]} and container_type = 'Course') or (container_type = 'Course' and container_id in (#{user_course_ids.empty? ? '0': user_course_ids.join(',')})) ").order("created_on desc") + @attachments = Attachment.where("(author_id = #{params[:id]} and container_type = 'Course' and is_publish = 1) or (container_type = 'Course' and container_id in (#{user_course_ids.empty? ? '0': user_course_ids.join(',')}) and is_publish = 1) ").order("created_on desc") else user_course_ids = User.find(params[:id]).courses.visible.map { |c| c.id} #如果课程私有资源,那么要看这个资源的课程是不是在 这个user的所有我可见的课程中 - @attachments = Attachment.where("(author_id = #{params[:id]} and is_public = 1 and container_type = 'Course')"+ - "or (container_type = 'Course' and is_public = 1 and container_id in (#{user_course_ids.empty? ? '0': user_course_ids.join(',')}))").order("created_on desc") + @attachments = Attachment.where("(author_id = #{params[:id]} and is_public = 1 and container_type = 'Course' and is_publish = 1)"+ + "or (container_type = 'Course' and is_public = 1 and is_publish = 1 and container_id in (#{user_course_ids.empty? ? '0': user_course_ids.join(',')}))").order("created_on desc") end elsif params[:type] == "3" #项目资源 if User.current.id.to_i == params[:id].to_i diff --git a/app/helpers/courses_helper.rb b/app/helpers/courses_helper.rb index 40ed4a21a..6d0066fbc 100644 --- a/app/helpers/courses_helper.rb +++ b/app/helpers/courses_helper.rb @@ -746,7 +746,7 @@ module CoursesHelper return[] unless course result = [] course.attachments.each do |attachment| - if attachment.is_public? || User.current.member_of_course?(course) || User.current.admin? + if attachment.is_public? ||User.current.allowed_to?(:as_teacher,Course.find(attachment.container_id))|| (User.current.member_of_course?(course) && attachment.is_publish == 1) || User.current.admin? result << attachment end end diff --git a/app/helpers/files_helper.rb b/app/helpers/files_helper.rb index bd023f6d0..6b748649b 100644 --- a/app/helpers/files_helper.rb +++ b/app/helpers/files_helper.rb @@ -123,7 +123,8 @@ module FilesHelper attachments.each do |attachment| if attachment.is_public? || (attachment.container_type == "Project" && User.current.member_of?(attachment.project)) || - (attachment.container_type == "Course" && User.current.member_of_course?(Course.find(attachment.container_id)))|| + (attachment.container_type == "Course" && User.current.allowed_to?(:as_teacher,Course.find(attachment.container_id)))|| + (attachment.container_type == "Course" && User.current.member_of_course?(Course.find(attachment.container_id)) && attachment.is_publish == 1)|| attachment.author_id == User.current.id || attachment.container_type == "OrgSubfield" result << attachment diff --git a/app/views/files/_course_list.html.erb b/app/views/files/_course_list.html.erb index 47c08d2fb..d7aade6c2 100644 --- a/app/views/files/_course_list.html.erb +++ b/app/views/files/_course_list.html.erb @@ -18,6 +18,9 @@ 私有 <%end %> + <% if file.is_publish == 0 %> + <%=file.publish_time %>  0点发布 + <% end %>
上传时间:<%= format_time(file.created_on)%> diff --git a/app/views/files/_upload_course_files.erb b/app/views/files/_upload_course_files.erb index 6cce4bf2e..2e53f05d2 100644 --- a/app/views/files/_upload_course_files.erb +++ b/app/views/files/_upload_course_files.erb @@ -21,10 +21,20 @@ <%= render :partial => 'files/new_style_attachment_list',:locals => {:container => course} %>
- - <%= l(:button_cancel)%> - - <%= submit_tag '确定',:onclick=>'submit_resource();',:onfocus=>'this.blur()',:id=>'submit_resource',:class=>'sendSourceText fr' %> + <% if User.current.allowed_to?(:as_teacher,course) %> +
+ +
+ + <%#= calendar_for('attachment_publish_time')%> +
+ +
+
+ <% end %> + <%= l(:button_cancel)%> + <%= l(:button_confirm)%> + <%#= submit_tag '确定',:onclick=>'submit_course_resource();',:onfocus=>'this.blur()',:id=>'submit_resource',:class=>'sendSourceText fr' %> <% end %> @@ -35,8 +45,39 @@ \ No newline at end of file diff --git a/db/migrate/20160222064143_add_publish_to_attachments.rb b/db/migrate/20160222064143_add_publish_to_attachments.rb new file mode 100644 index 000000000..5ca354396 --- /dev/null +++ b/db/migrate/20160222064143_add_publish_to_attachments.rb @@ -0,0 +1,21 @@ +class AddPublishToAttachments < ActiveRecord::Migration + def change + add_column :attachments, :is_publish, :integer, :default => 1 + add_column :attachments, :publish_time, :date +=begin + count = Attachment.all.count / 30 + 2 + transaction do + for i in 1 ... count do i + Attachment.page(i).per(30).each do |atta| + begin + atta.publish_time = atta.created_on.strftime('%d-%b-%Y') + atta.save + ensure + logger.error("===================>>container_id is null") + end + end + end + end +=end + end +end