-
Notifications
You must be signed in to change notification settings - Fork 63
Expand file tree
/
Copy pathStartupExtenstions.cs
More file actions
100 lines (80 loc) · 3.52 KB
/
StartupExtenstions.cs
File metadata and controls
100 lines (80 loc) · 3.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
using cloudscribe.Core.Models.EventHandlers;
using cloudscribe.Core.SimpleContent;
using cloudscribe.Core.SimpleContent.EventHandlers;
using cloudscribe.Core.SimpleContent.Integration;
using cloudscribe.SimpleContent.Models;
using cloudscribe.SimpleContent.Web.Design;
using cloudscribe.SimpleContent.Web.TagHelpers;
using cloudscribe.Versioning;
using cloudscribe.Web.Navigation.Caching;
using Microsoft.AspNetCore.Authorization;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection.Extensions;
namespace Microsoft.Extensions.DependencyInjection
{
public static class StartupExtenstions
{
public static IServiceCollection AddCloudscribeCoreIntegrationForSimpleContent(
this IServiceCollection services,
IConfiguration configuration = null
)
{
services.AddScoped<IProjectSettingsResolver, SiteProjectSettingsResolver>();
services.AddScoped<IProjectSecurityResolver, ProjectSecurityResolver>();
services.TryAddScoped<IMediaProcessor, SiteFileSystemMediaProcessor>();
services.AddScoped<IBlogRoutes, MultiTenantBlogRoutes>();
services.AddScoped<IPageRoutes, MultiTenantPageRoutes>();
services.AddScoped<IRoleSelectorProperties, SiteRoleSelectorProperties>();
services.TryAddScoped<IAuthorNameResolver, AuthorNameResolver>();
services.TryAddScoped<IProjectEmailService, CoreProjectEmailService>();
services.AddScoped<ISimpleContentThemeHelper, SiteSimpleContentThemeHelper>();
services.AddScoped<ITreeCacheKeyResolver, SiteNavigationCacheKeyResolver>();
services.AddScoped<IHandleRoleUpdated, HandleRoleUpdated>();
services.AddScoped<IHandleRoleDeleted, HandleRoleDeleted>();
services.AddScoped<IVersionProvider, VersionProvider>();
if (configuration != null)
{
services.Configure<ContentSettingsUIConfig>(configuration.GetSection("ContentSettingsUIConfig"));
}
else
{
services.Configure<ContentSettingsUIConfig>(c =>
{
// not doing anything just configuring the default
});
}
return services;
}
public static AuthorizationOptions AddCloudscribeCoreSimpleContentIntegrationDefaultPolicies(this AuthorizationOptions options)
{
options.AddPolicy("BlogViewPolicy", policy =>
policy.RequireAssertion(context =>
{
return true; //allow anonymous
})
);
options.AddPolicy(
"BlogEditPolicy",
authBuilder =>
{
//authBuilder.RequireClaim("blogId");
authBuilder.RequireRole("Administrators", "Content Administrators");
}
);
options.AddPolicy(
"PageEditPolicy",
authBuilder =>
{
authBuilder.RequireRole("Administrators", "Content Administrators");
});
options.AddPolicy(
"ViewContentHistoryPolicy",
authBuilder =>
{
authBuilder.RequireRole("Administrators", "Content Administrators");
}
);
return options;
}
}
}