2020-10-23 10:10:02 +11:00
using System ;
2020-05-20 16:43:06 +10:00
using System.Collections.Generic ;
using System.Linq ;
using System.Runtime.Serialization ;
using System.Threading.Tasks ;
2020-08-20 22:18:50 +01:00
using Microsoft.AspNetCore.Http ;
using Microsoft.AspNetCore.Routing ;
using Microsoft.Extensions.Options ;
2020-05-20 16:43:06 +10:00
using Umbraco.Core ;
using Umbraco.Core.Configuration ;
2020-08-20 22:18:50 +01:00
using Umbraco.Core.Configuration.Models ;
2020-05-20 16:43:06 +10:00
using Umbraco.Core.Hosting ;
2020-09-22 15:06:03 +02:00
using Umbraco.Core.Media ;
2020-05-20 16:43:06 +10:00
using Umbraco.Core.WebAssets ;
using Umbraco.Extensions ;
2020-10-21 10:29:25 +01:00
using Umbraco.Web.BackOffice.HealthCheck ;
2020-05-26 17:42:51 +10:00
using Umbraco.Web.BackOffice.Profiling ;
using Umbraco.Web.BackOffice.PropertyEditors ;
2020-09-30 10:02:28 +02:00
using Umbraco.Web.BackOffice.Routing ;
2020-11-27 13:33:01 +01:00
using Umbraco.Web.BackOffice.Security ;
2020-10-26 16:18:48 +01:00
using Umbraco.Web.BackOffice.Trees ;
2020-05-20 16:43:06 +10:00
using Umbraco.Web.Common.Attributes ;
using Umbraco.Web.Features ;
2020-06-03 19:52:43 +02:00
using Umbraco.Web.Models.ContentEditing ;
2020-05-20 16:43:06 +10:00
using Umbraco.Web.Trees ;
namespace Umbraco.Web.BackOffice.Controllers
{
/// <summary>
/// Used to collect the server variables for use in the back office angular app
/// </summary>
public class BackOfficeServerVariables
{
private readonly LinkGenerator _linkGenerator ;
private readonly IRuntimeState _runtimeState ;
private readonly UmbracoFeatures _features ;
2020-08-21 14:52:47 +01:00
private readonly GlobalSettings _globalSettings ;
2020-05-20 16:43:06 +10:00
private readonly IUmbracoVersion _umbracoVersion ;
2020-08-20 22:18:50 +01:00
private readonly ContentSettings _contentSettings ;
2020-06-09 07:49:26 +02:00
private readonly TreeCollection _treeCollection ;
2020-05-20 16:43:06 +10:00
private readonly IHttpContextAccessor _httpContextAccessor ;
private readonly IHostingEnvironment _hostingEnvironment ;
2020-08-20 22:18:50 +01:00
private readonly RuntimeSettings _runtimeSettings ;
private readonly SecuritySettings _securitySettings ;
2020-05-20 16:43:06 +10:00
private readonly IRuntimeMinifier _runtimeMinifier ;
2020-10-23 14:18:53 +11:00
private readonly IBackOfficeExternalLoginProviders _externalLogins ;
2020-09-22 15:06:03 +02:00
private readonly IImageUrlGenerator _imageUrlGenerator ;
2020-10-01 07:03:31 +02:00
private readonly PreviewRoutes _previewRoutes ;
2020-05-20 16:43:06 +10:00
public BackOfficeServerVariables (
LinkGenerator linkGenerator ,
IRuntimeState runtimeState ,
UmbracoFeatures features ,
2020-08-23 23:36:48 +02:00
IOptions < GlobalSettings > globalSettings ,
2020-05-20 16:43:06 +10:00
IUmbracoVersion umbracoVersion ,
2020-08-23 23:36:48 +02:00
IOptions < ContentSettings > contentSettings ,
2020-05-25 19:37:16 +10:00
IHttpContextAccessor httpContextAccessor ,
2020-06-09 07:49:26 +02:00
TreeCollection treeCollection ,
2020-05-20 16:43:06 +10:00
IHostingEnvironment hostingEnvironment ,
2020-08-23 23:36:48 +02:00
IOptions < RuntimeSettings > runtimeSettings ,
IOptions < SecuritySettings > securitySettings ,
2020-05-20 16:43:06 +10:00
IRuntimeMinifier runtimeMinifier ,
2020-10-23 14:18:53 +11:00
IBackOfficeExternalLoginProviders externalLogins ,
2020-09-30 10:02:28 +02:00
IImageUrlGenerator imageUrlGenerator ,
2020-10-01 07:03:31 +02:00
PreviewRoutes previewRoutes )
2020-05-20 16:43:06 +10:00
{
_linkGenerator = linkGenerator ;
_runtimeState = runtimeState ;
_features = features ;
2020-08-21 14:52:47 +01:00
_globalSettings = globalSettings . Value ;
2020-05-20 16:43:06 +10:00
_umbracoVersion = umbracoVersion ;
2020-08-20 22:18:50 +01:00
_contentSettings = contentSettings . Value ? ? throw new ArgumentNullException ( nameof ( contentSettings ) ) ;
2020-05-25 19:37:16 +10:00
_httpContextAccessor = httpContextAccessor ;
2020-06-09 07:49:26 +02:00
_treeCollection = treeCollection ? ? throw new ArgumentNullException ( nameof ( treeCollection ) ) ;
2020-05-20 16:43:06 +10:00
_hostingEnvironment = hostingEnvironment ;
2020-08-20 22:18:50 +01:00
_runtimeSettings = runtimeSettings . Value ;
_securitySettings = securitySettings . Value ;
2020-05-20 16:43:06 +10:00
_runtimeMinifier = runtimeMinifier ;
2020-10-23 14:18:53 +11:00
_externalLogins = externalLogins ;
2020-09-22 15:06:03 +02:00
_imageUrlGenerator = imageUrlGenerator ;
2020-10-01 07:03:31 +02:00
_previewRoutes = previewRoutes ;
2020-05-20 16:43:06 +10:00
}
/// <summary>
/// Returns the server variables for non-authenticated users
/// </summary>
/// <returns></returns>
internal async Task < Dictionary < string , object > > BareMinimumServerVariablesAsync ( )
{
//this is the filter for the keys that we'll keep based on the full version of the server vars
var keepOnlyKeys = new Dictionary < string , string [ ] >
{
2020-09-30 10:02:28 +02:00
{ "umbracoUrls" , new [ ] { "authenticationApiBaseUrl" , "serverVarsJs" , "externalLoginsUrl" , "currentUserApiBaseUrl" , "previewHubUrl" } } ,
2020-12-09 09:23:48 +01:00
{ "umbracoSettings" , new [ ] { "allowPasswordReset" , "imageFileTypes" , "maxFileSize" , "loginBackgroundImage" , "loginLogoImage" , "canSendRequiredEmail" , "usernameIsEmail" } } ,
2020-05-20 16:43:06 +10:00
{ "application" , new [ ] { "applicationPath" , "cacheBuster" } } ,
{ "isDebuggingEnabled" , new string [ ] { } } ,
{ "features" , new [ ] { "disabledFeatures" } }
} ;
//now do the filtering...
var defaults = await GetServerVariablesAsync ( ) ;
foreach ( var key in defaults . Keys . ToArray ( ) )
{
if ( keepOnlyKeys . ContainsKey ( key ) = = false )
{
defaults . Remove ( key ) ;
}
else
{
if ( defaults [ key ] is System . Collections . IDictionary asDictionary )
{
var toKeep = keepOnlyKeys [ key ] ;
foreach ( var k in asDictionary . Keys . Cast < string > ( ) . ToArray ( ) )
{
if ( toKeep . Contains ( k ) = = false )
{
asDictionary . Remove ( k ) ;
}
}
}
}
}
// TODO: This is ultra confusing! this same key is used for different things, when returning the full app when authenticated it is this URL but when not auth'd it's actually the ServerVariables address
// so based on compat and how things are currently working we need to replace the serverVarsJs one
2020-05-25 23:15:32 +10:00
( ( Dictionary < string , object > ) defaults [ "umbracoUrls" ] ) [ "serverVarsJs" ]
= _linkGenerator . GetPathByAction (
nameof ( BackOfficeController . ServerVariables ) ,
ControllerExtensions . GetControllerName < BackOfficeController > ( ) ,
new { area = Constants . Web . Mvc . BackOfficeArea } ) ;
2020-05-20 16:43:06 +10:00
return defaults ;
}
/// <summary>
/// Returns the server variables for authenticated users
/// </summary>
/// <returns></returns>
2020-11-27 13:34:32 +01:00
internal Task < Dictionary < string , object > > GetServerVariablesAsync ( )
2020-05-20 16:43:06 +10:00
{
var globalSettings = _globalSettings ;
2020-05-25 23:15:32 +10:00
var backOfficeControllerName = ControllerExtensions . GetControllerName < BackOfficeController > ( ) ;
2020-05-20 16:43:06 +10:00
var defaultVals = new Dictionary < string , object >
{
{
"umbracoUrls" , new Dictionary < string , object >
{
// TODO: Add 'umbracoApiControllerBaseUrl' which people can use in JS
// to prepend their URL. We could then also use this in our own resources instead of
2020-10-05 20:48:38 +02:00
// having each URL defined here explicitly - we can do that in v8! for now
2020-05-20 16:43:06 +10:00
// for umbraco services we'll stick to explicitly defining the endpoints.
2020-11-27 13:34:32 +01:00
{ "externalLoginsUrl" , _linkGenerator . GetPathByAction ( nameof ( BackOfficeController . ExternalLogin ) , backOfficeControllerName , new { area = Constants . Web . Mvc . BackOfficeArea } ) } ,
{ "externalLinkLoginsUrl" , _linkGenerator . GetPathByAction ( nameof ( BackOfficeController . LinkLogin ) , backOfficeControllerName , new { area = Constants . Web . Mvc . BackOfficeArea } ) } ,
2020-05-25 23:15:32 +10:00
{ "gridConfig" , _linkGenerator . GetPathByAction ( nameof ( BackOfficeController . GetGridConfig ) , backOfficeControllerName , new { area = Constants . Web . Mvc . BackOfficeArea } ) } ,
2020-05-20 16:43:06 +10:00
// TODO: This is ultra confusing! this same key is used for different things, when returning the full app when authenticated it is this URL but when not auth'd it's actually the ServerVariables address
2020-05-25 23:15:32 +10:00
{ "serverVarsJs" , _linkGenerator . GetPathByAction ( nameof ( BackOfficeController . Application ) , backOfficeControllerName , new { area = Constants . Web . Mvc . BackOfficeArea } ) } ,
2020-05-20 16:43:06 +10:00
//API URLs
{
"packagesRestApiBaseUrl" , Constants . PackageRepository . RestApiBaseUrl
} ,
2020-06-03 19:52:43 +02:00
{
"redirectUrlManagementApiBaseUrl" , _linkGenerator . GetUmbracoApiServiceBaseUrl < RedirectUrlManagementController > (
controller = > controller . GetEnableState ( ) )
} ,
2020-05-25 23:15:32 +10:00
{
"tourApiBaseUrl" , _linkGenerator . GetUmbracoApiServiceBaseUrl < TourController > (
controller = > controller . GetTours ( ) )
} ,
2020-05-26 17:42:51 +10:00
{
"embedApiBaseUrl" , _linkGenerator . GetUmbracoApiServiceBaseUrl < RteEmbedController > (
controller = > controller . GetEmbed ( "" , 0 , 0 ) )
} ,
2020-06-22 10:08:08 +02:00
{
"userApiBaseUrl" , _linkGenerator . GetUmbracoApiServiceBaseUrl < UsersController > (
controller = > controller . PostSaveUser ( null ) )
} ,
{
"userGroupsApiBaseUrl" , _linkGenerator . GetUmbracoApiServiceBaseUrl < UserGroupsController > (
controller = > controller . PostSaveUserGroup ( null ) )
} ,
2020-06-09 13:48:50 +02:00
{
"contentApiBaseUrl" , _linkGenerator . GetUmbracoApiServiceBaseUrl < ContentController > (
controller = > controller . PostSave ( null ) )
} ,
2020-06-12 22:13:43 +02:00
{
"mediaApiBaseUrl" , _linkGenerator . GetUmbracoApiServiceBaseUrl < MediaController > (
controller = > controller . GetRootMedia ( ) )
} ,
2020-08-26 08:05:15 +02:00
{
"iconApiBaseUrl" , _linkGenerator . GetUmbracoApiServiceBaseUrl < IconController > (
controller = > controller . GetIcon ( "" ) )
} ,
2020-05-25 23:15:32 +10:00
{
"imagesApiBaseUrl" , _linkGenerator . GetUmbracoApiServiceBaseUrl < ImagesController > (
controller = > controller . GetBigThumbnail ( "" ) )
} ,
2020-06-11 08:00:35 +02:00
{
"sectionApiBaseUrl" , _linkGenerator . GetUmbracoApiServiceBaseUrl < SectionController > (
controller = > controller . GetSections ( ) )
} ,
{
"treeApplicationApiBaseUrl" , _linkGenerator . GetUmbracoApiServiceBaseUrl < ApplicationTreeController > (
controller = > controller . GetApplicationTrees ( null , null , null , TreeUse . None ) )
} ,
2020-06-12 22:13:43 +02:00
{
"contentTypeApiBaseUrl" , _linkGenerator . GetUmbracoApiServiceBaseUrl < ContentTypeController > (
controller = > controller . GetAllowedChildren ( 0 ) )
} ,
{
"mediaTypeApiBaseUrl" , _linkGenerator . GetUmbracoApiServiceBaseUrl < MediaTypeController > (
controller = > controller . GetAllowedChildren ( 0 ) )
} ,
2020-06-04 12:53:08 +02:00
{
"macroRenderingApiBaseUrl" , _linkGenerator . GetUmbracoApiServiceBaseUrl < MacroRenderingController > (
controller = > controller . GetMacroParameters ( 0 ) )
} ,
2020-06-03 20:39:54 +02:00
{
"macroApiBaseUrl" , _linkGenerator . GetUmbracoApiServiceBaseUrl < MacrosController > (
controller = > controller . Create ( null ) )
} ,
2020-05-25 23:15:32 +10:00
{
"authenticationApiBaseUrl" , _linkGenerator . GetUmbracoApiServiceBaseUrl < AuthenticationController > (
controller = > controller . PostLogin ( null ) )
} ,
2020-06-22 10:08:08 +02:00
{
"currentUserApiBaseUrl" , _linkGenerator . GetUmbracoApiServiceBaseUrl < CurrentUserController > (
controller = > controller . PostChangePassword ( null ) )
} ,
2020-06-15 13:07:49 +02:00
{
"entityApiBaseUrl" , _linkGenerator . GetUmbracoApiServiceBaseUrl < EntityController > (
controller = > controller . GetById ( 0 , UmbracoEntityTypes . Media ) )
} ,
2020-06-03 19:52:43 +02:00
{
"dataTypeApiBaseUrl" , _linkGenerator . GetUmbracoApiServiceBaseUrl < DataTypeController > (
controller = > controller . GetById ( 0 ) )
} ,
2020-05-25 23:15:32 +10:00
{
"dashboardApiBaseUrl" , _linkGenerator . GetUmbracoApiServiceBaseUrl < DashboardController > (
controller = > controller . GetDashboard ( null ) )
} ,
2020-06-03 19:52:43 +02:00
{
"logApiBaseUrl" , _linkGenerator . GetUmbracoApiServiceBaseUrl < LogController > (
controller = > controller . GetPagedEntityLog ( 0 , 0 , 0 , Direction . Ascending , null ) )
} ,
2020-06-18 21:03:11 +02:00
{
"memberApiBaseUrl" , _linkGenerator . GetUmbracoApiServiceBaseUrl < MemberController > (
controller = > controller . GetByKey ( Guid . Empty ) )
} ,
2020-06-03 19:52:43 +02:00
{
"packageInstallApiBaseUrl" , _linkGenerator . GetUmbracoApiServiceBaseUrl < PackageInstallController > (
controller = > controller . Fetch ( string . Empty ) )
} ,
{
"packageApiBaseUrl" , _linkGenerator . GetUmbracoApiServiceBaseUrl < PackageController > (
controller = > controller . GetCreatedPackages ( ) )
} ,
{
"relationApiBaseUrl" , _linkGenerator . GetUmbracoApiServiceBaseUrl < RelationController > (
controller = > controller . GetById ( 0 ) )
} ,
2020-05-26 17:42:51 +10:00
{
"rteApiBaseUrl" , _linkGenerator . GetUmbracoApiServiceBaseUrl < RichTextPreValueController > (
controller = > controller . GetConfiguration ( ) )
} ,
2020-06-03 19:52:43 +02:00
{
"stylesheetApiBaseUrl" , _linkGenerator . GetUmbracoApiServiceBaseUrl < StylesheetController > (
controller = > controller . GetAll ( ) )
} ,
2020-06-18 21:03:11 +02:00
{
"memberTypeApiBaseUrl" , _linkGenerator . GetUmbracoApiServiceBaseUrl < MemberTypeController > (
controller = > controller . GetAllTypes ( ) )
} ,
2020-06-22 10:08:08 +02:00
{
"memberGroupApiBaseUrl" , _linkGenerator . GetUmbracoApiServiceBaseUrl < MemberGroupController > (
controller = > controller . GetAllGroups ( ) )
} ,
2020-06-03 19:52:43 +02:00
{
"updateCheckApiBaseUrl" , _linkGenerator . GetUmbracoApiServiceBaseUrl < UpdateCheckController > (
controller = > controller . GetCheck ( ) )
} ,
{
"templateApiBaseUrl" , _linkGenerator . GetUmbracoApiServiceBaseUrl < TemplateController > (
controller = > controller . GetById ( 0 ) )
} ,
2020-06-09 07:49:26 +02:00
{
"memberTreeBaseUrl" , _linkGenerator . GetUmbracoApiServiceBaseUrl < MemberTreeController > (
controller = > controller . GetNodes ( "-1" , null ) )
} ,
{
"mediaTreeBaseUrl" , _linkGenerator . GetUmbracoApiServiceBaseUrl < MediaTreeController > (
controller = > controller . GetNodes ( "-1" , null ) )
} ,
{
"contentTreeBaseUrl" , _linkGenerator . GetUmbracoApiServiceBaseUrl < ContentTreeController > (
controller = > controller . GetNodes ( "-1" , null ) )
} ,
2020-05-26 17:42:51 +10:00
{
"tagsDataBaseUrl" , _linkGenerator . GetUmbracoApiServiceBaseUrl < TagsDataController > (
controller = > controller . GetTags ( "" , "" , null ) )
} ,
2020-05-25 23:15:32 +10:00
{
"examineMgmtBaseUrl" , _linkGenerator . GetUmbracoApiServiceBaseUrl < ExamineManagementController > (
controller = > controller . GetIndexerDetails ( ) )
} ,
2020-05-26 17:42:51 +10:00
{
"healthCheckBaseUrl" , _linkGenerator . GetUmbracoApiServiceBaseUrl < HealthCheckController > (
controller = > controller . GetAllHealthChecks ( ) )
} ,
2020-06-22 10:08:08 +02:00
{
"templateQueryApiBaseUrl" , _linkGenerator . GetUmbracoApiServiceBaseUrl < TemplateQueryController > (
controller = > controller . PostTemplateQuery ( null ) )
} ,
2020-06-03 19:52:43 +02:00
{
"codeFileApiBaseUrl" , _linkGenerator . GetUmbracoApiServiceBaseUrl < CodeFileController > (
controller = > controller . GetByPath ( "" , "" ) )
} ,
{
"publishedStatusBaseUrl" , _linkGenerator . GetUmbracoApiServiceBaseUrl < PublishedStatusController > (
controller = > controller . GetPublishedStatusUrl ( ) )
} ,
{
"dictionaryApiBaseUrl" , _linkGenerator . GetUmbracoApiServiceBaseUrl < DictionaryController > (
controller = > controller . DeleteById ( int . MaxValue ) )
} ,
{
"publishedSnapshotCacheStatusBaseUrl" , _linkGenerator . GetUmbracoApiServiceBaseUrl < PublishedSnapshotCacheStatusController > (
controller = > controller . GetStatus ( ) )
} ,
2020-05-25 23:15:32 +10:00
{
"helpApiBaseUrl" , _linkGenerator . GetUmbracoApiServiceBaseUrl < HelpController > (
controller = > controller . GetContextHelpForPage ( "" , "" , "" ) )
} ,
2020-06-03 19:52:43 +02:00
{
"backOfficeAssetsApiBaseUrl" , _linkGenerator . GetUmbracoApiServiceBaseUrl < BackOfficeAssetsController > (
controller = > controller . GetSupportedLocales ( ) )
} ,
{
"languageApiBaseUrl" , _linkGenerator . GetUmbracoApiServiceBaseUrl < LanguageController > (
controller = > controller . GetAllLanguages ( ) )
} ,
{
"relationTypeApiBaseUrl" , _linkGenerator . GetUmbracoApiServiceBaseUrl < RelationTypeController > (
controller = > controller . GetById ( 1 ) )
} ,
{
"logViewerApiBaseUrl" , _linkGenerator . GetUmbracoApiServiceBaseUrl < LogViewerController > (
controller = > controller . GetNumberOfErrors ( null , null ) )
} ,
2020-05-26 17:42:51 +10:00
{
"webProfilingBaseUrl" , _linkGenerator . GetUmbracoApiServiceBaseUrl < WebProfilingController > (
controller = > controller . GetStatus ( ) )
} ,
2020-06-03 19:52:43 +02:00
{
"tinyMceApiBaseUrl" , _linkGenerator . GetUmbracoApiServiceBaseUrl < TinyMceController > (
controller = > controller . UploadImage ( null ) )
} ,
2020-05-25 23:15:32 +10:00
{
"imageUrlGeneratorApiBaseUrl" , _linkGenerator . GetUmbracoApiServiceBaseUrl < ImageUrlGeneratorController > (
controller = > controller . GetCropUrl ( null , null , null , null , null ) )
} ,
2020-08-07 14:00:56 +02:00
{
"elementTypeApiBaseUrl" , _linkGenerator . GetUmbracoApiServiceBaseUrl < ElementTypeController > (
controller = > controller . GetAll ( ) )
} ,
2020-09-30 10:02:28 +02:00
{
2020-10-01 07:03:31 +02:00
"previewHubUrl" , _previewRoutes . GetPreviewHubRoute ( )
2020-09-30 10:02:28 +02:00
} ,
2020-05-20 16:43:06 +10:00
}
} ,
{
"umbracoSettings" , new Dictionary < string , object >
{
{ "umbracoPath" , _globalSettings . GetBackOfficePath ( _hostingEnvironment ) } ,
{ "mediaPath" , _hostingEnvironment . ToAbsolute ( globalSettings . UmbracoMediaPath ) . TrimEnd ( '/' ) } ,
{ "appPluginsPath" , _hostingEnvironment . ToAbsolute ( Constants . SystemDirectories . AppPlugins ) . TrimEnd ( '/' ) } ,
{
"imageFileTypes" ,
2020-09-22 15:06:03 +02:00
string . Join ( "," , _imageUrlGenerator . SupportedImageFileTypes )
2020-05-20 16:43:06 +10:00
} ,
{
"disallowedUploadFiles" ,
string . Join ( "," , _contentSettings . DisallowedUploadFiles )
} ,
{
"allowedUploadFiles" ,
string . Join ( "," , _contentSettings . AllowedUploadFiles )
} ,
{
"maxFileSize" ,
GetMaxRequestLength ( )
} ,
{ "keepUserLoggedIn" , _securitySettings . KeepUserLoggedIn } ,
{ "usernameIsEmail" , _securitySettings . UsernameIsEmail } ,
{ "cssPath" , _hostingEnvironment . ToAbsolute ( globalSettings . UmbracoCssPath ) . TrimEnd ( '/' ) } ,
{ "allowPasswordReset" , _securitySettings . AllowPasswordReset } ,
{ "loginBackgroundImage" , _contentSettings . LoginBackgroundImage } ,
2021-01-18 15:40:22 +01:00
{ "loginLogoImage" , _contentSettings . LoginLogoImage } ,
2020-05-20 16:43:06 +10:00
{ "showUserInvite" , EmailSender . CanSendRequiredEmail ( globalSettings ) } ,
{ "canSendRequiredEmail" , EmailSender . CanSendRequiredEmail ( globalSettings ) } ,
{ "showAllowSegmentationForDocumentTypes" , false } ,
}
} ,
{
"umbracoPlugins" , new Dictionary < string , object >
{
// for each tree that is [PluginController], get
// alias -> areaName
// so that routing (route.js) can look for views
{ "trees" , GetPluginTrees ( ) . ToArray ( ) }
}
} ,
{
"isDebuggingEnabled" , _hostingEnvironment . IsDebugMode
} ,
{
"application" , GetApplicationState ( )
} ,
{
"externalLogins" , new Dictionary < string , object >
{
{
2020-11-27 13:34:32 +01:00
// TODO: It would be nicer to not have to manually translate these properties
// but then needs to be changed in quite a few places in angular
2020-10-23 14:18:53 +11:00
"providers" , _externalLogins . GetBackOfficeProviders ( )
2020-05-20 16:43:06 +10:00
. Select ( p = > new
{
2020-11-27 13:34:32 +01:00
authType = p . AuthenticationType ,
caption = p . Name ,
2020-11-27 13:33:01 +01:00
properties = p . Options
2020-05-20 16:43:06 +10:00
} )
. ToArray ( )
}
}
} ,
{
"features" , new Dictionary < string , object >
{
{
"disabledFeatures" , new Dictionary < string , object >
{
{ "disableTemplates" , _features . Disabled . DisableTemplates }
}
}
}
}
} ;
2020-11-27 13:34:32 +01:00
return Task . FromResult ( defaultVals ) ;
2020-05-20 16:43:06 +10:00
}
[DataContract]
private class PluginTree
{
[DataMember(Name = "alias")]
public string Alias { get ; set ; }
[DataMember(Name = "packageFolder")]
public string PackageFolder { get ; set ; }
}
private IEnumerable < PluginTree > GetPluginTrees ( )
{
// used to be (cached)
//var treeTypes = Current.TypeLoader.GetAttributedTreeControllers();
//
// ie inheriting from TreeController and marked with TreeAttribute
//
// do this instead
// inheriting from TreeControllerBase and marked with TreeAttribute
2020-06-09 07:49:26 +02:00
foreach ( var tree in _treeCollection )
{
var treeType = tree . TreeControllerType ;
2020-05-20 16:43:06 +10:00
2020-06-09 07:49:26 +02:00
// exclude anything marked with CoreTreeAttribute
var coreTree = treeType . GetCustomAttribute < CoreTreeAttribute > ( false ) ;
if ( coreTree ! = null ) continue ;
2020-05-20 16:43:06 +10:00
2020-06-09 07:49:26 +02:00
// exclude anything not marked with PluginControllerAttribute
var pluginController = treeType . GetCustomAttribute < PluginControllerAttribute > ( false ) ;
if ( pluginController = = null ) continue ;
2020-05-20 16:43:06 +10:00
2020-06-09 07:49:26 +02:00
yield return new PluginTree { Alias = tree . TreeAlias , PackageFolder = pluginController . AreaName } ;
}
2020-05-20 16:43:06 +10:00
}
/// <summary>
/// Returns the server variables regarding the application state
/// </summary>
/// <returns></returns>
private Dictionary < string , object > GetApplicationState ( )
{
var app = new Dictionary < string , object >
{
// add versions - see UmbracoVersion for details & differences
// the complete application version (eg "8.1.2-alpha.25")
{ "version" , _umbracoVersion . SemanticVersion . ToSemanticString ( ) } ,
// the assembly version (eg "8.0.0")
{ "assemblyVersion" , _umbracoVersion . AssemblyVersion . ToString ( ) }
} ;
var version = _runtimeState . SemanticVersion . ToSemanticString ( ) ;
//the value is the hash of the version, cdf version and the configured state
app . Add ( "cacheBuster" , $"{version}.{_runtimeState.Level}.{_runtimeMinifier.CacheBuster}" . GenerateHash ( ) ) ;
//useful for dealing with virtual paths on the client side when hosted in virtual directories especially
app . Add ( "applicationPath" , _httpContextAccessor . GetRequiredHttpContext ( ) . Request . PathBase . ToString ( ) . EnsureEndsWith ( '/' ) ) ;
//add the server's GMT time offset in minutes
app . Add ( "serverTimeOffset" , Convert . ToInt32 ( DateTimeOffset . Now . Offset . TotalMinutes ) ) ;
return app ;
}
private string GetMaxRequestLength ( )
{
2020-08-20 22:18:50 +01:00
return _runtimeSettings . MaxRequestLength . HasValue ? _runtimeSettings . MaxRequestLength . Value . ToString ( ) : string . Empty ;
2020-05-20 16:43:06 +10:00
}
}
}