diff --git a/app/assets/javascripts/packages_and_registries/settings/project/components/packages_protection_rules.vue b/app/assets/javascripts/packages_and_registries/settings/project/components/packages_protection_rules.vue index 152ce8474f24659c05cce9c6c7e5b6556c25932a..b8fc8ccb65c58b9d528100ee31ab452e00a0be9a 100644 --- a/app/assets/javascripts/packages_and_registries/settings/project/components/packages_protection_rules.vue +++ b/app/assets/javascripts/packages_and_registries/settings/project/components/packages_protection_rules.vue @@ -8,21 +8,21 @@ import { GlKeysetPagination, GlModal, GlModalDirective, + GlFormSelect, } from '@gitlab/ui'; import packagesProtectionRuleQuery from '~/packages_and_registries/settings/project/graphql/queries/get_packages_protection_rules.query.graphql'; import { getPackageTypeLabel } from '~/packages_and_registries/package_registry/utils'; import deletePackagesProtectionRuleMutation from '~/packages_and_registries/settings/project/graphql/mutations/delete_packages_protection_rule.mutation.graphql'; +import updatePackagesProtectionRuleMutation from '~/packages_and_registries/settings/project/graphql/mutations/update_packages_protection_rule.mutation.graphql'; import SettingsBlock from '~/packages_and_registries/shared/components/settings_block.vue'; import PackagesProtectionRuleForm from '~/packages_and_registries/settings/project/components/packages_protection_rule_form.vue'; import { s__, __ } from '~/locale'; const PAGINATION_DEFAULT_PER_PAGE = 10; -const ACCESS_LEVEL_GRAPHQL_VALUE_TO_LABEL = { - DEVELOPER: __('Developer'), - MAINTAINER: __('Maintainer'), - OWNER: __('Owner'), -}; +const I18N_PUSH_PROTECTED_UP_TO_ACCESS_LEVEL = s__( + 'PackageRegistry|Push protected up to access level', +); export default { components: { @@ -35,6 +35,7 @@ export default { PackagesProtectionRuleForm, GlKeysetPagination, GlModal, + GlFormSelect, }, directives: { GlModal: GlModalDirective, @@ -51,6 +52,7 @@ export default { 'PackageRegistry|Users with at least the Developer role for this project will be able to publish, edit, and delete packages.', ), }, + pushProtectedUpToAccessLevel: I18N_PUSH_PROTECTED_UP_TO_ACCESS_LEVEL, }, data() { return { @@ -59,11 +61,9 @@ export default { protectionRuleFormVisibility: false, packageProtectionRulesQueryPayload: { nodes: [], pageInfo: {} }, packageProtectionRulesQueryPaginationParams: { first: PAGINATION_DEFAULT_PER_PAGE }, - deleteInProgress: false, - deleteItem: null, + protectionRuleMutationInProgress: false, + protectionRuleMutationItem: null, alertErrorMessage: '', - protectionRuleDeletionInProgress: false, - protectionRuleDeletionItem: null, }; }, computed: { @@ -71,12 +71,9 @@ export default { return this.packageProtectionRulesQueryResult.map((packagesProtectionRule) => { return { id: packagesProtectionRule.id, + pushProtectedUpToAccessLevel: packagesProtectionRule.pushProtectedUpToAccessLevel, col_1_package_name_pattern: packagesProtectionRule.packageNamePattern, col_2_package_type: getPackageTypeLabel(packagesProtectionRule.packageType), - col_3_push_protected_up_to_access_level: - ACCESS_LEVEL_GRAPHQL_VALUE_TO_LABEL[ - packagesProtectionRule.pushProtectedUpToAccessLevel - ], }; }); }, @@ -105,6 +102,13 @@ export default { text: __('Cancel'), }; }, + pushProtectedUpToAccessLevelOptions() { + return [ + { value: 'DEVELOPER', text: __('Developer') }, + { value: 'MAINTAINER', text: __('Maintainer') }, + { value: 'OWNER', text: __('Owner') }, + ]; + }, }, apollo: { packageProtectionRulesQueryPayload: { @@ -146,16 +150,13 @@ export default { last: PAGINATION_DEFAULT_PER_PAGE, }; }, - isButtonDisabled(item) { - return this.protectionRuleDeletionItem === item && this.protectionRuleDeletionInProgress; - }, showProtectionRuleDeletionConfirmModal(protectionRule) { - this.protectionRuleDeletionItem = protectionRule; + this.protectionRuleMutationItem = protectionRule; }, deleteProtectionRule(protectionRule) { this.clearAlertMessage(); - this.protectionRuleDeletionInProgress = true; + this.protectionRuleMutationInProgress = true; return this.$apollo .mutate({ @@ -175,30 +176,78 @@ export default { this.alertErrorMessage = e.message; }) .finally(() => { - this.protectionRuleDeletionItem = null; - this.protectionRuleDeletionInProgress = false; + this.resetProtectionRuleMutation(); + }); + }, + updatePackageProtectionRule(packageProtectionRule) { + this.clearAlertMessage(); + + this.protectionRuleMutationItem = packageProtectionRule; + this.protectionRuleMutationInProgress = true; + + return this.$apollo + .mutate({ + mutation: updatePackagesProtectionRuleMutation, + variables: { + input: { + id: packageProtectionRule.id, + pushProtectedUpToAccessLevel: packageProtectionRule.pushProtectedUpToAccessLevel, + }, + }, + }) + .then(({ data }) => { + const [errorMessage] = data?.updatePackagesProtectionRule?.errors ?? []; + if (errorMessage) { + this.alertErrorMessage = errorMessage; + } + + this.$toast.show(s__('PackageRegistry|Package protection rule updated.')); + }) + .catch((error) => { + this.alertErrorMessage = error.message; + }) + .finally(() => { + this.resetProtectionRuleMutation(); }); }, clearAlertMessage() { this.alertErrorMessage = ''; }, + resetProtectionRuleMutation() { + this.protectionRuleMutationItem = null; + this.protectionRuleMutationInProgress = false; + }, + isProtectionRulePushProtectedUpToAccessLevelFormSelectDisabled(item) { + return this.isProtectionRuleMutationInProgress(item); + }, + isProtectionRuleDeleteButtonDisabled(item) { + return this.isProtectionRuleMutationInProgress(item); + }, + isProtectionRuleMutationInProgress(item) { + return this.protectionRuleMutationItem === item && this.protectionRuleMutationInProgress; + }, }, - table: {}, fields: [ { key: 'col_1_package_name_pattern', label: s__('PackageRegistry|Package name pattern'), + tdClass: 'gl-w-30', + }, + { + key: 'col_2_package_type', + label: s__('PackageRegistry|Package type'), + tdClass: 'gl-w-10', }, - { key: 'col_2_package_type', label: s__('PackageRegistry|Package type') }, { key: 'col_3_push_protected_up_to_access_level', - label: s__('PackageRegistry|Push protected up to access level'), + label: I18N_PUSH_PROTECTED_UP_TO_ACCESS_LEVEL, + tdClass: 'gl-w-15', }, { key: 'col_4_actions', label: '', thClass: 'gl-display-none', - tdClass: 'gl-w-15p', + tdClass: 'gl-w-10', }, ], modal: { id: 'delete-package-protection-rule-confirmation-modal' }, @@ -262,13 +311,24 @@ export default { + +