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

This commit is contained in:
daiao 2017-02-24 14:52:06 +08:00
commit 47017f875a
13 changed files with 174 additions and 122 deletions

View File

@ -4,9 +4,9 @@ unless RUBY_PLATFORM =~ /w32/
# unix-like only
gem 'iconv'
if RUBY_PLATFORM =~ /darwin/
gem "rmagick", "= 2.15.4" ## osx must be this version
# gem "rmagick", "= 2.15.4" ## osx must be this version
elsif RUBY_PLATFORM =~ /linux/
gem "rmagick", "~> 2.13.1" ## centos yum install ImageMagick-devel
# gem "rmagick", "~> 2.13.1" ## centos yum install ImageMagick-devel
end
gem 'certified'
gem 'net-ssh', '2.9.1'

View File

@ -978,7 +978,11 @@ class AdminController < ApplicationController
#作业
def homework
#@homework = HomeworkCommon.order('end_time desc')
@homework = HomeworkCommon.order( 'created_at desc ')
if params[:type] == "2"
@homework = HomeworkCommon.where(:homework_type => 2).order( 'created_at desc ')
else
@homework = HomeworkCommon.order( 'created_at desc ')
end
@homework = paginateHelper @homework,30
@page = (params['page'] || 1).to_i - 1
respond_to do |format|

View File

@ -312,7 +312,11 @@ class ApplicationController < ActionController::Base
def authorize_allowed(ctrl = params[:controller], action = params[:action], global = false)
#modify by NWB
if @project
allowed = User.current.allowed_to?({:controller => ctrl, :action => action}, @project || @projects, :global => global)
if ctrl == "repositories" && action == "show" && @project.hidden_repo
allowed = User.current.admin? || (User.current.member_of?(@project) && !(role_of_members_in_project(@project.id, User.current.id) == "Reporter"))
else
allowed = User.current.allowed_to?({:controller => ctrl, :action => action}, @project || @projects, :global => global)
end
elsif @course
allowed = User.current.allowed_to?({:controller => ctrl, :action => action}, @course || @courses, :global => global)
else

View File

