Skip to content

Commit

Permalink
Merge pull request #288 from sul-dlss/default-exhibit
Browse files Browse the repository at this point in the history
remove unnecessary references to Spotlight::Exhibit.default
  • Loading branch information
jcoyne committed Feb 21, 2014
2 parents d3d3ba6 + b6a1622 commit a498e16
Show file tree
Hide file tree
Showing 22 changed files with 44 additions and 56 deletions.
4 changes: 2 additions & 2 deletions app/controllers/spotlight/catalog_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ class Spotlight::CatalogController < Spotlight::ApplicationController
load_resource :exhibit, class: Spotlight::Exhibit
before_filter :authenticate_user!, only: [:admin, :edit, :make_public, :make_private]
before_filter :check_authorization, only: [:admin, :edit, :make_public, :make_private]
load_and_authorize_resource instance_name: :document, class: ::SolrDocument, only: [:edit]

before_filter :attach_breadcrumbs

Expand Down Expand Up @@ -51,7 +50,7 @@ def update
if params[:solr_document]
@document = ::SolrDocument.find params[:id]
authenticate_user!
authorize! :update, @document
authorize! :curate, current_exhibit
@document.update(current_exhibit, solr_document_params)
@document.save
redirect_to exhibit_catalog_path(current_exhibit, @document)
Expand All @@ -61,6 +60,7 @@ def update
end

def edit
@document = ::SolrDocument.find(params[:id])
blacklight_config.view.edit.partials = blacklight_config.view_config(:show).partials.dup
blacklight_config.view.edit.partials.delete "spotlight/catalog/tags"
blacklight_config.view.edit.partials.insert(2, :edit)
Expand Down
1 change: 1 addition & 0 deletions app/controllers/spotlight/contact_forms_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ def new

def create
@contact_form = Spotlight::ContactForm.new(contact_form_params)
@contact_form.current_exhibit = current_exhibit
@contact_form.request = request

if @contact_form.valid?
Expand Down
3 changes: 1 addition & 2 deletions app/controllers/spotlight/contacts_controller.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
module Spotlight
class ContactsController < Spotlight::ApplicationController
before_filter :authenticate_user!
load_and_authorize_resource except: [:new, :create]
load_and_authorize_resource :exhibit, class: "Spotlight::Exhibit", only: [:new, :create]
load_and_authorize_resource through: :exhibit, only: [:new, :create]
load_and_authorize_resource through: :exhibit, shallow: true
before_filter :attach_breadcrumbs

def new
Expand Down
4 changes: 1 addition & 3 deletions app/controllers/spotlight/custom_fields_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ class Spotlight::CustomFieldsController < Spotlight::ApplicationController
before_filter :authenticate_user!

load_resource :exhibit, class: Spotlight::Exhibit, only: [:index, :new, :create]
load_and_authorize_resource through: :exhibit, only: [:index, :new, :create]

load_and_authorize_resource only: [:edit, :update, :destroy]
load_and_authorize_resource through: :exhibit, shallow: true
before_filter :attach_breadcrumbs, only: [:new, :edit]

def new
Expand Down
7 changes: 1 addition & 6 deletions app/controllers/spotlight/exhibits_controller.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
class Spotlight::ExhibitsController < Spotlight::ApplicationController
before_filter :authenticate_user!
before_filter :default_exhibit
include Blacklight::SolrHelper

authorize_resource
load_and_authorize_resource

def edit
add_breadcrumb @exhibit.title, @exhibit
Expand All @@ -30,8 +29,4 @@ def exhibit_params
contact_emails_attributes: [:email]
)
end

def default_exhibit
@exhibit = Spotlight::Exhibit.default
end
end
6 changes: 4 additions & 2 deletions app/controllers/spotlight/home_pages_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,10 @@ def search_action_url *args
def blacklight_config
if @page
@page.exhibit.blacklight_config
else
Spotlight::Exhibit.default.blacklight_config
elsif current_exhibit
current_exhibit.blacklight_config
else
super
end
end
end
Expand Down
3 changes: 1 addition & 2 deletions app/controllers/spotlight/pages_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ class PagesController < Spotlight::ApplicationController
before_filter :authenticate_user!, except: [:show]

load_resource :exhibit, class: Spotlight::Exhibit, only: [:index, :new, :create, :update_all]
load_and_authorize_resource only: [:show, :edit, :update, :destroy, :update_all], instance_name: 'page'
load_and_authorize_resource through: :exhibit, only: [:index, :new, :create], instance_name: 'page'
load_and_authorize_resource through: :exhibit, shallow: true, instance_name: 'page'

