From 306e3147ebb4e90636079a7b7071fed06fa90cc3 Mon Sep 17 00:00:00 2001 From: vfedosevich Date: Tue, 26 Mar 2013 10:57:01 +0300 Subject: [PATCH 1/2] Added maximum OrgId length parameter to hosted organization policies. --- .../SettingsExchangePolicy.ascx.resx | 3 + .../OrganizationCreateOrganization.ascx.cs | 74 +++++++--- .../WebsitePanel/SettingsExchangePolicy.ascx | 14 ++ .../SettingsExchangePolicy.ascx.cs | 26 ++-- .../SettingsExchangePolicy.ascx.designer.cs | 30 +++- .../OrgIdPolicyEditor.ascx.resx | 132 ++++++++++++++++++ .../UserControls/OrgIdPolicyEditor.ascx | 18 +++ .../UserControls/OrgIdPolicyEditor.ascx.cs | 69 +++++++++ .../OrgIdPolicyEditor.ascx.designer.cs | 78 +++++++++++ .../WebsitePanel.Portal.Modules.csproj | 9 ++ 10 files changed, 419 insertions(+), 34 deletions(-) create mode 100644 WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/UserControls/App_LocalResources/OrgIdPolicyEditor.ascx.resx create mode 100644 WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/UserControls/OrgIdPolicyEditor.ascx create mode 100644 WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/UserControls/OrgIdPolicyEditor.ascx.cs create mode 100644 WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/UserControls/OrgIdPolicyEditor.ascx.designer.cs diff --git a/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/App_LocalResources/SettingsExchangePolicy.ascx.resx b/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/App_LocalResources/SettingsExchangePolicy.ascx.resx index 84c57ed9..2303aa66 100644 --- a/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/App_LocalResources/SettingsExchangePolicy.ascx.resx +++ b/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/App_LocalResources/SettingsExchangePolicy.ascx.resx @@ -120,4 +120,7 @@ User Password Policy + + Organization Id Policy + \ No newline at end of file diff --git a/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/ExchangeServer/OrganizationCreateOrganization.ascx.cs b/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/ExchangeServer/OrganizationCreateOrganization.ascx.cs index f29b3cf0..990a5bed 100644 --- a/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/ExchangeServer/OrganizationCreateOrganization.ascx.cs +++ b/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/ExchangeServer/OrganizationCreateOrganization.ascx.cs @@ -27,8 +27,6 @@ // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. using System; -using System.Data; -using System.Text; using System.Collections.Generic; using WebsitePanel.EnterpriseServer; using WebsitePanel.Providers.HostedSolution; @@ -39,18 +37,19 @@ namespace WebsitePanel.Portal.ExchangeServer { protected void Page_Load(object sender, EventArgs e) { - DomainInfo[] domains = ES.Services.Servers.GetMyDomains(PanelSecurity.PackageId); - Organization[] orgs = ES.Services.Organizations.GetOrganizations(PanelSecurity.PackageId, false); - - List list = new List(); + var list = new List(); + SetPolicy(PanelSecurity.PackageId, UserSettings.EXCHANGE_POLICY, "OrgIdPolicy"); foreach (Organization o in orgs) { OrganizationDomainName[] tmpList = ES.Services.Organizations.GetOrganizationDomains(o.Id); - foreach (OrganizationDomainName name in tmpList) list.Add(name); + foreach (OrganizationDomainName name in tmpList) + { + list.Add(name); + } } foreach (DomainInfo d in domains) @@ -65,9 +64,11 @@ namespace WebsitePanel.Portal.ExchangeServer bAdd = false; break; } - } - if (bAdd) ddlDomains.Items.Add(d.DomainName.ToLower()); + if (bAdd) + { + ddlDomains.Items.Add(d.DomainName.ToLower()); + } } } @@ -77,6 +78,50 @@ namespace WebsitePanel.Portal.ExchangeServer } } + public void SetPolicy(int packageId, string settingsName, string key) + { + PackageInfo package = PackagesHelper.GetCachedPackage(packageId); + + if (package != null) + { + SetOrgIdPolicy(package.UserId, settingsName, key); + } + } + + public void SetOrgIdPolicy(int userId, string settingsName, string key) + { + UserInfo user = UsersHelper.GetCachedUser(userId); + + if (user != null) + { + UserSettings settings = ES.Services.Users.GetUserSettings(userId, settingsName); + + if (settings != null && settings["OrgIdPolicy"] != null) + { + SetOrgIdPolicy(settings); + } + } + } + + private void SetOrgIdPolicy(UserSettings settings) + { + string policyValue = settings["OrgIdPolicy"]; + string[] values = policyValue.Split(';'); + + if (values.Length > 1 && Convert.ToBoolean(values[0])) + { + try + { + int maxLength = Convert.ToInt32(values[1]); + txtOrganizationID.MaxLength = maxLength; + valRequireCorrectOrgID.ValidationExpression = string.Format("[a-zA-Z0-9.-]{{1,{0}}}", maxLength); + } + catch (Exception) + { + } + } + } + protected void btnCreate_Click(object sender, EventArgs e) { CreateOrganization(); @@ -85,14 +130,13 @@ namespace WebsitePanel.Portal.ExchangeServer private void CreateOrganization() { if (!Page.IsValid) + { return; + } try { - - int itemId = ES.Services.Organizations.CreateOrganization(PanelSecurity.PackageId, - txtOrganizationID.Text.Trim().ToLower(), txtOrganizationName.Text.Trim().ToLower(), - ddlDomains.SelectedValue.Trim().ToLower()); + int itemId = ES.Services.Organizations.CreateOrganization(PanelSecurity.PackageId, txtOrganizationID.Text.Trim().ToLower(), txtOrganizationName.Text.Trim().ToLower(), ddlDomains.SelectedValue.Trim().ToLower()); if (itemId < 0) { @@ -100,9 +144,7 @@ namespace WebsitePanel.Portal.ExchangeServer return; } - Response.Redirect(EditUrl("SpaceID", PanelSecurity.PackageId.ToString(), "organization_home", - "ItemID=" + itemId)); - + Response.Redirect(EditUrl("SpaceID", PanelSecurity.PackageId.ToString(), "organization_home", "ItemID=" + itemId)); } catch (Exception ex) { diff --git a/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/SettingsExchangePolicy.ascx b/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/SettingsExchangePolicy.ascx index d57e25d6..251b3972 100644 --- a/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/SettingsExchangePolicy.ascx +++ b/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/SettingsExchangePolicy.ascx @@ -1,5 +1,6 @@ <%@ Control Language="C#" AutoEventWireup="true" CodeBehind="SettingsExchangePolicy.ascx.cs" Inherits="WebsitePanel.Portal.SettingsExchangePolicy" %> <%@ Register Src="UserControls/PasswordPolicyEditor.ascx" TagName="PasswordPolicyEditor" TagPrefix="wsp" %> +<%@ Register Src="UserControls/OrgIdPolicyEditor.ascx" TagName="OrgIdPolicyEditor" TagPrefix="wsp" %> <%@ Register TagPrefix="wsp" TagName="CollapsiblePanel" Src="UserControls/CollapsiblePanel.ascx" %> + + + + + + + + + +
+ + +
\ No newline at end of file diff --git a/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/SettingsExchangePolicy.ascx.cs b/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/SettingsExchangePolicy.ascx.cs index 8aa6df73..e9371049 100644 --- a/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/SettingsExchangePolicy.ascx.cs +++ b/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/SettingsExchangePolicy.ascx.cs @@ -26,33 +26,27 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -using System; -using System.Data; -using System.Configuration; -using System.Collections; -using System.Web; -using System.Web.Security; -using System.Web.UI; -using System.Web.UI.WebControls; -using System.Web.UI.WebControls.WebParts; -using System.Web.UI.HtmlControls; - using WebsitePanel.EnterpriseServer; namespace WebsitePanel.Portal { - public partial class SettingsExchangePolicy : WebsitePanelControlBase, IUserSettingsEditorControl + public partial class SettingsExchangePolicy : WebsitePanelControlBase, IUserSettingsEditorControl { + #region IUserSettingsEditorControl Members + public void BindSettings(UserSettings settings) { // mailbox - mailboxPasswordPolicy.Value = settings["MailboxPasswordPolicy"]; + mailboxPasswordPolicy.Value = settings["MailboxPasswordPolicy"]; + orgIdPolicy.Value = settings["OrgIdPolicy"]; } public void SaveSettings(UserSettings settings) { - // mailbox - settings["MailboxPasswordPolicy"] = mailboxPasswordPolicy.Value; + settings["MailboxPasswordPolicy"] = mailboxPasswordPolicy.Value; + settings["OrgIdPolicy"] = orgIdPolicy.Value; } - } + + #endregion + } } \ No newline at end of file diff --git a/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/SettingsExchangePolicy.ascx.designer.cs b/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/SettingsExchangePolicy.ascx.designer.cs index e3a47369..c03ba832 100644 --- a/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/SettingsExchangePolicy.ascx.designer.cs +++ b/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/SettingsExchangePolicy.ascx.designer.cs @@ -1,10 +1,9 @@ //------------------------------------------------------------------------------ // // This code was generated by a tool. -// Runtime Version:2.0.50727.1433 // // Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. +// the code is regenerated. // //------------------------------------------------------------------------------ @@ -39,5 +38,32 @@ namespace WebsitePanel.Portal { /// To modify move field declaration from designer file to code-behind file. /// protected global::WebsitePanel.Portal.PasswordPolicyEditor mailboxPasswordPolicy; + + /// + /// secOrg control. + /// + /// + /// Auto-generated field. + /// To modify move field declaration from designer file to code-behind file. + /// + protected global::WebsitePanel.Portal.CollapsiblePanel secOrg; + + /// + /// OrgIdPanel control. + /// + /// + /// Auto-generated field. + /// To modify move field declaration from designer file to code-behind file. + /// + protected global::System.Web.UI.WebControls.Panel OrgIdPanel; + + /// + /// orgIdPolicy control. + /// + /// + /// Auto-generated field. + /// To modify move field declaration from designer file to code-behind file. + /// + protected global::WebsitePanel.Portal.UserControls.OrgIdPolicyEditor orgIdPolicy; } } diff --git a/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/UserControls/App_LocalResources/OrgIdPolicyEditor.ascx.resx b/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/UserControls/App_LocalResources/OrgIdPolicyEditor.ascx.resx new file mode 100644 index 00000000..d34ec2b5 --- /dev/null +++ b/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/UserControls/App_LocalResources/OrgIdPolicyEditor.ascx.resx @@ -0,0 +1,132 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + Enable Policy + + + Maximum OrgId length: + + + * + + + * + + \ No newline at end of file diff --git a/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/UserControls/OrgIdPolicyEditor.ascx b/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/UserControls/OrgIdPolicyEditor.ascx new file mode 100644 index 00000000..4321cc18 --- /dev/null +++ b/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/UserControls/OrgIdPolicyEditor.ascx @@ -0,0 +1,18 @@ +<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="OrgIdPolicyEditor.ascx.cs" Inherits="WebsitePanel.Portal.UserControls.OrgIdPolicyEditor" %> + + + + + + + + +
+ + + + + +
+
+
\ No newline at end of file diff --git a/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/UserControls/OrgIdPolicyEditor.ascx.cs b/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/UserControls/OrgIdPolicyEditor.ascx.cs new file mode 100644 index 00000000..43d0e214 --- /dev/null +++ b/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/UserControls/OrgIdPolicyEditor.ascx.cs @@ -0,0 +1,69 @@ +using System; +using System.Text; +using System.Web.UI; + +namespace WebsitePanel.Portal.UserControls +{ + public partial class OrgIdPolicyEditor : UserControl + { + #region Properties + + public string Value + { + get + { + var sb = new StringBuilder(); + sb.Append(enablePolicyCheckBox.Checked.ToString()).Append(";"); + sb.Append(txtMaximumLength.Text).Append(";"); + + return sb.ToString(); + } + set + { + if (String.IsNullOrEmpty(value)) + { + enablePolicyCheckBox.Checked = true; + txtMaximumLength.Text = "128"; + } + else + { + try + { + string[] parts = value.Split(';'); + enablePolicyCheckBox.Checked = Utils.ParseBool(parts[0], false); + txtMaximumLength.Text = parts[1]; + } + catch + { + } + } + + ToggleControls(); + } + } + + #endregion + + #region Methods + + protected void Page_Load(object sender, EventArgs e) + { + } + + private void ToggleControls() + { + PolicyTable.Visible = enablePolicyCheckBox.Checked; + } + + #endregion + + #region Event Handlers + + protected void EnablePolicy_CheckedChanged(object sender, EventArgs e) + { + ToggleControls(); + } + + #endregion + } +} \ No newline at end of file diff --git a/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/UserControls/OrgIdPolicyEditor.ascx.designer.cs b/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/UserControls/OrgIdPolicyEditor.ascx.designer.cs new file mode 100644 index 00000000..ddd87fbb --- /dev/null +++ b/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/UserControls/OrgIdPolicyEditor.ascx.designer.cs @@ -0,0 +1,78 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace WebsitePanel.Portal.UserControls { + + + public partial class OrgIdPolicyEditor { + + /// + /// OrgIdPolicyPanel control. + /// + /// + /// Auto-generated field. + /// To modify move field declaration from designer file to code-behind file. + /// + protected global::System.Web.UI.UpdatePanel OrgIdPolicyPanel; + + /// + /// enablePolicyCheckBox control. + /// + /// + /// Auto-generated field. + /// To modify move field declaration from designer file to code-behind file. + /// + protected global::System.Web.UI.WebControls.CheckBox enablePolicyCheckBox; + + /// + /// PolicyTable control. + /// + /// + /// Auto-generated field. + /// To modify move field declaration from designer file to code-behind file. + /// + protected global::System.Web.UI.HtmlControls.HtmlTable PolicyTable; + + /// + /// lblMaximumLength control. + /// + /// + /// Auto-generated field. + /// To modify move field declaration from designer file to code-behind file. + /// + protected global::System.Web.UI.WebControls.Label lblMaximumLength; + + /// + /// txtMaximumLength control. + /// + /// + /// Auto-generated field. + /// To modify move field declaration from designer file to code-behind file. + /// + protected global::System.Web.UI.WebControls.TextBox txtMaximumLength; + + /// + /// valRequireMaxLength control. + /// + /// + /// Auto-generated field. + /// To modify move field declaration from designer file to code-behind file. + /// + protected global::System.Web.UI.WebControls.RequiredFieldValidator valRequireMaxLength; + + /// + /// valCorrectMaxLength control. + /// + /// + /// Auto-generated field. + /// To modify move field declaration from designer file to code-behind file. + /// + protected global::System.Web.UI.WebControls.RegularExpressionValidator valCorrectMaxLength; + } +} diff --git a/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/WebsitePanel.Portal.Modules.csproj b/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/WebsitePanel.Portal.Modules.csproj index 5a320f77..505af506 100644 --- a/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/WebsitePanel.Portal.Modules.csproj +++ b/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/WebsitePanel.Portal.Modules.csproj @@ -412,6 +412,13 @@ EditFeedsList.ascx + + OrgIdPolicyEditor.ascx + ASPXCodeBehind + + + OrgIdPolicyEditor.ascx + MonitoringPage.aspx ASPXCodeBehind @@ -3855,6 +3862,7 @@ + @@ -4991,6 +4999,7 @@ Designer + Designer From 252d5185379fc1f745d13f8439cc48bb3dbdc4dd Mon Sep 17 00:00:00 2001 From: vfedosevich Date: Thu, 28 Mar 2013 16:14:51 +0300 Subject: [PATCH 2/2] Check OrgId policy while adding hosted organization if "Automated Hosted Organization" checked on. --- .../OrganizationProxy.cs | 86 +++++++++++++++++++ .../HostedSolution/OrganizationController.cs | 2 +- .../esOrganizations.asmx.cs | 6 ++ .../WebsitePanel/UserCreateSpace.ascx.cs | 47 +++++++++- 4 files changed, 138 insertions(+), 3 deletions(-) diff --git a/WebsitePanel/Sources/WebsitePanel.EnterpriseServer.Client/OrganizationProxy.cs b/WebsitePanel/Sources/WebsitePanel.EnterpriseServer.Client/OrganizationProxy.cs index 87b2169c..088e33d6 100644 --- a/WebsitePanel/Sources/WebsitePanel.EnterpriseServer.Client/OrganizationProxy.cs +++ b/WebsitePanel/Sources/WebsitePanel.EnterpriseServer.Client/OrganizationProxy.cs @@ -62,6 +62,8 @@ namespace WebsitePanel.EnterpriseServer.HostedSolution { [System.Xml.Serialization.XmlIncludeAttribute(typeof(ResultObject))] [System.Xml.Serialization.XmlIncludeAttribute(typeof(ServiceProviderItem))] public partial class esOrganizations : Microsoft.Web.Services3.WebServicesClientProtocol { + + private System.Threading.SendOrPostCallback CheckOrgIdExistsOperationCompleted; private System.Threading.SendOrPostCallback CreateOrganizationOperationCompleted; @@ -117,6 +119,9 @@ namespace WebsitePanel.EnterpriseServer.HostedSolution { public esOrganizations() { this.Url = "http://localhost:9002/esOrganizations.asmx"; } + + /// + public event CheckOrgIdExistsCompletedEventHandler CheckOrgIdExistsCompleted; /// public event CreateOrganizationCompletedEventHandler CreateOrganizationCompleted; @@ -192,6 +197,55 @@ namespace WebsitePanel.EnterpriseServer.HostedSolution { /// public event GetPasswordPolicyCompletedEventHandler GetPasswordPolicyCompleted; + + /// + [System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://tempuri.org/CheckOrgIdExists", RequestNamespace = "http://tempuri.org/", ResponseNamespace = "http://tempuri.org/", Use = System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle = System.Web.Services.Protocols.SoapParameterStyle.Wrapped)] + public bool CheckOrgIdExists(string orgId) + { + object[] results = this.Invoke("CheckOrgIdExists", new object[] { + orgId}); + return ((bool)(results[0])); + } + + /// + public System.IAsyncResult BeginCheckOrgIdExists(string orgId, System.AsyncCallback callback, object asyncState) + { + return this.BeginInvoke("CheckOrgIdExists", new object[] { + orgId}, callback, asyncState); + } + + /// + public bool EndCheckOrgIdExists(System.IAsyncResult asyncResult) + { + object[] results = this.EndInvoke(asyncResult); + return ((bool)(results[0])); + } + + /// + public void CheckOrgIdExistsAsync(string orgId) + { + this.CheckOrgIdExistsAsync(orgId, null); + } + + /// + public void CheckOrgIdExistsAsync(string orgId, object userState) + { + if ((this.CheckOrgIdExistsOperationCompleted == null)) + { + this.CheckOrgIdExistsOperationCompleted = new System.Threading.SendOrPostCallback(this.OnCheckOrgIdExistsOperationCompleted); + } + this.InvokeAsync("CheckOrgIdExists", new object[] { + orgId}, this.CheckOrgIdExistsOperationCompleted, userState); + } + + private void OnCheckOrgIdExistsOperationCompleted(object arg) + { + if ((this.CheckOrgIdExistsCompleted != null)) + { + System.Web.Services.Protocols.InvokeCompletedEventArgs invokeArgs = ((System.Web.Services.Protocols.InvokeCompletedEventArgs)(arg)); + this.CheckOrgIdExistsCompleted(this, new CheckOrgIdExistsCompletedEventArgs(invokeArgs.Results, invokeArgs.Error, invokeArgs.Cancelled, invokeArgs.UserState)); + } + } /// [System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://tempuri.org/CreateOrganization", RequestNamespace="http://tempuri.org/", ResponseNamespace="http://tempuri.org/", Use=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)] @@ -204,6 +258,8 @@ namespace WebsitePanel.EnterpriseServer.HostedSolution { return ((int)(results[0])); } + + /// public System.IAsyncResult BeginCreateOrganization(int packageId, string organizationID, string organizationName, string domainName, System.AsyncCallback callback, object asyncState) { return this.BeginInvoke("CreateOrganization", new object[] { @@ -1585,6 +1641,36 @@ namespace WebsitePanel.EnterpriseServer.HostedSolution { base.CancelAsync(userState); } } + + /// + [System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "4.0.30319.17929")] + public delegate void CheckOrgIdExistsCompletedEventHandler(object sender, CheckOrgIdExistsCompletedEventArgs e); + + /// + [System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "4.0.30319.17929")] + [System.Diagnostics.DebuggerStepThroughAttribute()] + [System.ComponentModel.DesignerCategoryAttribute("code")] + public partial class CheckOrgIdExistsCompletedEventArgs : System.ComponentModel.AsyncCompletedEventArgs + { + + private object[] results; + + internal CheckOrgIdExistsCompletedEventArgs(object[] results, System.Exception exception, bool cancelled, object userState) : + base(exception, cancelled, userState) + { + this.results = results; + } + + /// + public bool Result + { + get + { + this.RaiseExceptionIfNecessary(); + return ((bool)(this.results[0])); + } + } + } /// [System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "2.0.50727.3038")] diff --git a/WebsitePanel/Sources/WebsitePanel.EnterpriseServer/Code/HostedSolution/OrganizationController.cs b/WebsitePanel/Sources/WebsitePanel.EnterpriseServer/Code/HostedSolution/OrganizationController.cs index 41f27079..b9c816cf 100644 --- a/WebsitePanel/Sources/WebsitePanel.EnterpriseServer/Code/HostedSolution/OrganizationController.cs +++ b/WebsitePanel/Sources/WebsitePanel.EnterpriseServer/Code/HostedSolution/OrganizationController.cs @@ -265,7 +265,7 @@ namespace WebsitePanel.EnterpriseServer return itemId; } - private static bool OrganizationIdentifierExists(string organizationId) + public static bool OrganizationIdentifierExists(string organizationId) { return DataProvider.ExchangeOrganizationExists(organizationId); } diff --git a/WebsitePanel/Sources/WebsitePanel.EnterpriseServer/esOrganizations.asmx.cs b/WebsitePanel/Sources/WebsitePanel.EnterpriseServer/esOrganizations.asmx.cs index cc4a6b85..ac5a1e38 100644 --- a/WebsitePanel/Sources/WebsitePanel.EnterpriseServer/esOrganizations.asmx.cs +++ b/WebsitePanel/Sources/WebsitePanel.EnterpriseServer/esOrganizations.asmx.cs @@ -45,6 +45,12 @@ namespace WebsitePanel.EnterpriseServer { #region Organizations + [WebMethod] + public bool CheckOrgIdExists(string orgId) + { + return OrganizationController.OrganizationIdentifierExists(orgId); + } + [WebMethod] public int CreateOrganization(int packageId, string organizationID, string organizationName, string domainName) { diff --git a/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/UserCreateSpace.ascx.cs b/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/UserCreateSpace.ascx.cs index 5e92633c..41241784 100644 --- a/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/UserCreateSpace.ascx.cs +++ b/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/UserCreateSpace.ascx.cs @@ -27,8 +27,11 @@ // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. using System; +using System.Collections.Generic; +using System.Linq; using System.Web.UI.WebControls; using WebsitePanel.EnterpriseServer; +using WebsitePanel.Providers.HostedSolution; namespace WebsitePanel.Portal { @@ -173,11 +176,18 @@ namespace WebsitePanel.Portal UserInfo user = UsersHelper.GetUser(PanelSecurity.SelectedUserId); if (user != null) - { + { if (user.Role != UserRole.Reseller) { + UserSettings settings = ES.Services.Users.GetUserSettings(user.UserId, UserSettings.EXCHANGE_POLICY); + string orgId = domainName.ToLower(); - ES.Services.Organizations.CreateOrganization(result.Result, domainName.ToLower(), domainName.ToLower(), domainName.ToLower()); + if (settings != null && settings["OrgIdPolicy"] != null) + { + orgId = GetOrgId(settings["OrgIdPolicy"], domainName, result.Result); + } + + ES.Services.Organizations.CreateOrganization(result.Result, orgId, domainName.ToLower(), domainName.ToLower()); if (result.Result < 0) { @@ -199,6 +209,39 @@ namespace WebsitePanel.Portal Response.Redirect(PortalUtils.GetSpaceHomePageUrl(result.Result)); } + private string GetOrgId(string orgIdPolicy, string domainName, int packageId) + { + string[] values = orgIdPolicy.Split(';'); + + if (values.Length > 1 && Convert.ToBoolean(values[0])) + { + try + { + int maxLength = Convert.ToInt32(values[1]); + + if (domainName.Length > maxLength) + { + domainName = domainName.Substring(0, maxLength); + string orgId = domainName; + int counter = 0; + + while (ES.Services.Organizations.CheckOrgIdExists(orgId)) + { + counter++; + orgId = maxLength > 3 ? string.Format("{0}{1}", orgId.Substring(0, orgId.Length - 3), counter.ToString("d3")) : counter.ToString("d3"); + } + + return orgId; + } + } + catch (Exception) + { + } + } + + return domainName; + } + protected void ddlPlans_SelectedIndexChanged(object sender, EventArgs e) { BindHostingPlan();