From 0f328c9c583827805077cc3451383353042e9cd5 Mon Sep 17 00:00:00 2001 From: huang Date: Thu, 10 Nov 2016 10:27:57 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=A3=E5=86=B3=E7=94=A8=E6=88=B7ID=E8=BD=AC?= =?UTF-8?q?=E6=8D=A2=E6=88=90=E7=94=A8=E6=88=B7=E5=90=8D=E5=90=8E=E5=BC=95?= =?UTF-8?q?=E5=8F=91=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/users_controller.rb | 109 +++++++++----------- app/helpers/application_helper.rb | 12 +-- app/models/user.rb | 6 +- app/views/repositories/commit_diff.html.erb | 11 +- 4 files changed, 57 insertions(+), 81 deletions(-) diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index c95366835..b1d458d49 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -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" diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index cf90e58a6..c32f6c175 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -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 diff --git a/app/models/user.rb b/app/models/user.rb index c226e2a52..8f7939bb3 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -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 diff --git a/app/views/repositories/commit_diff.html.erb b/app/views/repositories/commit_diff.html.erb index cee017978..417158c7e 100644 --- a/app/views/repositories/commit_diff.html.erb +++ b/app/views/repositories/commit_diff.html.erb @@ -2,14 +2,7 @@
<%= render :partial => "top" %>
- - - - - - - -
Commit +
Commit <%= @commit_details.id %>
  • <%= render :partial => 'commit_details', :locals => {:changeset => @commit_details} %> @@ -26,7 +19,7 @@ <% @commit_diff.each do |cd| %>