Added redactions resource
This commit is contained in:
parent
9519f26241
commit
851de28303
14 changed files with 228 additions and 19 deletions
|
@ -111,6 +111,20 @@ class ApplicationController < ActionController::Base
|
|||
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
|
||||
|
|
84
app/controllers/redactions_controller.rb
Normal file
84
app/controllers/redactions_controller.rb
Normal file
|
@ -0,0 +1,84 @@
|
|||
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
|
|
@ -106,20 +106,6 @@ class UserBlocksController < ApplicationController
|
|||
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
|
||||
|
|
|
@ -8,7 +8,13 @@
|
|||
# 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
|
||||
|
|
1
app/views/redactions/_redaction.html.erb
Normal file
1
app/views/redactions/_redaction.html.erb
Normal file
|
@ -0,0 +1 @@
|
|||
<li><%= link_to h(redaction.title), :controller => 'redaction', :action => 'show', :id => redaction.id %></li>
|
3
app/views/redactions/_redactions.html.erb
Normal file
3
app/views/redactions/_redactions.html.erb
Normal file
|
@ -0,0 +1,3 @@
|
|||
<ul id="redaction_list">
|
||||
<%= render :partial => 'redaction', :collection => @redactions %>
|
||||
</ul>
|
19
app/views/redactions/edit.html.erb
Normal file
19
app/views/redactions/edit.html.erb
Normal file
|
@ -0,0 +1,19 @@
|
|||
<% @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 %>
|
||||
|
8
app/views/redactions/index.html.erb
Normal file
8
app/views/redactions/index.html.erb
Normal file
|
@ -0,0 +1,8 @@
|
|||
<% @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 %>
|
20
app/views/redactions/new.html.erb
Normal file
20
app/views/redactions/new.html.erb
Normal file
|
@ -0,0 +1,20 @@
|
|||
<% @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 %>
|
||||
|
||||
|
16
app/views/redactions/show.html.erb
Normal file
16
app/views/redactions/show.html.erb
Normal file
|
@ -0,0 +1,16 @@
|
|||
<% @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 %>
|
|
@ -1522,6 +1522,8 @@ en:
|
|||
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."
|
||||
|
@ -1921,7 +1923,6 @@ en:
|
|||
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:
|
||||
|
@ -1999,3 +2000,34 @@ en:
|
|||
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."
|
||||
|
|
|
@ -229,4 +229,7 @@ OpenStreetMap::Application.routes.draw do
|
|||
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
|
||||
|
|
|
@ -20,7 +20,7 @@ class CreateRedactions < ActiveRecord::Migration
|
|||
remove_foreign_key tbl, [:redaction_id], :redactions, [:id]
|
||||
remove_column tbl, :redaction_id
|
||||
end
|
||||
|
||||
|
||||
drop_table :redactions
|
||||
end
|
||||
end
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
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
|
Loading…
Add table
Add a link
Reference in a new issue