diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 39a467d53..0b3302fae 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -46,7 +46,7 @@ class UsersController < ApplicationController :user_homeworks, :destroy_membership, :user_activities, :user_projects, :user_newfeedback, :user_comments, :watch_contests, :info, :watch_projects, :show_score, :topic_score_index, :project_score_index, :activity_score_index, :influence_score_index, :score_index,:show_new_score, :topic_new_score_index, :project_new_score_index, - :activity_new_score_index, :influence_new_score_index, :score_new_index,:user_projects_index, + :activity_new_score_index, :influence_new_score_index, :score_new_index,:user_projects_index,:user_resource, :user_courses4show,:user_projects4show,:user_course_activities,:user_project_activities,:user_feedback4show,:user_visitorlist] before_filter :auth_user_extension, only: :show #before_filter :rest_user_score, only: :show @@ -807,6 +807,27 @@ class UsersController < ApplicationController end end + # 上传用户资源 + def user_resource_create + @user = User.find(params[:id]) + #@user.save_attachments(params[:attachments],User.current) + # Container_type为Principal + Attachment.attach_filesex(@user, params[:attachments], params[:attachment_type]) + @attachments = Attachment.where("author_id = #{params[:id]} and container_type in('Project','Principal','Course','Issue','Document','Message','News','StudentWorkScore','HomewCommon') ").order("created_on desc") + respond_to do |format| + format.js + end + end + + # 删除用户资源 + def user_resource_delete + Attachment.delete(params[:resource_id]) + @attachments = Attachment.where("author_id = #{params[:id]} and container_type in('Project','Principal','Course','Issue','Document','Message','News','StudentWorkScore','HomewCommon') ").order("created_on desc") + respond_to do |format| + format.js + end + end + def destroy @user.destroy respond_to do |format| @@ -1008,6 +1029,55 @@ class UsersController < ApplicationController @user = User.find(params[:id]) end + # 资源库 分为全部 课程资源 项目资源 附件 + def user_resource + #确定container_type + # @user = User.find(params[:id]) + if(params[:type].nil? || params[:type] == "1") #全部 + if User.current.id == params[:id] + @attachments = Attachment.where("author_id = #{params[:id]} and container_type in('Project','Principal','Course','Issue','Document','Message','News','StudentWorkScore','HomewCommon') ").order("created_on desc") + else + @attachments = Attachment.where("author_id = #{params[:id]} and is_public = 1 and container_type in('Project','Principal','Course','Issue','Document','Message','News','StudentWorkScore','HomewCommon') ").order("created_on desc") + end + elsif params[:type] == "2" #课程资源 + if User.current.id == params[:id] + @attachments = Attachment.where("author_id = #{params[:id]} and container_type = 'Course'").order("created_on desc") + else + @attachments = Attachment.where("author_id = #{params[:id]} and is_public = 1 and container_type = 'Course' ").order("created_on desc") + end + elsif params[:type] == "3" #项目资源 + if User.current.id == params[:id] + @attachments = Attachment.where("author_id = #{params[:id]} and container_type = 'Project'").order("created_on desc") + else + @attachments = Attachment.where("author_id = #{params[:id]} and is_public = 1 and container_type = 'Project' ").order("created_on desc") + end + elsif params[:type] == "4" #附件 + if User.current.id == params[:id] + @attachments = Attachment.where("author_id = #{params[:id]} and container_type in('Project','Issue','Document','Message','News','StudentWorkScore','HomewCommon')").order("created_on desc") + else + @attachments = Attachment.where("author_id = #{params[:id]} and is_public = 1 and container_type in('Issue','Document','Message','News','StudentWorkScore','HomewCommon')").order("created_on desc") + end + end + @type = params[:type] + respond_to do |format| + format.js + format.html {render :layout => 'base_users_new'} + end + end + + # 根据资源关键字进行搜索 + def resource_search + search = params[:search].to_s.strip.downcase + if User.current.id == params[:id] + @attachments = Attachment.where("author_id = #{params[:id]} and container_type not in ('Version','PhoneAppVersion','StudentWork') and (filename like '%#{search}%') ").order("created_on desc") + else + @attachments = Attachment.where("author_id = #{params[:id]} and container_type not in ('Version','PhoneAppVersion','StudentWork') and is_public = 1 and (filename like '%#{search}%') ").order("created_on desc") + end + respond_to do |format| + format.js + end + end + private def find_user @@ -1021,7 +1091,7 @@ class UsersController < ApplicationController render_404 end - def setting_layout(default_base='base_users') + def setting_layout(default_base='base_users_new') User.current.admin? ? default_base : default_base end @@ -1071,4 +1141,7 @@ class UsersController < ApplicationController impl.save end end + + + end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 6ac3c234a..cdcb6fc4d 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1852,7 +1852,8 @@ module ApplicationHelper candown = true elsif attachment.container.class.to_s=="StudentWork" candown = true - + elsif attachment.container.class.to_s == "User" + candown = (attachment.is_public == 1 || attachment.is_public == true || attachment.author_id == User.current.id) 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) diff --git a/app/helpers/users_helper.rb b/app/helpers/users_helper.rb index 49865d335..41458bc90 100644 --- a/app/helpers/users_helper.rb +++ b/app/helpers/users_helper.rb @@ -29,6 +29,29 @@ module UsersHelper ["#{l(:status_locked)} (#{user_count_by_status[3].to_i})", '3']], selected.to_s) end + def get_resource_type type + case type + when 'Course' + '课程资源' + when 'Project' + '项目资源' + when 'Issue' + '缺陷附件' + when 'Message' + '讨论区附件' + when 'Document' + '文档附件' + when 'News' + '通知附件' + when 'HomewCommon' + '作业附件' + when 'StudentWorkScore' + '批改附件' + when 'Principal' + '用户资源' + end + end + def user_mail_notification_options(user) user.valid_notification_options.collect {|o| [l(o.last), o.first]} end diff --git a/app/models/user.rb b/app/models/user.rb index 1cd0675c8..4fae33185 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -150,7 +150,8 @@ class User < Principal nil } - + acts_as_attachable :view_permission => :view_files, + :delete_permission => :manage_files acts_as_customizable ############################added by william acts_as_taggable @@ -239,6 +240,12 @@ class User < Principal self.user_extensions ||= UserExtensions.new end + # User现在可以作为一个Container_type,而Attachment的Container方法会有一个Container.try(:project), + # 所以这里定义一个空方法,保证不报错 + def project + + end + def user_score_attr self.user_score ||= UserScore.new end diff --git a/app/views/layouts/base_users_new.html.erb b/app/views/layouts/base_users_new.html.erb index 09d437da4..f9f065e2a 100644 --- a/app/views/layouts/base_users_new.html.erb +++ b/app/views/layouts/base_users_new.html.erb @@ -146,6 +146,12 @@ (<%=@user.projects.count%>) + <% else%> + <% end %>