You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
97 lines
2.8 KiB
97 lines
2.8 KiB
CREATE OR ALTER PROCEDURE [dbo].[OrganizationUser_CreateManyWithCollectionsAndGroups] |
|
@organizationUserData NVARCHAR(MAX), |
|
@collectionData NVARCHAR(MAX), |
|
@groupData NVARCHAR(MAX) |
|
AS |
|
BEGIN |
|
SET NOCOUNT ON |
|
|
|
INSERT INTO [dbo].[OrganizationUser] |
|
( |
|
[Id], |
|
[OrganizationId], |
|
[UserId], |
|
[Email], |
|
[Key], |
|
[Status], |
|
[Type], |
|
[ExternalId], |
|
[CreationDate], |
|
[RevisionDate], |
|
[Permissions], |
|
[ResetPasswordKey], |
|
[AccessSecretsManager] |
|
) |
|
SELECT |
|
OUI.[Id], |
|
OUI.[OrganizationId], |
|
OUI.[UserId], |
|
OUI.[Email], |
|
OUI.[Key], |
|
OUI.[Status], |
|
OUI.[Type], |
|
OUI.[ExternalId], |
|
OUI.[CreationDate], |
|
OUI.[RevisionDate], |
|
OUI.[Permissions], |
|
OUI.[ResetPasswordKey], |
|
OUI.[AccessSecretsManager] |
|
FROM |
|
OPENJSON(@organizationUserData) |
|
WITH ( |
|
[Id] UNIQUEIDENTIFIER '$.Id', |
|
[OrganizationId] UNIQUEIDENTIFIER '$.OrganizationId', |
|
[UserId] UNIQUEIDENTIFIER '$.UserId', |
|
[Email] NVARCHAR(256) '$.Email', |
|
[Key] VARCHAR(MAX) '$.Key', |
|
[Status] SMALLINT '$.Status', |
|
[Type] TINYINT '$.Type', |
|
[ExternalId] NVARCHAR(300) '$.ExternalId', |
|
[CreationDate] DATETIME2(7) '$.CreationDate', |
|
[RevisionDate] DATETIME2(7) '$.RevisionDate', |
|
[Permissions] NVARCHAR (MAX) '$.Permissions', |
|
[ResetPasswordKey] VARCHAR (MAX) '$.ResetPasswordKey', |
|
[AccessSecretsManager] BIT '$.AccessSecretsManager' |
|
) OUI |
|
|
|
INSERT INTO [dbo].[GroupUser] |
|
( |
|
[OrganizationUserId], |
|
[GroupId] |
|
) |
|
SELECT |
|
OUG.OrganizationUserId, |
|
OUG.GroupId |
|
FROM |
|
OPENJSON(@groupData) |
|
WITH( |
|
[OrganizationUserId] UNIQUEIDENTIFIER '$.OrganizationUserId', |
|
[GroupId] UNIQUEIDENTIFIER '$.GroupId' |
|
) OUG |
|
|
|
INSERT INTO [dbo].[CollectionUser] |
|
( |
|
[CollectionId], |
|
[OrganizationUserId], |
|
[ReadOnly], |
|
[HidePasswords], |
|
[Manage] |
|
) |
|
SELECT |
|
OUC.[CollectionId], |
|
OUC.[OrganizationUserId], |
|
OUC.[ReadOnly], |
|
OUC.[HidePasswords], |
|
OUC.[Manage] |
|
FROM |
|
OPENJSON(@collectionData) |
|
WITH( |
|
[CollectionId] UNIQUEIDENTIFIER '$.CollectionId', |
|
[OrganizationUserId] UNIQUEIDENTIFIER '$.OrganizationUserId', |
|
[ReadOnly] BIT '$.ReadOnly', |
|
[HidePasswords] BIT '$.HidePasswords', |
|
[Manage] BIT '$.Manage' |
|
) OUC |
|
END |
|
go |
|
|
|
|