Skip to content

Commit 56860a5

Browse files
ColinBeebyHEEAnjuJose011
authored andcommitted
Added trigger to ensure that DigitalLearningSolutions external user system also includes DigitalLearningSolutionsSso external user system
1 parent f9eea7b commit 56860a5

File tree

3 files changed

+61
-0
lines changed

3 files changed

+61
-0
lines changed

WebAPI/LearningHub.Nhs.Database/LearningHub.Nhs.Database.sqlproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,8 @@
9898
<Folder Include="Tables\Report" />
9999
<Folder Include="Scripts\NLog Database Scripts" />
100100
<Folder Include="Functions\Resources" />
101+
<Folder Include="Triggers" />
102+
<Folder Include="Triggers\external" />
101103
</ItemGroup>
102104
<ItemGroup>
103105
<None Include="Scripts\learningHub_Data.sql" />
@@ -506,6 +508,7 @@
506508
<Build Include="Functions\Resources\UserCanEditResource.sql" />
507509
<Build Include="Stored Procedures\Hierarchy\UserGroupPreviewerEnsure.sql" />
508510
<None Include="Scripts\Post-Deploy\Scripts\AttributeData.sql" />
511+
<None Include="Triggers\external\AddDigitalLearningSolutionsExternalSystem.sql" />
509512
</ItemGroup>
510513
<ItemGroup>
511514
<None Include="Scripts\Pre-Deploy\Scripts\Card5766_AuthorTableChanges.PreDeployment.sql" />
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
Script for adding DigitalLearningSolutionsSso ExternalSystemUser to users which already have DigitalLearningSolutions ExternalSystemUser
3+
*/
4+
DECLARE @DigitalLearningSolutionsId INT;
5+
DECLARE @DigitalLearningSolutionsSsoId INT;
6+
7+
SELECT @DigitalLearningSolutionsId = id
8+
FROM [external].[ExternalSystem]
9+
WHERE code = 'DigitalLearningSolutions';
10+
11+
SELECT @DigitalLearningSolutionsSsoId = id
12+
FROM [external].[ExternalSystem]
13+
WHERE code = 'DigitalLearningSolutionsSso';
14+
15+
INSERT INTO [external].[ExternalSystemUser] (UserId, ExternalSystemId, Deleted, CreateUserId, CreateDate, AmendUserId, AmendDate)
16+
SELECT UserId, @DigitalLearningSolutionsId, Deleted, 4, SYSDATETIMEOFFSET(), 4, SYSDATETIMEOFFSET()
17+
FROM [external].[ExternalSystemUser]
18+
WHERE ExternalSystemId = @DigitalLearningSolutionsSsoId
19+
AND userId NOT IN (
20+
SELECT userId
21+
FROM [external].[ExternalSystemUser]
22+
WHERE ExternalSystemId = @DigitalLearningSolutionsId
23+
);
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
2+
-------------------------------------------------------------------------------
3+
-- Author Colin Beeby
4+
-- Created 21-03-2024
5+
-- Purpose Ensure that when a user is associated with external system DigitalLearningSolutionsSso, they are also associated with DigitalLearningSolutions
6+
--
7+
-- Modification History
8+
--
9+
-- 21-03-2024 ColB Initial Version
10+
-------------------------------------------------------------------------------
11+
12+
CREATE TRIGGER [external].InsertTrigger_AddDigitalLearningSolutionsExternalSystem
13+
ON [external].[ExternalSystemUser]
14+
FOR INSERT
15+
AS
16+
BEGIN
17+
DECLARE @DigitalLearningSolutionsId INT;
18+
DECLARE @DigitalLearningSolutionsSsoId INT;
19+
20+
SELECT @DigitalLearningSolutionsId = id
21+
FROM [external].[ExternalSystem]
22+
WHERE code = 'DigitalLearningSolutions';
23+
24+
SELECT @DigitalLearningSolutionsSsoId = id
25+
FROM [external].[ExternalSystem]
26+
WHERE code = 'DigitalLearningSolutionsSso';
27+
28+
29+
IF EXISTS (SELECT 1 FROM inserted WHERE ExternalSystemId = @DigitalLearningSolutionsSsoId)
30+
BEGIN
31+
INSERT INTO ExternalSystemUser (UserId, ExternalSystemId, Deleted, CreateUserId, CreateDate, AmendUserId, AmendDate)
32+
SELECT UserId, @DigitalLearningSolutionsId, Deleted, CreateUserId, CreateDate, AmendUserId, AmendDate
33+
FROM inserted;
34+
END
35+
END;

0 commit comments

Comments
 (0)