Skip to content

Commit

Permalink
Merge branch 'master' into TAN-515-remove-continous-code
Browse files Browse the repository at this point in the history
# Conflicts:
#	back/engines/commercial/multi_tenancy/app/services/multi_tenancy/rake/continuous_project_migration_service.rb
#	back/engines/commercial/multi_tenancy/lib/tasks/core/migrate_continuous_projects.rake
#	back/engines/commercial/multi_tenancy/spec/services/multi_tenancy/rake/continuous_project_migration_service_spec.rb
  • Loading branch information
jamesspeake committed Nov 13, 2023
2 parents bd2f6f2 + 3487658 commit 284a072
Show file tree
Hide file tree
Showing 159 changed files with 4,043 additions and 1,051 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -880,7 +880,7 @@ workflows:
compose_file: docker-compose-production-benelux.yml
stack_name: cl2-prd-bnlx-stack
env_file: ".env-production-benelux"
cluster_name: "prd"
cluster_name: "eu"
- back-deploy-to-swarm:
name: Deploy to Canada
requires:
Expand Down
17 changes: 17 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,23 @@ e2e-ci-env-run-test:
cd e2e && \
docker-compose run --rm --name cypress_run front npm run cypress:run -- --config baseUrl=http://e2e.front:3000 --spec ${spec}

e2e-ci-env-db-dump:
cd e2e && \
docker compose exec postgres pg_dumpall -c -U postgres > dump.sql

e2e-ci-env-db-restore:
cd e2e && \
docker compose exec postgres psql -U postgres -d cl2_back_development -c "SELECT 1" 1> /dev/null && \
docker compose exec postgres psql -U postgres -d cl2_back_development -c "DROP SCHEMA IF EXISTS e2e_front,public CASCADE" 1> /dev/null 2> /dev/null && \
docker compose exec postgres psql -U postgres -d cl2_back_development -c "CREATE SCHEMA public" && \
cat dump.sql | docker compose exec -T postgres psql --quiet -U postgres 1> /dev/null 2> /dev/null

e2e-ci-env-reproduce-flaky-test:
for i in $(shell seq 1 10); do \
make e2e-ci-env-db-restore && \
make e2e-ci-env-run-test spec="${spec}"; \
done

# =================
# CircleCI
# =================
Expand Down
15 changes: 8 additions & 7 deletions back/app/services/cl2_data_listing_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,14 @@ def cl2_schema_models
views = ActiveRecord::Base.connection.execute(
"SELECT table_name FROM information_schema.tables WHERE table_type = 'VIEW'"
).pluck('table_name')
ActiveRecord::Base.descendants.select do |claz|
[
*ActiveRecord::Base.subclasses.map(&:name),
Tenant.name
].exclude? claz.name
end.select do |claz|
views.exclude? claz.table_name
subclasses = [
*ActiveRecord::Base.subclasses.map(&:name),
Tenant.name
]
ActiveRecord::Base.descendants.reject do |claz|
subclasses.include?(claz.name) ||
views.include?(claz.table_name) ||
claz.abstract_class
end
end

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddMembershipsCountToGroups < ActiveRecord::Migration[7.0]
def change
add_column :groups, :memberships_count, :integer, null: false, default: 0, if_not_exists: true
end
end
3 changes: 2 additions & 1 deletion back/db/structure.sql
Original file line number Diff line number Diff line change
Expand Up @@ -7960,6 +7960,7 @@ INSERT INTO "schema_migrations" (version) VALUES
('20230915391649'),
('20230927135924'),
('20231003095622'),
('20231018083110');
('20231018083110'),
('20231109101517');


Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def exposed_config_parameters
def profile_to_uid(auth)
case config[:identity_source]
when DK_MIT_ID
auth['uuid']
auth['uid']
else
raise "Unsupported identity source #{config[:identity_source]}"
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,80 +7,84 @@
let(:user) { create(:user, first_name: 'Rudolphi', last_name: 'Raindeari') }
let(:token) { AuthToken::AuthToken.new(payload: user.to_token_payload).token }

