private PermissionsDto GetPermissionsData(int portalId, int desktopModuleId) { var permissions = new PermissionsDto(true); if (desktopModuleId > 0) { var portalModule = DesktopModuleController.GetPortalDesktopModule(portalId, desktopModuleId); if (portalModule != null) { permissions.DesktopModuleId = desktopModuleId; var modulePermissions = DesktopModulePermissionController.GetDesktopModulePermissions(portalModule.PortalDesktopModuleID); foreach (DesktopModulePermissionInfo permission in modulePermissions) { if (permission.UserID != Null.NullInteger) { permissions.AddUserPermission(permission); } else { permissions.AddRolePermission(permission); } } permissions.RolePermissions = permissions.RolePermissions.OrderByDescending(p => p.Locked) .ThenByDescending(p => p.IsDefault) .ThenBy(p => p.RoleName) .ToList(); permissions.UserPermissions = permissions.UserPermissions.OrderBy(p => p.DisplayName).ToList(); } } return(permissions); }
private void BindPermissions() { PortalDesktopModuleInfo portalModule = DesktopModuleController.GetPortalDesktopModule(ModuleContext.PortalSettings.PortalId, DesktopModule.DesktopModuleID); if (portalModule != null) { dgPermissions.PortalDesktopModuleID = portalModule.PortalDesktopModuleID; bool isVisible = DesktopModulePermissionController.HasDesktopModulePermission(DesktopModulePermissionController.GetDesktopModulePermissions(portalModule.PortalDesktopModuleID), "DEPLOY") || ModuleContext.PortalSettings.UserInfo.IsInRole(ModuleContext.PortalSettings.AdministratorRoleName) || ModuleContext.PortalSettings.UserInfo.IsSuperUser; pnlPermissions.Visible = isVisible; if (!isVisible) { lblHelp.Text = Localization.GetString("NoPermission", LocalResourceFile); } } }
private void UpdatePermissions(DesktopModuleInfo desktopModule, PackageSettingsDto packageSettings) { if (!packageSettings.EditorActions.ContainsKey("permissions") || string.IsNullOrEmpty(packageSettings.EditorActions["permissions"])) { return; } var portalModule = DesktopModuleController.GetPortalDesktopModule(packageSettings.PortalId, desktopModule.DesktopModuleID); if (portalModule == null) { return; } var portalSettings = new PortalSettings(packageSettings.PortalId); var permissions = JsonConvert.DeserializeObject <PermissionsDto>(packageSettings.EditorActions["permissions"]); var hasAdmin = permissions.RolePermissions == null ? false : permissions.RolePermissions.Any(permission => permission.RoleId == portalSettings.AdministratorRoleId); var desktopModulePermissions = new DesktopModulePermissionCollection(); //add default permissions for administrators if (!hasAdmin || (permissions.RolePermissions.Count == 0 && permissions.UserPermissions.Count == 0)) { //add default permissions var permissionController = new PermissionController(); var permissionsList = permissionController.GetPermissionByCodeAndKey("SYSTEM_DESKTOPMODULE", "DEPLOY"); foreach (PermissionInfo permissionInfo in permissionsList) { var permission = new DesktopModulePermissionInfo(permissionInfo) { RoleID = portalSettings.AdministratorRoleId, UserID = Null.NullInteger, PortalDesktopModuleID = portalModule.PortalDesktopModuleID, AllowAccess = true, RoleName = portalSettings.AdministratorRoleName }; desktopModulePermissions.Add(permission); } } //add role permissions if (permissions.RolePermissions != null) { foreach (var rolePermission in permissions.RolePermissions) { foreach (var permission in rolePermission.Permissions) { desktopModulePermissions.Add(new DesktopModulePermissionInfo() { PermissionID = permission.PermissionId, RoleID = rolePermission.RoleId, UserID = Null.NullInteger, PortalDesktopModuleID = portalModule.PortalDesktopModuleID, AllowAccess = permission.AllowAccess }); } } } //add user permissions if (permissions.UserPermissions != null) { foreach (var userPermission in permissions.UserPermissions) { foreach (var permission in userPermission.Permissions) { int roleId; int.TryParse(Globals.glbRoleNothing, out roleId); desktopModulePermissions.Add(new DesktopModulePermissionInfo() { PermissionID = permission.PermissionId, RoleID = roleId, UserID = userPermission.UserId, PortalDesktopModuleID = portalModule.PortalDesktopModuleID, AllowAccess = permission.AllowAccess }); } } } //Update DesktopModule Permissions var currentPermissions = DesktopModulePermissionController.GetDesktopModulePermissions(portalModule.PortalDesktopModuleID); if (!currentPermissions.CompareTo(desktopModulePermissions)) { DesktopModulePermissionController.DeleteDesktopModulePermissionsByPortalDesktopModuleID(portalModule.PortalDesktopModuleID); foreach (DesktopModulePermissionInfo objPermission in desktopModulePermissions) { DesktopModulePermissionController.AddDesktopModulePermission(objPermission); } } DataCache.RemoveCache(string.Format(DataCache.PortalDesktopModuleCacheKey, portalSettings.PortalId)); }