]> git.openstreetmap.org Git - rails.git/blob - app/controllers/redactions_controller.rb
Improve error handling for routing engines
[rails.git] / app / controllers / redactions_controller.rb
1 class RedactionsController < ApplicationController
2   layout "site"
3
4   before_action :authorize_web
5   before_action :set_locale
6   before_action :require_user, :only => [:new, :create, :edit, :update, :destroy]
7   before_action :require_moderator, :only => [:new, :create, :edit, :update, :destroy]
8   before_action :lookup_redaction, :only => [:show, :edit, :update, :destroy]
9   before_action :check_database_readable
10   before_action :check_database_writable, :only => [:create, :update, :destroy]
11
12   def index
13     @redactions = Redaction.order(:id)
14   end
15
16   def new
17     @redaction = Redaction.new
18   end
19
20   def create
21     @redaction = Redaction.new
22     @redaction.user = @user
23     @redaction.title = params[:redaction][:title]
24     @redaction.description = params[:redaction][:description]
25     # note that the description format will default to 'markdown'
26
27     if @redaction.save
28       flash[:notice] = t("redaction.create.flash")
29       redirect_to @redaction
30     else
31       render :action => "new"
32     end
33   end
34
35   def show
36   end
37
38   def edit
39   end
40
41   def update
42     # note - don't update the user ID
43     @redaction.title = params[:redaction][:title]
44     @redaction.description = params[:redaction][:description]
45
46     if @redaction.save
47       flash[:notice] = t("redaction.update.flash")
48       redirect_to @redaction
49     else
50       render :action => "edit"
51     end
52   end
53
54   def destroy
55     if @redaction.old_nodes.empty? &&
56        @redaction.old_ways.empty? &&
57        @redaction.old_relations.empty?
58       if @redaction.destroy
59         flash[:notice] = t("redaction.destroy.flash")
60         redirect_to :redactions
61       else
62         flash[:error] = t("redaction.destroy.error")
63         redirect_to @redaction
64       end
65     else
66       flash[:error] = t("redaction.destroy.not_empty")
67       redirect_to @redaction
68     end
69   end
70
71   private
72
73   def lookup_redaction
74     @redaction = Redaction.find(params[:id])
75   end
76 end