another big commit :D

This commit is contained in:
jomo
2013-10-07 04:59:21 +02:00
parent 2761387703
commit 5fac505a31
74 changed files with 1003 additions and 357 deletions

View File

@@ -2,8 +2,7 @@ class CommentsController < ApplicationController
def edit
@comment = Comment.find(params[:id])
if current_user && ((current_user.rank >= rank_to_int("mod") && current_user.rank.to_i >= @comment.user.rank.to_i) || (current_user == @comment.user))
session[:return_to] = blogpost_path(@comment.blogpost)
if mod? || @comment.author.is?(current_user)
else
flash[:alert] = "You are not allowed to edit this comment"
redirect_to @comment.blogpost
@@ -11,39 +10,43 @@ class CommentsController < ApplicationController
end
def create
if current_user
if confirmed?
params[:comment].slice!("content") if params[:comment]
@comment = Comment.new(params[:comment])
@comment.user_id = current_user.id
@comment.user_author = current_user
@comment.blogpost = Blogpost.find(params[:blogpost_id])
if @comment.save
redirect_to @comment.blogpost, notice: 'Comment created!'
else
flash[:alert] = @comment.errors.full_messages.first
redirect_to blogpost_path(params[:blogpost_id])
flash[:alert] = "Could not create comment."
redirect_to Blogpost.find(params[:blogpost_id])
end
else
flash[:alert] = "You are not allowed to create comments."
redirect_to Blogpost.find(params[:blogpost_id])
end
end
def update
@comment = Comment.find(params[:id])
if current_user && ((current_user.rank >= rank_to_int("mod") && current_user.rank.to_i >= @comment.user.rank.to_i) || (current_user == @comment.user))
if mod? || @comment.author.is?(current_user)
params[:comment].slice!("content") if params[:comment]
if @comment.update_attributes(params[:comment])
flash[:notice] = "Comment updated!"
redirect_to @comment.blogpost
else
flash[:alert] = "There was a problem while updating your comment"
redirect_to session[:return_to]
session.delete(:redirect_to)
render action: "edit"
end
else
flash[:alert] = "You are not allowed to edit this comment"
redirect_to blogpost_path(params[:blogpost_id])
redirect_to @comment.blogpost
end
end
def destroy
@comment = Comment.find(params[:id])
if current_user && ((current_user.rank >= rank_to_int("mod") && current_user.rank.to_i >= @comment.user.rank.to_i) || (current_user == @comment.user))
if mod? || @comment.author.is?(current_user)
if @comment.destroy
flash[:notice] = "Comment deleted!"
else