This commit is contained in:
zhanghaitao 2014-08-20 09:42:15 +08:00
commit 337f0ec270
20 changed files with 127 additions and 35 deletions

View File

@ -103,7 +103,11 @@ class MessagesController < ApplicationController
# Edit a message
def edit
if @project
(render_403; return false) unless @message.editable_by?(User.current)
else
(render_403; return false) unless @message.course_editable_by?(User.current)
end
@message.safe_attributes = params[:message]
if request.post? && @message.save
attachments = Attachment.attach_files(@message, params[:attachments])
@ -124,7 +128,11 @@ class MessagesController < ApplicationController
# Delete a messages
def destroy
if @project
(render_403; return false) unless @message.destroyable_by?(User.current)
else
(render_403; return false) unless @message.course_destroyable_by?(User.current)
end
r = @message.to_param
@message.destroy
# modify by nwb

View File

@ -441,7 +441,7 @@ FROM `users` where id = #{user.id}")
#更新对缺陷留言数
def update_messges_for_issue(user,type,project=nil)
option_number = get_option_number(user,type)
option_number = get_option_number(user,type,project)
option_number.messages_for_issues = messges_for_issue_num(user,project)#Journal.includes(:user).where("user_id = '#{user.id}' and notes != '' and notes is not null").all.count
update_score(option_number)
end
@ -464,7 +464,7 @@ FROM `users` where id = #{user.id}")
#更新更改缺陷状态状态次数
def update_issues_status(user,type,project=nil)
option_number = get_option_number(user,type)
option_number = get_option_number(user,type,project)
option_number.issues_status = issues_status_num(user,project)#Journal.joins(:details, :user).where("#{JournalDetail.table_name}.prop_key = 'status_id' and #{User.table_name}.id = '#{user.id}'").count
update_score(option_number)
end
@ -490,7 +490,7 @@ FROM `users` where id = #{user.id}")
#更新对留言的回复数量
def update_replay_for_message(user,type,project=nil)
option_number = get_option_number(user,type)
option_number = get_option_number(user,type,project)
option_number.replay_for_message = replay_for_message_num(user,project)#JournalsForMessage.includes(:user).where("m_parent_id IS NOT NULL and user_id = #{user.id}").count
update_score(option_number)
end
@ -514,7 +514,7 @@ FROM `users` where id = #{user.id}")
#更新对帖子的回复数量
def update_replay_for_memo(user,type,project=nil)
option_number = get_option_number(user,type)
option_number = get_option_number(user,type,project)
option_number.replay_for_memo = replay_for_memo_num(user,project)#Message.includes(:author).where("parent_id IS NOT NULL and author_id = #{user.id}").all.count #+ Memo.includes(:author).where("parent_id IS NOT NULL and author_id = #{user.id}").all.count
update_score(option_number)
end
@ -552,7 +552,7 @@ FROM `users` where id = #{user.id}")
#更新帖子踩各项数量
def update_tread(user,type,project=nil)
option_number = get_option_number(user,type)
option_number = get_option_number(user,type,project)
tread_nums = tread_num(user,project)
option_number.tread = tread_nums[:tread]
option_number.tread_by_one = tread_nums[:tead_by_one]
@ -617,7 +617,7 @@ FROM `users` where id = #{user.id}")
#更新帖子顶数量
def update_praise(user,type,project=nil)
option_number = get_option_number(user,type)
option_number = get_option_number(user,type,project)
praise_nums = praise_num(user,project)
option_number.praise_by_one = praise_nums[:praise_by_one]
option_number.praise_by_two = praise_nums[:praise_by_two]
@ -682,7 +682,7 @@ FROM `users` where id = #{user.id}")
#更新提交代码次数
def update_changeset(user,type,project=nil)
option_number = get_option_number(user,type)
option_number = get_option_number(user,type,project)
option_number.changeset = changeset_num(user,project)#Changeset.includes(:user).where("user_id = '#{user.id}'").all.count
update_score(option_number)
end
@ -698,7 +698,7 @@ FROM `users` where id = #{user.id}")
#更新文档提交次数
def update_document(user,type,project=nil)
option_number = get_option_number(user,type)
option_number = get_option_number(user,type,project)
option_number.document = document_num(user,project)#Document.includes(:user).where("user_id = '#{user.id}'").all.count
update_score(option_number)
end
@ -714,7 +714,7 @@ FROM `users` where id = #{user.id}")
#更新附件提交数量
def update_attachment(user,type,project=nil)
option_number = get_option_number(user,type)
option_number = get_option_number(user,type,project)
option_number.attachment = attachment_num(user,project)#Attachment.includes(:author).where("author_id = '#{user.id}'").all.count
update_score(option_number)
end
@ -729,7 +729,7 @@ FROM `users` where id = #{user.id}")
#更新缺陷完成度次数
def update_issue_done_ratio(user,type,project=nil)
option_number = get_option_number(user,type)
option_number = get_option_number(user,type,project)
option_number.issue_done_ratio = issue_done_ratio_num(user,project) #Journal.joins(:details, :user).where("#{JournalDetail.table_name}.prop_key = 'done_ratio' and #{User.table_name}.id = '#{user.id}'").count
update_score(option_number)
end
@ -745,7 +745,7 @@ FROM `users` where id = #{user.id}")
#更新发布缺陷次数
def update_post_issue(user,type,project=nil)
option_number = get_option_number(user,type)
option_number = get_option_number(user,type,project)
option_number.post_issue = post_issue_num(user,project) #Issue.includes(:author).where("author_id = '#{user.id}'").all.count
update_score(option_number)
end
@ -758,6 +758,12 @@ FROM `users` where id = #{user.id}")
end
end
#读取项目成员得分
def read_user_project_scores(user,project)
option_num = get_option_number(user,2,project)
option_num.total_score
end
def user_scores(user,type,project=nil)
ooption_num = get_option_number(user,type,project)
update_memo_number(user,type,project)

