Skip to content

Protected packages: Add enum for attr push_protected_up_to_access_level

What does this MR do and why?

  • This MR adds an enum for attribute push_protected_up_to_access_level
  • Adding this enum adds further model utilities that are helpful, make the code more readable and increases dev usability / productivity
  • Note: This change is backward compatible as existing code related to this attribute still works

🛠 with at Siemens

Screenshots or screen recordings

There are no visuals. This MR contains only backend -related changes.

How to set up and validate locally

  1. Open rails console rails c
  2. Create as a Packages::Protection::Rule as we did before
ppr = Packages::Protection::Rule.create(project: Project.find(7),
                                        package_type: :npm,
                                        # With the enum the following values would be also fine:
                                        # push_protected_up_to_access_level: :developer
                                        # push_protected_up_to_access_level: "developer"
                                        push_protected_up_to_access_level: Gitlab::Access::DEVELOPER,
                                        package_name_pattern: "@gitlab-org/npm-package-new-enum-*")
  1. With the newly defined enum, we get additional utilities for "free"
# We get these method
ppr.push_protected_up_to_developer? # => true
ppr.push_protected_up_to_maintainer? # => false

# Values of this attribute are more readable instead of the number `30` for Gitlab::Access::DEVELOPER
ppr.push_protected_up_to_access_level # => "developer"

# etc.

Todos

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Related to #419957

Edited by Gerardo Navarro

Merge request reports