let(:auth_hash) do
{
'provider' => 'criipto',
'uid' => '{29d14ea0-6e16-4732-86ac-5de87a941784}',
'info' =>
{ 'name' => 'Bulenga Poulsen',
'email' => nil,
'email_verified' => nil,
'nickname' => nil,
'first_name' => nil,
'last_name' => nil,
'gender' => nil,
'image' => nil,
'phone' => nil,
'urls' => { 'website' => nil } },
'credentials' =>
{ 'id_token' =>
# rubocop:disable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hbWUiOiJCdWxlbmdhIFBvdWxzZW4iLCJyZWZUZXh0SGVhZGVyIjoiTG9nIG9uIGF0IENyaWlwdG8iLCJyZWZUZXh0Qm9keSI6ImxvY2FsIGRldmVsb3BtZW50IHRlc3QgKEtvZW4pIiwiY291bnRyeSI6IkRLIiwiaWF0IjoxNjkyNjIxOTAyLCJuYmYiOjE2OTI2MjE5MDIsImV4cCI6MTY5MjYzOTg4OH0.1dMJe80vvEFt4EFIF2kd_Tdy5UPEEw3qGjjVuNYHhw1Oonxpjtpjm1t-Q8YiMUZ_zwsjtnZF8hoJ8PlNV_Q5f4PS0rRk7XOeYbCvwHqAUVyFdlQudXsKi7FatqsDBfBcxqNkR4Wi1kWCpGQGtPc3X2yjtBkZP7xvvOAzdOlWjL9VuI7s2LXk-TH_7SorEqKnEAIOFVD6wYLGJ0vbU-EAG3b1lAmGsPQPRNqbgrIic1ll4DEurKs76X_-Jcq4dZiRx-X2gMJ4lefU4aaBKkIyUiYdNSRtgZSN_V6J68ZzcU2UO-_PlQX8vgE7z0vRdM1wmJQIdXpQDL4PRmjpvKl_tg',
# rubocop:enable Layout/LineLength
'token' => 'bb7cb707-f405-43af-9f7e-b151846fd92b',
'refresh_token' => nil,
'expires_in' => '120',
'scope' => nil },
'extra' =>
{ 'raw_info' =>
{ 'nonce' => 'bf5811df0cbf392754ca252a29c0cc36',
'identityscheme' => 'dkmitid',
'authenticationtype' => 'urn:grn:authn:dk:mitid:substantial',
'authenticationmethod' =>
'app:1692621888956:SUBSTANTIAL:SUBSTANTIAL:HIGH:HIGH',
'authenticationinstant' => '2023-08-21T12:45:01.733Z',
'nameidentifier' => '29d14ea06e16473286ac5de87a941784',
'sub' => '{29d14ea0-6e16-4732-86ac-5de87a941784}',
'sessionindex' => '531690ce-9792-4949-8a11-f3f5a4c504b5',
'loA' => 'SUBSTANTIAL',
'ial' => 'SUBSTANTIAL',
'aal' => 'SUBSTANTIAL',
'fal' => 'HIGH',
'uuid' => '410a77ec-4f85-46e4-aaef-bdbbd1a951f2',
'cprNumberIdentifier' => '3112772846',
'birthdate' => '1977-12-31',
'dateofbirth' => '1977-12-31',
'age' => '45',
'name' => 'Bulenga Poulsen',
'refTextHeader' => 'Log on at Criipto',
'refTextBody' => 'local development test (Koen)',
'country' => 'DK',
'iss' => 'https://kobenhavn-test.criipto.id',
'aud' => 'urn:my:application:identifier:407793',
'iat' => 1_692_621_902,
'nbf' => 1_692_621_902,
'exp' => 1_692_639_888,
address: {
formatted: "Paiman Petersen\nGrusgraven 1,3 tv\n3400 Hillerød\n(Lokalitet ukendt)\nDanmark",
common_name: 'Paiman Petersen',
street_address: 'Grusgraven 1,3 tv',
postal_code: '3400',
city: 'Hillerød',
locality: '(Lokalitet ukendt)',
region: nil,
country: 'Danmark'
},
address_details: {
road: 'Grusgraven',
road_code: '1732',
municipality: 'Lyngby-Taarbæk',
municipality_code: '0173',
house_number: '001',
floor: '03',
apartment_code: ' tv'
} } }
}
end

