公共资源只包括公开资源

This commit is contained in:
huang 2016-03-14 16:35:18 +08:00
parent 7d2bb572b2
commit 7c624cd571
3 changed files with 25 additions and 12 deletions

View File

@ -1555,7 +1555,7 @@ class UsersController < ApplicationController
@user = User.find(params[:id])
#@user.save_attachments(params[:attachments],User.current)
# Container_type为Principal
Attachment.attach_filesex(@user, params[:attachments], params[:attachment_type])
attach = Attachment.attach_filesex_public(@user, params[:attachments], params[:attachment_type], is_public = true)
if(params[:type].blank? || params[:type] == "1") # 我的资源
# 修正:我的资源库的话,那么应该是我上传的所有资源加上,我加入的课程、项目、组织的所有资源
if params[:status] == 2
@ -2340,9 +2340,7 @@ class UsersController < ApplicationController
# 获取公共资源
def get_public_resources user_course_ids, user_project_ids
attachments = Attachment.where("(is_publish = 1 and container_id is not null and container_type in('Project','OrgSubfield','Principal','Course')) "+
"or (container_type = 'Course' and container_id in (#{user_course_ids.empty? ? '0': user_course_ids.join(',')}) and is_publish = 1 and container_id is not null)" +
"or (container_type = 'Project' and container_id in (#{user_project_ids.empty? ? '0': user_project_ids.join(',')}) and is_publish = 1 and container_id is not null)" ).order("created_on desc")
attachments = Attachment.where("(is_publish = 1 and is_public =1 and container_id is not null and container_type in('Project','OrgSubfield','Principal','Course')) ").order("created_on desc")
end
# 获取我的资源
@ -2359,7 +2357,7 @@ class UsersController < ApplicationController
# 获取公共资源课程
def get_course_resources_public user_course_ids
attchments = Attachment.where("(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")
attchments = Attachment.where("(container_type = 'Course'and container_id is not null and is_publish = 1 and is_public =1)").order("created_on desc")
end
# 获取我的项目资源
@ -2369,7 +2367,7 @@ class UsersController < ApplicationController
# 获取公共资源的项目资源
def get_project_resources_public user_project_ids
attchments = Attachment.where("(container_type = 'Project') or (container_type = 'Project' and container_id in (#{user_project_ids.empty? ? '0': user_project_ids.join(',')}) and is_publish = 1) ").order("created_on desc")
attchments = Attachment.where("container_type = 'Project' and container_id is not null and is_public =1").order("created_on desc")
end
# 获取我上传的附件
@ -2379,7 +2377,7 @@ class UsersController < ApplicationController
# 获取公共资源中我上传的附件
def get_attch_resources_public
attchments = Attachment.where("container_type in('Issue','Document','Message','News','StudentWorkScore','HomewCommon','OrgSubfield','Principal')").order("created_on desc")
attchments = Attachment.where("container_type in('Issue','Document','Message','News','StudentWorkScore','HomewCommon','OrgSubfield','Principal') and container_id is not null and is_public =1").order("created_on desc")
end
# 获取我的用户类型资源
@ -2389,7 +2387,7 @@ class UsersController < ApplicationController
# 获取我的用户类型资源
def get_principal_resources_public
attchments = Attachment.where("container_type = 'Principal'").order("created_on desc")
attchments = Attachment.where("container_type = 'Principal'and container_id is not null and is_public =1").order("created_on desc")
end
# 资源库 分为全部 课程资源 项目资源 附件
@ -2621,9 +2619,7 @@ class UsersController < ApplicationController
end
elsif params[:type] == "6" #全部资源
# 公共资源库:所有公开资源或者我上传的私有资源
@attachments = Attachment.where("((is_publish = 1 and container_id is not null and container_type in('Project','OrgSubfield','Principal','Course')) "+
"or (container_type = 'Course' and container_id in (#{user_course_ids.empty? ? '0': user_course_ids.join(',')}) and is_publish = 1 and container_id is not null)" +
"or (container_type = 'Project' and container_id in (#{user_project_ids.empty? ? '0': user_project_ids.join(',')}) and is_publish = 1 and container_id is not null)) and (filename like :p)" ,:p => search).order("created_on desc")
@attachments = Attachment.where("is_publish = 1 and is_public = 1 and container_id is not null and container_type in('Project','OrgSubfield','Principal','Course') and (filename like :p)" ,:p => search).order("created_on desc")
end
@type = params[:type]
@limit = 25

View File

@ -499,6 +499,12 @@ class Attachment < ActiveRecord::Base
result
end
def self.attach_filesex_public(obj, attachments,attachment_type, is_public)
result = obj.save_attachmentsex_public(attachments, User.current,attachment_type, is_public)
obj.attach_saved_attachments
result
end
def self.latest_attach(attachments, filename)
attachments.sort_by(&:created_on).reverse.detect {
|att| att.filename.downcase == filename.downcase

View File

@ -99,6 +99,13 @@ module Redmine
result
end
def save_attachmentsex_public(attachments, author=User.current,attachment_type, is_public)
@curattachment_type = attachment_type
@is_public = true
result = save_attachments(attachments,author)
result
end
def save_attachments(attachments, author=User.current)
# 清除临时文件
if attachments
@ -142,7 +149,11 @@ module Redmine
end
if a && !attachment['is_public_checkbox']
a.is_public = false
if @is_public
a.is_public = true
else
a.is_public = false
end
elsif a && attachment['is_public_checkbox']
a.is_public = true
end