Commit 7e3546d3 authored by Vitaly Slobodin's avatar Vitaly Slobodin

Merge branch 'remove-sast-entry-points-experiment' into 'master'

Remove sast_entry_points experiment

See merge request gitlab-org/gitlab!75014
parents 1e2c19b4 07470fff
......@@ -19,7 +19,6 @@
= render "archived_notice", project: @project
= render_if_exists "projects/marked_for_deletion_notice", project: @project
= render_if_exists "projects/ancestor_group_marked_for_deletion_notice", project: @project
= render_if_exists 'projects/sast_entry_points', project: @project
- view_path = @project.default_view
......
import '~/pages/projects/show/index';
import { initSastEntryPointsExperiment } from 'ee/projects/sast_entry_points_experiment';
import initVueAlerts from '~/vue_alerts';
initVueAlerts();
initSastEntryPointsExperiment();
<script>
import { GlBanner } from '@gitlab/ui';
import { I18N } from '../constants';
import { isDismissed, dismiss, trackShow, trackCtaClicked, trackDismissed } from '../utils';
export default {
components: {
GlBanner,
},
props: {
sastDocumentationPath: {
type: String,
required: true,
},
},
data() {
return {
isVisible: !isDismissed(),
};
},
mounted() {
if (this.isVisible) {
trackShow();
}
},
methods: {
onDismiss() {
this.isVisible = false;
dismiss();
trackDismissed();
},
onClick() {
dismiss();
trackCtaClicked();
},
},
i18n: I18N,
};
</script>
<template>
<gl-banner
v-if="isVisible"
:title="$options.i18n.title"
:button-text="$options.i18n.buttonText"
:button-link="sastDocumentationPath"
variant="promotion"
class="gl-my-5"
@close="onDismiss"
@primary="onClick"
>
<p>
{{ $options.i18n.bodyText }}
</p>
</gl-banner>
</template>
<script>
import { GlPopover, GlButton, GlLink } from '@gitlab/ui';
import { I18N, POPOVER_TARGET } from '../constants';
import { isDismissed, dismiss, trackShow, trackCtaClicked, trackDismissed } from '../utils';
export default {
components: {
GlPopover,
GlButton,
GlLink,
},
props: {
sastDocumentationPath: {
type: String,
required: true,
},
},
data() {
return {
isVisible: !isDismissed(),
target: document.querySelector(POPOVER_TARGET),
};
},
mounted() {
if (this.isVisible) {
trackShow();
}
},
methods: {
onDismiss() {
this.isVisible = false;
dismiss();
trackDismissed();
},
onClick() {
dismiss();
trackCtaClicked();
},
},
gitlabLogo: window.gon.gitlab_logo,
i18n: I18N,
};
</script>
<template>
<gl-popover
v-if="isVisible"
:target="target"
show
triggers="manual"
placement="bottomright"
:css-classes="['marketing-popover', 'gl-border-4']"
>
<div class="gl-display-flex gl-mt-n2">
<img :src="$options.gitlabLogo" :alt="''" height="24" width="24" class="gl-ml-2 gl-mr-3" />
<div>
<div
class="gl-font-weight-bold gl-font-lg gl-line-height-20 gl-text-theme-indigo-900 gl-mb-3"
>
{{ $options.i18n.title }}
</div>
<div class="gl-font-base gl-line-height-20 gl-mb-3">
{{ $options.i18n.bodyText }}
</div>
<gl-link :href="sastDocumentationPath" @click="onClick">
{{ $options.i18n.linkText }}
</gl-link>
</div>
<gl-button
category="tertiary"
class="gl-align-self-start gl-mt-n3 gl-mr-n3"
icon="close"
:aria-label="__('Close')"
@click="onDismiss"
/>
</div>
</gl-popover>
</template>
<script>
import { GlPopover, GlButton, GlLink } from '@gitlab/ui';
import { I18N, POPOVER_TARGET } from '../constants';
import { isDismissed, dismiss, trackShow, trackCtaClicked, trackDismissed } from '../utils';
export default {
components: {
GlPopover,
GlButton,
GlLink,
},
props: {
sastDocumentationPath: {
type: String,
required: true,
},
},
data() {
return {
isVisible: !isDismissed(),
target: document.querySelector(POPOVER_TARGET),
};
},
mounted() {
if (this.isVisible) {
trackShow();
}
},
methods: {
onDismiss() {
this.isVisible = false;
dismiss();
trackDismissed();
},
onClick() {
dismiss();
trackCtaClicked();
},
},
i18n: I18N,
};
</script>
<template>
<gl-popover v-if="isVisible" :target="target" show triggers="manual" placement="bottomright">
<template #title>
<div class="gl-display-flex">
<span>
{{ $options.i18n.title }}
<gl-emoji class="gl-ml-2" data-name="raised_hands" />
</span>
<gl-button
category="tertiary"
class="gl-align-self-start close gl-opacity-10"
icon="close"
:aria-label="__('Close')"
@click="onDismiss"
/>
</div>
</template>
{{ $options.i18n.bodyText }}
<div class="gl-text-right gl-font-weight-bold">
<gl-link :href="sastDocumentationPath" @click="onClick">
{{ $options.i18n.linkText }}
</gl-link>
</div>
</gl-popover>
</template>
import { s__ } from '~/locale';
export const EXPERIMENT_NAME = 'sast_entry_points';
export const COOKIE_NAME = 'sast_entry_point_dismissed';
export const POPOVER_TARGET = '.js-sast-entry-point';
export const I18N = {
title: s__('SastEntryPoints|Catch your security vulnerabilities ahead of time!'),
bodyText: s__(
'SastEntryPoints|GitLab can scan your code for security vulnerabilities. Static Application Security Testing (SAST) helps you worry less and build more.',
),
buttonText: s__('SastEntryPoints|Learn more'),
linkText: s__('SastEntryPoints|How do I set up SAST?'),
};
import Vue from 'vue';
import Banner from './components/banner.vue';
import PopoverDark from './components/popover_dark.vue';
import PopoverLight from './components/popover_light.vue';
export const initSastEntryPointsExperiment = () => {
const el = document.querySelector('.js-sast-entry-points-experiment');
if (!el) return false;
const { variant, sastDocumentationPath } = el.dataset;
const component = {
banner: Banner,
popover_dark: PopoverDark,
popover_light: PopoverLight,
}[variant];
if (!component) return false;
return new Vue({
el,
render(h) {
return h(component, {
props: {
sastDocumentationPath,
},
});
},
});
};
import ExperimentTracking from '~/experimentation/experiment_tracking';
import { setCookie, getCookie, parseBoolean } from '~/lib/utils/common_utils';
import { COOKIE_NAME, EXPERIMENT_NAME } from './constants';
const tracking = new ExperimentTracking(EXPERIMENT_NAME);
export const isDismissed = () => {
return parseBoolean(getCookie(COOKIE_NAME));
};
export const dismiss = () => {
setCookie(COOKIE_NAME, 'true');
};
export const trackDismissed = () => {
tracking.event('dismissed');
};
export const trackShow = () => {
tracking.event('show');
};
export const trackCtaClicked = () => {
tracking.event('cta_clicked');
};
......@@ -10,10 +10,6 @@ module EE
before_action :log_archive_audit_event, only: [:archive]
before_action :log_unarchive_audit_event, only: [:unarchive]
before_action only: :show do
enable_sast_entry_points_experiment
end
before_action only: :edit do
push_frontend_feature_flag(:group_merge_request_approval_settings_feature_flag, project.root_ancestor, default_enabled: :yaml)
end
......@@ -188,18 +184,5 @@ module EE
def log_unarchive_audit_event
log_audit_event(message: 'Project unarchived')
end
def enable_sast_entry_points_experiment
return unless enable_sast_entry_points_experiment?(project)
experiment(:sast_entry_points, namespace: project.root_ancestor) do |e|
e.control {}
e.candidate(:banner) {}
e.candidate(:popover_light) {}
e.candidate(:popover_dark) {}
e.record!
end
end
end
end
......@@ -253,17 +253,6 @@ module EE
project.marked_for_deletion_at.present?
end
def enable_sast_entry_points_experiment?(project)
can?(current_user, :admin_project, project) &&
!project.empty_repo? &&
!OnboardingProgress.completed?(project.root_ancestor, :security_scan_enabled)
end
def sast_entry_points_experiment_enabled?(project)
enable_sast_entry_points_experiment?(project) &&
experiment(:sast_entry_points, namespace: project.root_ancestor).variant.group == :experiment
end
private
def remove_message_data(project)
......
......@@ -5,37 +5,9 @@ module EE
extend ::Gitlab::Utils::Override
extend ::Gitlab::Utils::DelegatorOverride
override :statistics_buttons
def statistics_buttons(show_auto_devops_callout:)
super + extra_statistics_buttons
end
def extra_statistics_buttons
[sast_anchor_data.presence].compact
end
delegator_override :approver_groups
def approver_groups
::ApproverGroup.filtered_approver_groups(project.approver_groups, current_user)
end
private
def sast_anchor_data
return unless sast_entry_points_experiment_enabled?(project)
::ProjectPresenter::AnchorData.new(
false,
statistic_icon + s_('SastEntryPoints|Add Security Testing'),
help_page_path('user/application_security/sast/index'),
'btn-dashed js-sast-entry-point',
nil,
nil,
{
'track-action': 'cta_clicked_button',
'track-experiment': 'sast_entry_points'
}
)
end
end
end
- if sast_entry_points_experiment_enabled?(project)
- variant = experiment(:sast_entry_points, namespace: project.root_ancestor).variant.name
- add_page_specific_style 'page_bundles/marketing_popover'
.js-sast-entry-points-experiment{ data: { variant: variant, sast_documentation_path: help_page_path('user/application_security/sast/index') } }
---
name: sast_entry_points
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/64625
rollout_issue_url: https://gitlab.com/gitlab-org/gitlab/-/issues/334277
milestone: '14.1'
type: experiment
group: group::activation
default_enabled: false
......@@ -105,28 +105,6 @@ RSpec.describe ProjectsController do
it_behaves_like 'namespace storage limit alert'
end
context 'sast_entry_points experiment' do
before do
allow(controller).to receive(:enable_sast_entry_points_experiment?).with(public_project).and_return(true)
stub_experiments(sast_entry_points: :banner)
end
it 'tracks the assignment', :experiment do
expect(experiment(:sast_entry_points))
.to track(:assignment)
.with_context(namespace: public_project.namespace)
.on_next_instance
subject
end
it 'records the subject' do
expect(Experiment).to receive(:add_subject).with('sast_entry_points', variant: :experimental, subject: public_project.namespace)
subject
end
end
end
describe 'GET edit' do
......
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`When the cookie is not set matches the snapshot 1`] = `
<gl-banner-stub
buttonlink="sast_documentation_path"
buttontext="Learn more"
class="gl-my-5"
title="Catch your security vulnerabilities ahead of time!"
variant="promotion"
>
<p>
GitLab can scan your code for security vulnerabilities. Static Application Security Testing (SAST) helps you worry less and build more.
</p>
</gl-banner-stub>
`;
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`When the cookie is not set matches the snapshot 1`] = `
<gl-popover-stub
cssclasses="marketing-popover,gl-border-4"
placement="bottomright"
show=""
triggers="manual"
>
<div
class="gl-display-flex gl-mt-n2"
>
<img
alt=""
class="gl-ml-2 gl-mr-3"
height="24"
width="24"
/>
<div>
<div
class="gl-font-weight-bold gl-font-lg gl-line-height-20 gl-text-theme-indigo-900 gl-mb-3"
>
Catch your security vulnerabilities ahead of time!
</div>
<div
class="gl-font-base gl-line-height-20 gl-mb-3"
>
GitLab can scan your code for security vulnerabilities. Static Application Security Testing (SAST) helps you worry less and build more.
</div>
<gl-link-stub
href="sast_documentation_path"
>
How do I set up SAST?
</gl-link-stub>
</div>
<gl-button-stub
aria-label="Close"
buttontextclasses=""
category="tertiary"
class="gl-align-self-start gl-mt-n3 gl-mr-n3"
icon="close"
size="medium"
variant="default"
/>
</div>
</gl-popover-stub>
`;
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`When the cookie is not set matches the snapshot 1`] = `
<div
class="gl-popover"
show=""
>
GitLab can scan your code for security vulnerabilities. Static Application Security Testing (SAST) helps you worry less and build more.
<div
class="gl-text-right gl-font-weight-bold"
>
<a
class="gl-link"
href="sast_documentation_path"
>
How do I set up SAST?
</a>
</div>
<div
class="gl-display-flex"
>
<span>
Catch your security vulnerabilities ahead of time!
<gl-emoji
class="gl-ml-2"
data-name="raised_hands"
/>
</span>
<button
aria-label="Close"
class="btn gl-align-self-start close gl-opacity-10 btn-default btn-md gl-button btn-default-tertiary btn-icon"
type="button"
>
<!---->
<svg
aria-hidden="true"
class="gl-button-icon gl-icon s16"
data-testid="close-icon"
role="img"
>
<use
href="#close"
/>
</svg>
<!---->
</button>
</div>
</div>
`;
import { GlBanner } from '@gitlab/ui';
import { shallowMount } from '@vue/test-utils';
import Cookies from 'js-cookie';
import Banner from 'ee/projects/sast_entry_points_experiment/components/banner.vue';
import { COOKIE_NAME } from 'ee/projects/sast_entry_points_experiment/constants';
import ExperimentTracking from '~/experimentation/experiment_tracking';
jest.mock('~/experimentation/experiment_tracking');
let wrapper;
const sastDocumentationPath = 'sast_documentation_path';
const findBanner = () => wrapper.findComponent(GlBanner);
function createComponent() {
wrapper = shallowMount(Banner, {
propsData: { sastDocumentationPath },
});
}
afterEach(() => {
wrapper.destroy();
Cookies.remove(COOKIE_NAME);
});
describe('When the cookie is set', () => {
beforeEach(() => {
Cookies.set(COOKIE_NAME, 'true', { expires: 365 });
createComponent();
});
it('does not render the component', () => {
expect(findBanner().exists()).toBe(false);
});
});
describe('When the cookie is not set', () => {
beforeEach(() => {
createComponent();
});
it('renders the component', () => {
expect(findBanner().exists()).toBe(true);
});
it('tracks the show event', () => {
expect(ExperimentTracking.prototype.event).toHaveBeenCalledWith('show');
});
it('uses the sastDocumentationPath from the props for the button link', () => {
expect(findBanner().attributes('buttonlink')).toBe(sastDocumentationPath);
});
it('matches the snapshot', () => {
expect(wrapper.element).toMatchSnapshot();
});
describe('When clicking the CTA button', () => {
beforeEach(() => {
findBanner().vm.$emit('primary');
});
it('tracks the cta_clicked event', () => {
expect(ExperimentTracking.prototype.event).toHaveBeenCalledWith('cta_clicked');
});
it('sets a cookie', () => {
expect(Cookies.get(COOKIE_NAME)).toBe('true');
});
});
describe('When dismissing the component', () => {
beforeEach(() => {
findBanner().vm.$emit('close');
});
it('tracks the dismissed event', () => {
expect(ExperimentTracking.prototype.event).toHaveBeenCalledWith('dismissed');
});
it('sets a cookie', () => {
expect(Cookies.get(COOKIE_NAME)).toBe('true');
});
it('hides the component', () => {
expect(findBanner().exists()).toBe(false);
});
});
});
import '~/commons';
import { GlPopover, GlButton, GlLink } from '@gitlab/ui';
import { shallowMount } from '@vue/test-utils';
import Cookies from 'js-cookie';
import PopoverDark from 'ee/projects/sast_entry_points_experiment/components/popover_dark.vue';
import { COOKIE_NAME } from 'ee/projects/sast_entry_points_experiment/constants';
import ExperimentTracking from '~/experimentation/experiment_tracking';
jest.mock('~/experimentation/experiment_tracking');
let wrapper;
const sastDocumentationPath = 'sast_documentation_path';
const findPopover = () => wrapper.findComponent(GlPopover);
const findCtaLink = () => findPopover().findComponent(GlLink);
const findCloseButton = () => findPopover().findComponent(GlButton);
function createComponent() {
wrapper = shallowMount(PopoverDark, {
propsData: { sastDocumentationPath },
});
}
afterEach(() => {
wrapper.destroy();
Cookies.remove(COOKIE_NAME);
});
describe('When the cookie is set', () => {
beforeEach(() => {
Cookies.set(COOKIE_NAME, 'true', { expires: 365 });
createComponent();
});
it('does not render the component', () => {
expect(findPopover().exists()).toBe(false);
});
});
describe('When the cookie is not set', () => {
beforeEach(() => {
createComponent();
});
it('renders the component', () => {
expect(findPopover().exists()).toBe(true);
});
it('tracks the show event', () => {
expect(ExperimentTracking.prototype.event).toHaveBeenCalledWith('show');
});
it('uses the sastDocumentationPath from the props for the button link', () => {
expect(findCtaLink().attributes('href')).toBe(sastDocumentationPath);
});
it('matches the snapshot', () => {
expect(wrapper.element).toMatchSnapshot();
});
describe('When clicking the CTA button', () => {
beforeEach(() => {
findCtaLink().vm.$emit('click');
});
it('tracks the cta_clicked event', () => {
expect(ExperimentTracking.prototype.event).toHaveBeenCalledWith('cta_clicked');
});
it('sets a cookie', () => {
expect(Cookies.get(COOKIE_NAME)).toBe('true');
});
});
describe('When dismissing the component', () => {
beforeEach(() => {
findCloseButton().vm.$emit('click');
});
it('tracks the dismissed event', () => {
expect(ExperimentTracking.prototype.event).toHaveBeenCalledWith('dismissed');
});
it('sets a cookie', () => {
expect(Cookies.get(COOKIE_NAME)).toBe('true');
});
it('hides the component', () => {
expect(findPopover().exists()).toBe(false);
});
});
});
import '~/commons';
import { GlPopover, GlButton, GlLink } from '@gitlab/ui';
import { mount } from '@vue/test-utils';
import Cookies from 'js-cookie';
import PopoverLight from 'ee/projects/sast_entry_points_experiment/components/popover_light.vue';
import { COOKIE_NAME } from 'ee/projects/sast_entry_points_experiment/constants';
import ExperimentTracking from '~/experimentation/experiment_tracking';
jest.mock('~/experimentation/experiment_tracking');
let wrapper;
const sastDocumentationPath = 'sast_documentation_path';
const findPopover = () => wrapper.findComponent(GlPopover);
const findCtaLink = () => findPopover().findComponent(GlLink);
const findCloseButton = () => findPopover().findComponent(GlButton);
function createComponent() {
wrapper = mount(PopoverLight, {
propsData: { sastDocumentationPath },
});
}
afterEach(() => {
wrapper.destroy();
Cookies.remove(COOKIE_NAME);
});
describe('When the cookie is set', () => {
beforeEach(() => {
Cookies.set(COOKIE_NAME, 'true', { expires: 365 });
createComponent();
});
it('does not render the component', () => {
expect(findPopover().exists()).toBe(false);
});
});
describe('When the cookie is not set', () => {
beforeEach(() => {
createComponent();
});
it('renders the component', () => {
expect(findPopover().exists()).toBe(true);
});
it('tracks the show event', () => {
expect(ExperimentTracking.prototype.event).toHaveBeenCalledWith('show');
});
it('uses the sastDocumentationPath from the props for the button link', () => {
expect(findCtaLink().attributes('href')).toBe(sastDocumentationPath);
});
it('matches the snapshot', () => {
expect(wrapper.element).toMatchSnapshot();
});
describe('When clicking the CTA button', () => {
beforeEach(() => {
findCtaLink().vm.$emit('click');
});
it('tracks the cta_clicked event', () => {
expect(ExperimentTracking.prototype.event).toHaveBeenCalledWith('cta_clicked');
});
it('sets a cookie', () => {
expect(Cookies.get(COOKIE_NAME)).toBe('true');
});
});
describe('When dismissing the component', () => {
beforeEach(() => {
findCloseButton().vm.$emit('click');
});
it('tracks the dismissed event', () => {
expect(ExperimentTracking.prototype.event).toHaveBeenCalledWith('dismissed');
});
it('sets a cookie', () => {
expect(Cookies.get(COOKIE_NAME)).toBe('true');
});
it('hides the component', () => {
expect(findPopover().exists()).toBe(false);
});
});
});
......@@ -451,49 +451,4 @@ RSpec.describe ProjectsHelper do
})
end
end
describe '#enable_sast_entry_points_experiment?' do
using RSpec::Parameterized::TableSyntax
where(
can_admin_project?: [true, false],
empty_repo?: [true, false],
sast_enabled?: [true, false]
)
with_them do
before do
allow(helper).to receive(:can?) { can_admin_project? }
allow(project).to receive(:empty_repo?) { empty_repo? }
allow(project).to receive(:scanner_enabled?).and_call_original
allow(OnboardingProgress).to receive(:completed?).with(project.root_ancestor, :security_scan_enabled) { sast_enabled? }
allow(helper).to receive(:current_user) { double }
end
subject { helper.enable_sast_entry_points_experiment?(project) }
it { is_expected.to eq(can_admin_project? && !empty_repo? && !sast_enabled?) }
end
end
describe '#sast_entry_points_experiment_enabled?' do
using RSpec::Parameterized::TableSyntax
where(
enable_sast_entry_points_experiment?: [true, false],
experiment_enabled?: [true, false]
)
with_them do
before do
allow(helper).to receive(:enable_sast_entry_points_experiment?) { enable_sast_entry_points_experiment? }
variant = experiment_enabled? ? :banner : :control
stub_experiments(sast_entry_points: variant)
end
subject { helper.sast_entry_points_experiment_enabled?(project) }
it { is_expected.to eq(enable_sast_entry_points_experiment? && experiment_enabled?) }
end
end
end
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe ProjectPresenter do
include Gitlab::Routing.url_helpers
let(:user) { create(:user) }
describe '#extra_statistics_buttons' do
let(:project) { create(:project) }
let(:presenter) { described_class.new(project, current_user: user) }
it { expect(presenter.extra_statistics_buttons).to be_empty }
context 'when the sast entry points experiment is enabled' do
before do
allow(presenter).to receive(:sast_entry_points_experiment_enabled?).with(project).and_return(true)
end
it 'has the sast help page button' do
expect(presenter.extra_statistics_buttons.find { |button| button[:link] == help_page_path('user/application_security/sast/index') }).not_to be_nil
end
end
end
end
......@@ -30298,21 +30298,6 @@ msgstr ""
msgid "SVG illustration"
msgstr ""
msgid "SastEntryPoints|Add Security Testing"
msgstr ""
msgid "SastEntryPoints|Catch your security vulnerabilities ahead of time!"
msgstr ""
msgid "SastEntryPoints|GitLab can scan your code for security vulnerabilities. Static Application Security Testing (SAST) helps you worry less and build more."
msgstr ""
msgid "SastEntryPoints|How do I set up SAST?"
msgstr ""
msgid "SastEntryPoints|Learn more"
msgstr ""
msgid "Satisfied"
msgstr ""
......
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