View File

@ -512,11 +512,18 @@ class Attachment < ActiveRecord::Base
end
end
update_attachment(self.author,1)
if self.container_type == 'Project'
update_attachment(self.author,2,self.container)
end
end
#删除附件时重新统计用户的附件数量得分
def down_user_score
update_attachment(self.author,1)
if self.container_type == 'Project'
update_attachment(self.author,2,self.container)
end
end
end

View File

@ -308,12 +308,14 @@ class Changeset < ActiveRecord::Base
#更新用户等级
UserLevels.update_user_level(self.user)
update_changeset(self.user,1)
update_changeset(self.user,2,self.repository.project)
end
#积分刷新
def down_user_score
UserLevels.update_user_level(self.user)
update_changeset(self.user,1)
update_changeset(self.user,2,self.repository.project)
end
end

View File

@ -69,9 +69,11 @@ class Document < ActiveRecord::Base
def be_user_score
UserScore.project(:push_document, self.user,self,{ document_id: self.id })
update_document(self.user,1)
update_document(self.user,2,self.project)
end
def down_user_score
update_document(self.user,1)
update_document(self.user,2,self.project)
end
end

View File

@ -1524,6 +1524,7 @@ class Issue < ActiveRecord::Base
def be_user_score_new_issue
UserScore.project(:post_issue, self.author,self, { issue_id: self.id })
update_post_issue(self.author,1)
update_post_issue(self.author,2,self.project)
end
def down_user_score
@ -1539,8 +1540,13 @@ class Issue < ActiveRecord::Base
# update_issues_status(self.author , 1)
#end
update_post_issue(self.author,1)
update_issue_done_ratio(User.current,1)
update_issues_status(self.author , 1)
#update_issue_done_ratio(self.author,1)
#update_issues_status(self.author , 1)
update_post_issue(self.author,2,self.project)
#update_issue_done_ratio(self.author,2,self.project)
#update_issues_status(self.author , 2)
end

View File

