/// <summary> /// Performs object type seed /// </summary> /// <typeparam name="TDbCtx"></typeparam> /// <param name="context"></param> /// <param name="filter">Fully qualified namespaces to be taken into account when auto seeding object types</param> private static void SeedObjectTypes <TDbCtx>(TDbCtx context, IEnumerable <string> filter = null) where TDbCtx : ApplicationDbContext { //this is an automated seed, so ignore scenarios where context is not an app context if (context == null) { return; } foreach (var type in BaseObjectTypeIdentifierExtensions.GetRegisteredBaseSubclassingTypes()) { if (VerifyObjectType(type, filter)) { //context.ObjectTypes.AddOrUpdate(new ObjectType { Name = type.ToString(), Uuid = ObjectTypeExtensions.GetTypeUuid(type) }); if (!context.ObjectTypes.Any(o => o.Uuid == BaseObjectTypeIdentifierExtensions.GetTypeIdentifier(type))) { context.ObjectTypes.Add(new ObjectType { Name = type.ToString(), Uuid = BaseObjectTypeIdentifierExtensions.GetTypeIdentifier(type) }); } } } }
/// <summary> /// Whether or not request can perform a update action /// </summary> /// <returns></returns> protected virtual async Task <bool> IsCrudPrivilegeGrantedForUpdateAsync(DbContext dbCtx) { // Check if permission is required if (!IsCrudPrivilegeRequiredForUpdate) { return(true); } var roles = await GetUserRoles(dbCtx, Cartomatic.Utils.Identity.GetUserGuid()); // Check if user roles have required permission return(roles.Any(r => r.Privileges?.Any(p => p.TypeId == BaseObjectTypeIdentifierExtensions.GetTypeIdentifier(typeof(T)) && p.Update == true) == true)); }
/// <summary> /// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. /// </summary> /// <param name="app"></param> /// <param name="env"></param> /// <param name="settings"></param> public static void ConfigureMapHiveApi(this IApplicationBuilder app, IWebHostEnvironment env, ApiConfigurationSettings settings) { //this makes sure all the types inheriting from object base auto register themselves BaseObjectTypeIdentifierExtensions.AutoRegisterBaseTypes(); //store some common settings CommonSettings.Set(nameof(settings.AppShortNames), settings?.AppShortNames); CommonSettings.Set(nameof(settings.EnableRollbarLogging), settings?.EnableRollbarLogging); //plug in early, so can watch compressed input if (settings?.EnableCompression == true) { app.UseInputGzipEncodingMiddleware(); } if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } //so can return the api docs too! app.UseStaticFiles(); //use the middleware for api token related preflight if (settings?.AllowApiTokenAccess == true) { app.UseTokenAuthorizeMiddleware(); } //auto swagger documentation if (!string.IsNullOrEmpty(settings?.XmlCommentsPath)) { app.UseSwagger(); app.UseSwaggerUI(c => { c.SwaggerEndpoint( $"/swagger/{(settings.UseGitVersion ? Cartomatic.Utils.Git.GetRepoVersion() : settings.ApiVersion)}/swagger.json", settings?.ApiTitle ?? "unknown-api" ); }); } //customize cors app.UseCors(builder => builder.CustomizeCors()); //example using a cors policy added in the service confi section //app.UseCors("MapHiveCors"); //enforce auth app.UseAuthentication(); //this should give us the ability to check the request lng in a case it has not been explicitly provided by a callee app.UseRequestLocalization(); //enable outgoing compression when required if (settings.EnableCompression) { app.UseResponseCompression(); } app.UseRouting(); app.UseEndpoints(endpoints => { endpoints.MapControllerRoute("default", "{controller}/{action}"); }); }
static Layer() { BaseObjectTypeIdentifierExtensions.RegisterTypeIdentifier(MethodInfo.GetCurrentMethod().DeclaringType, Guid.Parse("e40ad645-cdf7-44ed-8691-40f9b6cd4504")); }
static DataStore() { BaseObjectTypeIdentifierExtensions.RegisterTypeIdentifier(MethodInfo.GetCurrentMethod().DeclaringType, Guid.Parse("d84701ad-913f-4e99-9ed7-749230f132a5")); }