解决用户ID转换成用户名后引发的问题

This commit is contained in:
huang 2016-11-10 10:27:57 +08:00
parent 6322d18325
commit 0f328c9c58
4 changed files with 57 additions and 81 deletions

View File

@ -1137,7 +1137,7 @@ class UsersController < ApplicationController
def user_import_resource
@user = User.current
user_course_ids = @user.courses.map { |c| c.id} #我的资源库的话,那么应该是我上传的所有资源 加上 我加入的课程的所有资源
@attachments = Attachment.where("(author_id = #{params[:id]} and container_type in('Project','Principal','Course','Issue','Document','Message','News','StudentWorkScore','HomewCommon')) "+
@attachments = Attachment.where("(author_id = #{@user.id} and container_type in('Project','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")
@type = params[:type]
@homework_id = params[:homework_id]
@ -1156,26 +1156,22 @@ class UsersController < ApplicationController
#引入资源列表根据类型过滤
def user_resource_type
if User.current.id.to_i != params[:id].to_i
render_403
return
end
user_course_ids = User.current.courses.map { |c| c.is_delete == 0 && c.id}
user_project_ids = User.current.projects.map {|p| p.status != 9 && p.id }
# user_org_ids = User.current.organizations.map {|o| o.id}
if(params[:type].blank? || params[:type] == "1") # 我的资源
# 修正:我的资源库的话,那么应该是我上传的所有资源加上,我加入的课程、项目、组织的所有资源
if params[:status] == "2"
@attachments = get_course_resources(params[:id], user_course_ids, @order, @score)
@attachments = get_course_resources(User.current.id, user_course_ids, @order, @score)
elsif params[:status] == "3"
@attachments = get_project_resources(params[:id], user_project_ids, @order, @score)
@attachments = get_project_resources(User.current.id, user_project_ids, @order, @score)
elsif params[:status] == "4"
@attachments = get_attch_resources(params[:id], @order, @score)
@attachments = get_attch_resources(User.current.id, @order, @score)
elsif params[:status] == "5"
@attachments = get_principal_resources(params[:id], @order, @score)
@attachments = get_principal_resources(User.current.id, @order, @score)
else
# 公共资源库:所有公开资源或者我上传的私有资源
@attachments = get_my_resources(params[:id], user_course_ids, user_project_ids, @order, @score)
@attachments = get_my_resources(User.current.id, user_course_ids, user_project_ids, @order, @score)
end
elsif params[:type] == "6" # 公共资源
if params[:status] == "2"
@ -1207,11 +1203,7 @@ class UsersController < ApplicationController
#引入资源列表根据关键词过滤
def user_ref_resource_search
if User.current.id.to_i != params[:id].to_i
render_403
return
end
def user_ref_resource_searc
@resource_id = params[:mul_id]
@resource_type = params[:mul_type]
@order, @b_sort = params[:order] || "created_on", params[:sort] || "asc"
@ -1225,7 +1217,7 @@ class UsersController < ApplicationController
user_course_ids = User.current.courses.map { |c| c.is_delete == 0 && c.id}
user_project_ids = User.current.projects.map {|p| p.status != 9 && p.id }
# user_org_ids = User.current.organizations.map {|o| o.id}
@attachments = get_my_resources_search(params[:id], user_course_ids, user_project_ids, @order, @score, search)
@attachments = get_my_resources_search(User.current.id, user_course_ids, user_project_ids, @order, @score, search)
elsif (params[:type].blank? || params[:type] == "6") # 公共资源
# 公共资源库:所有公开资源或者我上传的私有资源
@attachments = get_public_resources_search(user_course_ids, user_project_ids, @order, @score, search)
@ -2041,7 +2033,7 @@ class UsersController < ApplicationController
user_course_ids = User.current.courses.map { |c| c.is_delete == 0 && c.id}
user_project_ids = User.current.projects.map {|p| p.status != 9 && p.id }
# user_org_ids = User.current.organizations.map {|o| o.id}
@user = User.find(params[:id])
@user = User.current
# 保存文件
attach = Attachment.attach_filesex_public(@user, params[:attachments], params[:attachment_type], is_public = true)
@order, @b_sort = params[:order] || "created_on", params[:sort] || "asc"
@ -2050,16 +2042,16 @@ class UsersController < ApplicationController
if(params[:type].blank? || params[:type] == "1") # 我的资源
# 修正:我的资源库的话,那么应该是我上传的所有资源加上,我加入的课程、项目、组织的所有资源
if params[:status] == "2"
@attachments = get_course_resources(params[:id], user_course_ids, @order, @score)
@attachments = get_course_resources(@user.id, user_course_ids, @order, @score)
elsif params[:status] == "3"
@attachments = get_project_resources(params[:id], user_project_ids, @order, @score)
@attachments = get_project_resources(@user.id, user_project_ids, @order, @score)
elsif params[:status] == "4"
@attachments = get_attch_resources(params[:id], @order, @score)
@attachments = get_attch_resources(@user.id, @order, @score)
elsif params[:status] == "5"
@attachments = get_principal_resources(params[:id], @order, @score)
@attachments = get_principal_resources(@user.id, @order, @score)
else
# 公共资源库:所有公开资源或者我上传的私有资源
@attachments = get_my_resources(params[:id], user_course_ids, user_project_ids, @order, @score)
@attachments = get_my_resources(@user.id, user_course_ids, user_project_ids, @order, @score)
end
elsif params[:type] == "6" # 公共资源
if params[:status] == "2"
@ -2109,16 +2101,16 @@ class UsersController < ApplicationController
if(params[:type].blank? || params[:type] == "1") # 我的资源
# 修正:我的资源库的话,那么应该是我上传的所有资源加上,我加入的课程、项目、组织的所有资源
if params[:status] == "2"
@attachments = get_course_resources(params[:id], user_course_ids, @order, @score)
@attachments = get_course_resources(@user.id, user_course_ids, @order, @score)
elsif params[:status] == "3"
@attachments = get_project_resources(params[:id], user_project_ids, @order, @score)
@attachments = get_project_resources(@user.id, user_project_ids, @order, @score)
elsif params[:status] == "4"
@attachments = get_attch_resources(params[:id], @order, @score)
@attachments = get_attch_resources(@user.id, @order, @score)
elsif params[:status] == "5"
@attachments = get_principal_resources(params[:id], @order, @score)
@attachments = get_principal_resources(@user.id, @order, @score)
else
# 公共资源库:所有公开资源或者我上传的私有资源
@attachments = get_my_resources(params[:id], user_course_ids, user_project_ids, @order, @score)
@attachments = get_my_resources(@user.id, user_course_ids, user_project_ids, @order, @score)
end
elsif params[:type] == "6" # 公共资源
if params[:status] == "2"
@ -2248,16 +2240,16 @@ class UsersController < ApplicationController
if(params[:type] == "1") # 我的资源
# 修正:我的资源库的话,那么应该是我上传的所有资源加上,我加入的课程、项目、组织的所有资源
if params[:status] == "2"
@attachments = get_course_resources(params[:id], user_course_ids, @order, @score)
@attachments = get_course_resources(User.current.id, user_course_ids, @order, @score)
elsif params[:status] == "3"
@attachments = get_project_resources(params[:id], user_project_ids, @order, @score)
@attachments = get_project_resources(User.current.id, user_project_ids, @order, @score)
elsif params[:status] == "4"
@attachments = get_attch_resources(params[:id], @order, @score)
@attachments = get_attch_resources(User.current.id, @order, @score)
elsif params[:status] == "5"
@attachments = get_principal_resources(params[:id], @order, @score)
@attachments = get_principal_resources(User.current.id, @order, @score)
else
# 公共资源库:所有公开资源或者我上传的私有资源
@attachments = get_my_resources(params[:id], user_course_ids, user_project_ids, @order, @score)
@attachments = get_my_resources(User.current.id, user_course_ids, user_project_ids, @order, @score)
end
elsif (params[:type].blank? || params[:type] == "6") # 公共资源
if params[:status] == "2"
@ -2408,16 +2400,16 @@ class UsersController < ApplicationController
if(params[:type] == "1") # 我的资源
# 修正:我的资源库的话,那么应该是我上传的所有资源加上,我加入的课程、项目、组织的所有资源
if params[:status] == "2"
@attachments = get_course_resources(params[:id], user_course_ids, @order, @score)
@attachments = get_course_resources(User.current.id, user_course_ids, @order, @score)
elsif params[:status] == "3"
@attachments = get_project_resources(params[:id], user_project_ids, @order, @score)
@attachments = get_project_resources(User.current.id, user_project_ids, @order, @score)
elsif params[:status] == "4"
@attachments = get_attch_resources(params[:id], @order, @score)
@attachments = get_attch_resources(User.current.id, @order, @score)
elsif params[:status] == "5"
@attachments = get_principal_resources(params[:id], @order, @score)
@attachments = get_principal_resources(User.current.id, @order, @score)
else
# 公共资源库:所有公开资源或者我上传的私有资源
@attachments = get_my_resources(params[:id], user_course_ids, user_project_ids, @order, @score)
@attachments = get_my_resources(User.current.id, user_course_ids, user_project_ids, @order, @score)
end
elsif (params[:type].blank? || params[:type] == "6") # 公共资源
if params[:status] == "2"
@ -2549,16 +2541,16 @@ class UsersController < ApplicationController
if(params[:type] == "1") # 我的资源
# 修正:我的资源库的话,那么应该是我上传的所有资源加上,我加入的课程、项目、组织的所有资源
if params[:status] == "2"
@attachments = get_course_resources(params[:id], user_course_ids, @order, @score)
@attachments = get_course_resources(User.current.id, user_course_ids, @order, @score)
elsif params[:status] == "3"
@attachments = get_project_resources(params[:id], user_project_ids, @order, @score)
@attachments = get_project_resources(User.current.id, user_project_ids, @order, @score)
elsif params[:status] == "4"
@attachments = get_attch_resources(params[:id], @order, @score)
@attachments = get_attch_resources(User.current.id, @order, @score)
elsif params[:status] == "5"
@attachments = get_principal_resources(params[:id], @order, @score)
@attachments = get_principal_resources(User.current.id, @order, @score)
else
# 公共资源库:所有公开资源或者我上传的私有资源
@attachments = get_my_resources(params[:id], user_course_ids, user_project_ids, @order, @score)
@attachments = get_my_resources(User.current.id, user_course_ids, user_project_ids, @order, @score)
end
elsif (params[:type].blank? || params[:type] == "6") # 公共资源
if params[:status] == "2"
@ -3061,16 +3053,16 @@ class UsersController < ApplicationController
if(params[:type].blank? || params[:type] == "1") # 我的资源
# 修正:我的资源库的话,那么应该是我上传的所有资源加上,我加入的课程、项目、组织的所有资源
if params[:status] == "2"
@attachments = get_course_resources(params[:id], user_course_ids, @order, @score)
@attachments = get_course_resources(User.current.id, user_course_ids, @order, @score)
elsif params[:status] == "3"
@attachments = get_project_resources(params[:id], user_project_ids, @order, @score)
@attachments = get_project_resources(User.current.id, user_project_ids, @order, @score)
elsif params[:status] == "4"
@attachments = get_attch_resources(params[:id], @order, @score)
@attachments = get_attch_resources(User.current.id, @order, @score)
elsif params[:status] == "5"
@attachments = get_principal_resources(params[:id], @order, @score)
@attachments = get_principal_resources(User.current.id, @order, @score)
else
# 公共资源库:所有公开资源或者我上传的私有资源
@attachments = get_my_resources(params[:id], user_course_ids, user_project_ids, @order, @score)
@attachments = get_my_resources(User.current.id, user_course_ids, user_project_ids, @order, @score)
end
elsif (params[:type] == "6") # 公共资源
if params[:status] == "2"
@ -3115,11 +3107,6 @@ class UsersController < ApplicationController
# 导入资源
def import_resources
# 别人的资源库是没有权限去看的
if User.current.id != params[:id].to_i
render_403
return
end
@resource_id = params[:project_id].nil? ? (params[:course_id].nil? ? params[:subfield_file_id] : params[:course_id]) : params[:project_id]
@resource_type = params[:project_id].nil? ? (params[:course_id].nil? ? "SubfieldFile" : "Course") : "Project"
@order, @b_sort = params[:order] || "created_on", params[:sort] || "asc"
@ -3128,7 +3115,7 @@ class UsersController < ApplicationController
user_project_ids = User.current.projects.map {|p| p.status != 9 && p.id } # user_org_ids = User.current.organizations.map {|o| o.id}
if(params[:type].blank? || params[:type] == "1") # 我的资源
# 修正:我的资源库的话,那么应该是我上传的所有资源加上,我加入的课程、项目、组织的所有资源
@attachments = get_my_resources(params[:id], user_course_ids, user_project_ids, @order, @score)
@attachments = get_my_resources(User.current.id, user_course_ids, user_project_ids, @order, @score)
elsif params[:type] == "6" # 公共资源
# 公共资源库:所有公开资源或者我上传的私有资源
@attachments = get_public_resources(user_course_ids, user_project_ids, params[:order], @score)
@ -3149,10 +3136,6 @@ class UsersController < ApplicationController
end
def import_resources_search
if User.current.id.to_i != params[:id].to_i
render_403
return
end
@resource_id = params[:mul_id]
@resource_type = params[:mul_type]
@order, @b_sort = params[:order] || "created_on", params[:sort] || "asc"
@ -3166,7 +3149,7 @@ class UsersController < ApplicationController
user_course_ids = User.current.courses.map { |c| c.is_delete == 0 && c.id}
user_project_ids = User.current.projects.map {|p| p.status != 9 && p.id }
# user_org_ids = User.current.organizations.map {|o| o.id}
@attachments = get_my_resources_search(params[:id], user_course_ids, user_project_ids, @order, @score, search)
@attachments = get_my_resources_search(User.current.id, user_course_ids, user_project_ids, @order, @score, search)
elsif params[:type] == "6" # 公共资源
# 公共资源库:所有公开资源或者我上传的私有资源
@attachments = get_public_resources_search(user_course_ids, user_project_ids, @order, @score, search)
@ -3253,16 +3236,16 @@ class UsersController < ApplicationController
user_project_ids = User.current.projects.map {|p| p.status != 9 && p.id }
if(params[:type].nil? || params[:type].blank? || params[:type] == "1" || params[:type] == 'all') # 全部
if params[:status] == "2"
@attachments = get_course_resources_search(params[:id], user_course_ids, @order, @score, search)
@attachments = get_course_resources_search(User.current.id, user_course_ids, @order, @score, search)
elsif params[:status] == "3"
@attachments = get_project_resources_search(params[:id], user_project_ids, @order, @score, search)
@attachments = get_project_resources_search(User.current.id, user_project_ids, @order, @score, search)
elsif params[:status] == "4"
@attachments = get_attch_resources_search(params[:id], @order, @score, search)
@attachments = get_attch_resources_search(User.current.id, @order, @score, search)
elsif params[:status] == "5"
@attachments = get_principal_resources_search(params[:id], @order, @score, search)
@attachments = get_principal_resources_search(User.current.id, @order, @score, search)
else
# 公共资源库:所有公开资源或者我上传的私有资源
@attachments = get_my_resources_search(params[:id], user_course_ids, user_project_ids, @order, @score, search)
@attachments = get_my_resources_search(User.current.id, user_course_ids, user_project_ids, @order, @score, search)
end
elsif params[:type] == "6" # 公共资源
if params[:status] == "2"

View File

@ -67,12 +67,12 @@ module ApplicationHelper
end
# 重置user_path目的是将id转换成用户名
# def user_path(resource, parameters = {})
# if Fixnum === resource
# resource = User.find(resource)
# end
# super
# end
def user_path(resource, parameters = {})
if Fixnum === resource
resource = User.find(resource)
end
super
end
# 历史数据(老版本库数据)处理完则可以修改该放放
def get_rep_identifier_by_project project

View File

@ -322,9 +322,9 @@ class User < Principal
end
# id 转换成 登录名
# def to_param
# self.login.to_i > 0 ? id : login
# end
def to_param
self.login.to_i > 0 ? id : login
end
def my_blogs_count

View File

@ -2,14 +2,7 @@
<div class="project_r_h">
<%= render :partial => "top" %>
</div>
<!--<script>-->
<!--// $(document).ready(function(){-->
<!--// $("#changed-files").click(function(){-->
<!--// $("#changed-files-detail").toggle();-->
<!--// });-->
<!--// });-->
<!--</script>-->
<div class="showing-changes-info fontGrey2"> Commit <a href="javascript:void()" class="linkGrey3">
<div class="showing-changes-info fontGrey2"> Commit <a href="javascript:void(0);" class="linkGrey3">
<%= @commit_details.id %></a><br />
<li class="commit js-toggle-container">
<%= render :partial => 'commit_details', :locals => {:changeset => @commit_details} %>
@ -26,7 +19,7 @@
<% @commit_diff.each do |cd| %>
<div class="showing-changes-row fontGrey2">
<a href="javascript:void()" class="linkGrey3" id="changed-files">
<a href="javascript:void(0);" class="linkGrey3" id="changed-files">
<img src="/images/vlicon/file.png" width="18" height="20" style="vertical-align:middle;" class="mr5" /><%= cd.new_path %>
</a>
</div>