Welcome to mirror list, hosted at ThFree Co, Russian Federation.

jira_auth_fields.vue « components « edit « integrations « javascripts « assets « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 30a39e48959812a2a399b3d709b1e660477b62bb (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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
<script>
import { mapGetters } from 'vuex';
import { isEmpty } from 'lodash';
import { GlFormGroup, GlFormRadio, GlFormRadioGroup } from '@gitlab/ui';
import { __, s__ } from '~/locale';

import { jiraIntegrationAuthFields, jiraAuthTypeFieldProps } from '~/integrations/constants';
import DynamicField from './dynamic_field.vue';

const authTypeOptions = [
  {
    value: 0,
    text: s__('JiraService|Basic'),
  },
  {
    value: 1,
    text: s__('JiraService|Jira personal access token'),
    help: s__('JiraService|Recommended. Only available for Jira Data Center and Jira Server.'),
  },
];

export default {
  name: 'JiraAuthFields',

  components: {
    GlFormGroup,
    GlFormRadio,
    GlFormRadioGroup,
    DynamicField,
  },

  props: {
    isValidated: {
      type: Boolean,
      required: false,
      default: false,
    },

    fields: {
      type: Array,
      required: false,
      default: () => [],
    },
  },

  data() {
    return {
      authType: 0,
    };
  },

  computed: {
    ...mapGetters(['currentKey', 'isInheriting']),

    isAuthTypeBasic() {
      return this.authType === 0;
    },

    isNonEmptyPassword() {
      return !isEmpty(this.passwordField?.value);
    },

    authTypeProps() {
      return jiraAuthTypeFieldProps[this.authType];
    },

    authTypeField() {
      return this.findFieldByName(jiraIntegrationAuthFields.AUTH_TYPE);
    },

    usernameField() {
      return this.findFieldByName(jiraIntegrationAuthFields.USERNAME);
    },

    passwordField() {
      return this.findFieldByName(jiraIntegrationAuthFields.PASSWORD);
    },

    usernameProps() {
      return {
        ...this.usernameField,
        ...(this.isAuthTypeBasic ? { required: true } : {}),
        title: this.authTypeProps.username,
      };
    },

    passwordProps() {
      const extraProps = this.isNonEmptyPassword
        ? { title: this.authTypeProps.nonEmptyPassword }
        : { title: this.authTypeProps.password, help: this.authTypeProps.passwordHelp };

      return {
        ...this.passwordField,
        ...extraProps,
      };
    },
  },

  mounted() {
    const authTypeValue = this.authTypeField?.value;
    if (authTypeValue) {
      this.authType = parseInt(authTypeValue, 10);
    }
  },

  methods: {
    findFieldByName(name) {
      return this.fields.find((field) => field.name === name);
    },
  },

  authTypeOptions,

  i18n: {
    authTypeLabel: __('Authentication method'),
  },
};
</script>

<template>
  <gl-form-group :label="$options.i18n.authTypeLabel" label-for="service[jira_auth_type]">
    <input name="service[jira_auth_type]" type="hidden" :value="authType" />
    <gl-form-radio-group v-model="authType" :disabled="isInheriting">
      <gl-form-radio
        v-for="option in $options.authTypeOptions"
        :key="option.value"
        :value="option.value"
      >
        <template v-if="option.help" #help>
          {{ option.help }}
        </template>
        {{ option.text }}
      </gl-form-radio>
    </gl-form-radio-group>

    <div class="gl-ml-6 gl-mt-3">
      <dynamic-field
        v-if="isAuthTypeBasic"
        :key="`${currentKey}-${usernameProps.name}`"
        data-testid="jira-auth-username"
        v-bind="usernameProps"
        :is-validated="isValidated"
      />
      <dynamic-field
        :key="`${currentKey}-${passwordProps.name}`"
        data-testid="jira-auth-password"
        v-bind="passwordProps"
        :is-validated="isValidated"
      />
    </div>
  </gl-form-group>
</template>