diff --git a/app/api/mobile/apis/users.rb b/app/api/mobile/apis/users.rb index 675ad33c5..508d95200 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 @@ -111,11 +112,13 @@ module Mobile requires :token, type: String requires :user_id, type: Integer,desc: '被留言的用户id' requires :content,type:String,desc:'留言内容' - optional :refer_user_id,type:Integer,desc:'被回复的用户id' + requires :ref_user_id,type:Integer,desc:'被回复的用户id' + requires :parent_id,type:Integer,desc:'留言父id' + requires :ref_message_id,type:Integer,desc:'引用消息id' end post ':user_id/leave_message' do us = UsersService.new - jours = us.leave_messages params,current_user + jours = us.reply_user_messages params,current_user present :status,0 end diff --git a/app/controllers/avatar_controller.rb b/app/controllers/avatar_controller.rb index ef7cdf2f7..a7c0e7b95 100644 --- a/app/controllers/avatar_controller.rb +++ b/app/controllers/avatar_controller.rb @@ -1,9 +1,9 @@ class AvatarController < ApplicationController - - + + include ActionView::Helpers::NumberHelper #before_filter :set_cache_buster include AvatarHelper - + def upload # Make sure that API users get used to set this content type # as it won't trigger Rails' automatic parsing of the request body for parameters @@ -24,48 +24,58 @@ class AvatarController < ApplicationController else @image_file=params[:filename] end + @temp_file = StringIO.new(@temp_file) end end end if @temp_file && (@temp_file.size > 0) - diskfile=disk_filename(@source_type,@source_id) - @urlfile='/' << File.join("images","avatars",avatar_directory(@source_type),avatar_filename(@source_id,@image_file)) + 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).image? + diskfile=disk_filename(@source_type,@source_id) + @urlfile='/' << File.join("images","avatars",avatar_directory(@source_type),avatar_filename(@source_id,@image_file)) - # 用户头像上传时进行特别处理 - if @source_type == 'User' + # 用户头像上传时进行特别处理 + if @source_type == 'User' diskfile += "temp" @urlfile += "temp" - end - - logger.info("Saving avatar '#{diskfile}' (#{@temp_file.size} bytes)") - path = File.dirname(diskfile) - unless File.directory?(path) - FileUtils.mkdir_p(path) - end - md5 = Digest::MD5.new - File.open(diskfile, "wb") do |f| - if @temp_file.respond_to?(:read) - buffer = "" - while (buffer = @temp_file.read(8192)) - f.write(buffer) - md5.update(buffer) - end - else - f.write(@temp_file) - md5.update(@temp_file) end + + logger.info("Saving avatar '#{diskfile}' (#{@temp_file.size} bytes)") + path = File.dirname(diskfile) + unless File.directory?(path) + FileUtils.mkdir_p(path) + end + 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) + md5.update(buffer) + end + else + f.write(@temp_file) + md5.update(@temp_file) + end + end + + Trustie::Utils::Image.new(diskfile,true).compress(300) + @status = 0 + @msg = '' + else + @status = 2 + @msg = l(:not_valid_image_file) end -# self.digest = md5.hexdigest end @temp_file = nil - image = Trustie::Utils::Image.new(diskfile,true) - image.compress(300) - respond_to do |format| format.json{ - render :inline => "#{@urlfile.to_s}?#{Time.now.to_i}",:content_type => 'text/html' + render :inline => {status: @status, message:@msg, url:"#{@urlfile.to_s}?#{Time.now.to_i}"}.to_json,:content_type => 'text/html' return } format.js diff --git a/app/controllers/files_controller.rb b/app/controllers/files_controller.rb index aa2c9574b..0003f7586 100644 --- a/app/controllers/files_controller.rb +++ b/app/controllers/files_controller.rb @@ -67,9 +67,7 @@ class FilesController < ApplicationController end sort = "#{@sort} #{@order}" end - # show_attachments [@course] - begin q = "%#{params[:name].strip}%" #(redirect_to stores_url, :notice => l(:label_sumbit_empty);return) if params[:name].blank? @@ -108,14 +106,18 @@ class FilesController < ApplicationController end sort = "#{@sort} #{@order}" end - begin q = "%#{params[:name].strip}%" #(redirect_to stores_url, :notice => l(:label_sumbit_empty);return) if params[:name].blank? if params[:insite] - @result = find_public_attache q,sort - @result = visable_attachemnts_insite @result,@project - @searched_attach = paginateHelper @result,10 + if q == "%%" + @result = [] + @searched_attach = paginateHelper @result,10 + else + @result = find_public_attache q,sort + @result = visable_attachemnts_insite @result,@project + @searched_attach = paginateHelper @result,10 + end else @result = find_project_attache q,@project,sort @result = visable_attachemnts @result diff --git a/app/controllers/issues_controller.rb b/app/controllers/issues_controller.rb index 8acca7f81..83f68d8d8 100644 --- a/app/controllers/issues_controller.rb +++ b/app/controllers/issues_controller.rb @@ -169,7 +169,7 @@ class IssuesController < ApplicationController attrs = {:tracker_id => @issue.tracker, :parent_issue_id => @issue.parent_issue_id}.reject {|k,v| v.nil?} redirect_to new_project_issue_url(@issue.project, :issue => attrs) else - redirect_to issue_url(@issue) + redirect_to issue_url(@issue.id) end } format.api { render :action => 'show', :status => :created, :location => issue_url(@issue) } @@ -239,7 +239,8 @@ class IssuesController < ApplicationController flash[:notice] = l(:notice_successful_update) unless @issue.current_journal.new_record? respond_to do |format| - format.html { redirect_back_or_default issue_path(@issue) } + + format.html { redirect_to issue_url(@issue.id) } format.api { render_api_ok } end else diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index c79d0862f..536ea6bba 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -247,9 +247,9 @@ class ProjectsController < ApplicationController # 1、自动注册 # 2、加入项目、创建角色 # 3、用户得分 - if params[:email] - user = User.find_by_mail(params[:email].to_s) - Member.create(:role_ids => [4], :user_id => user.id,:project_id => @project.id) + if params[:mail] + Member.create(:role_ids => [4], :user_id => params[:user],:project_id => params[:id]) + UserGrade.create(:user_id =>params[:user], :project_id => params[:id]) end if params[:jump] && redirect_to_project_menu_item(@project, params[:jump]) return 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/helpers/account_helper.rb b/app/helpers/account_helper.rb index 7ad6fe65b..827557a40 100644 --- a/app/helpers/account_helper.rb +++ b/app/helpers/account_helper.rb @@ -47,6 +47,18 @@ module AccountHelper user end + # 自动创建一个新用户,但是初始状态是锁定的 + def automatically_register_lock(user, &block) + user.lock + user.last_login_on = Time.now + if user.save + UserStatus.create(:user_id => user.id, :changsets_count => 0, :watchers_count => 0) + else + yield if block_given? + end + user + end + def administrator_manually__register(user, &block) if user.save UserStatus.create(:user_id => user.id ,:changsets_count => 0, :watchers_count => 0) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 0836bf307..a07ff320d 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -622,8 +622,8 @@ module ApplicationHelper # 公开项目资源可以引用,admin和管理员和资源上传者拥有设置公开私有权限 def authority_pubilic_for_files(project, file) @result = false - if (is_project_manager?(User.current.id, @project.id) || file.author_id == User.current.id || User.current.admin) && - project_contains_attachment?(project,file) && file.container_id == project.id && file.container_type == "Project" + if (is_project_manager?(User.current.id, @project.id) && User.current.allowed_to?(:manage_files, project)) || file.author_id == User.current.id || User.current.admin && + project_contains_attachment?(project,file) && file.container_id == project.id && file.container_type == "Project" @result = true end return @result diff --git a/app/helpers/projects_helper.rb b/app/helpers/projects_helper.rb index 508e58ba3..12925b0b1 100644 --- a/app/helpers/projects_helper.rb +++ b/app/helpers/projects_helper.rb @@ -65,6 +65,16 @@ module ProjectsHelper content_tag('div', content, :class => "tabs") end + # 判断我的项目中是否有重名项目 + def judge_same_projectname(user, project_name) + result = false + my_projects = user.projects + my_projects.each do |mp| + result = true if mp.name == project_name + end + return result + end + # Added by young def course_settings_tabs tabs = [{:name => 'info', :action => :edit_project, :partial => 'projects/edit', :label => :label_information_plural, :course=>'1'}, diff --git a/app/helpers/queries_helper.rb b/app/helpers/queries_helper.rb index d9d910a66..43d01a5dd 100644 --- a/app/helpers/queries_helper.rb +++ b/app/helpers/queries_helper.rb @@ -255,7 +255,7 @@ module QueriesHelper # Give it a name, required to be valid @query = IssueQuery.new(:name => "_") @query.project = @project - params[:f] = %w(subject status_id priority_id author_id assigned_to_id) unless params[:status_id].nil? + params[:f] = %w(subject status_id priority_id author_id assigned_to_id created_on) unless params[:status_id].nil? params[:op] = {'subject' => "~" , 'status_id' => ( params[:status_id] == '0' ? "!":"=" ), 'priority_id' => ( params[:priority_id] == '0' ? "!":"=" ), @@ -266,6 +266,22 @@ module QueriesHelper 'priority_id' => [params[:priority_id]], 'author_id' => [params[:author_id]], 'assigned_to_id' => [params[:assigned_to_id]]} unless params[:status_id].nil? + if(params[:status_id] != nil) + if( params[:issue_create_date_start]!=nil && params[:issue_create_date_start]!='' && + params[:issue_create_date_end]!=nil && params[:issue_create_date_end]!='' ) + params[:op][:created_on]='><' + params[:v][:created_on]=[params[:issue_create_date_start],params[:issue_create_date_end]] + elsif(params[:issue_create_date_start]!=nil && params[:issue_create_date_start]!='') + params[:op][:created_on]='>=' + params[:v][:created_on]=[params[:issue_create_date_start]] + elsif(params[:issue_create_date_end]!=nil && params[:issue_create_date_end]!='') + params[:op][:created_on]='<=' + params[:v][:created_on]=[params[:issue_create_date_end]] + else + params[:op][:created_on]='!' + params[:v][:created_on]='' + end + end @query.build_from_params(params) #session[:query] = {:project_id => @query.project_id, :filters => @query.filters, :group_by => @query.group_by, :column_names => @query.column_names} # else diff --git a/app/models/mailer.rb b/app/models/mailer.rb index 7756b7e27..2c3a94874 100644 --- a/app/models/mailer.rb +++ b/app/models/mailer.rb @@ -58,14 +58,10 @@ class Mailer < ActionMailer::Base us = UsersService.new # 自动激活用户 user = us.register_auto(login, @email, @password) - - Member.create(:role_ids => [4], :user_id => user.id,:project_id => project.id) - UserGrade.create(:user_id => user.id, :project_id => project.id) User.current = user unless User.current.nil? @user = user @token = Token.get_token_from_user(user, 'autologin') - @project_url = url_for(:controller => 'projects', :action => 'show', :id => project.id,:user => user, :token => @token.value - ) + @project_url = url_for(:controller => 'projects', :action => 'show', :id => project.id, :user => user.id, :mail => true, :token => @token.value) mail :to => email, :subject => @subject end @@ -77,7 +73,7 @@ class Mailer < ActionMailer::Base @project_name = "#{project.name}" @user = user @token = Token.get_token_from_user(user, 'autologin') - @project_url = url_for(:controller => 'projects', :action => 'show', :id => project.id, :email => email, :token => @token.value) + @project_url = url_for(:controller => 'projects', :action => 'show', :id => project.id, :user => user.id, :mail => true, :token => @token.value) mail :to => email, :subject => @subject end diff --git a/app/models/project.rb b/app/models/project.rb index f257058ea..47878dbec 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -114,7 +114,7 @@ class Project < ActiveRecord::Base validates_presence_of :name, :identifier validates_uniqueness_of :identifier - validates_uniqueness_of :name + # validates_uniqueness_of :name validates_associated :wiki#, :repository # validates_length_of :description, :maximum => 255 validates_length_of :name, :maximum => 255 diff --git a/app/services/users_service.rb b/app/services/users_service.rb index 6e566b519..1ae477d74 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) @@ -166,13 +166,22 @@ class UsersService jours end - # 给某个用户留言 - def leave_messages params,current_user + # 回复用户 + def reply_user_messages params,current_user user = User.find(params[:user_id]) - user.add_jour(current_user, params[:content], params[:refer_user_id] ||= 0) - unless params[:refer_user_id].nil? || params[:refer_user_id] == 0 || params[:refer_user_id] == User.current.id - User.find(params[:refer_user_id]).add_jour(current_user, params[:content], params[:refer_user_id]) - end + parent_id = params[:parent_id] + author_id = current_user.id + reply_user_id = params[:ref_user_id] + reply_id = params[:ref_message_id] + content = params[:content] + options = {:user_id => author_id, + :status => true, + :m_parent_id => parent_id, + :m_reply_id => reply_id, + :reply_id => reply_user_id, + :notes => content, + :is_readed => false} + user.add_jour(nil, nil,nil,options) end diff --git a/app/views/bids/_new_homework_form.html.erb b/app/views/bids/_new_homework_form.html.erb index 7a5f628f9..5958fccff 100644 --- a/app/views/bids/_new_homework_form.html.erb +++ b/app/views/bids/_new_homework_form.html.erb @@ -15,10 +15,10 @@ <% if edit_mode %> - <%= f.kindeditor :description,:width=>'91%',:editor_id => 'bid_description_editor',:owner_id => bid.id,:owner_type =>OwnerTypeHelper::BID %> + <%= f.kindeditor :description,:width=>'91%',:editor_id => 'bid_description_editor',:owner_id => bid.id,:owner_type =>OwnerTypeHelper::BID,:resizeType => 0 %> <% else %> <%= hidden_field_tag :asset_id,params[:asset_id],:required => false,:style => 'display:none' %> - <%= f.kindeditor :description,:width=>'91%',:editor_id => 'bid_description_editor' %> + <%= f.kindeditor :description,:width=>'91%',:editor_id => 'bid_description_editor',:resizeType => 0 %> <% end %>
diff --git a/app/views/contests/index.html.erb b/app/views/contests/index.html.erb index 170f11037..26e9e2114 100644 --- a/app/views/contests/index.html.erb +++ b/app/views/contests/index.html.erb @@ -46,9 +46,7 @@ <%= text_field_tag 'name', params[:name], :size => 30, :onkeyup => 'regexName1();', :width => "125px" %> <%= hidden_field_tag 'project_type', params[:project_type] %> <%#= submit_tag l(:label_search), :class => "enterprise", :name => "contests_search" %> - - <%= l(:label_search)%> - + <%= submit_tag l(:label_search), :class => "enterprise", :name => "contests_search" %><%= content_tag "span", "#{l(:label_course_brief_introduction)}:", :class => "course-font" %> - <%= content_tag "div", course.short_description, :class => "brief_introduction", :title => course.short_description %>
+ <%= content_tag "div", course.short_description, :class => "brief_introduction",:style=>'float:left;', :title => course.short_description %> diff --git a/app/views/files/_project_file_list.html.erb b/app/views/files/_project_file_list.html.erb index d32d2319f..35aa36195 100644 --- a/app/views/files/_project_file_list.html.erb +++ b/app/views/files/_project_file_list.html.erb @@ -1,4 +1,4 @@ - +<% delete_allowed = User.current.allowed_to?(:manage_files, project) %>共有 <%= all_attachments.count%> 个资源
@@ -22,13 +22,13 @@ <% if User.current.logged? %> <% if (manage_allowed || file.author_id == User.current.id) && project_contains_attachment?(project,file) %> <%= link_to(l(:label_slected_to_other_project),quote_resource_show_project_project_file_path(project,file),:class => "f_l re_select",:remote => true) if has_project?(User.current,file) %> - <% else %> - <%= link_to(l(:label_slected_to_project),quote_resource_show_project_project_file_path(project,file),:class => "f_l re_select",:remote => true) if has_project?(User.current,file) %> - <% end %> - <% if authority_pubilic_for_files(project, file) %> + <% if authority_pubilic_for_files(project, file) && delete_allowed %> <%= link_to (file.is_public? ? "公开":"私有"), update_file_dense_attachments_path(:attachmentid=>file.id,:newtype=>(file.is_public? ? 0:1)),:remote=>true,:class=>"f_l re_open",:method => :post %> + <% end %> + <% else %> + <%= link_to(l(:label_slected_to_project),quote_resource_show_project_project_file_path(project,file),:class => "f_l re_select",:remote => true) if has_project?(User.current,file) %> <% end %> <% end %>
+