Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

Fix pasting of a token and handle simultaneous changes by multiple admins

Inga Maiffdf711d15f0
diff --git a/app/controllers/enterprises_controller.rb b/app/controllers/enterprises_controller.rb
index e203e3bf58f..b3cf4920aa2 100644
--- a/app/controllers/enterprises_controller.rb
+++ b/app/controllers/enterprises_controller.rb
@@ -43,15 +43,26 @@ class EnterprisesController < ApplicationController
@current_token = EnterpriseToken.current
@token = @current_token || EnterpriseToken.new
- if @current_token.blank?
+ if !@current_token.present?
initialize_gon
end
end
def create
@token = EnterpriseToken.current || EnterpriseToken.new
+ saved_encoded_token = @token.encoded_token
@token.encoded_token = params[:enterprise_token][:encoded_token]
- @token.save
+ if @token.save
+ flash[:notice] = t(:notice_successful_update)
+ redirect_to action: :show
+ else
+ # restore the old token
+ if saved_encoded_token
+ @token.encoded_token = saved_encoded_token
+ @current_token = @token || EnterpriseToken.new
+ end
+ render action: :show
+ end
end
def destroy
@@ -59,8 +70,10 @@ class EnterprisesController < ApplicationController
if token
token.destroy
flash[:notice] = t(:notice_successful_delete)
- trial_key = Token::EnterpriseTrialKey.find_by(user_id: current_user.id)
+
+ trial_key = Token::EnterpriseTrialKey.find_by(user_id: User.system.id)
trial_key.destroy
+
redirect_to action: :show
else
render_404
@@ -68,12 +81,11 @@ class EnterprisesController < ApplicationController
end
def save_trial_key
- @trial_key = params[:trial_key]
- Token::EnterpriseTrialKey.create(user_id: current_user.id, value: @trial_key)
+ Token::EnterpriseTrialKey.create(user_id: User.system.id, value: params[:trial_key])
end
def initialize_gon
- @trial_key = Token::EnterpriseTrialKey.find_by(user_id: current_user.id)
+ @trial_key = Token::EnterpriseTrialKey.find_by(user_id: User.system.id)
if @trial_key
gon.ee_trial_key = {
value: @trial_key.value
diff --git a/frontend/src/app/components/enterprise/enterprise-trial.service.ts b/frontend/src/app/components/enterprise/enterprise-trial.service.ts
index 55318b250fb..cce9cd244e8 100644
--- a/frontend/src/app/components/enterprise/enterprise-trial.service.ts
+++ b/frontend/src/app/components/enterprise/enterprise-trial.service.ts
@@ -133,7 +133,7 @@ export class EnterpriseTrialService {
)
.toPromise()
.catch((error:HttpErrorResponse) => {
- this.notificationsService.addError(error.error || I18n.t('js.error.internal'));
+ this.notificationsService.addError(error.error.description || I18n.t('js.error.internal'));
});
}