Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@
<Folder Include="Tables\Report" />
<Folder Include="Scripts\NLog Database Scripts" />
<Folder Include="Functions\Resources" />
<Folder Include="Triggers" />
<Folder Include="Triggers\external" />
</ItemGroup>
<ItemGroup>
<None Include="Scripts\learningHub_Data.sql" />
Expand Down Expand Up @@ -506,6 +508,7 @@
<Build Include="Functions\Resources\UserCanEditResource.sql" />
<Build Include="Stored Procedures\Hierarchy\UserGroupPreviewerEnsure.sql" />
<None Include="Scripts\Post-Deploy\Scripts\AttributeData.sql" />
<None Include="Triggers\external\AddDigitalLearningSolutionsExternalSystem.sql" />
</ItemGroup>
<ItemGroup>
<None Include="Scripts\Pre-Deploy\Scripts\Card5766_AuthorTableChanges.PreDeployment.sql" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
Script for adding DigitalLearningSolutionsSso ExternalSystemUser to users which already have DigitalLearningSolutions ExternalSystemUser
*/
DECLARE @DigitalLearningSolutionsId INT;
DECLARE @DigitalLearningSolutionsSsoId INT;

SELECT @DigitalLearningSolutionsId = id
FROM [external].[ExternalSystem]
WHERE code = 'DigitalLearningSolutions';

SELECT @DigitalLearningSolutionsSsoId = id
FROM [external].[ExternalSystem]
WHERE code = 'DigitalLearningSolutionsSso';

INSERT INTO [external].[ExternalSystemUser] (UserId, ExternalSystemId, Deleted, CreateUserId, CreateDate, AmendUserId, AmendDate)
SELECT UserId, @DigitalLearningSolutionsId, Deleted, 4, SYSDATETIMEOFFSET(), 4, SYSDATETIMEOFFSET()
FROM [external].[ExternalSystemUser]
WHERE ExternalSystemId = @DigitalLearningSolutionsSsoId
AND userId NOT IN (
SELECT userId
FROM [external].[ExternalSystemUser]
WHERE ExternalSystemId = @DigitalLearningSolutionsId
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@

-------------------------------------------------------------------------------
-- Author Colin Beeby
-- Created 21-03-2024
-- Purpose Ensure that when a user is associated with external system DigitalLearningSolutionsSso, they are also associated with DigitalLearningSolutions
--
-- Modification History
--
-- 21-03-2024 ColB Initial Version
-------------------------------------------------------------------------------

CREATE TRIGGER [external].InsertTrigger_AddDigitalLearningSolutionsExternalSystem
ON [external].[ExternalSystemUser]
FOR INSERT
AS
BEGIN
DECLARE @DigitalLearningSolutionsId INT;
DECLARE @DigitalLearningSolutionsSsoId INT;

SELECT @DigitalLearningSolutionsId = id
FROM [external].[ExternalSystem]
WHERE code = 'DigitalLearningSolutions';

SELECT @DigitalLearningSolutionsSsoId = id
FROM [external].[ExternalSystem]
WHERE code = 'DigitalLearningSolutionsSso';


IF EXISTS (SELECT 1 FROM inserted WHERE ExternalSystemId = @DigitalLearningSolutionsSsoId)
BEGIN
INSERT INTO ExternalSystemUser (UserId, ExternalSystemId, Deleted, CreateUserId, CreateDate, AmendUserId, AmendDate)
SELECT UserId, @DigitalLearningSolutionsId, Deleted, CreateUserId, CreateDate, AmendUserId, AmendDate
FROM inserted;
END
END;