Fix inability to set snippet visibility via API
Consider the scenario:
- The snippet visibility level is set to internal
- A user attempts to create a private snippet
Previously this would always fail because default_value_for
would
overwrite the private visibility setting, no matter what
visibility_level was. This was happening because default_value_for
was
confused by the default value of 0 specified by the database schema.
default_value_for
attempts to assign the default value in the block by
checking whether the attribute has changed. The problem is that since
the default value by the database was 0, and the user requested 0, this
appeared as though no changes were made. As a result,
default_value_for
would always overwrite the user's preference.
To fix this, we remove the use of default_value_for
and only set the
visibility level to the default application setting when no preference
has been given at creation time.
This is similar to the fix in gitlab-foss!29578 (merged).
Closes #34016 (closed).