diff --git a/Gemfile b/Gemfile index 3784e60d8..9dae2827c 100644 --- a/Gemfile +++ b/Gemfile @@ -14,7 +14,7 @@ gem "i18n", "~> 0.6.0" gem "coderay", "~> 1.0.6" gem "fastercsv", "~> 1.5.0", :platforms => [:mri_18, :mingw_18, :jruby] gem "builder", "3.0.0" -gem 'acts-as-taggable-on' +gem 'acts-as-taggable-on', '2.4.1' group :development do gem 'better_errors', path: 'lib/better_errors' diff --git a/Gemfile.lock b/Gemfile.lock index 6680070a7..e6ee7da71 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -134,7 +134,7 @@ PLATFORMS DEPENDENCIES activerecord-jdbc-adapter (= 1.2.5) activerecord-jdbcmysql-adapter - acts-as-taggable-on + acts-as-taggable-on (= 2.4.1) better_errors! builder (= 3.0.0) coderay (~> 1.0.6) diff --git a/ReadMe.txt b/ReadMe.txt index 9d223259a..0fcba47c0 100644 --- a/ReadMe.txt +++ b/ReadMe.txt @@ -44,4 +44,10 @@ app\controller\welcome_controller.rb return 0 end end -================================================================================ \ No newline at end of file +================================================================================ + +================================================================================ +0606:新坑 +user_scores表结构有问题,需要运行 +bundle exec rake db:migrate:down VERSION=20140410021724 +bundle exec rake db:migrate:up VERSION=20140410021724 \ No newline at end of file diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index a25b346ca..4b877818b 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -264,6 +264,14 @@ class ApplicationController < ActionController::Base render_404 end + #根据course_id找project + def find_project_by_course_id + @bid = Bid.find params[:course_id] + @project = @bid.courses[0] + rescue ActiveRecord::RecordNotFound + render_404 + end + # Find a project based on params[:project_id] # TODO: some subclasses override this, see about merging their logic def find_optional_project diff --git a/app/controllers/bids_controller.rb b/app/controllers/bids_controller.rb index db2ea9249..93bb1d9e9 100644 --- a/app/controllers/bids_controller.rb +++ b/app/controllers/bids_controller.rb @@ -25,7 +25,14 @@ class BidsController < ApplicationController helper :projects helper :words helper :welcome - + + def find_project_by_bid_id + @bid = Bid.find(params[:id]) + @project = @bid.courses[0] + rescue ActiveRecord::RecordNotFound + render_404 + end + def homework_ajax_modal @bid = Bid.find_by_id(params[:id]) # find_bid @@ -410,9 +417,7 @@ class BidsController < ApplicationController @homework = HomeworkAttach.new #@homework_list = @bid.homeworks #增加作业按评分排序, - @homework_list = HomeworkAttach.find_by_sql("SELECT homework_attaches.*, - (SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id) AS score - FROM homework_attaches WHERE bid_id = #{@bid.id} ORDER BY score DESC,created_at ASC",:include => [:attachments]) + @homework_list = @bid.homeworks.eager_load(:rate_averages, :user, :attachments).order('seems_rateable_cached_ratings.avg DESC') if params[:student_id].present? @temp = [] @homework_list.each do |pro| @@ -528,6 +533,7 @@ class BidsController < ApplicationController message = params[:bid_message][:message] + "\n" + params[:reference_content] else message = params[:bid_message][:message] + @m = message end refer_user_id = params[:bid_message][:reference_user_id].to_i @bid.add_jour(User.current, message, refer_user_id) diff --git a/app/controllers/contests_controller.rb b/app/controllers/contests_controller.rb index b51a11436..c89fef5a6 100644 --- a/app/controllers/contests_controller.rb +++ b/app/controllers/contests_controller.rb @@ -210,11 +210,14 @@ class ContestsController < ApplicationController # @contesting_project_pages = Paginator.new @contesting_project_count, per_page_option, params['page'] @membership.each do |membership| unless(membership.project.project_type==1) - membership.member_roles.each{|role| - if(role.role_id == 3) - @option << membership.project - end - } + #membership.member_roles.each{|role| + # if(role.role_id == 3) + # @option << membership.project + # end + #} + if User.current.allowed_to?({:controller => "projects", :action => "edit"}, membership.project, :global => false) + @option << membership.project + end end end @user = @contest.author @@ -301,11 +304,15 @@ class ContestsController < ApplicationController # @contesting_project_pages = Paginator.new @contesting_project_count, per_page_option, params['page'] @membership.each do |membership| unless(membership.project.project_type==1) - membership.member_roles.each{|role| - if(role.role_id == 3) + #membership.member_roles.each{|role| + #if(role.role_id == 3) + #@option << membership.project + #end + #} + #拥有编辑项目权限的可将该项目参赛 + if User.current.allowed_to?({:controller => "projects", :action => "edit"}, membership.project, :global => false) @option << membership.project - end - } + end end end @user = @contest.author diff --git a/app/controllers/homework_attach_controller.rb b/app/controllers/homework_attach_controller.rb index 074a6d91f..c4c1f8922 100644 --- a/app/controllers/homework_attach_controller.rb +++ b/app/controllers/homework_attach_controller.rb @@ -1,5 +1,23 @@ class HomeworkAttachController < ApplicationController ############################### + #判断当前角色权限时需先找到当前操作的project + before_filter :find_project_by_bid_id, :only => [:new] + before_filter :find_project_by_hoemwork_id, :only => [:edit,:update,:destroy] + #判断当前角色是否有操作权限 + #勿删 before_filter :authorize, :only => [:new,:edit,:update,:destroy] + + def find_project_by_bid_id + @bid = Bid.find(params[:id]) + @project = @bid.courses[0] + rescue ActiveRecord::RecordNotFound + render_404 + end + + def find_project_by_hoemwork_id + @homework = HomeworkAttach.find(params[:id]) + @project = @homework.bid.courses[0] + end + def index @homeworks = HomeworkAttach.all respond_to do |format| diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index 16d9d71d4..ad3dc3dca 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -37,6 +37,7 @@ class ProjectsController < ApplicationController # before_filter :authorize, :except => [:new_join, :new_homework, :homework, :statistics, :search, :watcherlist, :index, :list, :new, :create, :copy, :archive, :unarchive, :destroy, :member, :focus, :file, # :statistics, :feedback, :course, :enterprise_course, :course_enterprise, :project_respond, :share, # :show_projects_score, :issue_score_index, :news_score_index, :file_score_index, :code_submit_score_index, :projects_topic_score_index] + #此条勿删 课程相关权限 ,:new_homework,:homework,:feedback,,:member before_filter :authorize, :only => [:show, :settings, :edit, :sort_project_members, :update, :modules, :close, :reopen,:view_homework_attaches,:course] before_filter :authorize_global, :only => [:new, :create,:view_homework_attaches] before_filter :require_admin, :only => [ :copy, :archive, :unarchive, :destroy, :calendar] @@ -721,6 +722,9 @@ class ProjectsController < ApplicationController @teachers= searchTeacherAndAssistant(@project) @canShowRealName = isCourseTeacher(User.current.id) end + + #勿删 real_name action为虚拟的该方法并不存在,用来辅助判断真名权限 + #勿删 @canShowRealName = User.current.allowed_to?({:controller => "projects", :action => "real_name"}, @project || @projects, :global => false) respond_to do |format| format.html{render :layout => 'base_courses' if @base_courses_tag==1} format.api diff --git a/app/controllers/softapplications_controller.rb b/app/controllers/softapplications_controller.rb index b8d81b108..362a04f57 100644 --- a/app/controllers/softapplications_controller.rb +++ b/app/controllers/softapplications_controller.rb @@ -108,11 +108,16 @@ class SoftapplicationsController < ApplicationController # @contesting_project_pages = Paginator.new @contesting_project_count, per_page_option, params['page'] @membership.each do |membership| unless(membership.project.project_type==1) - membership.member_roles.each{|role| - if(role.role_id == 3) + #membership.member_roles.each{|role| + # if(role.role_id == 3) + # @option << membership.project + # end + #} + + #拥有编辑项目权限的可操作该项目 + if User.current.allowed_to?({:controller => "projects", :action => "edit"}, membership.project, :global => false) @option << membership.project - end - } + end end end diff --git a/app/controllers/zipdown_controller.rb b/app/controllers/zipdown_controller.rb index b3d093f7a..b1a245dd1 100644 --- a/app/controllers/zipdown_controller.rb +++ b/app/controllers/zipdown_controller.rb @@ -1,7 +1,21 @@ class ZipdownController < ApplicationController + #查找项目(课程) + before_filter :find_project_by_bid_id, :only => [:assort,:download_user_homework] + #检查权限 + #勿删 before_filter :authorize, :only => [:assort,:download_user_homework] SAVE_FOLDER = "#{Rails.root}/files" OUTPUT_FOLDER = "#{Rails.root}/tmp/archiveZip" + #通过作业Id找到项目(课程) + def find_project_by_bid_id + obj_class = params[:obj_class] + obj_id = params[:obj_id] + obj = obj_class.constantize.find(obj_id) + case obj.class.to_s.to_sym + when :Bid + @project = obj.courses[0] + end + end def assort obj_class = params[:obj_class] obj_id = params[:obj_id] diff --git a/app/helpers/bids_helper.rb b/app/helpers/bids_helper.rb index 8b03d74cd..a41867c64 100644 --- a/app/helpers/bids_helper.rb +++ b/app/helpers/bids_helper.rb @@ -157,13 +157,24 @@ module BidsHelper end #当前用户是不是指定课程的学生 def is_cur_course_student? course - people = [] - course.members.each do |member| - if [5,10].include? member.roles.first.id - people << member.user + #people = [] + #course.members.includes(:user, :roles).each do |member| + # if [5,10].include? member.roles.first.id + # people << member.user + # end + #end + #people.include?(User.current) + #修改:能新建占位且不能新建任务的角色判定为学生 + is_student = false + @membership = User.current.memberships.all(:conditions => Project.visible_condition(User.current)) + @membership.each do |membership| + unless(membership.project.project_type==0) + if !User.current.allowed_to?({:controller => "projects", :action => "new_homework"}, membership.project, :global => false) && User.current.allowed_to?({:controller => "homework_attach", :action => "new"}, membership.project, :global => false) + is_student = true + end end end - people.include?(User.current) + is_student end # def select_option_helper option diff --git a/app/helpers/courses_helper.rb b/app/helpers/courses_helper.rb index cc207e845..924e19447 100644 --- a/app/helpers/courses_helper.rb +++ b/app/helpers/courses_helper.rb @@ -137,12 +137,47 @@ module CoursesHelper Course.find_by_extra(try(extra)) end #判断制定用户是不是当前课程的老师 - def is_course_teacher user,course - searchPeopleByRoles(course, TeacherRoles).include?(user) + def is_course_teacher (user,course) + #people = [] + #course.members.includes(:roles, :user).each do |member| + # role_id = member.roles.first.id + # if TeacherRoles.include? role_id + # people << member.user + # end + #end + #people.include?(user) + #修改为根据用户是否有发布任务的权限来判断用户是否是课程的老师 + is_teacher = false + @membership = user.memberships.all(:conditions => Project.visible_condition(User.current)) + @membership.each do |membership| + unless(membership.project.project_type==0) + if user.allowed_to?({:controller => "projects", :action => "new_homework"}, membership.project, :global => false) + is_teacher = true + end + end + end + is_teacher end #当前用户是不是指定课程的学生 def is_cur_course_student? course - searchPeopleByRoles(course, StudentRoles).include?(User.current) + #people = [] + #course.members.includes(:roles, :user).each do |member| + # if StudentRoles.include? member.roles.first.id + # people << member.user + # end + #end + #people.include?(User.current) + #修改:能新建占位且不能新建任务的角色判定为学生 + is_student = false + @membership = User.current.memberships.all(:conditions => Project.visible_condition(User.current)) + @membership.each do |membership| + unless(membership.project.project_type==0) + if !User.current.allowed_to?({:controller => "projects", :action => "new_homework"}, membership.project, :global => false) && User.current.allowed_to?({:controller => "homework_attach", :action => "new"}, membership.project, :global => false) + is_student = true + end + end + end + is_student end #获取当前用户在指定作业下提交的作业的集合 def cur_user_homework_for_bid bid diff --git a/app/helpers/shares_helper.rb b/app/helpers/shares_helper.rb index f2cbc6ab9..9e0828133 100644 --- a/app/helpers/shares_helper.rb +++ b/app/helpers/shares_helper.rb @@ -4,11 +4,15 @@ def options_from_select_project(user) @option = [] @membership.each do |membership| unless(membership.project.project_type==1) - membership.member_roles.each{|role| - if(role.role_id == 3) + #membership.member_roles.each{|role| + # if(role.role_id == 3) + # @option << membership.project + # end + #} + #拥有编辑项目权限的可操作该项目 + if user.allowed_to?({:controller => "projects", :action => "edit"}, membership.project, :global => false) @option << membership.project - end - } + end end end options_for_select(@option) diff --git a/app/helpers/user_score_helper.rb b/app/helpers/user_score_helper.rb index d9ab8730a..3101b823c 100644 --- a/app/helpers/user_score_helper.rb +++ b/app/helpers/user_score_helper.rb @@ -228,12 +228,21 @@ module UserScoreHelper isManager = 0 members = Member.where('user_id = ?', user.id) members.each do |m| - roles = m.member_roles - roles.each do |r| - if r.role_id == 3 + #roles = m.member_roles + #roles.each do |r| + # if r.role_id == 3 + # isManager = 1 + # end + #end + @membership = m.memberships.all(:conditions => Project.visible_condition(User.current)) + @membership.each do |membership| + #拥有编辑项目权限的可操作该项目 + if m.allowed_to?({:controller => "projects", :action => "edit"}, membership.project, :global => false) isManager = 1 end end + + end level = 0 diff --git a/app/models/attachment.rb b/app/models/attachment.rb index aff63439e..b2a7cfb08 100644 --- a/app/models/attachment.rb +++ b/app/models/attachment.rb @@ -56,6 +56,7 @@ class Attachment < ActiveRecord::Base @@thumbnails_storage_path = File.join(Rails.root, "tmp", "thumbnails") before_save :files_to_final_location + before_save :be_user_score # user_score after_destroy :delete_from_disk # Returns an unsaved copy of the attachment @@ -361,4 +362,17 @@ class Attachment < ActiveRecord::Base end "#{timestamp}_#{ascii}" end + + + # update user score + def be_user_score + if self.container_id_changed? + type = self.container_type + types = %w|Document News Version Project Issue Message WikiPage| + if types.include?(type) + UserScore.project(:push_file, User.current, { attachment_id: self.id }) + end + end + end + end diff --git a/app/models/changeset.rb b/app/models/changeset.rb index e3e7ac705..93248850b 100644 --- a/app/models/changeset.rb +++ b/app/models/changeset.rb @@ -18,6 +18,9 @@ class Changeset < ActiveRecord::Base belongs_to :repository belongs_to :user + + after_save :be_user_score # user_score + has_many :filechanges, :class_name => 'Change', :dependent => :delete_all # fq has_many :acts, :class_name => 'Activity', :as => :act, :dependent => :destroy @@ -292,4 +295,14 @@ class Changeset < ActiveRecord::Base def self.to_utf8(str, encoding) Redmine::CodesetUtil.to_utf8(str, encoding) end + + private + + # update user score + def be_user_score + if self.new_record? + UserScore.project(:push_code, self.user, { changeset_id: self.id }) + end + end + end diff --git a/app/models/document.rb b/app/models/document.rb index 0c2ce1736..5e3df4bf7 100644 --- a/app/models/document.rb +++ b/app/models/document.rb @@ -19,6 +19,10 @@ class Document < ActiveRecord::Base include Redmine::SafeAttributes belongs_to :project belongs_to :category, :class_name => "DocumentCategory", :foreign_key => "category_id" + + before_save :be_user_score # user_score + + acts_as_attachable :delete_permission => :delete_documents acts_as_searchable :columns => ['title', "#{table_name}.description"], :include => :project @@ -54,4 +58,11 @@ class Document < ActiveRecord::Base end @updated_on end + + # update user score + def be_user_score + if self.new_record? + UserScore.project(:push_document, User.current, { document_id: self.id }) + end + end end diff --git a/app/models/issue.rb b/app/models/issue.rb index 7e899eafc..5c1fb8173 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -77,6 +77,8 @@ class Issue < ActiveRecord::Base # fq after_create :act_as_activity + before_save :be_user_score + # after_create :be_user_score # end delegate :notes, :notes=, :private_notes, :private_notes=, :to => :current_journal, :allow_nil => true @@ -1484,4 +1486,14 @@ class Issue < ActiveRecord::Base and #{visible_condition(User.current, :project => project)} group by s.id, s.is_closed, j.id") end + + # update user score + def be_user_score + if self.new_record? + UserScore.project(:post_issue, User.current, { issue_id: self.id }) + elsif self.done_ratio_changed? + UserScore.project(:update_issue_ratio, User.current, { issue_id: self.id }) + end + end + end diff --git a/app/models/mailer.rb b/app/models/mailer.rb index bb7a2424f..e954f03c8 100644 --- a/app/models/mailer.rb +++ b/app/models/mailer.rb @@ -51,7 +51,7 @@ class Mailer < ActionMailer::Base when :User user_newfeedback_user_url(journals_for_message.jour, anchor: "word_li_#{journals_for_message.id}") else - logger.error "[Builds a Mail::Message ERROR] journalsForMessage's jour is unkown type, journalsForMessage.id = #{journals_for_message.id}" + Rails.logger.error "[Builds a Mail::Message ERROR] journalsForMessage's jour is unkown type, journalsForMessage.id = #{journals_for_message.id}" return -1 end #如果是直接留言并且留言对象是Project并且Project类型是课程 @@ -70,7 +70,12 @@ class Mailer < ActionMailer::Base end mail :to => @recipients, :subject => "#{l(:label_your_course)}#{journals_for_message.jour.name}#{l(:label_have_message)} " - else + elsif journals_for_message.jour.class.to_s.to_sym == :Bid + if !journals_for_message.jour.author.notify_about? journals_for_message + return -1 + end + mail :to => journals_for_message.jour.author.mail, :subject => @title + else mail :to => @mail.mail, :subject => @title end diff --git a/app/models/message.rb b/app/models/message.rb index 2421a7d4f..c266d9a8c 100644 --- a/app/models/message.rb +++ b/app/models/message.rb @@ -54,6 +54,7 @@ class Message < ActiveRecord::Base # fq after_create :act_as_activity + before_save :be_user_score # end scope :visible, lambda {|*args| @@ -121,4 +122,11 @@ class Message < ActiveRecord::Base self.acts << Activity.new(:user_id => self.author_id) end # end + + # update user score + def be_user_score + if self.new_record? + UserScore.joint(:post_message, User.current,nil, { message_id: self.id }) + end + end end diff --git a/app/models/user.rb b/app/models/user.rb index d79cf11e1..331ff6993 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -137,7 +137,7 @@ class User < Principal has_one :user_extensions,:dependent => :destroy ## end - #default_scope -> { includes(:user_extensions, :user_score) } + # default_scope -> { includes(:user_extensions, :user_score) } scope :teacher, -> { joins(:user_extensions).where('user_extensions.identity = ?', UserExtensions::TEACHER) } @@ -201,6 +201,7 @@ class User < Principal # ====================================================================== # 集中处理 User 扩展表为空的问题 + # 合并 user_score 属性 validate :valid_user_extensions after_save :save_user_extensions @@ -208,21 +209,32 @@ class User < Principal self.user_extensions ||= UserExtensions.new end + def user_score_attr + self.user_score ||= UserScore.new + end + + alias_method :ori_respond_to?, :respond_to? def respond_to?(m, include_private = false) - flag = UserExtensions.instance_methods.include? m.to_sym - if flag - flag - else - super - end + flag = false + flag = ori_respond_to? m.to_sym unless flag + flag = UserExtensions.new.respond_to? m.to_sym unless flag + flag = UserScore.new.respond_to? m.to_sym unless flag + + flag end def method_missing m, *args, &block if extensions.respond_to? m.to_sym - self.class.send :define_method, m.to_sym, *args do + self.class.send(:define_method, "_meta_#{m}".to_sym) do |*args, &block| self.extensions.__send__ m.to_sym, *args end - __send__ m.to_sym, *args, &block + __send__ "_meta_#{m}".to_sym, *args, &block + + elsif user_score_attr.respond_to? m.to_sym + self.class.send(:define_method, "_meta_#{m}".to_sym) do |*args, &block| + self.user_score_attr.__send__ m.to_sym, *args + end + __send__ "_meta_#{m}".to_sym, *args, &block else super @@ -241,6 +253,7 @@ class User < Principal def save_user_extensions self.extensions.save + self.user_score_attr.save end # 集中处理 User 扩展表为空的问题 < end # ====================================================================== diff --git a/app/models/user_score.rb b/app/models/user_score.rb index f383d6670..3857eaec4 100644 --- a/app/models/user_score.rb +++ b/app/models/user_score.rb @@ -33,4 +33,154 @@ class UserScore < ActiveRecord::Base def self.find_min_issue self.minimum(:file) end + # 以上类方法目测没用,反正也报错 + # =============================================================================== + + # 前略·协同得分 + # operate - 更新操作 类型 symbol + # user - 计分用户 + # + # Examples + # + # UserScore.joint(:post_message, User.current, nil) + # # => true #当前用户发帖计分操作成功 + # + # Returns boolean. 返回积分保存结果 + def self.joint(operate, current_user, target_user, options={}) + current_user, target_user = get_users(current_user, target_user) + user_score = current_user.user_score_attr + case operate + when :post_message # current_user 发帖了 + user_score.collaboration = user_score.collaboration.to_i + 2 + user_score.save + Rails.logger.info "[UserScore#joint] ===> User: #{current_user} posting a message. options => (#{options.to_s})" + when :post_issue # current_user 对 target_user 的缺陷留言了 + user_score.collaboration = user_score.collaboration.to_i + 1 + user_score.save + Rails.logger.info "[UserScore#joint] ===> User: #{current_user} posting a issue. options => (#{options.to_s})" + when :change_issue_status # current_user 更改了缺陷的状态 + user_score.collaboration = user_score.collaboration.to_i + 1 + user_score.save + Rails.logger.info "[UserScore#joint] ===> User: #{current_user} change issue status. options => (#{options.to_s})" + when :reply_message # current_user 对 target_user 留言的回复 + user_score.collaboration = user_score.collaboration.to_i + 1 + user_score.save + Rails.logger.info "[UserScore#joint] ===> User: #{current_user} reply message. options => (#{options.to_s})" + when :reply_posting # current_user 对 target_user 帖子的回复 + user_score.collaboration = user_score.collaboration.to_i + 1 + user_score.save + Rails.logger.info "[UserScore#joint] ===> User: #{current_user} reply posting. options => (#{options.to_s})" + else + Rails.logger.error "[UserScore#joint] ===> #{operate} is not define." + return false + end + rescue => e + Rails.logger.error "[UserScore#joint] ===> Exception: #{e}." + end + + # 前略·影响力得分 + # operate - 更新操作 类型 symbol + # user - 计分用户 + # + # Examples + # + # UserScore.influence(:followed_by, user) + # # => true #当前被关注用户记分成功 + # + # Returns boolean. 返回积分保存结果 + def self.influence(operate, current_user, target_user, options={}) + current_user, target_user = get_users(current_user, target_user) + user_score = current_user.user_score_attr + case operate + when :followed_by # current_user 关注了target_user + user_score.active = user_score.influence.to_i + 2 + user_score.save + Rails.logger.info "[UserScore#influence] ===> User: #{current_user} be followed. options => (#{options.to_s})" + else + Rails.logger.error "[UserScore#influence] ===> #{operate} is not define." + return false + end + rescue => e + Rails.logger.error "[UserScore#influence] ===> Exception: #{e}." + end + + # 前略·技术得分 + # operate - 更新操作 类型 symbol + # user - 计分用户 + # + # Examples + # + # UserScore.skill(:followed_by, current_user, target_user) + # # => true #当前current_user对target_user用户帖子的记分成功 + # + # Returns boolean. 返回积分保存结果 + def self.skill(operate, current_user, target_user, options={}) + current_user, target_user = get_users(current_user, target_user) + user_score = current_user.user_score_attr + case operate + # when :treading # current_user 踩了 target_user 的帖子 + # Rails.logger.info "[UserScore#skill] ===> User: #{current_user} treading #{target_user}'s posting. options => (#{options.to_s})" + when :treaded_by_user # current_user 踩了 target_user 的帖子 + Rails.logger.info "[UserScore#skill] ===> User: #{current_user} treaded_by #{target_user}. options => (#{options.to_s})" + when :praised_by_user # current_user 顶了 target_user 的帖子 + Rails.logger.info "[UserScore#skill] ===> User: #{current_user} praised_by #{target_user}. options => (#{options.to_s})" + else + Rails.logger.error "[UserScore#skill] ===> #{operate} is not define." + return false + end + rescue => e + Rails.logger.error "[UserScore#skill] ===> Exception: #{e}." + end + + # 前略·项目得分 + # operate - 更新操作 类型 symbol + # user - 计分用户 + # + # Examples + # + # UserScore.project(:pull_code, current_user) + # # => true #当前current_user对项目贡献积分成功 + # + # Returns boolean. 返回积分保存结果 + def self.project(operate, current_user, options={}) + current_user, target_user = get_users(current_user, nil) + user_score = current_user.try(:user_score_attr) + return false if current_user.nil? + case operate + when :push_code # current_user 提交了代码 + user_score = user_score.active.to_i + 4 + user_score.save + Rails.logger.debug "[UserScore#project] ===> User: [#{current_user.id},#{current_user.name}] pushed code one time. options => (#{options.to_s})" + when :push_document # current_user + user_score.active = user_score.active.to_i + 4 + user_score.save + Rails.logger.debug "[UserScore#project] ===> User: [#{current_user.id},#{current_user.name}] pushed a document. options => (#{options.to_s})" + when :push_file # current_user + user_score.active = user_score.active.to_i + 4 + user_score.save + Rails.logger.debug "[UserScore#project] ===> User: [#{current_user.id},#{current_user.name}] pushed a file. options => (#{options.to_s})" + when :update_issue_ratio # current_user + user_score.active = user_score.active.to_i + 2 + user_score.save + Rails.logger.debug "[UserScore#project] ===> User: [#{current_user.id},#{current_user.name}] updated issue ratio. options => (#{options.to_s})" + when :post_issue # current_user + user_score.active = user_score.active.to_i + 4 + user_score.save + Rails.logger.debug "[UserScore#project] ===> User: [#{current_user.id},#{current_user.name}] posting issue. options => (#{options.to_s})" + else + Rails.logger.error "[UserScore#project] ===> #{operate} is not define." + return false + end + rescue => e + Rails.logger.error "[UserScore#project] ===> Exception: #{e}." + end + + private + + def self.get_users(current_user, target_user) + cUser = (current_user.kind_of?User) ? current_user : User.find_by_id(current_user) + tUser = (target_user.kind_of?User) ? target_user : User.find_by_id(target_user) + + [cUser, tUser] + end end diff --git a/app/views/bids/_homework_list.html.erb b/app/views/bids/_homework_list.html.erb index f1fd0b7b7..4415b996d 100644 --- a/app/views/bids/_homework_list.html.erb +++ b/app/views/bids/_homework_list.html.erb @@ -75,7 +75,8 @@ 作业评分: - <%= homework_score homework %> + + <%= format("%.2f", homework.rate_averages.first.try(:avg).to_i ) %> <% if Time.parse(@bid.deadline.to_s) < Time.parse(homework.created_at.to_s) %> @@ -86,7 +87,7 @@   <% if User.current.member_of?(@bid.courses.first) %> - <%= l(:label_bidding_user_studentcode) %>  : <%= homework.user.user_extensions.student_id%> + <%= l(:label_bidding_user_studentcode) %>  : <%= homework.user.student_id%> <% end %> diff --git a/app/views/bids/show_project.html.erb b/app/views/bids/show_project.html.erb index c14d2e14c..039de6b7a 100644 --- a/app/views/bids/show_project.html.erb +++ b/app/views/bids/show_project.html.erb @@ -1,8 +1,9 @@ <% if @bid.homework_type == Bid::HomeworkFile %> + <%= render :partial => 'homework' %> <% else %> - +