FIX: display and link to correct grant_by users for granted badges (#24021)
* FIX: display and link to correct grant_by users for granted badges in admin * DEV: add system test for admin user badge granted by behaviour
This commit is contained in:
parent
a2000a3559
commit
6121869900
|
@ -8,6 +8,7 @@ import { grantableBadges } from "discourse/lib/grant-badge-utils";
|
|||
import UserBadge from "discourse/models/user-badge";
|
||||
import discourseComputed from "discourse-common/utils/decorators";
|
||||
import I18n from "discourse-i18n";
|
||||
import AdminUser from "admin/models/admin-user";
|
||||
|
||||
export default class AdminUserBadgesController extends Controller {
|
||||
@service dialog;
|
||||
|
@ -61,6 +62,12 @@ export default class AdminUserBadgesController extends Controller {
|
|||
|
||||
expanded.push(result);
|
||||
});
|
||||
expanded.forEach((badgeGroup) => {
|
||||
const user = badgeGroup.granted_by;
|
||||
if (user) {
|
||||
badgeGroup.granted_by = AdminUser.create(user);
|
||||
}
|
||||
});
|
||||
|
||||
return expanded.sortBy("granted_at").reverse();
|
||||
}
|
||||
|
|
|
@ -57,7 +57,7 @@
|
|||
@count={{userBadge.count}}
|
||||
/></td>
|
||||
<td>
|
||||
<LinkTo @route="adminUser" @model={{userBadge.badge.granted_by}}>
|
||||
<LinkTo @route="adminUser" @model={{userBadge.granted_by}}>
|
||||
{{avatar userBadge.granted_by imageSize="tiny"}}
|
||||
{{userBadge.granted_by.username}}
|
||||
</LinkTo>
|
||||
|
|
|
@ -44,6 +44,11 @@ UserBadge.reopenClass({
|
|||
users[userJson.id] = User.create(userJson);
|
||||
});
|
||||
|
||||
json.granted_bies = json.granted_bies ?? [];
|
||||
json.granted_bies.forEach(function (userJson) {
|
||||
users[userJson.id] = User.create(userJson);
|
||||
});
|
||||
|
||||
// Create Topic objects.
|
||||
if (json.topics === undefined) {
|
||||
json.topics = [];
|
||||
|
|
|
@ -0,0 +1,21 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
describe "Admin User Badges Page", type: :system do
|
||||
before { SiteSetting.enable_badges = true }
|
||||
|
||||
fab!(:granter) { Fabricate(:admin) }
|
||||
fab!(:user) { Fabricate(:user) }
|
||||
fab!(:badge) { Fabricate(:manually_grantable_badge) }
|
||||
let(:user_badges_page) { PageObjects::Pages::AdminUserBadges.new }
|
||||
|
||||
before { sign_in(granter) }
|
||||
|
||||
it "displays badge granter and links to their profile" do
|
||||
BadgeGranter.grant(badge, user, granted_by: granter)
|
||||
badge_row = user_badges_page.visit_page(user).find_badge_row_by_granter(granter)
|
||||
expect(badge_row).to have_css("[data-badge-name='#{badge.name}']")
|
||||
|
||||
badge_row.click_link(granter.username)
|
||||
expect(page).to have_current_path "/admin/users/#{granter.id}/#{granter.username}"
|
||||
end
|
||||
end
|
|
@ -0,0 +1,19 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module PageObjects
|
||||
module Pages
|
||||
class AdminUserBadges < PageObjects::Pages::Base
|
||||
def visit_page(user)
|
||||
page.visit "/admin/users/#{user.id}/#{user.username}/badges"
|
||||
self
|
||||
end
|
||||
|
||||
def user_badges_table
|
||||
page.find(:table, id: "user-badges", visible: true)
|
||||
end
|
||||
def find_badge_row_by_granter(granter)
|
||||
user_badges_table.find(:table_row, { "Granted By" => "#{granter.username}" })
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue