From 762c2f5e8a58d3b25f0f86cafe4f431c4d82b6e6 Mon Sep 17 00:00:00 2001 From: Christophe Vilayphiou Date: Mon, 30 Jan 2012 18:12:18 +0800 Subject: [PATCH] Add key in module_app.rb to use instead of title for authorization --- app/controllers/application_controller.rb | 2 +- app/models/module_app.rb | 9 +++++++-- lib/tasks/dev.rake | 3 ++- vendor/built_in_modules/announcement/announcement.json | 3 ++- 4 files changed, 12 insertions(+), 5 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 412da0e2..f48777cc 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -7,7 +7,7 @@ class ApplicationController < ActionController::Base before_filter :set_locale, :set_site def front_end_available(module_app_title='') - app_controller = ModuleApp.first(conditions: {:title => module_app_title} ) + app_controller = ModuleApp.first(conditions: {:key => module_app_title} ) unless app_controller.enable_frontend? render :nothing => true end diff --git a/app/models/module_app.rb b/app/models/module_app.rb index f4a63618..d98ea206 100644 --- a/app/models/module_app.rb +++ b/app/models/module_app.rb @@ -2,6 +2,7 @@ class ModuleApp include Mongoid::Document include Mongoid::Timestamps + field :key field :title field :version field :organization @@ -19,6 +20,8 @@ class ModuleApp has_one :app_auth,dependent: :delete + before_save :set_key + def managing_users self.managers.collect{ |t| t.user } end @@ -61,8 +64,10 @@ class ModuleApp end end - field :app_pages ,type: Array + protected - has_one :app_auth,dependent: :delete + def set_key + self.key = self.title.underscore if self.title + end end diff --git a/lib/tasks/dev.rake b/lib/tasks/dev.rake index e1070926..eca6a158 100644 --- a/lib/tasks/dev.rake +++ b/lib/tasks/dev.rake @@ -105,7 +105,8 @@ namespace :dev do home = Page.create!( :i18n_variable_id => var_10.id, :design_id => design_1.id, :name => 'home', :is_published => true, :theme_id => theme.id ) home.page_parts.create!( :name => 'content_1', :content => File.open("#{Rails.root}/lib/template/home.page").read, :kind => 'text', :i18n_variable_id => var_13.id ) - ModuleApp.create.from_json(File.open("#{Rails.root}/vendor/built_in_modules/new_blog/new_blog.json").read).save + ModuleApp.new.from_json(File.open("#{Rails.root}/vendor/built_in_modules/new_blog/new_blog.json").read).save + ModuleApp.new.from_json(File.open("#{Rails.root}/vendor/built_in_modules/announcement/announcement.json").read).save Post.create(:title=>"1st post",:body=>"Long long time ago.....") Post.create(:title=>"2ec post",:body=>"And?.....") diff --git a/vendor/built_in_modules/announcement/announcement.json b/vendor/built_in_modules/announcement/announcement.json index 7cd3da1e..56146333 100644 --- a/vendor/built_in_modules/announcement/announcement.json +++ b/vendor/built_in_modules/announcement/announcement.json @@ -6,5 +6,6 @@ "intro": "A simple blog……", "update_info": "Some info", "create_date": "11-11-2011", - "app_pages": ["/panel/announcement/front_end/"] + "app_pages": ["/panel/announcement/front_end/"], + "enable_frontend": true }