Files
Fuchs_Intranet/Fuchs_Database/dbo/Stored Procedures/fis_admin_delUserGroup.sql
T
Stefan b26c24ef98 feat: Enhance user group management and transaction handling in stored procedures
- Improved user group deletion logic to accurately report success or failure.
- Updated user group renaming checks to prevent unintended inserts or updates.
- Added documentation on transaction blocking risks during full resets in stored procedures.
- Removed unnecessary login scripts from database project.
2026-09-16 09:42:32 +02:00

47 lines
1.5 KiB
Transact-SQL

-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <Description,,>
-- =============================================
CREATE PROCEDURE [dbo].[fis_admin_delUserGroup]
@authaccount varchar(5)
,@usergroup_id varchar(5)
AS
BEGIN
SET NOCOUNT ON;
DECLARE @utcnow datetime = GETUTCDATE();
DECLARE @auth smallint = [dbo].[fis_admin_getUserAuth](@authaccount);
-- Tracks whether THIS call actually soft-deleted an active group, so a never-existing or
-- already-deleted @usergroup_id reports failure instead of a false "ok:true" (the previous
-- version derived success from "not currently active", which is also true when nothing here
-- ever existed).
DECLARE @deleted bit = 0;
IF @auth > 1 AND EXISTS (SELECT * FROM [dbo].[fis_usergroups] WHERE [usergroup_id] = @usergroup_id and [DateDeleted] is null)
BEGIN
UPDATE [dbo].[fis_usergroups]
SET [UserDeleted] = @authaccount
,[DateDeleted] = @utcnow
WHERE
[usergroup_id] = @usergroup_id
AND [DateDeleted] is null;
IF @@ROWCOUNT > 0 SET @deleted = 1;
-- Soft-delete the group's active memberships too, matching the confirm text
-- ("Die Mitgliedschaft aller Benutzer in dieser Gruppe geht dabei verloren.").
UPDATE [dbo].[fis_usergroups_members]
SET [UserDeleted] = @authaccount
,[DateDeleted] = @utcnow
WHERE
[usergroup_id] = @usergroup_id
AND [DateDeleted] is null;
END
SELECT @deleted;
END