diff --git a/CHANGELOG.md b/CHANGELOG.md index 29f44a7ee..a3967568f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ - Faraday was downgraded from 1.0 to 0.17 for better compatibility with elasticsearch-ruby 5 (#205 #196) - Added [an option](doc/environment.md#ALLOW_INSECURE_HTTP) to allow usage in production without HTTPS - Now using node.js instead of therubyracer for building javascript assets +- Removed dependency to has_secure_token to fix warnings about already initialized constant - Fix a bug: when an admin logs on the subscription page, his view is broken - Fix a bug: admin's members list shows the same members multiple times - Fix a bug: when a new account is created through the sign-up modal, the role is not reported in the StatisticProfile (#196) diff --git a/Gemfile b/Gemfile index 3eb93aaca..6c091f384 100644 --- a/Gemfile +++ b/Gemfile @@ -132,7 +132,6 @@ gem 'openlab_ruby' gem 'api-pagination' gem 'apipie-rails' -gem 'has_secure_token' # XLS files generation gem 'caxlsx' diff --git a/Gemfile.lock b/Gemfile.lock index 486eaf098..f6cbe0f62 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -179,8 +179,6 @@ GEM raabro (~> 1.1) globalid (0.4.2) activesupport (>= 4.2.0) - has_secure_token (1.0.0) - activerecord (>= 3.0) hashdiff (1.0.1) hashery (2.1.2) hashie (4.1.0) @@ -484,7 +482,6 @@ DEPENDENCIES foreman forgery friendly_id (~> 5.1.0) - has_secure_token icalendar jbuilder (~> 2.5) jbuilder_cache_multi diff --git a/app/models/open_api/client.rb b/app/models/open_api/client.rb index 2dc2bf231..a9815eaf7 100644 --- a/app/models/open_api/client.rb +++ b/app/models/open_api/client.rb @@ -1,9 +1,29 @@ +# frozen_string_literal: true + +# OpenAPI::Client keeps track of the authorized accesses to the 3-rd party API (aka. OpenAPI) class OpenAPI::Client < ApplicationRecord has_many :calls_count_tracings, foreign_key: :open_api_client_id, dependent: :destroy - has_secure_token + validates :name, presence: true + validates_uniqueness_of :token + + before_create :set_initial_token def increment_calls_count update_column(:calls_count, calls_count+1) end + + def regenerate_token + update_attributes(token: generate_unique_secure_token) + end + + private + + def set_initial_token + self.token = generate_unique_secure_token + end + + def generate_unique_secure_token + SecureRandom.base58(24) + end end