Skip to content

Commit

Permalink
Merge pull request #693 from Orckestra/dev
Browse files Browse the repository at this point in the history
C1 CMS 6.7
  • Loading branch information
mawtex authored Oct 28, 2019
2 parents 66e1af9 + 2e33ce0 commit 999992a
Show file tree
Hide file tree
Showing 55 changed files with 707 additions and 422 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,16 @@ public static void ReloadPageElementInConsole(IPage page)

public static void ReloadDataElementInConsole(DataEntityToken dataEntityToken)
{
if (dataEntityToken == null) throw new ArgumentNullException(nameof(dataEntityToken));

var parentEntityTokens = AuxiliarySecurityAncestorFacade.GetParents(dataEntityToken);

foreach (var parentEntityToken in parentEntityTokens)
if (parentEntityTokens != null)
{
ConsoleMessageQueueFacade.Enqueue(new RefreshTreeMessageQueueItem { EntityToken = parentEntityToken }, null);
foreach (var parentEntityToken in parentEntityTokens)
{
ConsoleMessageQueueFacade.Enqueue(new RefreshTreeMessageQueueItem { EntityToken = parentEntityToken }, null);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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>>
{
Expand Down Expand Up @@ -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));
}


Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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())
{
Expand Down Expand Up @@ -398,18 +367,26 @@ from r in oldRelations
}

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);
}
}
}

Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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
{
Expand Down Expand Up @@ -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"));
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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)
Expand Down
Loading

0 comments on commit 999992a

Please sign in to comment.