This commit is contained in:
z9hang 2014-07-22 16:00:11 +08:00
commit 41ea3a1baf
15 changed files with 97 additions and 77 deletions

View File

@ -57,15 +57,9 @@ bundle exec rake db:migrate:up VERSION=20140410021724
2.运行 bundle install --without development test
3.运行 rake redmine:plugins:migrate RAILS_ENV=production
4.启动服务器
5.把文本格式 (Administration > Settings > General > Text formatting)改为CKEditor
6.配置CKEditor插件(Administration > Plugins > Configure)
某些情况数据库未插入插件配置值解决方案:
1 复制plugins
2 启动rails
3 运行migrate
3 打开admin配置插件http://127.0.0.1:3000/settings/plugin/redmine_ckeditor
4 点击“查询”(就是确定的功能)
5.配置CKEditor插件(Administration > Plugins > Configure)
6.把文本格式 (Administration > Settings > General > Text formatting)改为CKEditor
注意一定要先配置CKEditor插件再见文本格式更改不然数据库不会生成对应记录会报错。。
===============================================================================
0719若遇到首页定制报错问题请尝试如下操作
如果运行迁移文件有报错与sort_type相关 先运行 bundle exec rake db:migrate:down version=20140716021202 bundle exec rake db:migrate:up version=20140716021202

View File

@ -70,7 +70,7 @@ class BoardsController < ApplicationController
@message = Message.new(:board => @board)
#modify by nwb
if @project
render :action => 'show', :layout => !request.xhr?
render :action => 'show', :layout => 'base_projects'
elsif @course
render :action => 'show', :layout => 'base_courses'
end

View File

@ -29,14 +29,21 @@ class DocumentsController < ApplicationController
def index
@sort_by = %w(category date title author).include?(params[:sort_by]) ? params[:sort_by] : 'category'
documents = @project.documents.includes(:attachments, :category).all
temp = @project.documents.includes(:attachments, :category).all
documents = []
temp.each do |doc|
if doc.has_right?(@project)
documents << doc
end
end
case @sort_by
when 'date'
@grouped = documents.group_by {|d| d.updated_on.to_date }
when 'title'
@grouped = documents.group_by {|d| d.title.first.upcase}
when 'author'
@grouped = documents.select{|d| d.attachments.any?}.group_by {|d| d.attachments.last.author}
# @grouped = documents.select{|d| d.attachments.any?}.group_by {|d| d.attachments.last.author}
@grouped = documents.group_by {|d| d.user.name }
else
@grouped = documents.group_by(&:category)
end
@ -105,7 +112,7 @@ class DocumentsController < ApplicationController
# 权限判断
# add by nwb
def authorize_document
if !(User.current.admin? || User.current.member_of?(@project) || @document.is_public==1)
if !(User.current.admin? || User.current.member_of?(@project) || @document == nil || (@document != nil && @document.is_public==1))
render_403 :message => :notice_not_authorized
end
end

View File

@ -148,7 +148,7 @@ class WelcomeController < ApplicationController
end
private
# 判断网站的入口,是课程 course 则跳过index去渲染 course 方法
def entry_select
url = request.original_url
if url.include?("course.trustie.net")
@ -166,28 +166,6 @@ class WelcomeController < ApplicationController
end
# 判断网站的入口,是课程 course 则跳过index去渲染 course 方法
def entry_select_course
if request.original_url.match(/.*course\.trustie\.net/)
(course() and render :course and return 0)
end
end
def entry_select_contest
if request.original_url.match(/.*contest\.trustie\.net/)
contest
render :contest
return 0
end
end
def entry_select_user
if request.original_url.match(/.*user\.trustie\.net$/)
redirect_to(:controller => "users", :action => "index")
return 0
end
end
# def render(*args)
# _fake if @fake_filter
# super

View File

