remove whilelist for theme assets (no useful since we have got roles now) + a little bit of refactoring
This commit is contained in:
parent
91f2f145b3
commit
1e465e231e
@ -13,7 +13,7 @@ module Admin
|
||||
before_filter :sanitize_params, :only => [:create, :update]
|
||||
|
||||
def index
|
||||
@assets = ThemeAsset.all_grouped_by_folder(current_site, params[:all])
|
||||
@assets = ThemeAsset.all_grouped_by_folder(current_site)
|
||||
@js_and_css_assets = (@assets[:javascripts] || []) + (@assets[:stylesheets] || [])
|
||||
|
||||
if request.xhr?
|
||||
@ -48,9 +48,6 @@ module Admin
|
||||
|
||||
def sanitize_params
|
||||
params[:theme_asset] = { :source => params[:file] } if params[:file]
|
||||
|
||||
# performing_plain_text = params[:theme_asset][:performing_plain_text]
|
||||
# params[:theme_asset].delete(:content_type) if performing_plain_text.blank? || performing_plain_text == 'false'
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -12,7 +12,6 @@ class ThemeAsset
|
||||
field :height, :type => Integer
|
||||
field :size, :type => Integer
|
||||
field :folder, :default => nil
|
||||
field :hidden, :type => Boolean, :default => false
|
||||
mount_uploader :source, ThemeAssetUploader
|
||||
|
||||
## associations ##
|
||||
@ -35,7 +34,6 @@ class ThemeAsset
|
||||
validate :content_type_can_not_changed
|
||||
|
||||
## named scopes ##
|
||||
scope :visible, lambda { |all| all ? {} : { :where => { :hidden => false } } }
|
||||
|
||||
## accessors ##
|
||||
attr_accessor :plain_text_name, :plain_text, :plain_text_type, :performing_plain_text
|
||||
@ -101,8 +99,8 @@ class ThemeAsset
|
||||
{ :url => self.source.url }.merge(self.attributes).stringify_keys
|
||||
end
|
||||
|
||||
def self.all_grouped_by_folder(site, include_all = true)
|
||||
assets = site.theme_assets.visible(include_all).order_by([[:slug, :asc]])
|
||||
def self.all_grouped_by_folder(site)
|
||||
assets = site.theme_assets.order_by([[:slug, :asc]])
|
||||
assets.group_by { |a| a.folder.split('/').first.to_sym }
|
||||
end
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
- edit = local_assigns.key?(:edit) ? edit : true
|
||||
|
||||
%li{ :class => "#{asset.new_record? ? 'new-asset' : 'asset'} #{'hidden' if asset.hidden?}" }
|
||||
%li{ :class => (asset.new_record? ? 'new-asset' : 'asset') }
|
||||
%em
|
||||
%strong= link_to asset.local_path(!edit), edit ? edit_admin_theme_asset_path(asset) : asset.source.url, :'data-local-path' => asset.local_path
|
||||
.more
|
||||
|
@ -33,5 +33,3 @@
|
||||
|
||||
= f.foldable_inputs :name => :options do
|
||||
= f.input :folder
|
||||
= f.custom_input :hidden, :css => 'toggle' do
|
||||
= f.check_box :hidden
|
||||
|
@ -4,7 +4,6 @@
|
||||
= render 'admin/shared/menu/settings'
|
||||
|
||||
- content_for :buttons do
|
||||
= admin_button_tag t('admin.theme_assets.index.all'), all_admin_theme_assets_url, :class => 'show' if can?(:manage, ThemeAsset)
|
||||
= admin_button_tag t('admin.snippets.index.new'), new_admin_snippet_url, :class => 'new' if can?(:manage, Snippet)
|
||||
= admin_button_tag :new, new_admin_theme_asset_url, :class => 'new' if can?(:manage, ThemeAsset)
|
||||
|
||||
|
@ -168,7 +168,6 @@ de:
|
||||
index:
|
||||
title: Template-Dateien
|
||||
help: "In diesem Bereich kannst du alle Dateien organisieren, die für dein Layout verwendet werden. Wenn du eine Bilder-Galerie organisieren möchtest, dann gehe dazu in den Galerien-Abschnitt."
|
||||
all: alle Dateien
|
||||
new: neue Datei
|
||||
snippets: Snippets
|
||||
css_and_js: Style und Javascript
|
||||
|
@ -172,7 +172,6 @@ en:
|
||||
index:
|
||||
title: Listing theme files
|
||||
help: "The theme files section is the place where you manage the files needed by your layout, snippets...etc. If you need to manage an image gallery, create a new content type instead.<br/><b>Warning:</b> you may not see all the assets depending on your rights."
|
||||
all: all assets
|
||||
new: new file
|
||||
snippets: Snippets
|
||||
css_and_js: Style and javascript
|
||||
|
@ -169,7 +169,6 @@ fr:
|
||||
index:
|
||||
title: Liste des fichiers du thème
|
||||
help: "Les fichiers du thème sont utilisés pour construire le gabarit de vos pages. Si vous avez besoin d'une galerie d'images, créer un modèle sera plus adéquate.<br/><b>Attention : </b> Suivant les droits que vous avez, il se peut que vous ne puissiez pas voir tous les fichiers."
|
||||
all: tous les fichiers
|
||||
new: nouveau fichier
|
||||
snippets: Snippets
|
||||
css_and_js: Style et javascript
|
||||
|
@ -166,7 +166,6 @@ it:
|
||||
index:
|
||||
title: Lista file del tema
|
||||
help: "La sezione di file del tema è il luogo in cui si amministrano i file necessari al layout, ...ecc. Se devi invece amministrare una galleria immagini, vai nella sezione Risorse."
|
||||
all: tutte le risorse
|
||||
new: nuovo file
|
||||
snippets: Frammenti
|
||||
css_and_js: Style e javascript
|
||||
|
@ -163,7 +163,6 @@ pt-BR:
|
||||
index:
|
||||
title: Listando arquivos do tema
|
||||
help: "Nesta seção todos os arquivos relacionados a layout são armazenados e gerenciados. Se você precisa de uma galeria de imagens, vá a seção de Arquivos."
|
||||
all: todos arquivos
|
||||
new: novo arquivo
|
||||
snippets: Blocos
|
||||
css_and_js: CSS e Javascript
|
||||
|
@ -27,7 +27,6 @@ fr:
|
||||
plain_text_name: Nom du fichier
|
||||
content_type: Type du fichier
|
||||
folder: Dossier
|
||||
hidden: Caché
|
||||
new:
|
||||
source: Fichier
|
||||
edit:
|
||||
|
8
doc/TODO
8
doc/TODO
@ -63,14 +63,14 @@ x bug: duplicate fields (new entry) when errors in the content type form
|
||||
x tinyMCE => fullscreen
|
||||
x export site
|
||||
x rake task to import a remote template
|
||||
|
||||
=> MERGE
|
||||
x MERGE
|
||||
x remove withelist for assets since we've got now roles
|
||||
- test and/or convert existing templates (the 2 of the themes section)
|
||||
|
||||
- overide sort for contents
|
||||
- icon for redirection page in the pages section (back-office)
|
||||
- test and/or convert existing templates (the 2 of the themes section)
|
||||
- [bushido] guiders / welcome page / devise cas authentication (SSO)
|
||||
- remove withelist for assets since we've now roles
|
||||
|
||||
|
||||
|
||||
BACKLOG:
|
||||
|
@ -15,8 +15,7 @@ Background:
|
||||
Scenario: Accessing theme assets as an Admin
|
||||
Given I am an authenticated "admin"
|
||||
When I go to theme assets
|
||||
Then I should see "all assets"
|
||||
And I should see "new snippet"
|
||||
Then I should see "new snippet"
|
||||
And I should see "new file"
|
||||
And I should see "Snippets"
|
||||
And I should see "Style and javascript"
|
||||
@ -25,8 +24,7 @@ Background:
|
||||
Scenario: Accessing theme assets as a Designer
|
||||
Given I am an authenticated "designer"
|
||||
When I go to theme assets
|
||||
Then I should see "all assets"
|
||||
And I should see "new snippet"
|
||||
Then I should see "new snippet"
|
||||
And I should see "new file"
|
||||
And I should see "Snippets"
|
||||
And I should see "Style and javascript"
|
||||
@ -35,8 +33,7 @@ Background:
|
||||
Scenario: Accessing theme assets as an Author
|
||||
Given I am an authenticated "author"
|
||||
When I go to theme assets
|
||||
Then I should not see "all assets"
|
||||
And I should not see "new snippet"
|
||||
Then I should not see "new snippet"
|
||||
And I should not see "new file"
|
||||
And I should not see "Snippets"
|
||||
And I should not see "Style and javascript"
|
||||
|
@ -3,32 +3,26 @@ module Locomotive
|
||||
class Assets < Base
|
||||
|
||||
def process
|
||||
whitelist = self.build_regexps_in_withlist(database['site']['assets']['whitelist']) rescue nil
|
||||
|
||||
self.log "white list = #{whitelist.inspect}"
|
||||
|
||||
self.add_theme_assets(whitelist)
|
||||
self.add_theme_assets
|
||||
|
||||
self.add_other_assets
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def add_theme_assets(whitelist)
|
||||
def add_theme_assets
|
||||
%w(images media fonts javascripts stylesheets).each do |kind|
|
||||
Dir[File.join(theme_path, 'public', kind, '**/*')].each do |asset_path|
|
||||
|
||||
next if File.directory?(asset_path)
|
||||
|
||||
visible = self.check_against_whitelist(whitelist, asset_path.gsub(File.join(theme_path, 'public'), '').gsub(/^\//, ''))
|
||||
|
||||
folder = asset_path.gsub(File.join(theme_path, 'public'), '').gsub(File.basename(asset_path), '').gsub(/^\//, '').gsub(/\/$/, '')
|
||||
|
||||
asset = site.theme_assets.where(:local_path => File.join(folder, File.basename(asset_path))).first
|
||||
|
||||
asset ||= site.theme_assets.build(:folder => folder)
|
||||
|
||||
asset.attributes = { :source => File.open(asset_path), :performing_plain_text => false, :hidden => !visible }
|
||||
asset.attributes = { :source => File.open(asset_path), :performing_plain_text => false }
|
||||
|
||||
begin
|
||||
asset.save!
|
||||
@ -63,18 +57,6 @@ module Locomotive
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def check_against_whitelist(whitelist, path)
|
||||
(whitelist || []).each do |rule|
|
||||
case rule
|
||||
when Regexp
|
||||
return true if path =~ rule
|
||||
when String
|
||||
return true if path == rule
|
||||
end
|
||||
end
|
||||
false
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
@ -1,4 +1,4 @@
|
||||
# Code taken from Mephisto sources (http://mephistoblog.com/)
|
||||
# Liquify taken from Mephisto sources (http://mephistoblog.com/)
|
||||
module Locomotive
|
||||
module Liquid
|
||||
module Drops
|
||||
@ -6,26 +6,16 @@ module Locomotive
|
||||
|
||||
@@forbidden_attributes = %w{_id _version _index}
|
||||
|
||||
class_inheritable_reader :liquid_attributes
|
||||
write_inheritable_attribute :liquid_attributes, []
|
||||
attr_reader :_source
|
||||
delegate :hash, :to => :_source
|
||||
|
||||
def initialize(source)
|
||||
unless source.nil?
|
||||
@_source = source
|
||||
@liquid = liquid_attributes.flatten.inject({}) { |h, k| h.update k.to_s => @_source.send(k) }
|
||||
end
|
||||
end
|
||||
|
||||
def id
|
||||
(@_source.respond_to?(:id) ? @_source.id : nil) || 'new'
|
||||
end
|
||||
|
||||
def before_method(method)
|
||||
@liquid[method.to_s]
|
||||
end
|
||||
|
||||
# converts an array of records to an array of liquid drops
|
||||
def self.liquify(*records, &block)
|
||||
i = -1
|
||||
|
@ -2,6 +2,7 @@ module Locomotive
|
||||
module Liquid
|
||||
module Drops
|
||||
class Content < Base
|
||||
|
||||
delegate :seo_title, :meta_keywords, :meta_description, :to => '_source'
|
||||
|
||||
def _id
|
||||
|
@ -2,7 +2,8 @@ module Locomotive
|
||||
module Liquid
|
||||
module Drops
|
||||
class Page < Base
|
||||
delegate :seo_title, :meta_keywords, :meta_description, :to => "_source"
|
||||
|
||||
delegate :seo_title, :meta_keywords, :meta_description, :to => '_source'
|
||||
|
||||
def title
|
||||
self._source.templatized? ? @context['content_instance'].highlighted_field_value : self._source.title
|
||||
|
@ -3,14 +3,14 @@ module Locomotive
|
||||
module Drops
|
||||
class Site < Base
|
||||
|
||||
liquid_attributes << :name << :seo_title << :meta_keywords << :meta_description
|
||||
delegate :name, :seo_title, :meta_keywords, :meta_description, :to => '_source'
|
||||
|
||||
def index
|
||||
@index ||= self._source.pages.root.first
|
||||
end
|
||||
|
||||
def pages
|
||||
@pages ||= self._source.pages.to_a.collect(&:to_liquid)
|
||||
@pages ||= liquify(*self._source.pages)
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -130,4 +130,5 @@ $(document).ready(function() {
|
||||
$('.formtastic fieldset.inputs').bind('refresh', function(e) { $(this).find('ol li:not(.item)').removeClass('last').filter(':visible').last().addClass('last'); })
|
||||
.trigger('refresh');
|
||||
|
||||
$('.formtastic fieldset.inputs ol li:not(.item)').last().addClass('last');
|
||||
});
|
||||
|
BIN
spec/fixtures/themes/default.zip
vendored
BIN
spec/fixtures/themes/default.zip
vendored
Binary file not shown.
@ -46,14 +46,6 @@ describe Locomotive::Import::Job do
|
||||
@site.theme_assets.count.should == 10
|
||||
end
|
||||
|
||||
it 'hides some theme assets' do
|
||||
asset = @site.theme_assets.where(:local_path => 'stylesheets/style.css').first
|
||||
asset.hidden.should == false
|
||||
|
||||
asset = @site.theme_assets.where(:local_path => 'stylesheets/ie7.css').first
|
||||
asset.hidden.should == true
|
||||
end
|
||||
|
||||
it 'inserts all the pages' do
|
||||
@site.pages.count.should == 11
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user