From 0e8b1d5ee8c5b4a8bbc3ba5eacdc96252b6281c2 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Wed, 3 Apr 2019 18:21:25 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=A2=E6=88=B7=E5=88=97=E8=A1=A8=E8=B0=83?= =?UTF-8?q?=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/cooperates_controller.rb | 18 +++++++++++++++++- app/views/layouts/_logined_header.html.erb | 3 +++ config/routes.rb | 3 +-- 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/app/controllers/cooperates_controller.rb b/app/controllers/cooperates_controller.rb index 09895193..8a014d62 100644 --- a/app/controllers/cooperates_controller.rb +++ b/app/controllers/cooperates_controller.rb @@ -1,8 +1,11 @@ class CooperatesController < ApplicationController + before_filter :require_login + before_filter :find_partner, only: [:partner_list] + before_filter :is_admin, only: [:partner_list] def partner_list search = params[:search] - @schools = School.where(id: [117, 179, 3181, 3216]) + @schools = School.where(customer_id: @partner.customer_ids) @all_count = @schools.size unless search.blank? @@ -17,4 +20,17 @@ class CooperatesController < ApplicationController format.html{render :layout => "base_edu"} end end + + def find_partner + @partner = Partner.find_by_id(params[:id]) + render_404 if @partner.nil? || @partner.status == -1 + rescue ActiveRecord::RecordNotFound + render_404 + end + + def is_admin + unless User.current.admin? || (User.current.partner.present? && User.current.partner == @partner) + render_403 + end + end end diff --git a/app/views/layouts/_logined_header.html.erb b/app/views/layouts/_logined_header.html.erb index 9c8f4a8d..9e07db32 100644 --- a/app/views/layouts/_logined_header.html.erb +++ b/app/views/layouts/_logined_header.html.erb @@ -52,6 +52,9 @@
  • <%= link_to '我的课堂', user_path(User.current) %>
  • <%= link_to '我的实训', user_path(User.current, :type => 'a_shixun') %>
  • <%= link_to '我的实训课程', user_path(User.current, :type => 'a_path') %>
  • + <% if User.current.partner.present? %> +
  • <%= link_to '客户管理', partner_list_cooperate_path(User.current.partner) %>
  • + <% end %>
  • <%= link_to '我的项目', user_path(User.current, :type => 'a_project') %>
  • 客户管理
  • diff --git a/config/routes.rb b/config/routes.rb index 1df8d0d6..57410238 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -42,11 +42,10 @@ RedmineApp::Application.routes.draw do ## oauth相关 resources :cooperates do member do - + get 'partner_list' end collection do - get 'partner_list' end end