]> git.openstreetmap.org Git - rails.git/blob - app/controllers/redactions_controller.rb
Stop the data browser leaking details of redactions
[rails.git] / app / controllers / redactions_controller.rb
1 class RedactionsController < ApplicationController
2   layout 'site'
3   
4   before_filter :authorize_web
5   before_filter :set_locale
6   before_filter :require_user, :only => [:new, :create, :edit, :update, :destroy]
7   before_filter :require_moderator, :only => [:new, :create, :edit, :update, :destroy]
8   before_filter :lookup_redaction, :only => [:show, :edit, :update, :destroy]
9   before_filter :check_database_readable
10   before_filter :check_database_writable, :only => [:create, :update, :destroy]
11
12   def index
13     @redactions_pages, @redactions = paginate(:redactions, :order => :id, :per_page => 10)
14   end
15
16   def new
17     @redaction = Redaction.new
18   end
19      
20   def create
21     @redaction = Redaction.new
22     @redaction.user_id = @user.id
23     @redaction.title = params[:redaction][:title]
24     @redaction.description = params[:redaction][:description]
25     # didn't see this come in from the form - maybe i'm doing something
26     # wrong, or markdown is the only thing supported at the moment?
27     @redaction.description_format = 'markdown'
28
29     if @redaction.save
30       flash[:notice] = t('redaction.create.flash')
31       redirect_to @redaction
32     else
33       render :action => 'new'
34     end
35   end
36      
37   def show
38   end
39   
40   def edit
41   end
42      
43   def update
44     # note - don't update the user ID
45     
46     if params[:redaction][:title] and params[:redaction][:title] != @redaction.title
47       @redaction.title = params[:redaction][:title]
48     end
49
50     if params[:redaction][:description] and params[:redaction][:description] != @redaction.description
51       @redaction.description = params[:redaction][:description]
52     end
53
54     if @redaction.save
55       flash[:notice] = t('redaction.update.flash')
56       redirect_to @redaction
57     else
58       render :action => 'edit'
59     end
60   end
61      
62   def destroy
63     unless @redaction.old_nodes.empty? and
64         @redaction.old_ways.empty? and
65         @redaction.old_relations.empty?
66       flash[:error] = t('redaction.destroy.not_empty')
67       redirect_to @redaction
68     else
69       if @redaction.destroy
70         flash[:notice] = t('redaction.destroy.flash')
71         redirect_to :index
72       else
73         flash[:error] = t('redaction.destroy.error')
74         redirect_to @redaction
75       end
76     end
77   end
78
79   private
80
81   def lookup_redaction
82     @redaction = Redaction.find(params[:id])
83   end
84 end