Skip to content

Commit

Permalink
solve #356 and #345
Browse files Browse the repository at this point in the history
  • Loading branch information
joeaudette committed Oct 23, 2018
1 parent a94309a commit f054e91
Show file tree
Hide file tree
Showing 26 changed files with 430 additions and 189 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public async Task<ProjectSecurityResult> ValidatePermissions(
var isAuthenticated = false;
var canEditPosts = false;
var canEditPages = false;
var timeZoneId = userManager.Site.TimeZoneId;

var authUser = await userManager.FindByNameAsync(userName);

Expand Down Expand Up @@ -75,9 +76,14 @@ public async Task<ProjectSecurityResult> ValidatePermissions(

//displayName = claimsPrincipal.GetDisplayName();
displayName = claimsPrincipal.Identity.Name;
if(!string.IsNullOrWhiteSpace(authUser.TimeZoneId))
{
timeZoneId = authUser.TimeZoneId;
}

}

var blogSecurity = new ProjectSecurityResult(displayName, projectId, isAuthenticated, canEditPosts, canEditPages);
var blogSecurity = new ProjectSecurityResult(displayName, projectId, isAuthenticated, canEditPosts, canEditPages, timeZoneId);

return blogSecurity;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

<PropertyGroup>
<Description>integration library for integrating cloudscribe SimpleContent with cloudscribe Core multi-tenant web app foundation</Description>
<VersionPrefix>4.0.2</VersionPrefix>
<AssemblyVersion>4.0.2</AssemblyVersion>
<VersionPrefix>4.0.3</VersionPrefix>
<AssemblyVersion>4.0.3</AssemblyVersion>
<Authors>Joe Audette</Authors>
<TargetFrameworks>netstandard2.0</TargetFrameworks>
<PackageTags>cloudscribe;blog</PackageTags>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ bool commentsOpen
{
PostStruct p = new PostStruct();



p.author = post.Author;
p.categories = post.Categories;
p.commentPolicy = commentsOpen ? "1" : "0";
Expand Down
273 changes: 202 additions & 71 deletions src/cloudscribe.SimpleContent.MetaWeblog/MetaWeblogService.cs

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

<PropertyGroup>
<Description>cloudscribe.SimpleContent.MetaWeblog Class Library</Description>
<VersionPrefix>4.0.4</VersionPrefix>
<AssemblyVersion>4.0.4</AssemblyVersion>
<VersionPrefix>4.0.5</VersionPrefix>
<AssemblyVersion>4.0.5</AssemblyVersion>
<Authors>Joe Audette</Authors>
<TargetFrameworks>netstandard2.0</TargetFrameworks>
<PackageTags>cloudscribe;metaweblog;blog;cms</PackageTags>
Expand All @@ -22,6 +22,7 @@
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="2.1.0" />
<PackageReference Include="cloudscribe.MetaWeblog" Version="2.1.4" />
<PackageReference Include="cloudscribe.Web.Common" Version="3.0.14" />
</ItemGroup>


Expand Down
12 changes: 6 additions & 6 deletions src/cloudscribe.SimpleContent.Models/Blog/IBlogService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,14 @@ Task<PagedPostResult> GetPosts(

Task Delete(string postId);

Task Create(IPost post, bool convertToRelativeUrls = false);
Task Create(IPost post);

Task Update(IPost post, bool convertToRelativeUrls = false);
Task Update(IPost post);

Task SaveMedia(
string projectId,
byte[] bytes,
string fileName);
//Task SaveMedia(
// string projectId,
// byte[] bytes,
// string fileName);

Task FirePublishEvent(IPost post);
Task FireUnPublishEvent(IPost post);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ public interface IBlogUrlResolver
{
Task<string> ResolveBlogUrl(IProjectSettings project);
Task<string> ResolvePostUrl(IPost post, IProjectSettings projectSettings);
Task ConvertToRelativeUrls(IPost post, IProjectSettings projectSettings);
Task ConvertMediaToRelativeUrls(IPost post);
Task ConvertMediaToAbsoluteUrls(IPost post, IProjectSettings projectSettings);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -93,20 +93,20 @@ public Task<PagedPostResult> GetPosts(
}


public Task Create(IPost post, bool convertToRelativeUrls = false)
public Task Create(IPost post)
{
throw new NotImplementedException();
}

public Task Update(IPost post, bool convertToRelativeUrls = false)
public Task Update(IPost post)
{
throw new NotImplementedException();
}

public Task SaveMedia(string blogId, byte[] bytes, string fileName)
{
throw new NotImplementedException();
}
//public Task SaveMedia(string blogId, byte[] bytes, string fileName)
//{
// throw new NotImplementedException();
//}

public Task<bool> SlugIsAvailable(string slug)
{
Expand Down
1 change: 1 addition & 0 deletions src/cloudscribe.SimpleContent.Models/IMediaProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

namespace cloudscribe.SimpleContent.Models
{
// this is only uised in MetaweblogService
public interface IMediaProcessor
{
Task<string> ResolveMediaUrl(string mediaVirtualPath, string fileName);
Expand Down
4 changes: 2 additions & 2 deletions src/cloudscribe.SimpleContent.Models/Page/IPageService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ public interface IPageService
Task<IPage> GetPageBySlug(string slug, CancellationToken cancellationToken = default(CancellationToken));
Task<bool> SlugIsAvailable(string slug);

Task Create(IPage page, bool convertToRelativeUrls = false);
Task Create(IPage page);

Task Update(IPage page, bool convertToRelativeUrls = false);
Task Update(IPage page);

void ClearNavigationCache();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ namespace cloudscribe.SimpleContent.Models
public interface IPageUrlResolver
{
Task<string> ResolvePageUrl(IPage page);
Task ConvertToRelativeUrls(IPage page, IProjectSettings projectSettings);
Task ConvertMediaToRelativeUrls(IPage page);
Task ConvertMediaToAbsoluteUrls(IPage page, IProjectSettings projectSettings);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,12 @@ public Task DeletePage(string pageId)
}


public Task Create(IPage page, bool convertToRelativeUrls = false)
public Task Create(IPage page)
{
throw new NotImplementedException();
}

public Task Update(IPage page, bool convertToRelativeUrls = false)
public Task Update(IPage page)
{
throw new NotImplementedException();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
// Author: Joe Audette
// Created: 2016-02-15
// Last Modified: 2016-08-11
// Last Modified: 2018-10-23
//


Expand All @@ -15,21 +15,24 @@ public ProjectSecurityResult(
string projectId,
bool isAuthenticated,
bool canEditPosts,
bool canEditPages
bool canEditPages,
string timeZoneId = "GMT"
)
{
this.displayName = displayName;
this.projectId = projectId;
this.isAuthenticated = isAuthenticated;
this.canEditPosts = canEditPosts;
this.canEditPages = canEditPages;
this.timeZoneId = timeZoneId;
}

private string displayName = string.Empty;
private string projectId = string.Empty;
private bool isAuthenticated = false;
private bool canEditPosts = false;
private bool canEditPages = false;
private string timeZoneId = "GMT";

public string DisplayName
{
Expand All @@ -55,5 +58,10 @@ public bool CanEditPages
{
get { return canEditPages; }
}

public string TimeZoneId
{
get { return timeZoneId; }
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

<PropertyGroup>
<Description>cloudscribe.SimpleContent.Models Class Library</Description>
<VersionPrefix>4.0.3</VersionPrefix>
<AssemblyVersion>4.0.3</AssemblyVersion>
<VersionPrefix>4.0.4</VersionPrefix>
<AssemblyVersion>4.0.4</AssemblyVersion>
<Authors>Joe Audette</Authors>
<TargetFrameworks>netstandard1.6</TargetFrameworks>
<PackageTags>cloudscribe;blog;cms</PackageTags>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@
using cloudscribe.SimpleContent.Models;
using NoDb;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

Expand Down
7 changes: 6 additions & 1 deletion src/cloudscribe.SimpleContent.Storage.NoDb/PageCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,12 @@ public async Task Create(
)
{
var p = Page.FromIPage(page);
p.Id = _keyGenerator.GenerateKey(p);
// metaweblog sets the id, don't change it if it exists
if (string.IsNullOrWhiteSpace(p.Id))
{
p.Id = _keyGenerator.GenerateKey(p);
}

p.LastModified = DateTime.UtcNow;

await _commands.CreateAsync(projectId, p.Id, p).ConfigureAwait(false);
Expand Down
8 changes: 6 additions & 2 deletions src/cloudscribe.SimpleContent.Storage.NoDb/PostCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,12 @@ public async Task Create(
var p = Post.FromIPost(post);

p.LastModified = DateTime.UtcNow;

p.Id = _keyGenerator.GenerateKey(p);
// metaweblog sets the id, don't change it if it exists
if(string.IsNullOrWhiteSpace(p.Id))
{
p.Id = _keyGenerator.GenerateKey(p);
}


await _commands.CreateAsync(projectId, p.Id, p).ConfigureAwait(false);
_cache.ClearListCache(projectId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

<PropertyGroup>
<Description>cloudscribe.SimpleContent.Storage implemented with NoDb file system storage</Description>
<VersionPrefix>4.0.6</VersionPrefix>
<AssemblyVersion>4.0.6</AssemblyVersion>
<VersionPrefix>4.0.7</VersionPrefix>
<AssemblyVersion>4.0.7</AssemblyVersion>
<Authors>Joe Audette</Authors>
<TargetFrameworks>netstandard2.0</TargetFrameworks>
<PackageTags>cloudscribe;blog;json</PackageTags>
Expand Down
53 changes: 25 additions & 28 deletions src/cloudscribe.SimpleContent.Web/Services/Blog/BlogService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ public BlogService(
IProjectService projectService,
IPostQueries postQueries,
IPostCommands postCommands,
IMediaProcessor mediaProcessor,
IContentProcessor contentProcessor,
IBlogUrlResolver blogUrlResolver,
PostEvents eventHandlers,
Expand All @@ -32,7 +31,6 @@ ILogger<BlogService> logger
{
_postQueries = postQueries;
_postCommands = postCommands;
_mediaProcessor = mediaProcessor;
_projectService = projectService;
_contentProcessor = contentProcessor;
_blogUrlResolver = blogUrlResolver;
Expand All @@ -44,7 +42,6 @@ ILogger<BlogService> logger
private readonly IProjectService _projectService;
private readonly IPostQueries _postQueries;
private readonly IPostCommands _postCommands;
private readonly IMediaProcessor _mediaProcessor;
private IProjectSettings _settings = null;
private readonly IContentProcessor _contentProcessor;
private readonly IBlogUrlResolver _blogUrlResolver;
Expand Down Expand Up @@ -191,14 +188,14 @@ public async Task FireUnPublishEvent(IPost post)
await _eventHandlers.HandleUnPublished(post.BlogId, post);
}

public async Task Create(IPost post, bool convertToRelativeUrls = false)
public async Task Create(IPost post)
{
await EnsureBlogSettings().ConfigureAwait(false);

if(convertToRelativeUrls)
{
await _blogUrlResolver.ConvertToRelativeUrls(post, _settings).ConfigureAwait(false);
}
//if(convertToRelativeUrls)
//{
// await _blogUrlResolver.ConvertToRelativeUrls(post, _settings).ConfigureAwait(false);
//}

if (string.IsNullOrEmpty(post.Slug))
{
Expand All @@ -214,15 +211,15 @@ public async Task Create(IPost post, bool convertToRelativeUrls = false)
await _eventHandlers.HandleCreated(_settings.Id, post).ConfigureAwait(false);
}

public async Task Update(IPost post, bool convertToRelativeUrls = false)
public async Task Update(IPost post)
{
await EnsureBlogSettings().ConfigureAwait(false);
await _eventHandlers.HandlePreUpdate(_settings.Id, post.Id).ConfigureAwait(false);

if (convertToRelativeUrls)
{
await _blogUrlResolver.ConvertToRelativeUrls(post, _settings).ConfigureAwait(false);
}
//if (convertToRelativeUrls)
//{
// await _blogUrlResolver.ConvertToRelativeUrls(post, _settings).ConfigureAwait(false);
//}

await _postCommands.Update(_settings.Id, post).ConfigureAwait(false);
await _eventHandlers.HandleUpdated(_settings.Id, post).ConfigureAwait(false);
Expand Down Expand Up @@ -338,21 +335,21 @@ public async Task<bool> CommentsAreOpen(IPost post, bool userCanEdit)
return result;
}

/// <summary>
/// this is only used for processing images added via metaweblog api
/// </summary>
/// <param name="projectId"></param>
/// <param name="bytes"></param>
/// <param name="fileName"></param>
/// <returns></returns>
public async Task SaveMedia(
string projectId,
byte[] bytes, string
fileName)
{
var settings = await _projectService.GetProjectSettings(projectId).ConfigureAwait(false);
await _mediaProcessor.SaveMedia(settings.LocalMediaVirtualPath, fileName, bytes).ConfigureAwait(false);
}
///// <summary>
///// this is only used for processing images added via metaweblog api
///// </summary>
///// <param name="projectId"></param>
///// <param name="bytes"></param>
///// <param name="fileName"></param>
///// <returns></returns>
//public async Task SaveMedia(
// string projectId,
// byte[] bytes, string
// fileName)
//{
// var settings = await _projectService.GetProjectSettings(projectId).ConfigureAwait(false);
// await _mediaProcessor.SaveMedia(settings.LocalMediaVirtualPath, fileName, bytes).ConfigureAwait(false);
//}


}
Expand Down
Loading

0 comments on commit f054e91

Please sign in to comment.