Skip to content
Permalink
Browse files

Merge pull request #678 from Orckestra/dev

Bringing fix branch up to date
  • Loading branch information...
mawtex committed Jul 4, 2019
2 parents 4422d5d + dbde1a5 commit 566caaff3f3342eca80dde15e1fc4530940d73aa
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
@@ -48,6 +48,7 @@ private static class BindingNames
public const string User = "User";
public const string UserFormLogin = "UserFormLogin";
public const string NewPassword = "NewPassword";
public const string ActiveContentLanguage = "ActiveLocaleName";
}

private void CheckActiveLanguagesExists(object sender, System.Workflow.Activities.ConditionalEventArgs e)
@@ -80,11 +81,9 @@ private void initializeCodeActivity_ExecuteCode(object sender, EventArgs e)
this.Bindings.Add("C1ConsoleUiCultures", regionLanguageList);
this.Bindings.Add("C1ConsoleUiLanguageName", c1ConsoleUiLanguage.Name);

if (UserSettings.GetActiveLocaleCultureInfos(user.Username).Any() && (user.Username != UserSettings.Username))
{
this.Bindings.Add("ActiveLocaleName", UserSettings.GetCurrentActiveLocaleCultureInfo(user.Username).Name);
this.Bindings.Add("ActiveLocaleList", DataLocalizationFacade.ActiveLocalizationCultures.ToDictionary(f => f.Name, DataLocalizationFacade.GetCultureTitle));
}
var currentActiveCulture = UserSettings.GetCurrentActiveLocaleCultureInfo(user.Username);
this.Bindings.Add("ActiveLocaleName", currentActiveCulture != null ? currentActiveCulture.Name : null);
this.Bindings.Add("ActiveLocaleList", DataLocalizationFacade.ActiveLocalizationCultures.ToDictionary(f => f.Name, DataLocalizationFacade.GetCultureTitle));

var clientValidationRules = new Dictionary<string, List<ClientValidationRule>>
{
@@ -157,7 +156,7 @@ private void UpdateFormDefinitionWithActiveLocales(IUser user, XElement bindings
bindingsElement.Add(helper.GetBindingsMarkup());
placeHolderElement.Add(helper.GetFormMarkup());

helper.UpdateWithNewBindings(this.Bindings, UserSettings.GetActiveLocaleCultureInfos(user.Username));
helper.UpdateWithNewBindings(this.Bindings, UserSettings.GetActiveLocaleCultureInfos(user.Username, false));
}


@@ -198,41 +197,11 @@ private void saveCodeActivity_ExecuteCode(object sender, EventArgs e)


List<CultureInfo> newActiveLocales = ActiveLocalesFormsHelper.GetSelectedLocalesTypes(this.Bindings).ToList();
List<CultureInfo> currentActiveLocales = null;
CultureInfo selectedActiveLocal = null;

if (newActiveLocales.Count > 0)
{
currentActiveLocales = UserSettings.GetActiveLocaleCultureInfos(user.Username).ToList();
List<CultureInfo> currentActiveLocales = UserSettings.GetActiveLocaleCultureInfos(user.Username, false).ToList();

string selectedActiveLocaleName = this.GetBinding<string>("ActiveLocaleName");

string selectedActiveLocaleName = (user.Username != UserSettings.Username ?
this.GetBinding<string>("ActiveLocaleName") :
UserSettings.ActiveLocaleCultureInfo.ToString());

if (selectedActiveLocaleName != null)
{
selectedActiveLocal = CultureInfo.CreateSpecificCulture(selectedActiveLocaleName);
if (!newActiveLocales.Contains(selectedActiveLocal))
{
if (user.Username != UserSettings.Username)
{
this.ShowFieldMessage("ActiveLocaleName", GetText("Website.Forms.Administrative.EditUserStep1.ActiveLocaleNotChecked"));
}
else
{
this.ShowFieldMessage("ActiveLocalesFormsHelper_Selected", GetText("Website.Forms.Administrative.EditUserStep1.NoActiveLocaleSelected"));
}
userValidated = false;
}
}
}
else
{
this.ShowFieldMessage("ActiveLocalesFormsHelper_Selected", GetText("Website.Forms.Administrative.EditUserStep1.NoActiveLocaleSelected"));
userValidated = false;
}

CultureInfo selectedActiveLocale = CultureInfo.CreateSpecificCulture(selectedActiveLocaleName);

string systemPerspectiveEntityToken = EntityTokenSerializer.Serialize(AttachingPoint.SystemPerspective.EntityToken);

@@ -359,14 +328,14 @@ private void saveCodeActivity_ExecuteCode(object sender, EventArgs e)
}
}

