USP_PROXYUSER_MARKINACTIVE_REVOKEPERSONALACCESSTOKEN

Parameters

Parameter Parameter Type Mode Description
@ID uniqueidentifier IN
@CHANGEAGENTID uniqueidentifier IN
@CURRENTDATE datetime IN
@DETAILS nvarchar(300) IN

Definition

Copy


            create procedure dbo.USP_PROXYUSER_MARKINACTIVE_REVOKEPERSONALACCESSTOKEN
            (
                @ID uniqueidentifier,
                @CHANGEAGENTID uniqueidentifier = null,
                @CURRENTDATE datetime,
                @DETAILS nvarchar(300)
            )
            as
                set nocount on;

                if @CHANGEAGENTID is null  
                    exec dbo.USP_CHANGEAGENT_GETORCREATECHANGEAGENT @CHANGEAGENTID output;

                begin
                    --insert/update PAT revoked reason

                    --Reserve ID for default reason User is inactive.

                    --Default reason will inserted via revision file.

                    --Default reason will be linked with mapping table so that user cannot delete default reason from code table

                    --Admin can change the text of default reason from Admin/code tables to manage the localization.


                    declare @TEMPUPDATEDPATTABLE table ( ID uniqueidentifier );
                    declare @DEFAULTREVOKECODEID uniqueidentifier = 'B2DBE01F-D1C6-4645-A546-A7365AE53458';

                    --inserting ID of updated token into temp table

                    --we will have max two active token for a user, it means we will get only two entries in the temp table

                    --we are updating only active tokens


                    update dbo.PERSONALACCESSTOKEN set
                            ENABLED = 0,
                            CHANGEDBYID = @CHANGEAGENTID,
                            DATECHANGED = @CURRENTDATE
                            OUTPUT INSERTED.ID
                            INTO @TEMPUPDATEDPATTABLE
                    where 
                            PROXYUSERID = @ID and ENABLED <> 0;

                    if exists(select count(1) from @TEMPUPDATEDPATTABLE)
                        begin
                            -- insert new entry in the detail table 


                            insert into dbo.PERSONALACCESSTOKENREVOKEDETAIL (ID, PERSONALACCESSTOKENREVOKECODEID, DETAILS, ADDEDBYID, CHANGEDBYID, DATEADDED, DATECHANGED)
                            select TEMPUPDATEDPATTABLE.ID, @DEFAULTREVOKECODEID, @DETAILS, @CHANGEAGENTID, @CHANGEAGENTID, @CURRENTDATE, @CURRENTDATE
                            from @TEMPUPDATEDPATTABLE TEMPUPDATEDPATTABLE
                            left join PERSONALACCESSTOKENREVOKEDETAIL on TEMPUPDATEDPATTABLE.ID = PERSONALACCESSTOKENREVOKEDETAIL.ID
                            where PERSONALACCESSTOKENREVOKEDETAIL.ID is null;
                        end
                end