using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Umbraco.Web.Security
{
///
/// This is used specifically to assign a default 'app' to a particular section in order to validate the
/// currently logged in user's allowed applications
///
///
/// This relates to these issues:
/// http://issues.umbraco.org/issue/U4-2021
/// http://issues.umbraco.org/issue/U4-529
///
/// In order to fix these issues we need to pass in an 'app' parameter but since we don't want to break compatibility
/// we will create this mapping to map a 'default application' to a section action (like creating or deleting)
///
public static class LegacyDefaultAppMapping
{
///
/// Constructor that assigns all initial known mappings
///
static LegacyDefaultAppMapping()
{
}
private static readonly ConcurrentDictionary NodeTypeAliasMapping = new ConcurrentDictionary();
///
/// Adds the default app mapping to the node type
///
/// The nodeType is the same nodeType found in the UI.xml
/// The default app associated with this nodeType if the 'app' parameter was not detected
public static void AddNodeTypeMappingForCreateDialog(string nodeType, string defaultApp)
{
NodeTypeAliasMapping.AddOrUpdate(nodeType, s => defaultApp, (s, s1) => defaultApp);
}
internal static string GetDefaultAppForCreateDialog(string nodeTypeAlias)
{
string app;
return NodeTypeAliasMapping.TryGetValue(nodeTypeAlias, out app) ? app : null;
}
}
}