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) => { ...@@ -36,6 +36,7 @@ const populateUserInfo = (user) => {
if (userData) { if (userData) {
Object.assign(user, { Object.assign(user, {
avatarUrl: userData.avatar_url, avatarUrl: userData.avatar_url,
bot: userData.bot,
username: userData.username, username: userData.username,
name: userData.name, name: userData.name,
location: userData.location, location: userData.location,
......
...@@ -12,11 +12,6 @@ import UserAvatarImage from '../user_avatar/user_avatar_image.vue'; ...@@ -12,11 +12,6 @@ import UserAvatarImage from '../user_avatar/user_avatar_image.vue';
const MAX_SKELETON_LINES = 4; const MAX_SKELETON_LINES = 4;
const SECURITY_BOT_USER_DATA = {
username: 'GitLab-Security-Bot',
name: 'GitLab Security Bot',
};
export default { export default {
name: 'UserPopover', name: 'UserPopover',
maxSkeletonLines: MAX_SKELETON_LINES, maxSkeletonLines: MAX_SKELETON_LINES,
...@@ -56,15 +51,6 @@ export default { ...@@ -56,15 +51,6 @@ export default {
userIsLoading() { userIsLoading() {
return !this.user?.loaded; 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() { availabilityStatus() {
return this.user?.status?.availability || ''; return this.user?.status?.availability || '';
}, },
...@@ -114,7 +100,7 @@ export default { ...@@ -114,7 +100,7 @@ export default {
<div v-if="statusHtml" class="js-user-status gl-mt-3"> <div v-if="statusHtml" class="js-user-status gl-mt-3">
<span v-html="statusHtml"></span> <span v-html="statusHtml"></span>
</div> </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-icon name="question" />
<gl-link data-testid="user-popover-bot-docs-link" :href="user.websiteUrl"> <gl-link data-testid="user-popover-bot-docs-link" :href="user.websiteUrl">
{{ sprintf(__('Learn more about %{username}'), { username: user.name }) }} {{ 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 = { ...@@ -9,6 +9,7 @@ const DEFAULT_PROPS = {
username: 'root', username: 'root',
name: 'Administrator', name: 'Administrator',
location: 'Vienna', location: 'Vienna',
bot: false,
bio: null, bio: null,
workInformation: null, workInformation: null,
status: null, status: null,
...@@ -22,9 +23,6 @@ describe('User Popover Component', () => { ...@@ -22,9 +23,6 @@ describe('User Popover Component', () => {
let wrapper; let wrapper;
beforeEach(() => { beforeEach(() => {
window.gon.features = {
securityAutoFix: true,
};
loadFixtures(fixtureTemplate); loadFixtures(fixtureTemplate);
}); });
...@@ -36,6 +34,7 @@ describe('User Popover Component', () => { ...@@ -36,6 +34,7 @@ describe('User Popover Component', () => {
const findUserStatus = () => wrapper.find('.js-user-status'); const findUserStatus = () => wrapper.find('.js-user-status');
const findTarget = () => document.querySelector('.js-user-link'); const findTarget = () => document.querySelector('.js-user-link');
const findUserName = () => wrapper.find(UserNameWithStatus); const findUserName = () => wrapper.find(UserNameWithStatus);
const findSecurityBotDocsLink = () => findByTestId('user-popover-bot-docs-link');
const createWrapper = (props = {}, options = {}) => { const createWrapper = (props = {}, options = {}) => {
wrapper = shallowMount(UserPopover, { wrapper = shallowMount(UserPopover, {
...@@ -85,6 +84,12 @@ describe('User Popover Component', () => { ...@@ -85,6 +84,12 @@ describe('User Popover Component', () => {
expect(iconEl.props('name')).toEqual('location'); 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', () => { describe('job data', () => {
...@@ -229,14 +234,14 @@ describe('User Popover Component', () => { ...@@ -229,14 +234,14 @@ describe('User Popover Component', () => {
}); });
}); });
describe('security bot', () => { describe('bot user', () => {
const SECURITY_BOT_USER = { const SECURITY_BOT_USER = {
...DEFAULT_PROPS.user, ...DEFAULT_PROPS.user,
name: 'GitLab Security Bot', name: 'GitLab Security Bot',
username: 'GitLab-Security-Bot', username: 'GitLab-Security-Bot',
websiteUrl: '/security/bot/docs', websiteUrl: '/security/bot/docs',
bot: true,
}; };
const findSecurityBotDocsLink = () => findByTestId('user-popover-bot-docs-link');
it("shows a link to the bot's documentation", () => { it("shows a link to the bot's documentation", () => {
createWrapper({ user: SECURITY_BOT_USER }); createWrapper({ user: SECURITY_BOT_USER });
...@@ -244,14 +249,5 @@ describe('User Popover Component', () => { ...@@ -244,14 +249,5 @@ describe('User Popover Component', () => {
expect(securityBotDocsLink.exists()).toBe(true); expect(securityBotDocsLink.exists()).toBe(true);
expect(securityBotDocsLink.attributes('href')).toBe(SECURITY_BOT_USER.websiteUrl); 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