2013-11-12 15:24:08 +11:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Globalization;
|
2013-11-07 17:16:22 +01:00
|
|
|
|
using System.Linq;
|
|
|
|
|
|
using System.Net.Http.Formatting;
|
|
|
|
|
|
using System.Web.Security;
|
|
|
|
|
|
using Umbraco.Core;
|
2014-03-13 15:25:30 +11:00
|
|
|
|
using Umbraco.Core.Persistence.Querying;
|
2014-03-18 20:36:02 +11:00
|
|
|
|
using Umbraco.Core.Security;
|
2013-11-07 17:16:22 +01:00
|
|
|
|
using Umbraco.Web.Models.Trees;
|
|
|
|
|
|
using Umbraco.Web.Mvc;
|
2013-11-20 14:18:03 +11:00
|
|
|
|
using Umbraco.Web.WebApi.Filters;
|
2013-11-07 17:16:22 +01:00
|
|
|
|
using umbraco;
|
|
|
|
|
|
using umbraco.BusinessLogic.Actions;
|
|
|
|
|
|
using Constants = Umbraco.Core.Constants;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Umbraco.Web.Trees
|
|
|
|
|
|
{
|
2013-11-20 14:18:03 +11:00
|
|
|
|
//We will not allow the tree to render unless the user has access to any of the sections that the tree gets rendered
|
|
|
|
|
|
// this is not ideal but until we change permissions to be tree based (not section) there's not much else we can do here.
|
|
|
|
|
|
[UmbracoApplicationAuthorize(
|
|
|
|
|
|
Constants.Applications.Content,
|
|
|
|
|
|
Constants.Applications.Media,
|
|
|
|
|
|
Constants.Applications.Members)]
|
2013-11-07 17:16:22 +01:00
|
|
|
|
[LegacyBaseTree(typeof (loadMembers))]
|
|
|
|
|
|
[Tree(Constants.Applications.Members, Constants.Trees.Members, "Members")]
|
|
|
|
|
|
[PluginController("UmbracoTrees")]
|
|
|
|
|
|
[CoreTree]
|
|
|
|
|
|
public class MemberTreeController : TreeController
|
|
|
|
|
|
{
|
2014-03-18 20:36:02 +11:00
|
|
|
|
public MemberTreeController()
|
|
|
|
|
|
{
|
|
|
|
|
|
_provider = Core.Security.MembershipProviderExtensions.GetMembersMembershipProvider();
|
2014-09-19 09:47:42 +10:00
|
|
|
|
_isUmbracoProvider = _provider.IsUmbracoMembershipProvider();
|
2014-03-18 20:36:02 +11:00
|
|
|
|
}
|
|
|
|
|
|
|
2014-09-19 09:47:42 +10:00
|
|
|
|
private readonly MembershipProvider _provider;
|
|
|
|
|
|
private readonly bool _isUmbracoProvider;
|
2014-03-18 20:36:02 +11:00
|
|
|
|
|
2013-11-07 17:16:22 +01:00
|
|
|
|
protected override TreeNodeCollection GetTreeNodes(string id, FormDataCollection queryStrings)
|
|
|
|
|
|
{
|
|
|
|
|
|
var nodes = new TreeNodeCollection();
|
|
|
|
|
|
|
|
|
|
|
|
if (id == Constants.System.Root.ToInvariantString())
|
|
|
|
|
|
{
|
2014-09-19 09:47:42 +10:00
|
|
|
|
nodes.Add(
|
|
|
|
|
|
CreateTreeNode("all-members", id, queryStrings, "All Members", "icon-users", false,
|
|
|
|
|
|
queryStrings.GetValue<string>("application") + TreeAlias.EnsureStartsWith('/') + "/list/all-members"));
|
2014-03-13 15:25:30 +11:00
|
|
|
|
|
2014-09-19 09:47:42 +10:00
|
|
|
|
if (_isUmbracoProvider)
|
2013-11-07 17:16:22 +01:00
|
|
|
|
{
|
2014-09-19 09:47:42 +10:00
|
|
|
|
nodes.AddRange(Services.MemberTypeService.GetAll()
|
|
|
|
|
|
.Select(memberType =>
|
|
|
|
|
|
CreateTreeNode(memberType.Alias, id, queryStrings, memberType.Name, "icon-users", false,
|
|
|
|
|
|
queryStrings.GetValue<string>("application") + TreeAlias.EnsureStartsWith('/') + "/list/" + memberType.Alias)));
|
2013-11-07 17:16:22 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return nodes;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2013-11-19 18:31:15 +11:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Allows for developers to override this in case their provider does some funky stuff to search
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="letter"></param>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
/// <remarks>
|
|
|
|
|
|
/// We're going to do a special check here - for active dir provider or sql provider
|
|
|
|
|
|
/// </remarks>
|
|
|
|
|
|
protected virtual MembershipUserCollection FindUsersByName(char letter)
|
|
|
|
|
|
{
|
|
|
|
|
|
int total;
|
2014-03-18 20:36:02 +11:00
|
|
|
|
if (_provider is SqlMembershipProvider)
|
2013-11-19 18:31:15 +11:00
|
|
|
|
{
|
|
|
|
|
|
//this provider uses the % syntax
|
2014-03-18 20:36:02 +11:00
|
|
|
|
return _provider.FindUsersByName(letter + "%", 0, 9999, out total);
|
2013-11-19 18:31:15 +11:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2014-09-19 09:47:42 +10:00
|
|
|
|
//the AD provider - and potentially all other providers will use the asterisk syntax.
|
2014-03-18 20:36:02 +11:00
|
|
|
|
return _provider.FindUsersByName(letter + "*", 0, 9999, out total);
|
2013-11-19 18:31:15 +11:00
|
|
|
|
}
|
2014-09-19 09:47:42 +10:00
|
|
|
|
|
2013-11-19 18:31:15 +11:00
|
|
|
|
}
|
|
|
|
|
|
|
2013-11-18 15:58:53 +11:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// We'll see if it is a GUID, if so we'll ensure to format it without hyphens
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="providerUserKey"></param>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
private string GetNodeIdForCustomProvider(object providerUserKey)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (providerUserKey == null) throw new ArgumentNullException("providerUserKey");
|
|
|
|
|
|
var guidAttempt = providerUserKey.TryConvertTo<Guid>();
|
|
|
|
|
|
if (guidAttempt.Success)
|
|
|
|
|
|
{
|
|
|
|
|
|
return guidAttempt.Result.ToString("N");
|
|
|
|
|
|
}
|
|
|
|
|
|
return providerUserKey.ToString();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2013-11-07 17:16:22 +01:00
|
|
|
|
protected override MenuItemCollection GetMenuForNode(string id, FormDataCollection queryStrings)
|
|
|
|
|
|
{
|
|
|
|
|
|
var menu = new MenuItemCollection();
|
|
|
|
|
|
|
|
|
|
|
|
if (id == Constants.System.Root.ToInvariantString())
|
|
|
|
|
|
{
|
2013-11-17 13:43:04 +11:00
|
|
|
|
// root actions
|
2014-03-18 20:36:02 +11:00
|
|
|
|
if (_provider.IsUmbracoMembershipProvider())
|
2013-11-17 13:43:04 +11:00
|
|
|
|
{
|
|
|
|
|
|
//set default
|
|
|
|
|
|
menu.DefaultMenuAlias = ActionNew.Instance.Alias;
|
2013-11-07 17:16:22 +01:00
|
|
|
|
|
2013-11-17 13:43:04 +11:00
|
|
|
|
//Create the normal create action
|
|
|
|
|
|
menu.Items.Add<ActionNew>(ui.Text("actions", ActionNew.Instance.Alias));
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
//Create a custom create action - this does not launch a dialog, it just navigates to the create screen
|
2014-09-19 09:47:42 +10:00
|
|
|
|
// we'll create it based on the ActionNew so it maintains the same icon properties, name, etc...
|
2013-11-17 13:43:04 +11:00
|
|
|
|
var createMenuItem = new MenuItem(ActionNew.Instance);
|
|
|
|
|
|
//we want to go to this route: /member/member/edit/-1?create=true
|
|
|
|
|
|
createMenuItem.NavigateToRoute("/member/member/edit/-1?create=true");
|
|
|
|
|
|
menu.Items.Add(createMenuItem);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2013-11-07 17:16:22 +01:00
|
|
|
|
menu.Items.Add<RefreshNode, ActionRefresh>(ui.Text("actions", ActionRefresh.Instance.Alias), true);
|
|
|
|
|
|
return menu;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2014-09-19 09:47:42 +10:00
|
|
|
|
menu.Items.Add<RefreshNode, ActionRefresh>(ui.Text("actions", ActionRefresh.Instance.Alias), false);
|
|
|
|
|
|
|
2013-11-07 17:16:22 +01:00
|
|
|
|
return menu;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2013-10-01 15:36:08 +10:00
|
|
|
|
}
|