@ -163,6 +163,7 @@ class Journal < ActiveRecord::Base
#协同得分加分
UserScore.joint(:post_issue_message, self.user,self.issue.author,self, { message_id: self.id })
update_messges_for_issue(self.user,1)
update_messges_for_issue(self.user,2,self.issue.project)
end
end
@ -173,6 +174,7 @@ class Journal < ActiveRecord::Base
#协同得分减分
UserScore.joint(:delete_issue_message, self.user,self.issue.author,self, { message_id: self.id })
update_messges_for_issue(self.user,1)
update_messges_for_issue(self.user,2,self.issue.project)
end
end

View File

@ -46,9 +46,15 @@ class JournalDetail < ActiveRecord::Base
#更新缺陷完成度
if self.prop_key == 'done_ratio'
update_issue_done_ratio(self.journal.user,1)
unless self.journal.project.nil?
update_issue_done_ratio(self.journal.user,2,self.journal.project)
end
#更新缺陷状态
elsif self.prop_key == 'status_id'
update_issues_status(self.journal.user , 1)
unless self.journal.project.nil?
update_issues_status(self.journal.user,2,self.journal.project)
end
end
end
@ -57,9 +63,16 @@ class JournalDetail < ActiveRecord::Base
if self.prop_key == 'done_ratio'
update_issue_done_ratio(self.journal.user,1)
unless self.journal.project.nil?
update_issue_done_ratio(self.journal.user,2,self.journal.project)
end
#更新缺陷状态
elsif self.prop_key == 'status_id'
update_issues_status(self.journal.user, 1)
unless self.journal.project.nil?
update_issues_status(self.journal.user,2,self.journal.project)
end
end
end

View File

@ -144,6 +144,9 @@ class JournalsForMessage < ActiveRecord::Base
#协同得分加分
UserScore.joint(:reply_message, self.user,User.find(self.reply_id),self, { journals_for_messages_id: self.id })
update_replay_for_message(self.user,1)
if self.jour_type == "Project"
update_replay_for_message(self.user,2,self.jour)
end
end
end
# 更新用户分数 -by zjc
@ -153,6 +156,9 @@ class JournalsForMessage < ActiveRecord::Base
#协同得分减分
UserScore.joint(:reply_message_delete, self.user,User.find(self.reply_id), { journals_for_messages_id: self.id })
update_replay_for_message(self.user,1)
if self.jour_type == "Project"
update_replay_for_message(self.user,2,self.jour)
end
end
end
end

View File

@ -151,6 +151,7 @@ class Memo < ActiveRecord::Base
if self.parent_id.nil?
UserScore.joint(:post_message, User.current,nil,self ,{ memo_id: self.id })
update_memo_number(User.current,1)
#新建memo且有parent的为回帖
elsif !self.parent_id.nil?
UserScore.joint(:reply_posting, User.current,self.parent.author,self, { memo_id: self.id })

View File

@ -127,6 +127,14 @@ class Message < ActiveRecord::Base
board.course
end
def course_editable_by?(usr)
usr && usr.logged? && (usr.allowed_to?(:edit_messages, course) || (self.author == usr && usr.allowed_to?(:edit_own_messages, course)))
end
def course_destroyable_by?(usr)
usr && usr.logged? && (usr.allowed_to?(:delete_messages, course) || (self.author == usr && usr.allowed_to?(:delete_own_messages, course)))
end
def editable_by?(usr)
usr && usr.logged? && (usr.allowed_to?(:edit_messages, project) || (self.author == usr && usr.allowed_to?(:edit_own_messages, project)))
end
@ -152,11 +160,17 @@ class Message < ActiveRecord::Base
#新建message且无parent的为发帖
if self.parent_id.nil? && !self.board.project.nil?
UserScore.joint(:post_message, self.author,nil,self, { message_id: self.id })
update_memo_number(User.current,1)
update_memo_number(self.author,1)
if self.board.project_id != -1
update_memo_number(self.author,2,self.board.project)
end
#新建message且有parent的为回帖
elsif !self.parent_id.nil? && !self.board.project.nil?
UserScore.joint(:reply_posting, self.author,self.parent.author,self, { message_id: self.id })
update_replay_for_memo(User.current,1)
update_replay_for_memo(self.author,1)
if self.board.project_id != -1
update_replay_for_memo(self.author,2,self.board.project)
end
end
end
@ -165,9 +179,15 @@ class Message < ActiveRecord::Base
if self.parent_id.nil? && !self.board.project.nil?
UserScore.joint(:delete_message, self.author,nil,self, { message_id: self.id })
update_memo_number(User.current,1)
if self.board.project_id != -1
update_memo_number(self.author,2,self.board.project)
end
elsif !self.parent_id.nil? && !self.board.project.nil?
UserScore.joint(:reply_deleting, self.author,self.parent.author,self, { message_id: self.id })
update_replay_for_memo(User.current,1)
if self.board.project_id != -1
update_replay_for_memo(self.author,2,self.board.project)
end
end
end
end

