From bff3cefbc79e15a09a8525056db36393ee920319 Mon Sep 17 00:00:00 2001 From: "Matthew K. Fu JuYuan" Date: Tue, 1 May 2012 16:05:05 +0800 Subject: [PATCH] Apply app_auth to ad_banner. From now,ad_banner can only be viewed for at least manager. --- app/controllers/admin/ad_banners_controller.rb | 4 ++-- app/controllers/application_controller.rb | 3 ++- app/helpers/application_helper.rb | 9 +++++++++ app/views/layouts/_side_bar.html.erb | 12 +++++++----- 4 files changed, 20 insertions(+), 8 deletions(-) diff --git a/app/controllers/admin/ad_banners_controller.rb b/app/controllers/admin/ad_banners_controller.rb index a21693aa..47d3d355 100644 --- a/app/controllers/admin/ad_banners_controller.rb +++ b/app/controllers/admin/ad_banners_controller.rb @@ -1,7 +1,7 @@ -class Admin::AdBannersController < ApplicationController +class Admin::AdBannersController < OrbitBackendController layout "new_admin" before_filter :authenticate_user! - before_filter :is_admin? + before_filter :for_app_manager def destroy @ad_banner = AdBanner.find(params[:id]) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 8fc3a90b..ab01ea6b 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -40,7 +40,8 @@ class ApplicationController < ActionController::Base end def auth_failed_in_backend - redirect_to admin_dashboards_url + #redirect_to admin_dashboards_url + redirect_to root_path end # Check if the current_user is admin diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 682799eb..1839cf66 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -74,6 +74,15 @@ module ApplicationHelper end end + def active_sys_call_for_app(controller_name,action_name,app_title) + unless active_for_action(controller_name,action_name).nil? + app = ModuleApp.find params[:id] + app.title == app_title ? 'active' : nil + else + nil + end + end + def active_for_controllers(*controller_names) (controller_names.include?(controller.controller_name) || controller_names.include?(request.fullpath)) ? 'active' : nil end diff --git a/app/views/layouts/_side_bar.html.erb b/app/views/layouts/_side_bar.html.erb index dd8ffa83..41416bc4 100644 --- a/app/views/layouts/_side_bar.html.erb +++ b/app/views/layouts/_side_bar.html.erb @@ -5,7 +5,7 @@ <%= javascript_include_tag "/static/kernel.js" %> <% end %> -<%= content_tag :li, :class => active_for_controllers('bulletins', '/panel/announcement/back_end/tags', 'bulletin_categorys','module_apps', 'approvals') do -%> +<%= content_tag :li, :class => active_for_controllers('bulletins', '/panel/announcement/back_end/tags', 'bulletin_categorys', 'approvals') || active_sys_call_for_app('module_apps','edit','Announcement') do -%> <%= link_to content_tag(:i, nil, :class => 'icons-announcement') + t('admin.announcement'), panel_announcement_back_end_bulletins_path %> <%= content_tag :ul, :class => ("nav nav-list " + visible_for_controllers('bulletins', '/panel/announcement/back_end/tags', 'bulletin_categorys', 'approvals')) do -%> <%= content_tag :li, link_to(t('announcement.all_articles'), panel_announcement_back_end_bulletins_path), :class => active_for_action('bulletins', 'index') %> @@ -13,7 +13,7 @@ <%= content_tag :li, link_to(t('announcement.categories'), panel_announcement_back_end_bulletin_categorys_path), :class => active_for_action('bulletin_categorys', 'index') %> <%= content_tag :li, link_to(t('announcement.tags'), panel_announcement_back_end_tags_path), :class => active_for_action('/panel/announcement/back_end/tags', 'index') %> <%= content_tag :li, link_to(t('announcement.bulletin.approval_setting'), panel_announcement_back_end_approval_setting_path), :class => active_for_action('approvals', 'setting') if (is_manager? rescue nil) %> - <%= content_tag :li, link_to(t('admin.module.authorization'),edit_admin_module_app_path(ModuleApp.first(conditions: {title: "Announcement"}))), :class => active_for_action('module_apps', 'edit') if (is_admin? rescue nil) %> + <%= content_tag :li, link_to(t('admin.module.authorization'),edit_admin_module_app_path(ModuleApp.first(conditions: {title: "Announcement"}))), :class => active_sys_call_for_app('module_apps','edit','Announcement') if (is_admin? rescue nil) %> <% end -%> @@ -46,13 +46,15 @@ <%= link_to content_tag(:i, nil, :class => 'icons-window-block') + t('admin.design'), admin_designs_path %> <% end -%> -<%= content_tag :li, :class => active_for_controllers('ad_banners', 'ad_images') do -%> +<%= content_tag :li, :class => active_for_controllers('ad_banners', 'ad_images') || active_sys_call_for_app('module_apps','edit','ad_banners') do -%> <%= link_to content_tag(:i, nil, :class => 'icons-link') + t('admin.ad_banner'), admin_ad_banners_path %> - <%#= content_tag :ul, :class => ("nav nav-list " + visible_for_controllers('ad_banners', 'ad_images')) do -%> + + <%= content_tag :ul, :class => ("nav nav-list " + visible_for_controllers('ad_banners', 'ad_images') ) do -%> <%#= content_tag :li, link_to(t('admin.ad.all_banners'), admin_ad_banners_path), :class => active_for_action('ad_banners', 'index') %> <%#= content_tag :li, link_to(t('admin.ad.new_banner'), new_admin_ad_banner_path), :class => active_for_action('ad_banners', 'new') %> <%#= content_tag :li, link_to(t('admin.ad.new_image'), new_ad_image_admin_ad_banners_path), :class => active_for_action('ad_images', 'new') %> - <%# end %> + <%= content_tag :li, link_to(t('admin.module.authorization'),edit_admin_module_app_path(ModuleApp.first(conditions: {title: "ad_banners"}))), :class => active_sys_call_for_app('module_apps','edit','ad_banners') if (is_admin? rescue nil) %> + <% end -%> <% end %> <%= content_tag :li, :class => active_for_controllers('web_links', '/panel/web_resource/back_end/tags', 'web_link_categorys') do -%>