Skip to content

Commit

Permalink
C1 CMS v6.8
Browse files Browse the repository at this point in the history
 - new tree selector widget
 - support for "version published" content in C1 Package system
 - fix: adding new language and selecting 'give access to all users' will include access to all groups also
  • Loading branch information
mawtex authored Nov 25, 2019
2 parents 999992a + 3685e2c commit e40b0ff
Show file tree
Hide file tree
Showing 26 changed files with 648 additions and 62 deletions.
56 changes: 56 additions & 0 deletions .build/ReleaseCleanup.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
param (
[string]$cleanupTargetName,
[string]$cleanupDirectory
)

Write-Host "ReleaseCleanup script started..."
# This script deletes/rename files according to rules in ReleaseCleanupConfiguration.xml - it is used by automated builds

if(-not($cleanupTargetName)) { Throw "You must supply a value for -cleanupTargetName - matching a target name in ReleaseCleanupConfiguration.xml" }
if(-not($cleanupDirectory)) { Throw "You must supply a value for -cleanupDirectory - this is the path where cleaning will be taking place" }

$scriptPath = split-path -parent $MyInvocation.MyCommand.Definition
[xml]$xml = Get-Content (Join-Path $scriptPath "ReleaseCleanupConfiguration.xml")

$targetItems = $xml.SelectNodes("/Configuration/Target[@name='" + $cleanupTargetName + "']/*/*[@path]")

