From 847bb35906fbe09d57be6d7392ff5df0df14e607 Mon Sep 17 00:00:00 2001
From: z9hang
Date: Wed, 30 Jul 2014 10:00:07 +0800
Subject: [PATCH 1/6] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E8=B0=B7=E6=AD=8C?=
=?UTF-8?q?=E6=B5=8F=E8=A7=88=E5=99=A8=E8=B4=B4=E5=90=A7=E5=9B=BE=E6=A0=87?=
=?UTF-8?q?=E5=81=8F=E7=A7=BB=E9=97=AE=E9=A2=98?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
app/views/forums/show.html.erb | 31 ++++++++++++++++---------------
1 file changed, 16 insertions(+), 15 deletions(-)
diff --git a/app/views/forums/show.html.erb b/app/views/forums/show.html.erb
index 34fc953da..d558abe3f 100644
--- a/app/views/forums/show.html.erb
+++ b/app/views/forums/show.html.erb
@@ -31,24 +31,25 @@
<% #= link_to '发布帖子', new_forum_memo_path(@forum), :class => 'icon icon-add' %>
+
+ <%= link_to(
+ image_tag('edit.png')+l(:label_forum_edit),
+ {:action => 'edit', :id => @forum},
+ :method => 'get',
+ :title => l(:button_edit)
+ ) if @forum.editable_by?(User.current) %>
+ <%= link_to(
+ image_tag('delete.png')+'删除讨论区',
+ {:action => 'destroy', :id => @forum},
+ :method => :delete,
+ :data => {:confirm => l(:text_are_you_sure)},
+ :title => l(:button_delete)
+ ) if @forum.destroyable_by?(User.current) %>
+
<%= link_to l(:label_memo_new_from_forum), new_forum_memo_path(@forum), :class => 'icon icon-add',
:onclick => 'showAndScrollTo("add-memo", "memo_subject"); return false;' if User.current.logged? %>
-
- <%= link_to(
- image_tag('edit.png')+l(:label_forum_edit),
- {:action => 'edit', :id => @forum},
- :method => 'get',
- :title => l(:button_edit)
- ) if @forum.editable_by?(User.current) %>
- <%= link_to(
- image_tag('delete.png')+'删除讨论区',
- {:action => 'destroy', :id => @forum},
- :method => :delete,
- :data => {:confirm => l(:text_are_you_sure)},
- :title => l(:button_delete)
- ) if @forum.destroyable_by?(User.current) %>
-
+
<%= render :partial => 'forums/show_topics', :locals => {:memos => @memos} %>
From 281c48c0b317fd387acb780fbefbbe2d4c56f4f5 Mon Sep 17 00:00:00 2001
From: yanxd
Date: Wed, 30 Jul 2014 10:18:36 +0800
Subject: [PATCH 2/6] .
---
app/controllers/courses_controller.rb | 2 +-
test/fixtures/biding_projects.yml | 8 ++++
test/fixtures/bids.yml | 34 +++++++++++++++
test/fixtures/homework_for_courses.yml | 10 +++++
test/fixtures/journals_for_messages.yml | 32 ++++++++++++++
test/functional/courses_controller_test.rb | 49 ++++++++++++++++++++++
6 files changed, 134 insertions(+), 1 deletion(-)
create mode 100644 test/fixtures/biding_projects.yml
create mode 100644 test/fixtures/bids.yml
create mode 100644 test/fixtures/homework_for_courses.yml
diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb
index 9db479eb5..d05eed7a0 100644
--- a/app/controllers/courses_controller.rb
+++ b/app/controllers/courses_controller.rb
@@ -494,7 +494,7 @@ class CoursesController < ApplicationController
if (User.current.logged? && User.current.member_of_course?(Course.find params[:id] ))
render :layout => 'base_courses'
else
- render_404
+ render_403
end
end
diff --git a/test/fixtures/biding_projects.yml b/test/fixtures/biding_projects.yml
new file mode 100644
index 000000000..6a55145f4
--- /dev/null
+++ b/test/fixtures/biding_projects.yml
@@ -0,0 +1,8 @@
+# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html
+---
+biding_project_001:
+ id: 1
+ project_id: -1
+ bid_id: 1
+
+#biding_project_002:
diff --git a/test/fixtures/bids.yml b/test/fixtures/bids.yml
new file mode 100644
index 000000000..2f486a914
--- /dev/null
+++ b/test/fixtures/bids.yml
@@ -0,0 +1,34 @@
+# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html
+---
+homework_001:
+ id: 1
+ author_id: 20
+ budget: "0"
+ commit: 3
+ deadline: "2014-05-30"
+ description: ""
+ homework_type: 1
+ is_evaluation:
+ name: "course_001_homework_001"
+ parent_id:
+ password:
+ proportion: 60
+ reward_type: 3 # 作业
+ updated_on: 2014-05-23 08:15:28
+ created_on: 2014-05-23 08:15:28
+homework_002:
+ id: 2
+ author_id: 20
+ budget: "0"
+ commit: 3
+ deadline: "2014-05-30"
+ description: ""
+ homework_type: 1
+ is_evaluation:
+ name: "course_001_homework_002"
+ parent_id:
+ password:
+ proportion: 60
+ reward_type: 3 # 作业
+ updated_on: 2014-05-23 08:15:28
+ created_on: 2014-05-23 08:15:28
diff --git a/test/fixtures/homework_for_courses.yml b/test/fixtures/homework_for_courses.yml
new file mode 100644
index 000000000..cf8310143
--- /dev/null
+++ b/test/fixtures/homework_for_courses.yml
@@ -0,0 +1,10 @@
+# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html
+---
+homework_for_courses_001:
+ id: 1
+ course_id: 1
+ bid_id: 1
+homework_for_courses_002:
+ id: 2
+ course_id: 1
+ bid_id: 2
diff --git a/test/fixtures/journals_for_messages.yml b/test/fixtures/journals_for_messages.yml
index a5d28caec..75e4f8ed1 100644
--- a/test/fixtures/journals_for_messages.yml
+++ b/test/fixtures/journals_for_messages.yml
@@ -28,6 +28,38 @@ jfm_002:
m_reply_count:
m_reply_id:
is_comprehensive_evaluation:
+jfm_003:
+ # Course one's jfm
+ id: 3
+ jour_id: 1
+ jour_type: Course
+ user_id: 2
+ notes:
+ status:
+ reply_id: 0
+ created_on: 2014-07-16 15:27:2
+ updated_on: 2014-07-16 15:27:2
+ m_parent_id:
+ is_readed:
+ m_reply_count:
+ m_reply_id:
+ is_comprehensive_evaluation:
+jfm_004:
+ # Course one's jfm
+ id: 4
+ jour_id: 1
+ jour_type: Course
+ user_id: 25
+ notes: course_001的留言by_user_025
+ status:
+ reply_id: 0
+ created_on: 2014-07-16 15:27:2
+ updated_on: 2014-07-16 15:27:2
+ m_parent_id:
+ is_readed:
+ m_reply_count:
+ m_reply_id:
+ is_comprehensive_evaluation:
jfm_045:
id: 45
jour_id: 2
diff --git a/test/functional/courses_controller_test.rb b/test/functional/courses_controller_test.rb
index b905b5038..66e613bfb 100644
--- a/test/functional/courses_controller_test.rb
+++ b/test/functional/courses_controller_test.rb
@@ -6,6 +6,9 @@ class CoursesControllerTest < ActionController::TestCase
:course_statuses,
:users,
:user_extensions,
+ :bids,
+ :homework_for_courses,
+ :journals_for_messages,
:schools,
:roles,
:members,
@@ -88,6 +91,52 @@ class CoursesControllerTest < ActionController::TestCase
assert_response :forbidden
end
+ test ':homework get by non-member is access' do
+ get :homework, {id: 1}
+ assert_response :success
+ end
+
+ test ':feedback Get by non-member is access' do
+ get :feedback, {id: 1}
+ assert_response :success
+ # 检测留言是否在其中以及不报错
+ jfms = JournalsForMessage.where(jour_type: 'Course', jour_id: 1, m_parent_id: nil).reorder('id DESC')
+ jfms.take(5).each do |j|
+ assert_select "li#word_li_#{j.id}"
+ end
+ end
+
+ test ':homework get by non-member' do
+ get :homework, {id: 1}
+ assert_response :success
+ course = Course.find(1)
+ assert course.homeworks.any?
+ course.homeworks.each do |homework|
+ assert_select '.bid_path', homework.name
+ end
+ end
+
+ test ':new_homework by no user should not new_homework course_001' do
+ get :new_homework, {id: 1}
+ assert_response 403
+ end
+ test ':new_homework by loged & allowed user should get new_homework course_001' do
+ user_id = 25
+ member = Member.create(user_id: user_id, project_id: -1, course_id: 1, roles: [Role.last])
+ MemberRole.create(member_id: member.id, role_id: 3)
+ @request.session[:user_id] = user_id
+ get :new_homework, {id: 1}
+ assert_response :success
+ assert_template 'new_homework'
+ end
+
+ test ':member by ano' do
+ get :member, {id: 1}
+ assert_response :success
+ assert_template 'member'
+ assert assigns(:members).any?
+ end
+
# test "#index by non-admin user with view_time_entries permission should show overall spent time link" do
# @request.session[:user_id] = 3
From 03b212e363e1c67e2a1c0c88c44429fae731de73 Mon Sep 17 00:00:00 2001
From: z9hang
Date: Wed, 30 Jul 2014 15:26:55 +0800
Subject: [PATCH 3/6] =?UTF-8?q?=E9=A6=96=E9=A1=B5=E5=AE=9A=E5=88=B6?=
=?UTF-8?q?=EF=BC=8C=E6=98=AF=E5=90=A6=E6=98=BE=E7=A4=BA=E8=AF=BE=E7=A8=8B?=
=?UTF-8?q?=EF=BC=8C=E7=AB=9E=E8=B5=9B?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
app/controllers/admin_controller.rb | 1 +
app/controllers/application_controller.rb | 8 ++++++
app/controllers/bids_controller.rb | 19 +++++++++++++
app/controllers/contests_controller.rb | 10 +++++++
app/controllers/courses_controller.rb | 9 +++++-
app/controllers/homework_attach_controller.rb | 9 ++++++
app/controllers/users_controller.rb | 10 ++++++-
app/controllers/welcome_controller.rb | 28 +++++++++++++------
app/helpers/application_helper.rb | 14 +++++-----
app/views/admin/first_page_made.html.erb | 7 +++++
app/views/layouts/_base_header.html.erb | 2 +-
app/views/users/show.html.erb | 4 +--
config/locales/zh.yml | 1 +
config/settings.yml | 4 +++
...730021521_first_page_add_contest_column.rb | 5 ++++
db/schema.rb | 23 +++++++--------
16 files changed, 123 insertions(+), 31 deletions(-)
create mode 100644 db/migrate/20140730021521_first_page_add_contest_column.rb
diff --git a/app/controllers/admin_controller.rb b/app/controllers/admin_controller.rb
index c4a03adcf..aac107cfb 100644
--- a/app/controllers/admin_controller.rb
+++ b/app/controllers/admin_controller.rb
@@ -154,6 +154,7 @@ class AdminController < ApplicationController
@first_page.image_height = params[:image_height]
@first_page.sort_type = params[:sort_type]
@first_page.show_course = params[:show_course]
+ @first_page.show_contest = params[:show_contest]
if @first_page.save
respond_to do |format|
flash[:notice] = l(:notice_successful_update)
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb
index 110974b77..c4b72f584 100644
--- a/app/controllers/application_controller.rb
+++ b/app/controllers/application_controller.rb
@@ -41,6 +41,7 @@ class ApplicationController < ActionController::Base
cookies.delete(autologin_cookie_name)
end
+ before_filter :find_first_page
before_filter :session_expiration, :user_setup, :check_if_login_required, :set_localization
before_filter :user_agent
@@ -720,4 +721,11 @@ class ApplicationController < ActionController::Base
raise RuntimeError, 'unknow type, Please input you type into this helper.'
end
end
+
+ #查找首页相关信息
+ def find_first_page
+ @first_page = FirstPage.where("page_type = 'project'").first
+ @show_course = @first_page.show_course
+ @show_contest = @first_page.show_contest
+ end
end
diff --git a/app/controllers/bids_controller.rb b/app/controllers/bids_controller.rb
index ef0be71ac..49ee47327 100644
--- a/app/controllers/bids_controller.rb
+++ b/app/controllers/bids_controller.rb
@@ -7,6 +7,9 @@ class BidsController < ApplicationController
menu_item :project, :only => [:show_project,:show_results, :new_submit_homework]
menu_item :homework_respond, :only => :homework_respond
menu_item :homework_statistics, :only => :homework_statistics
+
+ before_filter :can_show_course,only: []
+ before_filter :can_show_contest,only: []
#Ended by young
before_filter :find_bid, :only => [:show, :show_project, :create,:destroy,:more,:back,:add,:delete,:new,:show_results,:set_reward, :add_homework, :fork, :create_fork,
:show_course, :show_courseEx,:show_bid_project, :show_bid_user, :join_in_contest, :unjoin_in_contest, :new_join,:show_participator, :settings]
@@ -983,5 +986,21 @@ class BidsController < ApplicationController
render_403 unless currentUser.member_of_course?(@bid.courses.first)
end
+ #验证是否显示课程
+ def can_show_course
+ @first_page = FirstPage.where("page_type = 'project'").first
+ if @first_page.show_course == 2
+ render_404
+ end
+ end
+
+ #验证是否显示竞赛
+ def can_show_contest
+ @first_page = FirstPage.where("page_type = 'project'").first
+ if @first_page.show_contest == 2
+ render_404
+ end
+ end
+
end
diff --git a/app/controllers/contests_controller.rb b/app/controllers/contests_controller.rb
index cf8750b5d..f0597fafb 100644
--- a/app/controllers/contests_controller.rb
+++ b/app/controllers/contests_controller.rb
@@ -7,6 +7,8 @@ class ContestsController < ApplicationController
menu_item :application, :only => :show_softapplication
menu_item :attendingcontests, :only => :show_attendingcontest
menu_item :contestnotifications, :only => :index
+
+ before_filter :can_show_contest,except: []
before_filter :find_contest, :only => [:show_contest, :show_project, :show_softapplication, :show_attendingcontest, :index, :set_reward_project, :set_reward_softapplication, :create,:destroy,:more,:back,:add,:add_softapplication,:new,:show_results, :set_reward,
:show_contest_project, :show_contest_user, :join_in_contest, :unjoin_in_contest, :new_join,:show_participator, :settings]
@@ -645,5 +647,13 @@ end
render_404
end
+ #验证是否显示竞赛
+ def can_show_contest
+ @first_page = FirstPage.where("page_type = 'project'").first
+ if @first_page.show_contest == 2
+ render_404
+ end
+ end
+
end
diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb
index 9db479eb5..59c7733ea 100644
--- a/app/controllers/courses_controller.rb
+++ b/app/controllers/courses_controller.rb
@@ -13,6 +13,7 @@ class CoursesController < ApplicationController
menu_item l(:label_sort_by_active), :only => :index
menu_item l(:label_sort_by_influence), :only => :index
+ before_filter :can_show_course, :except => []
before_filter :find_course, :except => [ :index, :search,:list, :new,:join,:unjoin, :create, :copy, :statistics, :new_join, :course, :enterprise_course, :course_enterprise,:view_homework_attaches]
before_filter :authorize_course, :only => [:show, :settings, :edit, :update, :modules, :close, :reopen, :view_homework_attaches, :course]
before_filter :authorize_course_global, :only => [:view_homework_attaches, :new,:create]
@@ -711,7 +712,13 @@ class CoursesController < ApplicationController
end
end
-
+ #验证是否显示课程
+ def can_show_course
+ @first_page = FirstPage.where("page_type = 'project'").first
+ if @first_page.show_course == 2
+ render_404
+ end
+ end
diff --git a/app/controllers/homework_attach_controller.rb b/app/controllers/homework_attach_controller.rb
index 1cb3fa197..920cd9d4d 100644
--- a/app/controllers/homework_attach_controller.rb
+++ b/app/controllers/homework_attach_controller.rb
@@ -2,6 +2,7 @@ class HomeworkAttachController < ApplicationController
layout "course_base"
include CoursesHelper
###############################
+ before_filter :can_show_course,except: []
#判断当前角色权限时需先找到当前操作的project
before_filter :find_course_by_bid_id, :only => [:new]
before_filter :find_course_by_hoemwork_id, :only => [:edit,:update,:destroy,:show,:add_homework_users,:destory_homework_users]
@@ -352,5 +353,13 @@ class HomeworkAttachController < ApplicationController
}
end
end
+
+ #验证是否显示课程
+ def can_show_course
+ @first_page = FirstPage.where("page_type = 'project'").first
+ if @first_page.show_course == 2
+ render_404
+ end
+ end
end
diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb
index 0e1f46d5a..7220f3ccb 100644
--- a/app/controllers/users_controller.rb
+++ b/app/controllers/users_controller.rb
@@ -29,7 +29,7 @@ class UsersController < ApplicationController
#Ended by young
-
+ before_filter :can_show_course, :only => [:user_courses,:user_homeworks]
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,
@@ -796,4 +796,12 @@ class UsersController < ApplicationController
document_num(@user)
end
+
+ #验证是否显示课程
+ def can_show_course
+ @first_page = FirstPage.where("page_type = 'project'").first
+ if @first_page.show_course == 2
+ render_404
+ end
+ end
end
diff --git a/app/controllers/welcome_controller.rb b/app/controllers/welcome_controller.rb
index 236665b7f..c7cbf217d 100644
--- a/app/controllers/welcome_controller.rb
+++ b/app/controllers/welcome_controller.rb
@@ -18,13 +18,14 @@
class WelcomeController < ApplicationController
include ApplicationHelper
include WelcomeHelper
+
caches_action :robots
# before_filter :fake, :only => [:index, :course]
before_filter :entry_select, :only => [:index]
def index
@first_page = FirstPage.where("page_type = 'project'").first
- @show_course = @first_page.show_course
+ #@show_course = @first_page.show_course
if @first_page.nil? || @first_page.sort_type.nil?
@projects = find_miracle_project(10, 3,"grade desc")
else
@@ -147,16 +148,27 @@ class WelcomeController < ApplicationController
private
# 判断网站的入口,是课程 course 则跳过index去渲染 course 方法
def entry_select
+ @first_page = FirstPage.where("page_type = 'project'").first
url = request.original_url
- if url.include?("course.trustie.net")
- course
- render :course
+ if url.include?(Setting.host_course)
+ if @first_page.show_course == 1
+ course
+ render :course
+ else
+ render_404
+ end
+
return 0
- elsif url.include?("contest.trustie.net")
- contest
- render :contest
+ elsif url.include?(Setting.host_contest)
+ if @first_page.show_contest == 1
+ contest
+ render :contest
+ else
+ render_404
+ end
+
return 0
- elsif url.include?("user.trustie.net")
+ elsif url.include?(Setting.host_user)
redirect_to(:controller => "users", :action => "index")
end
diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb
index 50500b40d..9f8b8fff5 100644
--- a/app/helpers/application_helper.rb
+++ b/app/helpers/application_helper.rb
@@ -1738,18 +1738,18 @@ module ApplicationHelper
#@nav_dispaly_project_label
nav_list = Array.new
- nav_list.push(school_all_school_link) if @nav_dispaly_course_all_label
- nav_list.push(course_all_course_link) if @nav_dispaly_course_all_label
- nav_list.push(course_teacher_all_link) if @nav_dispaly_teacher_all_label
+ nav_list.push(school_all_school_link) if @nav_dispaly_course_all_label && @show_course == 1
+ nav_list.push(course_all_course_link) if @nav_dispaly_course_all_label && @show_course == 1
+ nav_list.push(course_teacher_all_link) if @nav_dispaly_teacher_all_label && @show_course == 1
nav_list.push(main_project_link) if @nav_dispaly_main_project_label
- nav_list.push(main_course_link) if @nav_dispaly_main_course_label
- nav_list.push(main_contest_link) if @nav_dispaly_main_contest_label
+ nav_list.push(main_course_link) if @nav_dispaly_main_course_label && @show_course == 1
+ nav_list.push(main_contest_link) if @nav_dispaly_main_contest_label && @show_contest == 1
- nav_list.push(courses_link) if @nav_dispaly_course_label
+ nav_list.push(courses_link) if @nav_dispaly_course_label && @show_course == 1
nav_list.push(projects_link) if @nav_dispaly_project_label
nav_list.push(users_link) if @nav_dispaly_user_label
- nav_list.push(contest_link) if @nav_dispaly_contest_label
+ nav_list.push(contest_link) if @nav_dispaly_contest_label && @show_contest == 1
nav_list.push(bids_link) if @nav_dispaly_bid_label
nav_list.push(forum_link) if @nav_dispaly_forum_label
nav_list.push(stores_link) if @nav_dispaly_store_all_label
diff --git a/app/views/admin/first_page_made.html.erb b/app/views/admin/first_page_made.html.erb
index 601b2b8d8..8cb5b3716 100644
--- a/app/views/admin/first_page_made.html.erb
+++ b/app/views/admin/first_page_made.html.erb
@@ -34,6 +34,13 @@
+
+
+
+