From 0a9f0bcc45521663b20f2232323cea9080917a03 Mon Sep 17 00:00:00 2001 From: "Matthew K. Fu JuYuan" Date: Tue, 15 May 2012 09:57:05 +0800 Subject: [PATCH 1/6] starting ad_banner auth --- app/helpers/admin/ad_banner_helper.rb | 10 ++++++++++ app/models/ad_banner.rb | 4 ++-- app/views/admin/ad_banners/_ad_banner_tab.html.erb | 3 +++ config/locales/zh_tw.yml | 1 + .../panel/announcement/back_end/bulletins_helper.rb | 2 +- 5 files changed, 17 insertions(+), 3 deletions(-) diff --git a/app/helpers/admin/ad_banner_helper.rb b/app/helpers/admin/ad_banner_helper.rb index eff12427..f21c5e73 100644 --- a/app/helpers/admin/ad_banner_helper.rb +++ b/app/helpers/admin/ad_banner_helper.rb @@ -12,5 +12,15 @@ module Admin::AdBannerHelper printable_ad_images.shuffle! end + def show_ad_banner_permission_link(ad_banner) + type = 'edit' + oa = ad_banner.get_object_auth_by_title(type) + if oa.nil? + ad_banner.object_auths.new(title: type ).save + oa = ad_banner.get_object_auth_by_title(type) + end +# link_to t('announcement.bulletin.cate_auth'), edit_admin_object_auth_path(oa) + link_to t('admin.ad.cate_auth'),admin_object_auth_ob_auth_path(oa) + end end \ No newline at end of file diff --git a/app/models/ad_banner.rb b/app/models/ad_banner.rb index e1013c2f..6163a81f 100644 --- a/app/models/ad_banner.rb +++ b/app/models/ad_banner.rb @@ -1,9 +1,9 @@ class AdBanner - include OrbitCoreLib::ObjectAuthable include Mongoid::Document include Mongoid::Timestamps include Mongoid::MultiParameterAttributes - + include OrbitCoreLib::ObjectAuthable + field :title field :transition_msec,type: Integer field :ad_fx #TODO Design should explain diff --git a/app/views/admin/ad_banners/_ad_banner_tab.html.erb b/app/views/admin/ad_banners/_ad_banner_tab.html.erb index 797624ff..7074717f 100644 --- a/app/views/admin/ad_banners/_ad_banner_tab.html.erb +++ b/app/views/admin/ad_banners/_ad_banner_tab.html.erb @@ -20,6 +20,9 @@ + <% if is_manager? || is_admin? %> + <%= show_ad_banner_permission_link ad_banner_tab%> + <% end -%> <%#= render :partial => 'new_add_banner_file', :object => ad_banner_tab.ad_images.build, :locals => { :field_name => "new_ad_images[]", :f => f, :classes => "r_destroy" } %> <% end -%> diff --git a/config/locales/zh_tw.yml b/config/locales/zh_tw.yml index 7c2ac289..a27f67bc 100644 --- a/config/locales/zh_tw.yml +++ b/config/locales/zh_tw.yml @@ -76,6 +76,7 @@ zh_tw: sec_place_holder: 3秒請輸入3 ab_fx: 轉場特效 all_banners: 輪播清單 + cate_auth: 分類授權 banner_best_size: Banner 尺寸 new_banner: 新增輪播 new_image: 新增橫幅 diff --git a/vendor/built_in_modules/announcement/app/helpers/panel/announcement/back_end/bulletins_helper.rb b/vendor/built_in_modules/announcement/app/helpers/panel/announcement/back_end/bulletins_helper.rb index 8e6b9bff..68286c3e 100644 --- a/vendor/built_in_modules/announcement/app/helpers/panel/announcement/back_end/bulletins_helper.rb +++ b/vendor/built_in_modules/announcement/app/helpers/panel/announcement/back_end/bulletins_helper.rb @@ -2,7 +2,7 @@ module Panel::Announcement::BackEnd::BulletinsHelper def show_approval_link(bulletin) by_bulletin = (!bulletin.is_expired? and !bulletin.is_checked?) - by_user = (bulletin.bulletin_category.authed_users('fact_check').include?(current_user) or is_manager?) + by_user = (bulletin.bulletin_category.authed_users('fact_check').include?(current_user) or is_manager? or is_admin?) by_bulletin and by_user end From b23b5e8ec5142ed86d1fdbe89896f82f9816edb3 Mon Sep 17 00:00:00 2001 From: "Matthew K. Fu JuYuan" Date: Tue, 15 May 2012 16:39:23 +0800 Subject: [PATCH 2/6] Object auth for ad_banner --- .../admin/ad_banners_controller.rb | 3 ++- .../module_apps_new_interface_controller.rb | 3 ++- app/helpers/admin/ad_banner_helper.rb | 11 +++++++++-- app/models/object_auth.rb | 2 ++ .../admin/ad_banners/_ad_banner_tab.html.erb | 19 +++++++++++-------- .../ad_banners/_ad_image_update.html.erb | 10 ++++++---- config/locales/en.yml | 1 + config/locales/zh_tw.yml | 1 + 8 files changed, 34 insertions(+), 16 deletions(-) diff --git a/app/controllers/admin/ad_banners_controller.rb b/app/controllers/admin/ad_banners_controller.rb index 47d3d355..3457c4de 100644 --- a/app/controllers/admin/ad_banners_controller.rb +++ b/app/controllers/admin/ad_banners_controller.rb @@ -1,7 +1,8 @@ class Admin::AdBannersController < OrbitBackendController layout "new_admin" before_filter :authenticate_user! - before_filter :for_app_manager + before_filter :for_app_manager,:except => [:index,:show] + before_filter :for_app_sub_manager def destroy @ad_banner = AdBanner.find(params[:id]) diff --git a/app/controllers/admin/module_apps_new_interface_controller.rb b/app/controllers/admin/module_apps_new_interface_controller.rb index 52292588..83aa0d79 100644 --- a/app/controllers/admin/module_apps_new_interface_controller.rb +++ b/app/controllers/admin/module_apps_new_interface_controller.rb @@ -37,8 +37,9 @@ class Admin::ModuleAppsNewInterfaceController < ApplicationController protected def update_setting_by_params + user_sat = [] ma = ModuleApp.find params[:module_app][:id] - user_sat = User.find params[:users].keys + user_sat = User.find params[:users].keys if params.has_key? :users users_to_new = user_sat - ma.managing_users users_to_remove = ma.managing_users - user_sat diff --git a/app/helpers/admin/ad_banner_helper.rb b/app/helpers/admin/ad_banner_helper.rb index f21c5e73..bfebc1b9 100644 --- a/app/helpers/admin/ad_banner_helper.rb +++ b/app/helpers/admin/ad_banner_helper.rb @@ -11,7 +11,10 @@ module Admin::AdBannerHelper printable_ad_images.shuffle! end - + def sub_manager?(ad_banner) + ad_banner.authed_users(:edit).include?(current_user) + end + def show_ad_banner_permission_link(ad_banner) type = 'edit' oa = ad_banner.get_object_auth_by_title(type) @@ -20,7 +23,11 @@ module Admin::AdBannerHelper oa = ad_banner.get_object_auth_by_title(type) end # link_to t('announcement.bulletin.cate_auth'), edit_admin_object_auth_path(oa) - link_to t('admin.ad.cate_auth'),admin_object_auth_ob_auth_path(oa) + link_to t('admin.ad.cate_auth'),admin_object_auth_ob_auth_path(oa),:class => "btn btn-warning" end + def at_least_module_manager + is_manager? || is_admin? + end + end \ No newline at end of file diff --git a/app/models/object_auth.rb b/app/models/object_auth.rb index d1c1c673..0ac3de41 100644 --- a/app/models/object_auth.rb +++ b/app/models/object_auth.rb @@ -11,6 +11,8 @@ class ObjectAuth < PrototypeAuth end def check_user_has_app_auth +debugger + a=1 sub_managing_users = auth_obj.app_auth.sub_managing_users app_auth = auth_obj.app_auth self.auth_users.each do |auth_user| diff --git a/app/views/admin/ad_banners/_ad_banner_tab.html.erb b/app/views/admin/ad_banners/_ad_banner_tab.html.erb index 7074717f..a9e07ec2 100644 --- a/app/views/admin/ad_banners/_ad_banner_tab.html.erb +++ b/app/views/admin/ad_banners/_ad_banner_tab.html.erb @@ -1,5 +1,5 @@
" id=<%= ad_banner_tab.title.dehumanize %>> - +<% if at_least_module_manager || sub_manager?(ad_banner_tab)%> <%= form_for ad_banner_tab,:url=> admin_ad_banner_path(ad_banner_tab),:method => :put,:class=>"input-medium" do |f| -%>
@@ -11,20 +11,23 @@ <%= f.submit t("admin.ad.update_banner"), :class => 'btn' %> <%= f.submit t("cancel"),:type=>'reset', :class => 'btn' %>
-

