Commit ab695c19 authored by Stan Hu's avatar Stan Hu

Merge branch 'sh-secure-frontend-cookies' into 'master'

Enable Secure attribute for frontend cookies

See merge request gitlab-org/gitlab!79383
parents 50152771 9104396d
/* eslint-disable class-methods-use-this */ /* eslint-disable class-methods-use-this */
import $ from 'jquery'; import $ from 'jquery';
import Cookies from 'js-cookie'; import { setCookie } from '~/lib/utils/common_utils';
import createFlash from '~/flash'; import createFlash from '~/flash';
import { s__ } from '~/locale'; import { s__ } from '~/locale';
import { localTimeAgo } from './lib/utils/datetime_utility'; import { localTimeAgo } from './lib/utils/datetime_utility';
...@@ -55,7 +55,7 @@ export default class Activities { ...@@ -55,7 +55,7 @@ export default class Activities {
const filter = $sender.attr('id').split('_')[0]; const filter = $sender.attr('id').split('_')[0];
$('.event-filter .active').removeClass('active'); $('.event-filter .active').removeClass('active');
Cookies.set('event_filter', filter); setCookie('event_filter', filter);
$sender.closest('li').toggleClass('active'); $sender.closest('li').toggleClass('active');
} }
......
...@@ -2,10 +2,10 @@ ...@@ -2,10 +2,10 @@
import { GlBreakpointInstance as bp } from '@gitlab/ui/dist/utils'; import { GlBreakpointInstance as bp } from '@gitlab/ui/dist/utils';
import $ from 'jquery'; import $ from 'jquery';
import Cookies from 'js-cookie';
import { uniq } from 'lodash'; import { uniq } from 'lodash';
import { getCookie, setCookie, scrollToElement } from '~/lib/utils/common_utils';
import * as Emoji from '~/emoji'; import * as Emoji from '~/emoji';
import { scrollToElement } from '~/lib/utils/common_utils';
import { dispose, fixTitle } from '~/tooltips'; import { dispose, fixTitle } from '~/tooltips';
import createFlash from './flash'; import createFlash from './flash';
import axios from './lib/utils/axios_utils'; import axios from './lib/utils/axios_utils';
...@@ -506,7 +506,7 @@ export class AwardsHandler { ...@@ -506,7 +506,7 @@ export class AwardsHandler {
addEmojiToFrequentlyUsedList(emoji) { addEmojiToFrequentlyUsedList(emoji) {
if (this.emoji.isEmojiNameValid(emoji)) { if (this.emoji.isEmojiNameValid(emoji)) {
this.frequentlyUsedEmojis = uniq(this.getFrequentlyUsedEmojis().concat(emoji)); this.frequentlyUsedEmojis = uniq(this.getFrequentlyUsedEmojis().concat(emoji));
Cookies.set('frequently_used_emojis', this.frequentlyUsedEmojis.join(','), { expires: 365 }); setCookie('frequently_used_emojis', this.frequentlyUsedEmojis.join(','));
} }
} }
...@@ -514,7 +514,7 @@ export class AwardsHandler { ...@@ -514,7 +514,7 @@ export class AwardsHandler {
return ( return (
this.frequentlyUsedEmojis || this.frequentlyUsedEmojis ||
(() => { (() => {
const frequentlyUsedEmojis = uniq((Cookies.get('frequently_used_emojis') || '').split(',')); const frequentlyUsedEmojis = uniq((getCookie('frequently_used_emojis') || '').split(','));
this.frequentlyUsedEmojis = frequentlyUsedEmojis.filter((inputName) => this.frequentlyUsedEmojis = frequentlyUsedEmojis.filter((inputName) =>
this.emoji.isEmojiNameValid(inputName), this.emoji.isEmojiNameValid(inputName),
); );
......
import $ from 'jquery'; import $ from 'jquery';
import Cookies from 'js-cookie';
import { flatten } from 'lodash'; import { flatten } from 'lodash';
import Mousetrap from 'mousetrap'; import Mousetrap from 'mousetrap';
import Vue from 'vue'; import Vue from 'vue';
import { parseBoolean } from '~/lib/utils/common_utils'; import { getCookie, setCookie, parseBoolean } from '~/lib/utils/common_utils';
import findAndFollowLink from '~/lib/utils/navigation_utility'; import findAndFollowLink from '~/lib/utils/navigation_utility';
import { refreshCurrentPage, visitUrl } from '~/lib/utils/url_utility'; import { refreshCurrentPage, visitUrl } from '~/lib/utils/url_utility';
import { import {
...@@ -161,10 +161,10 @@ export default class Shortcuts { ...@@ -161,10 +161,10 @@ export default class Shortcuts {
static onTogglePerfBar(e) { static onTogglePerfBar(e) {
e.preventDefault(); e.preventDefault();
const performanceBarCookieName = 'perf_bar_enabled'; const performanceBarCookieName = 'perf_bar_enabled';
if (parseBoolean(Cookies.get(performanceBarCookieName))) { if (parseBoolean(getCookie(performanceBarCookieName))) {
Cookies.set(performanceBarCookieName, 'false', { expires: 365, path: '/' }); setCookie(performanceBarCookieName, 'false', { path: '/' });
} else { } else {
Cookies.set(performanceBarCookieName, 'true', { expires: 365, path: '/' }); setCookie(performanceBarCookieName, 'true', { path: '/' });
} }
refreshCurrentPage(); refreshCurrentPage();
} }
...@@ -172,8 +172,8 @@ export default class Shortcuts { ...@@ -172,8 +172,8 @@ export default class Shortcuts {
static onToggleCanary(e) { static onToggleCanary(e) {
e.preventDefault(); e.preventDefault();
const canaryCookieName = 'gitlab_canary'; const canaryCookieName = 'gitlab_canary';
const currentValue = parseBoolean(Cookies.get(canaryCookieName)); const currentValue = parseBoolean(getCookie(canaryCookieName));
Cookies.set(canaryCookieName, (!currentValue).toString(), { setCookie(canaryCookieName, (!currentValue).toString(), {
expires: 365, expires: 365,
path: '/', path: '/',
// next.gitlab.com uses a leading period. See https://gitlab.com/gitlab-org/gitlab/-/issues/350186 // next.gitlab.com uses a leading period. See https://gitlab.com/gitlab-org/gitlab/-/issues/350186
......
<script> <script>
import { GlModal, GlSprintf, GlLink, GlButton } from '@gitlab/ui'; import { GlModal, GlSprintf, GlLink, GlButton } from '@gitlab/ui';
import Cookies from 'js-cookie'; import { getCookie, removeCookie } from '~/lib/utils/common_utils';
import { __, s__ } from '~/locale'; import { __, s__ } from '~/locale';
import Tracking from '~/tracking'; import Tracking from '~/tracking';
...@@ -62,7 +62,7 @@ export default { ...@@ -62,7 +62,7 @@ export default {
return this.commitCookiePath || this.projectMergeRequestsPath; return this.commitCookiePath || this.projectMergeRequestsPath;
}, },
commitCookiePath() { commitCookiePath() {
const cookieVal = Cookies.get(this.commitCookie); const cookieVal = getCookie(this.commitCookie);
if (cookieVal !== 'true') return cookieVal; if (cookieVal !== 'true') return cookieVal;
return ''; return '';
...@@ -85,7 +85,7 @@ export default { ...@@ -85,7 +85,7 @@ export default {
}, },
methods: { methods: {
disableModalFromRenderingAgain() { disableModalFromRenderingAgain() {
Cookies.remove(this.commitCookie); removeCookie(this.commitCookie);
}, },
}, },
}; };
......
import Cookies from 'js-cookie'; import { setCookie } from '~/lib/utils/common_utils';
const handleOnDismiss = ({ currentTarget }) => { const handleOnDismiss = ({ currentTarget }) => {
currentTarget.removeEventListener('click', handleOnDismiss); currentTarget.removeEventListener('click', handleOnDismiss);
...@@ -6,7 +6,7 @@ const handleOnDismiss = ({ currentTarget }) => { ...@@ -6,7 +6,7 @@ const handleOnDismiss = ({ currentTarget }) => {
dataset: { id, expireDate }, dataset: { id, expireDate },
} = currentTarget; } = currentTarget;
Cookies.set(`hide_broadcast_message_${id}`, true, { expires: new Date(expireDate) }); setCookie(`hide_broadcast_message_${id}`, true, { expires: new Date(expireDate) });
const notification = document.querySelector(`.js-broadcast-notification-${id}`); const notification = document.querySelector(`.js-broadcast-notification-${id}`);
notification.parentNode.removeChild(notification); notification.parentNode.removeChild(notification);
......
...@@ -14,8 +14,8 @@ import { ...@@ -14,8 +14,8 @@ import {
GlModal, GlModal,
GlSprintf, GlSprintf,
} from '@gitlab/ui'; } from '@gitlab/ui';
import Cookies from 'js-cookie';
import { mapActions, mapState } from 'vuex'; import { mapActions, mapState } from 'vuex';
import { getCookie, setCookie } from '~/lib/utils/common_utils';
import { __ } from '~/locale'; import { __ } from '~/locale';
import Tracking from '~/tracking'; import Tracking from '~/tracking';
import glFeatureFlagsMixin from '~/vue_shared/mixins/gl_feature_flags_mixin'; import glFeatureFlagsMixin from '~/vue_shared/mixins/gl_feature_flags_mixin';
...@@ -59,7 +59,7 @@ export default { ...@@ -59,7 +59,7 @@ export default {
mixins: [glFeatureFlagsMixin(), trackingMixin], mixins: [glFeatureFlagsMixin(), trackingMixin],
data() { data() {
return { return {
isTipDismissed: Cookies.get(AWS_TIP_DISMISSED_COOKIE_NAME) === 'true', isTipDismissed: getCookie(AWS_TIP_DISMISSED_COOKIE_NAME) === 'true',
validationErrorEventProperty: '', validationErrorEventProperty: '',
}; };
}, },
...@@ -176,7 +176,7 @@ export default { ...@@ -176,7 +176,7 @@ export default {
'setVariableProtected', 'setVariableProtected',
]), ]),
dismissTip() { dismissTip() {
Cookies.set(AWS_TIP_DISMISSED_COOKIE_NAME, 'true', { expires: 90 }); setCookie(AWS_TIP_DISMISSED_COOKIE_NAME, 'true', { expires: 90 });
this.isTipDismissed = true; this.isTipDismissed = true;
}, },
deleteVarAndClose() { deleteVarAndClose() {
......
import { GlBreakpointInstance as bp, breakpoints } from '@gitlab/ui/dist/utils'; import { GlBreakpointInstance as bp, breakpoints } from '@gitlab/ui/dist/utils';
import $ from 'jquery'; import $ from 'jquery';
import Cookies from 'js-cookie';
import { debounce } from 'lodash'; import { debounce } from 'lodash';
import { getCookie, setCookie, parseBoolean } from '~/lib/utils/common_utils';
import initInviteMembersModal from '~/invite_members/init_invite_members_modal'; import initInviteMembersModal from '~/invite_members/init_invite_members_modal';
import initInviteMembersTrigger from '~/invite_members/init_invite_members_trigger'; import initInviteMembersTrigger from '~/invite_members/init_invite_members_trigger';
import { parseBoolean } from '~/lib/utils/common_utils';
export const SIDEBAR_COLLAPSED_CLASS = 'js-sidebar-collapsed'; export const SIDEBAR_COLLAPSED_CLASS = 'js-sidebar-collapsed';
...@@ -59,7 +58,7 @@ export default class ContextualSidebar { ...@@ -59,7 +58,7 @@ export default class ContextualSidebar {
if (!ContextualSidebar.isDesktopBreakpoint()) { if (!ContextualSidebar.isDesktopBreakpoint()) {
return; return;
} }
Cookies.set('sidebar_collapsed', value, { expires: 365 * 10 }); setCookie('sidebar_collapsed', value, { expires: 365 * 10 });
} }
toggleSidebarNav(show) { toggleSidebarNav(show) {
...@@ -111,7 +110,7 @@ export default class ContextualSidebar { ...@@ -111,7 +110,7 @@ export default class ContextualSidebar {
if (!ContextualSidebar.isDesktopBreakpoint()) { if (!ContextualSidebar.isDesktopBreakpoint()) {
this.toggleSidebarNav(false); this.toggleSidebarNav(false);
} else { } else {
const collapse = parseBoolean(Cookies.get('sidebar_collapsed')); const collapse = parseBoolean(getCookie('sidebar_collapsed'));
this.toggleCollapsedSidebar(collapse, true); this.toggleCollapsedSidebar(collapse, true);
} }
......
<script> <script>
import { GlLoadingIcon } from '@gitlab/ui'; import { GlLoadingIcon } from '@gitlab/ui';
import Cookies from 'js-cookie';
import { mapActions, mapState, mapGetters } from 'vuex'; import { mapActions, mapState, mapGetters } from 'vuex';
import { getCookie, setCookie } from '~/lib/utils/common_utils';
import { toYmd } from '~/analytics/shared/utils'; import { toYmd } from '~/analytics/shared/utils';
import PathNavigation from '~/cycle_analytics/components/path_navigation.vue'; import PathNavigation from '~/cycle_analytics/components/path_navigation.vue';
import StageTable from '~/cycle_analytics/components/stage_table.vue'; import StageTable from '~/cycle_analytics/components/stage_table.vue';
...@@ -35,7 +35,7 @@ export default { ...@@ -35,7 +35,7 @@ export default {
}, },
data() { data() {
return { return {
isOverviewDialogDismissed: Cookies.get(OVERVIEW_DIALOG_COOKIE), isOverviewDialogDismissed: getCookie(OVERVIEW_DIALOG_COOKIE),
}; };
}, },
computed: { computed: {
...@@ -134,7 +134,7 @@ export default { ...@@ -134,7 +134,7 @@ export default {
}, },
dismissOverviewDialog() { dismissOverviewDialog() {
this.isOverviewDialogDismissed = true; this.isOverviewDialogDismissed = true;
Cookies.set(OVERVIEW_DIALOG_COOKIE, '1', { expires: 365 }); setCookie(OVERVIEW_DIALOG_COOKIE, '1');
}, },
isUserAllowed(id) { isUserAllowed(id) {
const { permissions } = this; const { permissions } = this;
......
...@@ -13,7 +13,6 @@ deprecated_notes_spec.js is the spec for the legacy, jQuery notes application. I ...@@ -13,7 +13,6 @@ deprecated_notes_spec.js is the spec for the legacy, jQuery notes application. I
import { GlDeprecatedSkeletonLoading as GlSkeletonLoading } from '@gitlab/ui'; import { GlDeprecatedSkeletonLoading as GlSkeletonLoading } from '@gitlab/ui';
import Autosize from 'autosize'; import Autosize from 'autosize';
import $ from 'jquery'; import $ from 'jquery';
import Cookies from 'js-cookie';
import { escape, uniqueId } from 'lodash'; import { escape, uniqueId } from 'lodash';
import Vue from 'vue'; import Vue from 'vue';
import '~/lib/utils/jquery_at_who'; import '~/lib/utils/jquery_at_who';
...@@ -28,6 +27,7 @@ import { defaultAutocompleteConfig } from './gfm_auto_complete'; ...@@ -28,6 +27,7 @@ import { defaultAutocompleteConfig } from './gfm_auto_complete';
import GLForm from './gl_form'; import GLForm from './gl_form';
import axios from './lib/utils/axios_utils'; import axios from './lib/utils/axios_utils';
import { import {
getCookie,
isInViewport, isInViewport,
getPagePath, getPagePath,
scrollToElement, scrollToElement,
...@@ -121,7 +121,7 @@ export default class Notes { ...@@ -121,7 +121,7 @@ export default class Notes {
} }
setViewType(view) { setViewType(view) {
this.view = Cookies.get('diff_view') || view; this.view = getCookie('diff_view') || view;
} }
addBinding() { addBinding() {
...@@ -473,7 +473,7 @@ export default class Notes { ...@@ -473,7 +473,7 @@ export default class Notes {
} }
isParallelView() { isParallelView() {
return Cookies.get('diff_view') === 'parallel'; return getCookie('diff_view') === 'parallel';
} }
/** /**
......
<script> <script>
import { GlCollapse, GlButton, GlPopover } from '@gitlab/ui'; import { GlCollapse, GlButton, GlPopover } from '@gitlab/ui';
import Cookies from 'js-cookie'; import { getCookie, setCookie, parseBoolean, isLoggedIn } from '~/lib/utils/common_utils';
import { parseBoolean, isLoggedIn } from '~/lib/utils/common_utils';
import { s__ } from '~/locale'; import { s__ } from '~/locale';
import Participants from '~/sidebar/components/participants/participants.vue'; import Participants from '~/sidebar/components/participants/participants.vue';
import glFeatureFlagsMixin from '~/vue_shared/mixins/gl_feature_flags_mixin'; import glFeatureFlagsMixin from '~/vue_shared/mixins/gl_feature_flags_mixin';
...@@ -53,7 +53,7 @@ export default { ...@@ -53,7 +53,7 @@ export default {
}, },
data() { data() {
return { return {
isResolvedCommentsPopoverHidden: parseBoolean(Cookies.get(this.$options.cookieKey)), isResolvedCommentsPopoverHidden: parseBoolean(getCookie(this.$options.cookieKey)),
discussionWithOpenForm: '', discussionWithOpenForm: '',
isLoggedIn: isLoggedIn(), isLoggedIn: isLoggedIn(),
}; };
...@@ -96,7 +96,7 @@ export default { ...@@ -96,7 +96,7 @@ export default {
methods: { methods: {
handleSidebarClick() { handleSidebarClick() {
this.isResolvedCommentsPopoverHidden = true; this.isResolvedCommentsPopoverHidden = true;
Cookies.set(this.$options.cookieKey, 'true', { expires: 365 * 10 }); setCookie(this.$options.cookieKey, 'true', { expires: 365 * 10 });
this.updateActiveDiscussion(); this.updateActiveDiscussion();
}, },
updateActiveDiscussion(id) { updateActiveDiscussion(id) {
......
import Cookies from 'js-cookie';
import Vue from 'vue'; import Vue from 'vue';
import { mapActions, mapState, mapGetters } from 'vuex'; import { mapActions, mapState, mapGetters } from 'vuex';
import { parseBoolean } from '~/lib/utils/common_utils'; import { getCookie, setCookie, parseBoolean, removeCookie } from '~/lib/utils/common_utils';
import { getParameterValues } from '~/lib/utils/url_utility'; import { getParameterValues } from '~/lib/utils/url_utility';
import eventHub from '../notes/event_hub'; import eventHub from '../notes/event_hub';
import diffsApp from './components/app.vue'; import diffsApp from './components/app.vue';
...@@ -58,14 +58,14 @@ export default function initDiffsApp(store) { ...@@ -58,14 +58,14 @@ export default function initDiffsApp(store) {
// Check for cookie and save that setting for future use. // Check for cookie and save that setting for future use.
// Then delete the cookie as we are phasing it out and using the database as SSOT. // Then delete the cookie as we are phasing it out and using the database as SSOT.
// NOTE: This can/should be removed later // NOTE: This can/should be removed later
if (Cookies.get(DIFF_WHITESPACE_COOKIE_NAME)) { if (getCookie(DIFF_WHITESPACE_COOKIE_NAME)) {
const hideWhitespace = Cookies.get(DIFF_WHITESPACE_COOKIE_NAME); const hideWhitespace = getCookie(DIFF_WHITESPACE_COOKIE_NAME);
this.setShowWhitespace({ this.setShowWhitespace({
url: this.endpointUpdateUser, url: this.endpointUpdateUser,
showWhitespace: hideWhitespace !== '1', showWhitespace: hideWhitespace !== '1',
trackClick: false, trackClick: false,
}); });
Cookies.remove(DIFF_WHITESPACE_COOKIE_NAME); removeCookie(DIFF_WHITESPACE_COOKIE_NAME);
} else { } else {
// This is only to set the the user preference in Vuex for use later // This is only to set the the user preference in Vuex for use later
this.setShowWhitespace({ this.setShowWhitespace({
...@@ -77,7 +77,7 @@ export default function initDiffsApp(store) { ...@@ -77,7 +77,7 @@ export default function initDiffsApp(store) {
const vScrollingParam = getParameterValues('virtual_scrolling')[0]; const vScrollingParam = getParameterValues('virtual_scrolling')[0];
if (vScrollingParam === 'false' || vScrollingParam === 'true') { if (vScrollingParam === 'false' || vScrollingParam === 'true') {
Cookies.set('diffs_virtual_scrolling', vScrollingParam); setCookie('diffs_virtual_scrolling', vScrollingParam);
} }
}, },
methods: { methods: {
......
import Cookies from 'js-cookie';
import Vue from 'vue'; import Vue from 'vue';
import {
setCookie,
handleLocationHash,
historyPushState,
scrollToElement,
} from '~/lib/utils/common_utils';
import createFlash from '~/flash'; import createFlash from '~/flash';
import { diffViewerModes } from '~/ide/constants'; import { diffViewerModes } from '~/ide/constants';
import axios from '~/lib/utils/axios_utils'; import axios from '~/lib/utils/axios_utils';
import { handleLocationHash, historyPushState, scrollToElement } from '~/lib/utils/common_utils';
import httpStatusCodes from '~/lib/utils/http_status'; import httpStatusCodes from '~/lib/utils/http_status';
import Poll from '~/lib/utils/poll'; import Poll from '~/lib/utils/poll';
import { mergeUrlParams, getLocationHash } from '~/lib/utils/url_utility'; import { mergeUrlParams, getLocationHash } from '~/lib/utils/url_utility';
...@@ -369,7 +374,7 @@ export const setRenderIt = ({ commit }, file) => commit(types.RENDER_FILE, file) ...@@ -369,7 +374,7 @@ export const setRenderIt = ({ commit }, file) => commit(types.RENDER_FILE, file)
export const setInlineDiffViewType = ({ commit }) => { export const setInlineDiffViewType = ({ commit }) => {
commit(types.SET_DIFF_VIEW_TYPE, INLINE_DIFF_VIEW_TYPE); commit(types.SET_DIFF_VIEW_TYPE, INLINE_DIFF_VIEW_TYPE);
Cookies.set(DIFF_VIEW_COOKIE_NAME, INLINE_DIFF_VIEW_TYPE); setCookie(DIFF_VIEW_COOKIE_NAME, INLINE_DIFF_VIEW_TYPE);
const url = mergeUrlParams({ view: INLINE_DIFF_VIEW_TYPE }, window.location.href); const url = mergeUrlParams({ view: INLINE_DIFF_VIEW_TYPE }, window.location.href);
historyPushState(url); historyPushState(url);
...@@ -381,7 +386,7 @@ export const setInlineDiffViewType = ({ commit }) => { ...@@ -381,7 +386,7 @@ export const setInlineDiffViewType = ({ commit }) => {
export const setParallelDiffViewType = ({ commit }) => { export const setParallelDiffViewType = ({ commit }) => {
commit(types.SET_DIFF_VIEW_TYPE, PARALLEL_DIFF_VIEW_TYPE); commit(types.SET_DIFF_VIEW_TYPE, PARALLEL_DIFF_VIEW_TYPE);
Cookies.set(DIFF_VIEW_COOKIE_NAME, PARALLEL_DIFF_VIEW_TYPE); setCookie(DIFF_VIEW_COOKIE_NAME, PARALLEL_DIFF_VIEW_TYPE);
const url = mergeUrlParams({ view: PARALLEL_DIFF_VIEW_TYPE }, window.location.href); const url = mergeUrlParams({ view: PARALLEL_DIFF_VIEW_TYPE }, window.location.href);
historyPushState(url); historyPushState(url);
......
import Cookies from 'js-cookie'; import { getCookie } from '~/lib/utils/common_utils';
import { getParameterValues } from '~/lib/utils/url_utility'; import { getParameterValues } from '~/lib/utils/url_utility';
import { __, n__ } from '~/locale'; import { __, n__ } from '~/locale';
import { import {
...@@ -175,7 +175,7 @@ export function suggestionCommitMessage(state, _, rootState) { ...@@ -175,7 +175,7 @@ export function suggestionCommitMessage(state, _, rootState) {
} }
export const isVirtualScrollingEnabled = (state) => { export const isVirtualScrollingEnabled = (state) => {
const vSrollerCookie = Cookies.get('diffs_virtual_scrolling'); const vSrollerCookie = getCookie('diffs_virtual_scrolling');
if (state.disableVirtualScroller) { if (state.disableVirtualScroller) {
return false; return false;
......
import Cookies from 'js-cookie'; import { getCookie } from '~/lib/utils/common_utils';
import { getParameterValues } from '~/lib/utils/url_utility'; import { getParameterValues } from '~/lib/utils/url_utility';
import { INLINE_DIFF_VIEW_TYPE, DIFF_VIEW_COOKIE_NAME } from '../../constants'; import { INLINE_DIFF_VIEW_TYPE, DIFF_VIEW_COOKIE_NAME } from '../../constants';
const getViewTypeFromQueryString = () => getParameterValues('view')[0]; const getViewTypeFromQueryString = () => getParameterValues('view')[0];
const viewTypeFromCookie = Cookies.get(DIFF_VIEW_COOKIE_NAME); const viewTypeFromCookie = getCookie(DIFF_VIEW_COOKIE_NAME);
const defaultViewType = INLINE_DIFF_VIEW_TYPE; const defaultViewType = INLINE_DIFF_VIEW_TYPE;
export default () => ({ export default () => ({
......
import Cookies from 'js-cookie';
import { chunk, memoize, uniq } from 'lodash'; import { chunk, memoize, uniq } from 'lodash';
import { getCookie, setCookie } from '~/lib/utils/common_utils';
import { initEmojiMap, getEmojiCategoryMap } from '~/emoji'; import { initEmojiMap, getEmojiCategoryMap } from '~/emoji';
import { import {
EMOJIS_PER_ROW, EMOJIS_PER_ROW,
...@@ -13,7 +13,7 @@ export const generateCategoryHeight = (emojisLength) => ...@@ -13,7 +13,7 @@ export const generateCategoryHeight = (emojisLength) =>
emojisLength * EMOJI_ROW_HEIGHT + CATEGORY_ROW_HEIGHT; emojisLength * EMOJI_ROW_HEIGHT + CATEGORY_ROW_HEIGHT;
export const getFrequentlyUsedEmojis = () => { export const getFrequentlyUsedEmojis = () => {
const savedEmojis = Cookies.get(FREQUENTLY_USED_COOKIE_KEY); const savedEmojis = getCookie(FREQUENTLY_USED_COOKIE_KEY);
if (!savedEmojis) return null; if (!savedEmojis) return null;
...@@ -30,13 +30,13 @@ export const getFrequentlyUsedEmojis = () => { ...@@ -30,13 +30,13 @@ export const getFrequentlyUsedEmojis = () => {
export const addToFrequentlyUsed = (emoji) => { export const addToFrequentlyUsed = (emoji) => {
const frequentlyUsedEmojis = uniq( const frequentlyUsedEmojis = uniq(
(Cookies.get(FREQUENTLY_USED_COOKIE_KEY) || '') (getCookie(FREQUENTLY_USED_COOKIE_KEY) || '')
.split(',') .split(',')
.filter((e) => e) .filter((e) => e)
.concat(emoji), .concat(emoji),
); );
Cookies.set(FREQUENTLY_USED_COOKIE_KEY, frequentlyUsedEmojis.join(','), { expires: 365 }); setCookie(FREQUENTLY_USED_COOKIE_KEY, frequentlyUsedEmojis.join(','));
}; };
export const hasFrequentlyUsedEmojis = () => getFrequentlyUsedEmojis() !== null; export const hasFrequentlyUsedEmojis = () => getFrequentlyUsedEmojis() !== null;
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
* causes reflows, visit https://gist.github.com/paulirish/5d52fb081b3570c81e3a * causes reflows, visit https://gist.github.com/paulirish/5d52fb081b3570c81e3a
*/ */
import Cookies from 'js-cookie'; import { getCookie } from '~/lib/utils/common_utils';
const LINE_NUMBER_CLASS = 'diff-line-num'; const LINE_NUMBER_CLASS = 'diff-line-num';
const UNFOLDABLE_LINE_CLASS = 'js-unfold'; const UNFOLDABLE_LINE_CLASS = 'js-unfold';
...@@ -29,7 +29,7 @@ export default { ...@@ -29,7 +29,7 @@ export default {
$diffFile.closest(DIFF_CONTAINER_SELECTOR).data('canCreateNote') === ''; $diffFile.closest(DIFF_CONTAINER_SELECTOR).data('canCreateNote') === '';
} }
this.isParallelView = Cookies.get('diff_view') === 'parallel'; this.isParallelView = getCookie('diff_view') === 'parallel';
if (this.userCanCreateNote) { if (this.userCanCreateNote) {
$diffFile $diffFile
......
import Cookies from 'js-cookie'; import { getCookie, setCookie, parseBoolean } from '~/lib/utils/common_utils';
import { parseBoolean } from '~/lib/utils/common_utils';
class Landing { class Landing {
constructor(landingElement, dismissButton, cookieName) { constructor(landingElement, dismissButton, cookieName) {
...@@ -27,11 +26,11 @@ class Landing { ...@@ -27,11 +26,11 @@ class Landing {
dismissLanding() { dismissLanding() {
this.landingElement.classList.add('hidden'); this.landingElement.classList.add('hidden');
Cookies.set(this.cookieName, 'true', { expires: 365 }); setCookie(this.cookieName, 'true');
} }
isDismissed() { isDismissed() {
return parseBoolean(Cookies.get(this.cookieName)); return parseBoolean(getCookie(this.cookieName));
} }
} }
......
import { GlBreakpointInstance as bp } from '@gitlab/ui/dist/utils'; import { GlBreakpointInstance as bp } from '@gitlab/ui/dist/utils';
import $ from 'jquery'; import $ from 'jquery';
import Cookies from 'js-cookie'; import { setCookie } from '~/lib/utils/common_utils';
import { loadCSSFile } from '~/lib/utils/css_utils'; import { loadCSSFile } from '~/lib/utils/css_utils';
import UsersSelect from '~/users_select'; import UsersSelect from '~/users_select';
...@@ -62,7 +62,7 @@ export default class IssuableContext { ...@@ -62,7 +62,7 @@ export default class IssuableContext {
const supportedSizes = ['xs', 'sm', 'md']; const supportedSizes = ['xs', 'sm', 'md'];
if (supportedSizes.includes(bpBreakpoint)) { if (supportedSizes.includes(bpBreakpoint)) {
Cookies.set('collapsed_gutter', true); setCookie('collapsed_gutter', true);
} }
}); });
} }
......
...@@ -705,7 +705,10 @@ export const scopedLabelKey = ({ title = '' }) => { ...@@ -705,7 +705,10 @@ export const scopedLabelKey = ({ title = '' }) => {
}; };
// Methods to set and get Cookie // Methods to set and get Cookie
export const setCookie = (name, value) => Cookies.set(name, value, { expires: 365 }); export const setCookie = (name, value, attributes) => {
const defaults = { expires: 365, secure: Boolean(window.gon?.secure) };
Cookies.set(name, value, { ...defaults, ...attributes });
};
export const getCookie = (name) => Cookies.get(name); export const getCookie = (name) => Cookies.get(name);
......
import Cookies from 'js-cookie'; import { setCookie } from '~/lib/utils/common_utils';
import createFlash from '~/flash'; import createFlash from '~/flash';
import axios from '~/lib/utils/axios_utils'; import axios from '~/lib/utils/axios_utils';
import { __ } from '~/locale'; import { __ } from '~/locale';
...@@ -51,7 +51,7 @@ export const setFailedRequest = ({ commit }, message) => { ...@@ -51,7 +51,7 @@ export const setFailedRequest = ({ commit }, message) => {
export const setViewType = ({ commit }, viewType) => { export const setViewType = ({ commit }, viewType) => {
commit(types.SET_VIEW_TYPE, viewType); commit(types.SET_VIEW_TYPE, viewType);
Cookies.set('diff_view', viewType); setCookie('diff_view', viewType);
}; };
export const setSubmitState = ({ commit }, isSubmitting) => { export const setSubmitState = ({ commit }, isSubmitting) => {
......
import Cookies from 'js-cookie'; import { getCookie } from '~/lib/utils/common_utils';
import { VIEW_TYPES } from '../constants'; import { VIEW_TYPES } from '../constants';
const diffViewType = Cookies.get('diff_view'); const diffViewType = getCookie('diff_view');
export default () => ({ export default () => ({
isLoading: true, isLoading: true,
......
/* eslint-disable no-new, class-methods-use-this */ /* eslint-disable no-new, class-methods-use-this */
import { GlBreakpointInstance as bp } from '@gitlab/ui/dist/utils'; import { GlBreakpointInstance as bp } from '@gitlab/ui/dist/utils';
import $ from 'jquery'; import $ from 'jquery';
import Cookies from 'js-cookie';
import Vue from 'vue'; import Vue from 'vue';
import {
getCookie,
parseUrlPathname,
isMetaClick,
parseBoolean,
scrollToElement,
} from '~/lib/utils/common_utils';
import createEventHub from '~/helpers/event_hub_factory'; import createEventHub from '~/helpers/event_hub_factory';
import BlobForkSuggestion from './blob/blob_fork_suggestion'; import BlobForkSuggestion from './blob/blob_fork_suggestion';
import Diff from './diff'; import Diff from './diff';
import createFlash from './flash'; import createFlash from './flash';
import { initDiffStatsDropdown } from './init_diff_stats_dropdown'; import { initDiffStatsDropdown } from './init_diff_stats_dropdown';
import axios from './lib/utils/axios_utils'; import axios from './lib/utils/axios_utils';
import {
parseUrlPathname,
isMetaClick,
parseBoolean,
scrollToElement,
} from './lib/utils/common_utils';
import { localTimeAgo } from './lib/utils/datetime_utility'; import { localTimeAgo } from './lib/utils/datetime_utility';
import { isInVueNoteablePage } from './lib/utils/dom_utils'; import { isInVueNoteablePage } from './lib/utils/dom_utils';
import { __ } from './locale'; import { __ } from './locale';
...@@ -514,7 +515,7 @@ export default class MergeRequestTabs { ...@@ -514,7 +515,7 @@ export default class MergeRequestTabs {
// Expand the issuable sidebar unless the user explicitly collapsed it // Expand the issuable sidebar unless the user explicitly collapsed it
expandView() { expandView() {
if (parseBoolean(Cookies.get('collapsed_gutter'))) { if (parseBoolean(getCookie('collapsed_gutter'))) {
return; return;
} }
const $gutterBtn = $('.js-sidebar-toggle'); const $gutterBtn = $('.js-sidebar-toggle');
......
<script> <script>
import { GlButton } from '@gitlab/ui'; import { GlButton } from '@gitlab/ui';
import Cookies from 'js-cookie';
import Vue from 'vue'; import Vue from 'vue';
import { parseBoolean } from '~/lib/utils/common_utils'; import { getCookie, setCookie, parseBoolean } from '~/lib/utils/common_utils';
import Translate from '../../../../../vue_shared/translate'; import Translate from '../../../../../vue_shared/translate';
Vue.use(Translate); Vue.use(Translate);
...@@ -17,13 +17,13 @@ export default { ...@@ -17,13 +17,13 @@ export default {
inject: ['docsUrl', 'illustrationUrl'], inject: ['docsUrl', 'illustrationUrl'],
data() { data() {
return { return {
calloutDismissed: parseBoolean(Cookies.get(cookieKey)), calloutDismissed: parseBoolean(getCookie(cookieKey)),
}; };
}, },
methods: { methods: {
dismissCallout() { dismissCallout() {
this.calloutDismissed = true; this.calloutDismissed = true;
Cookies.set(cookieKey, this.calloutDismissed, { expires: 365 }); setCookie(cookieKey, this.calloutDismissed);
}, },
}, },
}; };
......
/* eslint-disable func-names, no-return-assign */ /* eslint-disable func-names, no-return-assign */
import $ from 'jquery'; import $ from 'jquery';
import Cookies from 'js-cookie'; import { setCookie } from '~/lib/utils/common_utils';
import initClonePanel from '~/clone_panel'; import initClonePanel from '~/clone_panel';
import initDeprecatedJQueryDropdown from '~/deprecated_jquery_dropdown'; import initDeprecatedJQueryDropdown from '~/deprecated_jquery_dropdown';
import createFlash from '~/flash'; import createFlash from '~/flash';
...@@ -24,19 +24,19 @@ export default class Project { ...@@ -24,19 +24,19 @@ export default class Project {
} }
$('.js-hide-no-ssh-message').on('click', function (e) { $('.js-hide-no-ssh-message').on('click', function (e) {
Cookies.set('hide_no_ssh_message', 'false'); setCookie('hide_no_ssh_message', 'false');
$(this).parents('.js-no-ssh-key-message').remove(); $(this).parents('.js-no-ssh-key-message').remove();
return e.preventDefault(); return e.preventDefault();
}); });
$('.js-hide-no-password-message').on('click', function (e) { $('.js-hide-no-password-message').on('click', function (e) {
Cookies.set('hide_no_password_message', 'false'); setCookie('hide_no_password_message', 'false');
$(this).parents('.js-no-password-message').remove(); $(this).parents('.js-no-password-message').remove();
return e.preventDefault(); return e.preventDefault();
}); });
$('.hide-auto-devops-implicitly-enabled-banner').on('click', function (e) { $('.hide-auto-devops-implicitly-enabled-banner').on('click', function (e) {
const projectId = $(this).data('project-id'); const projectId = $(this).data('project-id');
const cookieKey = `hide_auto_devops_implicitly_enabled_banner_${projectId}`; const cookieKey = `hide_auto_devops_implicitly_enabled_banner_${projectId}`;
Cookies.set(cookieKey, 'false'); setCookie(cookieKey, 'false');
$(this).parents('.auto-devops-implicitly-enabled-banner').remove(); $(this).parents('.auto-devops-implicitly-enabled-banner').remove();
return e.preventDefault(); return e.preventDefault();
}); });
......
import $ from 'jquery'; import $ from 'jquery';
import Cookies from 'js-cookie'; import { setCookie } from '~/lib/utils/common_utils';
import UserCallout from '~/user_callout'; import UserCallout from '~/user_callout';
import UserTabs from './user_tabs'; import UserTabs from './user_tabs';
...@@ -10,7 +10,7 @@ function initUserProfile(action) { ...@@ -10,7 +10,7 @@ function initUserProfile(action) {
// hide project limit message // hide project limit message
$('.hide-project-limit-message').on('click', (e) => { $('.hide-project-limit-message').on('click', (e) => {
e.preventDefault(); e.preventDefault();
Cookies.set('hide_project_limit_message', 'false'); setCookie('hide_project_limit_message', 'false');
$(this).parents('.project-limit-message').remove(); $(this).parents('.project-limit-message').remove();
}); });
} }
......
/* eslint-disable func-names, consistent-return, no-param-reassign */ /* eslint-disable func-names, consistent-return, no-param-reassign */
import $ from 'jquery'; import $ from 'jquery';
import Cookies from 'js-cookie'; import { setCookie } from '~/lib/utils/common_utils';
import { hide, fixTitle } from '~/tooltips'; import { hide, fixTitle } from '~/tooltips';
import createFlash from './flash'; import createFlash from './flash';
import axios from './lib/utils/axios_utils'; import axios from './lib/utils/axios_utils';
...@@ -80,7 +80,7 @@ Sidebar.prototype.sidebarToggleClicked = function (e, triggered) { ...@@ -80,7 +80,7 @@ Sidebar.prototype.sidebarToggleClicked = function (e, triggered) {
hide($this); hide($this);
if (!triggered) { if (!triggered) {
Cookies.set('collapsed_gutter', $('.right-sidebar').hasClass('right-sidebar-collapsed')); setCookie('collapsed_gutter', $('.right-sidebar').hasClass('right-sidebar-collapsed'));
} }
}; };
......
<script> <script>
import { GlBanner } from '@gitlab/ui'; import { GlBanner } from '@gitlab/ui';
import Cookies from 'js-cookie'; import { getCookie, setCookie, parseBoolean } from '~/lib/utils/common_utils';
import { parseBoolean } from '~/lib/utils/common_utils';
export default { export default {
components: { components: {
...@@ -19,13 +18,13 @@ export default { ...@@ -19,13 +18,13 @@ export default {
}; };
}, },
created() { created() {
if (parseBoolean(Cookies.get('hide_serverless_survey'))) { if (parseBoolean(getCookie('hide_serverless_survey'))) {
this.visible = false; this.visible = false;
} }
}, },
methods: { methods: {
handleClose() { handleClose() {
Cookies.set('hide_serverless_survey', 'true', { expires: 365 * 10 }); setCookie('hide_serverless_survey', 'true', { expires: 365 * 10 });
this.visible = false; this.visible = false;
}, },
}, },
......
import $ from 'jquery'; import $ from 'jquery';
import Cookies from 'js-cookie'; import { getCookie, setCookie } from '~/lib/utils/common_utils';
export default class UserCallout { export default class UserCallout {
constructor(options = {}) { constructor(options = {}) {
...@@ -9,7 +9,7 @@ export default class UserCallout { ...@@ -9,7 +9,7 @@ export default class UserCallout {
this.userCalloutBody = $(`.${className}`); this.userCalloutBody = $(`.${className}`);
this.cookieName = this.userCalloutBody.data('uid'); this.cookieName = this.userCalloutBody.data('uid');
this.isCalloutDismissed = Cookies.get(this.cookieName); this.isCalloutDismissed = getCookie(this.cookieName);
this.init(); this.init();
} }
...@@ -30,7 +30,7 @@ export default class UserCallout { ...@@ -30,7 +30,7 @@ export default class UserCallout {
cookieOptions.path = this.userCalloutBody.data('projectPath'); cookieOptions.path = this.userCalloutBody.data('projectPath');
} }
Cookies.set(this.cookieName, 'true', cookieOptions); setCookie(this.cookieName, 'true', cookieOptions);
if ($currentTarget.hasClass('close') || $currentTarget.hasClass('js-close')) { if ($currentTarget.hasClass('close') || $currentTarget.hasClass('js-close')) {
this.userCalloutBody.remove(); this.userCalloutBody.remove();
......
import Vue from 'vue'; import Vue from 'vue';
import Cookies from 'js-cookie'; import { setCookie, parseBoolean } from '~/lib/utils/common_utils';
import { parseBoolean } from '~/lib/utils/common_utils';
import DismissibleAlert from '~/vue_shared/components/dismissible_alert.vue'; import DismissibleAlert from '~/vue_shared/components/dismissible_alert.vue';
const getCookieExpirationPeriod = (expirationPeriod) => { const getCookieExpirationPeriod = (expirationPeriod) => {
...@@ -33,7 +33,7 @@ const mountVueAlert = (el) => { ...@@ -33,7 +33,7 @@ const mountVueAlert = (el) => {
if (!dismissCookieName) { if (!dismissCookieName) {
return; return;
} }
Cookies.set(dismissCookieName, true, { setCookie(dismissCookieName, true, {
expires: getCookieExpirationPeriod(dismissCookieExpire), expires: getCookieExpirationPeriod(dismissCookieExpire),
}); });
}, },
......
<script> <script>
import { GlIcon } from '@gitlab/ui'; import { GlIcon } from '@gitlab/ui';
import { GlBreakpointInstance as bp } from '@gitlab/ui/dist/utils'; import { GlBreakpointInstance as bp } from '@gitlab/ui/dist/utils';
import Cookies from 'js-cookie'; import { getCookie, setCookie, parseBoolean } from '~/lib/utils/common_utils';
import { parseBoolean } from '~/lib/utils/common_utils';
import { USER_COLLAPSED_GUTTER_COOKIE } from '../constants'; import { USER_COLLAPSED_GUTTER_COOKIE } from '../constants';
export default { export default {
...@@ -10,7 +10,7 @@ export default { ...@@ -10,7 +10,7 @@ export default {
GlIcon, GlIcon,
}, },
data() { data() {
const userExpanded = !parseBoolean(Cookies.get(USER_COLLAPSED_GUTTER_COOKIE)); const userExpanded = !parseBoolean(getCookie(USER_COLLAPSED_GUTTER_COOKIE));
// We're deliberately keeping two different props for sidebar status; // We're deliberately keeping two different props for sidebar status;
// 1. userExpanded reflects value based on cookie `collapsed_gutter`. // 1. userExpanded reflects value based on cookie `collapsed_gutter`.
...@@ -46,7 +46,7 @@ export default { ...@@ -46,7 +46,7 @@ export default {
this.isExpanded = !this.isExpanded; this.isExpanded = !this.isExpanded;
this.userExpanded = this.isExpanded; this.userExpanded = this.isExpanded;
Cookies.set(USER_COLLAPSED_GUTTER_COOKIE, !this.userExpanded); setCookie(USER_COLLAPSED_GUTTER_COOKIE, !this.userExpanded);
this.updatePageContainerClass(); this.updatePageContainerClass();
}, },
}, },
......
import $ from 'jquery'; import $ from 'jquery';
import Cookies from 'js-cookie';
import Vue from 'vue'; import Vue from 'vue';
import VueApollo from 'vue-apollo'; import VueApollo from 'vue-apollo';
import { setCookie } from '~/lib/utils/common_utils';
import createDefaultClient from '~/lib/graphql'; import createDefaultClient from '~/lib/graphql';
import glFeatureFlagsMixin from '~/vue_shared/mixins/gl_feature_flags_mixin'; import glFeatureFlagsMixin from '~/vue_shared/mixins/gl_feature_flags_mixin';
import BurnCharts from './components/burn_charts.vue'; import BurnCharts from './components/burn_charts.vue';
...@@ -17,7 +17,7 @@ export default () => { ...@@ -17,7 +17,7 @@ export default () => {
const hint = $('.burndown-hint'); const hint = $('.burndown-hint');
hint.on('click', '.dismiss-icon', () => { hint.on('click', '.dismiss-icon', () => {
hint.hide(); hint.hide();
Cookies.set('hide_burndown_message', 'true'); setCookie('hide_burndown_message', 'true');
}); });
// generate burndown chart (if data available) // generate burndown chart (if data available)
......
<script> <script>
import { GlTabs, GlTab } from '@gitlab/ui'; import { GlTabs, GlTab } from '@gitlab/ui';
import Cookies from 'js-cookie'; import { getCookie } from '~/lib/utils/common_utils';
import { __ } from '~/locale'; import { __ } from '~/locale';
import { DRAWER_Z_INDEX } from '~/lib/utils/constants'; import { DRAWER_Z_INDEX } from '~/lib/utils/constants';
import { COMPLIANCE_TAB_COOKIE_KEY } from '../constants'; import { COMPLIANCE_TAB_COOKIE_KEY } from '../constants';
...@@ -60,7 +60,7 @@ export default { ...@@ -60,7 +60,7 @@ export default {
}, },
methods: { methods: {
showTabs() { showTabs() {
return Cookies.get(COMPLIANCE_TAB_COOKIE_KEY) === 'true'; return getCookie(COMPLIANCE_TAB_COOKIE_KEY) === 'true';
}, },
toggleDrawer(mergeRequest) { toggleDrawer(mergeRequest) {
if (this.showDrawer && mergeRequest.id === this.drawerMergeRequest.id) { if (this.showDrawer && mergeRequest.id === this.drawerMergeRequest.id) {
......
import Cookies from 'js-cookie'; import { getCookie, setCookie, parseBoolean } from '~/lib/utils/common_utils';
import { parseBoolean } from '~/lib/utils/common_utils';
export default class EETrialBanner { export default class EETrialBanner {
constructor($trialBanner) { constructor($trialBanner) {
...@@ -55,23 +54,23 @@ export default class EETrialBanner { ...@@ -55,23 +54,23 @@ export default class EETrialBanner {
const today = new Date(); const today = new Date();
// Check if Cookie is defined // Check if Cookie is defined
if (!Cookies.get(this.COOKIE_KEY)) { if (!getCookie(this.COOKIE_KEY)) {
// Cookie was not defined, let's define with default value // Cookie was not defined, let's define with default value
// Check if License is yet to expire // Check if License is yet to expire
if (today < this.licenseExpiresOn) { if (today < this.licenseExpiresOn) {
// License has not expired yet, we show initial banner of 7 days // License has not expired yet, we show initial banner of 7 days
// with cookie set to validity same as license expiry // with cookie set to validity same as license expiry
Cookies.set(this.COOKIE_KEY, 'true', { expires: this.licenseExpiresOn }); setCookie(this.COOKIE_KEY, 'true', { expires: this.licenseExpiresOn });
} else { } else {
// License is already expired so we show final Banner with cookie set to 20 years validity. // License is already expired so we show final Banner with cookie set to 20 years validity.
Cookies.set(this.COOKIE_KEY, 'true', { expires: 7300 }); setCookie(this.COOKIE_KEY, 'true', { expires: 7300 });
} }
this.toggleBanner(true); this.toggleBanner(true);
} else { } else {
// Cookie was defined, let's read value and show/hide banner // Cookie was defined, let's read value and show/hide banner
this.toggleBanner(parseBoolean(Cookies.get(this.COOKIE_KEY))); this.toggleBanner(parseBoolean(getCookie(this.COOKIE_KEY)));
} }
} }
...@@ -103,8 +102,8 @@ export default class EETrialBanner { ...@@ -103,8 +102,8 @@ export default class EETrialBanner {
this.toggleBanner(false); this.toggleBanner(false);
this.toggleMainNavbarMargin(false); this.toggleMainNavbarMargin(false);
this.toggleSecondaryNavbarMargin(false); this.toggleSecondaryNavbarMargin(false);
if (Cookies.get(this.COOKIE_KEY)) { if (getCookie(this.COOKIE_KEY)) {
Cookies.set(this.COOKIE_KEY, 'false'); setCookie(this.COOKIE_KEY, 'false');
} }
} }
} }
import { GlBreakpointInstance as bp } from '@gitlab/ui/dist/utils'; import { GlBreakpointInstance as bp } from '@gitlab/ui/dist/utils';
import Cookies from 'js-cookie';
import Vue from 'vue'; import Vue from 'vue';
import VueApollo from 'vue-apollo'; import VueApollo from 'vue-apollo';
import { mapActions } from 'vuex'; import { mapActions } from 'vuex';
import { setCookie, convertObjectPropsToCamelCase, parseBoolean } from '~/lib/utils/common_utils';
import { parseIssuableData } from '~/issues/show/utils/parse_data'; import { parseIssuableData } from '~/issues/show/utils/parse_data';
import { convertObjectPropsToCamelCase, parseBoolean } from '~/lib/utils/common_utils';
import { defaultClient } from '~/sidebar/graphql'; import { defaultClient } from '~/sidebar/graphql';
import labelsSelectModule from '~/vue_shared/components/sidebar/labels_select_vue/store'; import labelsSelectModule from '~/vue_shared/components/sidebar/labels_select_vue/store';
...@@ -35,7 +35,7 @@ export default () => { ...@@ -35,7 +35,7 @@ export default () => {
// Collapse the sidebar on mobile screens by default // Collapse the sidebar on mobile screens by default
const bpBreakpoint = bp.getBreakpointSize(); const bpBreakpoint = bp.getBreakpointSize();
if (bpBreakpoint === 'xs' || bpBreakpoint === 'sm' || bpBreakpoint === 'md') { if (bpBreakpoint === 'xs' || bpBreakpoint === 'sm' || bpBreakpoint === 'md') {
Cookies.set('collapsed_gutter', true); setCookie('collapsed_gutter', true);
} }
return new Vue({ return new Vue({
......
import { GlBreakpointInstance as bp } from '@gitlab/ui/dist/utils'; import { GlBreakpointInstance as bp } from '@gitlab/ui/dist/utils';
import $ from 'jquery'; import $ from 'jquery';
import Cookies from 'js-cookie'; import { setCookie } from '~/lib/utils/common_utils';
export default class SidebarContext { export default class SidebarContext {
constructor() { constructor() {
...@@ -35,7 +35,7 @@ export default class SidebarContext { ...@@ -35,7 +35,7 @@ export default class SidebarContext {
// collapsed_gutter cookie hides the sidebar // collapsed_gutter cookie hides the sidebar
const bpBreakpoint = bp.getBreakpointSize(); const bpBreakpoint = bp.getBreakpointSize();
if (bpBreakpoint === 'xs' || bpBreakpoint === 'sm' || bpBreakpoint === 'md') { if (bpBreakpoint === 'xs' || bpBreakpoint === 'sm' || bpBreakpoint === 'md') {
Cookies.set('collapsed_gutter', true); setCookie('collapsed_gutter', true);
} }
}); });
} }
......
import $ from 'jquery'; import $ from 'jquery';
import Cookies from 'js-cookie'; import { getCookie, setCookie, parseBoolean } from '~/lib/utils/common_utils';
import { sanitize } from '~/lib/dompurify'; import { sanitize } from '~/lib/dompurify';
import createGqClient, { fetchPolicies } from '~/lib/graphql'; import createGqClient, { fetchPolicies } from '~/lib/graphql';
import { parseBoolean } from '~/lib/utils/common_utils';
import { dateInWords, parsePikadayDate } from '~/lib/utils/datetime_utility'; import { dateInWords, parsePikadayDate } from '~/lib/utils/datetime_utility';
import { __, s__, sprintf } from '~/locale'; import { __, s__, sprintf } from '~/locale';
...@@ -33,9 +32,9 @@ const toggleContainerClass = (className) => { ...@@ -33,9 +32,9 @@ const toggleContainerClass = (className) => {
} }
}; };
const getCollapsedGutter = () => parseBoolean(Cookies.get('collapsed_gutter')); const getCollapsedGutter = () => parseBoolean(getCookie('collapsed_gutter'));
const setCollapsedGutter = (value) => Cookies.set('collapsed_gutter', value); const setCollapsedGutter = (value) => setCookie('collapsed_gutter', value);
const getDateValidity = (startDateTime, dueDateTime) => { const getDateValidity = (startDateTime, dueDateTime) => {
// If both dates are defined // If both dates are defined
......
import Cookies from 'js-cookie'; import { setCookie } from '~/lib/utils/common_utils';
const handleOnDismiss = ({ currentTarget }) => { const handleOnDismiss = ({ currentTarget }) => {
const { const {
dataset: { id, level }, dataset: { id, level },
} = currentTarget; } = currentTarget;
Cookies.set(`hide_storage_limit_alert_${id}_${level}`, true, { expires: 30 }); setCookie(`hide_storage_limit_alert_${id}_${level}`, true, { expires: 30 });
const notification = document.querySelector('.js-namespace-storage-alert'); const notification = document.querySelector('.js-namespace-storage-alert');
notification.parentNode.removeChild(notification); notification.parentNode.removeChild(notification);
......
import Cookies from 'js-cookie'; import { setCookie } from '~/lib/utils/common_utils';
const handleOnDismiss = ({ currentTarget }) => { const handleOnDismiss = ({ currentTarget }) => {
const { const {
dataset: { cookieId }, dataset: { cookieId },
} = currentTarget; } = currentTarget;
Cookies.set(cookieId, true, { expires: 30 }); setCookie(cookieId, true, { expires: 30 });
}; };
export default () => { export default () => {
......
<script> <script>
import Cookies from 'js-cookie';
import { difference } from 'lodash'; import { difference } from 'lodash';
import { getCookie, setCookie, parseBoolean } from '~/lib/utils/common_utils';
import glFeatureFlagsMixin from '~/vue_shared/mixins/gl_feature_flags_mixin'; import glFeatureFlagsMixin from '~/vue_shared/mixins/gl_feature_flags_mixin';
import LocalStorageSync from '~/vue_shared/components/local_storage_sync.vue'; import LocalStorageSync from '~/vue_shared/components/local_storage_sync.vue';
import { parseBoolean } from '~/lib/utils/common_utils';
import { translateScannerNames } from '~/security_configuration/utils'; import { translateScannerNames } from '~/security_configuration/utils';
import SecurityTrainingPromo from 'ee/security_dashboard/components/shared/security_training_promo.vue'; import SecurityTrainingPromo from 'ee/security_dashboard/components/shared/security_training_promo.vue';
import ReportNotConfiguredProject from '../shared/empty_states/report_not_configured_project.vue'; import ReportNotConfiguredProject from '../shared/empty_states/report_not_configured_project.vue';
...@@ -31,7 +31,7 @@ export default { ...@@ -31,7 +31,7 @@ export default {
scannerAlertDismissed: false, scannerAlertDismissed: false,
securityScanners: {}, securityScanners: {},
shouldShowAutoFixUserCallout: shouldShowAutoFixUserCallout:
this.glFeatures.securityAutoFix && !Cookies.get(this.$options.autoFixUserCalloutCookieName), this.glFeatures.securityAutoFix && !getCookie(this.$options.autoFixUserCalloutCookieName),
}; };
}, },
apollo: { apollo: {
...@@ -73,7 +73,7 @@ export default { ...@@ -73,7 +73,7 @@ export default {
}, },
methods: { methods: {
closeAutoFixUserCallout() { closeAutoFixUserCallout() {
Cookies.set(this.$options.autoFixUserCalloutCookieName, 'true'); setCookie(this.$options.autoFixUserCalloutCookieName, 'true');
this.shouldShowAutoFixUserCallout = false; this.shouldShowAutoFixUserCallout = false;
}, },
setScannerAlertDismissed(value) { setScannerAlertDismissed(value) {
......
<script> <script>
import Cookies from 'js-cookie';
import { PortalTarget } from 'portal-vue'; import { PortalTarget } from 'portal-vue';
import { GlLink, GlSprintf } from '@gitlab/ui'; import { GlLink, GlSprintf } from '@gitlab/ui';
import { getCookie, setCookie } from '~/lib/utils/common_utils';
import { DASHBOARD_TYPES } from 'ee/security_dashboard/store/constants'; import { DASHBOARD_TYPES } from 'ee/security_dashboard/store/constants';
import { s__ } from '~/locale'; import { s__ } from '~/locale';
import glFeatureFlagsMixin from '~/vue_shared/mixins/gl_feature_flags_mixin'; import glFeatureFlagsMixin from '~/vue_shared/mixins/gl_feature_flags_mixin';
...@@ -58,7 +58,7 @@ export default { ...@@ -58,7 +58,7 @@ export default {
const shouldShowAutoFixUserCallout = const shouldShowAutoFixUserCallout =
this.dashboardType === DASHBOARD_TYPES.PROJECT && this.dashboardType === DASHBOARD_TYPES.PROJECT &&
this.glFeatures.securityAutoFix && this.glFeatures.securityAutoFix &&
!Cookies.get(this.$options.autoFixUserCalloutCookieName); !getCookie(this.$options.autoFixUserCalloutCookieName);
return { return {
filters: null, filters: null,
...@@ -103,7 +103,7 @@ export default { ...@@ -103,7 +103,7 @@ export default {
this.filters = filters; this.filters = filters;
}, },
handleAutoFixUserCalloutClose() { handleAutoFixUserCalloutClose() {
Cookies.set(this.$options.autoFixUserCalloutCookieName, 'true'); setCookie(this.$options.autoFixUserCalloutCookieName, 'true');
this.shouldShowAutoFixUserCallout = false; this.shouldShowAutoFixUserCallout = false;
}, },
}, },
......
<script> <script>
import { GlAlert } from '@gitlab/ui'; import { GlAlert } from '@gitlab/ui';
import Cookies from 'js-cookie'; import { getCookie, setCookie } from '~/lib/utils/common_utils';
import { __, sprintf } from '~/locale'; import { __, sprintf } from '~/locale';
export const COOKIE_NAME = 'dismissed_resolution_alerts'; export const COOKIE_NAME = 'dismissed_resolution_alerts';
...@@ -35,7 +35,7 @@ export default { ...@@ -35,7 +35,7 @@ export default {
methods: { methods: {
alreadyDismissedVulnerabilities() { alreadyDismissedVulnerabilities() {
try { try {
return JSON.parse(Cookies.get(COOKIE_NAME)); return JSON.parse(getCookie(COOKIE_NAME));
} catch (e) { } catch (e) {
return []; return [];
} }
...@@ -45,7 +45,7 @@ export default { ...@@ -45,7 +45,7 @@ export default {
}, },
dismiss() { dismiss() {
const dismissed = this.alreadyDismissedVulnerabilities().concat(this.vulnerabilityId); const dismissed = this.alreadyDismissedVulnerabilities().concat(this.vulnerabilityId);
Cookies.set(COOKIE_NAME, JSON.stringify(dismissed), { expires: 90 }); setCookie(COOKIE_NAME, JSON.stringify(dismissed), { expires: 90 });
this.isVisible = false; this.isVisible = false;
}, },
}, },
......
...@@ -55,7 +55,10 @@ describe('EE gitlab license banner dismiss', () => { ...@@ -55,7 +55,10 @@ describe('EE gitlab license banner dismiss', () => {
jest.spyOn(Cookies, 'set'); jest.spyOn(Cookies, 'set');
dismiss(); dismiss();
expect(Cookies.set).toHaveBeenCalledWith('show_ee_trial_banner', 'false'); expect(Cookies.set).toHaveBeenCalledWith('show_ee_trial_banner', 'false', {
expires: 365,
secure: false,
});
}); });
it('should not call Cookies.set for `show_ee_trial_banner` when a non close button is clicked', () => { it('should not call Cookies.set for `show_ee_trial_banner` when a non close button is clicked', () => {
......
...@@ -31,6 +31,7 @@ describe('broadcast message on dismiss', () => { ...@@ -31,6 +31,7 @@ describe('broadcast message on dismiss', () => {
expect(Cookies.set).toHaveBeenCalledWith('hide_storage_limit_alert_1_info', true, { expect(Cookies.set).toHaveBeenCalledWith('hide_storage_limit_alert_1_info', true, {
expires: 30, expires: 30,
secure: false,
}); });
}); });
}); });
...@@ -22,6 +22,9 @@ describe('dismissing the alert', () => { ...@@ -22,6 +22,9 @@ describe('dismissing the alert', () => {
clickDismissButton(); clickDismissButton();
expect(Cookies.set).toHaveBeenCalledWith('hide_user_cap_alert_1', true, { expires: 30 }); expect(Cookies.set).toHaveBeenCalledWith('hide_user_cap_alert_1', true, {
expires: 30,
secure: false,
});
}); });
}); });
...@@ -189,6 +189,10 @@ describe('Project vulnerability report app component', () => { ...@@ -189,6 +189,10 @@ describe('Project vulnerability report app component', () => {
expect(Cookies.set).toHaveBeenCalledWith( expect(Cookies.set).toHaveBeenCalledWith(
wrapper.vm.$options.autoFixUserCalloutCookieName, wrapper.vm.$options.autoFixUserCalloutCookieName,
'true', 'true',
{
expires: 365,
secure: false,
},
); );
}); });
......
...@@ -189,6 +189,10 @@ describe('Vulnerability Report', () => { ...@@ -189,6 +189,10 @@ describe('Vulnerability Report', () => {
expect(Cookies.set).toHaveBeenCalledWith( expect(Cookies.set).toHaveBeenCalledWith(
wrapper.vm.$options.autoFixUserCalloutCookieName, wrapper.vm.$options.autoFixUserCalloutCookieName,
'true', 'true',
{
expires: 365,
secure: false,
},
); );
}); });
......
...@@ -27,6 +27,7 @@ module Gitlab ...@@ -27,6 +27,7 @@ module Gitlab
gon.revision = Gitlab.revision gon.revision = Gitlab.revision
gon.feature_category = Gitlab::ApplicationContext.current_context_attribute(:feature_category).presence gon.feature_category = Gitlab::ApplicationContext.current_context_attribute(:feature_category).presence
gon.gitlab_logo = ActionController::Base.helpers.asset_path('gitlab_logo.png') gon.gitlab_logo = ActionController::Base.helpers.asset_path('gitlab_logo.png')
gon.secure = Gitlab.config.gitlab.https
gon.sprite_icons = IconsHelper.sprite_icon_path gon.sprite_icons = IconsHelper.sprite_icon_path
gon.sprite_file_icons = IconsHelper.sprite_file_icons_path gon.sprite_file_icons = IconsHelper.sprite_file_icons_path
gon.emoji_sprites_css_path = ActionController::Base.helpers.stylesheet_path('emoji_sprites') gon.emoji_sprites_css_path = ActionController::Base.helpers.stylesheet_path('emoji_sprites')
......
...@@ -30,6 +30,7 @@ describe('broadcast message on dismiss', () => { ...@@ -30,6 +30,7 @@ describe('broadcast message on dismiss', () => {
expect(Cookies.set).toHaveBeenCalledWith('hide_broadcast_message_1', true, { expect(Cookies.set).toHaveBeenCalledWith('hide_broadcast_message_1', true, {
expires: new Date(endsAt), expires: new Date(endsAt),
secure: false,
}); });
}); });
}); });
...@@ -118,7 +118,7 @@ describe('When the code_quality_walkthrough URL parameter is present', () => { ...@@ -118,7 +118,7 @@ describe('When the code_quality_walkthrough URL parameter is present', () => {
expect(Cookies.set).toHaveBeenCalledWith( expect(Cookies.set).toHaveBeenCalledWith(
EXPERIMENT_NAME, EXPERIMENT_NAME,
{ commit_ci_file: true, data: dummyContext }, { commit_ci_file: true, data: dummyContext },
{ expires: 365 }, { expires: 365, secure: false },
); );
}); });
......
...@@ -254,7 +254,10 @@ describe('Design management design sidebar component', () => { ...@@ -254,7 +254,10 @@ describe('Design management design sidebar component', () => {
it(`sets a ${cookieKey} cookie on clicking outside the popover`, () => { it(`sets a ${cookieKey} cookie on clicking outside the popover`, () => {
jest.spyOn(Cookies, 'set'); jest.spyOn(Cookies, 'set');
wrapper.trigger('click'); wrapper.trigger('click');
expect(Cookies.set).toHaveBeenCalledWith(cookieKey, 'true', { expires: 365 * 10 }); expect(Cookies.set).toHaveBeenCalledWith(cookieKey, 'true', {
expires: 365 * 10,
secure: false,
});
}); });
}); });
......
...@@ -31,6 +31,7 @@ describe('addToFrequentlyUsed', () => { ...@@ -31,6 +31,7 @@ describe('addToFrequentlyUsed', () => {
expect(Cookies.set).toHaveBeenCalledWith('frequently_used_emojis', 'thumbsup', { expect(Cookies.set).toHaveBeenCalledWith('frequently_used_emojis', 'thumbsup', {
expires: 365, expires: 365,
secure: false,
}); });
}); });
...@@ -41,6 +42,7 @@ describe('addToFrequentlyUsed', () => { ...@@ -41,6 +42,7 @@ describe('addToFrequentlyUsed', () => {
expect(Cookies.set).toHaveBeenCalledWith('frequently_used_emojis', 'thumbsdown,thumbsup', { expect(Cookies.set).toHaveBeenCalledWith('frequently_used_emojis', 'thumbsdown,thumbsup', {
expires: 365, expires: 365,
secure: false,
}); });
}); });
...@@ -51,6 +53,7 @@ describe('addToFrequentlyUsed', () => { ...@@ -51,6 +53,7 @@ describe('addToFrequentlyUsed', () => {
expect(Cookies.set).toHaveBeenCalledWith('frequently_used_emojis', 'thumbsup', { expect(Cookies.set).toHaveBeenCalledWith('frequently_used_emojis', 'thumbsup', {
expires: 365, expires: 365,
secure: false,
}); });
}); });
}); });
...@@ -159,7 +159,10 @@ describe('Landing', () => { ...@@ -159,7 +159,10 @@ describe('Landing', () => {
}); });
it('should call Cookies.set', () => { it('should call Cookies.set', () => {
expect(Cookies.set).toHaveBeenCalledWith(test.cookieName, 'true', { expires: 365 }); expect(Cookies.set).toHaveBeenCalledWith(test.cookieName, 'true', {
expires: 365,
secure: false,
});
}); });
}); });
......
...@@ -207,7 +207,10 @@ describe('merge conflicts actions', () => { ...@@ -207,7 +207,10 @@ describe('merge conflicts actions', () => {
], ],
[], [],
() => { () => {
expect(Cookies.set).toHaveBeenCalledWith('diff_view', payload); expect(Cookies.set).toHaveBeenCalledWith('diff_view', payload, {
expires: 365,
secure: false,
});
done(); done();
}, },
); );
......
...@@ -84,6 +84,7 @@ describe('Pipeline Schedule Callout', () => { ...@@ -84,6 +84,7 @@ describe('Pipeline Schedule Callout', () => {
expect(setCookiesSpy).toHaveBeenCalledWith('pipeline_schedules_callout_dismissed', true, { expect(setCookiesSpy).toHaveBeenCalledWith('pipeline_schedules_callout_dismissed', true, {
expires: 365, expires: 365,
secure: false,
}); });
}); });
}); });
......
...@@ -37,7 +37,10 @@ describe('Knative survey banner', () => { ...@@ -37,7 +37,10 @@ describe('Knative survey banner', () => {
wrapper.find(GlBanner).vm.$emit('close'); wrapper.find(GlBanner).vm.$emit('close');
await nextTick(); await nextTick();
expect(Cookies.set).toHaveBeenCalledWith('hide_serverless_survey', 'true', { expires: 3650 }); expect(Cookies.set).toHaveBeenCalledWith('hide_serverless_survey', 'true', {
expires: 3650,
secure: false,
});
expect(wrapper.find(GlBanner).exists()).toBe(false); expect(wrapper.find(GlBanner).exists()).toBe(false);
}); });
......
...@@ -70,7 +70,10 @@ describe('IssuableSidebarRoot', () => { ...@@ -70,7 +70,10 @@ describe('IssuableSidebarRoot', () => {
it('updates "collapsed_gutter" cookie value and layout classes', async () => { it('updates "collapsed_gutter" cookie value and layout classes', async () => {
await findToggleSidebarButton().trigger('click'); await findToggleSidebarButton().trigger('click');
expect(Cookies.set).toHaveBeenCalledWith(USER_COLLAPSED_GUTTER_COOKIE, true); expect(Cookies.set).toHaveBeenCalledWith(USER_COLLAPSED_GUTTER_COOKIE, true, {
expires: 365,
secure: false,
});
assertPageLayoutClasses({ isExpanded: false }); assertPageLayoutClasses({ isExpanded: false });
}); });
}); });
......
...@@ -6,9 +6,41 @@ RSpec.describe Gitlab::GonHelper do ...@@ -6,9 +6,41 @@ RSpec.describe Gitlab::GonHelper do
let(:helper) do let(:helper) do
Class.new do Class.new do
include Gitlab::GonHelper include Gitlab::GonHelper
def current_user
nil
end
end.new end.new
end end
describe '#add_gon_variables' do
let(:gon) { double('gon').as_null_object }
let(:https) { true }
before do
allow(helper).to receive(:gon).and_return(gon)
stub_config_setting(https: https)
end
context 'when HTTPS is enabled' do
it 'sets the secure flag to true' do
expect(gon).to receive(:secure=).with(true)
helper.add_gon_variables
end
end
context 'when HTTP is enabled' do
let(:https) { false }
it 'sets the secure flag to false' do
expect(gon).to receive(:secure=).with(false)
helper.add_gon_variables
end
end
end
describe '#push_frontend_feature_flag' do describe '#push_frontend_feature_flag' do
before do before do
skip_feature_flags_yaml_validation skip_feature_flags_yaml_validation
......
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