• Stan Hu's avatar
    Fix inability to set snippet visibility via API · c2b724b5
    Stan Hu authored
    Consider the scenario:
    
    1. The snippet visibility level is set to internal
    2. 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
    https://gitlab.com/gitlab-org/gitlab-foss/merge_requests/29578.
    
    Closes https://gitlab.com/gitlab-org/gitlab/issues/34016
    c2b724b5
snippet.rb 6.62 KB