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]
|
before_filter :sanitize_params, :only => [:create, :update]
|
||||||
|
|
||||||
def index
|
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] || [])
|
@js_and_css_assets = (@assets[:javascripts] || []) + (@assets[:stylesheets] || [])
|
||||||
|
|
||||||
if request.xhr?
|
if request.xhr?
|
||||||
@ -48,9 +48,6 @@ module Admin
|
|||||||
|
|
||||||
def sanitize_params
|
def sanitize_params
|
||||||
params[:theme_asset] = { :source => params[:file] } if params[:file]
|
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
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -12,7 +12,6 @@ class ThemeAsset
|
|||||||
field :height, :type => Integer
|
field :height, :type => Integer
|
||||||
field :size, :type => Integer
|
field :size, :type => Integer
|
||||||
field :folder, :default => nil
|
field :folder, :default => nil
|
||||||
field :hidden, :type => Boolean, :default => false
|
|
||||||
mount_uploader :source, ThemeAssetUploader
|
mount_uploader :source, ThemeAssetUploader
|
||||||
|
|
||||||
## associations ##
|
## associations ##
|
||||||
@ -35,7 +34,6 @@ class ThemeAsset
|
|||||||
validate :content_type_can_not_changed
|
validate :content_type_can_not_changed
|
||||||
|
|
||||||
## named scopes ##
|
## named scopes ##
|
||||||
scope :visible, lambda { |all| all ? {} : { :where => { :hidden => false } } }
|
|
||||||
|
|
||||||
## accessors ##
|
## accessors ##
|
||||||
attr_accessor :plain_text_name, :plain_text, :plain_text_type, :performing_plain_text
|
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
|
{ :url => self.source.url }.merge(self.attributes).stringify_keys
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.all_grouped_by_folder(site, include_all = true)
|
def self.all_grouped_by_folder(site)
|
||||||
assets = site.theme_assets.visible(include_all).order_by([[:slug, :asc]])
|
assets = site.theme_assets.order_by([[:slug, :asc]])
|
||||||
assets.group_by { |a| a.folder.split('/').first.to_sym }
|
assets.group_by { |a| a.folder.split('/').first.to_sym }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
- edit = local_assigns.key?(:edit) ? edit : true
|
- 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
|
%em
|
||||||
%strong= link_to asset.local_path(!edit), edit ? edit_admin_theme_asset_path(asset) : asset.source.url, :'data-local-path' => asset.local_path
|
%strong= link_to asset.local_path(!edit), edit ? edit_admin_theme_asset_path(asset) : asset.source.url, :'data-local-path' => asset.local_path
|
||||||
.more
|
.more
|
||||||
|
@ -32,6 +32,4 @@
|
|||||||
!= t('admin.theme_assets.form.choose_file')
|
!= t('admin.theme_assets.form.choose_file')
|
||||||
|
|
||||||
= f.foldable_inputs :name => :options do
|
= f.foldable_inputs :name => :options do
|
||||||
= f.input :folder
|
= f.input :folder
|
||||||
= f.custom_input :hidden, :css => 'toggle' do
|
|
||||||
= f.check_box :hidden
|
|
@ -4,7 +4,6 @@
|
|||||||
= render 'admin/shared/menu/settings'
|
= render 'admin/shared/menu/settings'
|
||||||
|
|
||||||
- content_for :buttons do
|
- 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 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)
|
= admin_button_tag :new, new_admin_theme_asset_url, :class => 'new' if can?(:manage, ThemeAsset)
|
||||||
|
|
||||||
|
@ -168,7 +168,6 @@ de:
|
|||||||
index:
|
index:
|
||||||
title: Template-Dateien
|
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."
|
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
|
new: neue Datei
|
||||||
snippets: Snippets
|
snippets: Snippets
|
||||||
css_and_js: Style und Javascript
|
css_and_js: Style und Javascript
|
||||||
|
@ -172,7 +172,6 @@ en:
|
|||||||
index:
|
index:
|
||||||
title: Listing theme files
|
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."
|
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
|
new: new file
|
||||||
snippets: Snippets
|
snippets: Snippets
|
||||||
css_and_js: Style and javascript
|
css_and_js: Style and javascript
|
||||||
|
@ -169,7 +169,6 @@ fr:
|
|||||||
index:
|
index:
|
||||||
title: Liste des fichiers du thème
|
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."
|
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
|
new: nouveau fichier
|
||||||
snippets: Snippets
|
snippets: Snippets
|
||||||
css_and_js: Style et javascript
|
css_and_js: Style et javascript
|
||||||
|
@ -166,7 +166,6 @@ it:
|
|||||||
index:
|
index:
|
||||||
title: Lista file del tema
|
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."
|
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
|
new: nuovo file
|
||||||
snippets: Frammenti
|
snippets: Frammenti
|
||||||
css_and_js: Style e javascript
|
css_and_js: Style e javascript
|
||||||
|
@ -163,7 +163,6 @@ pt-BR:
|
|||||||
index:
|
index:
|
||||||
title: Listando arquivos do tema
|
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."
|
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
|
new: novo arquivo
|
||||||
snippets: Blocos
|
snippets: Blocos
|
||||||
css_and_js: CSS e Javascript
|
css_and_js: CSS e Javascript
|
||||||
|
@ -27,7 +27,6 @@ fr:
|
|||||||
plain_text_name: Nom du fichier
|
plain_text_name: Nom du fichier
|
||||||
content_type: Type du fichier
|
content_type: Type du fichier
|
||||||
folder: Dossier
|
folder: Dossier
|
||||||
hidden: Caché
|
|
||||||
new:
|
new:
|
||||||
source: Fichier
|
source: Fichier
|
||||||
edit:
|
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 tinyMCE => fullscreen
|
||||||
x export site
|
x export site
|
||||||
x rake task to import a remote template
|
x rake task to import a remote template
|
||||||
|
x MERGE
|
||||||
=> 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
|
- overide sort for contents
|
||||||
- icon for redirection page in the pages section (back-office)
|
- 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)
|
- [bushido] guiders / welcome page / devise cas authentication (SSO)
|
||||||
- remove withelist for assets since we've now roles
|
|
||||||
|
|
||||||
|
|
||||||
BACKLOG:
|
BACKLOG:
|
||||||
|
@ -11,12 +11,11 @@ Background:
|
|||||||
Given I am not authenticated
|
Given I am not authenticated
|
||||||
When I go to theme assets
|
When I go to theme assets
|
||||||
Then I should see "Log in"
|
Then I should see "Log in"
|
||||||
|
|
||||||
Scenario: Accessing theme assets as an Admin
|
Scenario: Accessing theme assets as an Admin
|
||||||
Given I am an authenticated "admin"
|
Given I am an authenticated "admin"
|
||||||
When I go to theme assets
|
When I go to theme assets
|
||||||
Then I should see "all assets"
|
Then I should see "new snippet"
|
||||||
And I should see "new snippet"
|
|
||||||
And I should see "new file"
|
And I should see "new file"
|
||||||
And I should see "Snippets"
|
And I should see "Snippets"
|
||||||
And I should see "Style and javascript"
|
And I should see "Style and javascript"
|
||||||
@ -25,8 +24,7 @@ Background:
|
|||||||
Scenario: Accessing theme assets as a Designer
|
Scenario: Accessing theme assets as a Designer
|
||||||
Given I am an authenticated "designer"
|
Given I am an authenticated "designer"
|
||||||
When I go to theme assets
|
When I go to theme assets
|
||||||
Then I should see "all assets"
|
Then I should see "new snippet"
|
||||||
And I should see "new snippet"
|
|
||||||
And I should see "new file"
|
And I should see "new file"
|
||||||
And I should see "Snippets"
|
And I should see "Snippets"
|
||||||
And I should see "Style and javascript"
|
And I should see "Style and javascript"
|
||||||
@ -35,8 +33,7 @@ Background:
|
|||||||
Scenario: Accessing theme assets as an Author
|
Scenario: Accessing theme assets as an Author
|
||||||
Given I am an authenticated "author"
|
Given I am an authenticated "author"
|
||||||
When I go to theme assets
|
When I go to theme assets
|
||||||
Then I should not see "all assets"
|
Then I should not see "new snippet"
|
||||||
And I should not see "new snippet"
|
|
||||||
And I should not see "new file"
|
And I should not see "new file"
|
||||||
And I should not see "Snippets"
|
And I should not see "Snippets"
|
||||||
And I should not see "Style and javascript"
|
And I should not see "Style and javascript"
|
||||||
|
@ -3,32 +3,26 @@ module Locomotive
|
|||||||
class Assets < Base
|
class Assets < Base
|
||||||
|
|
||||||
def process
|
def process
|
||||||
whitelist = self.build_regexps_in_withlist(database['site']['assets']['whitelist']) rescue nil
|
self.add_theme_assets
|
||||||
|
|
||||||
self.log "white list = #{whitelist.inspect}"
|
|
||||||
|
|
||||||
self.add_theme_assets(whitelist)
|
|
||||||
|
|
||||||
self.add_other_assets
|
self.add_other_assets
|
||||||
end
|
end
|
||||||
|
|
||||||
protected
|
protected
|
||||||
|
|
||||||
def add_theme_assets(whitelist)
|
def add_theme_assets
|
||||||
%w(images media fonts javascripts stylesheets).each do |kind|
|
%w(images media fonts javascripts stylesheets).each do |kind|
|
||||||
Dir[File.join(theme_path, 'public', kind, '**/*')].each do |asset_path|
|
Dir[File.join(theme_path, 'public', kind, '**/*')].each do |asset_path|
|
||||||
|
|
||||||
next if File.directory?(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(/\/$/, '')
|
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.where(:local_path => File.join(folder, File.basename(asset_path))).first
|
||||||
|
|
||||||
asset ||= site.theme_assets.build(:folder => folder)
|
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
|
begin
|
||||||
asset.save!
|
asset.save!
|
||||||
@ -63,18 +57,6 @@ module Locomotive
|
|||||||
end
|
end
|
||||||
end
|
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
|
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 Locomotive
|
||||||
module Liquid
|
module Liquid
|
||||||
module Drops
|
module Drops
|
||||||
@ -6,26 +6,16 @@ module Locomotive
|
|||||||
|
|
||||||
@@forbidden_attributes = %w{_id _version _index}
|
@@forbidden_attributes = %w{_id _version _index}
|
||||||
|
|
||||||
class_inheritable_reader :liquid_attributes
|
|
||||||
write_inheritable_attribute :liquid_attributes, []
|
|
||||||
attr_reader :_source
|
attr_reader :_source
|
||||||
delegate :hash, :to => :_source
|
|
||||||
|
|
||||||
def initialize(source)
|
def initialize(source)
|
||||||
unless source.nil?
|
@_source = source
|
||||||
@_source = source
|
|
||||||
@liquid = liquid_attributes.flatten.inject({}) { |h, k| h.update k.to_s => @_source.send(k) }
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def id
|
def id
|
||||||
(@_source.respond_to?(:id) ? @_source.id : nil) || 'new'
|
(@_source.respond_to?(:id) ? @_source.id : nil) || 'new'
|
||||||
end
|
end
|
||||||
|
|
||||||
def before_method(method)
|
|
||||||
@liquid[method.to_s]
|
|
||||||
end
|
|
||||||
|
|
||||||
# converts an array of records to an array of liquid drops
|
# converts an array of records to an array of liquid drops
|
||||||
def self.liquify(*records, &block)
|
def self.liquify(*records, &block)
|
||||||
i = -1
|
i = -1
|
||||||
|
@ -2,6 +2,7 @@ module Locomotive
|
|||||||
module Liquid
|
module Liquid
|
||||||
module Drops
|
module Drops
|
||||||
class Content < Base
|
class Content < Base
|
||||||
|
|
||||||
delegate :seo_title, :meta_keywords, :meta_description, :to => '_source'
|
delegate :seo_title, :meta_keywords, :meta_description, :to => '_source'
|
||||||
|
|
||||||
def _id
|
def _id
|
||||||
|
@ -2,7 +2,8 @@ module Locomotive
|
|||||||
module Liquid
|
module Liquid
|
||||||
module Drops
|
module Drops
|
||||||
class Page < Base
|
class Page < Base
|
||||||
delegate :seo_title, :meta_keywords, :meta_description, :to => "_source"
|
|
||||||
|
delegate :seo_title, :meta_keywords, :meta_description, :to => '_source'
|
||||||
|
|
||||||
def title
|
def title
|
||||||
self._source.templatized? ? @context['content_instance'].highlighted_field_value : self._source.title
|
self._source.templatized? ? @context['content_instance'].highlighted_field_value : self._source.title
|
||||||
|
@ -3,14 +3,14 @@ module Locomotive
|
|||||||
module Drops
|
module Drops
|
||||||
class Site < Base
|
class Site < Base
|
||||||
|
|
||||||
liquid_attributes << :name << :seo_title << :meta_keywords << :meta_description
|
delegate :name, :seo_title, :meta_keywords, :meta_description, :to => '_source'
|
||||||
|
|
||||||
def index
|
def index
|
||||||
@index ||= self._source.pages.root.first
|
@index ||= self._source.pages.root.first
|
||||||
end
|
end
|
||||||
|
|
||||||
def pages
|
def pages
|
||||||
@pages ||= self._source.pages.to_a.collect(&:to_liquid)
|
@pages ||= liquify(*self._source.pages)
|
||||||
end
|
end
|
||||||
|
|
||||||
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'); })
|
$('.formtastic fieldset.inputs').bind('refresh', function(e) { $(this).find('ol li:not(.item)').removeClass('last').filter(':visible').last().addClass('last'); })
|
||||||
.trigger('refresh');
|
.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
|
@site.theme_assets.count.should == 10
|
||||||
end
|
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
|
it 'inserts all the pages' do
|
||||||
@site.pages.count.should == 11
|
@site.pages.count.should == 11
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user