generated from DFE-Digital/govuk-rails-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added core functionality for mulitple email addresses
- Loading branch information
1 parent
f579637
commit 1931220
Showing
21 changed files
with
294 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# frozen_string_literal: true | ||
|
||
class ParticipantIdentity < ApplicationRecord | ||
belongs_to :user | ||
has_many :participant_profiles | ||
|
||
validates :email, presence: true, uniqueness: true, notify_email: true | ||
validates :external_identifier, uniqueness: true | ||
|
||
enum origin: { | ||
ecf: "ecf", | ||
npq: "npq", | ||
}, _suffix: true | ||
|
||
scope :superceded, -> { where("participant_identities.external_identifier != participant_identities.user_id") } | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# frozen_string_literal: true | ||
|
||
class CreateUserIdentity < BaseService | ||
def call | ||
ParticipantIdentity.find_or_create_by!(email: user.email) do |identity| | ||
identity.user = user | ||
identity.external_identifier = user.id | ||
identity.email = user.email | ||
identity.origin = origin | ||
end | ||
end | ||
|
||
private | ||
|
||
attr_accessor :user, :origin | ||
|
||
def initialize(user:, origin: :ecf) | ||
@user = user | ||
@origin = origin | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# frozen_string_literal: true | ||
|
||
class TransferUserIdentity < BaseService | ||
def call | ||
from_user.participant_identities.each do |identity| | ||
identity.update!(user: to_user) | ||
identity.participant_profiles.each do |profile| | ||
# NOTE: this might currently make the profile disappear from the ecf participants api endpoint | ||
# because it limits one entry per teacher_profile | ||
profile.update!(teacher_profile: to_user.teacher_profile) | ||
end | ||
end | ||
end | ||
|
||
private | ||
|
||
attr_accessor :from_user, :to_user | ||
|
||
def initialize(from_user:, to_user:) | ||
@from_user = from_user | ||
@to_user = to_user | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# frozen_string_literal: true | ||
|
||
class CreateParticipantIdentity < ActiveRecord::Migration[6.1] | ||
def change | ||
create_table :participant_identities do |t| | ||
t.references :user, null: false, foreign_key: true | ||
t.string :email, null: false | ||
t.uuid :external_identifier, null: false | ||
t.string :origin, null: false, default: "ecf" | ||
t.timestamps | ||
end | ||
|
||
add_index :participant_identities, :email, unique: true | ||
add_index :participant_identities, :external_identifier, unique: true | ||
end | ||
end |
9 changes: 9 additions & 0 deletions
9
db/migrate/20211126114520_add_participant_identity_to_participant_profile.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# frozen_string_literal: true | ||
|
||
class AddParticipantIdentityToParticipantProfile < ActiveRecord::Migration[6.1] | ||
disable_ddl_transaction! | ||
|
||
def change | ||
add_reference :participant_profiles, :participant_identity, null: true, index: { algorithm: :concurrently } | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.