Merge branch 'develop' of https://git.trustie.net/jacknudt/trustieforge into develop

This commit is contained in:
txz 2016-04-19 16:26:29 +08:00
commit 45aa157ff0
7 changed files with 72 additions and 43 deletions

View File

@ -660,8 +660,8 @@ class AttachmentsController < ApplicationController
end
def has_login
unless @attachment && @attachment.container_type == "Organization"
unless @attachment && @attachment.container_type == "PhoneAppVersion"
unless (@attachment && @attachment.container_type == "Organization").nil?
unless (@attachment && @attachment.container_type == "PhoneAppVersion").nil?
render_403 if !User.current.logged? && !(@attachment.container_type == 'OrgSubfield' && @attachment.container.organization.allow_guest_download) && !(@attachment.container_type == 'OrgDocumentComment' && @attachment.container.organization.allow_guest_download)
end
end

View File

@ -120,59 +120,52 @@ module ApplicationHelper
case type
when "HomeworkCommon"
if course_contributor_score.nil?
CourseContributorScore.create(:course_id => course_id, :user_id => user_id, :message_num => 0, :message_reply_num => 0,
:news_reply_num => 0, :resource_num => 0, :journal_num => 0, :journal_reply_num => 0, :homework_journal_num => 1)
CourseContributorScore.create(:course_id => course_id, :user_id => user_id, :homework_journal_num => 1)
else
score = course_contributor_score.homework_journal_num + 1
score = course_contributor_score.homework_journal_num.to_i + 1
course_contributor_score.update_attributes(:homework_journal_num => score)
end
# 课程留言
when "Course"
if course_contributor_score.nil?
CourseContributorScore.create(:course_id => course_id, :user_id => user_id, :message_num => 0, :message_reply_num => 0,
:news_reply_num => 0, :resource_num => 0, :journal_num => 1, :journal_reply_num => 0)
CourseContributorScore.create(:course_id => course_id, :user_id => user_id, :journal_num => 1)
else
score = course_contributor_score.journal_num + 1
score = course_contributor_score.journal_num.to_i + 1
course_contributor_score.update_attributes(:journal_num => score)
end
when "Message"
if course_contributor_score.nil?
CourseContributorScore.create(:course_id => course_id, :user_id => user_id, :message_num => 1, :message_reply_num => 0,
:news_reply_num => 0, :resource_num => 0, :journal_num => 0, :journal_reply_num => 0)
CourseContributorScore.create(:course_id => course_id, :user_id => user_id, :message_num => 1)
else
score = course_contributor_score.message_num + 1
score = course_contributor_score.message_num.to_i + 1
course_contributor_score.update_attributes(:message_num => score)
end
when "MessageReply"
if course_contributor_score.nil?
CourseContributorScore.create(:course_id => course_id, :user_id => user_id, :message_num => 0, :message_reply_num => 1,
:news_reply_num => 0, :resource_num => 0, :journal_num => 0, :journal_reply_num => 0)
CourseContributorScore.create(:course_id => course_id, :user_id => user_id, :message_reply_num => 1)
else
score = course_contributor_score.message_reply_num + 1
score = course_contributor_score.message_reply_num.to_i + 1
course_contributor_score.update_attributes(:message_reply_num => score)
end
when "NewReply"
if course_contributor_score.nil?
CourseContributorScore.create(:course_id => course_id, :user_id => user_id, :message_num => 0, :message_reply_num => 0,
:news_reply_num => 1, :resource_num => 0, :journal_num => 0, :journal_reply_num => 0)
CourseContributorScore.create(:course_id => course_id, :user_id => user_id, :news_reply_num => 1)
else
score = course_contributor_score.news_reply_num + 1
score = course_contributor_score.news_reply_num.to_i + 1
course_contributor_score.update_attributes(:news_reply_num => score)
end
when "News"
if course_contributor_score.nil?
CourseContributorScore.create(:course_id => course_id, :user_id => user_id, :message_num => 0, :message_reply_num => 0,
:news_reply_num => 0, :news_num => 1, :resource_num => 0, :journal_num => 0, :journal_reply_num => 0)
CourseContributorScore.create(:course_id => course_id, :user_id => user_id, :news_num => 1)
else
score = course_contributor_score.news_num + 1
score = course_contributor_score.news_num.to_i + 1
course_contributor_score.update_attributes(:news_num => score)
end
when "Attachment"
if course_contributor_score.nil?
CourseContributorScore.create(:course_id => course_id, :user_id => user_id, :message_num => 0, :message_reply_num => 0,
:news_reply_num => 0, :news_num => 0, :resource_num => 1, :journal_num => 0, :journal_reply_num => 0)
CourseContributorScore.create(:course_id => course_id, :user_id => user_id, :resource_num => 1)
else
score = course_contributor_score.resource_num + 1
score = course_contributor_score.resource_num.to_i + 1
course_contributor_score.update_attributes(:resource_num => score)
end
end
@ -184,38 +177,38 @@ module ApplicationHelper
case type
when "HomeworkCommon"
unless course_contributor_score.nil?
score = course_contributor_score.homework_journal_num - 1
score = course_contributor_score.homework_journal_num.to_i - 1
course_contributor_score.update_attribute(:homework_journal_num, score < 0 ? 0 : score)
end
# 课程留言
when "Course"
unless course_contributor_score.nil?
score = course_contributor_score.journal_num - 1
score = course_contributor_score.journal_num.to_i - 1
course_contributor_score.update_attribute(:journal_num, score < 0 ? 0 : score)
end
when "Message"
unless course_contributor_score.nil?
score = course_contributor_score.message_num - 1
score = course_contributor_score.message_num.to_i - 1
course_contributor_score.update_attribute(:message_num, score < 0 ? 0 : score)
end
when "MessageReply"
unless course_contributor_score.nil?
score = course_contributor_score.message_reply_num - 1
score = course_contributor_score.message_reply_num.to_i - 1
course_contributor_score.update_attribute(:message_reply_num, score < 0 ? 0 : score)
end
when "NewReply"
unless course_contributor_score.nil?
score = course_contributor_score.news_reply_num - 1
score = course_contributor_score.news_reply_num.to_i - 1
course_contributor_score.update_attribute(:news_reply_num, score < 0 ? 0 : score)
end
when "News"
unless course_contributor_score.nil?
score = course_contributor_score.news_num - 1
score = course_contributor_score.news_num.to_i - 1
course_contributor_score.update_attribute(:news_num, score < 0 ? 0 : score)
end
when "Attachment"
unless course_contributor_score.nil?
score = course_contributor_score.resource_num - 1
score = course_contributor_score.resource_num.to_i - 1
course_contributor_score.update_attribute(:resource_num, score < 0 ? 0 : score)
end
end

