Add feature flag for making organization a required argument
What does this MR do and why?
As part of #443494 (closed), we are adding support for passing in an Organization when creating a Personal Namespace. We will require an Organization to be present on newly created Namespaces.
In a serie of MR's, we modified all the code paths that are using User.assign_personal_namespace
method and we ensured an Organization is now passed to the method. We are now ready to make Organization a required argument. In order to reduce risk, changing to required argument will be behind a derisk
Feature Flag.
This allows us to quickly make organization
an optional argument, in case we missed some code path.
This MR adds a feature flag personal_namespace_require_org
:
- If enabled,
User.assign_personal_namespace
requires an Organization argument - If disabled,
User.assign_personal_namespace
, the argument is optional
Behavior when the flag is enabled:
# Allowed
User.new.assign_personal_namespace(Organizations::Organization.find(1)) # Pass organization
User.new.assign_personal_namespace(nil) # Required argument but it is still ok to be `nil`
# Not allowed: Argument error
User.new.assign_personal_namespace
Behavior when the flag is disabled:
# Allowed
User.new.assign_personal_namespace(Organizations::Organization.find(1)) # Pass organization
User.new.assign_personal_namespace(nil)
User.new.assign_personal_namespace
MR acceptance checklist
Please evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.
How to set up and validate locally
Using rails console:
[1] pry(main)> Feature.enabled? :personal_namespace_require_org
=> false
[2] pry(main)> User.new.assign_personal_namespace # No error, returns new (unsaved) Namespace
=> #<Namespaces::UserNamespace id: @>
[3] pry(main)> Feature.enable :personal_namespace_require_org
=> true
[4] User.new.assign_personal_namespace
ArgumentError: Organzation is missing
from /path/app/models/user.rb:1688:in `assign_personal_namespace'