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 @@

+

+ + +