///----------------------------------------------------------------------------- /// <summary> /// Determines if user has the necessary permissions to access an item with the /// designated AccessLevel. /// </summary> /// <param name="accessLevel">The SecurityAccessLevel required to access a portal module or module action.</param> /// <param name="permissionKey">If Security Access is Edit the permissionKey is the actual "edit" permisison required.</param> /// <param name="moduleConfiguration">The ModuleInfo object for the associated module.</param> /// <returns>A boolean value indicating if the user has the necessary permissions</returns> /// <remarks>Every module control and module action has an associated permission level. This /// function determines whether the user represented by UserName has sufficient permissions, as /// determined by the PortalSettings and ModuleSettings, to access a resource with the /// designated AccessLevel.</remarks> ///----------------------------------------------------------------------------- public static bool HasModuleAccess(SecurityAccessLevel accessLevel, string permissionKey, ModuleInfo moduleConfiguration) { bool isAuthorized = false; UserInfo userInfo = UserController.GetCurrentUserInfo(); if (userInfo != null && userInfo.IsSuperUser) { isAuthorized = true; } else { switch (accessLevel) { case SecurityAccessLevel.Anonymous: isAuthorized = true; break; case SecurityAccessLevel.View: if (CanViewModule(moduleConfiguration)) { isAuthorized = true; } break; case SecurityAccessLevel.Edit: if (TabPermissionController.CanAddContentToPage()) { isAuthorized = true; } else { if (string.IsNullOrEmpty(permissionKey)) { permissionKey = "CONTENT,DELETE,EDIT,EXPORT,IMPORT,MANAGE"; } if (moduleConfiguration != null && CanViewModule(moduleConfiguration) && (HasModulePermission(moduleConfiguration.ModulePermissions, permissionKey) || HasModulePermission(moduleConfiguration.ModulePermissions, "EDIT"))) { isAuthorized = true; } } break; case SecurityAccessLevel.Admin: isAuthorized = TabPermissionController.CanAddContentToPage(); break; case SecurityAccessLevel.Host: break; } } return(isAuthorized); }
private static bool CanAddContentToPage(ModuleInfo objModule) { TabInfo objTab = new TabController().GetTab(objModule.TabID, objModule.PortalID, false); return(TabPermissionController.CanAddContentToPage(objTab)); }
///----------------------------------------------------------------------------- /// <summary> /// Determines if user has the necessary permissions to access an item with the /// designated AccessLevel. /// </summary> /// <param name="accessLevel">The SecurityAccessLevel required to access a portal module or module action.</param> /// <param name="permissionKey">If Security Access is Edit the permissionKey is the actual "edit" permisison required.</param> /// <param name="moduleConfiguration">The ModuleInfo object for the associated module.</param> /// <returns>A boolean value indicating if the user has the necessary permissions</returns> /// <remarks>Every module control and module action has an associated permission level. This /// function determines whether the user represented by UserName has sufficient permissions, as /// determined by the PortalSettings and ModuleSettings, to access a resource with the /// designated AccessLevel.</remarks> ///----------------------------------------------------------------------------- public virtual bool HasModuleAccess(SecurityAccessLevel accessLevel, string permissionKey, ModuleInfo moduleConfiguration) { bool isAuthorized = false; UserInfo userInfo = UserController.Instance.GetCurrentUserInfo(); TabInfo tab = TabController.Instance.GetTab(moduleConfiguration.TabID, moduleConfiguration.PortalID, false); if (userInfo != null && userInfo.IsSuperUser) { isAuthorized = true; } else { switch (accessLevel) { case SecurityAccessLevel.Anonymous: isAuthorized = true; break; case SecurityAccessLevel.View: if (ModulePermissionController.CanViewModule(moduleConfiguration)) { isAuthorized = true; } break; case SecurityAccessLevel.ViewPermissions: isAuthorized = TabPermissionController.CanAddContentToPage(tab); break; case SecurityAccessLevel.Edit: if (!((moduleConfiguration.IsShared && moduleConfiguration.IsShareableViewOnly) && TabPermissionController.CanAddContentToPage(tab))) { if (string.IsNullOrEmpty(permissionKey)) { permissionKey = "CONTENT,DELETE,EXPORT,IMPORT,MANAGE"; } if (TabPermissionController.CanAddContentToPage()) { //Need to check for Deny Edit at the Module Level if (permissionKey == "CONTENT") { isAuthorized = !IsDeniedModulePermission(moduleConfiguration, permissionKey); } else { isAuthorized = true; } } else { // Need to check if it was denied at Tab level if (IsDeniedTabPermission(tab, "CONTENT,EDIT")) { isAuthorized = false; } else { isAuthorized = HasModulePermission(moduleConfiguration, permissionKey); } } } break; case SecurityAccessLevel.Admin: if (!((moduleConfiguration.IsShared && moduleConfiguration.IsShareableViewOnly) && TabPermissionController.CanAddContentToPage(tab))) { isAuthorized = TabPermissionController.CanAddContentToPage(tab); } break; case SecurityAccessLevel.Host: break; } } return(isAuthorized); }