Skip to content

Instantly share code, notes, and snippets.

@ohadlevy
Created November 28, 2012 10:20
Show Gist options
  • Save ohadlevy/4160322 to your computer and use it in GitHub Desktop.
Save ohadlevy/4160322 to your computer and use it in GitHub Desktop.
commit e12c5a71dbbea0699e8c2925396a192a7af4ecf4
Author: Ohad Levy <[email protected]>
Date: Wed Nov 28 12:18:45 2012 +0200
minor cleanups
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb
index 19c1f93..6b6057d 100644
--- a/app/controllers/application_controller.rb
+++ b/app/controllers/application_controller.rb
@@ -9,9 +9,9 @@ class ApplicationController < ActionController::Base
# standard layout to all controllers
helper 'layout'
- before_filter :require_ssl, :require_login, :set_taxonomy
- before_filter :require_mail
+ before_filter :require_ssl, :require_login
before_filter :session_expiry, :update_activity_time, :unless => proc {|c| c.remote_user_provided? || c.api_request? } if SETTINGS[:login]
+ before_filter :set_taxonomy, :require_mail
before_filter :welcome, :only => :index, :unless => :api_request?
before_filter :authorize
diff --git a/app/controllers/fact_values_controller.rb b/app/controllers/fact_values_controller.rb
index 681b1e8..66de700 100644
--- a/app/controllers/fact_values_controller.rb
+++ b/app/controllers/fact_values_controller.rb
@@ -5,6 +5,7 @@ class FactValuesController < ApplicationController
skip_before_filter :require_login, :only => :create
skip_before_filter :authorize, :only => :create
skip_before_filter :verify_authenticity_token, :only => :create
+ skip_before_filter :set_taxonomy, :only => :create
skip_before_filter :session_expiry, :update_activity_time, :only => :create
before_filter :set_admin_user, :only => :create
before_filter :setup_search_options, :only => :index
diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb
index 74aafaf..cadb852 100644
--- a/app/controllers/home_controller.rb
+++ b/app/controllers/home_controller.rb
@@ -1,6 +1,6 @@
class HomeController < ApplicationController
skip_before_filter :require_login, :only => [:status]
- skip_before_filter :authorize, :only => [:status]
+ skip_before_filter :authorize, :set_taxonomy, :only => [:status]
skip_before_filter :session_expiry, :update_activity_time, :only => :status
def settings
diff --git a/app/controllers/hosts_controller.rb b/app/controllers/hosts_controller.rb
index 1b3361f..91425c1 100644
--- a/app/controllers/hosts_controller.rb
+++ b/app/controllers/hosts_controller.rb
@@ -11,6 +11,7 @@ class HostsController < ApplicationController
skip_before_filter :require_login, :only => ANONYMOUS_ACTIONS
skip_before_filter :require_ssl, :only => ANONYMOUS_ACTIONS
skip_before_filter :authorize, :only => ANONYMOUS_ACTIONS
+ skip_before_filter :set_taxonomy, :only => ANONYMOUS_ACTIONS
skip_before_filter :session_expiry, :update_activity_time, :only => ANONYMOUS_ACTIONS
before_filter :set_admin_user, :only => ANONYMOUS_ACTIONS
diff --git a/app/controllers/locations_controller.rb b/app/controllers/locations_controller.rb
index 39bf45e..4b1a772 100644
--- a/app/controllers/locations_controller.rb
+++ b/app/controllers/locations_controller.rb
@@ -2,7 +2,7 @@ class LocationsController < ApplicationController
include Foreman::Controller::AutoCompleteSearch
before_filter :find_location, :only => %w{edit update destroy clone}
- skip_before_filter :authorize, :only => %w{select}
+ skip_before_filter :authorize, :set_taxonomy, :only => %w{select}
def index
begin
diff --git a/app/controllers/organizations_controller.rb b/app/controllers/organizations_controller.rb
index 82de157..8d3cbe9 100644
--- a/app/controllers/organizations_controller.rb
+++ b/app/controllers/organizations_controller.rb
@@ -2,7 +2,7 @@ class OrganizationsController < ApplicationController
include Foreman::Controller::AutoCompleteSearch
before_filter :find_organization, :only => %w{edit update destroy clone}
- skip_before_filter :authorize, :only => %w{select}
+ skip_before_filter :authorize, :set_taxonomy, :only => %w{select}
def index
begin
diff --git a/app/controllers/reports_controller.rb b/app/controllers/reports_controller.rb
index 80dd0eb..c4c3d59 100644
--- a/app/controllers/reports_controller.rb
+++ b/app/controllers/reports_controller.rb
@@ -5,6 +5,7 @@ class ReportsController < ApplicationController
skip_before_filter :require_ssl, :only => :create
skip_before_filter :authorize, :only => :create
skip_before_filter :verify_authenticity_token, :only => :create
+ skip_before_filter :set_taxonomy, :only => :create
skip_before_filter :session_expiry, :update_activity_time, :only => :create
before_filter :set_admin_user, :only => :create
before_filter :setup_search_options, :only => :index
diff --git a/app/controllers/tasks_controller.rb b/app/controllers/tasks_controller.rb
index 1efeb44..d2e71a5 100644
--- a/app/controllers/tasks_controller.rb
+++ b/app/controllers/tasks_controller.rb
@@ -1,5 +1,5 @@
class TasksController < ApplicationController
- skip_before_filter :session_expiry, :update_activity_time, :only => [:show]
+ skip_before_filter :session_expiry, :update_activity_time, :set_taxonomy, :only => [:show]
def show
id = params[:id]
diff --git a/app/controllers/unattended_controller.rb b/app/controllers/unattended_controller.rb
index ea78c6a..8823de2 100644
--- a/app/controllers/unattended_controller.rb
+++ b/app/controllers/unattended_controller.rb
@@ -12,7 +12,7 @@ class UnattendedController < ApplicationController
FINISH_URLS = [:preseed_finish, :jumpstart_finish] + TemplateKind.where("name LIKE ?", "finish").map(&:name)
# We dont require any of these methods for provisioning
- skip_before_filter :require_ssl, :require_login, :authorize, :session_expiry, :update_activity_time
+ skip_before_filter :require_ssl, :require_login, :authorize, :session_expiry, :update_activity_time, :set_taxonomy
# require logged in user to see templates in spoof mode
before_filter do |c|
diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb
index 07efd86..4999dba 100644
--- a/app/controllers/users_controller.rb
+++ b/app/controllers/users_controller.rb
@@ -2,7 +2,7 @@ class UsersController < ApplicationController
include Foreman::Controller::AutoCompleteSearch
skip_before_filter :require_mail, :only => [:edit, :update, :logout]
- skip_before_filter :require_login, :authorize, :session_expiry, :update_activity_time, :only => [:login, :logout]
+ skip_before_filter :require_login, :authorize, :session_expiry, :update_activity_time, :set_taxonomy, :only => [:login, :logout]
after_filter :update_activity_time, :only => :login
attr_accessor :editing_self
diff --git a/app/helpers/home_helper.rb b/app/helpers/home_helper.rb
index 5e2b291..c9458b0 100644
--- a/app/helpers/home_helper.rb
+++ b/app/helpers/home_helper.rb
@@ -14,9 +14,9 @@ module HomeHelper
['Smart Proxies', :smart_proxies]
]
+ choices += [ [:divider] ]
if (SETTINGS[:organizations_enabled] or SETTINGS[:locations_enabled])
- choices += [ [:divider] ]
- choices += [ ['Locations', :locations] ] if SETTINGS[:locations_enabled]
+ choices += [ ['Locations', :locations] ] if SETTINGS[:locations_enabled]
choices += [ ['Organizations', :organizations] ] if SETTINGS[:organizations_enabled]
choices += [ [:divider ] ]
end
diff --git a/app/models/compute_resource.rb b/app/models/compute_resource.rb
index 81c500e..3efc24d 100644
--- a/app/models/compute_resource.rb
+++ b/app/models/compute_resource.rb
@@ -26,7 +26,7 @@ class ComputeResource < ActiveRecord::Base
# include all default scoping here
default_scope lambda {
with_taxonomy_scope do
- select("DISTINCT compute_resources.*").order("LOWER(compute_resources.name)")
+ order("LOWER(compute_resources.name)")
end
}
diff --git a/app/models/host.rb b/app/models/host.rb
index e482475..36c8af8 100644
--- a/app/models/host.rb
+++ b/app/models/host.rb
@@ -37,7 +37,11 @@ class Host < Puppet::Rails::Host
default_scope lambda {
org = Organization.current
- where(:organization_id => org.id) if org
+ loc = Location.current
+ conditions = {}
+ conditions[:organization_id] = org.id if org
+ conditions[:location_id] = loc.id if loc
+ where(conditions)
}
scope :recent, lambda { |*args| {:conditions => ["last_report > ?", (args.first || (Setting[:puppet_interval] + 5).minutes.ago)]} }
diff --git a/app/models/hostext/search.rb b/app/models/hostext/search.rb
index 0ae31f4..4c11e13 100644
--- a/app/models/hostext/search.rb
+++ b/app/models/hostext/search.rb
@@ -30,8 +30,8 @@ module Hostext
scoped_search :in => :fact_values, :on => :value, :in_key=> :fact_names, :on_key=> :name, :rename => :facts, :complete_value => true, :only_explicit => true
scoped_search :in => :search_parameters, :on => :value, :on_key=> :name, :complete_value => true, :rename => :params, :ext_method => :search_by_params, :only_explicit => true
- scoped_search :in => :location, :on => :name, :rename => :location, :complete_value => true
- scoped_search :in => :organization, :on => :name, :rename => :organization, :complete_value => true
+ scoped_search :in => :location, :on => :name, :rename => :location, :complete_value => true if SETTINGS[:locations_enabled]
+ scoped_search :in => :organization, :on => :name, :rename => :organization, :complete_value => true if SETTINGS[:organizations_enabled]
if SETTINGS[:unattended]
scoped_search :in => :subnet, :on => :network, :complete_value => true, :rename => :subnet
diff --git a/db/migrate/20120621135042_create_taxonomies.rb b/db/migrate/20120621135042_create_taxonomies.rb
index 09c5edd..1f4e3e9 100644
--- a/db/migrate/20120621135042_create_taxonomies.rb
+++ b/db/migrate/20120621135042_create_taxonomies.rb
@@ -2,6 +2,7 @@ class CreateTaxonomies < ActiveRecord::Migration
def self.up
create_table :taxonomies do |t|
t.string :name
+ t.string :type
t.timestamps
end
diff --git a/db/migrate/20120809204732_add_type_column_to_taxonomies.rb b/db/migrate/20120809204732_add_type_column_to_taxonomies.rb
deleted file mode 100644
index e7c80bd..0000000
--- a/db/migrate/20120809204732_add_type_column_to_taxonomies.rb
+++ /dev/null
@@ -1,9 +0,0 @@
-class AddTypeColumnToTaxonomies < ActiveRecord::Migration
- def self.up
- add_column :taxonomies, :type, :string
- end
-
- def self.down
- remove_column :taxonomies, :type
- end
-end
diff --git a/db/migrate/20121101141448_add_locations_organizations.rb b/db/migrate/20121101141448_add_locations_organizations.rb
index 1ce56fa..5d5992a 100644
--- a/db/migrate/20121101141448_add_locations_organizations.rb
+++ b/db/migrate/20121101141448_add_locations_organizations.rb
@@ -3,8 +3,6 @@ class AddLocationsOrganizations < ActiveRecord::Migration
create_table :locations_organizations, :id => false do |t|
t.integer :location_id
t.integer :organization_id
-
- t.timestamps
end
end
diff --git a/lib/foreman/threadsession.rb b/lib/foreman/threadsession.rb
index 204db8b..9f133b3 100644
--- a/lib/foreman/threadsession.rb
+++ b/lib/foreman/threadsession.rb
@@ -66,7 +66,7 @@ module Foreman
raise(ArgumentError, "Unable to set current organization, expected class '#{self}', got #{organization.inspect}")
end
- Rails.logger.debug "Setting current organization thread-local variable to #{organization}"
+ Rails.logger.debug "Setting current organization thread-local variable to #{organization || "none"}"
Thread.current[:organization] = organization
end
@@ -101,7 +101,7 @@ module Foreman
raise(ArgumentError, "Unable to set current location, expected class '#{self}'. got #{location.inspect}")
end
- Rails.logger.debug "Setting current location thread-local variable to #{location}"
+ Rails.logger.debug "Setting current location thread-local variable to #{location || "none"}"
Thread.current[:location] = location
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment