Merge pull request #3076 from evazion/feat-body-attrs

Fix #3073: Add attribute "data-is-moderator" to the <body> element.
This commit is contained in:
Albert Yi
2017-05-22 11:58:11 -07:00
committed by GitHub
4 changed files with 19 additions and 15 deletions

View File

@@ -129,7 +129,7 @@ a.blacklisted-active {
} }
/* Flagged posts have red borders for approvers. */ /* Flagged posts have red borders for approvers. */
body[data-can-approve-posts="true"] .post-preview { body[data-user-can-approve-posts="true"] .post-preview {
&.post-status-flagged img { &.post-status-flagged img {
border-color: $preview_flagged_color; border-color: $preview_flagged_color;
} }

View File

@@ -164,6 +164,18 @@ module ApplicationHelper
string.html_safe string.html_safe
end end
def body_attributes(user = CurrentUser.user)
attributes = [:id, :name, :level, :level_string, :can_approve_posts?, :can_upload_free?]
attributes += User::Roles.map { |role| :"is_#{role}?" }
attributes.map do |attr|
name = attr.to_s.dasherize.delete("?")
value = user.send(attr)
%{data-user-#{name}="#{h(value)}"}
end.join(" ").html_safe
end
protected protected
def nav_link_match(controller, url) def nav_link_match(controller, url)
url =~ case controller url =~ case controller

View File

@@ -8,6 +8,10 @@ class AnonymousUser
0 0
end end
def level_string
"Anonymous"
end
def comment_threshold def comment_threshold
0 0
end end
@@ -36,10 +40,6 @@ class AnonymousUser
true true
end end
def is_banned?
false
end
def is_banned_or_ip_banned? def is_banned_or_ip_banned?
false false
end end
@@ -245,14 +245,6 @@ class AnonymousUser
false false
end end
def is_voter?
false
end
def is_super_voter?
false
end
def disable_tagged_filenames? def disable_tagged_filenames?
false false
end end
@@ -261,7 +253,7 @@ class AnonymousUser
false false
end end
%w(member banned gold builder platinum moderator admin).each do |name| User::Roles.reject {|r| r == :anonymous}.each do |name|
define_method("is_#{name}?") do define_method("is_#{name}?") do
false false
end end

View File

@@ -69,7 +69,7 @@
} }
</script> </script>
</head> </head>
<body lang="en" data-can-approve-posts="<%= CurrentUser.user.can_approve_posts? %>"> <body lang="en" <%= body_attributes(CurrentUser.user) %>>
<header id="top"> <header id="top">
<%= render "news_updates/listing" %> <%= render "news_updates/listing" %>