]> git.openstreetmap.org Git - rails.git/blob - app/controllers/user_mutes_controller.rb
Merge pull request #4401 from KasperFranz/buried-wikidata
[rails.git] / app / controllers / user_mutes_controller.rb
1 class UserMutesController < ApplicationController
2   include UserMethods
3
4   layout "site"
5
6   before_action :authorize_web
7   before_action :set_locale
8
9   authorize_resource
10
11   before_action :lookup_user, :only => [:create, :destroy]
12   before_action :check_database_readable
13   before_action :check_database_writable, :only => [:create, :destroy]
14
15   def index
16     @muted_users = current_user.muted_users
17     @title = t ".title"
18
19     redirect_to edit_account_path unless @muted_users.any?
20   end
21
22   def create
23     user_mute = current_user.mutes.build(:subject => @user)
24
25     if user_mute.save
26       flash[:notice] = t(".notice", :name => user_mute.subject.display_name)
27     else
28       flash[:error] = t(".error", :name => user_mute.subject.display_name, :full_message => user_mute.errors.full_messages.to_sentence.humanize)
29     end
30
31     redirect_back_or_to user_mutes_path(current_user)
32   end
33
34   def destroy
35     user_mute = current_user.mutes.find_by!(:subject => @user)
36
37     if user_mute.destroy
38       flash[:notice] = t(".notice", :name => user_mute.subject.display_name)
39     else
40       flash[:error] = t(".error")
41     end
42
43     redirect_back_or_to user_mutes_path(current_user)
44   end
45 end