@ -37,12 +37,22 @@ class ZipdownController < ApplicationController
#下载某一学生的作业的所有文件
def download_user_homework
homework = HomeworkAttach.find params[:homework]
if homework != nil && (User.current.admin? || User.current.member_of_course?(homework.bid.courses.first))
if User.current.admin? || User.current.member_of_course?(homework.bid.courses.first)
if homework != nil
if homework.attachments.count > 0
zipfile = zip_homework_by_user homework
send_file zipfile, :filename => homework.name+".zip", :type => detect_content_type(zipfile) if zipfile
send_file zipfile, :filename => homework.name+".zip", :type => detect_content_type(zipfile) if(zipfile)
else
render_403 :message => :no_file_dowmload
end
else
render_403 :message =>:notice_file_not_found
end
else
render_403 :message => :notice_not_authorized
end
rescue => e
render file: 'public/file_not_found.html'
end
private
@ -67,8 +77,10 @@ class ZipdownController < ApplicationController
# 得到每一个人所有文件打包的zip文件
# 并将每一个人的zip打包为一个并返回路径
user_zip_paths = homeattaches.map do |homeattach|
if homeattach.attachments.count > 0
zip_homework_by_user homeattach
end
end
zipping "#{Time.now.to_i}_#{bid.name}.zip", user_zip_paths, OUTPUT_FOLDER
#@paths = homeworks_attach_path
@ -81,6 +93,7 @@ class ZipdownController < ApplicationController
end
def zip_homework_by_user(homeattach)
#if homeattach.attachments.count > 0
homeworks_attach_path = []
# 需要将所有homework.attachments遍历加入zip
# 并且返回zip路径
@ -88,8 +101,9 @@ class ZipdownController < ApplicationController
#length = attach.storage_path.length
homeworks_attach_path << attach.diskfile#.to_s.slice((length+1)..-1)
end
zipping "#{homeattach.user.name.to_s}_#{Time.now.to_i}.zip", homeworks_attach_path, OUTPUT_FOLDER, true
zipping("#{homeattach.user.name.to_s}_#{Time.now.to_i}.zip", homeworks_attach_path, OUTPUT_FOLDER, true)
#user_attaches_paths
#end
end

View File

@ -46,6 +46,10 @@ class Document < ActiveRecord::Base
!user.nil? && user.allowed_to?(:view_documents, project)
end
def has_right?(project,user=User.current)
user.admin? || user.member_of?(project) || self.is_public==1
end
def initialize(attributes=nil, *args)
super
if new_record?

View File

@ -56,13 +56,12 @@ class Project < ActiveRecord::Base
#added by xianbo for delete biding_project
has_many :biding_projects, :dependent => :destroy
has_many :contesting_projects, :dependent => :destroy
has_many :projecting_softapplications, :dependent => :destroy
has_many :softapplications, :through => :projecting_softapplications
#ended by xianbo
# added by fq
has_many :journals_for_messages, :as => :jour, :dependent => :destroy
has_many :homework_for_courses, :dependent => :destroy
has_many :homeworks, :through => :homework_for_courses, :source => :bid, :dependent => :destroy
#has_many :homework_for_courses, :dependent => :destroy
#has_many :homeworks, :through => :homework_for_courses, :source => :bid, :dependent => :destroy
has_many :shares, :dependent => :destroy
# has_many :students_for_courses, :dependent => :destroy
has_many :student, :through => :students_for_courses, :source => :user
@ -1138,13 +1137,13 @@ class Project < ActiveRecord::Base
# 创建项目后在项目下同步创建一个讨论区
def create_board_sync
@board = self.boards.build
self.name=" #{l(:label_borad_course) }"
self.name=" #{l(:label_borad_project) }"
@board.name = self.name
@board.description = self.name.to_s
if @board.save
logger.debug "[Course Model] ===> #{@board.to_json}"
logger.debug "[Project Model] ===> #{@board.to_json}"
else
logger.error "[Course Model] ===> Auto create board when Course saved, because #{@board.full_messages}"
logger.error "[Project Model] ===> Auto create board when Project saved, because #{@board.full_messages}"
end
end

View File

