From b49344107c502c862be597777ba5b139f234e2e0 Mon Sep 17 00:00:00 2001 From: nwb Date: Tue, 22 Jul 2014 08:51:35 +0800 Subject: [PATCH 01/12] =?UTF-8?q?=E7=94=A8=E6=88=B7=E5=8A=A8=E6=80=81?= =?UTF-8?q?=E6=9D=83=E9=99=90=E5=88=A4=E5=AE=9A=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/users_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 34745709b..9e7ee0229 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -33,7 +33,7 @@ class UsersController < ApplicationController before_filter :require_admin, :except => [:show, :index, :search, :tag_save, :tag_saveEx,:user_projects, :user_newfeedback, :user_comments, :watch_bids, :watch_contests, :info, :user_watchlist, :user_fanslist,:update, :user_courses, :user_homeworks, :watch_projects, :show_score, :topic_score_index, :project_score_index, :activity_score_index, :influence_score_index, :score_index,:show_new_score, :topic_new_score_index, :project_new_score_index, - :activity_new_score_index, :influence_new_score_index, :score_new_index,:update_score] + :activity_new_score_index, :influence_new_score_index, :score_new_index,:update_score,:user_activities] #edit has been deleted by huang, 2013-9-23 before_filter :find_user, :only => [:user_fanslist, :user_watchlist, :show, :edit, :update, :destroy, :edit_membership, :user_courses, :user_homeworks, :destroy_membership, :user_activities, :user_projects, :user_newfeedback, :user_comments, From 518edeac68696b473de09efecea558d9900a388d Mon Sep 17 00:00:00 2001 From: nwb Date: Tue, 22 Jul 2014 09:15:19 +0800 Subject: [PATCH 02/12] =?UTF-8?q?=E9=A1=B9=E7=9B=AE=E6=96=87=E6=A1=A3?= =?UTF-8?q?=E6=B5=8F=E8=A7=88BUG=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/boards_controller.rb | 2 +- app/controllers/documents_controller.rb | 2 +- app/models/project.rb | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/controllers/boards_controller.rb b/app/controllers/boards_controller.rb index a692acc12..40674b53f 100644 --- a/app/controllers/boards_controller.rb +++ b/app/controllers/boards_controller.rb @@ -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 diff --git a/app/controllers/documents_controller.rb b/app/controllers/documents_controller.rb index 89bd9dc92..7bca47f36 100644 --- a/app/controllers/documents_controller.rb +++ b/app/controllers/documents_controller.rb @@ -105,7 +105,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 diff --git a/app/models/project.rb b/app/models/project.rb index 5bcd2e8c5..35a360ac3 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -1138,13 +1138,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 From edee2b23273487fa37f774fb7c654228b9486d8a Mon Sep 17 00:00:00 2001 From: yanxd Date: Mon, 21 Jul 2014 17:21:09 +0800 Subject: [PATCH 03/12] =?UTF-8?q?=E5=88=A0=E6=8E=89welcome=E6=B2=A1?= =?UTF-8?q?=E7=94=A8=E7=9A=84=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/welcome_controller.rb | 24 +----------------------- 1 file changed, 1 insertion(+), 23 deletions(-) diff --git a/app/controllers/welcome_controller.rb b/app/controllers/welcome_controller.rb index 9330d1d44..516b88310 100644 --- a/app/controllers/welcome_controller.rb +++ b/app/controllers/welcome_controller.rb @@ -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 From 8496d6e0d2942fd1c3a6214960b0734e6e57c032 Mon Sep 17 00:00:00 2001 From: yanxd Date: Tue, 22 Jul 2014 09:16:07 +0800 Subject: [PATCH 04/12] =?UTF-8?q?=E5=88=A0=E9=99=A4project=E5=A4=9A?= =?UTF-8?q?=E4=BD=99=E5=AF=BC=E8=87=B4=E5=88=A0=E9=99=A4=E9=A1=B9=E7=9B=AE?= =?UTF-8?q?=E5=A4=B1=E8=B4=A5=E7=9A=84=E5=85=B3=E8=81=94=E5=85=B3=E7=B3=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/project.rb | 5 ++--- test/functional/courses_controller_test.rb | 4 ++++ 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/app/models/project.rb b/app/models/project.rb index 35a360ac3..d6283e44f 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -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 diff --git a/test/functional/courses_controller_test.rb b/test/functional/courses_controller_test.rb index a1551a717..7185f6303 100644 --- a/test/functional/courses_controller_test.rb +++ b/test/functional/courses_controller_test.rb @@ -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 From cf11cac0ad11a30b1bf8f2869891823075bef28a Mon Sep 17 00:00:00 2001 From: nwb Date: Tue, 22 Jul 2014 09:32:46 +0800 Subject: [PATCH 05/12] =?UTF-8?q?=E9=A1=B9=E7=9B=AE=E6=96=87=E6=A1=A3?= =?UTF-8?q?=E6=9D=83=E9=99=90=E5=88=A4=E6=96=AD=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/documents_controller.rb | 8 +++++++- app/models/document.rb | 4 ++++ app/views/documents/index.html.erb | 6 +++--- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/app/controllers/documents_controller.rb b/app/controllers/documents_controller.rb index 7bca47f36..b0ad6b109 100644 --- a/app/controllers/documents_controller.rb +++ b/app/controllers/documents_controller.rb @@ -29,7 +29,13 @@ 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 } diff --git a/app/models/document.rb b/app/models/document.rb index 5cfce896b..1467903b0 100644 --- a/app/models/document.rb +++ b/app/models/document.rb @@ -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? diff --git a/app/views/documents/index.html.erb b/app/views/documents/index.html.erb index 41b2d13fd..43b0cff49 100644 --- a/app/views/documents/index.html.erb +++ b/app/views/documents/index.html.erb @@ -27,8 +27,8 @@ <% if @grouped.empty? %>