@ -837,26 +837,43 @@ class ProjectsController < ApplicationController
if @project.training_tasks.count == 0
@notice = "实训开启失败:请先发布实训任务"
return
elsif Repository.where(:project_id => @project.id, :type => "Repository::Gitlab").count == 0
@notice = "实训开启失败:请先创建版本库"
return
end
jobName = "#{@project.id}"
pipeLine = "#{Base64.encode64(@project.script)}"
uri = URI("http://123.59.135.74:9999/jenkins-exec/api/createJob")
res = Net::HTTP.post_form(uri, {jobName: jobName, pipeLine: pipeLine}).body
@project.update_attribute(:training_status, 1)
@notice = "实训开启成功"
params = {jobName: jobName, pipeLine: pipeLine}
res = uri_exec uri, params
training_project_notice res
end
def training_project_update
jobName = "#{@project.id}"
pipeLine = "#{Base64.encode64(@project.script)}"
uri = URI("http://123.59.135.74:9999/jenkins-exec/api/updateJob")
res = Net::HTTP.post_form(uri, {jobName: jobName, pipeLine: pipeLine}).body
@notice = "重新开启实训成功"
params = {jobName: jobName, pipeLine: pipeLine}
res = uri_exec uri, params
training_project_notice res
end
def training_project_notice res
if res['code'] == 0
@notice = "实训开启成功"
elsif res['code'] == -2
@notice = "Job已存在"
else
@notice = res['msg'].nil? ? "实训开启失败" : res['msg']
end
end
# TrainintTask.status 0评测中 1评测成功 2评测惊醒中
# 非项目成员、非实训子项目不允许执行该方法
def task_execute
if !@project.is_child_training_project? || !User.current.member_of?(@project)
return render_403
end
taskId = params[:training_task_id]
jobName = @project.forked_from_project_id
@training_task = TrainingTask.find(taskId)
@ -864,17 +881,19 @@ class ProjectsController < ApplicationController
params = {:jobName => "#{jobName}", :taskId => "#{taskId}"}
uri = URI.parse("http://123.59.135.74:9999/jenkins-exec/api/buildJob")
begin
respond_message = uri_exec uri, params
res = uri_exec uri, params
# 任务开启成功后创建一条留言提示,并发布
@training_task.update_attribute(:status, 2)
return
rescue
@message = "失败,请联系系统管理员"
rescue Exception => e
puts e
end
end
end
def uri_exec uri, params
res = Net::HTTP.post_form(uri, params).body
res = JSON.parse(res)
end
# 开启实训项目,学生会fork一个项目并自动发送任务
@ -907,24 +926,51 @@ class ProjectsController < ApplicationController
# 需要传Task ID
# 判断任务是否完成
# 如果完成则发送下一个任务直到任务结束
# TrainingTask.status 1 成功,2 失败
# TrainingTask.status 1 成功,其它失败
def training_task_status
status = params[:code].to_i
status = params[:status].to_i
task_id = params[:taskId]
stage = params[:stage].to_i
@training_task = TrainingTask.find(task_id)
original_project_id = Project.find(@training_task.project_id).try(:forked_from_project_id)
original_project = Project.find(original_project_id)
message = params[:msg].to_i
begin
@training_task = TrainingTask.find(task_id)
# 如果已经执行成功过,则不重复执行
return if @training_task.status == 1
original_project_id = Project.find(@training_task.project_id).try(:forked_from_project_id)
original_project = Project.find(original_project_id)
rescue
return
end
original_tasks_count = original_project.training_tasks.count
position = @training_task.try(:position) + 1
# 测试,默认成功
if position <= original_tasks_count
# 继续下一个任务
publish_training_tasks original_project_id, @training_task.project_id, position
@training_task.update_attribute(:status, 1)
if status == 0
ActiveRecord::Base.transaction do
if position <= original_tasks_count
# 继续发布下一个任务
publish_training_tasks original_project_id, @training_task.project_id, position
@training_task.update_attribute(:status, 1)
end
# 创建一条回复提醒
content = "恭喜您通过测评"
add_training_task_journal(content, original_project.user_id)
end
else
content = "很遗憾,您没有通过该步"
add_training_task_journal(content, original_project.user_id)
end
end
# 创建一条回复
def add_training_task_journal content, user_id
jour = Journal.new
jour.user_id = user_id
jour.notes = content
jour.journalized = @training_task
jour.save
update_user_activity(@training_task.class, @training_task.id)
update_forge_activity(@training_task.class, @training_task.id)
end
# 实训开启成功后,发布第一个任务
# REDO:失败后提醒用户,及相关处理
def publish_training_tasks original_project_id, new_training_project_id, position
@ -938,7 +984,7 @@ class ProjectsController < ApplicationController
training_task.author_id = User.current.id
if training_task.save
respond_to do |format|
format.html{redirect_to project_training_tasks_url(:project_id => new_training_project_id)}
format.html{redirect_to project_url(new_training_project_id)}
end
else
raise "create task failed"

View File