before do
OmniAuth.config.test_mode = true
OmniAuth.config.mock_auth[:criipto] = OmniAuth::AuthHash.new(
{ 'provider' => 'criipto',
'uid' => '{29d14ea0-6e16-4732-86ac-5de87a941784}',
'info' =>
{ 'name' => 'Bulenga Poulsen',
'email' => nil,
'email_verified' => nil,
'nickname' => nil,
'first_name' => nil,
'last_name' => nil,
'gender' => nil,
'image' => nil,
'phone' => nil,
'urls' => { 'website' => nil } },
'credentials' =>
{ 'id_token' =>
# rubocop:disable Layout/LineLength
'eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImtpZCI6IjhCREY3OUEzRkY5OTdFQTg1QjYyRjk1OUQzRDdCMzdFRDAyMjhFOTAifQ.eyJpc3MiOiJodHRwczovL2tvYmVuaGF2bi10ZXN0LmNyaWlwdG8uaWQiLCJhdWQiOiJ1cm46bXk6YXBwbGljYXRpb246aWRlbnRpZmllcjo0MDc3OTMiLCJub25jZSI6ImJmNTgxMWRmMGNiZjM5Mjc1NGNhMjUyYTI5YzBjYzM2IiwiaW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8YiMUZ_zwsjtnZF8hoJ8PlNV_Q5f4PS0rRk7XOeYbCvwHqAUVyFdlQudXsKi7FatqsDBfBcxqNkR4Wi1kWCpGQGtPc3X2yjtBkZP7xvvOAzdOlWjL9VuI7s2LXk-TH_7SorEqKnEAIOFVD6wYLGJ0vbU-EAG3b1lAmGsPQPRNqbgrIic1ll4DEurKs76X_-Jcq4dZiRx-X2gMJ4lefU4aaBKkIyUiYdNSRtgZSN_V6J68ZzcU2UO-_PlQX8vgE7z0vRdM1wmJQIdXpQDL4PRmjpvKl_tg',
# rubocop:enable Layout/LineLength
'token' => 'bb7cb707-f405-43af-9f7e-b151846fd92b',
'refresh_token' => nil,
'expires_in' => '120',
'scope' => nil },
'extra' =>
{ 'raw_info' =>
{ 'nonce' => 'bf5811df0cbf392754ca252a29c0cc36',
'identityscheme' => 'dkmitid',
'authenticationtype' => 'urn:grn:authn:dk:mitid:substantial',
'authenticationmethod' =>
'app:1692621888956:SUBSTANTIAL:SUBSTANTIAL:HIGH:HIGH',
'authenticationinstant' => '2023-08-21T12:45:01.733Z',
'nameidentifier' => '29d14ea06e16473286ac5de87a941784',
'sub' => '{29d14ea0-6e16-4732-86ac-5de87a941784}',
'sessionindex' => '531690ce-9792-4949-8a11-f3f5a4c504b5',
'loA' => 'SUBSTANTIAL',
'ial' => 'SUBSTANTIAL',
'aal' => 'SUBSTANTIAL',
'fal' => 'HIGH',
'uuid' => '410a77ec-4f85-46e4-aaef-bdbbd1a951f2',
'cprNumberIdentifier' => '3112772846',
'birthdate' => '1977-12-31',
'dateofbirth' => '1977-12-31',
'age' => '45',
'name' => 'Bulenga Poulsen',
'refTextHeader' => 'Log on at Criipto',
'refTextBody' => 'local development test (Koen)',
'country' => 'DK',
'iss' => 'https://kobenhavn-test.criipto.id',
'aud' => 'urn:my:application:identifier:407793',
'iat' => 1_692_621_902,
'nbf' => 1_692_621_902,
'exp' => 1_692_639_888,
address: {
formatted: "Paiman Petersen\nGrusgraven 1,3 tv\n3400 Hillerød\n(Lokalitet ukendt)\nDanmark",
common_name: 'Paiman Petersen',
street_address: 'Grusgraven 1,3 tv',
postal_code: '3400',
city: 'Hillerød',
locality: '(Lokalitet ukendt)',
region: nil,
country: 'Danmark'
},
address_details: {
road: 'Grusgraven',
road_code: '1732',
municipality: 'Lyngby-Taarbæk',
municipality_code: '0173',
house_number: '001',
floor: '03',
apartment_code: ' tv'
} } } }
)
OmniAuth.config.mock_auth[:criipto] = OmniAuth::AuthHash.new(auth_hash)

configuration = AppConfiguration.instance
settings = configuration.settings
Expand Down Expand Up @@ -111,17 +115,48 @@

expect(response).to redirect_to('/en/yipie?random-passthrough-param=somevalue&verification_success=true')

expect(user.reload).to have_attributes({
verified: true
})
expect(user.reload).to have_attributes(verified: true)
expect(user.custom_field_values['municipality_code']).to eq '0173'
expect(user.custom_field_values['birthyear']).to eq 1977
expect(user.custom_field_values['birthdate']).to eq '1977-12-31'
expect(user.verifications.first).to have_attributes({
method_name: 'criipto',
user_id: user.id,
active: true,
hashed_uid: '203fb09eaa8e93ee8439b92c4ce8a4e47ab820c1b87bd7d9772376cbd1e63529'
active: true
})
hash_value = Verification::VerificationService.new.send(:hashed_uid, '{29d14ea0-6e16-4732-86ac-5de87a941784}', 'criipto')
expect(user.verifications.first.hashed_uid).to eq(hash_value)
expect(user.verifications.first.hashed_uid).to eq('d006d4bf453dcd6abf792b0a18f330796a715bdf19315c2c1db8714371bcb025')
end

it 'successfully verifies another user with another MitID account' do
get "/auth/criipto?token=#{token}"
follow_redirect!
expect(user.reload).to have_attributes({
verified: true
})

