Settings: Added SendOwnerChangeInstructions and ChangeOwner
This commit is contained in:
parent
020b64dbbe
commit
dd28738907
@ -26,16 +26,19 @@
|
||||
|
||||
using System;
|
||||
using System.Text;
|
||||
|
||||
using ASC.Common.Logging;
|
||||
using ASC.Core;
|
||||
using ASC.Core.Users;
|
||||
using ASC.Web.Studio.Utility;
|
||||
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.WebUtilities;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.DependencyInjection.Extensions;
|
||||
using Microsoft.Extensions.Options;
|
||||
|
||||
using static ASC.Security.Cryptography.EmailValidationKeyProvider;
|
||||
|
||||
namespace ASC.Security.Cryptography
|
||||
@ -168,6 +171,9 @@ namespace ASC.Security.Cryptography
|
||||
case ConfirmType.LinkInvite:
|
||||
checkKeyResult = provider.ValidateEmailKey(Type.ToString() + (int)EmplType, Key, provider.ValidInterval);
|
||||
break;
|
||||
case ConfirmType.PortalOwnerChange:
|
||||
checkKeyResult = provider.ValidateEmailKey(Email + Type + UiD.HasValue, Key, provider.ValidInterval);
|
||||
break;
|
||||
case ConfirmType.EmailChange:
|
||||
checkKeyResult = provider.ValidateEmailKey(Email + Type + authContext.CurrentAccount.ID, Key, provider.ValidInterval);
|
||||
break;
|
||||
|
@ -992,6 +992,60 @@ namespace ASC.Api.Settings
|
||||
return Resource.SuccessfullySaveSettingsMessage;
|
||||
}
|
||||
|
||||
[Create("owner")]
|
||||
public object SendOwnerChangeInstructions(SettingsModel model)
|
||||
{
|
||||
PermissionContext.DemandPermissions(SecutiryConstants.EditPortalSettings);
|
||||
|
||||
var curTenant = TenantManager.GetCurrentTenant();
|
||||
var owner = UserManager.GetUsers(curTenant.OwnerId);
|
||||
var newOwner = UserManager.GetUsers(model.OwnerId);
|
||||
|
||||
if (newOwner.IsVisitor(UserManager)) throw new System.Security.SecurityException("Collaborator can not be an owner");
|
||||
|
||||
if (!owner.ID.Equals(AuthContext.CurrentAccount.ID) || Guid.Empty.Equals(newOwner.ID))
|
||||
{
|
||||
return new { Status = 0, Message = Resource.ErrorAccessDenied };
|
||||
}
|
||||
|
||||
var confirmLink = CommonLinkUtility.GetConfirmationUrl(owner.Email, ConfirmType.PortalOwnerChange, newOwner.ID, newOwner.ID);
|
||||
StudioNotifyService.SendMsgConfirmChangeOwner(owner, newOwner, confirmLink);
|
||||
|
||||
MessageService.Send(MessageAction.OwnerSentChangeOwnerInstructions, MessageTarget.Create(owner.ID), owner.DisplayUserName(false, DisplayUserSettingsHelper));
|
||||
|
||||
var emailLink = string.Format("<a href=\"mailto:{0}\">{0}</a>", owner.Email);
|
||||
return new { Status = 1, Message = Resource.ChangePortalOwnerMsg.Replace(":email", emailLink) };
|
||||
}
|
||||
|
||||
[Update("owner")]
|
||||
[Authorize(AuthenticationSchemes = "confirm", Roles = "PortalOwnerChange")]
|
||||
public void Owner(SettingsModel model)
|
||||
{
|
||||
var newOwner = Constants.LostUser;
|
||||
try
|
||||
{
|
||||
newOwner = UserManager.GetUsers(model.OwnerId);
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
if (Constants.LostUser.Equals(newOwner))
|
||||
{
|
||||
throw new Exception(Resource.ErrorUserNotFound);
|
||||
}
|
||||
|
||||
if (UserManager.IsUserInGroup(newOwner.ID, Constants.GroupVisitor.ID))
|
||||
{
|
||||
throw new Exception(Resource.ErrorUserNotFound);
|
||||
}
|
||||
|
||||
var curTenant = TenantManager.GetCurrentTenant();
|
||||
curTenant.OwnerId = newOwner.ID;
|
||||
TenantManager.SaveTenant(curTenant);
|
||||
|
||||
MessageService.Send(MessageAction.OwnerUpdated, newOwner.DisplayUserName(false, DisplayUserSettingsHelper));
|
||||
}
|
||||
|
||||
///<visible>false</visible>
|
||||
[Update("defaultpage")]
|
||||
public string SaveDefaultPageSettings(SettingsModel model)
|
||||
|
@ -15,5 +15,7 @@ namespace ASC.Web.Api.Models
|
||||
public bool Show { get; set; } //tips
|
||||
|
||||
public int VersionId { get; set; }
|
||||
|
||||
public Guid OwnerId { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -45,6 +45,7 @@ using ASC.Web.Core.PublicResources;
|
||||
using ASC.Web.Core.Users;
|
||||
using ASC.Web.Core.WhiteLabel;
|
||||
using ASC.Web.Studio.Utility;
|
||||
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.DependencyInjection.Extensions;
|
||||
@ -721,23 +722,21 @@ namespace ASC.Web.Studio.Core.Notify
|
||||
new TagValue(Tags.OwnerName, u.DisplayUserName(DisplayUserSettingsHelper)));
|
||||
}
|
||||
|
||||
|
||||
public void SendMsgConfirmChangeOwner(Tenant t, string newOwnerName, string confirmOwnerUpdateUrl)
|
||||
public void SendMsgConfirmChangeOwner(UserInfo owner, UserInfo newOwner, string confirmOwnerUpdateUrl)
|
||||
{
|
||||
var u = UserManager.GetUsers(t.OwnerId);
|
||||
|
||||
static string greenButtonText() => WebstudioNotifyPatternResource.ButtonConfirmPortalOwnerUpdate;
|
||||
|
||||
client.SendNoticeToAsync(
|
||||
Actions.ConfirmOwnerChange,
|
||||
new IRecipient[] { u },
|
||||
new[] { EMailSenderName },
|
||||
TagValues.GreenButton(greenButtonText, confirmOwnerUpdateUrl),
|
||||
new TagValue(Tags.UserName, newOwnerName),
|
||||
new TagValue(Tags.OwnerName, u.DisplayUserName(DisplayUserSettingsHelper)));
|
||||
Actions.ConfirmOwnerChange,
|
||||
null,
|
||||
new IRecipient[] { owner },
|
||||
new[] { EMailSenderName },
|
||||
null,
|
||||
TagValues.GreenButton(greenButtonText, confirmOwnerUpdateUrl),
|
||||
new TagValue(Tags.UserName, newOwner.DisplayUserName(DisplayUserSettingsHelper)),
|
||||
new TagValue(Tags.OwnerName, owner.DisplayUserName(DisplayUserSettingsHelper)));
|
||||
}
|
||||
|
||||
|
||||
public void SendCongratulations(UserInfo u)
|
||||
{
|
||||
try
|
||||
|
Loading…
Reference in New Issue
Block a user