@ -35,3 +35,5 @@
<% content_for :header_tags do %>
<%= javascript_include_tag 'attachments' %>
<% end %>

View File

@ -8,10 +8,7 @@
<table width="100%" valign="center">
<tr>
<td ><span style="margin-left:0px"><%= l(:label_task_plural)%>(<%= @homework_list.count%>)</span>
<%#= link_to "作业打包下载", zipdown_assort_path(obj_class: @bid.class, obj_id: @bid), remote: false, class: "button_submit button_submit_font_white", style: "margin: 5px 10px;line-height: 20px;height: 20px;display: inline-block;" if(
User.current.admin? ||
!(User.current.roles_for_project(@bid.courses.first).map(&:id) & ([7,9])).empty? ) ||
(Rails.env.development?) %>
<%= link_to "作业打包下载", zipdown_assort_path(obj_class: @bid.class, obj_id: @bid), remote: false, class: "button_submit button_submit_font_white", style: "margin: 5px 10px;line-height: 20px;height: 20px;display: inline-block;" if(is_teacher && @bid.homeworks.count > 0) %>
</td>
<td align="right">
<div class="project-search">

View File

@ -1867,6 +1867,7 @@ zh:
lable_close_mutual_evaluation: 关闭互评
label_has_been: 已经被
label_course_userd_by: 个课程引用
no_file_dowmload: 该作业没有任何的附件可以下载
role_of_course: 课程角色
label_student: 学生

View File

@ -0,0 +1,20 @@
class UpdateCourseAttachment < ActiveRecord::Migration
# 更新课程资源类型
def up
Attachment.all.each do |attachment|
if attachment.container_type == 'Course'
if attachment.attachtype == 1
attachment.attachtype = 4
elsif attachment.attachtype == 2
attachment.attachtype = 5
elsif attachment.attachtype == 3
attachment.attachtype = 6
end
attachment.save
end
end
end
def down
end
end

View File

@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.
ActiveRecord::Schema.define(:version => 20140721074353) do
ActiveRecord::Schema.define(:version => 20140722024513) do
create_table "activities", :force => true do |t|
t.integer "act_id", :null => false

View File

@ -156,12 +156,12 @@ function uploadBlob(blob, uploadUrl, attachmentId, options) {
}
function addInputFiles(inputEl) {
var clearedFileInput = $(inputEl).clone().val('');
// var clearedFileInput = $(inputEl).clone().val('');
if (inputEl.files) {
// upload files using ajax
uploadAndAttachFiles(inputEl.files, inputEl);
$(inputEl).remove();
// $(inputEl).remove();
} else {
// browser not supporting the file API, upload on form submission
var attachmentId;
@ -172,7 +172,7 @@ function addInputFiles(inputEl) {
}
}
clearedFileInput.insertAfter('#attachments_fields');
//clearedFileInput.insertAfter('#attachments_fields');
}
function uploadAndAttachFiles(files, inputEl) {

View File

@ -10,6 +10,7 @@ class CoursesControllerTest < ActionController::TestCase
Setting.default_language = 'en'
end
# Get :index
def test_index_by_anonymous_should_not_show_private_projects
get :index
assert_response :success
@ -19,6 +20,7 @@ class CoursesControllerTest < ActionController::TestCase
assert courses.all?(&:is_public?)
end
# Get :new
# 人员添加课程的权限是不属于任何角色
def test_new_course_anyone_temporary
@request.session[:user_id] = 5
@ -29,6 +31,7 @@ class CoursesControllerTest < ActionController::TestCase
assert_template :new
end
# post :create
def test_create_course_with_access_control
@request.session[:user_id] = 5
Role.find_by_name("Non member").add_permission! :add_course #Non member
@ -54,6 +57,7 @@ class CoursesControllerTest < ActionController::TestCase
# assert_redirected_to "courses/#{course.id}/settings"
end
# post :create 403
def test_create_course_without_access_control
@request.session[:user_id] = 5
#Role.find_by_name("Non member").add_permission! :add_course #Non member