This commit is contained in:
sw 2014-07-28 17:50:13 +08:00
commit e344f16f5c
8 changed files with 131 additions and 44 deletions

View File

@ -26,6 +26,7 @@ class AttachmentsController < ApplicationController
accept_api_auth :show, :download, :upload
require 'iconv'
def show
respond_to do |format|
format.html {
@ -41,6 +42,13 @@ class AttachmentsController < ApplicationController
render :action => 'diff'
elsif @attachment.is_text? && @attachment.filesize <= Setting.file_max_size_displayed.to_i.kilobyte
@content = File.new(@attachment.diskfile, "rb").read
# 编码为非 UTF-8先进行间接转码
# 部分unicode编码不直接支持转为 UTF-8
# modify by nwb
if @content.encoding.name != 'UTF-8'
@content = @content.force_encoding('GBK')
@content = @content.encode('UTF-8')
end
render :action => 'file'
else
download
@ -173,7 +181,7 @@ class AttachmentsController < ApplicationController
respond_to do |format|
# modify by nwb
if !@attachment.container.nil? && (@attachment.container.is_a?(Course) || @attachment.container.course)
if !@attachment.container.nil? && (@attachment.container.has_attribute?(:course) ||@attachment.container.has_attribute?(:course_id) ) &&(@attachment.container.is_a?(Course) || @attachment.container.course)
if @attachment.container.is_a?(News)
format.html { redirect_to_referer_or news_path(@attachment.container) }
elsif @course.nil?
@ -235,6 +243,9 @@ class AttachmentsController < ApplicationController
attach_copied_obj.container = obj
attach_copied_obj.created_on = Time.now
attach_copied_obj.author_id = User.current.id
if attach_copied_obj.attachtype == nil
attach_copied_obj.attachtype = 1
end
@obj = obj
@save_flag = attach_copied_obj.save
@save_message = attach_copied_obj.errors.full_messages
@ -264,6 +275,9 @@ class AttachmentsController < ApplicationController
attach_copied_obj.container = obj
attach_copied_obj.created_on = Time.now
attach_copied_obj.author_id = User.current.id
if attach_copied_obj.attachtype == nil
attach_copied_obj.attachtype = 4
end
@obj = obj
@save_flag = attach_copied_obj.save
@save_message = attach_copied_obj.errors.full_messages

View File

@ -263,9 +263,6 @@ class UsersController < ApplicationController
sort_init 'login', 'asc'
sort_update %w(login firstname lastname mail admin created_on last_login_on)
# Deprecation
@project_type = params[:project_type]
case params[:format]
when 'xml', 'json'
@offset, @limit = api_offset_and_limit({:limit => 15})
@ -274,16 +271,9 @@ class UsersController < ApplicationController
end
# retrieve all users
scope = UserStatus.visible
# if role has something, change scope.
case params[:role]
when 'teacher'
scope = UserStatus.teacher
when 'student'
scope = UserStatus.student
else
end
# 先内连一下statuses 保证排序之后数量一致
scope = User.visible.
joins("INNER JOIN user_statuses ON users.id = user_statuses.user_id")
# unknow
scope = scope.in_group(params[:group_id]) if params[:group_id].present?
@ -295,25 +285,32 @@ class UsersController < ApplicationController
# users classify
case params[:user_sort_type]
when '0'
# 创建时间排序
@s_type = 0
@us_ordered = scope.
joins("LEFT JOIN users ON user_statuses.user_id = users.id").
reorder('users.created_on DESC')
@users = scope.reorder('users.created_on DESC')
when '1'
# 活跃度排序, 就是所谓的得分情况
@s_type = 1
@us_ordered = scope.reorder('user_statuses.grade DESC')
@users = scope.
joins("LEFT JOIN user_scores ON users.id = user_scores.user_id").
reorder('user_scores.active DESC')
when '2'
# 粉丝数排序
@s_type = 2
@us_ordered = scope.reorder('user_statuses.watchers_count DESC')
@users = scope.
#joins("INNER JOIN user_statuses ON users.id = user_statuses.user_id").
reorder('user_statuses.watchers_count DESC')
else
# 默认活跃度排序
@s_type = 1
@us_ordered = scope.reorder('user_statuses.grade DESC')
@users = scope.
joins("LEFT JOIN user_scores ON users.id = user_scores.user_id").
reorder('user_scores.active DESC')
end
# limit and offset
@users_statuses = @us_ordered.offset(@user_pages.offset).limit(@user_pages.per_page)
# get users ActiveRecord
@users = @users_statuses.includes(:user).map(&:user)
@users = @users.limit(@user_pages.per_page).offset(@user_pages.offset)
@user_base_tag = params[:id] ? 'base_users':'users_base'
respond_to do |format|

View File

@ -186,6 +186,7 @@ en:
notice_account_deleted: "Your account has been permanently deleted."
notice_user_successful_create: "User %{id} created."
error_attachment_empty: "error in add file"
error_class_period_only_num: "class period can only digital"
error_can_t_load_default_data: "Default configuration could not be loaded: %{value}"
error_scm_not_found: "The entry or revision was not found in the repository."

View File

@ -195,6 +195,7 @@ zh:
notice_gantt_chart_truncated: "这个表是截断的因为它超过了可以显示的最大数量(%{max})"
error_complete_occupation: "请您填写工作单位,否则本系统的部分功能将无法正常使用。"
error_attachment_empty: "添加文件出错!"
error_class_period_only_num: "课程学时只能为数字"
error_can_t_load_default_data: "无法载入默认设置:%{value}"

View File

@ -439,6 +439,26 @@ ActiveRecord::Schema.define(:version => 20140728014933) do
t.datetime "updated_at", :null => false
end
create_table "gitlab_projects", :force => true do |t|
t.integer "gitlab_project_id"
t.integer "project_id"
t.string "repository_url"
t.string "web_url"
t.string "localfile_url"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
create_table "gitlab_users", :force => true do |t|
t.integer "gitlab_user_id"
t.integer "user_id"
t.string "email"
t.string "password"
t.string "login", :null => false
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
create_table "groups_users", :id => false, :force => true do |t|
t.integer "group_id", :null => false
t.integer "user_id", :null => false
@ -881,19 +901,6 @@ ActiveRecord::Schema.define(:version => 20140728014933) do
add_index "repositories", ["project_id"], :name => "index_repositories_on_project_id"
create_table "rich_rich_files", :force => true do |t|
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.string "rich_file_file_name"
t.string "rich_file_content_type"
t.integer "rich_file_file_size"
t.datetime "rich_file_updated_at"
t.string "owner_type"
t.integer "owner_id"
t.text "uri_cache"
t.string "simplified_type", :default => "file"
end
create_table "roles", :force => true do |t|
t.string "name", :limit => 30, :default => "", :null => false
t.integer "position", :default => 1

View File

@ -1,11 +1,12 @@
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html
one:
act_id:
act_type: MyString
user_id:
id: 1
act_id: 1
act_type: JournalsForMessage
user_id: 5
two:
act_id:
act_type: MyString
user_id:
act_id: 2
act_type: JournalsForMessage
user_id: 5

View File

@ -1,4 +1,34 @@
jfm_001:
id: 1
jour_id: 5
jour_type: Principal
user_id: 2
notes:
status: 0
reply_id: 0
created_on: 2014-07-16 15:27:2
updated_on: 2014-07-16 15:27:2
m_parent_id:
is_readed:
m_reply_count:
m_reply_id:
is_comprehensive_evaluation:
jfm_002:
id: 2
jour_id: 5
jour_type: Principal
user_id: 2
notes: 我觉得这个系统挺实用界面挺简洁美观1
status:
reply_id: 0
created_on: 2014-07-16 15:27:2
updated_on: 2014-07-16 15:27:2
m_parent_id:
is_readed:
m_reply_count:
m_reply_id:
is_comprehensive_evaluation:
jfm_045:
id: 45
jour_id: 2
jour_type: Project
@ -64,7 +94,7 @@ jfm_060:
jour_id: 2
jour_type: Project
user_id: 2
notes: something very nice
notes:
status:
reply_id: 0
created_on: 2013-08-21 07:04:43
@ -119,4 +149,3 @@ jfm_088:
m_reply_count:
m_reply_id:
is_comprehensive_evaluation:

View File

@ -0,0 +1,37 @@
require File.expand_path('../../test_helper', __FILE__)
class UsersControllerTest < ActionController::TestCase
fixtures :users, :projects, :members, :member_roles, :roles,
:custom_fields, :custom_values, :groups_users,
:auth_sources,
:activities,
:journals_for_messages
def setup
User.current = nil
@request.session[:user_id] = 1
@request.session[:ctime] = Time.now
@request.session[:atime] = Time.now
end
test '#index by non-member' do
@request.session[:user_id] = nil
get :index
assert_response :success
assert_template 'index'
end
test '#show by non-member' do
@request.session[:user_id] = 8
get :show, {id: 5}
assert_response :success
assert_template 'show'
end
test '#user_newfeedback by non-member' do
@request.session[:user_id] = nil
get :user_newfeedback, {id: 5}
assert_response :success
assert_template 'user_newfeedback'
end
end