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