Commit fc54e469 authored by Andrew Fontaine's avatar Andrew Fontaine

Merge branch 'jnnkl-bot-popover-be-info' into 'master'

Add check if user is bot to Users API

See merge request gitlab-org/gitlab!56362
parents ecbb279a 6722462e
......@@ -36,6 +36,7 @@ const populateUserInfo = (user) => {
if (userData) {
Object.assign(user, {
avatarUrl: userData.avatar_url,
bot: userData.bot,
username: userData.username,
name: userData.name,
location: userData.location,
......
......@@ -12,11 +12,6 @@ import UserAvatarImage from '../user_avatar/user_avatar_image.vue';
const MAX_SKELETON_LINES = 4;
const SECURITY_BOT_USER_DATA = {
username: 'GitLab-Security-Bot',
name: 'GitLab Security Bot',
};
export default {
name: 'UserPopover',
maxSkeletonLines: MAX_SKELETON_LINES,
......@@ -56,15 +51,6 @@ export default {
userIsLoading() {
return !this.user?.loaded;
},
isSecurityBot() {
const { username, name, websiteUrl = '' } = this.user;
return (
gon.features?.securityAutoFix &&
username === SECURITY_BOT_USER_DATA.username &&
name === SECURITY_BOT_USER_DATA.name &&
websiteUrl.length
);
},
availabilityStatus() {
return this.user?.status?.availability || '';
},
......@@ -114,7 +100,7 @@ export default {
<div v-if="statusHtml" class="js-user-status gl-mt-3">
<span v-html="statusHtml"></span>
</div>
<div v-if="isSecurityBot" class="gl-text-blue-500">
<div v-if="user.bot" class="gl-text-blue-500">
<gl-icon name="question" />
<gl-link data-testid="user-popover-bot-docs-link" :href="user.websiteUrl">
{{ sprintf(__('Learn more about %{username}'), { username: user.name }) }}
......
---
title: Consume check if user is bot from Users API
merge_request: 56362
author:
type: changed
......@@ -9,6 +9,7 @@ const DEFAULT_PROPS = {
username: 'root',
name: 'Administrator',
location: 'Vienna',
bot: false,
bio: null,
workInformation: null,
status: null,
......@@ -22,9 +23,6 @@ describe('User Popover Component', () => {
let wrapper;
beforeEach(() => {
window.gon.features = {
securityAutoFix: true,
};
loadFixtures(fixtureTemplate);
});
......@@ -36,6 +34,7 @@ describe('User Popover Component', () => {
const findUserStatus = () => wrapper.find('.js-user-status');
const findTarget = () => document.querySelector('.js-user-link');
const findUserName = () => wrapper.find(UserNameWithStatus);
const findSecurityBotDocsLink = () => findByTestId('user-popover-bot-docs-link');
const createWrapper = (props = {}, options = {}) => {
wrapper = shallowMount(UserPopover, {
......@@ -85,6 +84,12 @@ describe('User Popover Component', () => {
expect(iconEl.props('name')).toEqual('location');
});
it("should not show a link to bot's documentation", () => {
createWrapper();
const securityBotDocsLink = findSecurityBotDocsLink();
expect(securityBotDocsLink.exists()).toBe(false);
});
});
describe('job data', () => {
......@@ -229,14 +234,14 @@ describe('User Popover Component', () => {
});
});
describe('security bot', () => {
describe('bot user', () => {
const SECURITY_BOT_USER = {
...DEFAULT_PROPS.user,
name: 'GitLab Security Bot',
username: 'GitLab-Security-Bot',
websiteUrl: '/security/bot/docs',
bot: true,
};
const findSecurityBotDocsLink = () => findByTestId('user-popover-bot-docs-link');
it("shows a link to the bot's documentation", () => {
createWrapper({ user: SECURITY_BOT_USER });
......@@ -244,14 +249,5 @@ describe('User Popover Component', () => {
expect(securityBotDocsLink.exists()).toBe(true);
expect(securityBotDocsLink.attributes('href')).toBe(SECURITY_BOT_USER.websiteUrl);
});
it('does not show the link if the feature flag is disabled', () => {
window.gon.features = {
securityAutoFix: false,
};
createWrapper({ user: SECURITY_BOT_USER });
expect(findSecurityBotDocsLink().exists()).toBe(false);
});
});
});
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment