start new try with "core." id prefix for shared entities
This commit is contained in:
@@ -43,6 +43,10 @@ namespace zero.Core.Collections
|
||||
/// <inheritdoc />
|
||||
public async Task<string> GetSourceById(string id, bool thumb = false)
|
||||
{
|
||||
if (id.StartsWith(Constants.Database.CoreIdPrefix))
|
||||
{
|
||||
ApplyScope("shared");
|
||||
}
|
||||
IMedia media = await Session.LoadAsync<IMedia>(id);
|
||||
|
||||
if (media == null)
|
||||
|
||||
@@ -36,6 +36,7 @@
|
||||
public static class Database
|
||||
{
|
||||
public const string ReservationPrefix = "zero.";
|
||||
public const string CoreIdPrefix = "core.";
|
||||
public const string Expires = Raven.Client.Constants.Documents.Metadata.Expires;
|
||||
}
|
||||
|
||||
|
||||
@@ -38,6 +38,9 @@ namespace zero.Core.Entities
|
||||
|
||||
/// <inheritdoc />
|
||||
public MediaType Type { get; set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool IsCore { get; set; }
|
||||
}
|
||||
|
||||
|
||||
@@ -101,5 +104,10 @@ namespace zero.Core.Entities
|
||||
/// Type of the media
|
||||
/// </summary>
|
||||
MediaType Type { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Whether this media item is part of the core database (for multi-tenant setup)
|
||||
/// </summary>
|
||||
bool IsCore { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,9 @@ namespace zero.Core.Entities
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public string ParentId { get; set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool IsCore { get; set; }
|
||||
}
|
||||
|
||||
|
||||
@@ -20,5 +23,10 @@ namespace zero.Core.Entities
|
||||
/// Parent folder id
|
||||
/// </summary>
|
||||
string ParentId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Whether this media folder is part of the core database (for multi-tenant setup)
|
||||
/// </summary>
|
||||
bool IsCore { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -77,7 +77,7 @@ namespace zero.Core.Entities
|
||||
}
|
||||
|
||||
|
||||
[Collection("BackofficeUsers")]
|
||||
[Collection("Users")]
|
||||
public interface IBackofficeUser : IZeroEntity, IZeroDbConventions, IIdentityUserWithRoles
|
||||
{
|
||||
/// <summary>
|
||||
|
||||
@@ -17,7 +17,7 @@ namespace zero.Core.Entities
|
||||
}
|
||||
|
||||
|
||||
[Collection("BackofficeUserRoles")]
|
||||
[Collection("Roles")]
|
||||
public interface IBackofficeUserRole : IZeroEntity, IZeroDbConventions, IIdentityUserRole
|
||||
{
|
||||
/// <summary>
|
||||
|
||||
@@ -16,6 +16,7 @@ namespace zero.Core.Extensions
|
||||
public static class RavenDocumentStoreExtensions
|
||||
{
|
||||
const char DOT = '.';
|
||||
|
||||
/// <summary>
|
||||
/// Setup conventions for the document store
|
||||
/// </summary>
|
||||
@@ -29,10 +30,22 @@ namespace zero.Core.Extensions
|
||||
|
||||
store.Conventions.RegisterAsyncIdConvention<IZeroEntity>((_, entity) =>
|
||||
{
|
||||
string prefix = String.Empty;
|
||||
string guid = IdGenerator.Create();
|
||||
string collection = store.Conventions.GetCollectionName(entity);
|
||||
//CollectionAttribute collectionAttribute = entity.GetType().GetCustomAttribute<CollectionAttribute>(true);
|
||||
|
||||
if ((entity is IMedia && ((IMedia)entity).IsCore) || (entity is IMediaFolder && ((IMediaFolder)entity).IsCore))
|
||||
{
|
||||
prefix = Constants.Database.CoreIdPrefix;
|
||||
}
|
||||
if (entity is IBackofficeUser or IBackofficeUserRole)
|
||||
{
|
||||
guid = IdGenerator.Create(8);
|
||||
}
|
||||
|
||||
string tag = store.Conventions.TransformTypeCollectionNameToDocumentIdPrefix(collection);
|
||||
return Task.FromResult(tag + store.Conventions.IdentityPartsSeparator + IdGenerator.Create());
|
||||
return Task.FromResult(prefix + tag + store.Conventions.IdentityPartsSeparator + guid);
|
||||
});
|
||||
|
||||
store.Conventions.RegisterAsyncIdConvention<IPage>((_, entity) =>
|
||||
|
||||
Reference in New Issue
Block a user