@ -40,7 +40,8 @@ class RepositoriesController < ApplicationController
# before_filter :connect_gitlab, :only => [:quality_analysis, :commit_diff]
before_filter :find_changeset, :only => [:revision, :add_related_issue, :remove_related_issue]
before_filter :authorize , :except => [:newrepo,:newcreate,:fork, :to_gitlab, :forked, :project_archive, :quality_analysis, :commit_diff, :training_project_extend]
# before_filter :authorize , :except => [:newrepo,:newcreate,:fork, :to_gitlab, :forked, :project_archive, :quality_analysis, :commit_diff]
before_filter :authorize_visible , :except => [:newrepo,:newcreate,:fork, :to_gitlab, :forked, :project_archive, :quality_analysis, :commit_diff]
# 版本库新增权限
# before_filter :show_rep, :only => [:show, :stats, :revisions, :revision, :diff, :commit_diff ]
accept_rss_auth :revisions
@ -485,11 +486,12 @@ update
redirect_to :controller => 'repositories', :action => 'show', :id => @project.id, to: 'gitlab'
end
# 权限:
# 如果项目隐藏了版本库,则非项目成员及项目报告人员不能够访问版本库
# 如果没有隐藏版本库,只要项目公开,其它成员都可以看到版本库
# 项目关联了课程,课程的老师是可以看到版本库的
# 超级管理员可以看到项目版本库
def show
if !User.current.admin? && (@project.hidden_repo && (role_of_members_in_project(@project.id, User.current.id) == "Reporter" || !is_project_member?(User.current.id, @project.id)))
render_403
return
else
# 顶部导航
@project_menu_type = 5
@ -499,7 +501,6 @@ update
if request.xhr?
@entries ? render(:partial => 'dir_list_content') : render(:nothing => true)
else
unless @entries.blank?
@changesets_latest_coimmit = @g.rep_last_changes(@project.gpid, :rev => @rev, :path => @path)
# @g.rep_last_changes(@project.gpid, :rev => @rev, :path => @path)
# 总的提交数
@ -515,7 +516,6 @@ update
# token值解密
# gitlab_token = aes_dicrypt("priEn3UwXfJs3Pmy", token)
@zip_path = Gitlab.endpoint.to_s + "/projects/" + @project.gpid.to_s + "/repository/archive?&private_token=" + token
end
@creator = @project.owner.to_s
gitlab_address = Redmine::Configuration['gitlab_address']
@ -537,7 +537,6 @@ update
render :layout => 'base_projects'
end
end
end
alias_method :browse, :show
@ -787,6 +786,19 @@ update
end
end
def authorize_visible
allowed = authorize_allowed(params[:controller], params[:action], global = false)
if allowed || User.current.admin? || (@project.hidden_repo && User.current.member_of?(@project) && !role_of_members_in_project(@project.id, User.current.id) == "Reporter")
true
else
if @project && @project.archived?
render_403 :message => :notice_not_authorized_archived_project
else
deny_access
end
end
end
private
# 更新项目统计数
def update_commits_count project, count

View File

@ -1,7 +1,7 @@
<h3>
<%=l(:label_user_homework)%>
</h3>
<p><%= link_to "编程作业", admin_homework_path(:type => "2") %></p>
<div class="autoscroll">
<table class="list" style="width: 100%;table-layout: fixed">
<thead>

View File

@ -59,12 +59,9 @@
<%= link_to project_file_num > 0 ? "#{l(:project_module_files)}<span class='issues_nav_tag ml5'>#{switch_integer_into_k project_file_num}</span>".html_safe : l(:project_module_files), project_files_path(@project), :class => "pro_new_proname", :title => "#{project_file_num}" %>
<% end %>
<!--版本库-->
<% if visible_repository?(@project) %>
<% if User.current.admin? || (is_project_member?(User.current.id, @project.id) && role_of_members_in_project(@project.id, User.current.id) != "Reporter" ) %>
<li id="project_menu_05"><%= link_to @project.project_score.changeset_num.to_i > 0 ? "#{l(:project_module_repository)}<span class='issues_nav_tag ml5'>#{switch_integer_into_k project_score.changeset_num}</span>".html_safe : "#{l(:project_module_repository)}",({:controller => 'repositories', :action => 'show', :id => @project, :repository_id => gitlab_repository(@project).try(:identifier)}), :class => "pro_new_proname", :title => "#{project_score.changeset_num}" %>
</li>
<% if !@project.enabled_modules.where("name = 'repository'").empty? && !Repository.where(:project_id => @project.id, :type => "Repository::Gitlab").first.nil? %>
<li id="project_menu_05"><%= link_to @project.project_score.changeset_num.to_i > 0 ? "#{l(:project_module_repository)}<span class='issues_nav_tag ml5'>#{switch_integer_into_k project_score.changeset_num}</span>".html_safe : "#{l(:project_module_repository)}",({:controller => 'repositories', :action => 'show', :id => @project, :repository_id => gitlab_repository(@project).try(:identifier)}), :class => "pro_new_proname", :title => "#{project_score.changeset_num}" %></li>
<% end %>
<% end %>
<!--Pull Request-->
<% unless @project.gpid.nil? %>
<li id="project_menu_06">

View File

@ -46,9 +46,12 @@
<div class="mb10" style="font-weight:normal;">
<%= render :partial=>"attachments/activity_attach", :locals=>{:activity => activity} %>
</div>
<div id="training_project_task_status_<%= activity.id %>">
<%= render :partial => "training_tasks/action_status", :locals => {:activity => activity} %>
</div>
<% if @project.is_child_training_project? %>
<div id="training_project_task_status_<%= activity.id %>">
<%= render :partial => "training_tasks/action_status", :locals => {:activity => activity} %>
</div>
<% end %>
</div>
<div class="cl"></div>
</div>

