diff --git a/app/controllers/admin/authorizations_controller.rb b/app/controllers/admin/authorizations_controller.rb index 8454c2411..e293a25c2 100644 --- a/app/controllers/admin/authorizations_controller.rb +++ b/app/controllers/admin/authorizations_controller.rb @@ -144,7 +144,7 @@ class Admin::AuthorizationsController < OrbitBackendController def setup_vars @module_app = ModuleApp.first(conditions: {:key => params[:module]} ) if params[:module] - @category = Category.find(params[:category]) rescue nil + @category = Category.find(params[:id]) rescue nil @type = params[:type] end diff --git a/app/helpers/orbit_backend_helper.rb b/app/helpers/orbit_backend_helper.rb index 23e81dbd6..4e7d783ba 100644 --- a/app/helpers/orbit_backend_helper.rb +++ b/app/helpers/orbit_backend_helper.rb @@ -106,14 +106,16 @@ module OrbitBackendHelper if object.is_hidden? res << content_tag(:span, t(:hidden), class: "label") + ' ' end - if object.is_pending? - res << content_tag(:span, t(:pending), class: "label") + ' ' - end - if object.is_checked? - res << content_tag(:span, t(:passed), class: "label") + ' ' - end - if object.is_rejected? - res << content_tag(:span, t(:rejected), class: "label") + ' ' + if @approvable + if object.is_pending? + res << content_tag(:span, t(:pending), class: "label") + ' ' + end + if object.is_checked? + res << content_tag(:span, t(:passed), class: "label") + ' ' + end + if object.is_rejected? + res << content_tag(:span, t(:rejected), class: "label") + ' ' + end end when 'tags' object.sorted_tags.each do |tag| @@ -154,8 +156,8 @@ module OrbitBackendHelper end def set_default_index(&block) - @approvable = false - @authorization = false + @approvable = @module_app.is_approvable + @authorization = @module_app.is_authorizable @fields = [] @filter_fields =[] @filterable = false @@ -167,14 +169,6 @@ module OrbitBackendHelper protected - def approvable - @approvable = true - end - - def authorization - @authorization = true - end - # =============================================================== # type: # check "get_value" diff --git a/app/models/category.rb b/app/models/category.rb index 1b0e040d2..974914b08 100644 --- a/app/models/category.rb +++ b/app/models/category.rb @@ -13,25 +13,4 @@ class Category scope :enabled, where(:disable.in => [false, nil, '']) -end - - - - # base.instance_eval("scope :admin_manager_all,find(:all)") - - # base.define_singleton_method :find do |*args| - # if args ==[:all] - # unscoped - # else - # res = unscoped.find(args) - # res.count == 1 ? res[0] : res - # end - # end - - # base.define_singleton_method :first do |*args| - # all.first - # end - - # base.define_singleton_method :last do |*args| - # all.last - # end \ No newline at end of file +end \ No newline at end of file diff --git a/app/models/module_app.rb b/app/models/module_app.rb index 5fb35100a..3fe38bdf0 100644 --- a/app/models/module_app.rb +++ b/app/models/module_app.rb @@ -22,7 +22,9 @@ class ModuleApp self[:widgets] = reg.get_widgets self[:has_tag] = reg.get_has_tags self[:has_category] = reg.get_has_category + self[:is_approvable] = reg.get_is_approvable self[:is_authorizable] = reg.get_is_authorizable + self[:authorizable_models] = reg.get_authorizable_models end diff --git a/config/routes.rb b/config/routes.rb index ac6230328..a373f593e 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -51,11 +51,11 @@ Orbit::Application.routes.draw do resources :ad_images ,:except => [:show,:index] end - match 'authorizations/add_roles/:module(/:type(/:category))' => 'authorizations#add_roles', :as => :add_roles_authorizations - match 'authorizations/add_users/:module(/:type(/:category))' => 'authorizations#add_users', :as => :add_users_authorizations - match 'authorizations/modal_select/:module(/:type(/:category))' => 'authorizations#modal_select', :as => :modal_select_authorizations - match 'authorizations/remove_users/:module(/:type(/:category))' => 'authorizations#remove_users', :as => :remove_users_authorizations, :via => :delete - match 'authorizations(/:module(/:type(/:category)))' => 'authorizations#index', :as => :authorizations + match 'authorizations/add_roles/:module(/:type(/:id))' => 'authorizations#add_roles', :as => :add_roles_authorizations + match 'authorizations/add_users/:module(/:type(/:id))' => 'authorizations#add_users', :as => :add_users_authorizations + match 'authorizations/modal_select/:module(/:type(/:id))' => 'authorizations#modal_select', :as => :modal_select_authorizations + match 'authorizations/remove_users/:module(/:type(/:id))' => 'authorizations#remove_users', :as => :remove_users_authorizations, :via => :delete + match 'authorizations(/:module(/:type(/:id)))' => 'authorizations#index', :as => :authorizations resources :dashboards do collection do diff --git a/lib/orbit_app/module/registration.rb b/lib/orbit_app/module/registration.rb index 71302607b..902efe6c7 100644 --- a/lib/orbit_app/module/registration.rb +++ b/lib/orbit_app/module/registration.rb @@ -28,7 +28,7 @@ module OrbitApp end class DataSheet - attr_reader :name,:key,:base_path,:module_label,:data_count, :has_tag + attr_reader :name,:key,:base_path,:module_label,:data_count, :has_category, :has_tag, :authorizable_models, :is_approvable, :is_authorizable def initialize(name, &block) @name = name @@ -39,6 +39,8 @@ module OrbitApp @data_count = 1..15 # as default @has_category = nil @has_tag = nil + @authorizable_models = [] + @is_approvable = nil @is_authorizable = nil block.arity < 1 ? instance_eval(&block) : block.call(self) if block_given? setup_module_app @@ -123,7 +125,7 @@ module OrbitApp end def side_bar(&block) #setter for side_bar from init - @side_bar = SideBarRegisition::SideBar.new(@name,@key,method(:get_module_app),&block) + @side_bar = SideBarRegisition::SideBar.new(@name,@key,method(:get_module_app), is_approvable_with_link?, is_authorizable_with_link?, &block) end def personal_plugin(params) #setter for personal_plugin from init @@ -143,8 +145,21 @@ module OrbitApp define_method(field){|var| instance_variable_set( "@" + field, var)} end - def authorizable - @is_authorizable = true + def approvable(link=true) + @is_approvable = {:with_link => link} + end + + def authorizable(link=true, &block) + @is_authorizable = {:with_link => link} + if block + block.call + else + authorizable_on + end + end + + def authorizable_on(klass = 'Category') + @authorizable_models << klass end def categorizable @@ -155,16 +170,32 @@ module OrbitApp @has_tag = true end + def get_authorizable_models + @authorizable_models + end + def get_has_category - @has_category.nil? ? false : true + @has_category == true end def get_has_tags - @has_tag.nil? ? false : true + @has_tag == true + end + + def get_is_approvable + !@is_approvable.blank? end def get_is_authorizable - @is_authorizable.nil? ? false : true + !@is_authorizable.blank? + end + + def is_approvable_with_link? + @is_approvable && @is_approvable[:with_link] + end + + def is_authorizable_with_link? + @is_authorizable && @is_authorizable[:with_link] end end # of class DataSheet diff --git a/lib/orbit_app/module/side_bar.rb b/lib/orbit_app/module/side_bar.rb index 408dd5875..be90e062a 100644 --- a/lib/orbit_app/module/side_bar.rb +++ b/lib/orbit_app/module/side_bar.rb @@ -41,7 +41,7 @@ module OrbitApp # include AdminHelper include SideBarRenderer - def initialize(name = '',key,get_module_app,&block) + def initialize(name = '',key,get_module_app, approvable_with_link, authorizable_with_link, &block) @head_label = name @context_links = [] @available_for = [] @@ -54,6 +54,8 @@ module OrbitApp @module_app_key = key @get_module_app = get_module_app @sidebar_order = 0 + @approvable_with_link = approvable_with_link + @authorizable_with_link = authorizable_with_link block.arity < 1 ? instance_eval(&block) : block.call(self) if block_given? # setup_module_app(module_app_key) finalize! @@ -107,6 +109,19 @@ module OrbitApp def finalize! set_controllers_scope # set_default_active_app_auth + current_priority = @context_links.count + if @approvable_with_link + context_link 'approval_setting', + :link_path => "admin_authorizations_path(get_module_app.key, 'approval')", + :priority => current_priority + 1, + :available_for => [:manager] + end + if @authorizable_with_link + context_link 'module_authorization', + :link_path => "admin_authorizations_path(get_module_app.key)", + :priority => current_priority + 2, + :available_for => [:manager] + end @context_links.each do |t| # t.set_module_app = @module_app t.finalize! diff --git a/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/bulletins/index.html.erb b/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/bulletins/index.html.erb index 0aaefc36f..0ba95d2f7 100644 --- a/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/bulletins/index.html.erb +++ b/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/bulletins/index.html.erb @@ -1,7 +1,5 @@ <% set_default_index do objects @bulletins - approvable - authorization filterable sortable quick_edit_link type: 'edit', diff --git a/vendor/built_in_modules/announcement/init.rb b/vendor/built_in_modules/announcement/init.rb index d01edbe7e..001176eff 100644 --- a/vendor/built_in_modules/announcement/init.rb +++ b/vendor/built_in_modules/announcement/init.rb @@ -26,6 +26,7 @@ module Announcement data_count 3..10 authorizable + approvable categorizable taggable @@ -84,16 +85,6 @@ module Announcement :priority=>4, :active_for_tag => 'Announcement', :available_for => [:manager] - context_link 'approval_setting', - :link_path=>"admin_authorizations_path(get_module_app.key, 'approval')" , - :priority=>5, - :active_for_action=>{:approvals=>:setting}, - :active_for_object_auth => 'BulletinCategory', - :available_for => [:manager] - context_link 'module_authorization', - :link_path=>"admin_authorizations_path(get_module_app.key)", - :priority=>6, - :available_for => [:manager] end end end