圖片列表

+ <% end -%> +<% end -%> +

<%= t("admin.ad.picture_list")%>

-
- <%= link_to t("admin.ad.new_image"),new_admin_ad_banner_ad_image_path(ad_banner_tab) ,:class => "btn btn-primary"%> - <%= link_to t("modal.preview"), admin_realtime_preview_ad_banner_path(ad_banner_tab.id) , :class=>'preview_trigger btn btn-success'%> -
+ <%if at_least_module_manager || sub_manager?(ad_banner_tab)%> + <%= content_tag :div ,:class=>'adbanner-action' do%> + <%= link_to t("admin.ad.new_image"),new_admin_ad_banner_ad_image_path(ad_banner_tab) ,:class => "btn btn-primary"%> + <%= link_to t("modal.preview"), admin_realtime_preview_ad_banner_path(ad_banner_tab.id) , :class=>'preview_trigger btn btn-success'%> + <% end -%> + <% end -%>
    <%= render :partial => "ad_image_update", :collection => ad_banner_tab.ad_images,:as => :ad_image,:locals=>{:ad_banner => ad_banner_tab} %>
- <% if is_manager? || is_admin? %> + <% if at_least_module_manager %> <%= show_ad_banner_permission_link ad_banner_tab%> <% end -%> <%#= render :partial => 'new_add_banner_file', :object => ad_banner_tab.ad_images.build, :locals => { :field_name => "new_ad_images[]", :f => f, :classes => "r_destroy" } %>
- <% end -%> <%#= render :partial => 'preview_block',:locals=> {:ad_banner =>ad_banner_tab} %>
diff --git a/app/views/admin/ad_banners/_ad_image_update.html.erb b/app/views/admin/ad_banners/_ad_image_update.html.erb index c055a8c9..0b4277a0 100644 --- a/app/views/admin/ad_banners/_ad_image_update.html.erb +++ b/app/views/admin/ad_banners/_ad_image_update.html.erb @@ -4,8 +4,10 @@ <%= ad_image.display? ? "[#{t('admin.ad.showing')}]" : "[#{t('admin.ad.not_showing')}]" %> <%= "#{ad_image.post_date ||'NeedReset' }~#{ad_image.unpost_date || 'NeedReset'}" %>