View File

@ -80,12 +80,10 @@ class Message < ActiveRecord::Base
validates_length_of :subject, :maximum => 255
validate :cannot_reply_to_locked_topic, :on => :create
after_create :add_author_as_watcher, :reset_counters!, :add_boards_count
# after_create :add_author_as_watcher, :reset_counters!, :add_boards_count
after_update :update_messages_board, :update_activity
after_destroy :reset_counters!,:down_user_score,:delete_kindeditor_assets, :decrease_boards_count, :down_course_score
after_create :act_as_activity,:act_as_course_activity,:be_user_score,:act_as_forge_activity,
:act_as_system_message, :send_mail, :act_as_student_score, act_as_at_message(:content, :author_id)
after_create :act_as_course_activity, :act_as_forge_activity, :act_as_student_score, act_as_at_message(:content, :author_id), :add_author_as_watcher, :reset_counters!, :add_boards_count
#before_save :be_user_score
scope :visible, lambda {|*args|
@ -137,11 +135,11 @@ class Message < ActiveRecord::Base
if self.project && !project.project_score.nil?
# 讨论区
if self.parent_id.nil?
count = self.project.project_score.board_num + 1
self.project.project_score.update_attribute(:board_num, count)
count = self.project.project_score.board_num.to_i + 1
self.project.project_score.update_column(:board_num, count)
else # 回复
count = self.project.project_score.board_message_num + 1
self.project.project_score.update_attribute(:board_message_num, count)
count = self.project.project_score.board_message_num.to_i + 1
self.project.project_score.update_column(:board_message_num, count)
end
end
end

View File

@ -43,8 +43,8 @@
</div>
<div class="homepagePostSetting">
<ul>
<% if User.current.logged? %>
<li class="homepagePostSettingIcon">
<% if User.current.logged? %>
<% if (delete_allowed || User.current.id == file.author_id) && file.container_id == org_subfield.id && file.container_type == "OrgSubfield" %>
<ul class="homepagePostSettiongText">
<li><%= link_to("发&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;送".html_safe, 'javascript:void(0)',:class => "postOptionLink",:onclick=>"show_send('#{file.id}','#{User.current.id}','file')") %></li>
@ -66,8 +66,8 @@
<li><%= link_to("发&nbsp;&nbsp;送".html_safe, 'javascript:void(0)',:class => "postOptionLink2",:onclick=>"show_send('#{file.id}','#{User.current.id}','file')") %></li>
</ul>
<% end %>
<% end %>
</li>
<% end %>
</ul>
</div>

View File

@ -69,7 +69,7 @@
<span class="width120"><pre style="white-space: pre-wrap; margin-right: 15px;"><%=x["result"].force_encoding("UTF-8")%> </pre></span>
<span class="w60">正确输出:</span>
<span class="width120"><pre style="white-space: pre-wrap; margin-right: 15px;"><%=x["output"]%></pre></span>
<span class="width120"><pre style="white-space: pre-wrap; margin-right: 15px;"><%=x["output"].force_encoding("UTF-8")%></pre></span>
<span class="w50">耗时:</span>
<span class="w80"><pre><%=x["time_used"]==0?1:x["time_used"]%>毫秒</pre></span>
<div class="cl"></div>

View File

@ -143,9 +143,9 @@
<span class="w60 c_red">测试错误!</span>
<% end %>
<span class="w60">您的输出:</span>
<span class="w180"><pre style="white-space: pre-wrap; margin-right: 15px;"><%=x["result"]%> </pre></span>
<span class="w180"><pre style="white-space: pre-wrap; margin-right: 15px;"><%=x["result"].force_encoding("UTF-8")%> </pre></span>
<span class="w60">正确输出:</span>
<span class="w180"><pre style="white-space: pre-wrap; margin-right: 15px;"><%= x["output"] %></pre></span>
<span class="w180"><pre style="white-space: pre-wrap; margin-right: 15px;"><%= x["output"].force_encoding("UTF-8") %></pre></span>
<span class="w50"> 耗时:</span>
<span class="w80"><pre><%=x["time_used"]==0?1:x["time_used"]%>毫秒</pre></span>

38
lib/tasks/sync_files.rake Normal file
View File

@ -0,0 +1,38 @@
require 'trustie/gitlab/sync'
namespace :trustie do
namespace :files do
desc "sync course'file"
task :course => :environment do
# Course.all.each do |course|
# unless course.attachments.count.to_i == 0
# attachment_count = Attachment.find_by_sql("SELECT * FROM `attachments` where container_id = #{course.id} and container_type ='Course'").count
# project_score = ProjectScore.where("project_id=?", project.id).first
# if project_score.nil?
# ProjectScore.create(:project_id => project.id, :attach_num => 0)
# else
# project_score.attach_num = attachment_count
# project_score.save
# end
# end
# end
end
desc "sync project'file"
task :project => :environment do
Project.all.each do |project|
unless project.attachments.count.to_i == 0
attachment_count = Attachment.find_by_sql("SELECT * FROM `attachments` where container_id = #{project.id} and container_type ='Project'").count
project_score = ProjectScore.where("project_id=?", project.id).first
if project_score.nil?
ProjectScore.create(:project_id => project.id, :attach_num => 0)
else
project_score.attach_num = attachment_count
project_score.save
end
end
end
end
end
end