ability to specify default organization

This commit is contained in:
vfedosevich 2014-04-25 04:30:36 +03:00
parent 00e416f5d4
commit e0c38e8ed7
9 changed files with 173 additions and 35 deletions

View file

@ -158,7 +158,6 @@ order by rg.groupOrder
public const string ORGANIZATION_USERS = "HostedSolution.Users"; public const string ORGANIZATION_USERS = "HostedSolution.Users";
public const string ORGANIZATION_DOMAINS = "HostedSolution.Domains"; public const string ORGANIZATION_DOMAINS = "HostedSolution.Domains";
public const string ORGANIZATION_ALLOWCHANGEUPN = "HostedSolution.AllowChangeUPN"; public const string ORGANIZATION_ALLOWCHANGEUPN = "HostedSolution.AllowChangeUPN";
//public const string ORGANIZATION_SECURITYGROUPMANAGEMENT = "HostedSolution.SecurityGroupManagement";
public const string ORGANIZATION_SECURITYGROUPS = "HostedSolution.SecurityGroups"; public const string ORGANIZATION_SECURITYGROUPS = "HostedSolution.SecurityGroups";
public const string CRM_USERS = "HostedCRM.Users"; public const string CRM_USERS = "HostedCRM.Users";

View file

@ -144,6 +144,8 @@ namespace WebsitePanel.EnterpriseServer.HostedSolution
private System.Threading.SendOrPostCallback AddAdditionalGroupOperationCompleted; private System.Threading.SendOrPostCallback AddAdditionalGroupOperationCompleted;
private System.Threading.SendOrPostCallback SetDefaultOrganizationOperationCompleted;
/// <remarks/> /// <remarks/>
public esOrganizations() public esOrganizations()
{ {
@ -267,6 +269,9 @@ namespace WebsitePanel.EnterpriseServer.HostedSolution
/// <remarks/> /// <remarks/>
public event AddAdditionalGroupCompletedEventHandler AddAdditionalGroupCompleted; public event AddAdditionalGroupCompletedEventHandler AddAdditionalGroupCompleted;
/// <remarks/>
public event SetDefaultOrganizationCompletedEventHandler SetDefaultOrganizationCompleted;
/// <remarks/> /// <remarks/>
[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)] [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)]
@ -2608,6 +2613,56 @@ namespace WebsitePanel.EnterpriseServer.HostedSolution
} }
} }
/// <remarks/>
[System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://tempuri.org/SetDefaultOrganization", RequestNamespace = "http://tempuri.org/", ResponseNamespace = "http://tempuri.org/", Use = System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle = System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
public void SetDefaultOrganization(int newDefaultOrganizationId, int currentDefaultOrganizationId)
{
this.Invoke("SetDefaultOrganization", new object[] {
newDefaultOrganizationId,
currentDefaultOrganizationId});
}
/// <remarks/>
public System.IAsyncResult BeginSetDefaultOrganization(int newDefaultOrganizationId, int currentDefaultOrganizationId, System.AsyncCallback callback, object asyncState)
{
return this.BeginInvoke("SetDefaultOrganization", new object[] {
newDefaultOrganizationId,
currentDefaultOrganizationId}, callback, asyncState);
}
/// <remarks/>
public void EndSetDefaultOrganization(System.IAsyncResult asyncResult)
{
this.EndInvoke(asyncResult);
}
/// <remarks/>
public void SetDefaultOrganizationAsync(int newDefaultOrganizationId, int currentDefaultOrganizationId)
{
this.SetDefaultOrganizationAsync(newDefaultOrganizationId, currentDefaultOrganizationId, null);
}
/// <remarks/>
public void SetDefaultOrganizationAsync(int newDefaultOrganizationId, int currentDefaultOrganizationId, object userState)
{
if ((this.SetDefaultOrganizationOperationCompleted == null))
{
this.SetDefaultOrganizationOperationCompleted = new System.Threading.SendOrPostCallback(this.OnSetDefaultOrganizationOperationCompleted);
}
this.InvokeAsync("SetDefaultOrganization", new object[] {
newDefaultOrganizationId,
currentDefaultOrganizationId}, this.SetDefaultOrganizationOperationCompleted, userState);
}
private void OnSetDefaultOrganizationOperationCompleted(object arg)
{
if ((this.SetDefaultOrganizationCompleted != null))
{
System.Web.Services.Protocols.InvokeCompletedEventArgs invokeArgs = ((System.Web.Services.Protocols.InvokeCompletedEventArgs)(arg));
this.SetDefaultOrganizationCompleted(this, new System.ComponentModel.AsyncCompletedEventArgs(invokeArgs.Error, invokeArgs.Cancelled, invokeArgs.UserState));
}
}
/// <remarks/> /// <remarks/>
public new void CancelAsync(object userState) public new void CancelAsync(object userState)
{ {
@ -3732,4 +3787,8 @@ namespace WebsitePanel.EnterpriseServer.HostedSolution
} }
} }
} }
/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "2.0.50727.3038")]
public delegate void SetDefaultOrganizationCompletedEventHandler(object sender, System.ComponentModel.AsyncCompletedEventArgs e);
} }

