2019-09-03 15:13:25 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using ASC.Api.Core;
|
|
|
|
|
using ASC.Common.Logging;
|
|
|
|
|
using ASC.Core;
|
|
|
|
|
using ASC.Core.Billing;
|
|
|
|
|
using ASC.Core.Tenants;
|
|
|
|
|
using ASC.Core.Users;
|
|
|
|
|
using ASC.MessagingSystem;
|
2019-09-17 12:42:32 +00:00
|
|
|
|
using ASC.Security.Cryptography;
|
2019-09-03 15:13:25 +00:00
|
|
|
|
using ASC.Web.Api.Routing;
|
|
|
|
|
using ASC.Web.Core.Utility;
|
|
|
|
|
using ASC.Web.Studio.Core.Notify;
|
|
|
|
|
using ASC.Web.Studio.Utility;
|
|
|
|
|
using Microsoft.AspNetCore.Hosting;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
2019-10-31 13:54:43 +00:00
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
2019-10-17 15:55:35 +00:00
|
|
|
|
using Microsoft.Extensions.Options;
|
2019-09-03 15:13:25 +00:00
|
|
|
|
|
|
|
|
|
namespace ASC.Web.Api.Controllers
|
|
|
|
|
{
|
|
|
|
|
[DefaultRoute]
|
|
|
|
|
[ApiController]
|
|
|
|
|
public class PortalController : ControllerBase
|
|
|
|
|
{
|
|
|
|
|
public Tenant Tenant { get { return ApiContext.Tenant; } }
|
|
|
|
|
|
|
|
|
|
public ApiContext ApiContext { get; }
|
2019-09-09 12:56:33 +00:00
|
|
|
|
public UserManager UserManager { get; }
|
|
|
|
|
public AuthContext AuthContext { get; }
|
2019-09-17 08:07:46 +00:00
|
|
|
|
public TenantManager TenantManager { get; }
|
2019-09-17 12:42:32 +00:00
|
|
|
|
public EmailValidationKeyProvider EmailValidationKeyProvider { get; }
|
2019-09-18 14:18:44 +00:00
|
|
|
|
public PaymentManager PaymentManager { get; }
|
2019-09-19 15:55:44 +00:00
|
|
|
|
public CommonLinkUtility CommonLinkUtility { get; }
|
2019-09-24 10:32:12 +00:00
|
|
|
|
public UrlShortener UrlShortener { get; }
|
2019-09-27 10:45:37 +00:00
|
|
|
|
public PermissionContext PermissionContext { get; }
|
2019-09-03 15:13:25 +00:00
|
|
|
|
public MessageService MessageService { get; }
|
|
|
|
|
public StudioNotifyService StudioNotifyService { get; }
|
|
|
|
|
public IWebHostEnvironment WebHostEnvironment { get; }
|
2019-10-17 15:55:35 +00:00
|
|
|
|
public ILog Log { get; }
|
2019-09-03 15:13:25 +00:00
|
|
|
|
|
|
|
|
|
|
2019-10-17 15:55:35 +00:00
|
|
|
|
public PortalController(
|
2019-11-06 15:03:09 +00:00
|
|
|
|
IOptionsMonitor<ILog> options,
|
2019-09-03 15:13:25 +00:00
|
|
|
|
MessageService messageService,
|
|
|
|
|
StudioNotifyService studioNotifyService,
|
2019-09-09 12:56:33 +00:00
|
|
|
|
ApiContext apiContext,
|
|
|
|
|
UserManager userManager,
|
2019-09-17 08:07:46 +00:00
|
|
|
|
AuthContext authContext,
|
2019-09-17 12:42:32 +00:00
|
|
|
|
TenantManager tenantManager,
|
2019-09-18 14:18:44 +00:00
|
|
|
|
EmailValidationKeyProvider emailValidationKeyProvider,
|
2019-09-19 15:55:44 +00:00
|
|
|
|
PaymentManager paymentManager,
|
2019-09-24 10:32:12 +00:00
|
|
|
|
CommonLinkUtility commonLinkUtility,
|
2019-09-27 10:45:37 +00:00
|
|
|
|
UrlShortener urlShortener,
|
|
|
|
|
PermissionContext permissionContext
|
2019-09-09 12:56:33 +00:00
|
|
|
|
)
|
2019-09-03 15:13:25 +00:00
|
|
|
|
{
|
2019-11-06 15:03:09 +00:00
|
|
|
|
Log = options.CurrentValue;
|
2019-09-03 15:13:25 +00:00
|
|
|
|
MessageService = messageService;
|
|
|
|
|
StudioNotifyService = studioNotifyService;
|
|
|
|
|
ApiContext = apiContext;
|
2019-09-09 12:56:33 +00:00
|
|
|
|
UserManager = userManager;
|
|
|
|
|
AuthContext = authContext;
|
2019-09-17 08:07:46 +00:00
|
|
|
|
TenantManager = tenantManager;
|
2019-09-17 12:42:32 +00:00
|
|
|
|
EmailValidationKeyProvider = emailValidationKeyProvider;
|
2019-09-18 14:18:44 +00:00
|
|
|
|
PaymentManager = paymentManager;
|
2019-09-19 15:55:44 +00:00
|
|
|
|
CommonLinkUtility = commonLinkUtility;
|
2019-09-24 10:32:12 +00:00
|
|
|
|
UrlShortener = urlShortener;
|
2019-09-27 10:45:37 +00:00
|
|
|
|
PermissionContext = permissionContext;
|
2019-09-03 15:13:25 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Read("")]
|
|
|
|
|
public Tenant Get()
|
|
|
|
|
{
|
|
|
|
|
return Tenant;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Read("users/{userID}")]
|
|
|
|
|
public UserInfo GetUser(Guid userID)
|
|
|
|
|
{
|
2019-09-12 11:34:58 +00:00
|
|
|
|
return UserManager.GetUsers(userID);
|
2019-09-03 15:13:25 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Read("users/invite/{employeeType}")]
|
|
|
|
|
public string GeInviteLink(EmployeeType employeeType)
|
|
|
|
|
{
|
2019-09-27 10:45:37 +00:00
|
|
|
|
PermissionContext.DemandPermissions(Constants.Action_AddRemoveUser);
|
2019-10-30 08:45:55 +00:00
|
|
|
|
return CommonLinkUtility.GetConfirmationUrl(string.Empty, ConfirmType.LinkInvite, (int)employeeType)
|
2019-09-03 15:13:25 +00:00
|
|
|
|
+ $"&emplType={employeeType:d}";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Update("getshortenlink")]
|
|
|
|
|
public string GetShortenLink(string link)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2019-09-19 15:55:44 +00:00
|
|
|
|
return UrlShortener.Instance.GetShortenLink(link, CommonLinkUtility);
|
2019-09-03 15:13:25 +00:00
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
2019-10-17 15:55:35 +00:00
|
|
|
|
Log.Error("getshortenlink", ex);
|
2019-09-03 15:13:25 +00:00
|
|
|
|
return link;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[Read("usedspace")]
|
|
|
|
|
public double GetUsedSpace()
|
|
|
|
|
{
|
|
|
|
|
return Math.Round(
|
2019-09-17 08:07:46 +00:00
|
|
|
|
TenantManager.FindTenantQuotaRows(new TenantQuotaRowQuery(Tenant.TenantId))
|
2019-09-03 15:13:25 +00:00
|
|
|
|
.Where(q => !string.IsNullOrEmpty(q.Tag) && new Guid(q.Tag) != Guid.Empty)
|
|
|
|
|
.Sum(q => q.Counter) / 1024f / 1024f / 1024f, 2);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[Read("userscount")]
|
|
|
|
|
public long GetUsersCount()
|
|
|
|
|
{
|
2019-09-12 11:34:58 +00:00
|
|
|
|
return UserManager.GetUserNames(EmployeeStatus.Active).Count();
|
2019-09-03 15:13:25 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Read("tariff")]
|
|
|
|
|
public Tariff GetTariff()
|
|
|
|
|
{
|
2019-09-18 14:18:44 +00:00
|
|
|
|
return PaymentManager.GetTariff(Tenant.TenantId);
|
2019-09-03 15:13:25 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Read("quota")]
|
|
|
|
|
public TenantQuota GetQuota()
|
|
|
|
|
{
|
2019-09-17 08:07:46 +00:00
|
|
|
|
return TenantManager.GetTenantQuota(Tenant.TenantId);
|
2019-09-03 15:13:25 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Read("quota/right")]
|
|
|
|
|
public TenantQuota GetRightQuota()
|
|
|
|
|
{
|
|
|
|
|
var usedSpace = GetUsedSpace();
|
|
|
|
|
var needUsersCount = GetUsersCount();
|
|
|
|
|
|
2019-09-17 08:07:46 +00:00
|
|
|
|
return TenantManager.GetTenantQuotas().OrderBy(r => r.Price)
|
2019-09-03 15:13:25 +00:00
|
|
|
|
.FirstOrDefault(quota =>
|
|
|
|
|
quota.ActiveUsers > needUsersCount
|
|
|
|
|
&& quota.MaxTotalSize > usedSpace
|
|
|
|
|
&& !quota.Year);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[Read("path")]
|
|
|
|
|
public string GetFullAbsolutePath(string virtualPath)
|
|
|
|
|
{
|
2019-09-19 15:55:44 +00:00
|
|
|
|
return CommonLinkUtility.GetFullAbsolutePath(virtualPath);
|
2019-09-03 15:13:25 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2019-10-31 13:54:43 +00:00
|
|
|
|
|
2019-11-11 09:03:49 +00:00
|
|
|
|
public static class PortalControllerExtension
|
2019-10-31 13:54:43 +00:00
|
|
|
|
{
|
|
|
|
|
public static IServiceCollection AddPortalController(this IServiceCollection services)
|
|
|
|
|
{
|
|
|
|
|
return services
|
|
|
|
|
.AddUrlShortener()
|
|
|
|
|
.AddMessageServiceService()
|
|
|
|
|
.AddStudioNotifyServiceService()
|
|
|
|
|
.AddApiContextService()
|
|
|
|
|
.AddUserManagerService()
|
|
|
|
|
.AddAuthContextService()
|
|
|
|
|
.AddAuthContextService()
|
|
|
|
|
.AddTenantManagerService()
|
|
|
|
|
.AddEmailValidationKeyProviderService()
|
|
|
|
|
.AddPaymentManagerService()
|
|
|
|
|
.AddCommonLinkUtilityService()
|
|
|
|
|
.AddPermissionContextService();
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-09-03 15:13:25 +00:00
|
|
|
|
}
|