user2 = create(:user)
token2 = AuthToken::AuthToken.new(payload: user2.to_token_payload).token
auth_hash['uid'] = '12345'
OmniAuth.config.mock_auth[:criipto] = OmniAuth::AuthHash.new(auth_hash)

get "/auth/criipto?token=#{token2}"
follow_redirect!
expect(user2.reload).to have_attributes(verified: true)
end

it 'fails when uid has already been used' do
uid = '{29d14ea0-6e16-4732-86ac-5de87a941784}'
create(
:verification,
method_name: 'criipto',
hashed_uid: Verification::VerificationService.new.send(:hashed_uid, uid, 'criipto')
)

get "/auth/criipto?token=#{token}"
follow_redirect!

expect(user.reload).to have_attributes(verified: false)
end
end
23 changes: 11 additions & 12 deletions back/engines/commercial/multi_tenancy/app/models/tenant.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,18 +51,6 @@ class Tenant < ApplicationRecord
where(id: ids)
}

# Order by most important tenants (active) first
scope :prioritized, lambda {
priority_order = %w[active trial demo expired_trial churned not_applicable]
tenants = AppConfiguration.from_tenants(self).map do |config|
{ id: config[:id], lifecycle_stage: config[:settings]['core']['lifecycle_stage'] }
end
ordered_tenants = tenants.sort_by { |tenant| priority_order.index(tenant[:lifecycle_stage]) }

ordered_ids = ordered_tenants.pluck(:id)
sort_by { |tenant| ordered_ids.index(tenant[:id]) }
}

delegate :active?, :churned?, to: :configuration

class << self
Expand All @@ -73,6 +61,17 @@ def schema_name_to_host(schema_name)
def host_to_schema_name(host)
host&.tr('.', '_')
end

# Reorder tenants by most important tenants (active) first
def prioritize(tenants)
priority_order = %w[active trial demo expired_trial churned not_applicable]
tenant_lifecycles = AppConfiguration.from_tenants(tenants).map do |config|
{ id: config[:id], lifecycle_stage: config[:settings]['core']['lifecycle_stage'] }
end
ordered_tenants = tenant_lifecycles.sort_by { |tenant| priority_order.index(tenant[:lifecycle_stage]) }
ordered_ids = ordered_tenants.pluck(:id)
tenants.sort_by { |tenant| ordered_ids.index(tenant[:id]) }
end
end

def self.current
Expand Down
10 changes: 9 additions & 1 deletion back/engines/commercial/multi_tenancy/db/seeds/tenants.rb
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,14 @@ def create_localhost_tenant
environment: 'pre_production_integration',
issuer: ENV.fetch('DEFAULT_NEMLOG_IN_ISSUER', 'fake issuer'),
private_key: ENV.fetch('DEFAULT_NEMLOG_IN_PRIVATE_KEY', 'fake key')
},
{
name: 'criipto',
domain: 'cl-test.criipto.id',
client_id: ENV.fetch('DEFAULT_CRIIPTO_CLIENT_ID', 'fake id'),
client_secret: ENV.fetch('DEFAULT_CRIIPTO_CLIENT_SECRET', 'fake secret'),
identity_source: 'DK MitID',
method_name_multiloc: { en: 'MitID (Criipto)' }
}
]
},
Expand Down Expand Up @@ -427,7 +435,7 @@ def create_localhost_tenant
allowed: true
},
posthog_integration: {
enabled: true,
enabled: false,
allowed: true
},
user_blocking: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

namespace :setup_and_support do
namespace :setup_and_support do # rubocop:disable Metrics/BlockLength
desc 'Mass official feedback'
task :mass_official_feedback, %i[url host locale] => [:environment] do |_t, args|
# ID, Feedback, Feedback Author Name, Feedback Email, New Status
Expand Down Expand Up @@ -139,13 +139,15 @@ namespace :setup_and_support do
Apartment::Tenant.switch(args[:host].tr('.', '_')) do
translator = MachineTranslations::MachineTranslationService.new
data_listing = Cl2DataListingService.new
data_listing.cl2_schema_leaf_models.each do |claz|
claz.find_each do |object|
data_listing.cl2_schema_models.each do |claz|
puts "Processing class #{claz.name}"
claz.all.each do |object|
changes = {}
data_listing.multiloc_attributes(claz).each do |ml|
value = object.send ml
next unless value.present? && value[args[:locale_from]].present? && value[args[:locale_to]].blank?

puts "Translating #{object.class.name} #{object.id}"
changes[ml] = value.clone
changes[ml][args[:locale_to]] =
translator.translate value[args[:locale_from]], args[:locale_from], args[:locale_to],
Expand All @@ -154,6 +156,7 @@ namespace :setup_and_support do
object.update_columns changes if changes.present?
end
end
puts 'Successfully processed everything'
end
end

Expand Down
Loading

0 comments on commit 284a072

Please sign in to comment.