add notification settings, fix comment edit permissions

This commit is contained in:
jomo
2014-06-17 21:19:15 +02:00
parent 2564ea1aa6
commit 8a7d719920
9 changed files with 114 additions and 38 deletions

View File

@@ -4,7 +4,7 @@ class CommentsController < ApplicationController
def edit
@comment = Comment.find(params[:id])
if mod? || @comment.author.is?(current_user)
if (mod? && current_user.role >= @comment.author.role) || @comment.author.is?(current_user)
else
flash[:alert] = "You are not allowed to edit this comment"
redirect_to @comment.blogpost
@@ -49,7 +49,7 @@ class CommentsController < ApplicationController
def destroy
@comment = Comment.find(params[:id])
if mod? || @comment.author.is?(current_user)
if (mod? && current_user.role >= @comment.author.role) || @comment.author.is?(current_user)
if @comment.destroy
flash[:notice] = "Comment deleted!"
else

View File

@@ -204,6 +204,14 @@ class UsersController < ApplicationController
end
end
def edit_notifications
@user = User.find(params[:id])
unless @user.is?(current_user) || admin? && current_user.role > @user.role || superadmin?
flash[:alert] = "You are not allowed to edit this user's notification settings!"
redirect_to @user
end
end
def edit_login
@user = User.find(params[:id])
unless @user.is?(current_user) || admin? && current_user.role > @user.role || superadmin?
@@ -267,7 +275,7 @@ class UsersController < ApplicationController
end
def user_params(add = [])
a = [:ign, :email, :password, :password_confirmation] + add
a = [:ign, :email, :password, :password_confirmation, :mail_own_thread_reply, :mail_other_thread_reply, :mail_own_blogpost_comment, :mail_other_blogpost_comment, :mail_mention] + add
params.require(:user).permit(a)
end
end

View File

@@ -31,13 +31,13 @@ class Comment < ActiveRecord::Base
def send_new_comment_mail
userids = []
# thread + replies
posts = blogpost.comments.to_a
posts << blogpost # if thread.author.send_own_post_comment_mail (TODO)
posts.each do |post|
# don't send mail to the author, don't send to banned/disabled users
if post.author != author && post.author.normal? && post.author.confirmed? # &&
userids << post.author.id # && post.author.send_commented_comment_mail (TODO)
# post + comments
comments = blogpost.comments.to_a
comments << blogpost if blogpost.author.mail_own_blogpost_comment?
comments.each do |comment|
# don't send mail to the author of this comment, don't send to banned/disabled users
if comment.author != author && comment.author.normal? && comment.author.confirmed? # &&
userids << comment.author.id if comment.author.mail_other_blogpost_comment?
end
end
# making sure we don't send multiple mails to the same user

View File

@@ -37,11 +37,11 @@ class Threadreply < ActiveRecord::Base
# thread + replies
posts = thread.replies.to_a
posts << thread # if thread.author.send_own_thread_reply_mail (TODO)
posts << thread if thread.author.mail_own_thread_reply?
posts.each do |post|
# don't send mail to the author, don't send to banned/disabled users
# don't send mail to the author of this reply, don't send to banned/disabled users
if post.author != author && post.author.normal? && post.author.confirmed? # &&
userids << post.author.id # && post.author.send_replied_reply_mail (TODO)
userids << post.author.id if post.author.mail_other_thread_reply?
end
end
# making sure we don't send multiple mails to the same user

View File

@@ -68,7 +68,10 @@
</table>
<p><%= f.submit "Save profile", class: "btn blue left", disabled: (!@user.confirmed? && @user.is?(current_user)) %></p>
<p><%= link_to "Edit login details", edit_login_user_path(@user), class: "btn blue right" %></p>
<p>
<%= link_to "Edit login details", edit_login_user_path(@user), class: "btn blue right" %>
<%= link_to "Notification settings", edit_notifications_user_path(@user), class: "btn blue right" %>
</p>
<div class="clear"></div>
<% if !@user.confirmed? %>

View File

@@ -0,0 +1,51 @@
<% title "Edit Notification Settings: #{@user.name}" %>
<%= link_to @user.name, @user %> → Edit Notification Settings
<h1>Edit Notification Settings</h1>
<%= form_for @user do |f| %>
<p>Email me when someone...</p>
<table>
<tbody>
<tr>
<td>replies to my thread</td>
<td>
<%= f.check_box :mail_own_thread_reply %>
</td>
</tr>
<tr>
<td>replies to a thread I already replied to</td>
<td>
<%= f.check_box :mail_other_thread_reply %>
</td>
</tr>
<tr>
<td>
comments my blog post<br>
<i>(Currently used for staff only)</i>
</td>
<td>
<%= f.check_box :mail_own_blogpost_comment %>
</td>
</tr>
<tr>
<td>comments a blog post I already commented</td>
<td>
<%= f.check_box :mail_other_blogpost_comment %>
</td>
</tr>
<tr>
<td>
mentions me in a thread or comment<br>
<i>(Not yet implemented)</i>
</td>
<td>
<%= f.check_box :mail_mention %>
</td>
</tr>
</tbody>
</table>
<p><%= f.submit "Save changes", class: "btn blue left" %></p>
<div class="clear"></div>
<% end %>