40FINGERS DNN Nederlands40FINGERS DNN English

Our Blog

Menu: Blog

Change Translator permissions from EDIT to VIEW

By: Stefan Kamphuis

Recently, one of our clients requested that a user would be able to review the translation of pages for a not yet published language on a website. And of course I needed that wihout hours of work for configuration.

The first solution I thought about, was to publish te pages (because otherwise users can't see the pages at all) and set the permissions to all pages in that language to be only viewable by administrators and a new role for this translation-verifier.

As this seemed a bit too much of a hassle, I figured that the client didn't need a translator that could edit. So if I could change the translator to only have VIEW permissions, that would be the quicker solution. After all, DNN already allows Translators to be able to work with unpublished pages.

To get this done, I wrote a little SQL script that changes the permissions of a Translator role for a specific language, from EDIT to VIEW, for both modules and tabs. If you have the same use case, this script might help you out quickly.

Good luck!

BEGIN TRAN
 
DECLARE @portalid INT
DECLARE @cult nvarchar(5)
 
/* TODO BEFORE RUNNING
       CHANGE PortalID AND CULTURE CODE
*/
 
SET @portalid = 10
SET @cult = 'pt-PT'
 
DECLARE @roleid INT
DECLARE @permModuleEdit INT
DECLARE @permModuleView INT
DECLARE @permTabEdit INT
DECLARE @permTabView INT
 
 
SELECT @roleid = RoleId FROM Roles WHERE PortalID = @portalid AND RoleName = REPLACE('Translator (x)', 'x', @cult)
 
SELECT @permModuleEdit = PermissionID FROM Permission WHERE PermissionCode = 'SYSTEM_MODULE_DEFINITION' AND PermissionKey = 'EDIT'
SELECT @permModuleView = PermissionID FROM Permission WHERE PermissionCode = 'SYSTEM_MODULE_DEFINITION' AND PermissionKey = 'VIEW'
SELECT @permTabEdit = PermissionID FROM Permission WHERE PermissionCode = 'SYSTEM_TAB' AND PermissionKey = 'EDIT'
SELECT @permTabView = PermissionID FROM Permission WHERE PermissionCode = 'SYSTEM_TAB' AND PermissionKey = 'VIEW'
 
SELECT
       @permModuleEdit as ModuleEditPermissionId,
       @permModuleView as ModuleViewPermissionId,
       @permTabEdit as TabEditPermissionId,
       @permTabView as TabViewPermissionId
 
IF @permModuleEdit > 0 AND @permModuleView > 0 AND @permTabEdit > 0 AND @permTabView > 0
BEGIN
       SELECT * FROM TabPermission WHERE RoleID = @roleid
       SELECT  *  FROM ModulePermission WHERE RoleID = @roleid
 
       -- REMOVE EDIT WHERE VIEW ALREADY EXISTS (will not be the case in default scenario)
       DELETE FROM TabPermission WHERE RoleID = @roleid AND PermissionID = @permTabEdit AND TabId IN (SELECT T.TabID FROM TabPermission T WHERE T.TabID = TabId AND T.RoleID = @roleid AND T.PermissionID = @permTabView)
       DELETE FROM ModulePermission WHERE RoleID = @roleid AND PermissionID = @permModuleEdit AND ModuleID IN (SELECT M.ModuleID FROM ModulePermission M WHERE M.ModuleID = ModuleID AND M.RoleID = @roleid AND M.PermissionID = @permModuleView)
       -- CHANGE EDIT TO VIEW
       UPDATE TabPermission SET PermissionID = @permTabView WHERE RoleID = @roleid AND PermissionID = @permTabEdit
       UPDATE ModulePermission SET PermissionID = @permModuleView WHERE RoleID = @roleid AND PermissionID = @permModuleEdit
 
       SELECT * FROM TabPermission WHERE RoleID = @roleid
       SELECT  *  FROM ModulePermission WHERE RoleID = @roleid
END
 
ROLLBACK