Display commenter as admin description or name
This commit is contained in:
@@ -3,7 +3,8 @@
|
||||
<% allow_votes = local_assigns.fetch(:allow_votes, true) %>
|
||||
<% allow_actions = local_assigns.fetch(:allow_actions, true) %>
|
||||
<% allow_comments = local_assigns.fetch(:allow_comments, true) %>
|
||||
<% cache [locale_and_user_status(comment), comment, commentable_cache_key(comment.commentable), comment.author, (comment_flags[comment.id] if comment_flags)] do %>
|
||||
<% admin_layout = local_assigns.fetch(:admin_layout, false) %>
|
||||
<% cache [locale_and_user_status(comment), comment, commentable_cache_key(comment.commentable), comment.author, (comment_flags[comment.id] if comment_flags), (admin_layout if admin_layout)] do %>
|
||||
<ul id="<%= dom_id(comment) %>" class="comment no-bullet small-12">
|
||||
<li class="comment-body">
|
||||
<% if comment.hidden? || comment.user.hidden? %>
|
||||
@@ -30,7 +31,14 @@
|
||||
<div class="comment-info">
|
||||
|
||||
<% if comment.as_administrator? %>
|
||||
<span class="user-name"><%= t("comments.comment.admin") %> #<%= comment.administrator_id %></span>
|
||||
<span class="user-name">
|
||||
<%= t("comments.comment.admin") %>
|
||||
<% if admin_layout %>
|
||||
<%= Administrator.find(comment.administrator_id).description_or_name %>
|
||||
<% else %>
|
||||
#<%= comment.administrator_id %>
|
||||
<% end %>
|
||||
</span>
|
||||
<% elsif comment.as_moderator? %>
|
||||
<span class="user-name"><%= t("comments.comment.moderator") %> #<%= comment.moderator_id %></span>
|
||||
<% else %>
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
<% commentable = comment_tree.commentable %>
|
||||
<% valuation = local_assigns.fetch(:valuation, false) %>
|
||||
<% allow_comments = local_assigns.fetch(:allow_comments, true) %>
|
||||
<% cache [locale_and_user_status, comment_tree.order, commentable_cache_key(commentable), comment_tree.comments, comment_tree.comment_authors, commentable.comments_count, comment_flags] do %>
|
||||
<% admin_layout = local_assigns.fetch(:admin_layout, false) %>
|
||||
<% cache [locale_and_user_status, comment_tree.order, commentable_cache_key(commentable), comment_tree.comments, comment_tree.comment_authors, commentable.comments_count, comment_flags, admin_layout] do %>
|
||||
<section class="expanded comments">
|
||||
<div class="row">
|
||||
<div id="comments" class="small-12 column">
|
||||
@@ -46,7 +47,8 @@
|
||||
valuation: valuation,
|
||||
allow_votes: !valuation,
|
||||
allow_actions: !valuation,
|
||||
allow_comments: allow_comments } %>
|
||||
allow_comments: allow_comments,
|
||||
admin_layout: admin_layout } %>
|
||||
<% end %>
|
||||
<%= paginate comment_tree.root_comments %>
|
||||
</div>
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
<h2><%= t("valuation.budget_investments.valuation_comments") %></h2>
|
||||
<% unless @comment_tree.nil? %>
|
||||
<%= render partial: "/comments/comment_tree", locals: { comment_tree: @comment_tree,
|
||||
comment_flags: @comment_flags,
|
||||
display_comments_count: false,
|
||||
valuation: true,
|
||||
allow_comments: !@budget.finished? } %>
|
||||
<%= render partial: "/comments/comment_tree", locals: {
|
||||
comment_tree: @comment_tree,
|
||||
comment_flags: @comment_flags,
|
||||
display_comments_count: false,
|
||||
valuation: true,
|
||||
allow_comments: !@budget.finished?,
|
||||
admin_layout: true } %>
|
||||
<% end %>
|
||||
|
||||
@@ -382,49 +382,109 @@ describe "Commenting Budget::Investments" do
|
||||
end
|
||||
|
||||
describe "Administrators" do
|
||||
scenario "can create comment as an administrator", :js do
|
||||
admin = create(:administrator)
|
||||
context "comment as administrator" do
|
||||
scenario "can create comment", :js do
|
||||
admin = create(:administrator)
|
||||
|
||||
login_as(admin.user)
|
||||
visit budget_investment_path(investment.budget, investment)
|
||||
login_as(admin.user)
|
||||
visit budget_investment_path(investment.budget, investment)
|
||||
|
||||
fill_in "comment-body-budget_investment_#{investment.id}", with: "I am your Admin!"
|
||||
check "comment-as-administrator-budget_investment_#{investment.id}"
|
||||
click_button "Publish comment"
|
||||
fill_in "comment-body-budget_investment_#{investment.id}", with: "I am your Admin!"
|
||||
check "comment-as-administrator-budget_investment_#{investment.id}"
|
||||
click_button "Publish comment"
|
||||
|
||||
within "#comments" do
|
||||
expect(page).to have_content "I am your Admin!"
|
||||
expect(page).to have_content "Administrator ##{admin.id}"
|
||||
within "#comments" do
|
||||
expect(page).to have_content "I am your Admin!"
|
||||
expect(page).to have_content "Administrator ##{admin.id}"
|
||||
expect(page).to have_css "div.is-admin"
|
||||
expect(page).to have_css "img.admin-avatar"
|
||||
end
|
||||
end
|
||||
|
||||
scenario "display administrator description on admin views", :js do
|
||||
admin = create(:administrator, description: "user description")
|
||||
|
||||
login_as(admin.user)
|
||||
|
||||
visit admin_budget_budget_investment_path(investment.budget, investment)
|
||||
|
||||
fill_in "comment-body-budget_investment_#{investment.id}", with: "I am your Admin!"
|
||||
check "comment-as-administrator-budget_investment_#{investment.id}"
|
||||
click_button "Publish comment"
|
||||
|
||||
visit admin_budget_budget_investment_path(investment.budget, investment)
|
||||
|
||||
within "#comments" do
|
||||
expect(page).to have_content "I am your Admin!"
|
||||
expect(page).to have_content "Administrator user description"
|
||||
expect(page).to have_css "div.is-admin"
|
||||
expect(page).to have_css "img.admin-avatar"
|
||||
end
|
||||
end
|
||||
|
||||
scenario "display administrator id on public views", :js do
|
||||
admin = create(:administrator, description: "user description")
|
||||
|
||||
login_as(admin.user)
|
||||
visit admin_budget_budget_investment_path(investment.budget, investment)
|
||||
|
||||
fill_in "comment-body-budget_investment_#{investment.id}", with: "I am your Admin!"
|
||||
check "comment-as-administrator-budget_investment_#{investment.id}"
|
||||
click_button "Publish comment"
|
||||
|
||||
within "#comments" do
|
||||
expect(page).to have_content "I am your Admin!"
|
||||
expect(page).to have_content "Administrator ##{admin.id}"
|
||||
expect(page).to have_css "div.is-admin"
|
||||
expect(page).to have_css "img.admin-avatar"
|
||||
end
|
||||
end
|
||||
|
||||
scenario "can create reply as an administrator", :js do
|
||||
citizen = create(:user, username: "Ana")
|
||||
manuela = create(:user, username: "Manuela")
|
||||
admin = create(:administrator, user: manuela)
|
||||
comment = create(:comment, commentable: investment, user: citizen)
|
||||
|
||||
login_as(manuela)
|
||||
visit budget_investment_path(investment.budget, investment)
|
||||
|
||||
click_link "Reply"
|
||||
|
||||
within "#js-comment-form-comment_#{comment.id}" do
|
||||
fill_in "comment-body-comment_#{comment.id}", with: "Top of the world!"
|
||||
check "comment-as-administrator-comment_#{comment.id}"
|
||||
click_button "Publish reply"
|
||||
end
|
||||
|
||||
within "#comment_#{comment.id}" do
|
||||
expect(page).to have_content "Top of the world!"
|
||||
expect(page).to have_content "Administrator ##{admin.id}"
|
||||
expect(page).to have_css "img.admin-avatar"
|
||||
end
|
||||
|
||||
expect(page).not_to have_selector("#js-comment-form-comment_#{comment.id}", visible: true)
|
||||
expect(page).to have_css "div.is-admin"
|
||||
expect(page).to have_css "img.admin-avatar"
|
||||
end
|
||||
end
|
||||
|
||||
scenario "can create reply as an administrator", :js do
|
||||
citizen = create(:user, username: "Ana")
|
||||
manuela = create(:user, username: "Manuela")
|
||||
admin = create(:administrator, user: manuela)
|
||||
comment = create(:comment, commentable: investment, user: citizen)
|
||||
|
||||
login_as(manuela)
|
||||
visit budget_investment_path(investment.budget, investment)
|
||||
|
||||
click_link "Reply"
|
||||
|
||||
within "#js-comment-form-comment_#{comment.id}" do
|
||||
fill_in "comment-body-comment_#{comment.id}", with: "Top of the world!"
|
||||
check "comment-as-administrator-comment_#{comment.id}"
|
||||
click_button "Publish reply"
|
||||
end
|
||||
|
||||
within "#comment_#{comment.id}" do
|
||||
expect(page).to have_content "Top of the world!"
|
||||
expect(page).to have_content "Administrator ##{admin.id}"
|
||||
expect(page).to have_css "div.is-admin"
|
||||
expect(page).to have_css "img.admin-avatar"
|
||||
scenario "public users not see admin description", :js do
|
||||
manuela = create(:user, username: "Manuela")
|
||||
admin = create(:administrator, user: manuela)
|
||||
comment = create(:comment,
|
||||
commentable: investment,
|
||||
user: manuela,
|
||||
administrator_id: admin.id)
|
||||
|
||||
visit budget_investment_path(investment.budget, investment)
|
||||
|
||||
within "#comment_#{comment.id}" do
|
||||
expect(page).to have_content comment.body
|
||||
expect(page).to have_content "Administrator ##{admin.id}"
|
||||
expect(page).to have_css "img.admin-avatar"
|
||||
expect(page).to have_css "div.is-admin"
|
||||
end
|
||||
end
|
||||
|
||||
expect(page).not_to have_selector("#js-comment-form-comment_#{comment.id}", visible: true)
|
||||
end
|
||||
|
||||
scenario "can not comment as a moderator" do
|
||||
|
||||
Reference in New Issue
Block a user