diff --git a/app/api/mobile/apis/auth.rb b/app/api/mobile/apis/auth.rb index 320497e50..fbec9a3b0 100644 --- a/app/api/mobile/apis/auth.rb +++ b/app/api/mobile/apis/auth.rb @@ -40,6 +40,17 @@ module Mobile {status: 0} end + desc "忘记密码" + params do + requires :mail,type: String + end + post 'lost_password' do + us = UsersService.new + message = us.lost_password params + present :message, message + present :status, 0 + end + end end end diff --git a/app/api/mobile/apis/upgrade.rb b/app/api/mobile/apis/upgrade.rb index 02ff97185..e6a7916d9 100644 --- a/app/api/mobile/apis/upgrade.rb +++ b/app/api/mobile/apis/upgrade.rb @@ -3,16 +3,23 @@ module Mobile module Apis class Upgrade < Grape::API + include ApplicationHelper resource :upgrade do desc "get update info" params do requires :platform, type: String, desc: '平台名,android, ios' end get do + @current_version = ::PhoneAppVersion.reorder('created_at desc').first + attachment = @current_version.attachments.first + if attachment.nil? + raise '未发现客户端!' + end + url = Setting.host_name + "/attachments/download/" + attachment.id.to_s + "/" + attachment.filename { - version: '2', - url: 'http://u06.shellinfo.cn/trustie/Trustie_Beta1.0.0_201412310917.apk', - desc: '更新了什么功能' + version: @current_version.version, + url: url, + desc: @current_version.description } end end diff --git a/app/api/mobile/entities/course_dynamic.rb b/app/api/mobile/entities/course_dynamic.rb index 5e22e3df7..aa8aadbb6 100644 --- a/app/api/mobile/entities/course_dynamic.rb +++ b/app/api/mobile/entities/course_dynamic.rb @@ -1,9 +1,15 @@ module Mobile module Entities class CourseDynamic < Grape::Entity + include Redmine::I18n def self.course_dynamic_expose(field) expose field do |c,opt| - c[field] if (c.is_a?(Hash) && c.key?(field)) + if field == :update_time + (format_time(c[field]) if (c.is_a?(Hash) && c.key?(field))) + else + c[field] if (c.is_a?(Hash) && c.key?(field)) + end + end end course_dynamic_expose :type @@ -11,6 +17,8 @@ module Mobile course_dynamic_expose :course_name course_dynamic_expose :course_id course_dynamic_expose :course_img_url + course_dynamic_expose :message + course_dynamic_expose :update_time end end end \ No newline at end of file diff --git a/app/controllers/admin_controller.rb b/app/controllers/admin_controller.rb index c77ebe704..8e23041c6 100644 --- a/app/controllers/admin_controller.rb +++ b/app/controllers/admin_controller.rb @@ -337,6 +337,40 @@ class AdminController < ApplicationController end def create_version + @versions = PhoneAppVersion.reorder('created_at desc') + @new_version = PhoneAppVersion.new + @new_version.version = params[:version] + @new_version.description = params[:description] + if params[:attachments][:dummy][:file].nil? || params[:attachments][:dummy][:file] == "" + respond_to do |format| + flash.now[:error] = "#{l :label_version_create_fail}: #{l(:label_client_need)}" + #flash.now[:error] = "#{l :label_first_page_create_fail}: #{@course_page.errors.full_messages[0]}" + format.html { + render :action => 'mobile_version' + } + format.api { render_validation_errors(@new_version) } + end + else + @new_version.save_attachments(params[:attachments] || (params[:version] && params[:version][:uploads])) + if @new_version.save + respond_to do |format| + format.html { + flash[:notice] = l(:notice_successful_create) + redirect_to mobile_version_url + } + format.api { render_api_ok } + end + else + respond_to do |format| + flash.now[:error] = "#{l :label_version_create_fail}: #{@new_version.errors.full_messages[0]}" + #flash.now[:error] = "#{l :label_first_page_create_fail}: #{@course_page.errors.full_messages[0]}" + format.html { + render :action => 'mobile_version' + } + format.api { render_validation_errors(@new_version) } + end + end + end end diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 06e5dac30..47251cf85 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -177,6 +177,25 @@ class ApplicationController < ActionController::Base end end + def logged_user_by_apptoken + #从手机端传来apptoken则将当前登陆用户变为对应的用户 + if params[:apptoken] + token = ApiKey.where(access_token: params[:apptoken]).first + if token.expired? + return + end + if token && !token.expired? + @current_user = User.find(token.user_id) + end + unless @current_user.nil? + self.logged_user = @current_user + if @current_user + @current_user.update_column(:last_login_on, Time.now) + end + end + end + end + # Logs out current user def logout_user if User.current.logged? diff --git a/app/controllers/attachments_controller.rb b/app/controllers/attachments_controller.rb index ccc879c1c..72f4bdd92 100644 --- a/app/controllers/attachments_controller.rb +++ b/app/controllers/attachments_controller.rb @@ -231,6 +231,8 @@ class AttachmentsController < ApplicationController format.html { redirect_to_referer_or softapplications_path(@attachment.container) } elsif !@attachment.container.nil? && @attachment.container.is_a?(Bid) format.html { redirect_to_referer_or respond_path(@attachment.container) } + elsif !@attachment.container.nil? && @attachment.container.is_a?(PhoneAppVersion) + format.html { redirect_to_referer_or mobile_version_path } else if @project.nil? format.html { redirect_to_referer_or forum_memo_path(@attachment.container.forum, @attachment.container) } @@ -415,7 +417,7 @@ private @attachment.container.board.course) @course = @attachment.container.board.course else - unless @attachment.container_type == 'Bid' || @attachment.container_type == 'HomeworkAttach' || @attachment.container_type == 'Memo' || @attachment.container_type == 'Softapplication' + unless @attachment.container_type == 'Bid' || @attachment.container_type == 'HomeworkAttach' || @attachment.container_type == 'Memo' || @attachment.container_type == 'Softapplication' || @attachment.container_type == 'PhoneAppVersion' @project = @attachment.project end end diff --git a/app/controllers/boards_controller.rb b/app/controllers/boards_controller.rb index 67355fdfa..f797c7a2f 100644 --- a/app/controllers/boards_controller.rb +++ b/app/controllers/boards_controller.rb @@ -30,6 +30,7 @@ class BoardsController < ApplicationController def index #modify by nwb + @flag = params[:flag] || false if @project @boards = @project.boards.includes(:last_message => :author).all @boards = [] << @boards[0] if @boards.any? diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index 8fae547c4..9b66c047f 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -17,6 +17,7 @@ class CoursesController < ApplicationController menu_item l(:label_sort_by_influence), :only => :index before_filter :can_show_course, :except => [] + before_filter :logged_user_by_apptoken,:only => [:show,:new_homework,:feedback] before_filter :find_course, :except => [ :index, :search,:list, :new,:join,:unjoin, :create, :copy, :statistics, :new_join, :course, :enterprise_course, :course_enterprise,:view_homework_attaches,:join_private_courses] before_filter :authorize_course, :only => [:show, :settings, :edit, :update, :modules, :close, :reopen, :view_homework_attaches, :course] before_filter :authorize_course_global, :only => [:view_homework_attaches, :new,:create] diff --git a/app/controllers/files_controller.rb b/app/controllers/files_controller.rb index 7638949ba..28156ac0c 100644 --- a/app/controllers/files_controller.rb +++ b/app/controllers/files_controller.rb @@ -21,6 +21,7 @@ class FilesController < ApplicationController menu_item :files before_filter :auth_login1, :only => [:index] + before_filter :logged_user_by_apptoken,:only => [:index] before_filter :find_project_by_project_id#, :except => [:getattachtype] before_filter :authorize, :except => [:getattachtype,:quote_resource_show,:search] @@ -98,6 +99,7 @@ class FilesController < ApplicationController end def index + @flag = params[:flag] || false #sort_init 'filename', 'asc' sort_init 'created_on', 'desc' sort_update 'created_on' => "#{Attachment.table_name}.created_on", diff --git a/app/controllers/homework_attach_controller.rb b/app/controllers/homework_attach_controller.rb index 2c943e778..ba7e92467 100644 --- a/app/controllers/homework_attach_controller.rb +++ b/app/controllers/homework_attach_controller.rb @@ -6,7 +6,7 @@ class HomeworkAttachController < ApplicationController ############################### before_filter :can_show_course,except: [] #判断当前角色权限时需先找到当前操作的project - before_filter :find_course_by_bid_id, :only => [:new] + before_filter :logged_user_by_apptoken,:find_course_by_bid_id, :only => [:new] before_filter :find_bid_and_course,:only => [:get_not_batch_homework,:get_batch_homeworks,:get_homeworks,:get_homework_jours, :get_student_batch_homework, :get_my_homework] before_filter :find_course_by_hoemwork_id, :only => [:edit,:update,:destroy,:show,:add_homework_users,:destory_homework_users, :praise_homework] #判断当前角色是否有操作权限 diff --git a/app/controllers/members_controller.rb b/app/controllers/members_controller.rb index ce899eff5..d0be72961 100644 --- a/app/controllers/members_controller.rb +++ b/app/controllers/members_controller.rb @@ -107,17 +107,24 @@ class MembersController < ApplicationController AppliedProject.deleteappiled(member.user_id, @project.id) end end - respond_to do |format| - format.html { redirect_to_settings_in_projects } - format.js { @members = members; @applied_members = applied_members; } - format.api { - @member = members.first - if @member.valid? - render :action => 'show', :status => :created, :location => membership_url(@member) - else - render_validation_errors(@member) - end - } + if params[:flag] + flash[:notice] = l(:label_invite_success) + respond_to do |format| + format.html { redirect_to invite_members_project_url(@project) } + end + else + respond_to do |format| + format.html { redirect_to_settings_in_projects } + format.js { @members = members; @applied_members = applied_members; } + format.api { + @member = members.first + if @member.valid? + render :action => 'show', :status => :created, :location => membership_url(@member) + else + render_validation_errors(@member) + end + } + end end elsif @course course_info = [] @@ -310,6 +317,7 @@ class MembersController < ApplicationController end def autocomplete + @flag = params[:flag] || false respond_to do |format| format.js end diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index 052df384e..4f84212b4 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -180,6 +180,7 @@ class ProjectsController < ApplicationController @project = Project.new @project.safe_attributes = params[:project] @project.organization_id = params[:organization_id] + @project.user_id = User.current.id if validate_parent_id && @project.save @project.set_allowed_parent!(params[:project]['parent_id']) if params[:project].has_key?('parent_id') # Add current user as a project member if he is not admin @@ -333,8 +334,7 @@ class ProjectsController < ApplicationController end def send_mail_to_member - - if !params[:mail].nil? && User.find_by_mail(params[:mail].to_s).nil? + if !params[:mail].blank? && User.find_by_mail(params[:mail].to_s).nil? email = params[:mail] Mailer.send_invite_in_project(email, @project, User.current).deliver @is_zhuce =false @@ -347,16 +347,27 @@ class ProjectsController < ApplicationController end #发送邮件邀请新用户 def invite_members_by_mail - @is_zhuce =false - respond_to do |format| - format.html - format.js + if User.current.member_of?(@project) || User.current.admin? + @is_zhuce = false + respond_to do |format| + format.html + format.js + end + else + render_403 end end # 邀请Trustie注册用户 def invite_members - @member ||= @project.members.new + if User.current.member_of?(@project) || User.current.admin? + @member ||= @project.members.new + respond_to do |format| + format.html + end + else + render_403 + end end def edit diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 48c08e2fc..d770a4633 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -19,6 +19,7 @@ class UsersController < ApplicationController layout :setting_layout #Added by young before_filter :auth_login1, :only => [:show, :user_activities, :user_newfeedback] + before_filter :logged_user_by_apptoken, :only => [:show,:user_newfeedback] menu_item :activity menu_item :user_information, :only => :info menu_item :user_course, :only => :user_courses @@ -445,12 +446,13 @@ class UsersController < ApplicationController activity = Activity.where(where_condition).where('user_id = ?', @user.id).order('id desc') end activity = activity.reject { |e| - !User.current.admin? && + e.act.nil? || + (!User.current.admin? && !e.act.nil? (((e.act_type == "Issue") && !e.act.project.visible?(User.current)) || (e.act_type == "Bid" && !e.act.courses.first.nil? && e.act.courses.first.is_public == 0 && !User.current.member_of_course?(e.act.courses.first)) || (e.act_type == "Journal" && e.act.respond_to?("Project") && !e.act.project.visible?(User.current)) || (e.act_type == "News" && ((!e.act.project.nil? && !e.act.project.visible?(User.current)) || (!e.act.course.nil? && e.act.course.is_public == 0 && !User.current.member_of_course?(e.act.course)))) || - (e.act_type == "Message" && !e.act.board.nil? && ((!e.act.board.project.nil? && !e.act.board.project.visible?(User.current)) || (!e.act.board.course.nil? && e.act.board.course.is_public == 0 && !User.current.member_of_course?(e.act.board.course))))) + (e.act_type == "Message" && !e.act.board.nil? && ((!e.act.board.project.nil? && !e.act.board.project.visible?(User.current)) || (!e.act.board.course.nil? && e.act.board.course.is_public == 0 && !User.current.member_of_course?(e.act.board.course)))))) } @activity_count = activity.count @activity_pages = Paginator.new @activity_count, pre_count, params['page'] diff --git a/app/controllers/welcome_controller.rb b/app/controllers/welcome_controller.rb index 290af0068..949ddd643 100644 --- a/app/controllers/welcome_controller.rb +++ b/app/controllers/welcome_controller.rb @@ -28,7 +28,8 @@ class WelcomeController < ApplicationController # 企业版定制: params[:project]为传过来的参数 unless params[:organization].nil? @organization = Organization.find params[:organization] - @organization_projects = Project.visible.joins(:project_status).joins("LEFT JOIN project_scores ON projects.id = project_scores.project_id").where("projects.organization_id = ?", @organization.id).order("score DESC").limit(10).all + # @organization_projects = Project.joins(:project_status).joins("LEFT JOIN project_scores ON projects.id = project_scores.project_id").where("projects.organization_id = ?", @organization.id).order("score DESC").limit(10).all + @organization_projects = @organization.projects.visible.joins("LEFT JOIN project_scores ON projects.id = project_scores.project_id").order("project_scores.score DESC").limit(10).all @part_projects = @organization_projects.count < 9 ? find_miracle_project( 9 - @organization_projects.count, 3,"score desc") : [] # @cur_projects = Project.find(params[:organization]) # @organization = @cur_projects.enterprise_name diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 30b2e7a21..9629ed437 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -490,6 +490,15 @@ module ApplicationHelper s.html_safe end + #项目成员列表复选框生成 + def project_member_check_box_tags_ex name, principals + s = '' + principals.each do |principal| + s << "
  • #{ check_box_tag name, principal.id, false, :id => nil } #{h link_to principal.userInfo, user_path( principal.id)}
  • \n" + end + s.html_safe + end + #扩展的checkbox生成 def principals_check_box_tags_ex(name, principals) s = '' @@ -1198,6 +1207,17 @@ module ApplicationHelper html_safe end + def wiki_simple_format_without_paragraph(text) + text.to_s. + gsub(/\r\n?/, "\n"). # \r\n and \r -> \n + gsub(/\n\n+/, "

    "). # 2+ newline -> 2 br + gsub(/([^\n]\n)(?=[^\n])/, '\1
    '). # 1 newline -> br + gsub("&nbsp", " "). #gsub(/<\/?.*?>/,""). + gsub(/<\/?.*?>/, ""). + gsub(""", "'"). + html_safe + end + def lang_options_for_select(blank=true) { 'Chinese简体中文 '=> 'zh', :English => :en} end diff --git a/app/helpers/courses_helper.rb b/app/helpers/courses_helper.rb index 22eb9bfae..db547061f 100644 --- a/app/helpers/courses_helper.rb +++ b/app/helpers/courses_helper.rb @@ -351,10 +351,28 @@ module CoursesHelper str end - # added by nwb + # added by meng + # 课程time+term简写(2014.春/2014.秋)国际化输出 def get_course_term course - str = ( course.try(:time).to_s << '.' << course.try(:term).to_s ) - str[0..-4] + strterm = course.try(:term).to_s + if !(User.current.language == 'zh') + strterm == '春季学期' ? strterm = 'spring term' : strterm = 'autumn term' + str = ( course.try(:time).to_s << '.' << strterm ) + str[0..-6] + else + str = ( course.try(:time).to_s << '.' << strterm ) + str[0..-4] + end + end + + # added by meng + # 课程term(春季学期/秋季学期)国际化输出 + def get_course_term_locales course + str = course.try(:term).to_s + if !(User.current.language == 'zh') + str == '春季学期' ? str = ' ' + 'spring term' : str = ' ' + 'autumn term' + end + return str end def members_to_user_ids members diff --git a/app/helpers/files_helper.rb b/app/helpers/files_helper.rb index aace20e6c..9eff409ff 100644 --- a/app/helpers/files_helper.rb +++ b/app/helpers/files_helper.rb @@ -48,7 +48,7 @@ module FilesHelper def courses_check_box_tags(name,courses,current_course,attachment) s = '' courses.each do |course| - if !(attachment.container_type && attachment.container_id == course.id) && is_course_teacher(User.current,course) && course_in_current_or_next_term(course) + if !course_contains_attachment?(course,attachment) && is_course_teacher(User.current,course) && course_in_current_or_next_term(course) s << " [#{get_course_term course}]
    " end end diff --git a/app/helpers/members_helper.rb b/app/helpers/members_helper.rb index 6c11199fb..ed18b7ae4 100644 --- a/app/helpers/members_helper.rb +++ b/app/helpers/members_helper.rb @@ -23,15 +23,22 @@ module MembersHelper principal_count = scope.count principal_pages = Redmine::Pagination::Paginator.new principal_count, 10, params['page'] #by young principals = scope.offset(principal_pages.offset).limit(principal_pages.per_page).all - s = content_tag('div', principals_check_box_tags_ex('membership[user_ids][]', principals), :id => 'principals') - links = pagination_links_full(principal_pages, principal_count, :per_page_links => false) {|text, parameters, options| link_to text, autocomplete_project_memberships_path(project, parameters.merge(:q => params[:q], :format => 'js')), :remote => true } - s + content_tag('div', content_tag('ul', links), :class => 'pagination_new') + end + #获取项目可邀请的成员列表 + def render_project_members project + scope = Principal.active.sorted.not_member_of(project).like(params[:q]) + principals = paginateHelper scope,10 + s = content_tag('ul', project_member_check_box_tags_ex('membership[user_ids][]', principals), :class => 'mb5', :style => "margin-left: -40px;") + links = pagination_links_full(@obj_pages, @obj_count, :per_page_links => false, :remote => false, :flag => true){|text, parameters, options| + link_to text, autocomplete_project_memberships_path(project, parameters.merge(:q => params[:q],:flag => true, :format => 'js')), :remote => true + } + s + content_tag('ul', links,:class => 'wlist') end # add by nwb @@ -71,4 +78,18 @@ module MembersHelper s + content_tag('div', content_tag('ul', links), :class => 'applied_new') end + private + def paginateHelper obj, pre_size=20 + @obj_count = obj.count + @obj_pages = Redmine::Pagination::Paginator.new @obj_count, pre_size, params['page'] + if obj.kind_of? ActiveRecord::Base or obj.kind_of? ActiveRecord::Relation + obj.limit(@obj_pages.per_page).offset(@obj_pages.offset) + elsif obj.kind_of? Array + obj[@obj_pages.offset, @obj_pages.per_page] + else + logger.error "[ApplicationController] Error : application_controller#paginateHelper ===> unknow category: #{obj.class}" + raise RuntimeError, 'unknow type, Please input you type into this helper.' + end + end + end diff --git a/app/helpers/watchers_helper.rb b/app/helpers/watchers_helper.rb index 971bf603d..b9e658bb5 100644 --- a/app/helpers/watchers_helper.rb +++ b/app/helpers/watchers_helper.rb @@ -283,6 +283,6 @@ module WatchersHelper def exit_project_link(project) link_to(l(:label_exit_project),exit_cur_project_path(project.id), - :remote => true, :confirm => l(:lable_sure_exit_project), :style => "color: #fff; display:block; padding: 0px 5px;margin-right:10px;height:22px;background:none repeat scroll 0% 0% #64BDD9;TES" ) + :remote => true, :confirm => l(:lable_sure_exit_project), :style => "color: #fff; display:block; padding: 0px 5px; margin-right: 10px; height: 22px; line-height: 22px; background: none repeat scroll 0% 0% #64BDD9; TES" ) end end diff --git a/app/helpers/welcome_helper.rb b/app/helpers/welcome_helper.rb index eba3c0b3c..f6e205e82 100644 --- a/app/helpers/welcome_helper.rb +++ b/app/helpers/welcome_helper.rb @@ -341,7 +341,7 @@ module WelcomeHelper end str rescue Exception => e - str << content_tag("span", l(:field_user_active_unknow)) + str << content_tag("span", l('user.active.unknow')) end def show_event_reply event diff --git a/app/models/phone_app_version.rb b/app/models/phone_app_version.rb index abf4c54e3..92a32c0d3 100644 --- a/app/models/phone_app_version.rb +++ b/app/models/phone_app_version.rb @@ -1,3 +1,6 @@ class PhoneAppVersion < ActiveRecord::Base attr_accessible :description, :version + validates_presence_of :description, :version + validates_uniqueness_of :version + acts_as_attachable end diff --git a/app/models/project.rb b/app/models/project.rb index ec193cdfe..07854822e 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -131,7 +131,7 @@ class Project < ActiveRecord::Base #ActiveModel::Dirty 这里有一个changed方法。对任何对象都可以用 after_save :update_inherited_members, :if => Proc.new {|project| project.inherit_members_changed?} # 创建project之后默认创建一个board,之后的board去掉了board的概念 - after_create :create_board_sync + after_create :create_board_sync,:acts_as_forge_activities before_destroy :delete_all_members def remove_references_before_destroy return if self.id.nil? @@ -1154,6 +1154,13 @@ class Project < ActiveRecord::Base end end - + # Time 2015-03-10 15:33:16 + # Author lizanle + # Description 新建项目要在ForgeActivities中加一条数据。 + def acts_as_forge_activities + fa = ForgeActivity.new(:user_id => User.current.id,:project_id => self.id, + :forge_act_id => self.id,:forge_act_type => "ProjectCreateInfo") + fa.save! + end end diff --git a/app/models/user_extensions.rb b/app/models/user_extensions.rb index b21f0ad36..92690d1db 100644 --- a/app/models/user_extensions.rb +++ b/app/models/user_extensions.rb @@ -33,16 +33,32 @@ class UserExtensions < ActiveRecord::Base return self.brief_introduction end -# added by bai +# added by meng def show_identity if self.identity == 0 - user_identity = '教师' + if User.current.language == 'zh' + user_identity = '教师' + else + user_identity = 'Teacher' + end elsif self.identity == 1 - user_identity = '学生' + if User.current.language == 'zh' + user_identity = '学生' + else + user_identity = 'Student' + end elsif self.identity == 2 - user_identity = '企业' + if User.current.language == 'zh' + user_identity = '企业' + else + user_identity = 'Enterprise' + end elsif self.identity == 3 - user_identity = '开发者' + if User.current.language == 'zh' + user_identity = '开发者' + else + user_identity = 'Developer' + end else user_identity = '' end diff --git a/app/services/courses_service.rb b/app/services/courses_service.rb index 46b59ef08..c9ea1ca80 100644 --- a/app/services/courses_service.rb +++ b/app/services/courses_service.rb @@ -344,27 +344,67 @@ class CoursesService else membership = @user.coursememberships.all(:conditions => Course.visible_condition(current_user)) end + if membership.nil? || membership.count == 0 + raise l(:label_no_courses,:locale => current_user.language.nil? ? 'zh':current_user.language) + end membership.sort! {|older, newer| newer.created_on <=> older.created_on } result = [] membership.each do |mp| course = mp.course - unless current_user.nil? || !(current_user.admin? || course.is_public == 1 || (course.is_public == 0 && current_user.member_of_course?(course))) - count,is_teacher = get_course_anonymous_evaluation current_user,course - if is_teacher - student_commit_number = count - else - need_anonymous_comments_count = count + latest_course_dynamics = [] + latest_news = course.news.order("created_on desc").first + unless latest_news.nil? + latest_course_dynamics << {:type => 1,:time => latest_news.created_on,:message => l(:label_recently_updated_notification,:locale => current_user.language.nil? ? 'zh':current_user.language)} + end + latest_message = course.journals_for_messages.order("created_on desc").first + unless latest_message.nil? + latest_course_dynamics << {:type => 2,:time => latest_message.created_on,:message => l(:label_recently_updated_message,:locale => current_user.language.nil? ? 'zh':current_user.language)} + end + latest_attachment = course.attachments.order("created_on desc").first + unless latest_attachment.nil? + latest_course_dynamics << {:type => 3,:time => latest_attachment.created_on,:message => l(:label_recently_updated_courseware,:locale => current_user.language.nil? ? 'zh':current_user.language)} + end + latest_bid = course.homeworks.order('updated_on DESC').first + unless latest_bid.nil? + latest_course_dynamics << {:type => 4,:time => latest_bid.updated_on,:message => l(:label_recently_updated_homework,:locale => current_user.language.nil? ? 'zh':current_user.language)} + end + #每个作业中的最新留言 + messages = [] + course.homeworks.each do |bid| + jour = bid.journals_for_messages.order("created_on desc").first + unless jour.nil? + messages << jour end - news_count = course.news.count - message_count = course.journals_for_messages.count - - result << {:course_name => course.name,:course_id => course.id,:course_img_url => url_to_avatar(course),:type => 1,:count => message_count} - result << {:course_name => course.name,:course_id => course.id,:course_img_url => url_to_avatar(course),:type => 2,:count => need_anonymous_comments_count} - result << {:course_name => course.name,:course_id => course.id,:course_img_url => url_to_avatar(course),:type => 3,:count => student_commit_number} - result << {:course_name => course.name,:course_id => course.id,:course_img_url => url_to_avatar(course),:type => 4,:count => news_count} - #{:course_name => course.name,:need_anonymous_comments_count=>need_anonymous_comments_count,:student_commit_number=>student_commit_number,:news_count=> news_count,:message_count=>message_count} + end + unless messages.count == 0 + messages.sort!{|order,newer| newer.created_on <=> order.created_on} + end + latest_bid_message = messages.first + unless latest_bid_message.nil? + latest_course_dynamics << {:type => 4,:time => latest_bid_message.created_on,:message => '最近更新了作业'}#l(:label_recently_updated_message,:locale => current_user.language.nil? ? 'zh':current_user.language)} + end + #每个作业中学生最后提交的作业 + homeworks = [] + course.homeworks.each do |bid| + homework_attach = bid.homeworks.order('updated_at DESC').first + unless homework_attach.nil? + homeworks << homework_attach + end + end + unless homeworks.count == 0 + homeworks.sort!{|order,newer| newer.updated_at <=> order.updated_at} + end + latest_homework_attach = homeworks.first + unless latest_homework_attach.nil? + latest_course_dynamics << {:type => 4,:time => latest_homework_attach.updated_at,:message => '最近更新了作业'}#l(:label_recently_updated_homework,:locale => current_user.language.nil? ? 'zh':current_user.language)} + end + latest_course_dynamics.sort!{|order,newer| newer[:time] <=> order[:time]} + latest_course_dynamic = latest_course_dynamics.first + unless latest_course_dynamic.nil? + result << {:course_name => course.name,:course_id => course.id,:course_img_url => url_to_avatar(course),:type => latest_course_dynamic[:type],:update_time => latest_course_dynamic[:time],:message => latest_course_dynamic[:message],:count => nil} end end + result.sort!{|order,newer| newer[:update_time] <=> order[:update_time]} result end diff --git a/app/services/users_service.rb b/app/services/users_service.rb index 8cadf031c..f75a84c5b 100644 --- a/app/services/users_service.rb +++ b/app/services/users_service.rb @@ -80,6 +80,28 @@ class UsersService {:id => @user.id, :img_url => img_url, :nickname => @user.login, :gender => gender, :work_unit => work_unit, :mail => @user.mail, :location => location, :brief_introduction => @user.user_extensions.brief_introduction} end + #忘记密码 + def lost_password params + user = ::User.find_by_mail(params[:mail].to_s) + # user not found or not active + unless user && user.active? + raise l(:notice_account_unknown_email,:locale => 'zh') + end + # user cannot change its password + unless user.change_password_allowed? + raise l(:notice_can_t_change_password,:locale => user.language) + return + end + # create a new token for password recovery + token = Token.new(:user => user, :action => "recovery") + if token.save + Thread.new do + Mailer.lost_password(token).deliver + end + return l(:notice_account_lost_email_sent,:locale => user.language) + end + end + #编辑用户 #gender 1:female 0:male 其他:male def edit_user params diff --git a/app/views/admin/mobile_version.html.erb b/app/views/admin/mobile_version.html.erb index 293b0ec46..2a03ac003 100644 --- a/app/views/admin/mobile_version.html.erb +++ b/app/views/admin/mobile_version.html.erb @@ -1,9 +1,20 @@

    <%= l(:label_mobile_version) %>

    发布新版本
    - + <%= form_tag({:controller => 'admin', :action => 'create_version'},{:id => 'new_version',:style=>'display:none'}) do %> +

    + + <%= text_field_tag 'version', params[:version],:value => @new_version.version, :size => 30,:style => "font-size:small;width:490px;margin-left:10px;" %> +

    +

    + + <%= text_field_tag 'description', params[:description],:value => @new_version.description,:size => 30,:style => "font-size:small;width:490px;margin-left:10px;" %> +

    +

    + <%= render :partial => 'attachments/form', :locals => {:container => @new_version} %> +

    + <%= submit_tag l(:button_save), :class => "small", :name => nil %> + <% end %>

    当前版本:
    @@ -25,7 +36,10 @@ <% end %> - +<% if !@versions.first.nil? && @versions.first.attachments.any?%> + <% options = {:author => true, :deletable => true } %> + <%= render :partial => 'attachments/links', :locals => {:attachments => @versions.first.attachments, :options => options, :is_float => true} %> +<% end %>
    历史版本:
    diff --git a/app/views/bids/_bid_homework_show.html.erb b/app/views/bids/_bid_homework_show.html.erb index 1009f405f..6b3f91587 100644 --- a/app/views/bids/_bid_homework_show.html.erb +++ b/app/views/bids/_bid_homework_show.html.erb @@ -172,9 +172,9 @@ - <%= l(:label_create_time) %> + <%= l(:label_end_time) %> :  - <%=format_time bid.created_on %> + <%= bid.deadline %> <% if betweentime(bid.deadline) < 0 %> diff --git a/app/views/boards/_project_show.html.erb b/app/views/boards/_project_show.html.erb index 9a3b79051..1d9408e86 100644 --- a/app/views/boards/_project_show.html.erb +++ b/app/views/boards/_project_show.html.erb @@ -7,7 +7,7 @@ } } -