AlanTsai
1/14/2016 - 8:51 PM

Umbraco Department package - Duplicate same department node permission to another department. #umbraco #sql

Umbraco Department package - Duplicate same department node permission to another department. #umbraco #sql

目的

這個sql主要目的是把某個單位所開啟的節點權限全部copy到另外一個單位,來達到快速開啟 單位節點權限。

舉例來說,如果我把單位A的瀏覽權限全部開好。單位B的權限可能和單位A一樣,這個時候就可以用這個sql 來快速把單位A的節點權限都開個單位B

DECLARE @fromDepartmentId int;
DECLARE @toDepartmentId int;

SET @fromDepartmentId = $fromDepartmentId; -- set 來源copy的單位 - 以我們例子就是單位A
SET @toDepartmentId = $departmentId; -- set 要被copy的單位 - 以我們例子就是單位B

INSERT INTO Department2NodePermission (DepartmentId, NodeId, Permission)
	SELECT
		@toDepartmentId,
		[NodeId],
		[Permission]
	FROM [Department2NodePermission]
	WHERE DepartmentId = @fromDepartmentId