summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMrYummy <elemental428@gmail.com>2017-06-12 21:14:35 +0200
committerMrYummy <elemental428@gmail.com>2017-06-12 21:17:18 +0200
commit895e56ff0671f23c14e1a74d7e168126a9399c36 (patch)
treecee6abfed2282cbcfeae5d8656d86b3949acb332
parent68ee779c11e7d7fbaece844f34f2a7a4ed19a64b (diff)
Link to 'all messages' in message email fixed, added "delete_all" action
-rw-r--r--app/controllers/application_controller.rb2
-rw-r--r--app/controllers/messages_controller.rb53
-rw-r--r--app/helpers/application_helper.rb2
-rw-r--r--app/helpers/users_helper.rb2
-rw-r--r--app/views/messages/index.html.erb13
-rw-r--r--app/views/redstoner_mailer/new_message_mail.html.erb2
-rw-r--r--config/routes.rb3
7 files changed, 50 insertions, 27 deletions
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb
index a0e166e..d489611 100644
--- a/app/controllers/application_controller.rb
+++ b/app/controllers/application_controller.rb
@@ -75,4 +75,4 @@ class ApplicationController < ActionController::Base
!!(current_user && current_user.confirmed?)
end
-end \ No newline at end of file
+end
diff --git a/app/controllers/messages_controller.rb b/app/controllers/messages_controller.rb
index 4bcd954..6655ea6 100644
--- a/app/controllers/messages_controller.rb
+++ b/app/controllers/messages_controller.rb
@@ -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 = [])
diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb
index 1419391..90e4ce2 100644
--- a/app/helpers/application_helper.rb
+++ b/app/helpers/application_helper.rb
@@ -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 \ No newline at end of file
+end
diff --git a/app/helpers/users_helper.rb b/app/helpers/users_helper.rb
index 2ce1765..7ad99d8 100644
--- a/app/helpers/users_helper.rb
+++ b/app/helpers/users_helper.rb
@@ -52,4 +52,4 @@ module UsersHelper
end
end
-end \ No newline at end of file
+end
diff --git a/app/views/messages/index.html.erb b/app/views/messages/index.html.erb
index 20e5b92..562c14e 100644
--- a/app/views/messages/index.html.erb
+++ b/app/views/messages/index.html.erb
@@ -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">
diff --git a/app/views/redstoner_mailer/new_message_mail.html.erb b/app/views/redstoner_mailer/new_message_mail.html.erb
index 08cd2ba..42be00e 100644
--- a/app/views/redstoner_mailer/new_message_mail.html.erb
+++ b/app/views/redstoner_mailer/new_message_mail.html.erb
@@ -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>
diff --git a/config/routes.rb b/config/routes.rb
index 08f50e0..309b96a 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -42,6 +42,9 @@ Redstoner::Application.routes.draw do
end
resources :messages do
+ collection do
+ post 'destroy_all'
+ end
end
# get '/status' => 'status#show'