before_filter :attach_breadcrumbs

Expand Down
35 changes: 12 additions & 23 deletions app/models/spotlight/ability.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,34 +8,23 @@ def initialize(user)
# until this PR is merged: https://github.com/ryanb/cancan/pull/917
# can :create, Spotlight::Exhibit, admin_roles: { id: user.role_ids }
# Until then, workaround:
can :update, Spotlight::Exhibit, id: user.admin_roles.map(&:exhibit_id)

can [:index, :update, :destroy, :create], Spotlight::Role, exhibit_id: user.admin_roles.map(&:exhibit_id)
# exhibit admin
can :manage, Spotlight::Exhibit, id: user.admin_roles.map(&:exhibit_id)
can :manage, [Spotlight::Role], exhibit_id: user.admin_roles.map(&:exhibit_id)

# exhibit curator
can :manage, [
Spotlight::Search,
Spotlight::Page,
Spotlight::BlacklightConfiguration,
Spotlight::Contact,
Spotlight::CustomField], exhibit_id: user.roles.map(&:exhibit_id)

can [:create, :update, :destroy], Spotlight::Contact, exhibit_id: user.roles.map(&:exhibit_id)

can [:update, :edit_metadata_fields, :edit_facet_fields], Spotlight::BlacklightConfiguration do |config|
config.exhibit.roles.where(id: user.role_ids).any?
end

can :manage, Spotlight::CustomField do |config|
config.exhibit.roles.where(id: user.role_ids).any?
end

can [:curate, :tag], Spotlight::Exhibit do |exhibit|
# any curator or admin role
exhibit.roles.where(id: user.role_ids).any?
end
can [:curate, :tag], Spotlight::Exhibit, id: user.roles.map(&:exhibit_id)

# public
can [:read, :index], [Spotlight::Exhibit, Spotlight::Page, Spotlight::Search]

# any curator or admin role
if Spotlight::Exhibit.default.roles.where(id: user.role_ids).any?
can [:create, :update, :destroy], [Spotlight::Search, Spotlight::Page]
can :update_all, [Spotlight::Search, Spotlight::Page] #TODO make these specific to the owning exhibit
can [:update], ::SolrDocument
end

end
end
2 changes: 1 addition & 1 deletion app/models/spotlight/blacklight_configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

module Spotlight
class BlacklightConfiguration < ActiveRecord::Base
has_one :exhibit
belongs_to :exhibit
serialize :facet_fields, Hash
serialize :index_fields, Hash
serialize :sort_fields, Hash
Expand Down
6 changes: 4 additions & 2 deletions app/models/spotlight/contact_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