View File

@ -8,7 +8,7 @@
<table class="sy_new_table " cellpadding="0" cellspacing="0">
<thead>
<tr>
<td style="width:15%;">名称</td>
<td style="width:15%;padding-left: 5px">名称</td>
<td style="width:10%;">分支</td>
<td style="width:10%;">语言</td>
<td style="width:25%;">路径</td>
@ -20,7 +20,7 @@
<% if @quality_analyses && @quality_analyses.count > 0 %>
<% @quality_analyses.each do |qa| %>
<tr>
<td style="width:15%;overflow:hidden; white-space: nowrap; text-overflow:ellipsis;" title="<%= qa.sonar_name %>"><%=link_to qa.sonar_name, project_quality_analysis_path(:resource_id => qa.sonar_name, :branch => (qa.branch.nil? ? "master" : qa.branch)), :class => "analysis-result-name fl fontBlue2 hidden" %></td>
<td style="width:15%;overflow:hidden; white-space: nowrap; text-overflow:ellipsis;padding-left: 5px;" title="<%= qa.sonar_name %>"><%=link_to qa.sonar_name, project_quality_analysis_path(:resource_id => qa.sonar_name, :branch => (qa.branch.nil? ? "master" : qa.branch)), :class => "analysis-result-name fl fontBlue2 hidden" %></td>
<td style="width:10%;"><%= qa.branch %></td>
<td style="width:10%;"><%= qa.language %></td>
<td style="width:25%;overflow:hidden; white-space: nowrap; text-overflow:ellipsis;" title="<%= qa.path %>"><%= qa.path %></td>

View File

@ -1,11 +1,11 @@
<div class="recordBanner mt3">
<% if @changesets_latest_coimmit %>
<% if @changesets_latest_coimmit && @changesets_latest_coimmit.try(:time) %>
<div class="recordBanner mt3">
<%= image_tag(url_to_avatar(user_commit_rep(@changesets_latest_coimmit.try(:author_email))), :width => "25", :height => "25", :class => "fl portraitRadius mt2 ml4 mr5") %>
<%= link_to_user_mail(@changesets_latest_coimmit.try(:author_email), "fb fontGrey3 mr5 fl hidden maxwidth150 ml5") %>
<div class="fl">提交于 <%= time_tag(@changesets_latest_coimmit.try(:time)) %> 前:</div>
<div class="commit_content_dec fl" title="<%= @changesets_latest_coimmit.message %>"><%= @changesets_latest_coimmit.message %></div>
<% end %>
<% if @entry && @entry.kind == 'file' %>
<%= render :partial => 'link_to_functions' %>
<% end %>
</div>
<% if @entry && @entry.kind == 'file' %>
<%= render :partial => 'link_to_functions' %>
<% end %>
</div>
<% end %>

View File

