Add a simple way of filtering sites based on authentication

Clarke Brunsdon committed Feb 10, 2012
commit 412498700b0ea3b065b39b6a3dbb01d7b079b026
Showing 4 changed files with 16 additions and 6 deletions
app/controllers/cms_admin/base_controller.rb +1 -0
@@ @@ -27,6 +27,7 @@ protected
flash[:error] = I18n.t('cms.base.site_not_found')
return redirect_to(new_cms_admin_site_path)
end
+ raise "SiteNotAvailable" unless available_sites.detect { |x| x.id == @site.id }
I18n.locale = ComfortableMexicanSofa.config.admin_locale || @site.locale
end
app/controllers/cms_admin/sites_controller.rb +2 -2
@@ @@ -8,7 +8,7 @@ class CmsAdmin::SitesController < CmsAdmin::BaseController
def index
return redirect_to :action => :new if Cms::Site.count == 0
- @sites = Cms::Site.all
+ @sites = available_sites
end
def new
@@ @@ -60,4 +60,4 @@ protected
redirect_to :action => :index
end
- end
\ No newline at end of file
+ end
comfortable_mexican_sofa/authentication/dummy_auth.rb b/lib/comfortable_mexican_sofa/authentication/dummy_auth.rb +7 -3
@@ @@ -1,8 +1,12 @@
module ComfortableMexicanSofa::DummyAuth
-
+
# Will always let you in
def authenticate
true
end
-
- end
\ No newline at end of file
+
+ # The list of sites this authorization is allowed to edit.
+ def available_sites
+ Cms::Site.all
+ end
+ end
comfortable_mexican_sofa/authentication/http_auth.rb b/lib/comfortable_mexican_sofa/authentication/http_auth.rb +6 -1
@@ @@ -14,4 +14,9 @@ module ComfortableMexicanSofa::HttpAuth
username == self.username && password == self.password
end
end
- end
\ No newline at end of file
+
+ # The list of sites this authorization is allowed to edit.
+ def available_sites
+ Cms::Site.all
+ end
+ end