module Spotlight
class ContactForm < MailForm::Base
attribute :current_exhibit
attribute :name, validate: false
attribute :email, validate: /\A([\w\.%\+\-]+)@([\w\-]+\.)+([\w]{2,})\z/i
attribute :message
Expand All @@ -12,10 +13,11 @@ class ContactForm < MailForm::Base
def headers
{
subject: "#{I18n.t(:'blacklight.application_name')} Contact Form",
to: Spotlight::Exhibit.default.contact_emails.first,
to: current_exhibit.contact_emails.first,
from: %("#{name}" <#{email}>),
cc: Spotlight::Exhibit.default.contact_emails.join(", ")
cc: current_exhibit.contact_emails.join(", ")
}
end

end
end
2 changes: 1 addition & 1 deletion app/models/spotlight/exhibit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ class Spotlight::Exhibit < ActiveRecord::Base
has_many :users, through: :roles, class_name: '::User'
has_many :custom_fields
has_many :contacts
has_one :blacklight_configuration, class_name: Spotlight::BlacklightConfiguration

belongs_to :blacklight_configuration, class_name: Spotlight::BlacklightConfiguration
accepts_nested_attributes_for :blacklight_configuration
accepts_nested_attributes_for :searches
accepts_nested_attributes_for :about_pages
Expand Down
2 changes: 1 addition & 1 deletion app/views/_user_util_links.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@
<% else %>
<li><%= link_to t('spotlight.header_links.login'), new_user_session_path %></li>
<% end %>
<li><%= link_to t('spotlight.header_links.contact'), spotlight.new_contact_form_path %></li>
<li><%= link_to t('spotlight.header_links.contact'), spotlight.new_exhibit_contact_form_path(current_exhibit) %></li>
</ul>
2 changes: 1 addition & 1 deletion app/views/catalog/_save_search.html.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<%= button_tag t(:'spotlight.saved_search.label'), class: 'btn btn-default', data: {toggle:"modal", target:"#save-modal"} %>
<div class="modal fade" id="save-modal" tabindex="-1" role="dialog" aria-labelledby="save-modal-label" aria-hidden="true">
<div class="modal-dialog">
<%= bootstrap_form_for [spotlight, Spotlight::Exhibit.default, Spotlight::Search.new] do |f| %>
<%= bootstrap_form_for [spotlight, current_exhibit, Spotlight::Search.new] do |f| %>
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
Expand Down
2 changes: 1 addition & 1 deletion app/views/catalog/_sort_and_per_page.html.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<div id="sortAndPerPage" class="clearfix">
<%= render :partial => "paginate_compact", :object => @response %>
<div class="search-widgets pull-right">
<%= render('save_search') if can?( :curate, Spotlight::Exhibit.default) %>
<%= render('save_search') if current_exhibit and can?( :curate, current_exhibit) %>
<%= render :partial => 'sort_widget' %>
<%= render :partial => 'per_page_widget' %>
<%= render :partial => 'view_type_group' %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/spotlight/contact_forms/new.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<div id="content" class="col-md-9">
<%= bootstrap_form_for @contact_form, url: spotlight.contact_form_path(@contact_form), style: :horizontal, right: "col-sm-5" do |f| %>
<%= bootstrap_form_for @contact_form, url: spotlight.exhibit_contact_form_path(current_exhibit, @contact_form), style: :horizontal, right: "col-sm-5" do |f| %>
<%= curation_page_title %>
<div class="row">
<%= f.text_field :name %>
Expand Down
2 changes: 1 addition & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
Spotlight::Engine.routes.draw do
resources :attachments
resource :contact_form, only: [:new, :create]

get 'exhibits/:id' => 'home_pages#show'

resources :contacts, only: [:edit, :update, :destroy]
resources :exhibits, only: [:edit, :update] do
resource :contact_form, only: [:new, :create]
resource :blacklight_configuration, only: [:update]

get 'edit/metadata', to: "blacklight_configurations#edit_metadata_fields"
Expand Down
1 change: 0 additions & 1 deletion db/migrate/20140128155151_create_exhibits.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ def change
t.string :subtitle
t.text :description
t.text :contact_emails
t.references :blacklight_configuration
t.timestamps
end

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
class CreateSpotlightBlacklightConfigurations < ActiveRecord::Migration
def change
create_table :spotlight_blacklight_configurations do |t|
t.references :exhibit
t.text :facet_fields
t.text :index_fields
t.text :search_fields
Expand Down
6 changes: 5 additions & 1 deletion lib/spotlight/catalog.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ module Catalog
include Spotlight::Catalog::AccessControlsEnforcement

def blacklight_config
@blacklight_config ||= Exhibit.default.blacklight_config params.fetch(:view, :list)
if current_exhibit
@blacklight_config ||= current_exhibit.blacklight_config params.fetch(:view, :list)
else
super
end
end
end
end
2 changes: 1 addition & 1 deletion spec/features/curator_items.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

visit '/'
within '.dropdown-menu' do
click_link 'Curation'
click_link 'Dashboard'
end
expect(page).to have_content "Items"
end
Expand Down
2 changes: 2 additions & 0 deletions spec/features/feature_page_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

describe "Feature page" do
describe "sidebar" do
let!(:exhibit) { Spotlight::Exhibit.default }

let!(:parent_feature_page) {
FactoryGirl.create(:feature_page, title: "Parent Page")
}
Expand Down
5 changes: 1 addition & 4 deletions spec/models/spotlight/ability_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@
it { should_not be_able_to(:create, exhibit) }
it { should be_able_to(:read, exhibit) }
it { should be_able_to(:read, page) }
it { should_not be_able_to(:create, Spotlight::Page) }
it { should_not be_able_to(:create, Spotlight::Page.new(exhibit: exhibit)) }
it { should be_able_to(:read, search) }
it { should_not be_able_to(:edit, SolrDocument.new) }
it { should_not be_able_to(:tag, exhibit) }
end

Expand Down Expand Up @@ -47,8 +46,6 @@
it { should be_able_to(:update, page) }
it { should be_able_to(:destroy, page) }

it { should be_able_to(:edit, SolrDocument.new) }

it { should be_able_to(:tag, exhibit) }

let(:contact) { FactoryGirl.create(:contact, exhibit: exhibit) }
Expand Down

0 comments on commit a498e16

Please sign in to comment.