View File

@ -43,14 +43,21 @@ class PraiseTread < ActiveRecord::Base
obj = PraiseTread.find_object_by_type_and_id(self.praise_tread_object_type,praise_tread_object_id)
target_user = obj.author
UserScore.skill(:treaded_by_user, User.current,target_user,self, { praise_tread_id: self.id })
update_tread(User.current,1)
update_tread(self.user,1)
update_tread(target_user,1)
unless self.project.nil?
update_tread(self.user,2,self.project)
update_tread(target_user,2,self.project)
end
#顶贴吧或讨论区帖子
elsif self.praise_or_tread == 1 && (self.praise_tread_object_type == 'Issue' || self.praise_tread_object_type == 'Message')
obj = PraiseTread.find_object_by_type_and_id(self.praise_tread_object_type,praise_tread_object_id)
target_user = obj.author
UserScore.skill(:praised_by_user, User.current,target_user,self,{ praise_tread_id: self.id })
update_praise(target_user,1)
unless self.project.nil?
update_praise(target_user,2,self.project)
end
#更新用户等级
UserLevels.update_user_level(target_user)
end
@ -62,14 +69,21 @@ class PraiseTread < ActiveRecord::Base
obj = PraiseTread.find_object_by_type_and_id(self.praise_tread_object_type,praise_tread_object_id)
target_user = obj.author
#UserScore.skill(:treaded_by_user, User.current,target_user,self, { praise_tread_id: self.id })
update_tread(User.current,1)
update_tread(self.user,1)
update_tread(target_user,1)
unless self.project.nil?
update_tread(self.user,2,self.project)
update_tread(target_user,2,self.project)
end
#顶贴吧或讨论区帖子
elsif self.praise_or_tread == 1 && (self.praise_tread_object_type == 'Issue' || self.praise_tread_object_type == 'Message')
obj = PraiseTread.find_object_by_type_and_id(self.praise_tread_object_type,praise_tread_object_id)
target_user = obj.author
#UserScore.skill(:praised_by_user, User.current,target_user,self,{ praise_tread_id: self.id })
update_praise(target_user,1)
unless self.project.nil?
update_praise(target_user,2,self.project)
end
#更新用户等级
UserLevels.update_user_level(target_user)
end

View File

@ -148,7 +148,7 @@
"编辑",
{:action => 'edit', :id => message},
:title => l(:button_edit)
) if message.editable_by?(User.current) %>
) if message.course_editable_by?(User.current) %>
<%= link_to(
#image_tag('delete.png'),
"删除",
@ -156,7 +156,7 @@
:method => :post,
:data => {:confirm => l(:text_are_you_sure)},
:title => l(:button_delete)
) if message.destroyable_by?(User.current) %>
) if message.course_destroyable_by?(User.current) %>
</div></td>
</tr>
<tr>

View File

