summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/pages/projects/shared/permissions/components/settings_panel.vue
blob: a16f7e6b77c4071e9f96df6c531d514adf8c5c67 (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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
<script>
  import projectFeatureSetting from './project_feature_setting.vue';
  import projectFeatureToggle from '../../../../../vue_shared/components/toggle_button.vue';
  import projectSettingRow from './project_setting_row.vue';
  import { visibilityOptions, visibilityLevelDescriptions } from '../constants';
  import { toggleHiddenClassBySelector } from '../external';

  export default {
    components: {
      projectFeatureSetting,
      projectFeatureToggle,
      projectSettingRow,
    },

    props: {
      currentSettings: {
        type: Object,
        required: true,
      },
      canChangeVisibilityLevel: {
        type: Boolean,
        required: false,
        default: false,
      },
      allowedVisibilityOptions: {
        type: Array,
        required: false,
        default: () => [0, 10, 20],
      },
      lfsAvailable: {
        type: Boolean,
        required: false,
        default: false,
      },
      registryAvailable: {
        type: Boolean,
        required: false,
        default: false,
      },
      visibilityHelpPath: {
        type: String,
        required: false,
        default: '',
      },
      lfsHelpPath: {
        type: String,
        required: false,
        default: '',
      },
      registryHelpPath: {
        type: String,
        required: false,
        default: '',
      },
      pagesAvailable: {
        type: Boolean,
        required: false,
        default: false,
      },
      pagesAccessControlEnabled: {
        type: Boolean,
        required: false,
        default: false,
      },
      pagesHelpPath: {
        type: String,
        required: false,
        default: '',
      },
    },

    data() {
      const defaults = {
        visibilityOptions,
        visibilityLevel: visibilityOptions.PUBLIC,
        issuesAccessLevel: 20,
        repositoryAccessLevel: 20,
        mergeRequestsAccessLevel: 20,
        buildsAccessLevel: 20,
        wikiAccessLevel: 20,
        snippetsAccessLevel: 20,
        pagesAccessLevel: 20,
        containerRegistryEnabled: true,
        lfsEnabled: true,
        requestAccessEnabled: true,
        highlightChangesClass: false,
      };

      return { ...defaults, ...this.currentSettings };
    },

    computed: {
      featureAccessLevelOptions() {
        const options = [
          [10, 'Only Project Members'],
        ];
        if (this.visibilityLevel !== visibilityOptions.PRIVATE) {
          options.push([20, 'Everyone With Access']);
        }
        return options;
      },

      repoFeatureAccessLevelOptions() {
        return this.featureAccessLevelOptions.filter(
          ([value]) => value <= this.repositoryAccessLevel,
        );
      },

      pagesFeatureAccessLevelOptions() {
        if (this.visibilityLevel !== visibilityOptions.PUBLIC) {
          return this.featureAccessLevelOptions.concat([[30, 'Everyone']]);
        }
        return this.featureAccessLevelOptions;
      },

      repositoryEnabled() {
        return this.repositoryAccessLevel > 0;
      },

      visibilityLevelDescription() {
        return visibilityLevelDescriptions[this.visibilityLevel];
      },
    },

    watch: {
      visibilityLevel(value, oldValue) {
        if (value === visibilityOptions.PRIVATE) {
          // when private, features are restricted to "only team members"
          this.issuesAccessLevel = Math.min(10, this.issuesAccessLevel);
          this.repositoryAccessLevel = Math.min(10, this.repositoryAccessLevel);
          this.mergeRequestsAccessLevel = Math.min(10, this.mergeRequestsAccessLevel);
          this.buildsAccessLevel = Math.min(10, this.buildsAccessLevel);
          this.wikiAccessLevel = Math.min(10, this.wikiAccessLevel);
          this.snippetsAccessLevel = Math.min(10, this.snippetsAccessLevel);
          if (this.pagesAccessLevel === 20) {
            // When from Internal->Private narrow access for only members
            this.pagesAccessLevel = 10;
          }
          this.highlightChanges();
        } else if (oldValue === visibilityOptions.PRIVATE) {
          // if changing away from private, make enabled features more permissive
          if (this.issuesAccessLevel > 0) this.issuesAccessLevel = 20;
          if (this.repositoryAccessLevel > 0) this.repositoryAccessLevel = 20;
          if (this.mergeRequestsAccessLevel > 0) this.mergeRequestsAccessLevel = 20;
          if (this.buildsAccessLevel > 0) this.buildsAccessLevel = 20;
          if (this.wikiAccessLevel > 0) this.wikiAccessLevel = 20;
          if (this.snippetsAccessLevel > 0) this.snippetsAccessLevel = 20;
          if (this.pagesAccessLevel === 10) this.pagesAccessLevel = 20;
          this.highlightChanges();
        }
      },

      repositoryAccessLevel(value, oldValue) {
        if (value < oldValue) {
          // sub-features cannot have more premissive access level
          this.mergeRequestsAccessLevel = Math.min(this.mergeRequestsAccessLevel, value);
          this.buildsAccessLevel = Math.min(this.buildsAccessLevel, value);

          if (value === 0) {
            this.containerRegistryEnabled = false;
            this.lfsEnabled = false;
          }
        } else if (oldValue === 0) {
          this.mergeRequestsAccessLevel = value;
          this.buildsAccessLevel = value;
          this.containerRegistryEnabled = true;
          this.lfsEnabled = true;
        }
      },

      issuesAccessLevel(value, oldValue) {
        if (value === 0) toggleHiddenClassBySelector('.issues-feature', true);
        else if (oldValue === 0) toggleHiddenClassBySelector('.issues-feature', false);
      },

      mergeRequestsAccessLevel(value, oldValue) {
        if (value === 0) toggleHiddenClassBySelector('.merge-requests-feature', true);
        else if (oldValue === 0) toggleHiddenClassBySelector('.merge-requests-feature', false);
      },

      buildsAccessLevel(value, oldValue) {
        if (value === 0) toggleHiddenClassBySelector('.builds-feature', true);
        else if (oldValue === 0) toggleHiddenClassBySelector('.builds-feature', false);
      },
    },

    methods: {
      highlightChanges() {
        this.highlightChangesClass = true;
        this.$nextTick(() => {
          this.highlightChangesClass = false;
        });
      },

      visibilityAllowed(option) {
        return this.allowedVisibilityOptions.includes(option);
      },
    },
  };
</script>

<template>
  <div>
    <div class="project-visibility-setting">
      <project-setting-row
        :help-path="visibilityHelpPath"
        label="Project visibility"
      >
        <div class="project-feature-controls">
          <div class="select-wrapper">
            <select
              v-model="visibilityLevel"
              :disabled="!canChangeVisibilityLevel"
              name="project[visibility_level]"
              class="form-control select-control"
            >
              <option
                :value="visibilityOptions.PRIVATE"
                :disabled="!visibilityAllowed(visibilityOptions.PRIVATE)"
              >
                Private
              </option>
              <option
                :value="visibilityOptions.INTERNAL"
                :disabled="!visibilityAllowed(visibilityOptions.INTERNAL)"
              >
                Internal
              </option>
              <option
                :value="visibilityOptions.PUBLIC"
                :disabled="!visibilityAllowed(visibilityOptions.PUBLIC)"
              >
                Public
              </option>
            </select>
            <i
              aria-hidden="true"
              data-hidden="true"
              class="fa fa-chevron-down"
            >
            </i>
          </div>
        </div>
        <span class="form-text text-muted">{{ visibilityLevelDescription }}</span>
        <label
          v-if="visibilityLevel !== visibilityOptions.PRIVATE"
          class="request-access"
        >
          <input
            :value="requestAccessEnabled"
            type="hidden"
            name="project[request_access_enabled]"
          />
          <input
            v-model="requestAccessEnabled"
            type="checkbox"
          />
          Allow users to request access
        </label>
      </project-setting-row>
    </div>
    <div
      :class="{ 'highlight-changes': highlightChangesClass }"
      class="project-feature-settings"
    >
      <project-setting-row
        label="Issues"
        help-text="Lightweight issue tracking system for this project"
      >
        <project-feature-setting
          v-model="issuesAccessLevel"
          :options="featureAccessLevelOptions"
          name="project[project_feature_attributes][issues_access_level]"
        />
      </project-setting-row>
      <project-setting-row
        label="Repository"
        help-text="View and edit files in this project"
      >
        <project-feature-setting
          v-model="repositoryAccessLevel"
          :options="featureAccessLevelOptions"
          name="project[project_feature_attributes][repository_access_level]"
        />
      </project-setting-row>
      <div class="project-feature-setting-group">
        <project-setting-row
          label="Merge requests"
          help-text="Submit changes to be merged upstream"
        >
          <project-feature-setting
            v-model="mergeRequestsAccessLevel"
            :options="repoFeatureAccessLevelOptions"
            :disabled-input="!repositoryEnabled"
            name="project[project_feature_attributes][merge_requests_access_level]"
          />
        </project-setting-row>
        <project-setting-row
          label="Pipelines"
          help-text="Build, test, and deploy your changes"
        >
          <project-feature-setting
            v-model="buildsAccessLevel"
            :options="repoFeatureAccessLevelOptions"
            :disabled-input="!repositoryEnabled"
            name="project[project_feature_attributes][builds_access_level]"
          />
        </project-setting-row>
        <project-setting-row
          v-if="registryAvailable"
          :help-path="registryHelpPath"
          label="Container registry"
          help-text="Every project can have its own space to store its Docker images"
        >
          <project-feature-toggle
            v-model="containerRegistryEnabled"
            :disabled-input="!repositoryEnabled"
            name="project[container_registry_enabled]"
          />
        </project-setting-row>
        <project-setting-row
          v-if="lfsAvailable"
          :help-path="lfsHelpPath"
          label="Git Large File Storage"
          help-text="Manages large files such as audio, video, and graphics files"
        >
          <project-feature-toggle
            v-model="lfsEnabled"
            :disabled-input="!repositoryEnabled"
            name="project[lfs_enabled]"
          />
        </project-setting-row>
      </div>
      <project-setting-row
        label="Wiki"
        help-text="Pages for project documentation"
      >
        <project-feature-setting
          v-model="wikiAccessLevel"
          :options="featureAccessLevelOptions"
          name="project[project_feature_attributes][wiki_access_level]"
        />
      </project-setting-row>
      <project-setting-row
        label="Snippets"
        help-text="Share code pastes with others out of Git repository"
      >
        <project-feature-setting
          v-model="snippetsAccessLevel"
          :options="featureAccessLevelOptions"
          name="project[project_feature_attributes][snippets_access_level]"
        />
      </project-setting-row>
      <project-setting-row
        v-if="pagesAvailable && pagesAccessControlEnabled"
        :help-path="pagesHelpPath"
        label="Pages"
        help-text="Static website for the project."
      >
        <project-feature-setting
          v-model="pagesAccessLevel"
          :options="pagesFeatureAccessLevelOptions"
          name="project[project_feature_attributes][pages_access_level]"
        />
      </project-setting-row>
    </div>
  </div>
</template>