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