Commit 5b239279 authored by Vitaly Slobodin's avatar Vitaly Slobodin

Add Export license usage file button

Add "Export license usage file" button for exporting
the usage to a CSV file.
parent 73f7feb1
<script> <script>
import { GlAlert } from '@gitlab/ui'; import { GlAlert, GlButton } from '@gitlab/ui';
import { import {
activateSubscription, activateSubscription,
noActiveSubscription, noActiveSubscription,
...@@ -7,6 +7,7 @@ import { ...@@ -7,6 +7,7 @@ import {
subscriptionHistoryQueries, subscriptionHistoryQueries,
subscriptionMainTitle, subscriptionMainTitle,
subscriptionQueries, subscriptionQueries,
exportLicenseUsageBtnText,
} from '../constants'; } from '../constants';
import SubscriptionActivationCard from './subscription_activation_card.vue'; import SubscriptionActivationCard from './subscription_activation_card.vue';
import SubscriptionBreakdown from './subscription_breakdown.vue'; import SubscriptionBreakdown from './subscription_breakdown.vue';
...@@ -17,6 +18,7 @@ export default { ...@@ -17,6 +18,7 @@ export default {
name: 'CloudLicenseApp', name: 'CloudLicenseApp',
components: { components: {
GlAlert, GlAlert,
GlButton,
SubscriptionActivationCard, SubscriptionActivationCard,
SubscriptionBreakdown, SubscriptionBreakdown,
SubscriptionPurchaseCard, SubscriptionPurchaseCard,
...@@ -24,11 +26,16 @@ export default { ...@@ -24,11 +26,16 @@ export default {
}, },
i18n: { i18n: {
activateSubscription, activateSubscription,
exportLicenseUsageBtnText,
noActiveSubscription, noActiveSubscription,
subscriptionActivationNotificationText, subscriptionActivationNotificationText,
subscriptionMainTitle, subscriptionMainTitle,
}, },
props: { props: {
licenseUsageFilePath: {
type: String,
required: true,
},
hasActiveLicense: { hasActiveLicense: {
type: Boolean, type: Boolean,
required: false, required: false,
...@@ -81,8 +88,15 @@ export default { ...@@ -81,8 +88,15 @@ export default {
</script> </script>
<template> <template>
<div class="gl-display-flex gl-justify-content-center gl-flex-direction-column"> <div>
<div
class="gl-display-flex gl-flex-direction-row gl-justify-content-space-between gl-align-items-center"
>
<h4 data-testid="subscription-main-title">{{ $options.i18n.subscriptionMainTitle }}</h4> <h4 data-testid="subscription-main-title">{{ $options.i18n.subscriptionMainTitle }}</h4>
<gl-button v-if="canShowSubscriptionDetails" :href="licenseUsageFilePath">{{
$options.i18n.exportLicenseUsageBtnText
}}</gl-button>
</div>
<hr /> <hr />
<gl-alert <gl-alert
v-if="shouldShowActivationNotification" v-if="shouldShowActivationNotification"
......
...@@ -144,3 +144,4 @@ export const subscriptionBannerText = s__( ...@@ -144,3 +144,4 @@ export const subscriptionBannerText = s__(
); );
export const subscriptionBannerBlogPostUrl = export const subscriptionBannerBlogPostUrl =
'https://about.gitlab.com/blog/2021/07/20/improved-billing-and-subscription-management/'; 'https://about.gitlab.com/blog/2021/07/20/improved-billing-and-subscription-management/';
export const exportLicenseUsageBtnText = s__('SuperSonics|Export license usage file');
...@@ -33,6 +33,7 @@ export default () => { ...@@ -33,6 +33,7 @@ export default () => {
licenseUploadPath, licenseUploadPath,
subscriptionActivationBannerCalloutName, subscriptionActivationBannerCalloutName,
subscriptionSyncPath, subscriptionSyncPath,
licenseUsageFilePath,
} = el.dataset; } = el.dataset;
const connectivityHelpURL = helpPagePath('/user/admin_area/license.html', { const connectivityHelpURL = helpPagePath('/user/admin_area/license.html', {
anchor: 'there-is-a-connectivity-issue', anchor: 'there-is-a-connectivity-issue',
...@@ -56,6 +57,7 @@ export default () => { ...@@ -56,6 +57,7 @@ export default () => {
h(CloudLicenseShowApp, { h(CloudLicenseShowApp, {
props: { props: {
hasActiveLicense: parseBoolean(hasActiveLicense), hasActiveLicense: parseBoolean(hasActiveLicense),
licenseUsageFilePath,
}, },
}), }),
}); });
......
...@@ -62,7 +62,8 @@ module LicenseHelper ...@@ -62,7 +62,8 @@ module LicenseHelper
license_remove_path: admin_license_path, license_remove_path: admin_license_path,
subscription_sync_path: sync_seat_link_admin_license_path, subscription_sync_path: sync_seat_link_admin_license_path,
congratulation_svg_path: image_path('illustrations/illustration-congratulation-purchase.svg'), congratulation_svg_path: image_path('illustrations/illustration-congratulation-purchase.svg'),
subscription_activation_banner_callout_name: ::EE::UserCalloutsHelper::CL_SUBSCRIPTION_ACTIVATION subscription_activation_banner_callout_name: ::EE::UserCalloutsHelper::CL_SUBSCRIPTION_ACTIVATION,
license_usage_file_path: admin_license_usage_export_path(format: :csv)
} }
end end
......
...@@ -10,6 +10,12 @@ RSpec.describe 'Admin views Subscription', :js do ...@@ -10,6 +10,12 @@ RSpec.describe 'Admin views Subscription', :js do
gitlab_enable_admin_mode_sign_in(admin) gitlab_enable_admin_mode_sign_in(admin)
end end
shared_examples 'an "Export license usage file" button' do
it 'displays the Export License Usage File button' do
expect(page).to have_link('Export license usage file', href: admin_license_usage_export_path(format: :csv))
end
end
context 'with a cloud license' do context 'with a cloud license' do
let!(:license) { create_current_license(cloud_licensing_enabled: true, plan: License::ULTIMATE_PLAN) } let!(:license) { create_current_license(cloud_licensing_enabled: true, plan: License::ULTIMATE_PLAN) }
...@@ -43,6 +49,8 @@ RSpec.describe 'Admin views Subscription', :js do ...@@ -43,6 +49,8 @@ RSpec.describe 'Admin views Subscription', :js do
expect(page).to have_content('You can no longer sync your subscription details with GitLab. Get help for the most common connectivity issues by troubleshooting the activation code') expect(page).to have_content('You can no longer sync your subscription details with GitLab. Get help for the most common connectivity issues by troubleshooting the activation code')
end end
end end
it_behaves_like 'an "Export license usage file" button'
end end
end end
...@@ -53,6 +61,8 @@ RSpec.describe 'Admin views Subscription', :js do ...@@ -53,6 +61,8 @@ RSpec.describe 'Admin views Subscription', :js do
visit(admin_subscription_path) visit(admin_subscription_path)
end end
it_behaves_like 'an "Export license usage file" button'
context 'when removing a license file' do context 'when removing a license file' do
before do before do
accept_alert do accept_alert do
...@@ -118,6 +128,10 @@ RSpec.describe 'Admin views Subscription', :js do ...@@ -118,6 +128,10 @@ RSpec.describe 'Admin views Subscription', :js do
end end
end end
it 'does not display the Export License Usage File button' do
expect(page).not_to have_link('Export license usage file', href: admin_license_usage_export_path(format: :csv))
end
context 'when activating a new subscription' do context 'when activating a new subscription' do
before do before do
license = create(:license, data: create(:gitlab_license, { cloud_licensing_enabled: true, plan: License::ULTIMATE_PLAN }).export) license = create(:license, data: create(:gitlab_license, { cloud_licensing_enabled: true, plan: License::ULTIMATE_PLAN }).export)
......
import { GlButton } from '@gitlab/ui';
import { createLocalVue, shallowMount } from '@vue/test-utils'; import { createLocalVue, shallowMount } from '@vue/test-utils';
import VueApollo from 'vue-apollo'; import VueApollo from 'vue-apollo';
import SubscriptionManagementApp from 'ee/admin/subscriptions/show/components/app.vue'; import SubscriptionManagementApp from 'ee/admin/subscriptions/show/components/app.vue';
...@@ -28,6 +29,7 @@ describe('SubscriptionManagementApp', () => { ...@@ -28,6 +29,7 @@ describe('SubscriptionManagementApp', () => {
const findSubscriptionMainTitle = () => wrapper.findByTestId('subscription-main-title'); const findSubscriptionMainTitle = () => wrapper.findByTestId('subscription-main-title');
const findSubscriptionActivationSuccessAlert = () => const findSubscriptionActivationSuccessAlert = () =>
wrapper.findByTestId('subscription-activation-success-alert'); wrapper.findByTestId('subscription-activation-success-alert');
const findExportLicenseUsageFileLink = () => wrapper.findComponent(GlButton);
let currentSubscriptionResolver; let currentSubscriptionResolver;
let subscriptionHistoryResolver; let subscriptionHistoryResolver;
...@@ -45,6 +47,7 @@ describe('SubscriptionManagementApp', () => { ...@@ -45,6 +47,7 @@ describe('SubscriptionManagementApp', () => {
localVue, localVue,
apolloProvider: createMockApolloProvider(resolverMock), apolloProvider: createMockApolloProvider(resolverMock),
propsData: { propsData: {
licenseUsageFilePath: 'about:blank',
...props, ...props,
}, },
}), }),
...@@ -92,6 +95,10 @@ describe('SubscriptionManagementApp', () => { ...@@ -92,6 +95,10 @@ describe('SubscriptionManagementApp', () => {
it('does not show the activation success notification', () => { it('does not show the activation success notification', () => {
expect(findSubscriptionActivationSuccessAlert().exists()).toBe(false); expect(findSubscriptionActivationSuccessAlert().exists()).toBe(false);
}); });
it('does not render the "Export license usage file" link', () => {
expect(findExportLicenseUsageFileLink().exists()).toBe(false);
});
}); });
describe('activating the license', () => { describe('activating the license', () => {
...@@ -154,6 +161,10 @@ describe('SubscriptionManagementApp', () => { ...@@ -154,6 +161,10 @@ describe('SubscriptionManagementApp', () => {
it('does not the activation success notification', () => { it('does not the activation success notification', () => {
expect(findSubscriptionActivationSuccessAlert().exists()).toBe(false); expect(findSubscriptionActivationSuccessAlert().exists()).toBe(false);
}); });
it('renders the "Export license usage file" link', () => {
expect(findExportLicenseUsageFileLink().exists()).toBe(true);
});
}); });
}); });
}); });
...@@ -101,7 +101,8 @@ RSpec.describe LicenseHelper do ...@@ -101,7 +101,8 @@ RSpec.describe LicenseHelper do
license_upload_path: new_admin_license_path, license_upload_path: new_admin_license_path,
license_remove_path: admin_license_path, license_remove_path: admin_license_path,
congratulation_svg_path: helper.image_path('illustrations/illustration-congratulation-purchase.svg'), congratulation_svg_path: helper.image_path('illustrations/illustration-congratulation-purchase.svg'),
subscription_activation_banner_callout_name: ::EE::UserCalloutsHelper::CL_SUBSCRIPTION_ACTIVATION }) subscription_activation_banner_callout_name: ::EE::UserCalloutsHelper::CL_SUBSCRIPTION_ACTIVATION,
license_usage_file_path: admin_license_usage_export_path(format: :csv) })
end end
end end
...@@ -117,7 +118,8 @@ RSpec.describe LicenseHelper do ...@@ -117,7 +118,8 @@ RSpec.describe LicenseHelper do
license_upload_path: new_admin_license_path, license_upload_path: new_admin_license_path,
license_remove_path: admin_license_path, license_remove_path: admin_license_path,
congratulation_svg_path: helper.image_path('illustrations/illustration-congratulation-purchase.svg'), congratulation_svg_path: helper.image_path('illustrations/illustration-congratulation-purchase.svg'),
subscription_activation_banner_callout_name: ::EE::UserCalloutsHelper::CL_SUBSCRIPTION_ACTIVATION }) subscription_activation_banner_callout_name: ::EE::UserCalloutsHelper::CL_SUBSCRIPTION_ACTIVATION,
license_usage_file_path: admin_license_usage_export_path(format: :csv) })
end end
end end
end end
......
...@@ -31722,6 +31722,9 @@ msgstr "" ...@@ -31722,6 +31722,9 @@ msgstr ""
msgid "SuperSonics|Expires on" msgid "SuperSonics|Expires on"
msgstr "" msgstr ""
msgid "SuperSonics|Export license usage file"
msgstr ""
msgid "SuperSonics|Free trial" msgid "SuperSonics|Free trial"
msgstr "" 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