Skip to content

Commit

Permalink
Add organization id to unique_id (#10)
Browse files Browse the repository at this point in the history
- Add in CHANGELOG an advise
  • Loading branch information
laurajaime committed Mar 7, 2023
1 parent 1941122 commit c712e89
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.MD
@@ -1,5 +1,9 @@
# CHANGELOG

## v0.27.1.1
- Add organization id to generate unique_id because there are conflicts when there is a multitenant.
❗ Be careful, this change this fix will make all verifications in production no longer valid because the `unique_id` will be generated differently ❗

## v0.27.1.0
- Upgrade to use Ruby 3.1.3, but be compatible with > 3.0
- Upgrade to Decidim v0.27.1
Expand Down
2 changes: 1 addition & 1 deletion Gemfile.lock
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
decidim-file_authorization_handler (0.27.1.0)
decidim-file_authorization_handler (0.27.1.1)
decidim (~> 0.27.1)
decidim-admin (~> 0.27.1)
rails (>= 5.2)
Expand Down
2 changes: 1 addition & 1 deletion app/services/file_authorization_handler.rb
Expand Up @@ -41,7 +41,7 @@ def authorized?
end

def unique_id
census_for_user&.id_document
Digest::SHA256.hexdigest("#{census_for_user&.id_document}-#{organization.id}-#{Rails.application.secrets.secret_key_base}")
end

def census_for_user
Expand Down
2 changes: 1 addition & 1 deletion lib/decidim/file_authorization_handler/version.rb
Expand Up @@ -7,6 +7,6 @@ module FileAuthorizationHandler
# Uses the latest matching Decidim version for
# - major, minor and patch
# - the optional extra number is related to this module's patches
VERSION = "#{DECIDIM_VERSION}.0".freeze
VERSION = "#{DECIDIM_VERSION}.1".freeze
end
end
Expand Up @@ -11,6 +11,9 @@
described_class.new(user:, id_document: dni, birthdate: date)
.with_context(current_organization: organization)
end
let!(:unique_id) do
Digest::SHA256.hexdigest("#{handler.census_for_user&.id_document}-#{organization.id}-#{Rails.application.secrets.secret_key_base}")
end

let(:census_datum) do
create(:census_datum, id_document: encoded_dni,
Expand Down Expand Up @@ -38,6 +41,10 @@
expect(handler.metadata).to eq(birthdate: "1990/11/21")
end

it "generates unique_id correctly" do
expect(unique_id).to eq(handler.unique_id)
end

it "works when no current_organization context is provided (but the user is)" do
census_datum
contextless_handler = described_class.new(user:,
Expand Down

0 comments on commit c712e89

Please sign in to comment.