Compare commits

..

4 Commits

Author SHA1 Message Date
John Bintz
33b3e5a600 stupid simple support for a granular permissions system based on a content types table. h@xx 2012-06-22 15:40:15 -04:00
John Bintz
60cb10c4ca tweak 2012-06-20 15:18:49 -04:00
John Bintz
07e37d0521 mounted_on uses url_for 2012-06-20 10:38:06 -04:00
John Bintz
07f868594a basic suport for subdirectories 2012-06-20 10:28:10 -04:00
6 changed files with 35 additions and 6 deletions

View File

@ -22,26 +22,31 @@ module Locomotive
def show
@content_entry = @content_type.entries.find(params[:id])
authorize! params[:action].to_sym, @content_entry
respond_with @content_entry
end
def new
@content_entry = @content_type.entries.build
authorize! params[:action].to_sym, @content_entry
respond_with @content_entry
end
def create
@content_entry = @content_type.entries.create(params[:content_entry])
authorize! params[:action].to_sym, @content_entry
respond_with @content_entry, :location => edit_content_entry_url(@content_type.slug, @content_entry._id)
end
def edit
@content_entry = @content_type.entries.find(params[:id])
authorize! params[:action].to_sym, @content_entry
respond_with @content_entry
end
def update
@content_entry = @content_type.entries.find(params[:id])
authorize! params[:action].to_sym, @content_entry
@content_entry.update_attributes(params[:content_entry])
respond_with @content_entry, :location => edit_content_entry_url(@content_type.slug, @content_entry._id)
end
@ -51,8 +56,10 @@ module Locomotive
respond_with @content_type
end
def destroy
@content_entry = @content_type.entries.find(params[:id])
authorize! params[:action].to_sym, @content_entry
@content_entry.destroy
respond_with @content_entry, :location => content_entries_url(@content_type.slug)
end

View File

@ -32,7 +32,19 @@ module Locomotive
can :touch, [Page, ThemeAsset]
can :sort, Page
can :manage, [ContentEntry, ContentAsset]
can :manage, [ContentEntry, ContentAsset] do |entry|
result = true
if perm_defs = ContentType.where(:slug => 'permissions').first
perms = perm_defs.entries.where(:user_email => @account.email).collect(&:types).collect { |types| types.split(',') }.flatten
if !perms.empty?
result = perms.any? { |perm| perm == entry.content_type.slug }
end
end
result
end
can :touch, Site do |site|
site == @site

View File

@ -7,7 +7,7 @@
= render 'locomotive/shared/actions/contents'
- content_for :buttons do
= local_action_button :show, "/#{@page.fullpath}", :class => 'show'
= local_action_button :show, current_site_public_url + '/' + @page.fullpath, :class => 'show'
%p!= t('.help')

View File

@ -123,7 +123,16 @@ module Locomotive
end
def self.mounted_on
Rails.application.routes.named_routes[:locomotive].path.spec.to_s
url_for(Rails.application.routes.named_routes[:locomotive].path.spec.to_s)
end
def self.url_for(path)
result = path
if config.base_uri && !path[%r{^#{config.base_uri}}]
result = "#{config.base_uri}/#{path.gsub(%r{^/}, '')}"
end
result = "/#{result}" if result[0..0] != '/'
result
end
protected

View File

@ -9,7 +9,7 @@ module Locomotive
end
def current_site_public_url
request.protocol + request.host_with_port
request.protocol + request.host_with_port + (Locomotive.config.base_uri || '')
end
def switch_to_site_url(site, options = {})

View File

@ -13,6 +13,7 @@ module Locomotive
:enable_logs => false,
:delayed_job => false,
:default_locale => :en,
:base_uri => nil,
:mailer_sender => 'support@example.com',
:manage_subdomain => false,
:manage_manage_domains => false,