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

DNN-7706: hide delete/save button when edit global data types. #885

Merged
merged 3 commits into from
Oct 20, 2015
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
12 changes: 11 additions & 1 deletion DNN Platform/Dnn.DynamicContent/ContentTemplate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System;
using System.Linq;
using System.Web.Caching;
using DotNetNuke.Common.Utilities;
using DotNetNuke.ComponentModel.DataAnnotations;
using DotNetNuke.Services.FileSystem;
// ReSharper disable ConvertPropertyToExpressionBody
Expand Down Expand Up @@ -56,8 +57,17 @@ public DynamicContentType ContentType
/// </summary>
public bool IsEditTemplate { get; set; }

/// <summary>
/// True if the content template is defined to be available for all portals, false otherwise
/// </summary>
[IgnoreColumn]
public bool IsSystem { get { return (PortalId == -1); } }
public bool IsSystem
{
get
{
return PortalId == Null.NullInteger;
}
}

/// <summary>
/// The name of this <see cref="T:Dnn.DynamicContent.ContentTemplate"/>
Expand Down
15 changes: 11 additions & 4 deletions DNN Platform/Dnn.DynamicContent/DataType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@
// Licensed under the MIT License. See LICENSE in the project root for license information.

using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Web.Caching;
using Dnn.DynamicContent.Localization;
using DotNetNuke.Common.Utilities;
using DotNetNuke.ComponentModel.DataAnnotations;

// ReSharper disable ConvertPropertyToExpressionBody
Expand All @@ -31,8 +29,17 @@ public DataType(int portalId) : base()

public int DataTypeId { get; set; }

/// <summary>
/// True if the data type is defined to be available for all portals, false otherwise
/// </summary>
[IgnoreColumn]
public bool IsSystem { get { return (PortalId == -1); } }
public bool IsSystem
{
get
{
return PortalId == Null.NullInteger;
}
}

public string Name { get; set; }

Expand Down
43 changes: 37 additions & 6 deletions DNN Platform/Dnn.DynamicContent/DataTypeManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.UI;
using Dnn.DynamicContent.Common;
using Dnn.DynamicContent.Exceptions;
using Dnn.DynamicContent.Localization;
using DotNetNuke.Collections;
using DotNetNuke.Common;
using DotNetNuke.Common.Utilities;
using DotNetNuke.Data;
using DotNetNuke.Entities.Content;
using DotNetNuke.Entities.Portals;
using DotNetNuke.Entities.Users;
using DotNetNuke.Services.Localization;

