Skip to content

Commit

Permalink
read_only improvements: interface and multihost
Browse files Browse the repository at this point in the history
  • Loading branch information
ethn committed Feb 10, 2012
1 parent 8d5674f commit 3161eb2
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 14 deletions.
3 changes: 3 additions & 0 deletions app/models/multihost_mapping.rb
Expand Up @@ -32,6 +32,9 @@ def set_base_url(mapping)

def set_connection(wagn_name)
ActiveRecord::Base.connection.schema_search_path = wagn_name
if Hash===System.read_only_hosts
System.read_only = !!System.read_only_host[wagn_name]
end
end
end

Expand Down
4 changes: 2 additions & 2 deletions app/models/system.rb
Expand Up @@ -6,7 +6,7 @@ class System
:base_url, :max_render_time, :max_renders, # Common; docs in sample_wagn.rb
:enable_ruby_cards, :enable_server_cards, # Uncommon; Check Security risks before enabling these cardtypes (wagn.org ref url?)
:enable_postgres_fulltext, :postgres_src_dir, :postgres_tsearch_dir, # Optimize PostgreSQL performance
:multihost,:wagn_name
:multihost, :wagn_name, :read_only, :read_only_hosts

Wagn::Configuration.wagn_load_config

Expand Down Expand Up @@ -79,7 +79,7 @@ def logo
# PERMISSIONS

def read_only?()
@@read_only ||= (ro=ENV['WAGN_READ_ONLY']) && ro != 'false'
@@read_only.nil? ? (ro=ENV['WAGN_READ_ONLY'] and ro != 'false') : @@read_only
end

def ok?(task)
Expand Down
23 changes: 14 additions & 9 deletions app/views/card/denied.rhtml
Expand Up @@ -11,17 +11,22 @@
<h1>Ooo. Sorry, but...</h1> <%#ENGLISH%>

<p>
<% if User.current_user.anonymous? %>
You have to <%= link_to "sign in", :controller=>'account', :action=>'signin' %>
<% if @deny != 'view' && System.read_only? %>
<div>We are currently in read-only mode. Please try again later.</div>
<% else %>
You need permission
<% if User.current_user.anonymous? %>
You have to <%= link_to "sign in", :controller=>'account', :action=>'signin' %>
<% else %>
You need permission
<% end %>
to
<%= case @deny
when 'view', 'edit' ; @deny+ " " + (card.name ? "<strong>#{fancy_title(card)}</strong>" : 'this card')
when 'create'; "create #{@type} cards"
end
%>
<% end %>
to
<%= case @deny
when 'view', 'edit' ; @deny+ " " + (card.name ? "<strong>#{fancy_title(card)}</strong>" : 'this card')
when 'create'; "create #{@type} cards"
end
%>
</p>

<% unless @skip_slot_header or @deny=='view' %>
Expand Down
6 changes: 3 additions & 3 deletions lib/wagn/model/permissions.rb
Expand Up @@ -137,9 +137,9 @@ def lets_user(operation)
User.as_user.among?( who_can(operation) )
end

def approve_task(operation, verb=nil)
verb ||= operation.to_s
deny_because(you_cant "#{verb} this card") unless self.lets_user( operation )
def approve_task(operation, verb=nil)
deny_because( "Currently in read-only mode" ) if operation != :read && System.read_only?
deny_because( you_cant("#{verb || operation} this card") ) unless self.lets_user( operation )
end

def approve_create
Expand Down

0 comments on commit 3161eb2

Please sign in to comment.