View file

@ -286,6 +286,7 @@ namespace WebsitePanel.EnterpriseServer
TaskManager.WriteError(ex); TaskManager.WriteError(ex);
} }
} }
public static int CreateOrganization(int packageId, string organizationId, string organizationName, string domainName) public static int CreateOrganization(int packageId, string organizationId, string organizationName, string domainName)
{ {
int itemId; int itemId;
@ -1276,6 +1277,44 @@ namespace WebsitePanel.EnterpriseServer
return 0; return 0;
} }
public static void SetDefaultOrganization(int newDefaultOrganizationId, int currentDefaultOrganizationId)
{
// place log record
List<BackgroundTaskParameter> parameters = new List<BackgroundTaskParameter>();
parameters.Add(new BackgroundTaskParameter("ItemID", newDefaultOrganizationId));
TaskManager.StartTask("ORGANIZATION", "SET_DEFAULT_ORG", parameters);
try
{
if (currentDefaultOrganizationId > 0)
{
// load current default organization
Organization currentDefaultOrg = (Organization)PackageController.GetPackageItem(currentDefaultOrganizationId);
currentDefaultOrg.IsDefault = false;
// save changes
PackageController.UpdatePackageItem(currentDefaultOrg);
}
// load organization
Organization newDefaultOrg = (Organization)PackageController.GetPackageItem(newDefaultOrganizationId);
newDefaultOrg.IsDefault = true;
// save changes
PackageController.UpdatePackageItem(newDefaultOrg);
}
catch (Exception ex)
{
throw TaskManager.WriteError(ex);
}
finally
{
TaskManager.CompleteTask();
}
}
#region Users #region Users

View file

@ -117,6 +117,11 @@ namespace WebsitePanel.EnterpriseServer
return OrganizationController.GetAccountIdByUserPrincipalName(itemId, userPrincipalName); return OrganizationController.GetAccountIdByUserPrincipalName(itemId, userPrincipalName);
} }
[WebMethod]
public void SetDefaultOrganization(int newDefaultOrganizationId, int currentDefaultOrganizationId)
{
OrganizationController.SetDefaultOrganization(newDefaultOrganizationId, currentDefaultOrganizationId);
}
#endregion #endregion

View file

