Ensure that data types required by the core cannot be deleted. (#15738)

* Ensure that data types required by the core cannot be deleted.

* Update OpenApi.json
This commit is contained in:
Kenn Jacobsen
2024-02-21 10:22:22 +01:00
committed by GitHub
parent c12b88801a
commit d9aed7f9a7
12 changed files with 95 additions and 8 deletions

View File

@@ -42,10 +42,25 @@ public static class DataTypeExtensions
Constants.DataTypes.Guids.LabelDecimalGuid,
Constants.DataTypes.Guids.LabelDateTimeGuid,
Constants.DataTypes.Guids.LabelBigIntGuid,
Constants.DataTypes.Guids.LabelIntGuid,
Constants.DataTypes.Guids.LabelTimeGuid,
Constants.DataTypes.Guids.LabelDateTimeGuid,
};
private static readonly ISet<Guid> IdsOfNonDeletableDataTypes = new HashSet<Guid>
{
// these data types are required by PublishedContentType when creating system properties for members
// (e.g. username, last login date, approval status)
Constants.DataTypes.Guids.CheckboxGuid,
Constants.DataTypes.Guids.TextstringGuid,
Constants.DataTypes.Guids.LabelDateTimeGuid,
// these data types are required for default list view handling
Constants.DataTypes.Guids.ListViewContentGuid,
Constants.DataTypes.Guids.ListViewMediaGuid,
Constants.DataTypes.Guids.ListViewMembersGuid,
};
/// <summary>
/// Gets the configuration object.
/// </summary>
@@ -75,14 +90,26 @@ public static class DataTypeExtensions
}
/// <summary>
/// Returns true if this date type is build-in/default.
/// Returns true if this data type is build-in/default.
/// </summary>
/// <param name="dataType">The data type definition.</param>
/// <returns></returns>
public static bool IsBuildInDataType(this IDataType dataType) => IsBuildInDataType(dataType.Key);
/// <summary>
/// Returns true if this date type is build-in/default.
/// Returns true if this data type is build-in/default.
/// </summary>
public static bool IsBuildInDataType(Guid key) => IdsOfBuildInDataTypes.Contains(key);
/// <summary>
/// Returns true if this data type can be deleted.
/// </summary>
/// <param name="dataType">The data type definition.</param>
/// <returns></returns>
public static bool IsDeletableDataType(this IDataType dataType) => IsDeletableDataType(dataType.Key);
/// <summary>
/// Returns true if this data type can be deleted.
/// </summary>
public static bool IsDeletableDataType(Guid key) => IdsOfNonDeletableDataTypes.Contains(key) is false;
}