Link to 'all messages' in message email fixed, added "delete_all" action
This commit is contained in:
@@ -75,4 +75,4 @@ class ApplicationController < ActionController::Base
|
||||
!!(current_user && current_user.confirmed?)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,35 +1,32 @@
|
||||
class MessagesController < ApplicationController
|
||||
|
||||
before_filter :check_permission, only: [:destroy]
|
||||
before_filter :check_permission, only: :destroy
|
||||
|
||||
def index
|
||||
if !current_user
|
||||
if current_user
|
||||
@messages = Message.where(user_target: current_user).page(params[:page])
|
||||
else
|
||||
flash[:alert] = "Please log in to see your private messages."
|
||||
redirect_to blogposts_path
|
||||
end
|
||||
@messages = Message.where(user_target: current_user).page(params[:page])
|
||||
end
|
||||
|
||||
def destroy
|
||||
if @message.user_target.is?(current_user)
|
||||
if @message.destroy
|
||||
flash[:notice] = "Message deleted!"
|
||||
else
|
||||
flash[:alert] = "There was a problem while deleting this message"
|
||||
end
|
||||
def new
|
||||
if current_user
|
||||
@message = Message.new
|
||||
else
|
||||
flash[:alert] = "You are not allowed to delete this message"
|
||||
flash[:alert] = "Please log in to send a private message."
|
||||
redirect_to blogposts_path
|
||||
end
|
||||
redirect_to messages_path
|
||||
end
|
||||
|
||||
def create
|
||||
if !message_params[:user_target_id]
|
||||
unless message_params[:user_target_id]
|
||||
flash[:alert] = "Please enter a valid IGN before sending."
|
||||
redirect_to new_message_path
|
||||
return
|
||||
end
|
||||
if message_params[:text] == ""
|
||||
if message_params[:text].blank?
|
||||
flash[:alert] = "Please write a message before sending."
|
||||
redirect_to new_message_path
|
||||
return
|
||||
@@ -40,21 +37,33 @@ class MessagesController < ApplicationController
|
||||
@message.send_new_message_mail
|
||||
flash[:notice] = "Message sent!"
|
||||
redirect_to messages_path
|
||||
return
|
||||
else
|
||||
flash[:alert] = "Something went wrong while creating your message."
|
||||
render action: "new"
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
def new
|
||||
if !current_user
|
||||
flash[:alert] = "Please log in to send a private message."
|
||||
redirect_to blogposts_path
|
||||
return
|
||||
def destroy
|
||||
if @message.user_target.is?(current_user)
|
||||
if @message.destroy
|
||||
flash[:notice] = "Message deleted!"
|
||||
else
|
||||
flash[:alert] = "There was a problem while deleting this message."
|
||||
end
|
||||
else
|
||||
flash[:alert] = "You are not allowed to delete this message."
|
||||
end
|
||||
@message = Message.new
|
||||
redirect_to messages_path
|
||||
end
|
||||
|
||||
def destroy_all
|
||||
Message.destroy_all(user_target_id: current_user.id)
|
||||
if Message.where(user_target_id: current_user.id).empty?
|
||||
flash[:notice] = "Your messages have been deleted!"
|
||||
else
|
||||
flash[:alert] = "There was a problem while deleting your messages."
|
||||
end
|
||||
redirect_to messages_path
|
||||
end
|
||||
|
||||
def message_params(add = [])
|
||||
|
||||
@@ -90,4 +90,4 @@ module ApplicationHelper
|
||||
https://www.youtube-nocookie.com/embed/\\1?theme=light&vq=hd720&hd=1&iv_load_policy=3&showinfo=1&showsearch=0&rel=0&modestbranding&hd=1&autohide=1&html5=1&start=\\3'>
|
||||
</iframe>")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -52,4 +52,4 @@ module UsersHelper
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,5 +1,16 @@
|
||||
<% if @messages.any? %>
|
||||
<%= link_to "Delete all messages", destroy_all_messages_path, method: "post", class: "btn blue right", data: {confirm: "Delete all of your messages forever?"} %>
|
||||
<% end %>
|
||||
<%= link_to "Create new message", new_message_path, class: "btn blue right" %>
|
||||
<h3>Your private messages:</h3>
|
||||
<br>
|
||||
<h2>
|
||||
<% if Message.where(user_target_id: current_user.id).any? %>
|
||||
Your private messages:
|
||||
<% else %>
|
||||
You have no private messages.
|
||||
<% end %>
|
||||
</h2>
|
||||
|
||||
<div id="forum_groups">
|
||||
<% @messages.each do |message| %>
|
||||
<div class="item-group with-avatar">
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
<%= render_md(@message.text).html_safe %>
|
||||
</blockquote>
|
||||
|
||||
<p><%= link_to "Click here", messages_path %> to view your current messages.</p>
|
||||
<p><%= link_to "Click here", messages_url %> to view your current messages.</p>
|
||||
|
||||
<p>If you have any questions or problems, just ask one of our <%= link_to "Staff", users_url(role: "staff"), style: "text-decoration: none; color: #4096EE;" %> in-game or on the forums!</p>
|
||||
<p>Your Redstoner team</p>
|
||||
|
||||
@@ -42,6 +42,9 @@ Redstoner::Application.routes.draw do
|
||||
end
|
||||
|
||||
resources :messages do
|
||||
collection do
|
||||
post 'destroy_all'
|
||||
end
|
||||
end
|
||||
|
||||
# get '/status' => 'status#show'
|
||||
|
||||
Reference in New Issue
Block a user