namespace Dnn.DynamicContent
{
Expand All @@ -42,12 +38,19 @@ public DataTypeManager(IDataContext dataContext) : base(dataContext) { }
/// <returns>data type id.</returns>
/// <exception cref="System.ArgumentNullException">data type is null.</exception>
/// <exception cref="System.ArgumentException">dataType.Name is empty.</exception>
/// <exception cref="SystemDataTypeSecurityException">system data types can only be added by Super Users</exception>
public int AddDataType(DataType dataType)
{
//Argument Contract
Requires.PropertyNotNullOrEmpty(dataType, "Name");

dataType.CreatedByUserId = UserController.Instance.GetCurrentUserInfo().UserID;
var currentUser = UserController.Instance.GetCurrentUserInfo();
if (dataType.IsSystem && !currentUser.IsSuperUser)
{
throw new SystemDataTypeSecurityException();
}

dataType.CreatedByUserId = currentUser.UserID;
dataType.CreatedOnDate = DateUtilitiesManager.Instance.GetDatabaseTime();

Add(dataType);
Expand All @@ -61,13 +64,26 @@ public int AddDataType(DataType dataType)
/// <param name="dataType">The data type to delete.</param>
/// <exception cref="System.ArgumentNullException">data type is null.</exception>
/// <exception cref="System.ArgumentOutOfRangeException">data type id is less than 0.</exception>
/// <exception cref="SystemDataTypeSecurityException">system data types can only be deleted by Super Users</exception>
public void DeleteDataType(DataType dataType)
{
//Argument Contract
Requires.NotNull(dataType);
Requires.PropertyNotNull(dataType, "DataTypeId");
Requires.PropertyNotNegative(dataType, "DataTypeId");

var storedDataType = GetDataType(dataType.DataTypeId, dataType.PortalId, true);
if (storedDataType == null)
{
// TODO: add DataTypeDoesNotExistException here
return;
}

if (storedDataType.IsSystem && !UserController.Instance.GetCurrentUserInfo().IsSuperUser)
{
throw new SystemDataTypeSecurityException();
}

using (DataContext)
{
var fieldDefinitionRepository = DataContext.GetRepository<FieldDefinition>();
Expand Down Expand Up @@ -156,6 +172,7 @@ public IPagedList<DataType> GetDataTypes(string searchTerm, int portalId, int pa
/// <exception cref="System.ArgumentNullException">data type is null.</exception>
/// <exception cref="System.ArgumentOutOfRangeException">data type id is less than 0.</exception>
/// <exception cref="System.ArgumentException">dataType.Name is empty.</exception>
/// <exception cref="SystemDataTypeSecurityException">system data types can only be modified by Super Users</exception>
public void UpdateDataType(DataType dataType, bool overrideWarning = false)
{
//Argument Contract
Expand All @@ -164,7 +181,21 @@ public void UpdateDataType(DataType dataType, bool overrideWarning = false)
Requires.PropertyNotNegative(dataType, "DataTypeId");
Requires.PropertyNotNullOrEmpty(dataType, "Name");

dataType.LastModifiedByUserId = UserController.Instance.GetCurrentUserInfo().UserID;

var storedDataType = GetDataType(dataType.DataTypeId, dataType.PortalId, true);
if (storedDataType == null)
{
// TODO: add DataTypeDoesNotExistException here
return;
}

var currentUser = UserController.Instance.GetCurrentUserInfo();
if (storedDataType.IsSystem && !currentUser.IsSuperUser)
{
throw new SystemDataTypeSecurityException();
}

dataType.LastModifiedByUserId = currentUser.UserID;
dataType.LastModifiedOnDate = DateUtilitiesManager.Instance.GetDatabaseTime();

using (DataContext)
Expand Down
2 changes: 2 additions & 0 deletions DNN Platform/Dnn.DynamicContent/Dnn.DynamicContent.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@
<Compile Include="DynamicContentType.cs" />
<Compile Include="DynamicContentTypeManager.cs" />
<Compile Include="Exceptions\CreateValidatorException.cs" />
<Compile Include="Exceptions\SystemContentTypeSecurityException.cs" />
<Compile Include="Exceptions\SystemDataTypeSecurityException.cs" />
<Compile Include="Exceptions\DataTypeInUseException.cs" />
<Compile Include="Exceptions\InvalidValidationTypeException.cs" />
<Compile Include="Exceptions\InvalidValidatorException.cs" />
Expand Down
10 changes: 8 additions & 2 deletions DNN Platform/Dnn.DynamicContent/DynamicContentType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,16 @@ public IList<FieldDefinition> FieldDefinitions
public bool IsDynamic { get; set; }

/// <summary>
/// A flag that indicates whether the Content Type is a system type
/// A flag that indicates whether the Content Type is a global type available cross all portals
/// </summary>
[IgnoreColumn]
public bool IsSystem { get { return (PortalId == -1); } }
public bool IsSystem
{
get
{
return PortalId == Null.NullInteger;
}
}

/// <summary>
/// Gets or sets the name of the ContentType.
Expand Down
42 changes: 39 additions & 3 deletions DNN Platform/Dnn.DynamicContent/DynamicContentTypeManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
// Licensed under the MIT License. See LICENSE in the project root for license information.

using System;
using System.Collections.Generic;
using System.Linq;
using Dnn.DynamicContent.Common;
using Dnn.DynamicContent.Exceptions;
using Dnn.DynamicContent.Localization;
using DotNetNuke.Collections;
using DotNetNuke.Common;
Expand Down Expand Up @@ -35,12 +35,19 @@ public DynamicContentTypeManager(IDataContext dataContext) : base(dataContext) {
/// <returns>content type id.</returns>
/// <exception cref="System.ArgumentNullException">content type is null.</exception>
/// <exception cref="System.ArgumentException">contentType.ContentType is empty.</exception>
/// <exception cref="SystemContentTypeSecurityException">system content types can only be added by Super Users</exception>
public int AddContentType(DynamicContentType contentType)
{
//Argument Contract
Requires.PropertyNotNullOrEmpty(contentType, "Name");

contentType.CreatedByUserId = UserController.Instance.GetCurrentUserInfo().UserID;
var currentUser = UserController.Instance.GetCurrentUserInfo();
if (contentType.IsSystem && !currentUser.IsSuperUser)
{
throw new SystemContentTypeSecurityException();
}

contentType.CreatedByUserId = currentUser.UserID;
contentType.CreatedOnDate = DateUtilitiesManager.Instance.GetDatabaseTime();

Add(contentType);
Expand Down Expand Up @@ -68,10 +75,24 @@ public int AddContentType(DynamicContentType contentType)
/// <param name="contentType">Type of the content.</param>
/// <exception cref="System.ArgumentNullException">content type is null.</exception>
/// <exception cref="System.ArgumentOutOfRangeException">content type id is less than 0.</exception>
/// <exception cref="SystemContentTypeSecurityException">system content types can only be deleted by Super Users</exception>
public void DeleteContentType(DynamicContentType contentType)
{
Requires.NotNull(contentType);
Requires.PropertyNotNegative(contentType, "ContentTypeId");

var storedContentType = GetContentType(contentType.ContentTypeId, contentType.PortalId, true);
if (storedContentType == null)
{
// TODO: add ContentTypeDoesNotExistException here
return;
}

var currentUser = UserController.Instance.GetCurrentUserInfo();
if (storedContentType.IsSystem && !currentUser.IsSuperUser)
{
throw new SystemContentTypeSecurityException();
}

//Delete Field Definitions
foreach (var definition in contentType.FieldDefinitions)
Expand Down Expand Up @@ -160,12 +181,27 @@ public IPagedList<DynamicContentType> GetContentTypes(string searchTerm, int por
/// <exception cref="System.ArgumentNullException">content type is null.</exception>
/// <exception cref="System.ArgumentOutOfRangeException">content type id is less than 0.</exception>
/// <exception cref="System.ArgumentException">contentType.ContentType is empty.</exception>
/// <exception cref="SystemContentTypeSecurityException">system content types can only be modified by Super Users</exception>
public void UpdateContentType(DynamicContentType contentType)
{
//Argument Contract
Requires.PropertyNotNullOrEmpty(contentType, "Name");
Requires.PropertyNotNegative(contentType, "ContentTypeId");

var storedContentType = GetContentType(contentType.ContentTypeId, contentType.PortalId, true);
if (storedContentType == null)
{
// TODO: add ContentTypeDoesNotExistException here
return;
}

var currentUser = UserController.Instance.GetCurrentUserInfo();
if (storedContentType.IsSystem && !currentUser.IsSuperUser)
{
throw new SystemContentTypeSecurityException();
}

contentType.LastModifiedByUserId = UserController.Instance.GetCurrentUserInfo().UserID;
contentType.LastModifiedByUserId = currentUser.UserID;
contentType.LastModifiedOnDate = DateUtilitiesManager.Instance.GetDatabaseTime();

Update(contentType);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Copyright (c) DNN Software. All rights reserved.
// Licensed under the MIT License. See LICENSE in the project root for license information.

using System.Security;

namespace Dnn.DynamicContent.Exceptions
{
/// <summary>
/// Global Content Type can be created, modified or deleted only by super users
/// </summary>
public class SystemContentTypeSecurityException : SecurityException
{
public SystemContentTypeSecurityException()
: base(string.Format(
DotNetNuke.Services.Localization.Localization.GetString("SystemContentTypesSecurityException",
DotNetNuke.Services.Localization.Localization.ExceptionsResourceFile)))
{
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Copyright (c) DNN Software. All rights reserved.
// Licensed under the MIT License. See LICENSE in the project root for license information.

using System.Security;

namespace Dnn.DynamicContent.Exceptions
{
/// <summary>
/// Global Data Type can be created, modified or deleted only by super users
/// </summary>
public class SystemDataTypeSecurityException : SecurityException
{
public SystemDataTypeSecurityException()
: base(string.Format(
DotNetNuke.Services.Localization.Localization.GetString("SystemDataTypesSecurityException",
DotNetNuke.Services.Localization.Localization.ExceptionsResourceFile)))
{
}
}
}
4 changes: 4 additions & 0 deletions DNN Platform/Dnn.DynamicContent/IDataTypeManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Licensed under the MIT License. See LICENSE in the project root for license information.

using System.Linq;
using Dnn.DynamicContent.Exceptions;
using DotNetNuke.Collections;

namespace Dnn.DynamicContent
Expand All @@ -13,12 +14,14 @@ public interface IDataTypeManager
/// </summary>
/// <param name="dataType">The data type to add.</param>
/// <returns>data type id.</returns>
/// <exception cref="SystemDataTypeSecurityException">system data types can only be added by Super Users</exception>
int AddDataType(DataType dataType);

/// <summary>
/// Deletes the data type for use with Structured(Dynamic) Content Types.
/// </summary>
/// <param name="dataType">The data type to delete.</param>
/// <exception cref="SystemDataTypeSecurityException">system data types can only be deleted by Super Users</exception>
void DeleteDataType(DataType dataType);

/// <summary>
Expand Down Expand Up @@ -60,6 +63,7 @@ public interface IDataTypeManager
/// <exception cref="System.ArgumentNullException">data type is null.</exception>
/// <exception cref="System.ArgumentOutOfRangeException">data type id is less than 0.</exception>
/// <exception cref="System.ArgumentException">dataType.Name is empty.</exception>
/// <exception cref="SystemDataTypeSecurityException">system data types can only be modified by Super Users</exception>
void UpdateDataType(DataType dataType, bool overrideWarning = false);
}
}
4 changes: 4 additions & 0 deletions DNN Platform/Dnn.DynamicContent/IDynamicContentTypeManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Licensed under the MIT License. See LICENSE in the project root for license information.

using System.Linq;
using Dnn.DynamicContent.Exceptions;
using DotNetNuke.Collections;

namespace Dnn.DynamicContent
Expand All @@ -15,6 +16,7 @@ public interface IDynamicContentTypeManager
/// <returns>content type id.</returns>
/// <exception cref="System.ArgumentNullException">content type is null.</exception>
/// <exception cref="System.ArgumentException">contentType.ContentType is empty.</exception>
/// <exception cref="SystemContentTypeSecurityException">system content types can only be added by Super Users</exception>
int AddContentType(DynamicContentType contentType);

/// <summary>
Expand All @@ -23,6 +25,7 @@ public interface IDynamicContentTypeManager
/// <param name="contentType">Type of the content.</param>
/// <exception cref="System.ArgumentNullException">content type is null.</exception>
/// <exception cref="System.ArgumentOutOfRangeException">content type id is less than 0.</exception>
/// <exception cref="SystemContentTypeSecurityException">system content types can only be deleted by Super Users</exception>
void DeleteContentType(DynamicContentType contentType);

/// <summary>
Expand Down Expand Up @@ -63,6 +66,7 @@ public interface IDynamicContentTypeManager
/// <exception cref="System.ArgumentNullException">content type is null.</exception>
/// <exception cref="System.ArgumentOutOfRangeException">content type id is less than 0.</exception>
/// <exception cref="System.ArgumentException">contentType.ContentType is empty.</exception>
/// <exception cref="SystemContentTypeSecurityException">system content types can only be modified by Super Users</exception>
void UpdateContentType(DynamicContentType contentType);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ dcc.dataTypeViewModel = function(parentViewModel, config){

self.init = function() {
self.dataTypeId(-1);
self.canEdit(false);
self.canEdit(true);
self.baseType(0);
self.isSystem(false);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -280,9 +280,9 @@
</div>

<div class="buttons">
<a class="secondarybtn" id="dataTypes-deleteButton" data-bind="click: deleteDataType, visible: !isAddMode()">[Resx:{key:"Delete"}]</a>
<a class="secondarybtn" id="dataTypes-deleteButton" data-bind="click: deleteDataType, visible: !isAddMode() && canEdit()">[Resx:{key:"Delete"}]</a>
<a class="secondarybtn" data-bind="click: cancel">[Resx:{key:"Cancel"}]</a>
<a class="primarybtn" data-bind="click: saveDataType">[Resx:{key:"Save"}]</a>
<a class="primarybtn" data-bind="click: saveDataType, visible: canEdit()">[Resx:{key:"Save"}]</a>
</div>

<div class="clear"></div>
Expand Down
Loading