Advertisement
DataCCIW

cust_cciw_sp_setTagPermissions

May 31st, 2019
407
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
T-SQL 2.01 KB | None | 0 0
  1. /***
  2.  
  3. Original Author: nairdo
  4. Per: http://community.shelbysystems.com/arena/m/arena_shared_files_modules/2679
  5. Modifed By: Tony Visconti
  6. 5/31/19 - added @organization_id to input and script
  7.  
  8. Remove existing permissions on all child entities
  9. Add permissions from parent entity
  10. Set the @parent variable below to the profile_id of the parent entity
  11.  
  12. ***/
  13.  
  14. CREATE PROC [dbo].[cust_cciw_sp_setTagPermissions]
  15. @parent INT, @organization_id INT
  16.  
  17. AS
  18.  
  19. DECLARE @profile INT;
  20.  
  21. DECLARE ProfileCursor CURSOR READ_ONLY FOR
  22. WITH profiletree (
  23.                   [Root]
  24.                 , [Parent]
  25.                 , [Name]
  26.                 , [Level]
  27.                 , [ID]
  28.                 , [Branch])  AS
  29. (SELECT
  30.     profiles.profile_name AS [Root]
  31.   , CONVERT(VARCHAR(100),'') AS [Parent]
  32.   , profiles.profile_name AS [Name]
  33.   , CONVERT(INT,'0') AS [Level]
  34.   , profiles.profile_id AS [ID]
  35.   , CONVERT(VARCHAR,profiles.profile_id) AS [Branch]
  36.  FROM
  37.     dbo.core_profile AS profiles
  38.  WHERE
  39.     profiles.parent_profile_id = @parent
  40. UNION ALL
  41.  SELECT
  42.     tree.[Root]
  43.   , tree.Name AS [Parent]
  44.   , profiles.profile_name AS [Name]
  45.   , tree.[Level] + 1
  46.   , profiles.profile_id
  47.   , CONVERT(VARCHAR, tree.[Branch] + '.' + CONVERT(VARCHAR,profiles.profile_id))
  48.  FROM
  49.     dbo.core_profile AS profiles
  50.     INNER JOIN profiletree AS tree
  51.         ON profiles.parent_profile_id =  tree.[id])
  52. SELECT id FROM profiletree;
  53.  
  54. OPEN ProfileCursor
  55.  
  56. FETCH NEXT FROM ProfileCursor
  57. INTO @profile
  58.  
  59. WHILE (@@FETCH_STATUS <> -1)
  60. BEGIN
  61.  
  62.     IF (@@FETCH_STATUS = 0)
  63.     BEGIN
  64.  
  65. DELETE FROM dbo.secu_permission
  66. WHERE object_type=3 AND object_key =@profile
  67.  
  68. INSERT INTO dbo.secu_permission (created_by, modified_by, object_type, object_key, operation_type, subject_type, subject_key,organization_id)
  69. SELECT 'AS-IP', 'AS-IP',object_type, @profile, operation_type, subject_type, subject_key, @organization_id
  70. FROM dbo.secu_permission
  71. WHERE object_type=3 and organization_id = @organization_id
  72. AND object_key =@parent
  73.  
  74.     END
  75.  
  76.     FETCH NEXT FROM ProfileCursor
  77.     INTO @profile
  78.  
  79. END
  80.  
  81. CLOSE ProfileCursor
  82. DEALLOCATE ProfileCursor
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement