Add userName and externalID support
Signed-off-by: Bryan Frimin <bryan@getprobo.com>
This commit is contained in:
@@ -44,6 +44,8 @@ type (
|
||||
ContractStartDate *time.Time `db:"contract_start_date"`
|
||||
ContractEndDate *time.Time `db:"contract_end_date"`
|
||||
OrganizationName string `db:"organization_name"`
|
||||
UserName *string `db:"user_name"`
|
||||
ExternalID *string `db:"external_id"`
|
||||
CreatedAt time.Time `db:"created_at"`
|
||||
UpdatedAt time.Time `db:"updated_at"`
|
||||
}
|
||||
@@ -107,6 +109,8 @@ SELECT
|
||||
p.contract_start_date,
|
||||
p.contract_end_date,
|
||||
'' AS organization_name,
|
||||
p.user_name,
|
||||
p.external_id,
|
||||
p.created_at,
|
||||
p.updated_at
|
||||
FROM
|
||||
@@ -165,6 +169,8 @@ SELECT
|
||||
p.contract_start_date,
|
||||
p.contract_end_date,
|
||||
'' AS organization_name,
|
||||
p.user_name,
|
||||
p.external_id,
|
||||
p.created_at,
|
||||
p.updated_at
|
||||
FROM
|
||||
@@ -226,6 +232,8 @@ SELECT
|
||||
p.contract_start_date,
|
||||
p.contract_end_date,
|
||||
'' AS organization_name,
|
||||
p.user_name,
|
||||
p.external_id,
|
||||
p.created_at,
|
||||
p.updated_at
|
||||
FROM
|
||||
@@ -280,6 +288,8 @@ WITH profiles AS (
|
||||
p.position,
|
||||
p.contract_start_date,
|
||||
p.contract_end_date,
|
||||
p.user_name,
|
||||
p.external_id,
|
||||
p.created_at,
|
||||
p.updated_at
|
||||
FROM
|
||||
@@ -304,6 +314,8 @@ SELECT
|
||||
contract_start_date,
|
||||
contract_end_date,
|
||||
'' AS organization_name,
|
||||
user_name,
|
||||
external_id,
|
||||
created_at,
|
||||
updated_at
|
||||
FROM profiles
|
||||
@@ -355,6 +367,8 @@ WITH profiles AS (
|
||||
p.position,
|
||||
p.contract_start_date,
|
||||
p.contract_end_date,
|
||||
p.user_name,
|
||||
p.external_id,
|
||||
p.created_at,
|
||||
p.updated_at
|
||||
FROM
|
||||
@@ -378,6 +392,8 @@ SELECT
|
||||
p.contract_start_date,
|
||||
p.contract_end_date,
|
||||
o.name AS organization_name,
|
||||
p.user_name,
|
||||
p.external_id,
|
||||
p.created_at,
|
||||
p.updated_at
|
||||
FROM profiles p
|
||||
@@ -428,6 +444,8 @@ WITH profiles AS (
|
||||
mp.position,
|
||||
mp.contract_start_date,
|
||||
mp.contract_end_date,
|
||||
mp.user_name,
|
||||
mp.external_id,
|
||||
mp.created_at,
|
||||
mp.updated_at
|
||||
FROM
|
||||
@@ -455,6 +473,8 @@ SELECT
|
||||
p.contract_start_date,
|
||||
p.contract_end_date,
|
||||
'' AS organization_name,
|
||||
p.user_name,
|
||||
p.external_id,
|
||||
p.created_at,
|
||||
p.updated_at
|
||||
FROM profiles p
|
||||
@@ -534,6 +554,8 @@ WITH profiles AS (
|
||||
mp.position,
|
||||
mp.contract_start_date,
|
||||
mp.contract_end_date,
|
||||
mp.user_name,
|
||||
mp.external_id,
|
||||
mp.created_at,
|
||||
mp.updated_at
|
||||
FROM
|
||||
@@ -561,6 +583,8 @@ SELECT
|
||||
p.contract_start_date,
|
||||
p.contract_end_date,
|
||||
'' AS organization_name,
|
||||
p.user_name,
|
||||
p.external_id,
|
||||
p.created_at,
|
||||
p.updated_at
|
||||
FROM profiles p
|
||||
@@ -641,6 +665,8 @@ WITH attendees AS (
|
||||
p.position,
|
||||
p.contract_start_date,
|
||||
p.contract_end_date,
|
||||
p.user_name,
|
||||
p.external_id,
|
||||
p.created_at,
|
||||
p.updated_at,
|
||||
ma.created_at AS attendee_created_at
|
||||
@@ -667,6 +693,8 @@ SELECT
|
||||
contract_start_date,
|
||||
contract_end_date,
|
||||
'' AS organization_name,
|
||||
user_name,
|
||||
external_id,
|
||||
created_at,
|
||||
updated_at
|
||||
FROM
|
||||
@@ -728,6 +756,8 @@ SELECT
|
||||
p.contract_start_date,
|
||||
p.contract_end_date,
|
||||
'' AS organization_name,
|
||||
p.user_name,
|
||||
p.external_id,
|
||||
p.created_at,
|
||||
p.updated_at
|
||||
FROM
|
||||
@@ -881,6 +911,8 @@ INSERT INTO
|
||||
position,
|
||||
contract_start_date,
|
||||
contract_end_date,
|
||||
user_name,
|
||||
external_id,
|
||||
created_at,
|
||||
updated_at
|
||||
)
|
||||
@@ -897,6 +929,8 @@ VALUES (
|
||||
@position,
|
||||
@contract_start_date,
|
||||
@contract_end_date,
|
||||
@user_name,
|
||||
@external_id,
|
||||
@created_at,
|
||||
@updated_at
|
||||
)
|
||||
@@ -915,6 +949,8 @@ VALUES (
|
||||
"position": p.Position,
|
||||
"contract_start_date": p.ContractStartDate,
|
||||
"contract_end_date": p.ContractEndDate,
|
||||
"user_name": p.UserName,
|
||||
"external_id": p.ExternalID,
|
||||
"created_at": p.CreatedAt,
|
||||
"updated_at": p.UpdatedAt,
|
||||
}
|
||||
@@ -949,6 +985,8 @@ SET
|
||||
position = @position,
|
||||
contract_start_date = @contract_start_date,
|
||||
contract_end_date = @contract_end_date,
|
||||
user_name = @user_name,
|
||||
external_id = @external_id,
|
||||
updated_at = @updated_at
|
||||
WHERE
|
||||
id = @id
|
||||
@@ -967,6 +1005,8 @@ WHERE
|
||||
"position": p.Position,
|
||||
"contract_start_date": p.ContractStartDate,
|
||||
"contract_end_date": p.ContractEndDate,
|
||||
"user_name": p.UserName,
|
||||
"external_id": p.ExternalID,
|
||||
"updated_at": p.UpdatedAt,
|
||||
}
|
||||
maps.Copy(args, scope.SQLArguments())
|
||||
|
||||
@@ -28,6 +28,8 @@ type (
|
||||
excludeContractEnded *bool
|
||||
currentDate time.Time
|
||||
email *mail.Addr
|
||||
userName *string
|
||||
externalID *string
|
||||
state *ProfileState
|
||||
source *ProfileSource
|
||||
}
|
||||
@@ -59,6 +61,16 @@ func (f *MembershipProfileFilter) Email() *mail.Addr {
|
||||
return f.email
|
||||
}
|
||||
|
||||
func (f *MembershipProfileFilter) WithUserName(userName string) *MembershipProfileFilter {
|
||||
f.userName = &userName
|
||||
return f
|
||||
}
|
||||
|
||||
func (f *MembershipProfileFilter) WithExternalID(externalID string) *MembershipProfileFilter {
|
||||
f.externalID = &externalID
|
||||
return f
|
||||
}
|
||||
|
||||
func (f *MembershipProfileFilter) WithState(state ProfileState) *MembershipProfileFilter {
|
||||
f.state = &state
|
||||
return f
|
||||
@@ -80,6 +92,8 @@ func (f *MembershipProfileFilter) Source() *ProfileSource {
|
||||
func (f *MembershipProfileFilter) SQLArguments() pgx.StrictNamedArgs {
|
||||
return pgx.StrictNamedArgs{
|
||||
"filter_email": f.email,
|
||||
"filter_user_name": f.userName,
|
||||
"filter_external_id": f.externalID,
|
||||
"with_membership": f.withMembership,
|
||||
"with_trust_center_access": f.withTrustCenterAccess,
|
||||
"exclude_contract_ended": f.excludeContractEnded,
|
||||
@@ -137,5 +151,19 @@ AND (
|
||||
ELSE TRUE
|
||||
END
|
||||
)
|
||||
AND (
|
||||
CASE
|
||||
WHEN @filter_user_name::text IS NOT NULL THEN
|
||||
p.user_name = @filter_user_name::text
|
||||
ELSE TRUE
|
||||
END
|
||||
)
|
||||
AND (
|
||||
CASE
|
||||
WHEN @filter_external_id::text IS NOT NULL THEN
|
||||
p.external_id = @filter_external_id::text
|
||||
ELSE TRUE
|
||||
END
|
||||
)
|
||||
`
|
||||
}
|
||||
|
||||
16
pkg/coredata/migrations/20260306T120000Z.sql
Normal file
16
pkg/coredata/migrations/20260306T120000Z.sql
Normal file
@@ -0,0 +1,16 @@
|
||||
ALTER TABLE iam_membership_profiles
|
||||
ADD COLUMN user_name TEXT,
|
||||
ADD COLUMN external_id TEXT;
|
||||
|
||||
UPDATE iam_membership_profiles p
|
||||
SET user_name = i.email_address
|
||||
FROM identities i
|
||||
WHERE i.id = p.identity_id AND p.source = 'SCIM';
|
||||
|
||||
CREATE UNIQUE INDEX idx_profiles_user_name_organization_id
|
||||
ON iam_membership_profiles (user_name, organization_id)
|
||||
WHERE user_name IS NOT NULL;
|
||||
|
||||
CREATE UNIQUE INDEX idx_profiles_external_id_organization_id
|
||||
ON iam_membership_profiles (external_id, organization_id)
|
||||
WHERE external_id IS NOT NULL;
|
||||
Reference in New Issue
Block a user