Skip to content
Snippets Groups Projects

BE: Allow customers to extend or reactivate their trial on gitlab.com [RUN ALL RSPEC] [RUN AS-IF-FOSS]

Merged Qingyu Zhao requested to merge 290278-allow-extend-or-reactivate-trial-on-gitlab-com into master
All threads resolved!
Compare and
15 files
+ 361
5
Compare changes
  • Side-by-side
  • Inline
Files
15
@@ -8,6 +8,8 @@ class TrialsController < ApplicationController
before_action :check_if_gl_com_or_dev
before_action :authenticate_user!
before_action :find_or_create_namespace, only: :apply
before_action :find_namespace, only: [:extend_reactivate]
before_action :authenticate_namespace_owner!, only: [:extend_reactivate]
feature_category :purchase
@@ -49,6 +51,18 @@ def apply
end
end
def extend_reactivate
render_404 unless Feature.enabled?(:allow_extend_reactivate_trial)
@result = GitlabSubscriptions::ExtendReactivateTrialService.new.execute(extend_reactivate_trial_params) if valid_extension?
if @result&.dig(:success)
head 200
else
render_403
end
end
protected
# override the ConfirmEmailWarning method in order to skip
@@ -64,6 +78,16 @@ def authenticate_user!
redirect_to new_trial_registration_path, alert: I18n.t('devise.failure.unauthenticated')
end
def authenticate_namespace_owner!
user_is_namespace_owner = if @namespace.is_a?(Group)
@namespace.owners.include?(current_user)
else
@namespace.owner == current_user
end
render_403 unless user_is_namespace_owner
end
def company_params
params.permit(:company_name, :company_size, :first_name, :last_name, :phone_number, :number_of_users, :country)
.merge(extra_params)
@@ -90,6 +114,15 @@ def apply_trial_params
}
end
def extend_reactivate_trial_params
gl_com_params = { gitlab_com_trial: true, sync_to_gl: true }
{
trial_user: params.permit(:namespace_id, :trial_extension_type, :trial_entity, :glm_source, :glm_content).merge(gl_com_params),
uid: current_user.id
}
end
def find_or_create_namespace
@namespace = if find_namespace?
current_user.namespaces.find_by_id(params[:namespace_id])
@@ -100,10 +133,30 @@ def find_or_create_namespace
render_404 unless @namespace
end
def find_namespace
@namespace = if find_namespace?
current_user.namespaces.find_by_id(params[:namespace_id])
end
render_404 unless @namespace
end
def find_namespace?
params[:namespace_id].present? && params[:namespace_id] != '0'
end
def valid_extension?
trial_extension_type = params[:trial_extension_type].to_i
return false unless [GitlabSubscription::TRIAL_EXTENDED, GitlabSubscription::TRIAL_REACTIVATED].include?(trial_extension_type)
return false if trial_extension_type == GitlabSubscription::TRIAL_EXTENDED && !@namespace.can_extend?
return false if trial_extension_type == GitlabSubscription::TRIAL_REACTIVATED && !@namespace.can_reactivate?
true
end
def can_create_group?
params[:new_group_name].present? && can?(current_user, :create_group)
end
Loading