예제 #1
0
        public ExternalSharingRequest IsExternalSharingEnabled([FromBody]string value)
        {
            var _request = JsonConvert.DeserializeObject<ExternalSharingRequest>(value);
            _request.Success = false;

            try
            {
                AppOnlyAuthenticationTenant _auth = new AppOnlyAuthenticationTenant();
                _auth.TenantAdminUrl = _request.TenantAdminUrl;
                var _service = new Office365SiteProvisioningService();
                _service.Authentication = _auth;
                _request.ExternalSharingEnabled = _service.IsTenantExternalSharingEnabled(_request.TenantAdminUrl);
                _request.Success = true;
                return _request;
            }
            catch(Exception _ex)
            {
               _request.ErrorMessage = _ex.Message;
                OfficeDevPnP.Core.Diagnostics.Log.Error("ProvisioningController.IsExternalSharingEnabled", 
                   "There was an error processing the request. Exception: {0}", 
                   _ex);
               return _request;
            }
    
        }
예제 #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="siteUrl"></param>
        public virtual bool isSiteExternalSharingEnabled(string siteUrl)
        {
            ConfigManager _manager        = new ConfigManager();
            var           _tenantAdminUrl = _manager.GetAppSettingsKey("TenantAdminUrl");
            var           _returnResult   = false;

            AbstractSiteProvisioningService _siteService = new Office365SiteProvisioningService();

            _siteService.Authentication = new AppOnlyAuthenticationTenant();
            _siteService.Authentication.TenantAdminUrl = _tenantAdminUrl;

            _siteService.UsingContext(ctx =>
            {
                try
                {
                    Tenant _tenant            = new Tenant(ctx);
                    SiteProperties _siteProps = _tenant.GetSitePropertiesByUrl(siteUrl, false);
                    ctx.Load(_tenant);
                    ctx.Load(_siteProps);
                    ctx.ExecuteQuery();


                    var _tenantSharingCapability = _tenant.SharingCapability;
                    var _siteSharingCapability   = _siteProps.SharingCapability;

                    if (_tenantSharingCapability != SharingCapabilities.Disabled)
                    {
                        if (_siteSharingCapability != SharingCapabilities.Disabled)
                        {
                            // Enabled
                            _returnResult = true;
                        }
                        else
                        {
                            // Disabled
                            _returnResult = false;
                        }
                    }
                    else
                    {
                        // Disabled
                        _returnResult = false;
                    }
                }
                catch (Exception _ex)
                {
                    Log.Warning("AbstractSiteProvisioningService.IsSiteExternalSharingEnabled",
                                PCResources.SiteExternalSharing_Enabled_Error_Message,
                                siteUrl,
                                _ex);
                }
            });

            return(_returnResult);
        }
예제 #3
0
        public List<SitePolicyResults> GetSitePolicies()
        {
            var _returnResults = new List<SitePolicyResults>();
            ConfigManager _manager = new ConfigManager();

            AbstractSiteProvisioningService _siteService = new Office365SiteProvisioningService();
            var _auth = new AppOnlyAuthenticationTenant();
            _auth.SiteUrl = _manager.GetAppSettingsKey("SPHost");

            var _sitePolicies = _siteService.GetAvailablePolicies();
            foreach(var _sitePolicyEntity in _sitePolicies)
            {
                var _policy = new SitePolicyResults();
                _policy.Key = _sitePolicyEntity.Name;
                _policy.Value = _sitePolicyEntity.Description;
                _returnResults.Add(_policy);
            }
            return _returnResults;
        }
