Skip to content

Commit

Permalink
Merge pull request #11 from Platoniq/update-password-and-oauth
Browse files Browse the repository at this point in the history
Update password disabled with Oauth enabled
  • Loading branch information
fblupi authored Jun 15, 2023
2 parents d02c44c + 7b26daf commit a3a3b66
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 0 deletions.
18 changes: 18 additions & 0 deletions app/models/concerns/decidim/user_override.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# frozen_string_literal: true

module Decidim
module UserOverride
extend ActiveSupport::Concern

included do
def needs_password_update?
return false if organization.users_registration_mode == "disabled"
return false unless admin?
return false unless Decidim.config.admin_password_strong
return true if password_updated_at.blank?

password_updated_at < Decidim.config.admin_password_expiration_days.days.ago
end
end
end
end
5 changes: 5 additions & 0 deletions config/initializers/decidim_overrides.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# frozen_string_literal: true

Rails.application.config.to_prepare do
Decidim::User.include(Decidim::UserOverride)
end
35 changes: 35 additions & 0 deletions spec/lib/overrides_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# frozen_string_literal: true

require "rails_helper"

# We make sure that the checksum of the file overriden is the same
# as the expected. If this test fails, it means that the overriden
# file should be updated to match any change/bug fix introduced in the core
checksums = [
{
package: "decidim-core",
files: {
"/app/models/decidim/user.rb" => "2b0e4abef9f8ac3bc3b7bba735420cee"
}
}
]

describe "Overriden files", type: :view do
# rubocop:disable Rails/DynamicFindBy
checksums.each do |item|
spec = ::Gem::Specification.find_by_name(item[:package])

item[:files].each do |file, signature|
it "#{spec.gem_dir}#{file} matches checksum" do
expect(md5("#{spec.gem_dir}#{file}")).to eq(signature)
end
end
end
# rubocop:enable Rails/DynamicFindBy

private

def md5(file)
Digest::MD5.hexdigest(File.read(file))
end
end

0 comments on commit a3a3b66

Please sign in to comment.