if (selectedActiveLocal != null)
if (selectedActiveLocale != null)
{
if (!UserSettings.GetCurrentActiveLocaleCultureInfo(user.Username).Equals(selectedActiveLocal))
if (!selectedActiveLocale.Equals(UserSettings.GetCurrentActiveLocaleCultureInfo(user.Username)))
{
reloadUsersConsoles = true;
}

UserSettings.SetCurrentActiveLocaleCultureInfo(user.Username, selectedActiveLocal);
UserSettings.SetCurrentActiveLocaleCultureInfo(user.Username, selectedActiveLocale);
}
else if (UserSettings.GetActiveLocaleCultureInfos(user.Username).Any())
{
@@ -398,18 +367,26 @@ private void saveCodeActivity_ExecuteCode(object sender, EventArgs e)
}

LoggingService.LogEntry("UserManagement",
$"C1 Console user '{user.Username}' updated by '{UserValidationFacade.GetUsername()}'.",
$"C1 Console user '{user.Username}' updated by '{UserValidationFacade.GetUsername()}'.",
LoggingService.Category.Audit,
TraceEventType.Information);

transactionScope.Complete();
}

if (reloadUsersConsoles)
if (UserSettings.GetCurrentActiveLocaleCultureInfo(user.Username) == null)
{
this.ShowFieldMessage(BindingNames.ActiveContentLanguage, "The user doesn't have permissions to access the language you selected here. Assign permissions so the user may access this.");
this.ShowMessage(DialogType.Warning, "User missing permissions for language", "The user doesn't have permissions to access the language you selected as 'Active content language'.");
}
else
{
foreach (string consoleId in GetConsoleIdsOpenedByCurrentUser())
if (reloadUsersConsoles)
{
ConsoleMessageQueueFacade.Enqueue(new RebootConsoleMessageQueueItem(), consoleId);
foreach (string consoleId in GetConsoleIdsOpenedByUser(user.Username))
{
ConsoleMessageQueueFacade.Enqueue(new RebootConsoleMessageQueueItem(), consoleId);
}
}
}

