require_capability(:allow_write_gpx)
end
+ ##
+ # require that the user is a moderator, or fill out a helpful error message
+ # and return them to the blocks index.
+ def require_moderator
+ unless @user.moderator?
+ if request.get?
+ flash[:error] = t('application.require_moderator.not_a_moderator')
+ redirect_to :action => 'index'
+ else
+ render :nothing => true, :status => :forbidden
+ end
+ end
+ end
+
##
# sets up the @user object for use by other methods. this is mostly called
# from the authorize method, but can be called elsewhere if authorisation
--- /dev/null
+class RedactionsController < ApplicationController
+ layout 'site'
+
+ before_filter :authorize_web
+ before_filter :set_locale
+ before_filter :require_user, :only => [:new, :create, :edit, :update, :destroy]
+ before_filter :require_moderator, :only => [:new, :create, :edit, :update, :destroy]
+ before_filter :lookup_redaction, :only => [:show, :edit, :update, :destroy]
+ before_filter :check_database_readable
+ before_filter :check_database_writable, :only => [:create, :update, :destroy]
+
+ def index
+ @redactions_pages, @redactions = paginate(:redactions, :order => :id, :per_page => 10)
+ end
+
+ def new
+ @redaction = Redaction.new
+ end
+
+ def create
+ @redaction = Redaction.new
+ @redaction.user_id = @user.id
+ @redaction.title = params[:redaction][:title]
+ @redaction.description = params[:redaction][:description]
+ # didn't see this come in from the form - maybe i'm doing something
+ # wrong, or markdown is the only thing supported at the moment?
+ @redaction.description_format = 'markdown'
+
+ if @redaction.save
+ flash[:notice] = t('redaction.create.flash')
+ redirect_to @redaction
+ else
+ render :action => 'new'
+ end
+ end
+
+ def show
+ end
+
+ def edit
+ end
+
+ def update
+ # note - don't update the user ID
+
+ if params[:redaction][:title] and params[:redaction][:title] != @redaction.title
+ @redaction.title = params[:redaction][:title]
+ end
+
+ if params[:redaction][:description] and params[:redaction][:description] != @redaction.description
+ @redaction.description = params[:redaction][:description]
+ end
+
+ if @redaction.save
+ flash[:notice] = t('redaction.update.flash')
+ redirect_to @redaction
+ else
+ render :action => 'edit'
+ end
+ end
+
+ def destroy
+ unless @redaction.old_nodes.empty? and
+ @redaction.old_ways.empty? and
+ @redaction.old_relations.empty?
+ flash[:error] = t('redaction.destroy.not_empty')
+ redirect_to @redaction
+ else
+ if @redaction.destroy
+ flash[:notice] = t('redaction.destroy.flash')
+ redirect_to :index
+ else
+ flash[:error] = t('redaction.destroy.error')
+ redirect_to @redaction
+ end
+ end
+ end
+
+ private
+
+ def lookup_redaction
+ @redaction = Redaction.find(params[:id])
+ end
+end
end
private
- ##
- # require that the user is a moderator, or fill out a helpful error message
- # and return them to the blocks index.
- def require_moderator
- unless @user.moderator?
- if request.get?
- flash[:error] = t('user_block.filter.not_a_moderator')
- redirect_to :action => 'index'
- else
- render :nothing => true, :status => :forbidden
- end
- end
- end
-
##
# ensure that there is a "user_block" instance variable
def lookup_user_block
# displayed linked from the redacted records.
#
class Redaction < ActiveRecord::Base
- has_many :nodes
- has_many :ways
- has_many :relations
+ belongs_to :user
+
+ has_many :old_nodes
+ has_many :old_ways
+ has_many :old_relations
+
+ def description
+ RichText.new(read_attribute(:description_format), read_attribute(:description))
+ end
end
--- /dev/null
+<li><%= link_to h(redaction.title), :controller => 'redaction', :action => 'show', :id => redaction.id %></li>
--- /dev/null
+<ul id="redaction_list">
+ <%= render :partial => 'redaction', :collection => @redactions %>
+</ul>
--- /dev/null
+<% @title = t 'redaction.edit.title' %>
+<h1><%= t 'redaction.edit.heading' %></h1>
+
+<%= form_for(@redaction) do |f| %>
+ <%= f.error_messages %>
+
+ <p>
+ <%= f.label :title, t('redaction.edit.title') %><br />
+ <%= f.text_field :title %>
+ </p>
+ <p>
+ <%= f.label :description, t('redaction.edit.description') %><br />
+ <%= richtext_area :redaction, :description, :cols => 80, :rows => 20, :format => @redaction.description_format %>
+ </p>
+ <p>
+ <%= f.submit t('redaction.edit.submit') %>
+ </p>
+<% end %>
+
--- /dev/null
+<% @title = t('redaction.index.title') %>
+<h1><%= t('redaction.index.heading') %></h1>
+
+<% unless @redactions.empty? %>
+ <%= render :partial => 'redactions' %>
+<% else %>
+ <p><%= t 'redaction.index.empty' %></p>
+<% end %>
--- /dev/null
+<% @title = t 'redaction.new.title' %>
+<h1><%= t 'redaction.new.heading' %></h1>
+
+<%= form_for(@redaction) do |f| %>
+ <%= f.error_messages %>
+
+ <p>
+ <%= f.label :title, t('redaction.new.title') %><br />
+ <%= f.text_field :title %>
+ </p>
+ <p>
+ <%= f.label :description, t('redaction.new.description') %><br />
+ <%= richtext_area :redaction, :description, :cols => 80, :rows => 20, :format => @redaction.description_format %>
+ </p>
+ <p>
+ <%= f.submit t('redaction.new.submit') %>
+ </p>
+<% end %>
+
+
--- /dev/null
+<% @title = t('redaction.show.title') %>
+<h1><%= t('redaction.show.heading', :title => @redaction.title) %></h1>
+
+<p>
+ <b><%= t 'redaction.show.user' %></b>
+ <%= link_to(h(@redaction.user.display_name), {:controller => 'user', :action => 'view', :display_name => @redaction.user.display_name}) %>
+</p>
+<p>
+ <b><%= t 'redaction.show.description' %></b>
+ <%= @redaction.description.to_html %>
+</p>
+
+<% if @user and @user.moderator? %>
+<%= link_to t('redaction.show.edit'), edit_redaction_path(@redaction) %>
+<%= button_to(t('redaction.show.destroy'), @redaction, :confirm => t('redaction.show.confirm'), :method => "delete", :remote => true) %>
+<% end %>
application:
require_cookies:
cookies_needed: "You appear to have cookies disabled - please enable cookies in your browser before continuing."
+ require_moderator:
+ not_a_moderator: "You need to be a moderator to perform that action."
setup_user_auth:
blocked: "Your access to the API has been blocked. Please log-in to the web interface to find out more."
need_to_see_terms: "Your access to the API is temporarily suspended. Please log-in to the web interface to view the Contributor Terms. You do not need to agree, but you must view them."
back: "View all blocks"
needs_view: "Does the user need to log in before this block will be cleared?"
filter:
- not_a_moderator: "You need to be a moderator to perform that action."
block_expired: "The block has already expired and cannot be edited."
block_period: "The blocking period must be one of the values selectable in the drop-down list."
create:
history_tooltip: View edits for this area
history_disabled_tooltip: Zoom in to view edits for this area
history_zoom_alert: You must zoom in to view edits for this area
+ redaction:
+ edit:
+ description: "Description"
+ heading: "Edit redaction"
+ submit: "Save redaction"
+ title: "Edit redaction"
+ index:
+ empty: "No redactions to show."
+ heading: "List of redactions"
+ title: "List of redactions"
+ new:
+ description: "Description"
+ heading: "Enter information for new redaction"
+ submit: "Create redaction"
+ title: "Creating new redaction"
+ show:
+ description: "Description"
+ heading: "Showing redaction \"%{title}\""
+ title: "Showing redaction"
+ user: "Creator:"
+ edit: "Edit this redaction."
+ destroy: "Remove this redaction"
+ confirm: "Are you sure?"
+ create:
+ flash: "Redaction created."
+ update:
+ flash: "Changes saved."
+ destroy:
+ not_empty: "Redaction is not empty. Please un-redact all versions belonging to this redaction before destroying it."
+ flash: "Redaction destroyed."
+ error: "There was an error destroying this redaction."
match '/blocks/new/:display_name' => 'user_blocks#new', :via => :get, :as => "new_user_block"
resources :user_blocks
match '/blocks/:id/revoke' => 'user_blocks#revoke', :via => [:get, :post], :as => "revoke_user_block"
+
+ # redactions
+ resources :redactions
end
remove_foreign_key tbl, [:redaction_id], :redactions, [:id]
remove_column tbl, :redaction_id
end
-
+
drop_table :redactions
end
end
--- /dev/null
+require 'migrate'
+
+class AddUserAndDescriptionToRedaction < ActiveRecord::Migration
+ def up
+ add_column :redactions, :user_id, :bigint, :null => false
+ add_column :redactions, :description_format, :format_enum, :null => false, :default => "markdown"
+
+ add_foreign_key :redactions, [:user_id], :users, [:id]
+ end
+
+ def down
+ remove_foreign_key :redactions, [:user_id], :users, [:id]
+
+ remove_column :redactions, :description_format
+ remove_column :redactions, :user_id
+ end
+end