Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resource Manager Standardization & Improvement #3734

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 20 additions & 16 deletions DNN Platform/Modules/ResourceManager/Components/Common/Utils.cs
Original file line number Diff line number Diff line change
@@ -1,39 +1,43 @@
using System;
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information

using System;
using System.ComponentModel;
using System.Reflection;
using DotNetNuke.Services.FileSystem;

namespace Dnn.Modules.ResourceManager.Components.Common
{
public class Utils
{
public static string GetEnumDescription(Enum clickBehaviour)
/// <summary>
/// Obtains a human friendly description from an enum value using the
/// <see cref="System.ComponentModel.DescriptionAttribute" /> attribute to get a proper name
/// </summary>
/// <param name="enumValue">The enum value to lookup</param>
/// <returns>The specified description attribute name or the value of the enum as a string</returns>
public static string GetEnumDescription(Enum enumValue)
{
FieldInfo fi = clickBehaviour.GetType().GetField(clickBehaviour.ToString());
DescriptionAttribute[] attributes = (DescriptionAttribute[])fi.GetCustomAttributes(typeof(DescriptionAttribute), false);

return attributes[0].Description;
var fi = enumValue.GetType().GetField(enumValue.ToString());
var descriptionAttributes =
(DescriptionAttribute[]) fi.GetCustomAttributes(typeof(DescriptionAttribute), false);
if (descriptionAttributes.Length > 0)
return descriptionAttributes[0].Description;
return enumValue.ToString();
}

public static int GetFolderGroupId(int folderId)
{
var folder = FolderManager.Instance.GetFolder(folderId);
var folderPath = folder.DisplayPath;

if (!folderPath.StartsWith(Constants.GroupFolderPathStart))
{
return -1;
}
if (!folderPath.StartsWith(Constants.GroupFolderPathStart)) return -1;

var prefixLength = Constants.GroupFolderPathStart.Length;
var folderGroupIdString = folderPath.Substring(prefixLength);
folderGroupIdString = folderGroupIdString.Substring(0, folderGroupIdString.IndexOf("/"));

int folderGroupId;
if (!int.TryParse(folderGroupIdString, out folderGroupId))
{
return -1;
}
if (!int.TryParse(folderGroupIdString, out var folderGroupId)) return -1;
return folderGroupId;
}
}
Expand Down
17 changes: 4 additions & 13 deletions DNN Platform/Modules/ResourceManager/Components/Constants.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,6 @@
/*
' Copyright (c) 2017 DNN Software, Inc.
' All rights reserved.
'
' THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
' TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
' THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
' CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
' DEALINGS IN THE SOFTWARE.
'
*/
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information

using System;
using System.ComponentModel;
Expand Down Expand Up @@ -43,7 +35,6 @@ internal class Constants
#region Localization

internal const string LocalizationDataCacheKey = "LocalizationLocTable:{0}:{1}";
internal const string LocalizationDataModifiedDateCacheKey = "LocalizationDataModifiedDate:{0}";

public const string GroupIconCantBeDeletedKey = "GroupIconCantBeDeleted.Error";
public const string UserHasNoPermissionToDownloadKey = "UserHasNoPermissionToDownload.Error";
Expand All @@ -55,12 +46,12 @@ internal class Constants

#region Module settings

public const string AddFileContentType = "File";
public const string HomeFolderSettingName = "RM_HomeFolder";
public const string ModeSettingName = "RM_Mode";

public const int ItemsPerPage = 20;
public const int ItemWidth = 176;

public enum ModuleModes
{
[Description("Normal")]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
using System;
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information

using System;
using DotNetNuke.Common;
using DotNetNuke.Framework;
using DotNetNuke.Services.FileSystem;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
using DotNetNuke.Services.FileSystem;
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information

using DotNetNuke.Services.FileSystem;

namespace Dnn.Modules.ResourceManager.Components
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
using System.IO;
using DotNetNuke.Entities.Modules;
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information

using System.IO;
using DotNetNuke.Services.Assets;
using DotNetNuke.Services.FileSystem;
using Dnn.Modules.ResourceManager.Services.Dto;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
#region Copyright
// DotNetNuke® - http://www.dotnetnuke.com
// Copyright (c) 2002-2018
// by DotNetNuke Corporation
// All Rights Reserved
#endregion
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information

using System;
using System.Collections.Generic;
using Dnn.Modules.ResourceManager.Components.Models;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@

// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information

namespace Dnn.Modules.ResourceManager.Components
{
/// <summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
#region Copyright
// DotNetNuke® - http://www.dotnetnuke.com
// Copyright (c) 2002-2018
// by DotNetNuke Corporation
// All Rights Reserved
#endregion
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information

using System;
using System.Collections.Generic;
using DotNetNuke.Services.FileSystem;
using DotNetNuke.Services.Search.Entities;

namespace Dnn.Modules.ResourceManager.Components
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
using System.Drawing;
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information

using System.Drawing;
using DotNetNuke.Services.FileSystem;
using Dnn.Modules.ResourceManager.Components.Models;

Expand Down
45 changes: 7 additions & 38 deletions DNN Platform/Modules/ResourceManager/Components/ItemsManager.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
using System;
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using DotNetNuke.Entities;
using DotNetNuke.Entities.Content;
using DotNetNuke.Entities.Modules;
using DotNetNuke.Entities.Portals;
using DotNetNuke.Entities.Users;
using DotNetNuke.Framework;
Expand All @@ -22,18 +25,13 @@ namespace Dnn.Modules.ResourceManager.Components
{
public class ItemsManager : ServiceLocator<IItemsManager, ItemsManager>, IItemsManager
{
#region Members

private const int MaxDescriptionLength = 500;
private readonly IContentController _contentController;
private readonly IRoleController _roleController;
private readonly IFileManager _fileManager;
private readonly IAssetManager _assetManager;
private readonly IPermissionsManager _permissionsManager;

#endregion

#region Constructors

public ItemsManager()
{
Expand All @@ -44,8 +42,6 @@ public ItemsManager()
_permissionsManager = PermissionsManager.Instance;
}

#endregion

public ContentPage GetFolderContent(int folderId, int startIndex, int numItems, string sorting, int moduleMode)
{
var noPermissionMessage = Localization.GetExceptionMessage("UserHasNoPermissionToBrowseFolder",
Expand Down Expand Up @@ -128,17 +124,13 @@ public void SaveFileDetails(IFileInfo file, FileDetailsRequest fileDetails)
public void SaveFolderDetails(IFolderInfo folder, FolderDetailsRequest folderDetails)
{
_assetManager.RenameFolder(folderDetails.FolderId, folderDetails.FolderName);

var currentUserInfo = UserController.Instance.GetCurrentUserInfo();
}

public void DeleteFile(int fileId, int moduleMode, int groupId)
{
var file = FileManager.Instance.GetFile(fileId);
if (file == null)
{
throw new NotFoundException("File doesn't exist.");
}
return;

if (moduleMode == (int) Constants.ModuleModes.Group && IsGroupIcon(file))
{
Expand All @@ -157,9 +149,7 @@ public void DeleteFolder(int folderId, bool unlinkAllowedStatus, int moduleMode)
{
var folder = FolderManager.Instance.GetFolder(folderId);
if (folder == null)
{
throw new NotFoundException("Folder doesn't exist.");
}
return;

if (!_permissionsManager.HasDeletePermission(moduleMode, folderId))
{
Expand All @@ -185,27 +175,6 @@ private bool IsGroupIcon(IFileInfo file)
return role?.IconFile?.Substring(7) == file.FileId.ToString();
}

private ContentItem CreateFileContentItem(string contentType)
{
var typeController = new ContentTypeController();
var contentTypeFile = (from t in typeController.GetContentTypes() where t.ContentType == contentType select t).SingleOrDefault();

if (contentTypeFile == null)
{
contentTypeFile = new ContentType { ContentType = contentType };
contentTypeFile.ContentTypeId = typeController.AddContentType(contentTypeFile);
}

var objContent = new ContentItem
{
ContentTypeId = contentTypeFile.ContentTypeId,
Indexed = false,
};

objContent.ContentItemId = _contentController.AddContentItem(objContent);
return objContent;
}

#endregion

#region Service Locator
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
#region Copyright
// DotNetNuke® - http://www.dotnetnuke.com
// Copyright (c) 2002-2018
// by DotNetNuke Corporation
// All Rights Reserved
#endregion
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information

using System;
using System.Collections.Generic;
Expand All @@ -12,7 +9,6 @@
using System.Threading;
using System.Web.Caching;
using System.Xml;
using DotNetNuke.Application;
using DotNetNuke.Common;
using DotNetNuke.Common.Utilities;
using DotNetNuke.Framework;
Expand All @@ -23,14 +19,16 @@ namespace Dnn.Modules.ResourceManager.Components
{
public class LocalizationController : ServiceLocator<ILocalizationController, LocalizationController>, ILocalizationController
{
#region Overrides of ServiceLocator

/// <summary>
/// Provides a method to override Service Locator's GetFactory method
/// </summary>
/// <returns></returns>
protected override Func<ILocalizationController> GetFactory()
{
return () => new LocalizationControllerImpl();
}

#endregion

public string CultureName => Instance.CultureName;

Expand All @@ -48,8 +46,8 @@ public long GetResxTimeStamp(string resourceFile, Localization localization)

class LocalizationControllerImpl : ILocalizationController
{
public static readonly TimeSpan FiveMinutes = TimeSpan.FromMinutes(5);
public static readonly TimeSpan OneHour = TimeSpan.FromHours(1);
private static readonly TimeSpan FiveMinutes = TimeSpan.FromMinutes(5);
private static readonly TimeSpan OneHour = TimeSpan.FromHours(1);

public string CultureName
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
#region Copyright
// DotNetNuke® - http://www.dotnetnuke.com
// Copyright (c) 2002-2018
// by DotNetNuke Corporation
// All Rights Reserved
#endregion

// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information

namespace Dnn.Modules.ResourceManager.Components.Models
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
using System.Net.Http;
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information

using System.Net.Http;

namespace Dnn.Modules.ResourceManager.Components.Models
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
using System;
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information

using System;
using DotNetNuke.Entities.Portals;
using DotNetNuke.Entities.Users;
using DotNetNuke.Framework;
Expand All @@ -11,24 +15,18 @@ namespace Dnn.Modules.ResourceManager.Components
{
public class PermissionsManager : ServiceLocator<IPermissionsManager, PermissionsManager>, IPermissionsManager
{
#region Private Members

private readonly IFolderManager _folderManager;
private readonly IRoleController _roleController;
private readonly IUserController _userController;

#endregion

#region Constructors

public PermissionsManager()
{
_folderManager = FolderManager.Instance;
_roleController = RoleController.Instance;
_userController = UserController.Instance;
}

#endregion

public bool HasFolderContentPermission(int folderId, int moduleMode)
{
Expand Down
Loading