@ -1,4 +1,4 @@
// Copyright (c) 2014, Outercurve Foundation. // Copyright (c) 2012, Outercurve Foundation.
// All rights reserved. // All rights reserved.
// //
// Redistribution and use in source and binary forms, with or without modification, // Redistribution and use in source and binary forms, with or without modification,
@ -63,6 +63,9 @@ namespace WebsitePanel.Providers.HostedSolution
#endregion #endregion
[Persistent]
public bool IsDefault { get; set; }
[Persistent] [Persistent]
public int MaxSharePointStorage public int MaxSharePointStorage
{ {

View file

@ -168,4 +168,10 @@
<data name="Text.PageName" xml:space="preserve"> <data name="Text.PageName" xml:space="preserve">
<value>Home</value> <value>Home</value>
</data> </data>
<data name="gvOrgsDefault.HeaderText" xml:space="preserve">
<value>Default</value>
</data>
<data name="btnSetDefaultOrganization.Text" xml:space="preserve">
<value>Set Default Organization</value>
</data>
</root> </root>

View file

@ -74,6 +74,13 @@
</ItemTemplate> </ItemTemplate>
<HeaderStyle Wrap="False" /> <HeaderStyle Wrap="False" />
</asp:TemplateField> </asp:TemplateField>
<asp:TemplateField meta:resourcekey="gvOrgsDefault">
<ItemTemplate>
<div style="text-align:center">
<input type="radio" name="DefaultOrganization" value='<%# Eval("ItemID") %>' <%# IsChecked(Convert.ToString(Eval("IsDefault")), Eval("ItemID").ToString()) %>/>
</div>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField ItemStyle-Width="20px"> <asp:TemplateField ItemStyle-Width="20px">
<ItemTemplate> <ItemTemplate>
<asp:ImageButton ID="cmdDelete" runat="server" Text="Delete" SkinID="ExchangeDelete" <asp:ImageButton ID="cmdDelete" runat="server" Text="Delete" SkinID="ExchangeDelete"
@ -98,11 +105,15 @@
</asp:ObjectDataSource> </asp:ObjectDataSource>
<br /> <br />
<asp:Localize ID="locQuota" runat="server" meta:resourcekey="locQuota" Text="Total Organizations Created:"></asp:Localize> <asp:Localize ID="locQuota" runat="server" meta:resourcekey="locQuota" Text="Total Organizations Created:"></asp:Localize>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
<wsp:Quota ID="orgsQuota" runat="server" QuotaName="HostedSolution.Organizations" /> <wsp:Quota ID="orgsQuota" runat="server" QuotaName="HostedSolution.Organizations" />
<br />
<br /> <div style="text-align: center">
<asp:Button ID="btnSetDefaultOrganization" runat="server" meta:resourcekey="btnSetDefaultOrganization"
Text="Set Default Organization" CssClass="Button1" OnClick="btnSetDefaultOrganization_Click" />
</div>
</div> </div>
</div> </div>
</div> </div>

View file

@ -1,4 +1,4 @@
// Copyright (c) 2014, Outercurve Foundation. // Copyright (c) 2012, Outercurve Foundation.
// All rights reserved. // All rights reserved.
// //
// Redistribution and use in source and binary forms, with or without modification, // Redistribution and use in source and binary forms, with or without modification,
@ -27,14 +27,18 @@
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
using System; using System;
using System.Data;
using System.Text; using System.Text;
using System.Web.UI.WebControls; using System.Web.UI.WebControls;
using WebsitePanel.EnterpriseServer; using WebsitePanel.EnterpriseServer;
using WebsitePanel.Providers.HostedSolution;
namespace WebsitePanel.Portal.ExchangeServer namespace WebsitePanel.Portal.ExchangeServer
{ {
public partial class Organizations : WebsitePanelModuleBase public partial class Organizations : WebsitePanelModuleBase
{ {
private int CurrentDefaultOrgId { get; set; }
protected void Page_Load(object sender, EventArgs e) protected void Page_Load(object sender, EventArgs e)
{ {
// set display preferences // set display preferences
@ -50,7 +54,6 @@ namespace WebsitePanel.Portal.ExchangeServer
btnCreate.Enabled = false; btnCreate.Enabled = false;
} }
PackageContext cntx = PackagesHelper.GetCachedPackageContext(PanelSecurity.PackageId); PackageContext cntx = PackagesHelper.GetCachedPackageContext(PanelSecurity.PackageId);
if (cntx.Quotas.ContainsKey(Quotas.ORGANIZATIONS)) if (cntx.Quotas.ContainsKey(Quotas.ORGANIZATIONS))
{ {
@ -60,6 +63,8 @@ namespace WebsitePanel.Portal.ExchangeServer
//else //else
//if (gvOrgs.Rows.Count > 0) btnCreate.Enabled = false; //if (gvOrgs.Rows.Count > 0) btnCreate.Enabled = false;
btnSetDefaultOrganization.Enabled = !(gvOrgs.Rows.Count < 2);
if (!Page.IsPostBack) if (!Page.IsPostBack)
{ {
if (Request.UrlReferrer != null && PanelSecurity.SelectedUser.Role == UserRole.User) if (Request.UrlReferrer != null && PanelSecurity.SelectedUser.Role == UserRole.User)
@ -69,6 +74,8 @@ namespace WebsitePanel.Portal.ExchangeServer
if (Request.UrlReferrer.Query.Equals(queryBuilder.ToString(), StringComparison.InvariantCultureIgnoreCase) && gvOrgs.Rows.Count > 0) if (Request.UrlReferrer.Query.Equals(queryBuilder.ToString(), StringComparison.InvariantCultureIgnoreCase) && gvOrgs.Rows.Count > 0)
{ {
if (CurrentDefaultOrgId > 0) Response.Redirect(GetOrganizationEditUrl(CurrentDefaultOrgId.ToString()));
Response.Redirect(((HyperLink)gvOrgs.Rows[0].Cells[1].Controls[1]).NavigateUrl); Response.Redirect(((HyperLink)gvOrgs.Rows[0].Cells[1].Controls[1]).NavigateUrl);
} }
} }
@ -139,5 +146,33 @@ namespace WebsitePanel.Portal.ExchangeServer
} }
} }
} }
protected void btnSetDefaultOrganization_Click(object sender, EventArgs e)
{
// get org
int newDefaultOrgId = Utils.ParseInt(Request.Form["DefaultOrganization"], CurrentDefaultOrgId);
try
{
ES.Services.Organizations.SetDefaultOrganization(newDefaultOrgId, CurrentDefaultOrgId);
ShowSuccessMessage("REQUEST_COMPLETED_SUCCESFULLY");
}
catch (Exception ex)
{
ShowErrorMessage("ORGANIZATION_SET_DEFAULT_ORG", ex);
}
}
public string IsChecked(string val, string itemId)
{
if (!string.IsNullOrEmpty(val) && val.ToLowerInvariant() == "true")
{
CurrentDefaultOrgId = Utils.ParseInt(itemId, 0);
return "checked";
}
return "";
}
} }
} }

View file

@ -1,31 +1,3 @@
// Copyright (c) 2014, Outercurve Foundation.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
//
// - Redistributions of source code must retain the above copyright notice, this
// list of conditions and the following disclaimer.
//
// - Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// - Neither the name of the Outercurve Foundation nor the names of its
// contributors may be used to endorse or promote products derived from this
// software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// <auto-generated> // <auto-generated>
// This code was generated by a tool. // This code was generated by a tool.
@ -165,5 +137,14 @@ namespace WebsitePanel.Portal.ExchangeServer {
/// To modify move field declaration from designer file to code-behind file. /// To modify move field declaration from designer file to code-behind file.
/// </remarks> /// </remarks>
protected global::WebsitePanel.Portal.Quota orgsQuota; protected global::WebsitePanel.Portal.Quota orgsQuota;
/// <summary>
/// btnSetDefaultOrganization control.
/// </summary>
/// <remarks>
/// Auto-generated field.
/// To modify move field declaration from designer file to code-behind file.
/// </remarks>
protected global::System.Web.UI.WebControls.Button btnSetDefaultOrganization;
} }
} }