Skip to content

Instantly share code, notes, and snippets.

@kopigreenx
Forked from markasoftware/enterprise_token.rb
Created October 9, 2023 06:26
Show Gist options
  • Save kopigreenx/135f5c51248bc3e1ed3e7200f110a33a to your computer and use it in GitHub Desktop.
Save kopigreenx/135f5c51248bc3e1ed3e7200f110a33a to your computer and use it in GitHub Desktop.

Revisions

  1. @markasoftware markasoftware revised this gist Aug 24, 2023. 1 changed file with 4 additions and 4 deletions.
    8 changes: 4 additions & 4 deletions enterprise_token.rb
    Original file line number Diff line number Diff line change
    @@ -45,6 +45,10 @@ def allows_to?(action)
    true
    end

    def active?
    true
    end

    def show_banners?
    false
    end
    @@ -86,10 +90,6 @@ def token_object
    def allows_to?(action)
    true
    end

    def active?
    true
    end

    def unset_current_token
    # Clear current cache
  2. @markasoftware markasoftware revised this gist Aug 23, 2023. 1 changed file with 4 additions and 0 deletions.
    4 changes: 4 additions & 0 deletions enterprise_token.rb
    Original file line number Diff line number Diff line change
    @@ -86,6 +86,10 @@ def token_object
    def allows_to?(action)
    true
    end

    def active?
    true
    end

    def unset_current_token
    # Clear current cache
  3. @markasoftware markasoftware revised this gist Mar 12, 2023. 1 changed file with 8 additions and 9 deletions.
    17 changes: 8 additions & 9 deletions enterprise_token.rb
    Original file line number Diff line number Diff line change
    @@ -2,16 +2,15 @@
    ############ also be sure to RESTART OpenProject after replacing the file. ################
    ############ it doesn't show that enterprise mode is enabled in the settings, but all ################
    ############ enterprise mode features, such as KanBan boards, are enabled. ################

    #-- copyright
    # OpenProject is an open source project management software.
    # Copyright (C) 2012-2020 the OpenProject GmbH
    # Copyright (C) 2012-2023 the OpenProject GmbH
    #
    # This program is free software; you can redistribute it and/or
    # modify it under the terms of the GNU General Public License version 3.
    #
    # OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
    # Copyright (C) 2006-2017 Jean-Philippe Lang
    # Copyright (C) 2006-2013 Jean-Philippe Lang
    # Copyright (C) 2010-2013 the ChiliProject Team
    #
    # This program is free software; you can redistribute it and/or
    @@ -28,7 +27,7 @@
    # along with this program; if not, write to the Free Software
    # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
    #
    # See docs/COPYRIGHT.rdoc for more details.
    # See COPYRIGHT and LICENSE files for more details.
    #++
    class EnterpriseToken < ApplicationRecord
    class << self
    @@ -39,7 +38,7 @@ def current
    end

    def table_exists?
    connection.data_source_exists? self.table_name
    connection.data_source_exists? table_name
    end

    def allows_to?(action)
    @@ -59,7 +58,7 @@ def set_current_token
    end
    end

    validates_presence_of :encoded_token
    validates :encoded_token, presence: true
    validate :valid_token_object
    validate :valid_domain

    @@ -107,8 +106,8 @@ def invalid_domain?

    def load_token!
    @token_object = OpenProject::Token.import(encoded_token)
    rescue OpenProject::Token::ImportError => error
    Rails.logger.error "Failed to load EE token: #{error}"
    rescue OpenProject::Token::ImportError => e
    Rails.logger.error "Failed to load EE token: #{e}"
    nil
    end

    @@ -119,4 +118,4 @@ def valid_token_object
    def valid_domain
    errors.add :domain, :invalid if invalid_domain?
    end
    end
    end
  4. @markasoftware markasoftware revised this gist Mar 3, 2022. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions enterprise_token.rb
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,5 @@
    ############ REPLACE app/models/enterprise_token.rb in the source code with this file! ################
    ############ also be sure to RESTART OpenProject after replacing the file. ################
    ############ it doesn't show that enterprise mode is enabled in the settings, but all ################
    ############ enterprise mode features, such as KanBan boards, are enabled. ################

  5. @markasoftware markasoftware revised this gist Mar 3, 2022. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions enterprise_token.rb
    Original file line number Diff line number Diff line change
    @@ -112,10 +112,10 @@ def load_token!
    end

    def valid_token_object
    # errors.add(:encoded_token, :unreadable) unless load_token!
    errors.add(:encoded_token, :unreadable) unless load_token!
    end

    def valid_domain
    # errors.add :domain, :invalid if invalid_domain?
    errors.add :domain, :invalid if invalid_domain?
    end
    end
  6. @markasoftware markasoftware revised this gist Feb 27, 2022. 1 changed file with 5 additions and 3 deletions.
    8 changes: 5 additions & 3 deletions enterprise_token.rb
    Original file line number Diff line number Diff line change
    @@ -73,6 +73,8 @@ def set_current_token
    :issued_at,
    :starts_at,
    :expires_at,
    :reprieve_days,
    :reprieve_days_left,
    :restrictions,
    to: :token_object

    @@ -90,7 +92,7 @@ def unset_current_token
    RequestStore.delete :current_ee_token
    end

    def expired?
    def expired?(reprieve: true)
    false
    end

    @@ -110,10 +112,10 @@ def load_token!
    end

    def valid_token_object
    errors.add(:encoded_token, :unreadable) unless load_token!
    # errors.add(:encoded_token, :unreadable) unless load_token!
    end

    def valid_domain
    errors.add :domain, :invalid if invalid_domain?
    # errors.add :domain, :invalid if invalid_domain?
    end
    end
  7. @markasoftware markasoftware created this gist Aug 28, 2020.
    119 changes: 119 additions & 0 deletions enterprise_token.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,119 @@
    ############ REPLACE app/models/enterprise_token.rb in the source code with this file! ################
    ############ it doesn't show that enterprise mode is enabled in the settings, but all ################
    ############ enterprise mode features, such as KanBan boards, are enabled. ################

    #-- copyright
    # OpenProject is an open source project management software.
    # Copyright (C) 2012-2020 the OpenProject GmbH
    #
    # This program is free software; you can redistribute it and/or
    # modify it under the terms of the GNU General Public License version 3.
    #
    # OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
    # Copyright (C) 2006-2017 Jean-Philippe Lang
    # Copyright (C) 2010-2013 the ChiliProject Team
    #
    # This program is free software; you can redistribute it and/or
    # modify it under the terms of the GNU General Public License
    # as published by the Free Software Foundation; either version 2
    # of the License, or (at your option) any later version.
    #
    # This program is distributed in the hope that it will be useful,
    # but WITHOUT ANY WARRANTY; without even the implied warranty of
    # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    # GNU General Public License for more details.
    #
    # You should have received a copy of the GNU General Public License
    # along with this program; if not, write to the Free Software
    # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
    #
    # See docs/COPYRIGHT.rdoc for more details.
    #++
    class EnterpriseToken < ApplicationRecord
    class << self
    def current
    RequestStore.fetch(:current_ee_token) do
    set_current_token
    end
    end

    def table_exists?
    connection.data_source_exists? self.table_name
    end

    def allows_to?(action)
    true
    end

    def show_banners?
    false
    end

    def set_current_token
    token = EnterpriseToken.order(Arel.sql('created_at DESC')).first

    if token&.token_object
    token
    end
    end
    end

    validates_presence_of :encoded_token
    validate :valid_token_object
    validate :valid_domain

    before_save :unset_current_token
    before_destroy :unset_current_token

    delegate :will_expire?,
    :subscriber,
    :mail,
    :company,
    :domain,
    :issued_at,
    :starts_at,
    :expires_at,
    :restrictions,
    to: :token_object

    def token_object
    load_token! unless defined?(@token_object)
    @token_object
    end

    def allows_to?(action)
    true
    end

    def unset_current_token
    # Clear current cache
    RequestStore.delete :current_ee_token
    end

    def expired?
    false
    end

    ##
    # The domain is only validated for tokens from version 2.0 onwards.
    def invalid_domain?
    false
    end

    private

    def load_token!
    @token_object = OpenProject::Token.import(encoded_token)
    rescue OpenProject::Token::ImportError => error
    Rails.logger.error "Failed to load EE token: #{error}"
    nil
    end

    def valid_token_object
    errors.add(:encoded_token, :unreadable) unless load_token!
    end

    def valid_domain
    errors.add :domain, :invalid if invalid_domain?
    end
    end