diff --git a/app/controllers/wiki_controller.rb b/app/controllers/wiki_controller.rb
index e334c11860..3525a14eff 100644
--- a/app/controllers/wiki_controller.rb
+++ b/app/controllers/wiki_controller.rb
@@ -26,22 +26,22 @@ def show
end
if @node&.has_power_tag('redirect') && Node.where(nid: @node.power_tag('redirect')).exists?
- if current_user.nil? || (current_user.role != 'admin' && current_user.role != 'moderator')
+ if current_user.nil? || !current_user.can_moderate?
redirect_to Node.find(@node.power_tag('redirect')).path
return
- elsif current_user.role == 'admin' || current_user.role == 'moderator'
+ elsif current_user.can_moderate?
flash.now[:warning] = "Only moderators and admins see this page, as it is redirected to #{Node.find(@node.power_tag('redirect')).title}.
To remove the redirect, delete the tag beginning with 'redirect:'"
end
end
if @node&.has_power_tag('abtest') && !Node.where(nid: @node.power_tag('abtest')).empty?
- if current_user.nil? || (current_user.role != 'admin' && current_user.role != 'moderator')
+ if current_user.nil? || !current_user.can_moderate?
if Random.rand(2) == 0
redirect_to Node.find(@node.power_tag('abtest')).path
return
end
- elsif current_user.role == 'admin' || current_user.role == 'moderator'
+ elsif current_user.can_moderate?
flash.now[:warning] = "Only moderators and admins see this page, as it is redirected to #{Node.find(@node.power_tag('abtest')).title} roughly around 50% of the time.
To remove this behavior, delete the tag beginning with 'abtest:'"
end
@@ -94,7 +94,7 @@ def edit
Node.find_wiki(params[:id])
end
- if @node.has_tag('locked') && (current_user.role != 'admin' && current_user.role != 'moderator')
+ if @node.has_tag('locked') && !current_user.can_moderate?
flash[:warning] = "This page is locked, and only moderators can edit it."
redirect_to @node.path
end
@@ -171,7 +171,7 @@ def update
@revision = @node.new_revision(uid: current_user.uid,
title: params[:title],
body: params[:body])
- if @node.has_tag('locked') && (current_user.role != 'admin' && current_user.role != 'moderator')
+ if @node.has_tag('locked') && !current_user.can_moderate?
flash[:warning] = "This page is locked, and only moderators can update it."
redirect_to @node.path
@@ -211,7 +211,7 @@ def update
def delete
@node = Node.find(params[:id])
- if current_user && current_user.role == 'admin'
+ if current_user && current_user.admin?
@node.destroy
flash[:notice] = I18n.t('wiki_controller.wiki_page_deleted')
redirect_to '/dashboard'
@@ -224,7 +224,7 @@ def delete
def revert
revision = Revision.find params[:id]
node = revision.parent
- if current_user && (current_user.role == 'moderator' || current_user.role == 'admin')
+ if current_user && current_user.can_moderate?
new_rev = revision.dup
new_rev.timestamp = DateTime.now.to_i
if new_rev.save!
@@ -259,7 +259,7 @@ def revisions
@node = Node.find_wiki(params[:id])
if @node
@revisions = @node.revisions
- @revisions = @revisions.where(status: 1) unless current_user && (current_user.role == 'moderator' || current_user.role == 'admin')
+ @revisions = @revisions.where(status: 1) unless current_user && current_user.can_moderate?
@title = I18n.t('wiki_controller.revisions_for', title: @node.title).html_safe
@tags = @node.tags
else
@@ -278,7 +278,7 @@ def revision
if @revision.nil?
flash[:error] = I18n.t('wiki_controller.revision_not_found')
redirect_to action: 'revisions'
- elsif @revision.status == 1 || current_user && (current_user.role == 'moderator' || current_user.role == 'admin')
+ elsif @revision.status == 1 || current_user && current_user.can_moderate?
@title = I18n.t('wiki_controller.revisions_for', title: @revision.title).html_safe
render template: 'wiki/show'
else