Add model validations
What does this MR do and why?
Add model validations
Extends existing namespace validation on AddOnPurchase model.
It now further checks if namespace is root
namespace and of kind Group
, along with presence
, when on Gitlab.com
There aren't any AddOnPurchase
records on production
yet, as the feature flag: purchase_code_suggestions
is not enabled.
- https://gitlab.com/gitlab-org/customers-gitlab-com/-/issues/6656+
- https://gitlab.com/gitlab-org/gitlab/-/issues/415047+
How to set up and validate locally
- Checkout this branch
- Start gdk as SaaS, if not already:
GITLAB_SIMULATE_SAAS=1 gdk restart
- Create a new
root group namespace
- Open console
GITLAB_SIMULATE_SAAS=1 gdk rails c
add_on = GitlabSubscriptions::AddOn.find_or_create_by!(name: "code_suggestions") {|e| e.description = "Test"}
p = GitlabSubscriptions::AddOnPurchase.new(add_on: add_on,expires_on: 1.month.from_now, quantity: 5, purchase_xid: 'A-S0001')
# check that gdk is run as SAAS
::Gitlab::CurrentSettings.should_check_namespace_plan? # true
p.valid? # => false
p.errors.details # {:namespace=>[{:error=>:invalid}]}
p.namespace = Namespaces::UserNamespace.last # there is always one UserNamespace present
p.valid? # => false
p.errors.details # {:namespace=>[{:error=>:invalid}]}
p.namespace = Namespaces::ProjectNamespace.last # create a Project locally, if not present
p.valid? # => false
p.errors.details # {:namespace=>[{:error=>:invalid}]}
p.namespace = Group.last # Root Group Namespace created in step 2 above
p.valid? # => true
p.errors.details # {}
MR acceptance checklist
This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.
-
I have evaluated the MR acceptance checklist for this MR.
Related to #424085
Edited by Bishwa Hang Rai