Add data attributes for CurrentUser's privileges to <body> tag (fix #3073).

This commit is contained in:
evazion
2017-05-21 12:29:53 -05:00
parent f1f6e5ccc9
commit 9b613157ae
3 changed files with 14 additions and 2 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

@@ -163,6 +163,18 @@ module ApplicationHelper
string += '</div>' string += '</div>'
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)

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" %>