- Introduced a new module for managing user groups (`usrgrp`) in the administration interface. - Implemented CRUD operations for user groups: list, create, rename, and delete. - Added authorization checks to ensure only users with appropriate permissions can manage groups. - Created corresponding frontend JavaScript and SCSS files for the new module. - Updated documentation to reflect the new group management functionality and its authorization model. - Added SQL stored procedures for group management operations. - Established a new login script for database access, ensuring proper security practices.
109 lines
3.5 KiB
Transact-SQL
109 lines
3.5 KiB
Transact-SQL
-- =============================================
|
|
-- Author: <Author,,Name>
|
|
-- Create date: <Create Date,,>
|
|
-- Description: <Description,,>
|
|
-- =============================================
|
|
CREATE PROCEDURE [dbo].[mfr__updt__serviceobjects]
|
|
@tblname as nvarchar(50)
|
|
, @referencetable nvarchar(50)
|
|
, @tgtid bigint
|
|
AS
|
|
BEGIN
|
|
SET NOCOUNT ON;
|
|
SET XACT_ABORT ON;
|
|
|
|
BEGIN TRY
|
|
|
|
DECLARE @now datetime = GETUTCDATE();
|
|
DECLARE @tmp [dbo].[mfr__tt__serviceobjects];
|
|
|
|
DECLARE @tmp_cmd nvarchar(1000) = N'SELECT DISTINCT * FROM ' + @tblname
|
|
INSERT INTO @tmp EXECUTE [sp_executesql] @tmp_cmd;
|
|
|
|
BEGIN TRANSACTION;
|
|
|
|
IF @referencetable = 'mfr__serviceobjects'
|
|
BEGIN
|
|
DELETE p
|
|
--OUTput deleted.*, @now INTO [dbo].[mfr__d_*PartnerSet]
|
|
FROM [dbo].[mfr__*PartnerSet] as p
|
|
WHERE p.Property like 'ServiceObject[:]%' AND EXISTS (SELECT * FROM @tmp as tmp where tmp.[id] = p.[EntityId]);
|
|
DELETE cv
|
|
--OUTput deleted.*, @now INTO [dbo].[mfr__d_#customvalues]
|
|
FROM [dbo].[mfr__#customvalues] as cv
|
|
WHERE cv.Property like 'ServiceObject[:]%' AND EXISTS (SELECT * FROM @tmp as tmp where tmp.[id] = cv.[EntityId]);
|
|
DELETE lc
|
|
--OUTPUT deleted.*, @now INTO [dbo].[mfr__d_#locations]
|
|
FROM [dbo].[mfr__#locations] as lc
|
|
WHERE lc.Property like 'ServiceObject[:]%' AND EXISTS (SELECT * FROM @tmp as tmp where tmp.[id] = lc.[EntityId]);
|
|
DELETE itm
|
|
--OUTPUT deleted.*, @now INTO [dbo].[mfr__d_items]
|
|
FROM [dbo].[mfr__items] as itm
|
|
WHERE EXISTS (SELECT * FROM @tmp as tmp where tmp.[id] = itm.[ServiceObjectId] and ISNULL(itm.[ServiceRequestId],0) = 0);
|
|
END
|
|
|
|
|
|
MERGE [dbo].[mfr__serviceobjects] as TARGET
|
|
USING @tmp as SOURCE ON TARGET.[Id] = SOURCE.[Id]
|
|
WHEN MATCHED AND (TARGET.[Version] <= SOURCE.[Version] OR TARGET.[DateModified] <= SOURCE.[DateModified]) THEN
|
|
UPDATE
|
|
SET [Id] = SOURCE.[Id]
|
|
,[Location#ID] = SOURCE.[Location#ID]
|
|
,[Name] = SOURCE.[Name]
|
|
,[Note] = SOURCE.[Note]
|
|
,[CustomValues] = SOURCE.[CustomValues]
|
|
,[DateModified] = SOURCE.[DateModified]
|
|
,[ExternalId] = SOURCE.[ExternalId]
|
|
,[MappingId] = SOURCE.[MappingId]
|
|
,[QuickSearch] = SOURCE.[QuickSearch]
|
|
,[Version] = SOURCE.[Version]
|
|
,[CreateGeoLocation] = SOURCE.[CreateGeoLocation]
|
|
,[IsWarehouse] = SOURCE.[IsWarehouse]
|
|
,[ParentServiceObjectId] = SOURCE.[ParentServiceObjectId]
|
|
,[CompanyId] = SOURCE.[CompanyId]
|
|
,[ProductId] = SOURCE.[ProductId]
|
|
WHEN NOT MATCHED BY TARGET THEN
|
|
INSERT
|
|
( [Id]
|
|
,[Location#ID]
|
|
,[Name]
|
|
,[Note]
|
|
,[CustomValues]
|
|
,[DateModified]
|
|
,[ExternalId]
|
|
,[MappingId]
|
|
,[QuickSearch]
|
|
,[Version]
|
|
,[CreateGeoLocation]
|
|
,[IsWarehouse]
|
|
,[ParentServiceObjectId]
|
|
,[CompanyId]
|
|
,[ProductId])
|
|
VALUES
|
|
(SOURCE.[Id]
|
|
,SOURCE.[Location#ID]
|
|
,SOURCE.[Name]
|
|
,SOURCE.[Note]
|
|
,SOURCE.[CustomValues]
|
|
,SOURCE.[DateModified]
|
|
,SOURCE.[ExternalId]
|
|
,SOURCE.[MappingId]
|
|
,SOURCE.[QuickSearch]
|
|
,SOURCE.[Version]
|
|
,SOURCE.[CreateGeoLocation]
|
|
,SOURCE.[IsWarehouse]
|
|
,SOURCE.[ParentServiceObjectId]
|
|
,SOURCE.[CompanyId]
|
|
,SOURCE.[ProductId]);
|
|
|
|
COMMIT TRANSACTION;
|
|
END TRY
|
|
BEGIN CATCH
|
|
IF @@TRANCOUNT > 0 ROLLBACK TRANSACTION;
|
|
|
|
INSERT INTO dbo.[fds__admin_dberrors] ([UserName], [ErrorNumber], [ErrorState], [ErrorSeverity], [ErrorLine], [ErrorProcedure], [ErrorMessage], [ErrorDateTime])
|
|
VALUES (SUSER_SNAME(), ERROR_NUMBER(), ERROR_STATE(), ERROR_SEVERITY(), ERROR_LINE(), ERROR_PROCEDURE(), ERROR_MESSAGE(), GETDATE());
|
|
|
|
THROW;
|
|
END CATCH;
|
|
END |