-

- <%= link_to t('edit'),edit_admin_ad_banner_ad_image_path(ad_banner,ad_image),:class => 'btn btn-primary' %> - <%= link_to t('delete'),admin_ad_banner_ad_image_path(ad_banner,ad_image),:class => 'btn',:method => :delete,:confirm => t('sure?') %> -

+ <%if at_least_module_manager || sub_manager?(ad_image.ad_banner) %> +

+ <%= link_to t('edit'),edit_admin_ad_banner_ad_image_path(ad_banner,ad_image),:class => 'btn btn-primary' %> + <%= link_to t('delete'),admin_ad_banner_ad_image_path(ad_banner,ad_image),:class => 'btn',:method => :delete,:confirm => t('sure?') %> +

+ <% end -%> \ No newline at end of file diff --git a/config/locales/en.yml b/config/locales/en.yml index 374b3b33..595b5172 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -87,6 +87,7 @@ en: new_image: New image showing: Showing not_showing: NotShowing + picture_list: Picture List title: Title transition_sec: Transition time trans_unit_sec: sec diff --git a/config/locales/zh_tw.yml b/config/locales/zh_tw.yml index a27f67bc..fbae7ee3 100644 --- a/config/locales/zh_tw.yml +++ b/config/locales/zh_tw.yml @@ -82,6 +82,7 @@ zh_tw: new_image: 新增橫幅 showing: 顯示中 not_showing: 沒有顯示 + picture_list: 圖片列表 title: 標題 transition_sec: 轉場單位時間 trans_unit_sec: 秒 From 3f744dab0573be5cd9b3fb3ec0fead3224e7ff08 Mon Sep 17 00:00:00 2001 From: "Matthew K. Fu JuYuan" Date: Tue, 15 May 2012 18:55:16 +0800 Subject: [PATCH 3/6] First version of app and object auth for web_resource module. Basic fund is ok. backend need to be secued --- .../object_auths_new_interface_controller.rb | 1 - app/controllers/orbit_backend_controller.rb | 2 ++ app/helpers/admin/ad_banner_helper.rb | 8 +++----- app/helpers/admin/web_link_helper.rb | 11 +++++++++++ app/helpers/application_helper.rb | 4 ++++ app/models/object_auth.rb | 4 +--- .../admin/ad_banners/_ad_banner_tab.html.erb | 2 +- app/views/layouts/_side_bar.html.erb | 5 +++-- lib/orbit_core_lib.rb | 4 ++++ .../web_resource/back_end/web_links_controller.rb | 4 ++-- .../web_resource/app/models/web_link_category.rb | 11 ++++++++++- .../_web_link_category.html.erb | 15 +++++++++------ .../back_end/web_link_categorys/index.html.erb | 2 +- .../back_end/web_links/_web_link.html.erb | 2 ++ 14 files changed, 53 insertions(+), 22 deletions(-) create mode 100644 app/helpers/admin/web_link_helper.rb diff --git a/app/controllers/admin/object_auths_new_interface_controller.rb b/app/controllers/admin/object_auths_new_interface_controller.rb index 6c33ff71..f9191145 100644 --- a/app/controllers/admin/object_auths_new_interface_controller.rb +++ b/app/controllers/admin/object_auths_new_interface_controller.rb @@ -3,7 +3,6 @@ class Admin::ObjectAuthsNewInterfaceController < OrbitBackendController layout "new_admin" before_filter :force_order - layout "new_admin" def setting diff --git a/app/controllers/orbit_backend_controller.rb b/app/controllers/orbit_backend_controller.rb index cfa46847..e27e5b00 100644 --- a/app/controllers/orbit_backend_controller.rb +++ b/app/controllers/orbit_backend_controller.rb @@ -1,6 +1,8 @@ class OrbitBackendController< ApplicationController before_filter :force_order,:except => [:public] before_filter :setup_vars + before_filter :set_current_user + # before_filter {|c| c.front_end_available(@app_title)} # before_filter :check_user_can_use include OrbitCoreLib::PermissionUnility diff --git a/app/helpers/admin/ad_banner_helper.rb b/app/helpers/admin/ad_banner_helper.rb index bfebc1b9..ecba9b3b 100644 --- a/app/helpers/admin/ad_banner_helper.rb +++ b/app/helpers/admin/ad_banner_helper.rb @@ -16,8 +16,8 @@ module Admin::AdBannerHelper end def show_ad_banner_permission_link(ad_banner) - type = 'edit' - oa = ad_banner.get_object_auth_by_title(type) + type = 'edit' + oa = ad_banner.get_object_auth_by_title(type) if oa.nil? ad_banner.object_auths.new(title: type ).save oa = ad_banner.get_object_auth_by_title(type) @@ -26,8 +26,6 @@ module Admin::AdBannerHelper link_to t('admin.ad.cate_auth'),admin_object_auth_ob_auth_path(oa),:class => "btn btn-warning" end - def at_least_module_manager - is_manager? || is_admin? - end + end \ No newline at end of file diff --git a/app/helpers/admin/web_link_helper.rb b/app/helpers/admin/web_link_helper.rb new file mode 100644 index 00000000..813bc48c --- /dev/null +++ b/app/helpers/admin/web_link_helper.rb @@ -0,0 +1,11 @@ +module Admin::WebLinkHelper + def show_web_link_permission_link(web_link) + type = 'edit' + oa = web_link.get_object_auth_by_title(type) + if oa.nil? + web_link.object_auths.new(title: type ).save + oa = web_link.get_object_auth_by_title(type) + end + link_to t('admin.web_link.cate_auth'),admin_object_auth_ob_auth_path(oa) + end +end \ No newline at end of file diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index d04d8c59..2c5517e4 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -173,4 +173,8 @@ module ApplicationHelper locale.to_sym == I18n.locale ? 'active in': '' end + def at_least_module_manager + is_manager? || is_admin? + end + end diff --git a/app/models/object_auth.rb b/app/models/object_auth.rb index 0ac3de41..d5cc48de 100644 --- a/app/models/object_auth.rb +++ b/app/models/object_auth.rb @@ -11,9 +11,7 @@ class ObjectAuth < PrototypeAuth end def check_user_has_app_auth -debugger - a=1 - sub_managing_users = auth_obj.app_auth.sub_managing_users + sub_managing_users = auth_obj.app_auth.sub_managing_users rescue [] app_auth = auth_obj.app_auth self.auth_users.each do |auth_user| if !sub_managing_users.include? auth_user && !auth_user.admin? diff --git a/app/views/admin/ad_banners/_ad_banner_tab.html.erb b/app/views/admin/ad_banners/_ad_banner_tab.html.erb index a9e07ec2..56fd09a1 100644 --- a/app/views/admin/ad_banners/_ad_banner_tab.html.erb +++ b/app/views/admin/ad_banners/_ad_banner_tab.html.erb @@ -15,7 +15,7 @@ <% end -%>

