diff --git a/app/api/mobile/apis/users.rb b/app/api/mobile/apis/users.rb index fa1856b3d..96b788dab 100644 --- a/app/api/mobile/apis/users.rb +++ b/app/api/mobile/apis/users.rb @@ -98,6 +98,7 @@ module Mobile params do requires :token, type: String requires :user_id, type: Integer,desc: '被留言的用户id' + requires :page,type:Integer,desc:'请求数据的页码' end get ':user_id/messages' do us = UsersService.new @@ -106,7 +107,7 @@ module Mobile present :status,0 end - desc "给用户留言或回复用户留言" + desc "回复用户留言" params do requires :token, type: String requires :user_id, type: Integer,desc: '被留言的用户id' @@ -115,12 +116,23 @@ module Mobile requires :parent_id,type:Integer,desc:'留言父id' requires :ref_message_id,type:Integer,desc:'引用消息id' end - post ':user_id/leave_message' do + post ':user_id/reply_message' do us = UsersService.new jours = us.reply_user_messages params,current_user present :status,0 end + desc "给用户留言" + params do + requires :token, type: String + requires :user_id, type: Integer,desc:'被留言的用户id' + requires :content, type: String,desc:'留言内容' + end + post ':user_id/leave_message' do + us = UsersService.new + us.leave_message params,current_user + present :data,0 + end end end end diff --git a/app/controllers/avatar_controller.rb b/app/controllers/avatar_controller.rb index afd206c92..a7c0e7b95 100644 --- a/app/controllers/avatar_controller.rb +++ b/app/controllers/avatar_controller.rb @@ -24,6 +24,7 @@ class AvatarController < ApplicationController else @image_file=params[:filename] end + @temp_file = StringIO.new(@temp_file) end end end @@ -32,7 +33,7 @@ class AvatarController < ApplicationController if @temp_file.size > Setting.upload_avatar_max_size.to_i @status = 1 @msg = l(:error_upload_avatar_to_large, :max_size => number_to_human_size(Setting.upload_avatar_max_size.to_i)) - elsif Trustie::Utils::Image.new(@temp_file.tempfile.path).image? + elsif Trustie::Utils::Image.new(@temp_file).image? diskfile=disk_filename(@source_type,@source_id) @urlfile='/' << File.join("images","avatars",avatar_directory(@source_type),avatar_filename(@source_id,@image_file)) @@ -50,6 +51,7 @@ class AvatarController < ApplicationController md5 = Digest::MD5.new File.open(diskfile, "wb") do |f| if @temp_file.respond_to?(:read) + @temp_file.rewind buffer = "" while (buffer = @temp_file.read(8192)) f.write(buffer) diff --git a/app/controllers/zipdown_controller.rb b/app/controllers/zipdown_controller.rb index 06d69f72e..d9b900833 100644 --- a/app/controllers/zipdown_controller.rb +++ b/app/controllers/zipdown_controller.rb @@ -9,10 +9,14 @@ class ZipdownController < ApplicationController #统一下载功能 def download - begin - send_file "#{OUTPUT_FOLDER}/#{params[:file]}", :filename => params[:filename], :type => detect_content_type(params[:file]) - rescue => e - render file: 'public/no_file_found.html' + if User.current.logged? + begin + send_file "#{OUTPUT_FOLDER}/#{params[:file]}", :filename => params[:filename], :type => detect_content_type(params[:file]) + rescue => e + render file: 'public/no_file_found.html' + end + else + render_403 end end diff --git a/app/services/users_service.rb b/app/services/users_service.rb index a8aacb095..7d7976bb5 100644 --- a/app/services/users_service.rb +++ b/app/services/users_service.rb @@ -158,7 +158,7 @@ class UsersService # 获取某个用户的所有留言信息 def get_all_messages params user = User.find(params[:user_id]) - jours = user.journals_for_messages.where('m_parent_id IS NULL').order('created_on DESC') + jours = user.journals_for_messages.where('m_parent_id IS NULL').order('created_on DESC').page(params[:page] || 1).per(10) jours.update_all(:is_readed => true, :status => false) jours.each do |journal| fetch_user_leaveWord_reply(journal).update_all(:is_readed => true, :status => false) @@ -184,7 +184,11 @@ class UsersService user.add_jour(nil, nil,nil,options) end - + # 给用户留言 + def leave_message params,current_user + obj = User.find(params[:user_id]).add_jour(current_user, params[:content], 0) + obj + end #关注列表 diff --git a/app/views/issues/index.html.erb b/app/views/issues/index.html.erb index bb8ea1bef..670f5c51a 100644 --- a/app/views/issues/index.html.erb +++ b/app/views/issues/index.html.erb @@ -1,16 +1,9 @@ \ No newline at end of file diff --git a/app/views/settings/_general.html.erb b/app/views/settings/_general.html.erb index 763b65515..fdb3c6f85 100644 --- a/app/views/settings/_general.html.erb +++ b/app/views/settings/_general.html.erb @@ -15,6 +15,11 @@
<%= setting_text_field :activity_days_default, :size => 6 %> <%= l(:label_day_plural) %>
<%= setting_text_field :host_name, :size => 60 %> +
<%= setting_text_field :host_course, :size => 60 %> +
<%= setting_text_field :host_contest, :size => 60 %> +
<%= setting_text_field :host_user, :size => 60 %> +
<%= setting_text_field :host_repository, :size => 60 %> + <%= l(:label_example) %>: <%= @guessed_host_and_path %>
<%= setting_select :protocol, [['HTTP', 'http'], ['HTTPS', 'https']] %>
diff --git a/config/locales/en.yml b/config/locales/en.yml index 844818ae4..09897c1eb 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -183,6 +183,10 @@ en: setting_bcc_recipients: Blind carbon copy recipients (bcc) setting_plain_text_mail: Plain text mail (no HTML) setting_host_name: Host name and path + setting_host_course: Host course and path + setting_host_contest: Host contest and path + setting_host_user: Host user and path + setting_host_repository: Host repository and path setting_text_formatting: Text formatting setting_wiki_compression: Wiki history compression setting_feeds_limit: Maximum number of items in Atom feeds diff --git a/config/locales/zh.yml b/config/locales/zh.yml index 24702ad46..4c752660a 100644 --- a/config/locales/zh.yml +++ b/config/locales/zh.yml @@ -190,6 +190,10 @@ zh: setting_bcc_recipients: 使用密件抄送 (bcc) setting_plain_text_mail: 纯文本(无HTML) setting_host_name: 主机名称 + setting_host_course: 课程域名 + setting_host_contest: 竞赛域名 + setting_host_user: 用户域名 + setting_host_repository: 仓库域名 setting_text_formatting: 文本格式 setting_wiki_compression: 压缩Wiki历史文档 setting_feeds_limit: RSS Feed内容条数限制 diff --git a/db/schema.rb b/db/schema.rb index e3828b0be..83599c087 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -659,6 +659,16 @@ ActiveRecord::Schema.define(:version => 20150514133640) do add_index "journal_details", ["journal_id"], :name => "journal_details_journal_id" + create_table "journal_details_copy", :force => true do |t| + t.integer "journal_id", :default => 0, :null => false + t.string "property", :limit => 30, :default => "", :null => false + t.string "prop_key", :limit => 30, :default => "", :null => false + t.text "old_value" + t.text "value" + end + + add_index "journal_details_copy", ["journal_id"], :name => "journal_details_journal_id" + create_table "journal_replies", :id => false, :force => true do |t| t.integer "journal_id" t.integer "user_id" diff --git a/lib/trustie/utils/image.rb b/lib/trustie/utils/image.rb index f4ec328b3..7e23e7b66 100644 --- a/lib/trustie/utils/image.rb +++ b/lib/trustie/utils/image.rb @@ -17,21 +17,20 @@ module Trustie end def jpeg?(data) - data[0,4]== 0xff.chr + 0xd8.chr + 0xff.chr + 0xe0.chr + data[0,3]== 0xff.chr + 0xd8.chr + 0xff.chr end def png?(data) data[0,2]==0x89.chr + 80.chr end def image? - begin - f = File.open(@file,'rb') # rb means to read using binary - return false if f.size < 9 - data = f.read(9) # magic numbers are up to 9 bytes - return bitmap?(data) || gif?(data) || jpeg?(data) || png?(data) - ensure - f.close + data = '' + if @file.respond_to?(:read) + data = @file.read(9) + @file.rewind end + return false if data.size < 9 + bitmap?(data) || gif?(data) || jpeg?(data) || png?(data) end def compress(size=300) diff --git a/spec/requests/avatar_request_spec.rb b/spec/requests/avatar_request_spec.rb new file mode 100644 index 000000000..da80e38bf --- /dev/null +++ b/spec/requests/avatar_request_spec.rb @@ -0,0 +1,15 @@ +require 'rails_helper' + +RSpec.describe "avatar request", type: :request do + describe "上传头像" do + let(:user){FactoryGirl.create(:user)} + + it "参数正确,可以成功上传头像" do + data = File.open("#{Rails.root}/spec/fixtures/test.jpg").read + binding.pry + post upload_avatar_path(source_type: 'User', source_id: user.id, filename: 'test.jpg') + expect(response).to have_http_status(:success) + expect(response.body).to include(/\/images\/avatars\/User\//) + end + end +end