<%= l(:label_no_data) %>

<% end %> <% @grouped.keys.sort.each do |group| %> - - <%= render :partial => 'documents/document', :collection => @grouped[group] %> -<% end %> + + <%= render :partial => 'documents/document', :collection => @grouped[group] %> +<% end %> <% html_title(l(:label_document_plural)) -%> From ab55043880ac1e19ecabbfd7c7acc49391e4c82a Mon Sep 17 00:00:00 2001 From: sw <939547590@qq.com> Date: Tue, 22 Jul 2014 09:42:41 +0800 Subject: [PATCH 06/12] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=BD=93=E4=BD=9C?= =?UTF-8?q?=E4=B8=9A=E9=99=84=E4=BB=B6=E5=88=97=E8=A1=A8=E4=B8=BA=E7=A9=BA?= =?UTF-8?q?=E6=97=B6=EF=BC=8C=E7=82=B9=E5=87=BB=E6=89=93=E5=8C=85=E4=B8=8B?= =?UTF-8?q?=E8=BD=BD=E4=BC=9A=E6=8A=A5500=E9=94=99=E7=9A=84BUG?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/zipdown_controller.rb | 34 +++++++++++++++++--------- app/views/bids/_homework_list.html.erb | 5 +--- config/locales/zh.yml | 1 + 3 files changed, 24 insertions(+), 16 deletions(-) diff --git a/app/controllers/zipdown_controller.rb b/app/controllers/zipdown_controller.rb index 33a569f5d..777c0d8b7 100644 --- a/app/controllers/zipdown_controller.rb +++ b/app/controllers/zipdown_controller.rb @@ -37,9 +37,17 @@ 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)) - zipfile = zip_homework_by_user homework - send_file zipfile, :filename => homework.name+".zip", :type => detect_content_type(zipfile) if zipfile + 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 + 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 @@ -81,15 +89,17 @@ class ZipdownController < ApplicationController end def zip_homework_by_user(homeattach) - homeworks_attach_path = [] - # 需要将所有homework.attachments遍历加入zip - # 并且返回zip路径 - user_attaches_paths = homeattach.attachments.each do |attach| - #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 - #user_attaches_paths + #if homeattach.attachments.count > 0 + homeworks_attach_path = [] + # 需要将所有homework.attachments遍历加入zip + # 并且返回zip路径 + user_attaches_paths = homeattach.attachments.each do |attach| + #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) + #user_attaches_paths + #end end diff --git a/app/views/bids/_homework_list.html.erb b/app/views/bids/_homework_list.html.erb index 8b241030a..81c960781 100644 --- a/app/views/bids/_homework_list.html.erb +++ b/app/views/bids/_homework_list.html.erb @@ -8,10 +8,7 @@
<%= l(:label_task_plural)%>(<%= @homework_list.count%>) - <%#= 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) %>