Example #1
0
        private bool CheckStartupEnabled(TenantQuota currentQuota, TenantQuota startupQuota, out string errorMessage)
        {
            errorMessage = string.Empty;

            if (!currentQuota.Trial)
            {
                errorMessage = UserControlsCommonResource.SaasTariffErrorTrial;
                return(false);
            }

            if (TenantStatisticsProvider.GetUsersCount() > startupQuota.ActiveUsers)
            {
                errorMessage = string.Format(UserControlsCommonResource.SaasTariffErrorUsers, startupQuota.ActiveUsers);
                return(false);
            }

            if (TenantStatisticsProvider.GetVisitorsCount() > 0)
            {
                errorMessage = string.Format(UserControlsCommonResource.SaasTariffErrorGuests, 0);
                return(false);
            }

            if (TenantStatisticsProvider.GetAdminsCount() > 1)
            {
                errorMessage = string.Format(UserControlsCommonResource.SaasTariffErrorAdmins, 1);
                return(false);
            }

            if (TenantStatisticsProvider.GetUsedSize() > startupQuota.MaxTotalSize)
            {
                errorMessage = string.Format(UserControlsCommonResource.SaasTariffErrorStorage, FileSizeComment.FilesSizeToString(startupQuota.MaxTotalSize));
                return(false);
            }

            var authServiceList = new AuthorizationKeys().AuthServiceList.Where(x => x.CanSet);

            foreach (var service in authServiceList)
            {
                if (service.Props.Any(r => !string.IsNullOrEmpty(r.Value)))
                {
                    errorMessage = UserControlsCommonResource.SaasTariffErrorThirparty;
                    return(false);
                }
            }

            if (!TenantWhiteLabelSettings.Load().IsDefault)
            {
                errorMessage = UserControlsCommonResource.SaasTariffErrorWhiteLabel;
                return(false);
            }

            var currentTenant = CoreContext.TenantManager.GetCurrentTenant();

            if (!string.IsNullOrEmpty(currentTenant.MappedDomain))
            {
                errorMessage = UserControlsCommonResource.SaasTariffErrorDomain;
                return(false);
            }

            var accountLinker = new AccountLinker("webstudio");

            foreach (var user in CoreContext.UserManager.GetUsers(EmployeeStatus.All))
            {
                var linkedAccounts = accountLinker.GetLinkedProfiles(user.ID.ToString());

                if (linkedAccounts.Any())
                {
                    errorMessage = UserControlsCommonResource.SaasTariffErrorOauth;
                    return(false);
                }
            }

            if (SsoSettingsV2.Load().EnableSso)
            {
                errorMessage = UserControlsCommonResource.SaasTariffErrorSso;
                return(false);
            }

            if (ActiveDirectory.Base.Settings.LdapSettings.Load().EnableLdapAuthentication)
            {
                errorMessage = UserControlsCommonResource.SaasTariffErrorLdap;
                return(false);
            }

            using (var service = new BackupServiceClient())
            {
                var scheduleResponse = service.GetSchedule(currentTenant.TenantId);

                if (scheduleResponse != null)
                {
                    errorMessage = UserControlsCommonResource.SaasTariffErrorAutoBackup;
                    return(false);
                }
            }

            return(true);
        }