@ -1,86 +1,70 @@
<%#= call_hook(:view_repositories_show_contextual, {:repository => @repository, :project => @project}) %>
<div class="wrap-big">
<div class="repository_con" style="line-height:1.9;">
<% if @entries.nil? %>
<%# 未提交代码提示 %>
<div class=" repository-url light-well">
<% if @entries.nil? && authorize_for('repositories', 'browse') %>
<div class="page-title">
该版本库还没有上传代码!
</div>
<% end %>
<% if @repository.type.to_s == "Repository::Gitlab" %>
版本库地址:<%= @repos_url %>
<% else %>
版本库地址:<%= h @repository.url %>
<% end %>
<div class="cl"></div>
</div>
<% else %>
<ul class="clearfix pro-top-info mb10">
<li><i class="icon-time mr5 c_grey02 f16 fb"></i>
<%=link_to "#{choise_commit_count(@changesets_all_count, @g_project.commit_count.to_i)}",
{:action => 'changes', :path => to_path_param(@path), :id => @project, :repository_id => @repository.identifier_param,
:rev => @rev, :page => 1 ,:commit_count =>"#{@changesets_all_count}"}, :class => "linkBlue fb" %> 提交
</li>
<li><i class="icon-sitemap mr5 c_grey02 f16 fb"></i>
<a class="linkBlue fb "><%= @repository.branches.count %></a>分支
</li>
<li><i class="icon-bar-chart mr5 c_grey02 f16 fb"></i>
<%=link_to "贡献统计", stats_repository_project_path(:id => @project.id, :repository_id => @repository.identifier, :rev => @rev,
:creator => @creator, :default_branch => @g_default_branch ) %>
</li>
</ul>
<div class=" clearfix mb5">
<div class=" fl clearfix">
<%= render :partial => 'navigation' %>
</div>
<a href="<%= @zip_path %>" class="btn_zipdown fl ml10" onclick="">ZIP下载</a>
<% if User.current.member_of?(@project) && @project.is_public? %>
<% if quality_analysis(User.current.try(:login), @repository.id).nil? %>
<%= link_to "质量分析", quality_analysis_path(:id => @project.id, :repository_id => @repository.identifier, :rev => @rev, :default_branch => @g_default_branch, :type => "1"), :remote => true, :class => "btn_zipdown fl ml10" %>
<% else %>
<%= link_to "重新分析", quality_analysis_path(:id => @project.id, :repository_id => @repository.identifier, :rev => @rev, :default_branch => @g_default_branch, :type => "2"), :remote => true, :class => "btn_zipdown fl ml10" %>
<% end %>
<% end %>
<% unless QualityAnalysis.where(:project_id => @project.id).first.nil? %>
<%= link_to "代码分析结果", project_quality_analysis_path(:project_id => @project.id), :class => "btn_zipdown fl ml10" %>
<% end %>
<div class="fr ">
<label class="pro-fenzhi-label fl">克隆网址</label>
<input type="text" id="copy_rep_content" class="pro-fenzhi-input fl" value="<%= @repos_url.to_s.lstrip %>"/>
<a href="javascript:void(0);" alt="点击复制版本库地址" onclick="jsCopy()" title="点击复制版本库地址" class="fl pro-fenzhi-a"><i class="icon-copy"></i></a>
</div>
</div>
<div class="cl"></div>
<%= render :partial => 'latest_commit' %>
<div class="cl"></div>
<div class="repository_con" style="line-height:1.9;">
<ul class="clearfix pro-top-info mb10">
<li><i class="icon-time mr5 c_grey02 f16 fb"></i>
<%=link_to "#{choise_commit_count(@changesets_all_count, @g_project.commit_count.to_i)}",
{:action => 'changes', :path => to_path_param(@path), :id => @project, :repository_id => @repository.identifier_param,
:rev => @rev, :page => 1 ,:commit_count =>"#{@changesets_all_count}"}, :class => "linkBlue fb" %> 提交
</li>
<li><i class="icon-sitemap mr5 c_grey02 f16 fb"></i>
<a class="linkBlue fb "><%= @repository.branches.count %></a>分支
</li>
<li><i class="icon-bar-chart mr5 c_grey02 f16 fb"></i>
<%=link_to "贡献统计", stats_repository_project_path(:id => @project.id, :repository_id => @repository.identifier, :rev => @rev,
:creator => @creator, :default_branch => @g_default_branch ) %>
</li>
</ul>
<div class=" clearfix mb5">
<div class=" fl clearfix">
<%= render :partial => 'navigation' %>
</div>
<a href="<%= @zip_path %>" class="btn_zipdown fl ml10" onclick="">ZIP下载</a>
<% if !@entries.blank? && User.current.member_of?(@project) && @project.is_public? %>
<% if quality_analysis(User.current.try(:login), @repository.id).nil? %>
<%= link_to "质量分析", quality_analysis_path(:id => @project.id, :repository_id => @repository.identifier, :rev => @rev, :default_branch => @g_default_branch, :type => "1"), :remote => true, :class => "btn_zipdown fl ml10" %>
<% else %>
<%= link_to "重新分析", quality_analysis_path(:id => @project.id, :repository_id => @repository.identifier, :rev => @rev, :default_branch => @g_default_branch, :type => "2"), :remote => true, :class => "btn_zipdown fl ml10" %>
<% end %>
<% end %>
<% unless QualityAnalysis.where(:project_id => @project.id).first.nil? %>
<%= link_to "代码分析结果", project_quality_analysis_path(:project_id => @project.id), :class => "btn_zipdown fl ml10" %>
<% end %>
<% if !@entries.nil? && authorize_for('repositories', 'browse') %>
<div class="fr ">
<label class="pro-fenzhi-label fl">克隆网址</label>
<input type="text" id="copy_rep_content" class="pro-fenzhi-input fl" value="<%= @repos_url.to_s.lstrip %>"/>
<a href="javascript:void(0);" alt="点击复制版本库地址" onclick="jsCopy()" title="点击复制版本库地址" class="fl pro-fenzhi-a"><i class="icon-copy"></i></a>
</div>
</div>
<div class="cl"></div>
<%= render :partial => 'latest_commit' %>
<div class="cl"></div>
<% if !@entries.blank? && authorize_for('repositories', 'browse') %>
<%= render :partial => 'dir_list' %>
<% else %>
<%= render :partial => "projects/no_data" %>
<% end %>
<% memo = Memo.where(:id => 1232).first %>
<% unless memo.nil? %>
<a href="<%= Setting.protocol + "://" %><%=Setting.host_name %>/forums/1/memos/1232" class="linkBlue2" target="_blank">如何提交代码</a>
<a href="<%= Setting.protocol + "://" %><%=Setting.host_name %>/forums/1/memos/1232" class="linkBlue2" target="_blank">如何提交代码</a>
<% end %>
<% unless @entries.blank? %>
<div class="fr">
<a style="color: #7f7f7f;">导出统计结果:</a>
<%= link_to "最近一周", {:controller => 'repositories', :action => 'export_rep_static', :format => 'xls', :rev => @rev, :cycle => "week" }, :class => "linkBlue2" %> <a style="color: #7f7f7f;">|</a>
<%= link_to "最近一月", {:controller => 'repositories', :action => 'export_rep_static', :format => 'xls', :rev => @rev, :cycle => "month" }, :class => "linkBlue2" %>
</div>
<div class="cl"></div>
<div class="fr">
<a style="color: #7f7f7f;">导出统计结果:</a>
<%= link_to "最近一周", {:controller => 'repositories', :action => 'export_rep_static', :format => 'xls', :rev => @rev, :cycle => "week" }, :class => "linkBlue2" %> <a style="color: #7f7f7f;">|</a>
<%= link_to "最近一月", {:controller => 'repositories', :action => 'export_rep_static', :format => 'xls', :rev => @rev, :cycle => "month" }, :class => "linkBlue2" %>
</div>
<div class="cl"></div>
<% end %>
<%#= link_to "导出excel", {:controller => 'repositories', :action => 'export_rep_static', :rev => @rev}, :format => 'xls' %>
<!--<a href="<%#=project_issues_path(:project_id => @project, :format => 'xls')%>" class="hw_btn_blue fr" alt="导出EXCEL">导出EXCEL</a>-->
</div>
<%#= link_to "导出excel", {:controller => 'repositories', :action => 'export_rep_static', :rev => @rev}, :format => 'xls' %>
<!--<a href="<%#=project_issues_path(:project_id => @project, :format => 'xls')%>" class="hw_btn_blue fr" alt="导出EXCEL">导出EXCEL</a>-->
</div>
</div>
<%# content_for :header_tags do %>
<%#= stylesheet_link_tag "scm" %>
<%#= stylesheet_link_tag "scm" %>
<%# end %>
<% html_title(l(:label_repository)) -%>

View File

@ -5,7 +5,9 @@
<% elsif activity.status == 2 %>
<span class="task-display-span alert-blue mt10">当前任务正在后台测评中,稍后将显示您的任务完成情况......</span>
<% else %>
<%= link_to "提交评测", task_execute_project_path(@project, :training_task_id => activity.id), :class => "task-display-span bBlue mt10", :remote => true %>
<% if User.current.member_of?(@project) && @project.is_child_training_project? %>
<%= link_to "提交评测", task_execute_project_path(@project, :training_task_id => activity.id), :class => "task-display-span bBlue mt10", :remote => true %>
<% end %>
<% end %>
</div>

View File

@ -26,7 +26,7 @@
</div>
</td>
<td >
<% if activity.journals.count != 0 %>
<% if activity.journals.count != 0 %>
<a href="javascript:void(0);" class="issues_icons_mes fl mr5 ml5 "></a>
<a href="javascript:void(0);" class="fl mt2"><%= activity.journals.count %></a>
<% end %>