Skip to content

Commit

Permalink
14170-ShowColumnsAreReadOnly
Browse files Browse the repository at this point in the history
  • Loading branch information
DWDBE committed Dec 1, 2023
1 parent c004701 commit c16c98c
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Dynamicweb.DataIntegration" Version="10.0.13" />
<PackageReference Include="Dynamicweb.DataIntegration" Version="10.0.23" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All" />
</ItemGroup>
<ItemGroup>
Expand Down
38 changes: 25 additions & 13 deletions src/ODataProvider.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,5 @@
using Dynamicweb.Core;
using Dynamicweb.DataIntegration.EndpointManagement;
using Dynamicweb.DataIntegration.Integration;
using Dynamicweb.DataIntegration.Integration.ERPIntegration;
using Dynamicweb.DataIntegration.Integration.Interfaces;
using Dynamicweb.DataIntegration.Providers.ODataProvider.Interfaces;
using Dynamicweb.DataIntegration.Providers.ODataProvider.Interfaces;
using Dynamicweb.DataIntegration.Providers.ODataProvider.Model;
using Dynamicweb.Extensibility.AddIns;
using Dynamicweb.Extensibility.Editors;
using Dynamicweb.Logging;
using Dynamicweb.Security.Licensing;
using System;
using System.Collections.Generic;
using System.IO;
Expand Down Expand Up @@ -321,7 +312,7 @@ private void GetColumnsFromEntityTypeTableToEntitySetTable(Table table, Schema e
{
if (table.Columns.Where(obj => obj.Name == item.Name).Count() == 0)
{
table.AddColumn(new Column(item.Name, item.Type, table, item.IsPrimaryKey, item.IsNew));
table.AddColumn(new Column(item.Name, item.Type, table, item.IsPrimaryKey, item.IsNew, item.ReadOnly));
}
}
}
Expand All @@ -332,6 +323,7 @@ private void AddPropertiesFromXMLReaderToTable(XmlReader xmlReader, Table table,
string baseType = xmlReader.GetAttribute("BaseType");
string entityName = xmlReader.GetAttribute("Name");
List<string> primaryKeys = new List<string>();
Column column = null;
while (xmlReader.Read() && !(xmlReader.NodeType == XmlNodeType.EndElement && xmlReader.Name.Equals("EntityType", StringComparison.OrdinalIgnoreCase)))
{
if (xmlReader.NodeType == XmlNodeType.Element && xmlReader.Name.Equals("PropertyRef", StringComparison.OrdinalIgnoreCase))
Expand All @@ -344,7 +336,27 @@ private void AddPropertiesFromXMLReaderToTable(XmlReader xmlReader, Table table,
var columnTypeString = xmlReader.GetAttribute("Type");
var columnType = GetColumnType(columnTypeString);
var isPrimaryKey = primaryKeys.Contains(columnName);
table.AddColumn(new Column(columnName, columnType, table, isPrimaryKey, false));
column = new Column(columnName, columnType, table, isPrimaryKey, false);
table.AddColumn(column);
// BC
var scale = xmlReader.GetAttribute("Scale");
if (scale is not null && string.Equals(scale, "Variable", StringComparison.OrdinalIgnoreCase))
column.ReadOnly = true;
}
else if (xmlReader.NodeType == XmlNodeType.Element && xmlReader.Name.Equals("Annotation", StringComparison.OrdinalIgnoreCase) && column is not null)
{
// BC & FO
var term = xmlReader.GetAttribute("Term");
var value = xmlReader.GetAttribute("Bool");
if (!string.IsNullOrEmpty(term) && term.Contains("AllowEdit") && !string.IsNullOrEmpty(value) && !Converter.ToBoolean(value))
column.ReadOnly = true;
}
else if (xmlReader.NodeType == XmlNodeType.Element && xmlReader.Name.Equals("EnumMember", StringComparison.OrdinalIgnoreCase) && column is not null)
{
// CRM
string permission = xmlReader.Value;
if (!string.IsNullOrEmpty(permission) && permission.ToLower().EndsWith("permissiontype/read"))
column.ReadOnly = true;
}
else if (xmlReader.Name.Equals("EntityType", StringComparison.OrdinalIgnoreCase) && xmlReader.GetAttribute("Name") != entityName)
{
Expand All @@ -361,7 +373,7 @@ private void AddPropertiesFromXMLReaderToTable(XmlReader xmlReader, Table table,
{
if (table.Columns.Where(obj => obj.Name == item.Name).Count() == 0)
{
table.AddColumn(new Column(item.Name, item.Type, table, item.IsPrimaryKey, item.IsNew));
table.AddColumn(new Column(item.Name, item.Type, table, item.IsPrimaryKey, item.IsNew, item.ReadOnly));
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/ODataWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ internal string MapValuesToJSon(ColumnMappingCollection columnMappings, Dictiona

foreach (ColumnMapping columnMapping in columnMappings)
{
if (!columnMapping.Active || (columnMapping.ScriptValueForInsert && isPatchRequest))
if (!columnMapping.Active || (columnMapping.ScriptValueForInsert && isPatchRequest) || (columnMapping.DestinationColumn is not null && !columnMapping.DestinationColumn.ReadOnly))
continue;

if (columnMapping.HasScriptWithValue || row.ContainsKey(columnMapping.SourceColumn?.Name))
Expand Down

0 comments on commit c16c98c

Please sign in to comment.