@ -30,13 +30,14 @@
border-bottom: 1px dashed rgb(204, 204, 204);
}
.memo-content {
width: 82%;
padding: 1%;
margin: 1%;
margin-bottom: 40px;
background-color: #F6F6F6;
white-space: normal;
/*word-break: break-all; */
word-wrap: break-word;
word-break: break-all;
/*word-wrap: break-word;*/
}
.memo-timestamp {
position: absolute;

View File

@ -24,7 +24,7 @@
<%= content_tag "div", content_tag("p", rolesToLanguage(member.roles.sort.collect(&:to_s)).join(', ')), :class => "clear avatar_name" %>
<div class="clear avatar_user">
<p> <!--user_scores(member.user,2,@project).total_score).to_i UserGrade.find_by_user_id_and_project_id(member[:user_id], @project.id).grade).to_i-->
<%= l(:label_user_for_project_grade) %>: <span style="color:#ec6300"><%= format("%.2f" ,user_scores(member.user,2,@project).total_score).to_i %></span>
<%= l(:label_user_for_project_grade) %>: <span style="color:#ec6300"><%= format("%.2f" ,read_user_project_scores(member.user,@project)).to_i %></span>
</p>
</div>
<% end %>

View File

@ -4,7 +4,7 @@
<div> = <%= l(:label_issue_score) %> + <%= l(:label_news_score) %> + <%= l(:label_file_score) %> +
<%= l(:label_code_submit_score) %> + <%= l(:label_topic_score) %></div>
<div> = <%= format("%.2f" , issue_score(@project)).to_i %> + <%= format("%.2f" , news_score(@project)).to_i %> +
<%= format("%.2f" , document_score(@project)).to_i %> + <%= format("%.2f" , changesets_score(@project)).to_i %> +
<%= format("%.2f" , documents_score(@project)).to_i %> + <%= format("%.2f" , changesets_score(@project)).to_i %> +
<%= format("%.2f" , board_message_score(@project)).to_i %></div>
<div> = <%= format("%.2f" , project_scores(@project)).to_i %></div>
<!-- end -->

View File

@ -37,7 +37,7 @@
</li>
<li>
<%= link_to l(:label_file_score), {:controller => 'projects', :action => 'file_score_index', :remote => true}%> :
<%= format("%.2f" , document_score(@project)).to_i %>
<%= format("%.2f" , documents_score(@project)).to_i %>
</li>
<li>
<%= link_to l(:label_code_submit_score), {:controller => 'projects', :action => 'code_submit_score_index', :remote => true}%> :

View File

@ -71,13 +71,12 @@
<% end %>
<% when '5' %>
<% if Forum.find(params[:id]) %>
<% if Forum.find(params[:id]).creator_id == User.current.id %>
<% test = Forum.find(obj.id) %>
<% if test && test.creator_id == User.current.id %>
<span class='del'> <%= link_to 'x', :controller => "tags", :action => "remove_tag", :remote => true, :tag_name => tag,
:taggable_id => obj.id, :taggable_type => object_flag %> </span>
<% end %>
<% end %>
<% when '6' %>
<%# if (User.current.logged? &&
User.current.admin?

View File

@ -43,8 +43,13 @@ module Redmine
end
def attachments_visible?(user=User.current)
if self.respond_to?(:project)
(respond_to?(:visible?) ? visible?(user) : true) &&
user.allowed_to?(self.class.attachable_options[:view_permission], self.project)
else
return true
end
end
def attachments_deletable?(user=User.current)

View File

@ -107,7 +107,7 @@
<%
submit_url = url_for(:controller => 'code_review', :action => 'new', :id=>@project)
%>
<%= button_to_function l(:button_apply), "$('#review-form').load('#{submit_url}', $('#review_form').serialize2json())" %>
<%= button_to_function l(:label_button_ok), "$('#review-form').load('#{submit_url}', $('#review_form').serialize2json())" %>
<input type="button" value="<%=h l(:button_cancel) %> " onclick="javascript:hideForm();"/>
<%= preview_link({ :controller => 'code_review', :action => 'preview', :id => @project}, 'review_form') %>