Пример #1
0
        public object SaveSettings(bool anyone, bool registerUsers)
        {
            try
            {
                SecurityContext.DemandPermissions(SecutiryConstants.EditPortalSettings);

                var currentTenantQuota = CoreContext.TenantManager.GetTenantQuota(TenantProvider.CurrentTenantID);

                var enabled = SetupInfo.IsVisibleSettings("PublicPortal") &&
                              (currentTenantQuota.Free || currentTenantQuota.NonProfit || currentTenantQuota.Trial) && !currentTenantQuota.Open;

                if (!enabled)
                {
                    throw new SecurityException(Resource.PortalAccessSettingsTariffException);
                }

                var tenant = CoreContext.TenantManager.GetCurrentTenant();

                var currentSettings = TenantAccessSettings.Load();

                //do nothing if no changes detected
                if (currentSettings.Anyone != anyone)
                {
                    var items = WebItemManager.Instance.GetItemsAll();

                    if (anyone)
                    {
                        var openQuota = CoreContext.TenantManager.GetTenantQuotas(true).FirstOrDefault(q => q.Open);
                        SetQuota(openQuota);

                        foreach (var item in items)
                        {
                            WebItemSecurity.SetSecurity(item.ID.ToString(), item.ID != WebItemManager.CRMProductID, null); //disable crm product
                        }

                        new TenantAccessSettings {
                            Anyone = true, RegisterUsersImmediately = registerUsers
                        }.Save();
                        new StudioTrustedDomainSettings {
                            InviteUsersAsVisitors = false
                        }.Save();
                        new StudioAdminMessageSettings {
                            Enable = true
                        }.Save();

                        IPRestrictionsService.Save(new List <string>(), TenantProvider.CurrentTenantID);

                        tenant.TrustedDomainsType = registerUsers ? TenantTrustedDomainsType.All : TenantTrustedDomainsType.None;
                        CoreContext.TenantManager.SaveTenant(tenant);
                    }
                    else
                    {
                        var freeQuota = CoreContext.TenantManager.GetTenantQuotas(true).FirstOrDefault(q => q.Id == Tariff.CreateDefault().QuotaId);
                        SetQuota(freeQuota);

                        new TenantAccessSettings {
                            Anyone = false, RegisterUsersImmediately = false
                        }.Save();
                        new StudioTrustedDomainSettings {
                            InviteUsersAsVisitors = false
                        }.Save();
                        new StudioAdminMessageSettings {
                            Enable = false
                        }.Save();

                        foreach (var item in items)
                        {
                            WebItemSecurity.SetSecurity(item.ID.ToString(), true, null);
                        }

                        tenant.TrustedDomainsType = TenantTrustedDomainsType.None;
                        CoreContext.TenantManager.SaveTenant(tenant);
                    }

                    MessageService.Send(HttpContext.Current.Request, MessageAction.PortalAccessSettingsUpdated);
                }
                else if (anyone && currentSettings.RegisterUsersImmediately != registerUsers)
                {
                    new TenantAccessSettings {
                        Anyone = true, RegisterUsersImmediately = registerUsers
                    }.Save();
                    tenant.TrustedDomainsType = registerUsers ? TenantTrustedDomainsType.All : TenantTrustedDomainsType.None;
                    CoreContext.TenantManager.SaveTenant(tenant);
                }

                return(new
                {
                    Status = 1,
                    Message = Resource.SuccessfullySaveSettingsMessage
                });
            }
            catch (Exception e)
            {
                return(new
                {
                    Status = 0,
                    Message = e.Message.HtmlEncode()
                });
            }
        }
Пример #2
0
 public IEnumerable <string> SaveIpRestrictions(IEnumerable <string> ips)
 {
     SecurityContext.DemandPermissions(SecutiryConstants.EditPortalSettings);
     return(IPRestrictionsService.Save(ips, CurrentTenant));
 }
 public IEnumerable <string> SaveIpRestrictions(IpRestrictionsModel model)
 {
     SecurityContext.DemandPermissions(Tenant, SecutiryConstants.EditPortalSettings);
     return(IPRestrictionsService.Save(model.Ips, Tenant.TenantId));
 }