diff --git a/Application/EdFi.Ods.Standard/Standard/5.2.0/Artifacts/MsSql/Data/Security/2200-AssessmentRegistartion-security-metadata.sql b/Application/EdFi.Ods.Standard/Standard/5.2.0/Artifacts/MsSql/Data/Security/2200-AssessmentRegistration-security-metadata.sql similarity index 68% rename from Application/EdFi.Ods.Standard/Standard/5.2.0/Artifacts/MsSql/Data/Security/2200-AssessmentRegistartion-security-metadata.sql rename to Application/EdFi.Ods.Standard/Standard/5.2.0/Artifacts/MsSql/Data/Security/2200-AssessmentRegistration-security-metadata.sql index 1dd6675a47..a2dabcdbf2 100644 --- a/Application/EdFi.Ods.Standard/Standard/5.2.0/Artifacts/MsSql/Data/Security/2200-AssessmentRegistartion-security-metadata.sql +++ b/Application/EdFi.Ods.Standard/Standard/5.2.0/Artifacts/MsSql/Data/Security/2200-AssessmentRegistration-security-metadata.sql @@ -406,45 +406,6 @@ BEGIN - ---------------------------------------------------------------------------------------------------------------------------- - -- Claim set: 'Assessment Read' - ---------------------------------------------------------------------------------------------------------------------------- - SET @claimSetName = 'Assessment Read' - SET @claimSetId = NULL - - SELECT @claimSetId = ClaimSetId - FROM dbo.ClaimSets - WHERE ClaimSetName = @claimSetName - - IF @claimSetId IS NULL - BEGIN - PRINT 'Creating new claim set: ' + @claimSetName - - INSERT INTO dbo.ClaimSets(ClaimSetName) - VALUES (@claimSetName) - - SET @claimSetId = SCOPE_IDENTITY() - END - - PRINT 'Deleting existing actions for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ') on resource claim ''' + @claimName + '''.' - - DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides - WHERE ClaimSetResourceClaimActionId IN (SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId) - - DELETE FROM dbo.ClaimSetResourceClaimActions - WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId - - - -- Claim set-specific Read authorization - PRINT 'Creating ''Read'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @ReadActionId) + ').' - - INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId) - VALUES (@claimId, @claimSetId, @ReadActionId) -- Read - - SET @claimSetResourceClaimActionId = SCOPE_IDENTITY() - - - ---------------------------------------------------------------------------------------------------------------------------- -- Claim set: 'District Hosted SIS Vendor' ---------------------------------------------------------------------------------------------------------------------------- @@ -941,111 +902,6 @@ BEGIN END END - ---------------------------------------------------------------------------------------------------------------------------- - -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/studentEducationOrganizationAssessmentAccommodation' - ---------------------------------------------------------------------------------------------------------------------------- - SET @claimName = 'http://ed-fi.org/ods/identity/claims/studentEducationOrganizationAssessmentAccommodation' - SET @claimId = NULL - - SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId - FROM dbo.ResourceClaims - WHERE ClaimName = @claimName - - SELECT @parentResourceClaimId = ResourceClaimId - FROM @claimIdStack - WHERE Id = (SELECT Max(Id) FROM @claimIdStack) - - IF @claimId IS NULL - BEGIN - PRINT 'Creating new claim: ' + @claimName - - INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId) - VALUES ('studentEducationOrganizationAssessmentAccommodation', 'http://ed-fi.org/ods/identity/claims/studentEducationOrganizationAssessmentAccommodation', @parentResourceClaimId) - - SET @claimId = SCOPE_IDENTITY() - END - ELSE - BEGIN - IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL) - BEGIN - PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')' - - UPDATE dbo.ResourceClaims - SET ParentResourceClaimId = @parentResourceClaimId - WHERE ResourceClaimId = @claimId - END - END - - ---------------------------------------------------------------------------------------------------------------------------- - -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/studentEducationOrganizationAssessmentAccommodationGeneralAccommodation' - ---------------------------------------------------------------------------------------------------------------------------- - SET @claimName = 'http://ed-fi.org/ods/identity/claims/studentEducationOrganizationAssessmentAccommodationGeneralAccommodation' - SET @claimId = NULL - - SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId - FROM dbo.ResourceClaims - WHERE ClaimName = @claimName - - SELECT @parentResourceClaimId = ResourceClaimId - FROM @claimIdStack - WHERE Id = (SELECT Max(Id) FROM @claimIdStack) - - IF @claimId IS NULL - BEGIN - PRINT 'Creating new claim: ' + @claimName - - INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId) - VALUES ('studentEducationOrganizationAssessmentAccommodationGeneralAccommodation', 'http://ed-fi.org/ods/identity/claims/studentEducationOrganizationAssessmentAccommodationGeneralAccommodation', @parentResourceClaimId) - - SET @claimId = SCOPE_IDENTITY() - END - ELSE - BEGIN - IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL) - BEGIN - PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')' - - UPDATE dbo.ResourceClaims - SET ParentResourceClaimId = @parentResourceClaimId - WHERE ResourceClaimId = @claimId - END - END - - ---------------------------------------------------------------------------------------------------------------------------- - -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/studentSection504ProgramAssociation' - ---------------------------------------------------------------------------------------------------------------------------- - SET @claimName = 'http://ed-fi.org/ods/identity/claims/studentSection504ProgramAssociation' - SET @claimId = NULL - - SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId - FROM dbo.ResourceClaims - WHERE ClaimName = @claimName - - SELECT @parentResourceClaimId = ResourceClaimId - FROM @claimIdStack - WHERE Id = (SELECT Max(Id) FROM @claimIdStack) - - IF @claimId IS NULL - BEGIN - PRINT 'Creating new claim: ' + @claimName - - INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId) - VALUES ('studentSection504ProgramAssociation', 'http://ed-fi.org/ods/identity/claims/studentSection504ProgramAssociation', @parentResourceClaimId) - - SET @claimId = SCOPE_IDENTITY() - END - ELSE - BEGIN - IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL) - BEGIN - PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')' - - UPDATE dbo.ResourceClaims - SET ParentResourceClaimId = @parentResourceClaimId - WHERE ResourceClaimId = @claimId - END - END - -- Pop the stack DELETE FROM @claimIdStack WHERE Id = (SELECT Max(Id) FROM @claimIdStack) @@ -1480,6 +1336,888 @@ BEGIN END + -- Pop the stack + DELETE FROM @claimIdStack WHERE Id = (SELECT Max(Id) FROM @claimIdStack) + + ---------------------------------------------------------------------------------------------------------------------------- + -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/domains/relationshipBasedData' + ---------------------------------------------------------------------------------------------------------------------------- + SET @claimName = 'http://ed-fi.org/ods/identity/claims/domains/relationshipBasedData' + SET @claimId = NULL + + SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId + FROM dbo.ResourceClaims + WHERE ClaimName = @claimName + + SELECT @parentResourceClaimId = ResourceClaimId + FROM @claimIdStack + WHERE Id = (SELECT Max(Id) FROM @claimIdStack) + + IF @claimId IS NULL + BEGIN + PRINT 'Creating new claim: ' + @claimName + + INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId) + VALUES ('relationshipBasedData', 'http://ed-fi.org/ods/identity/claims/domains/relationshipBasedData', @parentResourceClaimId) + + SET @claimId = SCOPE_IDENTITY() + END + ELSE + BEGIN + IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL) + BEGIN + PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')' + + UPDATE dbo.ResourceClaims + SET ParentResourceClaimId = @parentResourceClaimId + WHERE ResourceClaimId = @claimId + END + END + + -- Setting default authorization metadata + PRINT 'Deleting default action authorizations for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').' + + DELETE FROM dbo.ResourceClaimActionAuthorizationStrategies + WHERE ResourceClaimActionId IN (SELECT ResourceClaimActionId FROM dbo.ResourceClaimActions WHERE ResourceClaimId = @claimId); + + DELETE FROM dbo.ResourceClaimActions + WHERE ResourceClaimId = @claimId + + -- Default Create authorization + PRINT 'Creating action ''Create'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').' + INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId) + VALUES (@claimId, @CreateActionId) + + SET @resourceClaimActionId = SCOPE_IDENTITY() + + + SET @authorizationStrategyId = NULL + + SELECT @authorizationStrategyId = a.AuthorizationStrategyId + FROM dbo.AuthorizationStrategies a + WHERE a.AuthorizationStrategyName = 'RelationshipsWithEdOrgsAndPeople' + + IF @authorizationStrategyId IS NULL + BEGIN + SET @msg = 'AuthorizationStrategy does not exist: ''RelationshipsWithEdOrgsAndPeople'''; + THROW 50000, @msg, 1 + END + + PRINT 'Adding authorization strategy ''RelationshipsWithEdOrgsAndPeople'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').' + INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId) + VALUES (@resourceClaimActionId, @authorizationStrategyId) + + + -- Default Read authorization + PRINT 'Creating action ''Read'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').' + INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId) + VALUES (@claimId, @ReadActionId) + + SET @resourceClaimActionId = SCOPE_IDENTITY() + + + SET @authorizationStrategyId = NULL + + SELECT @authorizationStrategyId = a.AuthorizationStrategyId + FROM dbo.AuthorizationStrategies a + WHERE a.AuthorizationStrategyName = 'RelationshipsWithEdOrgsAndPeople' + + IF @authorizationStrategyId IS NULL + BEGIN + SET @msg = 'AuthorizationStrategy does not exist: ''RelationshipsWithEdOrgsAndPeople'''; + THROW 50000, @msg, 1 + END + + PRINT 'Adding authorization strategy ''RelationshipsWithEdOrgsAndPeople'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').' + INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId) + VALUES (@resourceClaimActionId, @authorizationStrategyId) + + + -- Default Update authorization + PRINT 'Creating action ''Update'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').' + INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId) + VALUES (@claimId, @UpdateActionId) + + SET @resourceClaimActionId = SCOPE_IDENTITY() + + + SET @authorizationStrategyId = NULL + + SELECT @authorizationStrategyId = a.AuthorizationStrategyId + FROM dbo.AuthorizationStrategies a + WHERE a.AuthorizationStrategyName = 'RelationshipsWithEdOrgsAndPeople' + + IF @authorizationStrategyId IS NULL + BEGIN + SET @msg = 'AuthorizationStrategy does not exist: ''RelationshipsWithEdOrgsAndPeople'''; + THROW 50000, @msg, 1 + END + + PRINT 'Adding authorization strategy ''RelationshipsWithEdOrgsAndPeople'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').' + INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId) + VALUES (@resourceClaimActionId, @authorizationStrategyId) + + + -- Default Delete authorization + PRINT 'Creating action ''Delete'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').' + INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId) + VALUES (@claimId, @DeleteActionId) + + SET @resourceClaimActionId = SCOPE_IDENTITY() + + + SET @authorizationStrategyId = NULL + + SELECT @authorizationStrategyId = a.AuthorizationStrategyId + FROM dbo.AuthorizationStrategies a + WHERE a.AuthorizationStrategyName = 'RelationshipsWithEdOrgsAndPeople' + + IF @authorizationStrategyId IS NULL + BEGIN + SET @msg = 'AuthorizationStrategy does not exist: ''RelationshipsWithEdOrgsAndPeople'''; + THROW 50000, @msg, 1 + END + + PRINT 'Adding authorization strategy ''RelationshipsWithEdOrgsAndPeople'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').' + INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId) + VALUES (@resourceClaimActionId, @authorizationStrategyId) + + + -- Processing claim sets for http://ed-fi.org/ods/identity/claims/domains/relationshipBasedData + ---------------------------------------------------------------------------------------------------------------------------- + -- Claim set: 'SIS Vendor' + ---------------------------------------------------------------------------------------------------------------------------- + SET @claimSetName = 'SIS Vendor' + SET @claimSetId = NULL + + SELECT @claimSetId = ClaimSetId + FROM dbo.ClaimSets + WHERE ClaimSetName = @claimSetName + + IF @claimSetId IS NULL + BEGIN + PRINT 'Creating new claim set: ' + @claimSetName + + INSERT INTO dbo.ClaimSets(ClaimSetName) + VALUES (@claimSetName) + + SET @claimSetId = SCOPE_IDENTITY() + END + + PRINT 'Deleting existing actions for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ') on resource claim ''' + @claimName + '''.' + + DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides + WHERE ClaimSetResourceClaimActionId IN (SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId) + + DELETE FROM dbo.ClaimSetResourceClaimActions + WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId + + + -- Claim set-specific Create authorization + PRINT 'Creating ''Create'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @CreateActionId) + ').' + + INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId) + VALUES (@claimId, @claimSetId, @CreateActionId) -- Create + + SET @claimSetResourceClaimActionId = SCOPE_IDENTITY() + + + + + -- Claim set-specific Read authorization + PRINT 'Creating ''Read'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @ReadActionId) + ').' + + INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId) + VALUES (@claimId, @claimSetId, @ReadActionId) -- Read + + SET @claimSetResourceClaimActionId = SCOPE_IDENTITY() + + + + + -- Claim set-specific Update authorization + PRINT 'Creating ''Update'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @UpdateActionId) + ').' + + INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId) + VALUES (@claimId, @claimSetId, @UpdateActionId) -- Update + + SET @claimSetResourceClaimActionId = SCOPE_IDENTITY() + + + + + -- Claim set-specific Delete authorization + PRINT 'Creating ''Delete'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @DeleteActionId) + ').' + + INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId) + VALUES (@claimId, @claimSetId, @DeleteActionId) -- Delete + + SET @claimSetResourceClaimActionId = SCOPE_IDENTITY() + + + + ---------------------------------------------------------------------------------------------------------------------------- + -- Claim set: 'Ed-Fi Sandbox' + ---------------------------------------------------------------------------------------------------------------------------- + SET @claimSetName = 'Ed-Fi Sandbox' + SET @claimSetId = NULL + + SELECT @claimSetId = ClaimSetId + FROM dbo.ClaimSets + WHERE ClaimSetName = @claimSetName + + IF @claimSetId IS NULL + BEGIN + PRINT 'Creating new claim set: ' + @claimSetName + + INSERT INTO dbo.ClaimSets(ClaimSetName) + VALUES (@claimSetName) + + SET @claimSetId = SCOPE_IDENTITY() + END + + PRINT 'Deleting existing actions for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ') on resource claim ''' + @claimName + '''.' + + DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides + WHERE ClaimSetResourceClaimActionId IN (SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId) + + DELETE FROM dbo.ClaimSetResourceClaimActions + WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId + + + -- Claim set-specific Create authorization + PRINT 'Creating ''Create'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @CreateActionId) + ').' + + INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId) + VALUES (@claimId, @claimSetId, @CreateActionId) -- Create + + SET @claimSetResourceClaimActionId = SCOPE_IDENTITY() + + + + + -- Claim set-specific Read authorization + PRINT 'Creating ''Read'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @ReadActionId) + ').' + + INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId) + VALUES (@claimId, @claimSetId, @ReadActionId) -- Read + + SET @claimSetResourceClaimActionId = SCOPE_IDENTITY() + + + + + -- Claim set-specific Update authorization + PRINT 'Creating ''Update'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @UpdateActionId) + ').' + + INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId) + VALUES (@claimId, @claimSetId, @UpdateActionId) -- Update + + SET @claimSetResourceClaimActionId = SCOPE_IDENTITY() + + + + + -- Claim set-specific Delete authorization + PRINT 'Creating ''Delete'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @DeleteActionId) + ').' + + INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId) + VALUES (@claimId, @claimSetId, @DeleteActionId) -- Delete + + SET @claimSetResourceClaimActionId = SCOPE_IDENTITY() + + + + ---------------------------------------------------------------------------------------------------------------------------- + -- Claim set: 'District Hosted SIS Vendor' + ---------------------------------------------------------------------------------------------------------------------------- + SET @claimSetName = 'District Hosted SIS Vendor' + SET @claimSetId = NULL + + SELECT @claimSetId = ClaimSetId + FROM dbo.ClaimSets + WHERE ClaimSetName = @claimSetName + + IF @claimSetId IS NULL + BEGIN + PRINT 'Creating new claim set: ' + @claimSetName + + INSERT INTO dbo.ClaimSets(ClaimSetName) + VALUES (@claimSetName) + + SET @claimSetId = SCOPE_IDENTITY() + END + + PRINT 'Deleting existing actions for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ') on resource claim ''' + @claimName + '''.' + + DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides + WHERE ClaimSetResourceClaimActionId IN (SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId) + + DELETE FROM dbo.ClaimSetResourceClaimActions + WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId + + + -- Claim set-specific Create authorization + PRINT 'Creating ''Create'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @CreateActionId) + ').' + + INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId) + VALUES (@claimId, @claimSetId, @CreateActionId) -- Create + + SET @claimSetResourceClaimActionId = SCOPE_IDENTITY() + + + + + -- Claim set-specific Read authorization + PRINT 'Creating ''Read'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @ReadActionId) + ').' + + INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId) + VALUES (@claimId, @claimSetId, @ReadActionId) -- Read + + SET @claimSetResourceClaimActionId = SCOPE_IDENTITY() + + + + + -- Claim set-specific Update authorization + PRINT 'Creating ''Update'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @UpdateActionId) + ').' + + INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId) + VALUES (@claimId, @claimSetId, @UpdateActionId) -- Update + + SET @claimSetResourceClaimActionId = SCOPE_IDENTITY() + + + + + -- Claim set-specific Delete authorization + PRINT 'Creating ''Delete'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @DeleteActionId) + ').' + + INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId) + VALUES (@claimId, @claimSetId, @DeleteActionId) -- Delete + + SET @claimSetResourceClaimActionId = SCOPE_IDENTITY() + + + + -- Push claimId to the stack + INSERT INTO @claimIdStack (ResourceClaimId) VALUES (@claimId) + + -- Processing children of http://ed-fi.org/ods/identity/claims/domains/relationshipBasedData + ---------------------------------------------------------------------------------------------------------------------------- + -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/studentSection504ProgramAssociation' + ---------------------------------------------------------------------------------------------------------------------------- + SET @claimName = 'http://ed-fi.org/ods/identity/claims/studentSection504ProgramAssociation' + SET @claimId = NULL + + SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId + FROM dbo.ResourceClaims + WHERE ClaimName = @claimName + + SELECT @parentResourceClaimId = ResourceClaimId + FROM @claimIdStack + WHERE Id = (SELECT Max(Id) FROM @claimIdStack) + + IF @claimId IS NULL + BEGIN + PRINT 'Creating new claim: ' + @claimName + + INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId) + VALUES ('studentSection504ProgramAssociation', 'http://ed-fi.org/ods/identity/claims/studentSection504ProgramAssociation', @parentResourceClaimId) + + SET @claimId = SCOPE_IDENTITY() + END + ELSE + BEGIN + IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL) + BEGIN + PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')' + + UPDATE dbo.ResourceClaims + SET ParentResourceClaimId = @parentResourceClaimId + WHERE ResourceClaimId = @claimId + END + END + + + -- Pop the stack + DELETE FROM @claimIdStack WHERE Id = (SELECT Max(Id) FROM @claimIdStack) + + ---------------------------------------------------------------------------------------------------------------------------- + -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/domains/relationshipBasedData' + ---------------------------------------------------------------------------------------------------------------------------- + SET @claimName = 'http://ed-fi.org/ods/identity/claims/domains/relationshipBasedData' + SET @claimId = NULL + + SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId + FROM dbo.ResourceClaims + WHERE ClaimName = @claimName + + SELECT @parentResourceClaimId = ResourceClaimId + FROM @claimIdStack + WHERE Id = (SELECT Max(Id) FROM @claimIdStack) + + IF @claimId IS NULL + BEGIN + PRINT 'Creating new claim: ' + @claimName + + INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId) + VALUES ('relationshipBasedData', 'http://ed-fi.org/ods/identity/claims/domains/relationshipBasedData', @parentResourceClaimId) + + SET @claimId = SCOPE_IDENTITY() + END + ELSE + BEGIN + IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL) + BEGIN + PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')' + + UPDATE dbo.ResourceClaims + SET ParentResourceClaimId = @parentResourceClaimId + WHERE ResourceClaimId = @claimId + END + END + + -- Setting default authorization metadata + PRINT 'Deleting default action authorizations for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').' + + DELETE FROM dbo.ResourceClaimActionAuthorizationStrategies + WHERE ResourceClaimActionId IN (SELECT ResourceClaimActionId FROM dbo.ResourceClaimActions WHERE ResourceClaimId = @claimId); + + DELETE FROM dbo.ResourceClaimActions + WHERE ResourceClaimId = @claimId + + -- Default Create authorization + PRINT 'Creating action ''Create'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').' + INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId) + VALUES (@claimId, @CreateActionId) + + SET @resourceClaimActionId = SCOPE_IDENTITY() + + + SET @authorizationStrategyId = NULL + + SELECT @authorizationStrategyId = a.AuthorizationStrategyId + FROM dbo.AuthorizationStrategies a + WHERE a.AuthorizationStrategyName = 'RelationshipsWithEdOrgsAndPeople' + + IF @authorizationStrategyId IS NULL + BEGIN + SET @msg = 'AuthorizationStrategy does not exist: ''RelationshipsWithEdOrgsAndPeople'''; + THROW 50000, @msg, 1 + END + + PRINT 'Adding authorization strategy ''RelationshipsWithEdOrgsAndPeople'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').' + INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId) + VALUES (@resourceClaimActionId, @authorizationStrategyId) + + + -- Default Read authorization + PRINT 'Creating action ''Read'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').' + INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId) + VALUES (@claimId, @ReadActionId) + + SET @resourceClaimActionId = SCOPE_IDENTITY() + + + SET @authorizationStrategyId = NULL + + SELECT @authorizationStrategyId = a.AuthorizationStrategyId + FROM dbo.AuthorizationStrategies a + WHERE a.AuthorizationStrategyName = 'RelationshipsWithEdOrgsAndPeople' + + IF @authorizationStrategyId IS NULL + BEGIN + SET @msg = 'AuthorizationStrategy does not exist: ''RelationshipsWithEdOrgsAndPeople'''; + THROW 50000, @msg, 1 + END + + PRINT 'Adding authorization strategy ''RelationshipsWithEdOrgsAndPeople'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').' + INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId) + VALUES (@resourceClaimActionId, @authorizationStrategyId) + + + -- Default Update authorization + PRINT 'Creating action ''Update'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').' + INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId) + VALUES (@claimId, @UpdateActionId) + + SET @resourceClaimActionId = SCOPE_IDENTITY() + + + SET @authorizationStrategyId = NULL + + SELECT @authorizationStrategyId = a.AuthorizationStrategyId + FROM dbo.AuthorizationStrategies a + WHERE a.AuthorizationStrategyName = 'RelationshipsWithEdOrgsAndPeople' + + IF @authorizationStrategyId IS NULL + BEGIN + SET @msg = 'AuthorizationStrategy does not exist: ''RelationshipsWithEdOrgsAndPeople'''; + THROW 50000, @msg, 1 + END + + PRINT 'Adding authorization strategy ''RelationshipsWithEdOrgsAndPeople'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').' + INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId) + VALUES (@resourceClaimActionId, @authorizationStrategyId) + + + -- Default Delete authorization + PRINT 'Creating action ''Delete'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').' + INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId) + VALUES (@claimId, @DeleteActionId) + + SET @resourceClaimActionId = SCOPE_IDENTITY() + + + SET @authorizationStrategyId = NULL + + SELECT @authorizationStrategyId = a.AuthorizationStrategyId + FROM dbo.AuthorizationStrategies a + WHERE a.AuthorizationStrategyName = 'RelationshipsWithEdOrgsAndPeople' + + IF @authorizationStrategyId IS NULL + BEGIN + SET @msg = 'AuthorizationStrategy does not exist: ''RelationshipsWithEdOrgsAndPeople'''; + THROW 50000, @msg, 1 + END + + PRINT 'Adding authorization strategy ''RelationshipsWithEdOrgsAndPeople'' for resource claim ''' + @claimName + ''' (claimId=' + CONVERT(nvarchar, @claimId) + ').' + INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId) + VALUES (@resourceClaimActionId, @authorizationStrategyId) + + + -- Processing claim sets for http://ed-fi.org/ods/identity/claims/domains/relationshipBasedData + ---------------------------------------------------------------------------------------------------------------------------- + -- Claim set: 'SIS Vendor' + ---------------------------------------------------------------------------------------------------------------------------- + SET @claimSetName = 'SIS Vendor' + SET @claimSetId = NULL + + SELECT @claimSetId = ClaimSetId + FROM dbo.ClaimSets + WHERE ClaimSetName = @claimSetName + + IF @claimSetId IS NULL + BEGIN + PRINT 'Creating new claim set: ' + @claimSetName + + INSERT INTO dbo.ClaimSets(ClaimSetName) + VALUES (@claimSetName) + + SET @claimSetId = SCOPE_IDENTITY() + END + + PRINT 'Deleting existing actions for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ') on resource claim ''' + @claimName + '''.' + + DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides + WHERE ClaimSetResourceClaimActionId IN (SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId) + + DELETE FROM dbo.ClaimSetResourceClaimActions + WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId + + + -- Claim set-specific Create authorization + PRINT 'Creating ''Create'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @CreateActionId) + ').' + + INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId) + VALUES (@claimId, @claimSetId, @CreateActionId) -- Create + + SET @claimSetResourceClaimActionId = SCOPE_IDENTITY() + + + + + -- Claim set-specific Read authorization + PRINT 'Creating ''Read'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @ReadActionId) + ').' + + INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId) + VALUES (@claimId, @claimSetId, @ReadActionId) -- Read + + SET @claimSetResourceClaimActionId = SCOPE_IDENTITY() + + + + + -- Claim set-specific Update authorization + PRINT 'Creating ''Update'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @UpdateActionId) + ').' + + INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId) + VALUES (@claimId, @claimSetId, @UpdateActionId) -- Update + + SET @claimSetResourceClaimActionId = SCOPE_IDENTITY() + + + + + -- Claim set-specific Delete authorization + PRINT 'Creating ''Delete'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @DeleteActionId) + ').' + + INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId) + VALUES (@claimId, @claimSetId, @DeleteActionId) -- Delete + + SET @claimSetResourceClaimActionId = SCOPE_IDENTITY() + + + + ---------------------------------------------------------------------------------------------------------------------------- + -- Claim set: 'Ed-Fi Sandbox' + ---------------------------------------------------------------------------------------------------------------------------- + SET @claimSetName = 'Ed-Fi Sandbox' + SET @claimSetId = NULL + + SELECT @claimSetId = ClaimSetId + FROM dbo.ClaimSets + WHERE ClaimSetName = @claimSetName + + IF @claimSetId IS NULL + BEGIN + PRINT 'Creating new claim set: ' + @claimSetName + + INSERT INTO dbo.ClaimSets(ClaimSetName) + VALUES (@claimSetName) + + SET @claimSetId = SCOPE_IDENTITY() + END + + PRINT 'Deleting existing actions for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ') on resource claim ''' + @claimName + '''.' + + DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides + WHERE ClaimSetResourceClaimActionId IN (SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId) + + DELETE FROM dbo.ClaimSetResourceClaimActions + WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId + + + -- Claim set-specific Create authorization + PRINT 'Creating ''Create'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @CreateActionId) + ').' + + INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId) + VALUES (@claimId, @claimSetId, @CreateActionId) -- Create + + SET @claimSetResourceClaimActionId = SCOPE_IDENTITY() + + + + + -- Claim set-specific Read authorization + PRINT 'Creating ''Read'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @ReadActionId) + ').' + + INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId) + VALUES (@claimId, @claimSetId, @ReadActionId) -- Read + + SET @claimSetResourceClaimActionId = SCOPE_IDENTITY() + + + + + -- Claim set-specific Update authorization + PRINT 'Creating ''Update'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @UpdateActionId) + ').' + + INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId) + VALUES (@claimId, @claimSetId, @UpdateActionId) -- Update + + SET @claimSetResourceClaimActionId = SCOPE_IDENTITY() + + + + + -- Claim set-specific Delete authorization + PRINT 'Creating ''Delete'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @DeleteActionId) + ').' + + INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId) + VALUES (@claimId, @claimSetId, @DeleteActionId) -- Delete + + SET @claimSetResourceClaimActionId = SCOPE_IDENTITY() + + + + ---------------------------------------------------------------------------------------------------------------------------- + -- Claim set: 'District Hosted SIS Vendor' + ---------------------------------------------------------------------------------------------------------------------------- + SET @claimSetName = 'District Hosted SIS Vendor' + SET @claimSetId = NULL + + SELECT @claimSetId = ClaimSetId + FROM dbo.ClaimSets + WHERE ClaimSetName = @claimSetName + + IF @claimSetId IS NULL + BEGIN + PRINT 'Creating new claim set: ' + @claimSetName + + INSERT INTO dbo.ClaimSets(ClaimSetName) + VALUES (@claimSetName) + + SET @claimSetId = SCOPE_IDENTITY() + END + + PRINT 'Deleting existing actions for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ') on resource claim ''' + @claimName + '''.' + + DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides + WHERE ClaimSetResourceClaimActionId IN (SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId) + + DELETE FROM dbo.ClaimSetResourceClaimActions + WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId + + + -- Claim set-specific Create authorization + PRINT 'Creating ''Create'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @CreateActionId) + ').' + + INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId) + VALUES (@claimId, @claimSetId, @CreateActionId) -- Create + + SET @claimSetResourceClaimActionId = SCOPE_IDENTITY() + + + + + -- Claim set-specific Read authorization + PRINT 'Creating ''Read'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @ReadActionId) + ').' + + INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId) + VALUES (@claimId, @claimSetId, @ReadActionId) -- Read + + SET @claimSetResourceClaimActionId = SCOPE_IDENTITY() + + + + + -- Claim set-specific Update authorization + PRINT 'Creating ''Update'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @UpdateActionId) + ').' + + INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId) + VALUES (@claimId, @claimSetId, @UpdateActionId) -- Update + + SET @claimSetResourceClaimActionId = SCOPE_IDENTITY() + + + + + -- Claim set-specific Delete authorization + PRINT 'Creating ''Delete'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @DeleteActionId) + ').' + + INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId) + VALUES (@claimId, @claimSetId, @DeleteActionId) -- Delete + + SET @claimSetResourceClaimActionId = SCOPE_IDENTITY() + + + + ---------------------------------------------------------------------------------------------------------------------------- + -- Claim set: 'Assessment Vendor' + ---------------------------------------------------------------------------------------------------------------------------- + SET @claimSetName = 'Assessment Vendor' + SET @claimSetId = NULL + + SELECT @claimSetId = ClaimSetId + FROM dbo.ClaimSets + WHERE ClaimSetName = @claimSetName + + IF @claimSetId IS NULL + BEGIN + PRINT 'Creating new claim set: ' + @claimSetName + + INSERT INTO dbo.ClaimSets(ClaimSetName) + VALUES (@claimSetName) + + SET @claimSetId = SCOPE_IDENTITY() + END + + PRINT 'Deleting existing actions for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ') on resource claim ''' + @claimName + '''.' + + DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides + WHERE ClaimSetResourceClaimActionId IN (SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId) + + DELETE FROM dbo.ClaimSetResourceClaimActions + WHERE ClaimSetId = @claimSetId AND ResourceClaimId = @claimId + + + -- Claim set-specific Read authorization + PRINT 'Creating ''Read'' action for claim set ''' + @claimSetName + ''' (claimSetId=' + CONVERT(nvarchar, @claimSetId) + ', actionId = ' + CONVERT(nvarchar, @ReadActionId) + ').' + + INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId) + VALUES (@claimId, @claimSetId, @ReadActionId) -- Read + + SET @claimSetResourceClaimActionId = SCOPE_IDENTITY() + + + + -- Push claimId to the stack + INSERT INTO @claimIdStack (ResourceClaimId) VALUES (@claimId) + + -- Processing children of http://ed-fi.org/ods/identity/claims/domains/relationshipBasedData + ---------------------------------------------------------------------------------------------------------------------------- + -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/studentEducationOrganizationAssessmentAccommodation' + ---------------------------------------------------------------------------------------------------------------------------- + SET @claimName = 'http://ed-fi.org/ods/identity/claims/studentEducationOrganizationAssessmentAccommodation' + SET @claimId = NULL + + SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId + FROM dbo.ResourceClaims + WHERE ClaimName = @claimName + + SELECT @parentResourceClaimId = ResourceClaimId + FROM @claimIdStack + WHERE Id = (SELECT Max(Id) FROM @claimIdStack) + + IF @claimId IS NULL + BEGIN + PRINT 'Creating new claim: ' + @claimName + + INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId) + VALUES ('studentEducationOrganizationAssessmentAccommodation', 'http://ed-fi.org/ods/identity/claims/studentEducationOrganizationAssessmentAccommodation', @parentResourceClaimId) + + SET @claimId = SCOPE_IDENTITY() + END + ELSE + BEGIN + IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL) + BEGIN + PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')' + + UPDATE dbo.ResourceClaims + SET ParentResourceClaimId = @parentResourceClaimId + WHERE ResourceClaimId = @claimId + END + END + + ---------------------------------------------------------------------------------------------------------------------------- + -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/studentEducationOrganizationAssessmentAccommodationGeneralAccommodation' + ---------------------------------------------------------------------------------------------------------------------------- + SET @claimName = 'http://ed-fi.org/ods/identity/claims/studentEducationOrganizationAssessmentAccommodationGeneralAccommodation' + SET @claimId = NULL + + SELECT @claimId = ResourceClaimId, @existingParentResourceClaimId = ParentResourceClaimId + FROM dbo.ResourceClaims + WHERE ClaimName = @claimName + + SELECT @parentResourceClaimId = ResourceClaimId + FROM @claimIdStack + WHERE Id = (SELECT Max(Id) FROM @claimIdStack) + + IF @claimId IS NULL + BEGIN + PRINT 'Creating new claim: ' + @claimName + + INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId) + VALUES ('studentEducationOrganizationAssessmentAccommodationGeneralAccommodation', 'http://ed-fi.org/ods/identity/claims/studentEducationOrganizationAssessmentAccommodationGeneralAccommodation', @parentResourceClaimId) + + SET @claimId = SCOPE_IDENTITY() + END + ELSE + BEGIN + IF @parentResourceClaimId != @existingParentResourceClaimId OR (@parentResourceClaimId IS NULL AND @existingParentResourceClaimId IS NOT NULL) OR (@parentResourceClaimId IS NOT NULL AND @existingParentResourceClaimId IS NULL) + BEGIN + PRINT 'Repointing claim ''' + @claimName + ''' (ResourceClaimId=' + CONVERT(nvarchar, @claimId) + ') to new parent (ResourceClaimId=' + CONVERT(nvarchar, @parentResourceClaimId) + ')' + + UPDATE dbo.ResourceClaims + SET ParentResourceClaimId = @parentResourceClaimId + WHERE ResourceClaimId = @claimId + END + END + + -- Pop the stack DELETE FROM @claimIdStack WHERE Id = (SELECT Max(Id) FROM @claimIdStack) diff --git a/Application/EdFi.Ods.Standard/Standard/5.2.0/Artifacts/MsSql/Data/Security/2200-AssessmentRegistartion-security-metadata.xml b/Application/EdFi.Ods.Standard/Standard/5.2.0/Artifacts/MsSql/Data/Security/2200-AssessmentRegistration-security-metadata.xml similarity index 62% rename from Application/EdFi.Ods.Standard/Standard/5.2.0/Artifacts/MsSql/Data/Security/2200-AssessmentRegistartion-security-metadata.xml rename to Application/EdFi.Ods.Standard/Standard/5.2.0/Artifacts/MsSql/Data/Security/2200-AssessmentRegistration-security-metadata.xml index 59e5c39a37..a42736fe8f 100644 --- a/Application/EdFi.Ods.Standard/Standard/5.2.0/Artifacts/MsSql/Data/Security/2200-AssessmentRegistartion-security-metadata.xml +++ b/Application/EdFi.Ods.Standard/Standard/5.2.0/Artifacts/MsSql/Data/Security/2200-AssessmentRegistration-security-metadata.xml @@ -48,11 +48,6 @@ - - - - - @@ -75,9 +70,6 @@ - - - @@ -141,5 +133,119 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - \ No newline at end of file + + + diff --git a/Application/EdFi.Ods.Standard/Standard/5.2.0/Artifacts/PgSql/Data/Security/2200-AssessmentRegistartion-security-metadata.sql b/Application/EdFi.Ods.Standard/Standard/5.2.0/Artifacts/PgSql/Data/Security/2200-AssessmentRegistration-security-metadata.sql similarity index 67% rename from Application/EdFi.Ods.Standard/Standard/5.2.0/Artifacts/PgSql/Data/Security/2200-AssessmentRegistartion-security-metadata.sql rename to Application/EdFi.Ods.Standard/Standard/5.2.0/Artifacts/PgSql/Data/Security/2200-AssessmentRegistration-security-metadata.sql index 8ce699c5d3..296124dceb 100644 --- a/Application/EdFi.Ods.Standard/Standard/5.2.0/Artifacts/PgSql/Data/Security/2200-AssessmentRegistartion-security-metadata.sql +++ b/Application/EdFi.Ods.Standard/Standard/5.2.0/Artifacts/PgSql/Data/Security/2200-AssessmentRegistration-security-metadata.sql @@ -396,47 +396,6 @@ BEGIN - ---------------------------------------------------------------------------------------------------------------------------- - -- Claim set: 'Assessment Read' - ---------------------------------------------------------------------------------------------------------------------------- - claim_set_name := 'Assessment Read'; - claim_set_id := NULL; - - SELECT ClaimSetId INTO claim_set_id - FROM dbo.ClaimSets - WHERE ClaimSetName = claim_set_name; - - IF claim_set_id IS NULL THEN - RAISE NOTICE 'Creating new claim set: %', claim_set_name; - - INSERT INTO dbo.ClaimSets(ClaimSetName) - VALUES (claim_set_name) - RETURNING ClaimSetId - INTO claim_set_id; - END IF; - - - RAISE NOTICE USING MESSAGE = 'Deleting existing actions for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ') on resource claim ''' || claim_name || '''.'; - - DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides - WHERE ClaimSetResourceClaimActionId IN ( - SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id); - - DELETE FROM dbo.ClaimSetResourceClaimActions - WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id; - - - - -- Claim set-specific Read authorization - RAISE NOTICE USING MESSAGE = 'Creating ''Read'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Read_action_id || ').'; - - INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId) - VALUES (claim_id, claim_set_id, Read_action_id) -- Read - RETURNING ClaimSetResourceClaimActionId - INTO claim_set_resource_claim_action_id; - - - ---------------------------------------------------------------------------------------------------------------------------- -- Claim set: 'District Hosted SIS Vendor' ---------------------------------------------------------------------------------------------------------------------------- @@ -863,93 +822,6 @@ BEGIN END IF; END IF; - ---------------------------------------------------------------------------------------------------------------------------- - -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/studentEducationOrganizationAssessmentAccommodation' - ---------------------------------------------------------------------------------------------------------------------------- - claim_name := 'http://ed-fi.org/ods/identity/claims/studentEducationOrganizationAssessmentAccommodation'; - claim_id := NULL; - - SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id - FROM dbo.ResourceClaims - WHERE ClaimName = claim_name; - - parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)]; - - IF claim_id IS NULL THEN - RAISE NOTICE 'Creating new claim: %', claim_name; - - INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId) - VALUES ('studentEducationOrganizationAssessmentAccommodation', 'http://ed-fi.org/ods/identity/claims/studentEducationOrganizationAssessmentAccommodation', parent_resource_claim_id) - RETURNING ResourceClaimId - INTO claim_id; - ELSE - IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN - RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')'; - - UPDATE dbo.ResourceClaims - SET ParentResourceClaimId = parent_resource_claim_id - WHERE ResourceClaimId = claim_id; - END IF; - END IF; - - ---------------------------------------------------------------------------------------------------------------------------- - -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/studentEducationOrganizationAssessmentAccommodationGeneralAccommodation' - ---------------------------------------------------------------------------------------------------------------------------- - claim_name := 'http://ed-fi.org/ods/identity/claims/studentEducationOrganizationAssessmentAccommodationGeneralAccommodation'; - claim_id := NULL; - - SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id - FROM dbo.ResourceClaims - WHERE ClaimName = claim_name; - - parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)]; - - IF claim_id IS NULL THEN - RAISE NOTICE 'Creating new claim: %', claim_name; - - INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId) - VALUES ('studentEducationOrganizationAssessmentAccommodationGeneralAccommodation', 'http://ed-fi.org/ods/identity/claims/studentEducationOrganizationAssessmentAccommodationGeneralAccommodation', parent_resource_claim_id) - RETURNING ResourceClaimId - INTO claim_id; - ELSE - IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN - RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')'; - - UPDATE dbo.ResourceClaims - SET ParentResourceClaimId = parent_resource_claim_id - WHERE ResourceClaimId = claim_id; - END IF; - END IF; - - ---------------------------------------------------------------------------------------------------------------------------- - -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/studentSection504ProgramAssociation' - ---------------------------------------------------------------------------------------------------------------------------- - claim_name := 'http://ed-fi.org/ods/identity/claims/studentSection504ProgramAssociation'; - claim_id := NULL; - - SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id - FROM dbo.ResourceClaims - WHERE ClaimName = claim_name; - - parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)]; - - IF claim_id IS NULL THEN - RAISE NOTICE 'Creating new claim: %', claim_name; - - INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId) - VALUES ('studentSection504ProgramAssociation', 'http://ed-fi.org/ods/identity/claims/studentSection504ProgramAssociation', parent_resource_claim_id) - RETURNING ResourceClaimId - INTO claim_id; - ELSE - IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN - RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')'; - - UPDATE dbo.ResourceClaims - SET ParentResourceClaimId = parent_resource_claim_id - WHERE ResourceClaimId = claim_id; - END IF; - END IF; - -- Pop the stack claim_id_stack := (select claim_id_stack[1:array_upper(claim_id_stack, 1) - 1]); @@ -1373,6 +1245,858 @@ BEGIN END IF; + -- Pop the stack + claim_id_stack := (select claim_id_stack[1:array_upper(claim_id_stack, 1) - 1]); + + ---------------------------------------------------------------------------------------------------------------------------- + -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/domains/relationshipBasedData' + ---------------------------------------------------------------------------------------------------------------------------- + claim_name := 'http://ed-fi.org/ods/identity/claims/domains/relationshipBasedData'; + claim_id := NULL; + + SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id + FROM dbo.ResourceClaims + WHERE ClaimName = claim_name; + + parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)]; + + IF claim_id IS NULL THEN + RAISE NOTICE 'Creating new claim: %', claim_name; + + INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId) + VALUES ('relationshipBasedData', 'http://ed-fi.org/ods/identity/claims/domains/relationshipBasedData', parent_resource_claim_id) + RETURNING ResourceClaimId + INTO claim_id; + ELSE + IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN + RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')'; + + UPDATE dbo.ResourceClaims + SET ParentResourceClaimId = parent_resource_claim_id + WHERE ResourceClaimId = claim_id; + END IF; + END IF; + + -- Setting default authorization metadata + RAISE NOTICE USING MESSAGE = 'Deleting default action authorizations for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').'; + + DELETE FROM dbo.ResourceClaimActionAuthorizationStrategies + WHERE ResourceClaimActionId IN (SELECT ResourceClaimActionId FROM dbo.ResourceClaimActions WHERE ResourceClaimId = claim_id); + + DELETE FROM dbo.ResourceClaimActions + WHERE ResourceClaimId = claim_id; + + + -- Default Create authorization + RAISE NOTICE USING MESSAGE = 'Creating action ''Create'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').'; + + INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId) + VALUES (claim_id, Create_action_id) + RETURNING ResourceClaimActionId + INTO resource_claim_action_id; + + + authorization_strategy_id := NULL; + + SELECT a.AuthorizationStrategyId INTO authorization_strategy_id + FROM dbo.AuthorizationStrategies a + WHERE a.AuthorizationStrategyName = 'RelationshipsWithEdOrgsAndPeople'; + + IF authorization_strategy_id IS NULL THEN + RAISE EXCEPTION USING MESSAGE = 'AuthorizationStrategy does not exist: ''RelationshipsWithEdOrgsAndPeople'''; + END IF; + + RAISE NOTICE USING MESSAGE = 'Adding authorization strategy ''RelationshipsWithEdOrgsAndPeople'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').'; + INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId) + VALUES (resource_claim_action_id, authorization_strategy_id); + + -- Default Read authorization + RAISE NOTICE USING MESSAGE = 'Creating action ''Read'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').'; + + INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId) + VALUES (claim_id, Read_action_id) + RETURNING ResourceClaimActionId + INTO resource_claim_action_id; + + + authorization_strategy_id := NULL; + + SELECT a.AuthorizationStrategyId INTO authorization_strategy_id + FROM dbo.AuthorizationStrategies a + WHERE a.AuthorizationStrategyName = 'RelationshipsWithEdOrgsAndPeople'; + + IF authorization_strategy_id IS NULL THEN + RAISE EXCEPTION USING MESSAGE = 'AuthorizationStrategy does not exist: ''RelationshipsWithEdOrgsAndPeople'''; + END IF; + + RAISE NOTICE USING MESSAGE = 'Adding authorization strategy ''RelationshipsWithEdOrgsAndPeople'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').'; + INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId) + VALUES (resource_claim_action_id, authorization_strategy_id); + + -- Default Update authorization + RAISE NOTICE USING MESSAGE = 'Creating action ''Update'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').'; + + INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId) + VALUES (claim_id, Update_action_id) + RETURNING ResourceClaimActionId + INTO resource_claim_action_id; + + + authorization_strategy_id := NULL; + + SELECT a.AuthorizationStrategyId INTO authorization_strategy_id + FROM dbo.AuthorizationStrategies a + WHERE a.AuthorizationStrategyName = 'RelationshipsWithEdOrgsAndPeople'; + + IF authorization_strategy_id IS NULL THEN + RAISE EXCEPTION USING MESSAGE = 'AuthorizationStrategy does not exist: ''RelationshipsWithEdOrgsAndPeople'''; + END IF; + + RAISE NOTICE USING MESSAGE = 'Adding authorization strategy ''RelationshipsWithEdOrgsAndPeople'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').'; + INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId) + VALUES (resource_claim_action_id, authorization_strategy_id); + + -- Default Delete authorization + RAISE NOTICE USING MESSAGE = 'Creating action ''Delete'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').'; + + INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId) + VALUES (claim_id, Delete_action_id) + RETURNING ResourceClaimActionId + INTO resource_claim_action_id; + + + authorization_strategy_id := NULL; + + SELECT a.AuthorizationStrategyId INTO authorization_strategy_id + FROM dbo.AuthorizationStrategies a + WHERE a.AuthorizationStrategyName = 'RelationshipsWithEdOrgsAndPeople'; + + IF authorization_strategy_id IS NULL THEN + RAISE EXCEPTION USING MESSAGE = 'AuthorizationStrategy does not exist: ''RelationshipsWithEdOrgsAndPeople'''; + END IF; + + RAISE NOTICE USING MESSAGE = 'Adding authorization strategy ''RelationshipsWithEdOrgsAndPeople'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').'; + INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId) + VALUES (resource_claim_action_id, authorization_strategy_id); + + -- Processing claimsets for http://ed-fi.org/ods/identity/claims/domains/relationshipBasedData + ---------------------------------------------------------------------------------------------------------------------------- + -- Claim set: 'SIS Vendor' + ---------------------------------------------------------------------------------------------------------------------------- + claim_set_name := 'SIS Vendor'; + claim_set_id := NULL; + + SELECT ClaimSetId INTO claim_set_id + FROM dbo.ClaimSets + WHERE ClaimSetName = claim_set_name; + + IF claim_set_id IS NULL THEN + RAISE NOTICE 'Creating new claim set: %', claim_set_name; + + INSERT INTO dbo.ClaimSets(ClaimSetName) + VALUES (claim_set_name) + RETURNING ClaimSetId + INTO claim_set_id; + END IF; + + + RAISE NOTICE USING MESSAGE = 'Deleting existing actions for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ') on resource claim ''' || claim_name || '''.'; + + DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides + WHERE ClaimSetResourceClaimActionId IN ( + SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id); + + DELETE FROM dbo.ClaimSetResourceClaimActions + WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id; + + + + -- Claim set-specific Create authorization + RAISE NOTICE USING MESSAGE = 'Creating ''Create'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Create_action_id || ').'; + + INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId) + VALUES (claim_id, claim_set_id, Create_action_id) -- Create + RETURNING ClaimSetResourceClaimActionId + INTO claim_set_resource_claim_action_id; + + + + + -- Claim set-specific Read authorization + RAISE NOTICE USING MESSAGE = 'Creating ''Read'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Read_action_id || ').'; + + INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId) + VALUES (claim_id, claim_set_id, Read_action_id) -- Read + RETURNING ClaimSetResourceClaimActionId + INTO claim_set_resource_claim_action_id; + + + + + -- Claim set-specific Update authorization + RAISE NOTICE USING MESSAGE = 'Creating ''Update'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Update_action_id || ').'; + + INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId) + VALUES (claim_id, claim_set_id, Update_action_id) -- Update + RETURNING ClaimSetResourceClaimActionId + INTO claim_set_resource_claim_action_id; + + + + + -- Claim set-specific Delete authorization + RAISE NOTICE USING MESSAGE = 'Creating ''Delete'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Delete_action_id || ').'; + + INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId) + VALUES (claim_id, claim_set_id, Delete_action_id) -- Delete + RETURNING ClaimSetResourceClaimActionId + INTO claim_set_resource_claim_action_id; + + + + ---------------------------------------------------------------------------------------------------------------------------- + -- Claim set: 'Ed-Fi Sandbox' + ---------------------------------------------------------------------------------------------------------------------------- + claim_set_name := 'Ed-Fi Sandbox'; + claim_set_id := NULL; + + SELECT ClaimSetId INTO claim_set_id + FROM dbo.ClaimSets + WHERE ClaimSetName = claim_set_name; + + IF claim_set_id IS NULL THEN + RAISE NOTICE 'Creating new claim set: %', claim_set_name; + + INSERT INTO dbo.ClaimSets(ClaimSetName) + VALUES (claim_set_name) + RETURNING ClaimSetId + INTO claim_set_id; + END IF; + + + RAISE NOTICE USING MESSAGE = 'Deleting existing actions for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ') on resource claim ''' || claim_name || '''.'; + + DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides + WHERE ClaimSetResourceClaimActionId IN ( + SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id); + + DELETE FROM dbo.ClaimSetResourceClaimActions + WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id; + + + + -- Claim set-specific Create authorization + RAISE NOTICE USING MESSAGE = 'Creating ''Create'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Create_action_id || ').'; + + INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId) + VALUES (claim_id, claim_set_id, Create_action_id) -- Create + RETURNING ClaimSetResourceClaimActionId + INTO claim_set_resource_claim_action_id; + + + + + -- Claim set-specific Read authorization + RAISE NOTICE USING MESSAGE = 'Creating ''Read'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Read_action_id || ').'; + + INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId) + VALUES (claim_id, claim_set_id, Read_action_id) -- Read + RETURNING ClaimSetResourceClaimActionId + INTO claim_set_resource_claim_action_id; + + + + + -- Claim set-specific Update authorization + RAISE NOTICE USING MESSAGE = 'Creating ''Update'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Update_action_id || ').'; + + INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId) + VALUES (claim_id, claim_set_id, Update_action_id) -- Update + RETURNING ClaimSetResourceClaimActionId + INTO claim_set_resource_claim_action_id; + + + + + -- Claim set-specific Delete authorization + RAISE NOTICE USING MESSAGE = 'Creating ''Delete'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Delete_action_id || ').'; + + INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId) + VALUES (claim_id, claim_set_id, Delete_action_id) -- Delete + RETURNING ClaimSetResourceClaimActionId + INTO claim_set_resource_claim_action_id; + + + + ---------------------------------------------------------------------------------------------------------------------------- + -- Claim set: 'District Hosted SIS Vendor' + ---------------------------------------------------------------------------------------------------------------------------- + claim_set_name := 'District Hosted SIS Vendor'; + claim_set_id := NULL; + + SELECT ClaimSetId INTO claim_set_id + FROM dbo.ClaimSets + WHERE ClaimSetName = claim_set_name; + + IF claim_set_id IS NULL THEN + RAISE NOTICE 'Creating new claim set: %', claim_set_name; + + INSERT INTO dbo.ClaimSets(ClaimSetName) + VALUES (claim_set_name) + RETURNING ClaimSetId + INTO claim_set_id; + END IF; + + + RAISE NOTICE USING MESSAGE = 'Deleting existing actions for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ') on resource claim ''' || claim_name || '''.'; + + DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides + WHERE ClaimSetResourceClaimActionId IN ( + SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id); + + DELETE FROM dbo.ClaimSetResourceClaimActions + WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id; + + + + -- Claim set-specific Create authorization + RAISE NOTICE USING MESSAGE = 'Creating ''Create'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Create_action_id || ').'; + + INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId) + VALUES (claim_id, claim_set_id, Create_action_id) -- Create + RETURNING ClaimSetResourceClaimActionId + INTO claim_set_resource_claim_action_id; + + + + + -- Claim set-specific Read authorization + RAISE NOTICE USING MESSAGE = 'Creating ''Read'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Read_action_id || ').'; + + INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId) + VALUES (claim_id, claim_set_id, Read_action_id) -- Read + RETURNING ClaimSetResourceClaimActionId + INTO claim_set_resource_claim_action_id; + + + + + -- Claim set-specific Update authorization + RAISE NOTICE USING MESSAGE = 'Creating ''Update'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Update_action_id || ').'; + + INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId) + VALUES (claim_id, claim_set_id, Update_action_id) -- Update + RETURNING ClaimSetResourceClaimActionId + INTO claim_set_resource_claim_action_id; + + + + + -- Claim set-specific Delete authorization + RAISE NOTICE USING MESSAGE = 'Creating ''Delete'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Delete_action_id || ').'; + + INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId) + VALUES (claim_id, claim_set_id, Delete_action_id) -- Delete + RETURNING ClaimSetResourceClaimActionId + INTO claim_set_resource_claim_action_id; + + + + -- Push claimId to the stack + claim_id_stack := array_append(claim_id_stack, claim_id); + + -- Processing children of http://ed-fi.org/ods/identity/claims/domains/relationshipBasedData + ---------------------------------------------------------------------------------------------------------------------------- + -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/studentSection504ProgramAssociation' + ---------------------------------------------------------------------------------------------------------------------------- + claim_name := 'http://ed-fi.org/ods/identity/claims/studentSection504ProgramAssociation'; + claim_id := NULL; + + SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id + FROM dbo.ResourceClaims + WHERE ClaimName = claim_name; + + parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)]; + + IF claim_id IS NULL THEN + RAISE NOTICE 'Creating new claim: %', claim_name; + + INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId) + VALUES ('studentSection504ProgramAssociation', 'http://ed-fi.org/ods/identity/claims/studentSection504ProgramAssociation', parent_resource_claim_id) + RETURNING ResourceClaimId + INTO claim_id; + ELSE + IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN + RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')'; + + UPDATE dbo.ResourceClaims + SET ParentResourceClaimId = parent_resource_claim_id + WHERE ResourceClaimId = claim_id; + END IF; + END IF; + + + -- Pop the stack + claim_id_stack := (select claim_id_stack[1:array_upper(claim_id_stack, 1) - 1]); + + ---------------------------------------------------------------------------------------------------------------------------- + -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/domains/relationshipBasedData' + ---------------------------------------------------------------------------------------------------------------------------- + claim_name := 'http://ed-fi.org/ods/identity/claims/domains/relationshipBasedData'; + claim_id := NULL; + + SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id + FROM dbo.ResourceClaims + WHERE ClaimName = claim_name; + + parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)]; + + IF claim_id IS NULL THEN + RAISE NOTICE 'Creating new claim: %', claim_name; + + INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId) + VALUES ('relationshipBasedData', 'http://ed-fi.org/ods/identity/claims/domains/relationshipBasedData', parent_resource_claim_id) + RETURNING ResourceClaimId + INTO claim_id; + ELSE + IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN + RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')'; + + UPDATE dbo.ResourceClaims + SET ParentResourceClaimId = parent_resource_claim_id + WHERE ResourceClaimId = claim_id; + END IF; + END IF; + + -- Setting default authorization metadata + RAISE NOTICE USING MESSAGE = 'Deleting default action authorizations for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').'; + + DELETE FROM dbo.ResourceClaimActionAuthorizationStrategies + WHERE ResourceClaimActionId IN (SELECT ResourceClaimActionId FROM dbo.ResourceClaimActions WHERE ResourceClaimId = claim_id); + + DELETE FROM dbo.ResourceClaimActions + WHERE ResourceClaimId = claim_id; + + + -- Default Create authorization + RAISE NOTICE USING MESSAGE = 'Creating action ''Create'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').'; + + INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId) + VALUES (claim_id, Create_action_id) + RETURNING ResourceClaimActionId + INTO resource_claim_action_id; + + + authorization_strategy_id := NULL; + + SELECT a.AuthorizationStrategyId INTO authorization_strategy_id + FROM dbo.AuthorizationStrategies a + WHERE a.AuthorizationStrategyName = 'RelationshipsWithEdOrgsAndPeople'; + + IF authorization_strategy_id IS NULL THEN + RAISE EXCEPTION USING MESSAGE = 'AuthorizationStrategy does not exist: ''RelationshipsWithEdOrgsAndPeople'''; + END IF; + + RAISE NOTICE USING MESSAGE = 'Adding authorization strategy ''RelationshipsWithEdOrgsAndPeople'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').'; + INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId) + VALUES (resource_claim_action_id, authorization_strategy_id); + + -- Default Read authorization + RAISE NOTICE USING MESSAGE = 'Creating action ''Read'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').'; + + INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId) + VALUES (claim_id, Read_action_id) + RETURNING ResourceClaimActionId + INTO resource_claim_action_id; + + + authorization_strategy_id := NULL; + + SELECT a.AuthorizationStrategyId INTO authorization_strategy_id + FROM dbo.AuthorizationStrategies a + WHERE a.AuthorizationStrategyName = 'RelationshipsWithEdOrgsAndPeople'; + + IF authorization_strategy_id IS NULL THEN + RAISE EXCEPTION USING MESSAGE = 'AuthorizationStrategy does not exist: ''RelationshipsWithEdOrgsAndPeople'''; + END IF; + + RAISE NOTICE USING MESSAGE = 'Adding authorization strategy ''RelationshipsWithEdOrgsAndPeople'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').'; + INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId) + VALUES (resource_claim_action_id, authorization_strategy_id); + + -- Default Update authorization + RAISE NOTICE USING MESSAGE = 'Creating action ''Update'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').'; + + INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId) + VALUES (claim_id, Update_action_id) + RETURNING ResourceClaimActionId + INTO resource_claim_action_id; + + + authorization_strategy_id := NULL; + + SELECT a.AuthorizationStrategyId INTO authorization_strategy_id + FROM dbo.AuthorizationStrategies a + WHERE a.AuthorizationStrategyName = 'RelationshipsWithEdOrgsAndPeople'; + + IF authorization_strategy_id IS NULL THEN + RAISE EXCEPTION USING MESSAGE = 'AuthorizationStrategy does not exist: ''RelationshipsWithEdOrgsAndPeople'''; + END IF; + + RAISE NOTICE USING MESSAGE = 'Adding authorization strategy ''RelationshipsWithEdOrgsAndPeople'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').'; + INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId) + VALUES (resource_claim_action_id, authorization_strategy_id); + + -- Default Delete authorization + RAISE NOTICE USING MESSAGE = 'Creating action ''Delete'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').'; + + INSERT INTO dbo.ResourceClaimActions(ResourceClaimId, ActionId) + VALUES (claim_id, Delete_action_id) + RETURNING ResourceClaimActionId + INTO resource_claim_action_id; + + + authorization_strategy_id := NULL; + + SELECT a.AuthorizationStrategyId INTO authorization_strategy_id + FROM dbo.AuthorizationStrategies a + WHERE a.AuthorizationStrategyName = 'RelationshipsWithEdOrgsAndPeople'; + + IF authorization_strategy_id IS NULL THEN + RAISE EXCEPTION USING MESSAGE = 'AuthorizationStrategy does not exist: ''RelationshipsWithEdOrgsAndPeople'''; + END IF; + + RAISE NOTICE USING MESSAGE = 'Adding authorization strategy ''RelationshipsWithEdOrgsAndPeople'' for resource claim ''' || claim_name || ''' (claimId=' || claim_id || ').'; + INSERT INTO dbo.ResourceClaimActionAuthorizationStrategies(ResourceClaimActionId, AuthorizationStrategyId) + VALUES (resource_claim_action_id, authorization_strategy_id); + + -- Processing claimsets for http://ed-fi.org/ods/identity/claims/domains/relationshipBasedData + ---------------------------------------------------------------------------------------------------------------------------- + -- Claim set: 'SIS Vendor' + ---------------------------------------------------------------------------------------------------------------------------- + claim_set_name := 'SIS Vendor'; + claim_set_id := NULL; + + SELECT ClaimSetId INTO claim_set_id + FROM dbo.ClaimSets + WHERE ClaimSetName = claim_set_name; + + IF claim_set_id IS NULL THEN + RAISE NOTICE 'Creating new claim set: %', claim_set_name; + + INSERT INTO dbo.ClaimSets(ClaimSetName) + VALUES (claim_set_name) + RETURNING ClaimSetId + INTO claim_set_id; + END IF; + + + RAISE NOTICE USING MESSAGE = 'Deleting existing actions for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ') on resource claim ''' || claim_name || '''.'; + + DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides + WHERE ClaimSetResourceClaimActionId IN ( + SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id); + + DELETE FROM dbo.ClaimSetResourceClaimActions + WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id; + + + + -- Claim set-specific Create authorization + RAISE NOTICE USING MESSAGE = 'Creating ''Create'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Create_action_id || ').'; + + INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId) + VALUES (claim_id, claim_set_id, Create_action_id) -- Create + RETURNING ClaimSetResourceClaimActionId + INTO claim_set_resource_claim_action_id; + + + + + -- Claim set-specific Read authorization + RAISE NOTICE USING MESSAGE = 'Creating ''Read'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Read_action_id || ').'; + + INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId) + VALUES (claim_id, claim_set_id, Read_action_id) -- Read + RETURNING ClaimSetResourceClaimActionId + INTO claim_set_resource_claim_action_id; + + + + + -- Claim set-specific Update authorization + RAISE NOTICE USING MESSAGE = 'Creating ''Update'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Update_action_id || ').'; + + INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId) + VALUES (claim_id, claim_set_id, Update_action_id) -- Update + RETURNING ClaimSetResourceClaimActionId + INTO claim_set_resource_claim_action_id; + + + + + -- Claim set-specific Delete authorization + RAISE NOTICE USING MESSAGE = 'Creating ''Delete'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Delete_action_id || ').'; + + INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId) + VALUES (claim_id, claim_set_id, Delete_action_id) -- Delete + RETURNING ClaimSetResourceClaimActionId + INTO claim_set_resource_claim_action_id; + + + + ---------------------------------------------------------------------------------------------------------------------------- + -- Claim set: 'Ed-Fi Sandbox' + ---------------------------------------------------------------------------------------------------------------------------- + claim_set_name := 'Ed-Fi Sandbox'; + claim_set_id := NULL; + + SELECT ClaimSetId INTO claim_set_id + FROM dbo.ClaimSets + WHERE ClaimSetName = claim_set_name; + + IF claim_set_id IS NULL THEN + RAISE NOTICE 'Creating new claim set: %', claim_set_name; + + INSERT INTO dbo.ClaimSets(ClaimSetName) + VALUES (claim_set_name) + RETURNING ClaimSetId + INTO claim_set_id; + END IF; + + + RAISE NOTICE USING MESSAGE = 'Deleting existing actions for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ') on resource claim ''' || claim_name || '''.'; + + DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides + WHERE ClaimSetResourceClaimActionId IN ( + SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id); + + DELETE FROM dbo.ClaimSetResourceClaimActions + WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id; + + + + -- Claim set-specific Create authorization + RAISE NOTICE USING MESSAGE = 'Creating ''Create'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Create_action_id || ').'; + + INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId) + VALUES (claim_id, claim_set_id, Create_action_id) -- Create + RETURNING ClaimSetResourceClaimActionId + INTO claim_set_resource_claim_action_id; + + + + + -- Claim set-specific Read authorization + RAISE NOTICE USING MESSAGE = 'Creating ''Read'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Read_action_id || ').'; + + INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId) + VALUES (claim_id, claim_set_id, Read_action_id) -- Read + RETURNING ClaimSetResourceClaimActionId + INTO claim_set_resource_claim_action_id; + + + + + -- Claim set-specific Update authorization + RAISE NOTICE USING MESSAGE = 'Creating ''Update'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Update_action_id || ').'; + + INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId) + VALUES (claim_id, claim_set_id, Update_action_id) -- Update + RETURNING ClaimSetResourceClaimActionId + INTO claim_set_resource_claim_action_id; + + + + + -- Claim set-specific Delete authorization + RAISE NOTICE USING MESSAGE = 'Creating ''Delete'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Delete_action_id || ').'; + + INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId) + VALUES (claim_id, claim_set_id, Delete_action_id) -- Delete + RETURNING ClaimSetResourceClaimActionId + INTO claim_set_resource_claim_action_id; + + + + ---------------------------------------------------------------------------------------------------------------------------- + -- Claim set: 'District Hosted SIS Vendor' + ---------------------------------------------------------------------------------------------------------------------------- + claim_set_name := 'District Hosted SIS Vendor'; + claim_set_id := NULL; + + SELECT ClaimSetId INTO claim_set_id + FROM dbo.ClaimSets + WHERE ClaimSetName = claim_set_name; + + IF claim_set_id IS NULL THEN + RAISE NOTICE 'Creating new claim set: %', claim_set_name; + + INSERT INTO dbo.ClaimSets(ClaimSetName) + VALUES (claim_set_name) + RETURNING ClaimSetId + INTO claim_set_id; + END IF; + + + RAISE NOTICE USING MESSAGE = 'Deleting existing actions for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ') on resource claim ''' || claim_name || '''.'; + + DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides + WHERE ClaimSetResourceClaimActionId IN ( + SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id); + + DELETE FROM dbo.ClaimSetResourceClaimActions + WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id; + + + + -- Claim set-specific Create authorization + RAISE NOTICE USING MESSAGE = 'Creating ''Create'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Create_action_id || ').'; + + INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId) + VALUES (claim_id, claim_set_id, Create_action_id) -- Create + RETURNING ClaimSetResourceClaimActionId + INTO claim_set_resource_claim_action_id; + + + + + -- Claim set-specific Read authorization + RAISE NOTICE USING MESSAGE = 'Creating ''Read'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Read_action_id || ').'; + + INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId) + VALUES (claim_id, claim_set_id, Read_action_id) -- Read + RETURNING ClaimSetResourceClaimActionId + INTO claim_set_resource_claim_action_id; + + + + + -- Claim set-specific Update authorization + RAISE NOTICE USING MESSAGE = 'Creating ''Update'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Update_action_id || ').'; + + INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId) + VALUES (claim_id, claim_set_id, Update_action_id) -- Update + RETURNING ClaimSetResourceClaimActionId + INTO claim_set_resource_claim_action_id; + + + + + -- Claim set-specific Delete authorization + RAISE NOTICE USING MESSAGE = 'Creating ''Delete'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Delete_action_id || ').'; + + INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId) + VALUES (claim_id, claim_set_id, Delete_action_id) -- Delete + RETURNING ClaimSetResourceClaimActionId + INTO claim_set_resource_claim_action_id; + + + + ---------------------------------------------------------------------------------------------------------------------------- + -- Claim set: 'Assessment Vendor' + ---------------------------------------------------------------------------------------------------------------------------- + claim_set_name := 'Assessment Vendor'; + claim_set_id := NULL; + + SELECT ClaimSetId INTO claim_set_id + FROM dbo.ClaimSets + WHERE ClaimSetName = claim_set_name; + + IF claim_set_id IS NULL THEN + RAISE NOTICE 'Creating new claim set: %', claim_set_name; + + INSERT INTO dbo.ClaimSets(ClaimSetName) + VALUES (claim_set_name) + RETURNING ClaimSetId + INTO claim_set_id; + END IF; + + + RAISE NOTICE USING MESSAGE = 'Deleting existing actions for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ') on resource claim ''' || claim_name || '''.'; + + DELETE FROM dbo.ClaimSetResourceClaimActionAuthorizationStrategyOverrides + WHERE ClaimSetResourceClaimActionId IN ( + SELECT ClaimSetResourceClaimActionId FROM dbo.ClaimSetResourceClaimActions WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id); + + DELETE FROM dbo.ClaimSetResourceClaimActions + WHERE ClaimSetId = claim_set_id AND ResourceClaimId = claim_id; + + + + -- Claim set-specific Read authorization + RAISE NOTICE USING MESSAGE = 'Creating ''Read'' action for claim set ''' || claim_set_name || ''' (claimSetId=' || claim_set_id || ', actionId = ' || Read_action_id || ').'; + + INSERT INTO dbo.ClaimSetResourceClaimActions(ResourceClaimId, ClaimSetId, ActionId) + VALUES (claim_id, claim_set_id, Read_action_id) -- Read + RETURNING ClaimSetResourceClaimActionId + INTO claim_set_resource_claim_action_id; + + + + -- Push claimId to the stack + claim_id_stack := array_append(claim_id_stack, claim_id); + + -- Processing children of http://ed-fi.org/ods/identity/claims/domains/relationshipBasedData + ---------------------------------------------------------------------------------------------------------------------------- + -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/studentEducationOrganizationAssessmentAccommodation' + ---------------------------------------------------------------------------------------------------------------------------- + claim_name := 'http://ed-fi.org/ods/identity/claims/studentEducationOrganizationAssessmentAccommodation'; + claim_id := NULL; + + SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id + FROM dbo.ResourceClaims + WHERE ClaimName = claim_name; + + parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)]; + + IF claim_id IS NULL THEN + RAISE NOTICE 'Creating new claim: %', claim_name; + + INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId) + VALUES ('studentEducationOrganizationAssessmentAccommodation', 'http://ed-fi.org/ods/identity/claims/studentEducationOrganizationAssessmentAccommodation', parent_resource_claim_id) + RETURNING ResourceClaimId + INTO claim_id; + ELSE + IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN + RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')'; + + UPDATE dbo.ResourceClaims + SET ParentResourceClaimId = parent_resource_claim_id + WHERE ResourceClaimId = claim_id; + END IF; + END IF; + + ---------------------------------------------------------------------------------------------------------------------------- + -- Resource Claim: 'http://ed-fi.org/ods/identity/claims/studentEducationOrganizationAssessmentAccommodationGeneralAccommodation' + ---------------------------------------------------------------------------------------------------------------------------- + claim_name := 'http://ed-fi.org/ods/identity/claims/studentEducationOrganizationAssessmentAccommodationGeneralAccommodation'; + claim_id := NULL; + + SELECT ResourceClaimId, ParentResourceClaimId INTO claim_id, existing_parent_resource_claim_id + FROM dbo.ResourceClaims + WHERE ClaimName = claim_name; + + parent_resource_claim_id := claim_id_stack[array_upper(claim_id_stack, 1)]; + + IF claim_id IS NULL THEN + RAISE NOTICE 'Creating new claim: %', claim_name; + + INSERT INTO dbo.ResourceClaims(ResourceName, ClaimName, ParentResourceClaimId) + VALUES ('studentEducationOrganizationAssessmentAccommodationGeneralAccommodation', 'http://ed-fi.org/ods/identity/claims/studentEducationOrganizationAssessmentAccommodationGeneralAccommodation', parent_resource_claim_id) + RETURNING ResourceClaimId + INTO claim_id; + ELSE + IF parent_resource_claim_id != existing_parent_resource_claim_id OR (parent_resource_claim_id IS NULL AND existing_parent_resource_claim_id IS NOT NULL) OR (parent_resource_claim_id IS NOT NULL AND existing_parent_resource_claim_id IS NULL) THEN + RAISE NOTICE USING MESSAGE = 'Repointing claim ''' || claim_name || ''' (ResourceClaimId=' || claim_id || ') to new parent (from ResourceClaimId=' || COALESCE(existing_parent_resource_claim_id, 0) || ' to ResourceClaimId=' || COALESCE(parent_resource_claim_id, 0) || ')'; + + UPDATE dbo.ResourceClaims + SET ParentResourceClaimId = parent_resource_claim_id + WHERE ResourceClaimId = claim_id; + END IF; + END IF; + + -- Pop the stack claim_id_stack := (select claim_id_stack[1:array_upper(claim_id_stack, 1) - 1]); diff --git a/Application/EdFi.Ods.Standard/Standard/5.2.0/Artifacts/PgSql/Data/Security/2200-AssessmentRegistartion-security-metadata.xml b/Application/EdFi.Ods.Standard/Standard/5.2.0/Artifacts/PgSql/Data/Security/2200-AssessmentRegistration-security-metadata.xml similarity index 62% rename from Application/EdFi.Ods.Standard/Standard/5.2.0/Artifacts/PgSql/Data/Security/2200-AssessmentRegistartion-security-metadata.xml rename to Application/EdFi.Ods.Standard/Standard/5.2.0/Artifacts/PgSql/Data/Security/2200-AssessmentRegistration-security-metadata.xml index 59e5c39a37..a42736fe8f 100644 --- a/Application/EdFi.Ods.Standard/Standard/5.2.0/Artifacts/PgSql/Data/Security/2200-AssessmentRegistartion-security-metadata.xml +++ b/Application/EdFi.Ods.Standard/Standard/5.2.0/Artifacts/PgSql/Data/Security/2200-AssessmentRegistration-security-metadata.xml @@ -48,11 +48,6 @@ - - - - - @@ -75,9 +70,6 @@ - - - @@ -141,5 +133,119 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - \ No newline at end of file + + +