<%= t("admin.ad.picture_list")%>

- <%if at_least_module_manager || sub_manager?(ad_banner_tab)%> + <%if (at_least_module_manager || ad_banner_tab.cur_user_is_sub_manager_of(:edit) )%> <%= content_tag :div ,:class=>'adbanner-action' do%> <%= link_to t("admin.ad.new_image"),new_admin_ad_banner_ad_image_path(ad_banner_tab) ,:class => "btn btn-primary"%> <%= link_to t("modal.preview"), admin_realtime_preview_ad_banner_path(ad_banner_tab.id) , :class=>'preview_trigger btn btn-success'%> diff --git a/app/views/layouts/_side_bar.html.erb b/app/views/layouts/_side_bar.html.erb index 7a9bcf4e..2b6d75c0 100644 --- a/app/views/layouts/_side_bar.html.erb +++ b/app/views/layouts/_side_bar.html.erb @@ -54,16 +54,17 @@ <%#= 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') %> - <%= content_tag :li, link_to(t('admin.module.authorization'),admin_module_app_manager_auth_proc_path(ModuleApp.first(conditions: {title: "ad_banners"}))), :class => active_for_app_auth('ad_banners') if (is_admin? rescue nil) %> + <%= content_tag :li, link_to(t('admin.module.authorization'),admin_module_app_manager_auth_proc_path(ModuleApp.first(conditions: {title: "ad_banners"}))), :class => active_for_app_auth('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 -%> +<%= content_tag :li, :class => active_for_controllers('web_links', '/panel/web_resource/back_end/tags', 'web_link_categorys') || active_for_app_auth('web_resource') do -%> <%= link_to content_tag(:i, nil, :class => 'icons-link') + t('admin.link'), panel_web_resource_back_end_web_links_path %> <%= content_tag :ul, :class => ("nav nav-list " + visible_for_controllers('web_links', '/panel/web_resource/back_end/tags', 'web_link_categorys')) do -%> <%= content_tag :li, link_to(t('admin.all_articles'), panel_web_resource_back_end_web_links_path), :class => active_for_action('web_links', 'index') %> <%= content_tag :li, link_to(t('announcement.add_new'), new_panel_web_resource_back_end_web_link_path), :class => active_for_action('web_links', 'new') %> <%= content_tag :li, link_to(t('announcement.categories'), panel_web_resource_back_end_web_link_categorys_path), :class => active_for_action('web_link_categorys', 'index') %> <%= content_tag :li, link_to(t('announcement.tags'), panel_web_resource_back_end_tags_path), :class => active_for_action('/panel/web_resource/back_end/tags', 'index') %> + <%= content_tag :li, link_to(t('admin.module.authorization'),admin_module_app_manager_auth_proc_path(ModuleApp.first(conditions: {title: "web_resource"}))), :class => active_for_app_auth('web_resource') if (is_admin? rescue nil) %> <% end -%> <% end -%> diff --git a/lib/orbit_core_lib.rb b/lib/orbit_core_lib.rb index a6c9917f..ad4f6756 100644 --- a/lib/orbit_core_lib.rb +++ b/lib/orbit_core_lib.rb @@ -19,6 +19,10 @@ module OrbitCoreLib end + def cur_user_is_sub_manager_of(title) + authed_users(title).include?(User.current) + end + def app_auth ModuleApp.first(conditions: {:title => self.class::APP_NAME} ) end diff --git a/vendor/built_in_modules/web_resource/app/controllers/panel/web_resource/back_end/web_links_controller.rb b/vendor/built_in_modules/web_resource/app/controllers/panel/web_resource/back_end/web_links_controller.rb index 69aa8c1a..323b92fc 100644 --- a/vendor/built_in_modules/web_resource/app/controllers/panel/web_resource/back_end/web_links_controller.rb +++ b/vendor/built_in_modules/web_resource/app/controllers/panel/web_resource/back_end/web_links_controller.rb @@ -1,7 +1,7 @@ class Panel::WebResource::BackEnd::WebLinksController < OrbitBackendController - before_filter :authenticate_user! - before_filter :is_admin? + # before_filter :for_app_manager,:except => [:index,:show] + # before_filter :for_app_sub_manager def index diff --git a/vendor/built_in_modules/web_resource/app/models/web_link_category.rb b/vendor/built_in_modules/web_resource/app/models/web_link_category.rb index c2a95f4b..f9ef5989 100644 --- a/vendor/built_in_modules/web_resource/app/models/web_link_category.rb +++ b/vendor/built_in_modules/web_resource/app/models/web_link_category.rb @@ -3,12 +3,21 @@ class WebLinkCategory include Mongoid::Document include Mongoid::Timestamps + include OrbitCoreLib::ObjectAuthable + # include Mongoid::MultiParameterAttributes - + AfterObjectAuthUrl = '/panel/page_content/back_end/page_contexts' + APP_NAME = 'web_resource' + ObjectAuthTitlesOptions = %W{edit} + field :key has_one :i18n_variable, :as => :language_value, :autosave => true, :dependent => :destroy has_many :web_links + def pp_object + i18n_variable[I18n.locale] + end + end \ No newline at end of file diff --git a/vendor/built_in_modules/web_resource/app/views/panel/web_resource/back_end/web_link_categorys/_web_link_category.html.erb b/vendor/built_in_modules/web_resource/app/views/panel/web_resource/back_end/web_link_categorys/_web_link_category.html.erb index 9d43b94c..b17e634b 100644 --- a/vendor/built_in_modules/web_resource/app/views/panel/web_resource/back_end/web_link_categorys/_web_link_category.html.erb +++ b/vendor/built_in_modules/web_resource/app/views/panel/web_resource/back_end/web_link_categorys/_web_link_category.html.erb @@ -3,12 +3,15 @@ <%= web_link_category.key %> -
- -
+ <%if at_least_module_manager %> +
+ +
+ <% end -%> <% @site_valid_locales.each do |locale| %> <%= web_link_category.i18n_variable[locale] rescue nil %> diff --git a/vendor/built_in_modules/web_resource/app/views/panel/web_resource/back_end/web_link_categorys/index.html.erb b/vendor/built_in_modules/web_resource/app/views/panel/web_resource/back_end/web_link_categorys/index.html.erb index 87defb11..4a2e8c59 100644 --- a/vendor/built_in_modules/web_resource/app/views/panel/web_resource/back_end/web_link_categorys/index.html.erb +++ b/vendor/built_in_modules/web_resource/app/views/panel/web_resource/back_end/web_link_categorys/index.html.erb @@ -34,6 +34,6 @@ -
<%= render :partial => "form" %>
+
<%= render :partial => "form" if at_least_module_manager%>
diff --git a/vendor/built_in_modules/web_resource/app/views/panel/web_resource/back_end/web_links/_web_link.html.erb b/vendor/built_in_modules/web_resource/app/views/panel/web_resource/back_end/web_links/_web_link.html.erb index 457a05a8..f7d70250 100644 --- a/vendor/built_in_modules/web_resource/app/views/panel/web_resource/back_end/web_links/_web_link.html.erb +++ b/vendor/built_in_modules/web_resource/app/views/panel/web_resource/back_end/web_links/_web_link.html.erb @@ -24,8 +24,10 @@ <%= link_to web_link.name[I18n.locale], panel_web_resource_back_end_web_link_path(web_link) %>
From 88a26cc6a1c4a43e49b7672ec798b2e1a1d3f129 Mon Sep 17 00:00:00 2001 From: "Matthew K. Fu JuYuan" Date: Wed, 16 May 2012 12:10:16 +0800 Subject: [PATCH 4/6] Fix sidebar and hide some links by roles --- .../admin/module_apps_new_interface_controller.rb | 6 +++--- app/views/layouts/_side_bar.html.erb | 14 ++++++++------ .../back_end/web_link_categorys_controller.rb | 3 ++- .../web_resource/back_end/web_links_controller.rb | 9 ++++++++- 4 files changed, 21 insertions(+), 11 deletions(-) diff --git a/app/controllers/admin/module_apps_new_interface_controller.rb b/app/controllers/admin/module_apps_new_interface_controller.rb index 83aa0d79..404ac693 100644 --- a/app/controllers/admin/module_apps_new_interface_controller.rb +++ b/app/controllers/admin/module_apps_new_interface_controller.rb @@ -1,4 +1,4 @@ -class Admin::ModuleAppsNewInterfaceController < ApplicationController +class Admin::ModuleAppsNewInterfaceController < OrbitBackendController before_filter :authenticate_user! before_filter :is_admin? include AdminHelper @@ -25,9 +25,9 @@ class Admin::ModuleAppsNewInterfaceController < ApplicationController def update_setting module_app = update_setting_by_params if module_app.save! - flash[:notice] = "Update Done" + flash[:notice] = t("admin.object_auth.update_done") else - flash[:notice] = "Update Failed" + flash[:notice] = t("admin.object_auth.update_failed") end end diff --git a/app/views/layouts/_side_bar.html.erb b/app/views/layouts/_side_bar.html.erb index 2b6d75c0..fc3635c1 100644 --- a/app/views/layouts/_side_bar.html.erb +++ b/app/views/layouts/_side_bar.html.erb @@ -36,18 +36,20 @@ <%#= link_to content_tag(:i, nil, :class => 'icons-member') + t('admin.member'), admin_users_path %> <%# end -%> -<%= content_tag :li, :class => active_for_controllers('page_contexts') do -%> +<%= content_tag :li, :class => active_for_controllers('page_contexts') || active_for_app_auth('page_content') || active_for_ob_auths_object("PageContext") do -%> <%= link_to content_tag(:i, nil, :class => 'icons-page') + t('admin.page'), panel_page_content_back_end_page_contexts_path %> - <%#= content_tag :ul, :class => ("nav nav-list " + visible_for_controllers('page_contexts')) do -%> + <%= content_tag :ul, :class => ("nav nav-list " + visible_for_controllers('page_contexts')) do -%> <%#= content_tag :li, link_to(t('admin.all_articles'), panel_page_content_back_end_page_contexts_path), :class => active_for_action('page_context', 'index') %> - <%# end -%> + <%= content_tag :li, link_to(t('admin.module.authorization'),admin_module_app_manager_auth_proc_path(ModuleApp.first(conditions: {title: "page_content"}))), :class => active_for_app_auth('page_content') if (is_admin? rescue nil) %> + <% end -%> + <% end -%> <%= content_tag :li, :class => active_for_controllers('designs') do -%> <%= 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') || active_for_app_auth('ad_banners') do -%> +<%= content_tag :li, :class => active_for_controllers('ad_banners', 'ad_images') ||active_for_ob_auths_object("AdBanner") ||active_for_app_auth('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 -%> @@ -58,12 +60,12 @@ <% end -%> <% end %> -<%= content_tag :li, :class => active_for_controllers('web_links', '/panel/web_resource/back_end/tags', 'web_link_categorys') || active_for_app_auth('web_resource') do -%> +<%= content_tag :li, :class => active_for_controllers('web_links', '/panel/web_resource/back_end/tags', 'web_link_categorys') || active_for_app_auth('web_resource') || active_for_ob_auths_object("WebLinkCategory") do -%> <%= link_to content_tag(:i, nil, :class => 'icons-link') + t('admin.link'), panel_web_resource_back_end_web_links_path %> <%= content_tag :ul, :class => ("nav nav-list " + visible_for_controllers('web_links', '/panel/web_resource/back_end/tags', 'web_link_categorys')) do -%> <%= content_tag :li, link_to(t('admin.all_articles'), panel_web_resource_back_end_web_links_path), :class => active_for_action('web_links', 'index') %> <%= content_tag :li, link_to(t('announcement.add_new'), new_panel_web_resource_back_end_web_link_path), :class => active_for_action('web_links', 'new') %> - <%= content_tag :li, link_to(t('announcement.categories'), panel_web_resource_back_end_web_link_categorys_path), :class => active_for_action('web_link_categorys', 'index') %> + <%= content_tag :li, link_to(t('announcement.categories'), panel_web_resource_back_end_web_link_categorys_path), :class => (active_for_action('web_link_categorys', 'index') || active_for_ob_auths_object("WebLinkCategory")) %> <%= content_tag :li, link_to(t('announcement.tags'), panel_web_resource_back_end_tags_path), :class => active_for_action('/panel/web_resource/back_end/tags', 'index') %> <%= content_tag :li, link_to(t('admin.module.authorization'),admin_module_app_manager_auth_proc_path(ModuleApp.first(conditions: {title: "web_resource"}))), :class => active_for_app_auth('web_resource') if (is_admin? rescue nil) %> <% end -%> diff --git a/vendor/built_in_modules/web_resource/app/controllers/panel/web_resource/back_end/web_link_categorys_controller.rb b/vendor/built_in_modules/web_resource/app/controllers/panel/web_resource/back_end/web_link_categorys_controller.rb index 46e8933f..8c961cba 100644 --- a/vendor/built_in_modules/web_resource/app/controllers/panel/web_resource/back_end/web_link_categorys_controller.rb +++ b/vendor/built_in_modules/web_resource/app/controllers/panel/web_resource/back_end/web_link_categorys_controller.rb @@ -1,5 +1,6 @@ class Panel::WebResource::BackEnd::WebLinkCategorysController < OrbitBackendController - + before_filter :for_app_manager,:except => [:index] + def index @web_link_categorys = WebLinkCategory.all @web_link_category = WebLinkCategory.new(:display => 'List') diff --git a/vendor/built_in_modules/web_resource/app/controllers/panel/web_resource/back_end/web_links_controller.rb b/vendor/built_in_modules/web_resource/app/controllers/panel/web_resource/back_end/web_links_controller.rb index 323b92fc..af557bcb 100644 --- a/vendor/built_in_modules/web_resource/app/controllers/panel/web_resource/back_end/web_links_controller.rb +++ b/vendor/built_in_modules/web_resource/app/controllers/panel/web_resource/back_end/web_links_controller.rb @@ -1,7 +1,7 @@ class Panel::WebResource::BackEnd::WebLinksController < OrbitBackendController before_filter :authenticate_user! # before_filter :for_app_manager,:except => [:index,:show] - # before_filter :for_app_sub_manager + before_filter :for_app_sub_manager,:except => [:index] def index @@ -134,6 +134,13 @@ class Panel::WebResource::BackEnd::WebLinksController < OrbitBackendController def get_categorys(id = nil) @web_link_categorys = (id ? WebLinkCategory.find(id).to_a : WebLinkCategory.excludes('disabled' => true)) + + @web_link_categorys = [] + if(is_manager? || is_admin?) + @web_link_categorys = (id ? WebLinkCategory.find(id).to_a : WebLinkCategory.excludes('disabled' => true)) + elsif is_sub_manager? + @web_link_categorys = WebLinkCategory.authed_for_user(current_user,'edit') + end end def get_tags From befd3bcdec06a28ea51439b9297349c0cbd62764 Mon Sep 17 00:00:00 2001 From: "Matthew K. Fu JuYuan" Date: Wed, 16 May 2012 16:42:43 +0800 Subject: [PATCH 5/6] AdBanner reopen new banner and delete. Rename title with content editable tag. --- .../javascripts/lib/contenteditable.js.erb | 41 +++++++++++++++++++ .../admin/ad_banners_controller.rb | 5 +++ app/helpers/application_helper.rb | 7 ++-- .../admin/ad_banners/_ad_banner_tab.html.erb | 2 + .../ad_banners/_modal_ad_banner_form.html.erb | 1 + .../admin/ad_banners/create_error_msg.js.erb | 2 +- app/views/admin/ad_banners/index.html.erb | 10 +++-- .../admin/ad_banners/new_created_node.js.erb | 8 +++- config/locales/zh_tw.yml | 6 ++- config/routes.rb | 2 + 10 files changed, 73 insertions(+), 11 deletions(-) create mode 100644 app/assets/javascripts/lib/contenteditable.js.erb diff --git a/app/assets/javascripts/lib/contenteditable.js.erb b/app/assets/javascripts/lib/contenteditable.js.erb new file mode 100644 index 00000000..28dc9137 --- /dev/null +++ b/app/assets/javascripts/lib/contenteditable.js.erb @@ -0,0 +1,41 @@ +<%#= encoding: utf-8 %> +$(function() { + var content_holder, content; + var selector = 'li[contenteditable="true"]'; + // prevent clicks inside editable area to fire + // a click event on the body + // and therefor saving our content before we even edit it + $(selector).click(function(e) { + e.stopPropagation(); + }); + + // initialize the "save" function + $(selector).focus(function(e) { + content_holder = $(this); + content = content_holder.html(); + + // one click outside the editable area saves the content + $('body').one('click', function(e) { + // but not if the content didn't change + if ($(e.target).is(selector) || content == content_holder.html()) { + return; + } + + $.ajax({ + url: content_holder.data('edit-url'), + type: 'POST', + dataType: 'json', + data: { body: content_holder.html() }, + success: function(json) { + alert("<%= I18n.t("admin.contenteditable.update_done") %>"); + //content_holder.effect('highlight', {'color': '#0f0'}, 3000); + }, + error: function() { + alert("<%= I18n.t("admin.contenteditable.update_failed") %>"); + //content_holder.effect('highlight', {'color': '#f00'}, 3000); + content_holder.html(content); + } + }); + }); + }); +}); \ No newline at end of file diff --git a/app/controllers/admin/ad_banners_controller.rb b/app/controllers/admin/ad_banners_controller.rb index 3457c4de..347b9e88 100644 --- a/app/controllers/admin/ad_banners_controller.rb +++ b/app/controllers/admin/ad_banners_controller.rb @@ -4,6 +4,11 @@ class Admin::AdBannersController < OrbitBackendController before_filter :for_app_manager,:except => [:index,:show] before_filter :for_app_sub_manager + def rename + @ad_banner = AdBanner.find(params[:id]) + @ad_banner.title = Nokogiri::HTML.fragment(params["body"]).at("a").children().to_s + render :json => {:success =>@ad_banner.save!} + end def destroy @ad_banner = AdBanner.find(params[:id]) @ad_banner.destroy diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 64a6bf1d..59b45c27 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -172,11 +172,10 @@ module ApplicationHelper locale.to_sym == I18n.locale ? 'active in': '' end -<<<<<<< HEAD - def at_least_module_manager + def at_least_module_manager is_manager? || is_admin? - end -======= + end + def dislpay_view_count(object) "#{t(:view_count)}: #{object.view_count}" end diff --git a/app/views/admin/ad_banners/_ad_banner_tab.html.erb b/app/views/admin/ad_banners/_ad_banner_tab.html.erb index 56fd09a1..ca98e42e 100644 --- a/app/views/admin/ad_banners/_ad_banner_tab.html.erb +++ b/app/views/admin/ad_banners/_ad_banner_tab.html.erb @@ -26,7 +26,9 @@ <% if at_least_module_manager %> <%= show_ad_banner_permission_link ad_banner_tab%> + <%= link_to t('admin.ad.delete_banner'),admin_ad_banner_path(ad_banner_tab),:class => 'btn',:method => :delete,:confirm => t('sure?') %> <% end -%> + <%#= render :partial => 'new_add_banner_file', :object => ad_banner_tab.ad_images.build, :locals => { :field_name => "new_ad_images[]", :f => f, :classes => "r_destroy" } %>
<%#= render :partial => 'preview_block',:locals=> {:ad_banner =>ad_banner_tab} %> diff --git a/app/views/admin/ad_banners/_modal_ad_banner_form.html.erb b/app/views/admin/ad_banners/_modal_ad_banner_form.html.erb index 4a3f2db4..cbc4de8e 100644 --- a/app/views/admin/ad_banners/_modal_ad_banner_form.html.erb +++ b/app/views/admin/ad_banners/_modal_ad_banner_form.html.erb @@ -30,6 +30,7 @@ diff --git a/app/views/admin/ad_banners/create_error_msg.js.erb b/app/views/admin/ad_banners/create_error_msg.js.erb index 60f1d261..dbd013df 100644 --- a/app/views/admin/ad_banners/create_error_msg.js.erb +++ b/app/views/admin/ad_banners/create_error_msg.js.erb @@ -1 +1 @@ -alert("Error occures:<%= @ad_banner.errors.full_messages%>"); \ No newline at end of file +$("#ad_banner-modal-info").append("<%= @ad_banner.errors.full_messages.join(',')%>"); \ No newline at end of file diff --git a/app/views/admin/ad_banners/index.html.erb b/app/views/admin/ad_banners/index.html.erb index c0e02ecc..3e3b4689 100644 --- a/app/views/admin/ad_banners/index.html.erb +++ b/app/views/admin/ad_banners/index.html.erb @@ -4,21 +4,23 @@ <% content_for :page_specific_javascript do -%> <%= javascript_include_tag "/static/jquery.cycle.all.latest.js" %> <%= javascript_include_tag "inc/modal-preview" %> + <%= javascript_include_tag "lib/contenteditable" %> + <% end -%>
-
+
<%= render :partial => 'ad_banner_tab',:collection => @ad_banners %>
- <%#= render :partial => "modal_ad_banner_form"%> + <%= render :partial => "modal_ad_banner_form"%>
diff --git a/app/views/admin/ad_banners/new_created_node.js.erb b/app/views/admin/ad_banners/new_created_node.js.erb index 86970e6a..a53135da 100644 --- a/app/views/admin/ad_banners/new_created_node.js.erb +++ b/app/views/admin/ad_banners/new_created_node.js.erb @@ -1,8 +1,14 @@ $('<%= escape_javascript(content_tag(:li,link_to(@ad_banner.title,"##{@ad_banner.title}",:data=>{:toggle=>"tab"}))) %>').insertBefore("#new_ad_banner_tab_but"); -$('<%= escape_javascript(render(:partial => "ad_banner_tab",:locals => {:ad_banner_tab => @ad_banner})) %>').insertBefore($("#new-a-banner")); +$('<%= escape_javascript(render(:partial => "ad_banner_tab",:locals => {:ad_banner_tab => @ad_banner})) %>').insertAfter($("#ad_banner-tab-content").children(".tab-pane").last()); $('.modal').modal('hide'); +$("#ad_banner-modal-info").empty(); +$("#new-a-banner form").each(function(){this.reset();}); + $('#new-a-banner').unbind(); $('#post-body-content').find(".nav.nav-tabs").children('li.active').removeClass("active"); +$("#ad_banner-tab-content").children(".tab-pane").removeClass("active"); $('#post-body-content').find(".nav.nav-tabs").children('li[id!="new_ad_banner_tab_but"]').last().addClass("active"); +$("#ad_banner-tab-content").children(".tab-pane").last().addClass("active"); + diff --git a/config/locales/zh_tw.yml b/config/locales/zh_tw.yml index 916631d9..01d06e0b 100644 --- a/config/locales/zh_tw.yml +++ b/config/locales/zh_tw.yml @@ -82,8 +82,9 @@ zh_tw: sec_place_holder: 3秒請輸入3 ab_fx: 轉場特效 all_banners: 輪播清單 - cate_auth: 分類授權 banner_best_size: Banner 尺寸 + cate_auth: 分類授權 + delete_banner: 刪除整組輪播 new_banner: 新增輪播 new_image: 新增橫幅 showing: 顯示中 @@ -115,6 +116,9 @@ zh_tw: choose_file: 請選擇一個文件... class: 階級 content: 內容 + contenteditable: + update_done: 更新完成 + update_failed: 更新失敗 create_error_link: 新增連接時出錯。 create_error_page: 新增頁面時出錯。 create_success_home: 首頁已成功新增。 diff --git a/config/routes.rb b/config/routes.rb index 24862361..e1a6a1c7 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -37,6 +37,8 @@ Orbit::Application.routes.draw do match 'ad_banners/:id/preview' => 'ad_banners#realtime_preview',:as => :realtime_preview_ad_banner,:via => :put + match 'ad_banners/:id/rename' => 'ad_banners#rename',:as => :rename_ad_banner,:via => :post + resources :ad_banners do collection do match 'new_ad_image' => 'ad_images#new',:as => :new_ad_image,:via => :get From 064769801292fa974ab37d3cefb13ba75095de32 Mon Sep 17 00:00:00 2001 From: "Matthew K. Fu JuYuan" Date: Wed, 16 May 2012 17:16:48 +0800 Subject: [PATCH 6/6] fix ad_image size hints. fix orbit backend controller error when changing language. --- app/controllers/orbit_backend_controller.rb | 1 + app/models/ad_banner.rb | 1 + app/views/admin/ad_images/_form.html.erb | 2 +- config/locales/en.yml | 1 + config/locales/zh_tw.yml | 1 + 5 files changed, 5 insertions(+), 1 deletion(-) diff --git a/app/controllers/orbit_backend_controller.rb b/app/controllers/orbit_backend_controller.rb index e27e5b00..98882ec3 100644 --- a/app/controllers/orbit_backend_controller.rb +++ b/app/controllers/orbit_backend_controller.rb @@ -13,6 +13,7 @@ class OrbitBackendController< ApplicationController def setup_vars @app_title = request.fullpath.split('/')[2] @app_title = request.fullpath.split('/')[1] if(@app_title == "back_end") + @app_title.gsub!(/[?].*/,'') @module_app = ModuleApp.first(conditions: {:key => @app_title} ) end diff --git a/app/models/ad_banner.rb b/app/models/ad_banner.rb index 6163a81f..18c6d448 100644 --- a/app/models/ad_banner.rb +++ b/app/models/ad_banner.rb @@ -7,6 +7,7 @@ class AdBanner field :title field :transition_msec,type: Integer field :ad_fx #TODO Design should explain + field :best_size,:default => '' before_save :save_or_destroy validates_uniqueness_of :title diff --git a/app/views/admin/ad_images/_form.html.erb b/app/views/admin/ad_images/_form.html.erb index be5f2b47..1513fa05 100644 --- a/app/views/admin/ad_images/_form.html.erb +++ b/app/views/admin/ad_images/_form.html.erb @@ -80,7 +80,7 @@ <%= image_tag @ad_image.file rescue ''%>
- 此區塊圖片尺寸請使用580px × 225px + <%= t("admin.ad.widget_info_for_ad_image_size",:best_size=> @ad_image.ad_banner.best_size) if !@ad_image.ad_banner.best_size.empty?%>