diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index e91b17212..46000427b 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -379,7 +379,9 @@ class ProjectsController < ApplicationController def settings # 顶部导航 @project_menu_type = 10 - + if @project.is_child_training_project? + return render_404 + end # 修改查看消息状态 applied_messages = ForgeMessage.where("user_id =? and project_id =? and forge_message_type =? and viewed =?", User.current.id, @project, "AppliedProject", 0) applied_messages.update_all(:viewed => true) diff --git a/app/helpers/projects_helper.rb b/app/helpers/projects_helper.rb index c87cdcca5..a7fef3dd7 100644 --- a/app/helpers/projects_helper.rb +++ b/app/helpers/projects_helper.rb @@ -544,7 +544,7 @@ module ProjectsHelper result = "manage_versions" elsif user.allowed_to?(:manage_repository, @project) result = "manage_repository" - elsif user.admin? + elsif is_project_manager?(user.id, @project.id) result = "training_task" end result diff --git a/app/models/project.rb b/app/models/project.rb index 1421ebc8e..cd8ea3d7b 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -160,6 +160,7 @@ class Project < ActiveRecord::Base after_create :create_board_sync,:acts_as_forge_activities, :create_project_ealasticsearch_index before_destroy :delete_all_members,:delete_project_ealasticsearch_index after_update :update_project_ealasticsearch_index + def remove_references_before_destroy return if self.id.nil? Watcher.delete_all ['watchable_id = ?', id] @@ -194,6 +195,7 @@ class Project < ActiveRecord::Base scope :project_entities, -> { where(project_type: ProjectType_project) } scope :course_entities, -> { where(project_type: ProjectType_course) } scope :indexable,lambda { where('is_public = 1')} #用于elastic建索引的scope + def self.search(query) __elasticsearch__.search( { @@ -220,6 +222,17 @@ class Project < ActiveRecord::Base } ) end + + # 判断项目是否为实训项目 + def is_training_project? + (self.enabled_modules.where("name = 'training_tasks'").empty? && self.training_status == 0) ? false : true + end + + # 判断项目是否为开启实训的项目(eg:学生开启实训) + def is_child_training_project? + self.training_status == 1 ? true :false + end + def new_course self.where('project_type = ?', 1) end diff --git a/app/views/layouts/_base_project_top.html.erb b/app/views/layouts/_base_project_top.html.erb index 0c59da6cf..8c8c2bdb7 100644 --- a/app/views/layouts/_base_project_top.html.erb +++ b/app/views/layouts/_base_project_top.html.erb @@ -15,9 +15,12 @@ -
- -
+ <% if !@project.is_child_training_project? %> +
+ +
+ <% end %> +
<% unless @project.forked_from_project_id.nil? %>
@@ -87,7 +90,7 @@ <% end %> - <% if User.current.admin? || User.current.allowed_to?({:controller => 'projects', :action => 'settings'}, @project) %> + <% if (User.current.admin? || User.current.allowed_to?({:controller => 'projects', :action => 'settings'}, @project)) && !@project.is_child_training_project? %>
  • <%= link_to "#{l(:button_configure)}", settings_project_path(@project), :class => "pro_new_proname" %>
  • diff --git a/app/views/projects/_invite_code.html.erb b/app/views/projects/_invite_code.html.erb index 94a2d1ea5..03591034a 100644 --- a/app/views/projects/_invite_code.html.erb +++ b/app/views/projects/_invite_code.html.erb @@ -1,5 +1,5 @@

    项目简介 -<% if User.current.member_of?(@project) %> +<% if User.current.member_of?(@project) && !@project.is_child_training_project? %> 邀请码:<%= @project.invite_code %> <% end %>

    \ No newline at end of file diff --git a/app/views/projects/settings.html.erb b/app/views/projects/settings.html.erb index 6685f1e4f..21f5e2ecd 100644 --- a/app/views/projects/settings.html.erb +++ b/app/views/projects/settings.html.erb @@ -55,7 +55,7 @@
    - <%= render :partial=>"projects/settings/new_trainig_task" if User.current.admin? %> + <%= render :partial=>"projects/settings/new_trainig_task" if is_project_manager?(User.current.id, @project.id) %>
    diff --git a/app/views/projects/settings/_new_trainig_task.html.erb b/app/views/projects/settings/_new_trainig_task.html.erb index e92c42006..7db7d8518 100644 --- a/app/views/projects/settings/_new_trainig_task.html.erb +++ b/app/views/projects/settings/_new_trainig_task.html.erb @@ -7,11 +7,8 @@ 取消 确定 - -

    请输入脚本

    -

    <%= link_to "开启实训", training_project_execute_project_path(@project) %>

    - +