@@ -438,7 +415,7 @@ private void IsUserLoggedOn(object sender, System.Workflow.Activities.Conditiona
{
CultureInfo selectedActiveLocale = CultureInfo.CreateSpecificCulture(selectedActiveLocaleName);

if (!UserSettings.GetCurrentActiveLocaleCultureInfo(user.Username).Equals(selectedActiveLocale))
if (!selectedActiveLocale.Equals(UserSettings.GetCurrentActiveLocaleCultureInfo(user.Username)))
{
e.Result = ConsoleFacade.GetConsoleIdsByUsername(user.Username).Any();
return;
@@ -1,12 +1,14 @@
using System;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.Linq;
using System.Workflow.Activities;
using System.Xml.Linq;
using Composite.C1Console.Actions;
using Composite.C1Console.Events;
using Composite.C1Console.Users;
using Composite.Core.Logging;
using Composite.Data;
using Composite.Data.DynamicTypes;
using Composite.Data.Types;
@@ -22,7 +24,6 @@
using Microsoft.Practices.EnterpriseLibrary.Validation;

using SR = Composite.Core.ResourceSystem.StringResourceSystemFacade;
using Composite.Core.Logging;

namespace Composite.Plugins.Elements.ElementProviders.UserGroupElementProvider
{
@@ -66,6 +67,7 @@ private void step1CodeActivity_ShowDocument_ExecuteCode(object sender, EventArgs

UpdateFormDefinitionWithActivePerspectives(userGroup, bindingsElement, placeHolderElement);
UpdateFormDefinitionWithGlobalPermissions(userGroup, bindingsElement, placeHolderElement);
UpdateFormDefinitionWithActiveLocalePermissions(userGroup, bindingsElement, placeHolderElement);

var clientValidationRules = new Dictionary<string, List<ClientValidationRule>>();
clientValidationRules.Add("Name", ClientValidationRuleFacade.GetClientValidationRules(userGroup, "Name"));
@@ -139,6 +141,24 @@ private void saveCodeActivity_Save_ExecuteCode(object sender, EventArgs e)

UserGroupPerspectiveFacade.SetSerializedEntityTokens(userGroup.Id, newUserGroupEntityTokens);

List<CultureInfo> selectedUserGroupActiveLocales = ActiveLocalesFormsHelper.GetSelectedLocalesTypes(this.Bindings).ToList();

using (var connection = new DataConnection())
{
var existingLocales = connection.Get<IUserGroupActiveLocale>().Where(f=> f.UserGroupId == userGroup.Id).ToList();
var toDelete = existingLocales.Where(f => !selectedUserGroupActiveLocales.Contains(new CultureInfo(f.CultureName)));
connection.Delete<IUserGroupActiveLocale>(toDelete);

foreach (var localeToAdd in selectedUserGroupActiveLocales.Where(f => !existingLocales.Any(g => g.CultureName == f.Name)))
{
var toAdd = connection.CreateNew<IUserGroupActiveLocale>();
toAdd.Id = Guid.NewGuid();
toAdd.UserGroupId = userGroup.Id;
toAdd.CultureName = localeToAdd.Name;
connection.Add(toAdd);
}
}

SetSaveStatus(true);

LoggingService.LogEntry("UserManagement",
@@ -206,6 +226,28 @@ private void UpdateFormDefinitionWithGlobalPermissions(IUserGroup userGroup, XEl
helper.UpdateWithNewBindings(this.Bindings, permissionTypes);
}

private void UpdateFormDefinitionWithActiveLocalePermissions(IUserGroup userGroup, XElement bindingsElement, XElement placeHolderElement)
{
var helper = new ActiveLocalesFormsHelper(
SR.GetString("Composite.Plugins.UserGroupElementProvider", "EditUserGroup.EditUserGroupStep1.ActiveLocalesFieldLabel"),
SR.GetString("Composite.Plugins.UserGroupElementProvider", "EditUserGroup.EditUserGroupStep1.ActiveLocalesMultiSelectLabel"),
SR.GetString("Composite.Plugins.UserGroupElementProvider", "EditUserGroup.EditUserGroupStep1.ActiveLocalesMultiSelectHelp")
);

bindingsElement.Add(helper.GetBindingsMarkup());
placeHolderElement.Add(helper.GetFormMarkup());

EntityToken rootEntityToken = ElementFacade.GetRootsWithNoSecurity().Select(f => f.ElementHandle.EntityToken).Single();

using (var connection = new DataConnection())
{
IEnumerable<CultureInfo> activeCultures = null;
activeCultures = connection.Get<IUserGroupActiveLocale>().Where(f => f.UserGroupId == userGroup.Id).Select(f => new CultureInfo(f.CultureName));
helper.UpdateWithNewBindings(this.Bindings, activeCultures);
}

}



private void UpdateFormDefinitionWithActivePerspectives(IUserGroup userGroup, XElement bindingsElement, XElement placeHolderElement)
@@ -1,6 +1,7 @@
using System;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using Composite.Data;
using Composite.Data.Types;
@@ -46,6 +47,19 @@ public static IReadOnlyCollection<Guid> GetUserGroupIds(string username)
});
}

/// <exclude />

public static IEnumerable<CultureInfo> GetUserGroupActiveCultures(string username)
{
Verify.ArgumentNotNullOrEmpty(username, nameof(username));

return
from ugal in DataFacade.GetData<IUserGroupActiveLocale>()
join uugr in DataFacade.GetData<IUserUserGroupRelation>() on ugal.UserGroupId equals uugr.UserGroupId
join user in DataFacade.GetData<IUser>() on uugr.UserId equals user.Id
where user.Username == username
select CultureInfo.CreateSpecificCulture(ugal.CultureName);
}


private static void OnDataChanged(object sender, StoreEventArgs storeEventArgs)
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using Composite.C1Console.Elements;
@@ -67,16 +67,30 @@ public override IEnumerable<EntityToken> GetEntityTokens(EntityToken childEntity

private AncestorMatch GetAncestorFromParentFilter(TreeNodeDynamicContext dynamicContext)
{
var dataNode = dynamicContext.CurrentTreeNode as DataElementsTreeNode;
if(dataNode == null) return null;

var parentIdFilter = dynamicContext.CurrentTreeNode.FilterNodes.OfType<ParentIdFilterNode>().FirstOrDefault();
if (parentIdFilter == null) return null;
var treeNode = dynamicContext.CurrentTreeNode;
if (treeNode is DataElementsTreeNode)
{
var parentIdFilter = treeNode.FilterNodes.OfType<ParentIdFilterNode>().FirstOrDefault();
if (parentIdFilter == null) return null;

Type ancestorType = parentIdFilter.ParentFilterType;
object key = parentIdFilter.FindParentKeyValue(dynamicContext);

return key == null ? null : new AncestorMatch { InterfaceType = ancestorType, KeyValue = key};
}

Type ancestorType = parentIdFilter.ParentFilterType;
object key = parentIdFilter.FindParentKeyValue(dynamicContext);
if (treeNode is DataFolderElementsTreeNode
&& dynamicContext.CurrentEntityToken is TreeDataFieldGroupingElementEntityToken groupEntityToken
&& groupEntityToken.ChildGeneratingDataElementsReferenceValue != null)
{
return new AncestorMatch
{
InterfaceType = groupEntityToken.ChildGeneratingDataElementsReferenceType,
KeyValue = groupEntityToken.ChildGeneratingDataElementsReferenceValue
};
}

return key == null ? null : new AncestorMatch { InterfaceType = ancestorType, KeyValue = key};
return null;
}


@@ -1,8 +1,10 @@
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Net;
using Composite.C1Console.Security;
using System.Threading;
using Composite.Core.Caching;
using Composite.Data;


namespace Composite.C1Console.Users
@@ -109,7 +111,17 @@ public static CultureInfo ActiveLocaleCultureInfo
/// <exclude />
public static CultureInfo GetCurrentActiveLocaleCultureInfo(string username)
{
return _implementation.GetCurrentActiveLocaleCultureInfo(username);
var key = "CurrentActiveCulture" + username;
if (RequestLifetimeCache.HasKey(key)) return RequestLifetimeCache.TryGet<CultureInfo>(key);

var cultureInfo = _implementation.GetCurrentActiveLocaleCultureInfo(username);
var allowedCultures = GetActiveLocaleCultureInfos(username, true);

if( !allowedCultures.Contains(cultureInfo)) cultureInfo = allowedCultures.FirstOrDefault();

if (cultureInfo != null && !RequestLifetimeCache.HasKey(key)) RequestLifetimeCache.Add(key, cultureInfo);

return cultureInfo ?? CultureInfo.InvariantCulture;
}


@@ -170,22 +182,24 @@ public static void RemoveActiveLocaleCultureInfo(string username, CultureInfo cu

// Overload
/// <summary>
/// This is an overload for GetActiveLocaleCultureInfos(string username)
/// This is an overload for GetActiveLocaleCultureInfos(string username, includeGroupAssignedCultures = true)
/// using the current username.
/// </summary>
public static IEnumerable<CultureInfo> ActiveLocaleCultureInfos
{
get
{
return GetActiveLocaleCultureInfos(UserSettings.Username);
return GetActiveLocaleCultureInfos(UserSettings.Username, true);
}
}


/// <exclude />
public static IEnumerable<CultureInfo> GetActiveLocaleCultureInfos(string username)
public static IEnumerable<CultureInfo> GetActiveLocaleCultureInfos(string username, bool includeGroupAssignedCultures = true)
{
return _implementation.GetActiveLocaleCultureInfos(username);
return includeGroupAssignedCultures ?
_implementation.GetActiveLocaleCultureInfos(username).Union(UserGroupFacade.GetUserGroupActiveCultures(username)) :
_implementation.GetActiveLocaleCultureInfos(username);
}


@@ -572,13 +572,24 @@ protected string GetCurrentConsoleId()
return managementConsoleMessageService.CurrentConsoleId;
}


/// <exclude />
protected IEnumerable<string> GetConsoleIdsOpenedByCurrentUser()
{
string currentConsoleId = GetCurrentConsoleId();
return GetConsoleIdsOpenedByUser(UserSettings.Username);
}

return ConsoleFacade.GetConsoleIdsByUsername(UserSettings.Username).Union(new[] { currentConsoleId });
/// <exclude />
protected IEnumerable<string> GetConsoleIdsOpenedByUser(string username)
{
if (UserSettings.Username == username)
{
string currentConsoleId = GetCurrentConsoleId();
return ConsoleFacade.GetConsoleIdsByUsername(username).Union(new[] { currentConsoleId });
}
else
{
return ConsoleFacade.GetConsoleIdsByUsername(username);
}
}


@@ -256,6 +256,7 @@
<Compile Include="Core\WebClient\Renderings\INonCachebleRequestHostnameMapper.cs" />
<Compile Include="Core\WebClient\Services\WampRouter\WampRouteWrapper.cs" />
<Compile Include="Data\Caching\CachedTable.cs" />
<Compile Include="Data\Types\IUserGroupActiveLocale.cs" />
<Compile Include="Data\Types\VersionedDataHelperContract.cs" />
<Compile Include="Plugins\Elements\UrlToEntityToken\WebsiteFileUrlToEntityTokenMapper.cs" />
<Compile Include="Plugins\Elements\UrlToEntityToken\MediaUrlToEntityTokenMapper.cs" />

0 comments on commit 566caaf

Please sign in to comment.
You can’t perform that action at this time.