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 Show latest version
5 files
+ 39
39
Compare changes
  • Side-by-side
  • Inline
Files
5
@@ -9,7 +9,7 @@ class TrialsController < ApplicationController
@@ -9,7 +9,7 @@ class TrialsController < ApplicationController
before_action :authenticate_user!
before_action :authenticate_user!
before_action :find_or_create_namespace, only: :apply
before_action :find_or_create_namespace, only: :apply
before_action :find_namespace, only: [:extend_reactivate]
before_action :find_namespace, only: [:extend_reactivate]
before_action :authenticate_owner!, only: [:extend_reactivate]
before_action :authenticate_namespace_owner!, only: [:extend_reactivate]
feature_category :purchase
feature_category :purchase
@@ -52,17 +52,7 @@ def apply
@@ -52,17 +52,7 @@ def apply
end
end
def extend_reactivate
def extend_reactivate
trial_extension_type = params[:trial_extension_type].to_i
@result = GitlabSubscriptions::ExtendReactivateTrialService.new.execute(extend_reactivate_trial_params) if valid_extension?
return render_403 unless [GitlabSubscription::TRIAL_EXTENDED, GitlabSubscription::TRIAL_REACTIVATED].include?(trial_extension_type)
return render_403 if trial_extension_type == GitlabSubscription::TRIAL_EXTENDED && !@namespace.can_extend?
return render_403 if trial_extension_type == GitlabSubscription::TRIAL_REACTIVATED && !@namespace.can_reactivate?
return render_403 if @namespace.invalid?
@result = GitlabSubscriptions::ExtendReactivateTrialService.new.execute(extend_reactivate_trial_params)
if @result&.dig(:success)
if @result&.dig(:success)
head 200
head 200
@@ -86,7 +76,7 @@ def authenticate_user!
@@ -86,7 +76,7 @@ def authenticate_user!
redirect_to new_trial_registration_path, alert: I18n.t('devise.failure.unauthenticated')
redirect_to new_trial_registration_path, alert: I18n.t('devise.failure.unauthenticated')
end
end
def authenticate_owner!
def authenticate_namespace_owner!
render_403 unless @namespace.owners.include?(current_user)
render_403 unless @namespace.owners.include?(current_user)
end
end
@@ -147,6 +137,18 @@ def find_namespace?
@@ -147,6 +137,18 @@ def find_namespace?
params[:namespace_id].present? && params[:namespace_id] != '0'
params[:namespace_id].present? && params[:namespace_id] != '0'
end
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?
def can_create_group?
params[:new_group_name].present? && can?(current_user, :create_group)
params[:new_group_name].present? && can?(current_user, :create_group)
end
end
Loading