Foreach ($fileNode in $targetItems) {
$relPath = $fileNode.Attributes["path"].Value
$fullPath = Join-Path $cleanupDirectory $relPath

if (($fileNode.Attributes["rename-find"]) -and ($fileNode.Attributes["rename-replace"]) ) {
# if rename
Write-Host "Handling $fullPath for renaming"

$findString = $fileNode.Attributes["rename-find"].Value.Replace("\","/")
$replaceString = $fileNode.Attributes["rename-replace"].Value

$matches = Get-ChildItem -Path $fullPath -Recurse

if ($matches.length -eq 0) { Write-Warning "Pattern matched 0 files - probably you should remove it from ReleaseCleanupConfiguration.xml in repo" }

Foreach ($match in $matches) {
$name = $match.FullName.Replace("\","/")
$newName = $name.Replace($findString.Replace("\","/"), $replaceString)

#ensure dir
$newDirPath = Split-Path -Path $newName
if (-not (Test-Path($newDirPath))) { New-Item -ItemType Directory -Force -Path $newDirPath }
Move-Item $match -Destination $newName -Force
}
}
else {
# assume delete otherwise
Write-Host "Handling $fullPath for deletion"

if (($fileNode.Name -eq "Directory") -and (Test-Path $fullPath)) {
Remove-Item -LiteralPath $fullPath -Force -Recurse
} else {
$matches = Get-ChildItem -Path $fullPath -Recurse

if ($matches.length -eq 0) { Write-Warning "Pattern matched 0 files - probably you should remove it from ReleaseCleanupConfiguration.xml in repo" }

$matches | Where-Object { Test-Path($_) } | Remove-Item -Force -Recurse
}
}
}
47 changes: 47 additions & 0 deletions .build/ReleaseCleanupConfiguration.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?xml version="1.0" encoding="utf-8" ?>
<Configuration>
<Target name="prejavascriptcompile">
<CleanupOperations>
<!-- operations are done in sequence -->
<Directory path="/obj" />
<Directory path="/test" />
<Directory path="/Composite/content/dialogs/tests" />
<Directory path="/Composite/content/views/dev/developer/tests" />
<Directory path="/Composite/content/views/search" />
<Directory path="/Composite/extensions" />
<File path="/App_Data/Composite/ReleaseBuild.Composite.config.changeHistory.txt" />
<File path="*.bat" />
<File path="DebugBuild.*" />
<File path="*.csproj*" />
<File path="/bin/*.pdb" />
<File path="/bin/Composite.xml" rename-find=".xml" rename-replace=".xml.yolo" />
<File path="/bin/*.xml" />
<File path="/bin/Composite.xml.yolo" rename-find=".xml.yolo" rename-replace=".xml" />
</CleanupOperations>
</Target>

<Target name="postjavascriptcompile">
<CleanupOperations>
<Directory path="/Composite/scripts/source" />
<Directory path="/Composite/applets" />
<Directory path="/Composite/Images/Icons/svg" />
<Directory path="/Composite/Styles/default" />
<Directory path="/bower_components" />
<Directory path="/jspm_packages" />
<Directory path="/node_modules" />
<File path="/bower.json" />
<File path="/gruntfile.js" />
<File path="/package.json" />
<File path="/jspm.config.js" />
<File path="/package-lock.json" />
<File path="/packages.config" />
<File path="/Composite/Styles/styles.less" />
<File path="/Composite/console/index.prod.html" rename-find="console/index.prod.html" rename-replace="console.index.prod.html" />
<Directory path="/Composite/console" />
<File path="/Composite/console.index.prod.html" rename-find="console.index.prod.html" rename-replace="console/index.html" />
<File path=".*" />
<File path="ReleaseBuild.*" rename-find="ReleaseBuild." rename-replace="" />
<File path="/ReleaseCleanupConfiguration.xml" />
</CleanupOperations>
</Target>
</Configuration>
32 changes: 32 additions & 0 deletions Composite/C1Console/Forms/CoreUiControls/TreeSelectorUiControl.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using System;
using System.Collections.Generic;
using Composite.C1Console.Forms.Foundation;

namespace Composite.C1Console.Forms.CoreUiControls
{
[ControlValueProperty("SelectedKeys")]
internal abstract class TreeSelectorUiControl : UiControl
{
[BindableProperty]
[FormsProperty]
public string SelectedKey { get; set; }

[FormsProperty]
public string ElementProvider { get; set; }

[FormsProperty]
public string SelectableElementPropertyName { get; set; }

[FormsProperty]
public string SelectableElementPropertyValue { get; set; }

[FormsProperty]
public string SelectableElementReturnValue { get; set; }

[FormsProperty]
public string SerializedSearchToken { get; set; }

[FormsProperty]
public bool Required { get; set; }
}
}
5 changes: 5 additions & 0 deletions Composite/Composite.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@
<Compile Include="C1Console\Actions\Data\DataActionTokenResolverFacade.cs" />
<Compile Include="C1Console\Actions\Data\DataActionTokenResolverRegistry.cs" />
<Compile Include="C1Console\Actions\DuplicateActionToken.cs" />
<Compile Include="C1Console\Forms\CoreUiControls\TreeSelectorUiControl.cs" />
<Compile Include="C1Console\RichContent\Components\Component.cs" />
<Compile Include="C1Console\RichContent\Components\ComponentChangeNotifier.cs" />
<Compile Include="C1Console\RichContent\Components\ComponentManager.cs" />
Expand Down Expand Up @@ -260,6 +261,10 @@
<Compile Include="Data\Types\VersionedDataHelperContract.cs" />
<Compile Include="Plugins\Elements\UrlToEntityToken\WebsiteFileUrlToEntityTokenMapper.cs" />
<Compile Include="Plugins\Elements\UrlToEntityToken\MediaUrlToEntityTokenMapper.cs" />
<Compile Include="Plugins\Forms\WebChannel\UiControlFactories\TemplatedTreelSelectorUiControlFactory.cs">
<SubType>ASPXCodeBehind</SubType>
</Compile>
<Compile Include="Plugins\Functions\WidgetFunctionProviders\StandardWidgetFunctionProvider\String\TreeSelectorWidgetFunction.cs" />
<Compile Include="Plugins\Functions\WidgetFunctionProviders\StandardWidgetFunctionProvider\String\HierarchicalSelectorWidgetFunction.cs" />
<Compile Include="Plugins\Logging\LogTraceListeners\SystemDiagnosticsTrace\SystemDiagnosticsTraceBridge.cs" />
<Compile Include="Properties\GitCommitInfo.cs" />
Expand Down
13 changes: 13 additions & 0 deletions Composite/Core/Localization/LocalizationFacade.cs
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,19 @@ internal static void AddLocale(CultureInfo cultureInfo, string urlMappingName, b
UserSettings.SetForeignLocaleCultureInfo(username, cultureInfo);
}
}

List<Guid> usergroupids =
(from u in DataFacade.GetData<IUserGroup>()
select u.Id).ToList();

foreach (Guid usergroupid in usergroupids)
{
var groupLang = DataFacade.BuildNew<IUserGroupActiveLocale>();
groupLang.Id = Guid.NewGuid();
groupLang.CultureName = cultureInfo.ToString();
groupLang.UserGroupId = usergroupid;
DataFacade.AddNew(groupLang);
}
}

if (DataLocalizationFacade.DefaultLocalizationCulture == null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,15 +191,18 @@ private XElement AddData(DataType dataType, CultureInfo cultureInfo)
}


var dataKey = CopyFieldValues(dataType, data, addElement);
var dataKey = PopulateAndReturnKeyPropertyValues(dataType, data, addElement);

if (dataType.AllowOverwrite || dataType.OnlyUpdate)
{
IData existingData = DataFacade.TryGetDataByUniqueKey(interfaceType, dataKey);
List<IData> existingDataList = DataFacade.TryGetDataByLookupKeys(interfaceType, dataKey).ToList();
if (existingDataList.Count > 1) throw new InvalidOperationException("Got more than 1 existing data element when querying on key properties for " + addElement.ToString());

IData existingData = existingDataList.FirstOrDefault();

if (existingData != null)
{
CopyFieldValues(dataType, existingData, addElement);
PopulateAndReturnKeyPropertyValues(dataType, existingData, addElement);
DataFacade.Update(existingData, false, true, false);

continue;
Expand Down Expand Up @@ -280,13 +283,16 @@ private void UpdateVersionId(IVersioned data)
}
}


private static DataKeyPropertyCollection CopyFieldValues(DataType dataType, IData data, XElement addElement)
private static DataPropertyValueCollection PopulateAndReturnKeyPropertyValues(DataType dataType, IData dataToPopulate, XElement addElement)
{
var dataKeyPropertyCollection = new DataKeyPropertyCollection();
var dataKeyPropertyCollection = new DataPropertyValueCollection();

var properties = GetDataTypeProperties(dataType.InterfaceType);

var keyPropertyNames = dataType.InterfaceType.GetKeyPropertyNames();
var versionKeyPropertyNames = dataType.InterfaceType.GetVersionKeyPropertyNames();

foreach (XAttribute attribute in addElement.Attributes())
{
string fieldName = attribute.Name.LocalName;
Expand All @@ -298,11 +304,11 @@ private static DataKeyPropertyCollection CopyFieldValues(DataType dataType, IDat
PropertyInfo propertyInfo = properties[fieldName];

object fieldValue = ValueTypeConverter.Convert(attribute.Value, propertyInfo.PropertyType);
propertyInfo.SetValue(data, fieldValue, null);
propertyInfo.SetValue(dataToPopulate, fieldValue, null);

if (dataType.InterfaceType.GetKeyPropertyNames().Contains(fieldName))
if (keyPropertyNames.Contains(fieldName) || versionKeyPropertyNames.Contains(fieldName))
{
dataKeyPropertyCollection.AddKeyProperty(fieldName, fieldValue);
dataKeyPropertyCollection.AddKeyProperty(propertyInfo, fieldValue);
}
}

Expand Down
37 changes: 26 additions & 11 deletions Composite/Data/DataFacade.cs
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ public static IQueryable<T> GetDataFromOtherScope<T>(T data, DataScopeIdentifier

using (new DataScope(dataScopeIdentifier))
{
return DataExpressionBuilder.GetQueryableByData<T>(data, true);
return DataExpressionBuilder.GetQueryableByData<T>(data);
}
}

Expand All @@ -384,7 +384,7 @@ public static IQueryable<T> GetDataFromOtherLocale<T>(T data, CultureInfo cultur

using (new DataScope(cultureInfo))
{
return DataExpressionBuilder.GetQueryableByData<T>(data, true);
return DataExpressionBuilder.GetQueryableByData<T>(data);
}
}

Expand All @@ -397,13 +397,6 @@ public static IEnumerable<IData> GetDataFromOtherScope(IData data, DataScopeIden
/// <exclude />
public static IEnumerable<IData> GetDataFromOtherScope(
IData data, DataScopeIdentifier dataScopeIdentifier, bool useCaching)
{
return GetDataFromOtherScope(data, dataScopeIdentifier, useCaching, true);
}

/// <exclude />
public static IEnumerable<IData> GetDataFromOtherScope(
IData data, DataScopeIdentifier dataScopeIdentifier, bool useCaching, bool ignoreVersioning)
{
Verify.ArgumentNotNull(data, "data");
Verify.ArgumentNotNull(dataScopeIdentifier, nameof(dataScopeIdentifier));
Expand Down Expand Up @@ -432,7 +425,7 @@ public static IEnumerable<IData> GetDataFromOtherScope(
{
IQueryable table = GetData(data.DataSourceId.InterfaceType, false);

IQueryable queryable = DataExpressionBuilder.GetQueryableByData(data, table, ignoreVersioning);
IQueryable queryable = DataExpressionBuilder.GetQueryableByData(data, table);

foreach (object obj in queryable)
{
Expand Down Expand Up @@ -509,7 +502,7 @@ public static LambdaExpression GetPredicateExpressionByUniqueKey(Type interfaceT
// Private helper
private static Expression GetPredicateExpressionByUniqueKeyFilterExpression(IReadOnlyList<PropertyInfo> keyProperties, DataKeyPropertyCollection dataKeyPropertyCollection, ParameterExpression parameterExpression)
{
if (keyProperties.Count != dataKeyPropertyCollection.Count) throw new ArgumentException("Missing og to many key properties");
if (keyProperties.Count != dataKeyPropertyCollection.Count) throw new ArgumentException("Missing or too many key properties");

var propertiesWithValues = new List<Tuple<PropertyInfo, object>>();
foreach (var kvp in dataKeyPropertyCollection.KeyProperties)
Expand Down Expand Up @@ -606,6 +599,28 @@ public static IData TryGetDataByUniqueKey(Type interfaceType, DataKeyPropertyCol
return data;
}

/// <summary>
/// Returns all data items of the given type, which matches the provided dataPropertyCollection (property/value pairs)
/// </summary>
/// <param name="interfaceType">The data type to query - type is expected to implement a subinterface of IData</param>
/// <param name="dataPropertyCollection">The properties and values to use for filtering</param>
/// <returns>Data matching the provided property values</returns>
public static IEnumerable<IData> TryGetDataByLookupKeys(Type interfaceType, DataPropertyValueCollection dataPropertyCollection)
{
Verify.ArgumentNotNull(interfaceType, nameof(interfaceType));
Verify.ArgumentNotNull(dataPropertyCollection, nameof(dataPropertyCollection));

LambdaExpression lambdaExpression = GetPredicateExpression(interfaceType, dataPropertyCollection);

MethodInfo methodInfo = GetGetDataWithPredicatMethodInfo(interfaceType);

var queryable = (IQueryable)methodInfo.Invoke(null, new object[] { lambdaExpression });

return ((IEnumerable)queryable).Cast<IData>();
}




/// <exclude />
public static IEnumerable<IData> TryGetDataVersionsByUniqueKey(Type interfaceType, DataKeyPropertyCollection dataKeyPropertyCollection)
Expand Down
23 changes: 8 additions & 15 deletions Composite/Data/Foundation/DataExpressionBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,14 @@ static DataExpressionBuilder()
/// <returns></returns>
public static IQueryable GetQueryableByData(IData data)
{
return GetQueryableByData(data, true);
return GetQueryableByData(data, null);
}



public static IQueryable GetQueryableByData(IData data, bool ignoreVersioning)
public static IQueryable GetQueryableByData(IData data, IQueryable sourceQueryable)
{
return GetQueryableByData(data, null, ignoreVersioning);
}



public static IQueryable GetQueryableByData(IData data, IQueryable sourceQueryable, bool ignoreVersioning)
{
LambdaExpression whereLambdaExpression = GetWhereLambdaExpression(data, ignoreVersioning);
LambdaExpression whereLambdaExpression = GetWhereLambdaExpression(data);

if (sourceQueryable == null)
{
Expand All @@ -59,10 +52,10 @@ public static IQueryable GetQueryableByData(IData data, IQueryable sourceQueryab



public static IQueryable<T> GetQueryableByData<T>(T data, bool ignoreVersioning)
public static IQueryable<T> GetQueryableByData<T>(T data)
where T : class, IData
{
LambdaExpression whereLambdaExpression = GetWhereLambdaExpression(data, ignoreVersioning);
LambdaExpression whereLambdaExpression = GetWhereLambdaExpression(data);

IQueryable queryable = DataFacade.GetData(data.DataSourceId.InterfaceType);

Expand All @@ -75,9 +68,9 @@ public static IQueryable<T> GetQueryableByData<T>(T data, bool ignoreVersioning)



public static Delegate GetWherePredicateDelegate(IData data, bool ignoreVersioning)
public static Delegate GetWherePredicateDelegate(IData data)
{
LambdaExpression whereLambdaExpression = GetWhereLambdaExpression(data, ignoreVersioning);
LambdaExpression whereLambdaExpression = GetWhereLambdaExpression(data);

Delegate resultDelegate = whereLambdaExpression.Compile();

Expand All @@ -86,7 +79,7 @@ public static Delegate GetWherePredicateDelegate(IData data, bool ignoreVersioni



private static LambdaExpression GetWhereLambdaExpression(IData data, bool ignoreVersioning)
private static LambdaExpression GetWhereLambdaExpression(IData data)
{
var propertyInfoes = data.DataSourceId.InterfaceType.GetPhysicalKeyProperties();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ public List<ElementAction> GetActions(IData data, Type elementProviderType)
var clientActions = visualTrans.Select(newState => _visualTransitionsActions[newState]()).ToList();


IData publicData = DataFacade.GetDataFromOtherScope(data, DataScopeIdentifier.Public, true, false).FirstOrDefault();
IData publicData = DataFacade.GetDataFromOtherScope(data, DataScopeIdentifier.Public, true).FirstOrDefault();
if (publicData != null)
{
var unpublishAction = new ElementAction(new ActionHandle(new ProxyDataActionToken(ActionIdentifier.Unpublish) { DoIgnoreEntityTokenLocking = true }))
Expand Down
Loading

0 comments on commit e40b0ff

Please sign in to comment.