summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/security_configuration/resolver.js
blob: 93175d4a3d1e5031efa13e510a03bd41a338ae1c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import produce from 'immer';
import { __ } from '~/locale';
import securityTrainingProvidersQuery from './graphql/security_training_providers.query.graphql';

// Note: this is behind a feature flag and only a placeholder
// until the actual GraphQL fields have been added
// https://gitlab.com/gitlab-org/gi tlab/-/issues/346480
export default {
  Query: {
    securityTrainingProviders() {
      return [
        {
          __typename: 'SecurityTrainingProvider',
          id: 101,
          name: __('Kontra'),
          description: __('Interactive developer security education.'),
          url: 'https://application.security/',
          isEnabled: false,
        },
        {
          __typename: 'SecurityTrainingProvider',
          id: 102,
          name: __('SecureCodeWarrior'),
          description: __('Security training with guide and learning pathways.'),
          url: 'https://www.securecodewarrior.com/',
          isEnabled: true,
        },
      ];
    },
  },

  Mutation: {
    configureSecurityTrainingProviders: (
      _,
      { input: { enabledProviders, primaryProvider } },
      { cache },
    ) => {
      const sourceData = cache.readQuery({
        query: securityTrainingProvidersQuery,
      });

      const data = produce(sourceData.securityTrainingProviders, (draftData) => {
        /* eslint-disable no-param-reassign */
        draftData.forEach((provider) => {
          provider.isPrimary = provider.id === primaryProvider;
          provider.isEnabled =
            provider.id === primaryProvider || enabledProviders.includes(provider.id);
        });
      });
      return {
        __typename: 'configureSecurityTrainingProvidersPayload',
        securityTrainingProviders: data,
      };
    },
  },
};