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