예제 #4
0
파일: siteedit.aspx.cs 프로젝트: tandis/PnP
        protected void Submit_Click(object sender, EventArgs e)
        {
            var _web = _ctx.Web;
           
            var _division = Request.Form["selectDivision"].ToString();
            var _updateDivision = string.Compare(this.lblDivision.Text, _division, StringComparison.InvariantCultureIgnoreCase) != 0;
            if (_updateDivision)
            {
                _web.SetPropertyBagValue(SITE_PROPERTY_DIVISION, _division);
            }

            var _region = Request.Form["selectRegions"].ToString();
            var _updateRegion = string.Compare(this.lblRegion.Text, _region, StringComparison.InvariantCultureIgnoreCase) != 0;
            if (_updateRegion)
            {
                _web.SetPropertyBagValue(SITE_PROPERTY_REGION, _region);
            }

            var _function = Request.Form["selectFunction"].ToString();
            var _updateFunction = string.Compare(this.lblFunction.Text, _function, StringComparison.InvariantCultureIgnoreCase) != 0;
            if (_updateFunction)
            {
                _web.SetPropertyBagValue(SITE_PROPERTY_FUNCTION, _function);
            }

            var _sitePolicyName = Request.Form["BusinessImpact"].ToString();
            var _updateSitePolicy = String.Compare(this.lblSitePolicy.Text, _sitePolicyName, StringComparison.InvariantCultureIgnoreCase) != 0;
            if(_updateSitePolicy)
            {
                AbstractSiteProvisioningService _siteService = new Office365SiteProvisioningService();
                var _auth = new AppOnlyAuthenticationSite();
                _auth.SiteUrl = this.Url.Value;
                _siteService.Authentication = _auth;
                _siteService.SetSitePolicy(_sitePolicyName);

            }

            Response.Redirect(this.Url.Value);
        }
예제 #5
0
파일: siteedit.aspx.cs 프로젝트: tandis/PnP
        private void SetUXAvailableSitePolicy()
        {
            AbstractSiteProvisioningService _siteService = new Office365SiteProvisioningService();
            var _auth = new AppOnlyAuthenticationSite();
            _auth.SiteUrl = this.Url.Value;
            _siteService.Authentication = _auth;

            var _sitePolicies = _siteService.GetAvailablePolicies();
            foreach (var _sitePolicyEntity in _sitePolicies)
            {
                this.BusinessImpact.Items.Add(_sitePolicyEntity.Name);
            }

            var _appliedSitePolicy = _siteService.GetAppliedSitePolicy();
            if(_appliedSitePolicy != null)
            {
                this.lblSitePolicy.Text = _appliedSitePolicy.Name;
                var _expirationDate = _ctx.Web.GetSiteExpirationDate();
                this.lblExpirationDate.Text = _expirationDate == DateTime.MinValue ? String.Format("{0}", "None") : String.Format("{0}", _expirationDate);
            }
            else
            {
                this.lblSitePolicy.Text = string.Format("{0}", "None");
                this.lblExpirationDate.Text = String.Format("{0}", "None");
            }
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="siteUrl"></param>
        public virtual bool isSiteExternalSharingEnabled(string siteUrl)
        {
            ConfigManager _manager = new ConfigManager();
            var _tenantAdminUrl = _manager.GetAppSettingsKey("TenantAdminUrl");
            var _returnResult = false;

            AbstractSiteProvisioningService _siteService = new Office365SiteProvisioningService();
            _siteService.Authentication = new AppOnlyAuthenticationTenant();
            _siteService.Authentication.TenantAdminUrl = _tenantAdminUrl;

            _siteService.UsingContext(ctx =>
            {
                try
                {
                    Tenant _tenant = new Tenant(ctx);
                    SiteProperties _siteProps = _tenant.GetSitePropertiesByUrl(siteUrl, false);
                    ctx.Load(_tenant);
                    ctx.Load(_siteProps);
                    ctx.ExecuteQuery();


                    var _tenantSharingCapability = _tenant.SharingCapability;
                    var _siteSharingCapability = _siteProps.SharingCapability;

                    if (_tenantSharingCapability != SharingCapabilities.Disabled)
                    {
                        if (_siteSharingCapability != SharingCapabilities.Disabled)
                        {
                            // Enabled
                            _returnResult = true;
                        }
                        else
                        {
                            // Disabled
                            _returnResult = false;
                        }
                    }
                    else
                    {
                        // Disabled
                        _returnResult = false;
                    }

                }
                catch (Exception _ex)
                {
                    Log.Warning("AbstractSiteProvisioningService.IsSiteExternalSharingEnabled",
                        PCResources.SiteExternalSharing_Enabled_Error_Message,
                        siteUrl,
                        _ex);
                }

            });

            return _returnResult;
        }