/// <summary>Creates the custom permissions for the module. Expected to be called once from <see cref="FeaturesController.UpgradeModule"/></summary> /// <remarks>based on <see href="http://www.codeproject.com/KB/aspnet/dnn_custom_permissions.aspx"/> </remarks> /// <returns>A status message for <see cref="IUpgradeable.UpgradeModule"/></returns> public static string CreateCustomPermissions() { var permissionController = new PermissionController(); var existingPermissions = permissionController.GetPermissionByCodeAndKey(EngageEventsCustomPermissionsCode, ManageEventsCustomPermissionKey); if (existingPermissions != null && existingPermissions.Cast <PermissionInfo>().Any()) { return("Engage: Events custom permissions were already created (presumably by DNN 5 manifest), no upgrade action taken"); } var eventsDesktopModules = new DesktopModuleController().GetDesktopModuleByModuleName(Utility.DesktopModuleName); var moduleDefinition = new ModuleDefinitionController().GetModuleDefinitionByName( eventsDesktopModules.DesktopModuleID, Utility.ModuleDefinitionFriendlyName); permissionController.AddPermission(new PermissionInfo { PermissionCode = EngageEventsCustomPermissionsCode, PermissionKey = ManageEventsCustomPermissionKey, PermissionName = "Manage Events", ModuleDefID = moduleDefinition.ModuleDefID }); permissionController.AddPermission(new PermissionInfo { PermissionCode = EngageEventsCustomPermissionsCode, PermissionKey = ManageCategoriesCustomPermissionKey, PermissionName = "Manage Categories", ModuleDefID = moduleDefinition.ModuleDefID }); permissionController.AddPermission(new PermissionInfo { PermissionCode = EngageEventsCustomPermissionsCode, PermissionKey = ManageDisplayCustomPermissionKey, PermissionName = "Manage Display", ModuleDefID = moduleDefinition.ModuleDefID }); permissionController.AddPermission(new PermissionInfo { PermissionCode = EngageEventsCustomPermissionsCode, PermissionKey = ViewResponsesCustomPermissionKey, PermissionName = "View Responses", ModuleDefID = moduleDefinition.ModuleDefID }); return("Created custom permissions for category management in Engage: Events"); }
/// ----------------------------------------------------------------------------- /// <summary> /// SaveModuleDefinition saves the Module Definition to the database /// </summary> /// <param name="moduleDefinition">The Module Definition to save</param> /// <param name="saveChildren">A flag that determines whether the child objects are also saved</param> /// <param name="clearCache">A flag that determines whether to clear the host cache</param> /// <history> /// [cnurse] 01/14/2008 Created /// </history> /// ----------------------------------------------------------------------------- public static int SaveModuleDefinition(ModuleDefinitionInfo moduleDefinition, bool saveChildren, bool clearCache) { int moduleDefinitionID = moduleDefinition.ModuleDefID; if (moduleDefinitionID == Null.NullInteger) { //Add new Module Definition moduleDefinitionID = dataProvider.AddModuleDefinition(moduleDefinition.DesktopModuleID, moduleDefinition.FriendlyName, moduleDefinition.DefinitionName, moduleDefinition.DefaultCacheTime, UserController.GetCurrentUserInfo().UserID); } else { //Upgrade Module Definition dataProvider.UpdateModuleDefinition(moduleDefinition.ModuleDefID, moduleDefinition.FriendlyName, moduleDefinition.DefinitionName, moduleDefinition.DefaultCacheTime, UserController.GetCurrentUserInfo().UserID); } if (saveChildren) { foreach (KeyValuePair <string, PermissionInfo> kvp in moduleDefinition.Permissions) { kvp.Value.ModuleDefID = moduleDefinitionID; //check if permission exists var permissionController = new PermissionController(); ArrayList permissions = permissionController.GetPermissionByCodeAndKey(kvp.Value.PermissionCode, kvp.Value.PermissionKey); if (permissions != null && permissions.Count == 1) { var permission = (PermissionInfo)permissions[0]; kvp.Value.PermissionID = permission.PermissionID; permissionController.UpdatePermission(kvp.Value); } else { permissionController.AddPermission(kvp.Value); } } foreach (KeyValuePair <string, ModuleControlInfo> kvp in moduleDefinition.ModuleControls) { kvp.Value.ModuleDefID = moduleDefinitionID; //check if definition exists ModuleControlInfo moduleControl = ModuleControlController.GetModuleControlByControlKey(kvp.Value.ControlKey, kvp.Value.ModuleDefID); if (moduleControl != null) { kvp.Value.ModuleControlID = moduleControl.ModuleControlID; } ModuleControlController.SaveModuleControl(kvp.Value, clearCache); } } if (clearCache) { DataCache.ClearHostCache(true); } return(moduleDefinitionID); }
public static void InitTabPermissions() { PermissionController permCtl = new PermissionController(); #region Permissions Already Exists? bool pREVIEWCONTENT_Exists = false; foreach (Data.Entities.WorkflowPermissionInfo p in Managers.WorkflowManager.GetPermissionByCode(PERMISSION_CODE)) { if ((p.PermissionKey == PERMISSION_REVIEWCONTENT)) { pREVIEWCONTENT_Exists = true; } } #endregion #region Add Permissions try { if (!pREVIEWCONTENT_Exists) { PermissionInfo pi = new PermissionInfo { ModuleDefID = -1, PermissionCode = PERMISSION_CODE, PermissionKey = PERMISSION_REVIEWCONTENT, PermissionName = PERMISSION_REVIEWCONTENT }; permCtl.AddPermission(pi); } } catch { } #endregion }
public static int SaveModuleDefinition(ModuleDefinitionInfo moduleDefinition, bool saveChildren, bool clearCache) { int moduleDefinitionID = moduleDefinition.ModuleDefID; if (moduleDefinitionID == Null.NullInteger) { moduleDefinitionID = dataProvider.AddModuleDefinition(moduleDefinition.DesktopModuleID, moduleDefinition.FriendlyName, moduleDefinition.DefaultCacheTime, UserController.GetCurrentUserInfo().UserID); } else { dataProvider.UpdateModuleDefinition(moduleDefinition.ModuleDefID, moduleDefinition.FriendlyName, moduleDefinition.DefaultCacheTime, UserController.GetCurrentUserInfo().UserID); } if (saveChildren) { foreach (KeyValuePair<string, PermissionInfo> kvp in moduleDefinition.Permissions) { kvp.Value.ModuleDefID = moduleDefinitionID; PermissionController permissionController = new PermissionController(); ArrayList permissions = permissionController.GetPermissionByCodeAndKey(kvp.Value.PermissionCode, kvp.Value.PermissionKey); if (permissions != null && permissions.Count == 1) { PermissionInfo permission = (PermissionInfo)permissions[0]; kvp.Value.PermissionID = permission.PermissionID; permissionController.UpdatePermission(kvp.Value); } else { permissionController.AddPermission(kvp.Value); } } foreach (KeyValuePair<string, ModuleControlInfo> kvp in moduleDefinition.ModuleControls) { kvp.Value.ModuleDefID = moduleDefinitionID; ModuleControlInfo moduleControl = ModuleControlController.GetModuleControlByControlKey(kvp.Value.ControlKey, kvp.Value.ModuleDefID); if (moduleControl != null) { kvp.Value.ModuleControlID = moduleControl.ModuleControlID; } ModuleControlController.SaveModuleControl(kvp.Value, clearCache); } } if (clearCache) { DataCache.ClearHostCache(true); } return moduleDefinitionID; }