From c4e9321e148daa52b00fe11e9b926564141deaac Mon Sep 17 00:00:00 2001 From: z9hang Date: Tue, 31 Mar 2015 10:03:52 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B0=86attachment=5Fcandown=E6=96=B9=E6=B3=95?= =?UTF-8?q?=E6=8F=90=E5=8F=96=E5=88=B0application=5Fhelp=E9=87=8C=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/attachments_controller.rb | 33 ++----------------- app/controllers/files_controller.rb | 1 + app/helpers/application_helper.rb | 36 +++++++++++++++++++++ app/helpers/files_helper.rb | 35 -------------------- app/views/files/_project_file_list.html.erb | 2 +- 5 files changed, 40 insertions(+), 67 deletions(-) diff --git a/app/controllers/attachments_controller.rb b/app/controllers/attachments_controller.rb index d458b73e4..ddda15ce7 100644 --- a/app/controllers/attachments_controller.rb +++ b/app/controllers/attachments_controller.rb @@ -27,7 +27,7 @@ class AttachmentsController < ApplicationController accept_api_auth :show, :download, :upload require 'iconv' include AttachmentsHelper - + include ApplicationHelper def show respond_to do |format| @@ -65,36 +65,7 @@ class AttachmentsController < ApplicationController def download # modify by nwb # 下载添加权限设置 - candown = false - if @attachment.container.class.to_s != "HomeworkAttach" && (@attachment.container.has_attribute?(:project) || @attachment.container.has_attribute?(:project_id)) && @attachment.container.project - project = @attachment.container.project - candown= User.current.member_of?(project) || (project.is_public && @attachment.is_public == 1) - elsif @attachment.container.is_a?(Project) - project = @attachment.container - candown= User.current.member_of?(project) || (project.is_public && @attachment.is_public == 1) - elsif (@attachment.container.has_attribute?(:board) || @attachment.container.has_attribute?(:board_id)) && @attachment.container.board && - @attachment.container.board.project - project = @attachment.container.board.project - 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 - course = @attachment.container.course - candown = User.current.member_of_course?(course) || (course.is_public==1 && @attachment.is_public == 1) - elsif @attachment.container.is_a?(Course) - course = @attachment.container - candown= User.current.member_of_course?(course) || (course.is_public==1 && @attachment.is_public == 1) - elsif (@attachment.container.has_attribute?(:board) || @attachment.container.has_attribute?(:board_id)) && @attachment.container.board && - @attachment.container.board.course - course = @attachment.container.board.course - candown= User.current.member_of_course?(course) || (course.is_public==1 && @attachment.is_public == 1) - elsif @attachment.container.class.to_s=="HomeworkAttach" && @attachment.container.bid.reward_type == 3 - candown = true - elsif @attachment.container_type == "Bid" && @attachment.container && @attachment.container.courses.first - course = @attachment.container.courses.first - candown = User.current.member_of_course?(course) || (course.is_public == 1 && @attachment.is_public == 1) - else - - candown = @attachment.is_public == 1 - end + candown = attachment_candown @attachment if candown || User.current.admin? || User.current.id == @attachment.author_id @attachment.increment_download if stale?(:etag => @attachment.digest) diff --git a/app/controllers/files_controller.rb b/app/controllers/files_controller.rb index 21d2254c1..4a6daf77a 100644 --- a/app/controllers/files_controller.rb +++ b/app/controllers/files_controller.rb @@ -30,6 +30,7 @@ class FilesController < ApplicationController include FilesHelper helper :project_score include CoursesHelper + include ApplicationHelper def show_attachments obj @attachments = [] diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index c8168455c..fd567c1fa 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1676,6 +1676,42 @@ module ApplicationHelper courses_doing end + + def attachment_candown attachment + candown = false + if attachment.container + if attachment.container.class.to_s != "HomeworkAttach" && (attachment.container.has_attribute?(:project) || attachment.container.has_attribute?(:project_id)) && attachment.container.project + project = attachment.container.project + candown= User.current.member_of?(project) || (project.is_public && attachment.is_public == 1) + elsif attachment.container.is_a?(Project) + project = attachment.container + candown= User.current.member_of?(project) || (project.is_public && attachment.is_public == 1) + elsif (attachment.container.has_attribute?(:board) || attachment.container.has_attribute?(:board_id)) && attachment.container.board && + attachment.container.board.project + project = attachment.container.board.project + 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 + course = attachment.container.course + candown = User.current.member_of_course?(course) || (course.is_public==1 && attachment.is_public == 1) + elsif attachment.container.is_a?(Course) + course = attachment.container + candown= User.current.member_of_course?(course) || (course.is_public==1 && attachment.is_public == 1) + elsif (attachment.container.has_attribute?(:board) || attachment.container.has_attribute?(:board_id)) && attachment.container.board && + attachment.container.board.course + course = attachment.container.board.course + candown= User.current.member_of_course?(course) || (course.is_public==1 && attachment.is_public == 1) + elsif attachment.container.class.to_s=="HomeworkAttach" && attachment.container.bid.reward_type == 3 + candown = true + elsif attachment.container_type == "Bid" && attachment.container && attachment.container.courses + course = attachment.container.courses.first + candown = User.current.member_of_course?(attachment.container.courses.first) || (course.is_public == 1 && attachment.is_public == 1) + else + candown = (attachment.is_public == 1 || attachment.is_public == true) + end + end + candown + end + private def wiki_helper diff --git a/app/helpers/files_helper.rb b/app/helpers/files_helper.rb index 503e3d6ed..02699f6aa 100644 --- a/app/helpers/files_helper.rb +++ b/app/helpers/files_helper.rb @@ -118,41 +118,6 @@ module FilesHelper result end - def attachment_candown attachment - candown = false - if attachment.container - if attachment.container.class.to_s != "HomeworkAttach" && (attachment.container.has_attribute?(:project) || attachment.container.has_attribute?(:project_id)) && attachment.container.project - project = attachment.container.project - candown= User.current.member_of?(project) || (project.is_public && attachment.is_public == 1) - elsif attachment.container.is_a?(Project) - project = attachment.container - candown= User.current.member_of?(project) || (project.is_public && attachment.is_public == 1) - elsif (attachment.container.has_attribute?(:board) || attachment.container.has_attribute?(:board_id)) && attachment.container.board && - attachment.container.board.project - project = attachment.container.board.project - 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 - course = attachment.container.course - candown = User.current.member_of_course?(course) || (course.is_public==1 && attachment.is_public == 1) - elsif attachment.container.is_a?(Course) - course = attachment.container - candown= User.current.member_of_course?(course) || (course.is_public==1 && attachment.is_public == 1) - elsif (attachment.container.has_attribute?(:board) || attachment.container.has_attribute?(:board_id)) && attachment.container.board && - attachment.container.board.course - course = attachment.container.board.course - candown= User.current.member_of_course?(course) || (course.is_public==1 && attachment.is_public == 1) - elsif attachment.container.class.to_s=="HomeworkAttach" && attachment.container.bid.reward_type == 3 - candown = true - elsif attachment.container_type == "Bid" && attachment.container && attachment.container.courses - course = attachment.container.courses.first - candown = User.current.member_of_course?(attachment.container.courses.first) || (course.is_public == 1 && attachment.is_public == 1) - else - candown = (attachment.is_public == 1 || attachment.is_public == true) - end - end - candown - end - end \ No newline at end of file diff --git a/app/views/files/_project_file_list.html.erb b/app/views/files/_project_file_list.html.erb index 136be38e1..42c454965 100644 --- a/app/views/files/_project_file_list.html.erb +++ b/app/views/files/_project_file_list.html.erb @@ -21,7 +21,7 @@ <%= link_to_attachment file, :download => true,:text => truncate(file.filename,length: 35, omission: '...'), :title => file.filename+"\n"+file.description.to_s, :style => "overflow: hidden; white-space: nowrap;text-overflow: ellipsis;",:class => "c_dblue f_14 f_b f_l" %> <% if User.current.logged? %> <% if (manage_allowed || file.author_id == User.current.id) && project_contains_attachment?(project,file) %> - <%= link_to(l(:label_slected_to_other_project),quote_resource_show_course_file_path(@course,file),:class => "f_l re_select",:remote => true) if has_project?(User.current,file) %> + <%= link_to(l(:label_slected_to_other_project),quote_resource_show_course_file_path(project,file),:class => "f_l re_select",:remote => true) if has_project?(User.current,file) %> <% if manage_allowed && file.container_id == project.id && file.container_type == "Project" %>