diff --git a/zero.Core/Api/ApiScope.cs b/zero.Core/Api/ApiScope.cs deleted file mode 100644 index 659ad73d..00000000 --- a/zero.Core/Api/ApiScope.cs +++ /dev/null @@ -1,38 +0,0 @@ -using System; -using zero.Core.Extensions; - -namespace zero.Core.Api -{ - public class ApiScope - { - public string AppId { get; set; } - - public bool IncludeShared { get; set; } - - //public bool OnlyShared { get; set; } - - public bool IsShared { get; set; } - - public bool IsAppAware => !IsShared && !AppId.IsNullOrEmpty(); - - public bool IsAllowed(string appId) - { - if (!IsAppAware) - { - return true; - } - - if (appId.IsNullOrWhiteSpace()) - { - return false; - } - - if (appId.Equals(Constants.Database.SharedAppId, StringComparison.OrdinalIgnoreCase)) - { - return true; - } - - return appId.Equals(AppId, StringComparison.OrdinalIgnoreCase); - } - } -} diff --git a/zero.Core/Api/ApplicationContext.cs b/zero.Core/Api/ApplicationContext.cs index 9eea8552..2c07929a 100644 --- a/zero.Core/Api/ApplicationContext.cs +++ b/zero.Core/Api/ApplicationContext.cs @@ -88,7 +88,7 @@ namespace zero.Core.Api string[] allowedAppIds = GetAllowedAppIdsForUser(user); - bool isMainId = appId.Equals(user.AppId, StringComparison.InvariantCultureIgnoreCase); + bool isMainId = false; // appId.Equals(user.AppId, StringComparison.InvariantCultureIgnoreCase); // TODO appx fix bool isAllowedId = allowedAppIds.Contains(appId, StringComparer.InvariantCultureIgnoreCase); if (user.IsSuper || isMainId || isAllowedId) @@ -137,12 +137,12 @@ namespace zero.Core.Api } else { - appId = user.AppId; + //appId = user.AppId; // TODO appx fix } } else { - appId = user.AppId; + //appId = user.AppId; // TODO appx fix } if (appId.IsNullOrEmpty()) diff --git a/zero.Core/Api/AuthorizationApi.cs b/zero.Core/Api/AuthorizationApi.cs index 1dc8f968..60ea35ea 100644 --- a/zero.Core/Api/AuthorizationApi.cs +++ b/zero.Core/Api/AuthorizationApi.cs @@ -22,9 +22,6 @@ namespace zero.Core.Api protected ClaimsPrincipal Principal => HttpContextAccessor.HttpContext?.User; - static Type AppAwareType = typeof(IAppAwareEntity); - static Type AppAwareShareableType = typeof(IAppAwareShareableEntity); - public AuthorizationApi(IDocumentStore raven, IHttpContextAccessor httpContextAccessor, SignInManager signInManager) { @@ -93,8 +90,8 @@ namespace zero.Core.Api Type type = typeof(T); bool isSuperUser = Principal.HasClaim(Constants.Auth.Claims.IsSuper, PermissionsValue.True); - result.IsAppAware = AppAwareType.IsAssignableFrom(type); - result.IsShareable = result.IsAppAware && AppAwareShareableType.IsAssignableFrom(type); + //result.IsAppAware = AppAwareType.IsAssignableFrom(type); // TODO appx + //result.IsShareable = result.IsAppAware && AppAwareShareableType.IsAssignableFrom(type); if (isSuperUser) { diff --git a/zero.Core/Api/BackofficeApi.cs b/zero.Core/Api/BackofficeApi.cs index 72080c1a..ff006a32 100644 --- a/zero.Core/Api/BackofficeApi.cs +++ b/zero.Core/Api/BackofficeApi.cs @@ -2,8 +2,6 @@ using FluentValidation.Results; using Raven.Client; using Raven.Client.Documents; -using Raven.Client.Documents.Operations; -using Raven.Client.Documents.Queries; using Raven.Client.Documents.Session; using System; using System.Collections.Generic; @@ -12,30 +10,12 @@ using zero.Core.Attributes; using zero.Core.Entities; using zero.Core.Entities.Messages; using zero.Core.Extensions; -using zero.Core.Sync; using zero.Core.Utils; namespace zero.Core.Api { - public abstract class AppAwareBackofficeApi : BackofficeApi, IAppAwareBackofficeApi - { - protected bool AllowShared { get; set; } = false; - - public AppAwareBackofficeApi(IBackofficeStore store) : base(store) - { - Scope = new ApiScope() - { - AppId = store.AppContext.AppId, - IncludeShared = false // TODO based on user - }; - } - } - - public abstract class BackofficeApi : IBackofficeApi { - public ApiScope Scope { get; protected set; } - protected IDocumentStore Raven { get; private set; } const string NEW_ID = "new:"; @@ -47,10 +27,6 @@ namespace zero.Core.Api { Raven = store.Raven; Backoffice = store; - Scope = new ApiScope() - { - IsShared = true - }; } @@ -63,21 +39,7 @@ namespace zero.Core.Api } using IAsyncDocumentSession session = Raven.OpenAsyncSession(); - - T model = await session.LoadAsync(id); - IAppAwareEntity appAwareModel = model as IAppAwareEntity; - - if (model == null || appAwareModel == null) - { - return model; - } - - if (!Scope.IsAllowed(appAwareModel.AppId)) - { - return default; - } - - return model; + return await session.LoadAsync(id); } @@ -90,20 +52,7 @@ namespace zero.Core.Api foreach (string id in ids) { - if (!models.TryGetValue(id, out T model)) - { - result.Add(id, default); - continue; - } - - IAppAwareEntity appAwareModel = model as IAppAwareEntity; - - if (appAwareModel == null || !Scope.IsAllowed(appAwareModel.AppId)) - { - result.Add(id, default); - continue; - } - + models.TryGetValue(id, out T model); result.Add(id, model); } @@ -123,9 +72,6 @@ namespace zero.Core.Api // entity.Alias = entity.Alias?.ToLower().ToUrlSegment(); //} - // get specifics - IAppAwareEntity appAwareEntity = model as IAppAwareEntity; - // run validator if (validator != null) { @@ -137,21 +83,6 @@ namespace zero.Core.Api } } - // set app id - if (appAwareEntity != null && appAwareEntity.AppId.IsNullOrEmpty()) - { - appAwareEntity.AppId = Scope.AppId; // Constants.Database.SharedAppId; // TODO correct app id - } - - // check if current app id is valid - if (!model.Id.IsNullOrEmpty() && Scope.IsAppAware && appAwareEntity != null) - { - if (!Scope.IsAllowed(appAwareEntity.AppId)) - { - return EntityResult.Fail("@errors.onsave.notallowed"); - } - } - // find all media items in model //List> media = ObjectTraverser.Find(model); @@ -244,18 +175,12 @@ namespace zero.Core.Api session.Advanced.WaitForIndexesAfterSaveChanges(throwOnTimeout: false); T entity = await session.LoadAsync(id); - IAppAwareEntity appAwareEntity = entity as IAppAwareEntity; if (entity == null) { return EntityResult.Fail("@errors.ondelete.idnotfound"); } - if (appAwareEntity != null && Scope.IsAppAware && !Scope.IsAllowed(appAwareEntity.AppId)) - { - return EntityResult.Fail("@errors.ondelete.idnotfound"); - } - session.Delete(entity); await session.SaveChangesAsync(); @@ -322,10 +247,4 @@ namespace zero.Core.Api /// Task> Purge(string querySuffix = null, Parameters parameters = null); } - - - public interface IAppAwareBackofficeApi : IBackofficeApi - { - ApiScope Scope { get; } - } } diff --git a/zero.Core/Api/CountriesApi.cs b/zero.Core/Api/CountriesApi.cs index b2cb96b2..dcf323eb 100644 --- a/zero.Core/Api/CountriesApi.cs +++ b/zero.Core/Api/CountriesApi.cs @@ -9,7 +9,7 @@ using zero.Core.Extensions; namespace zero.Core.Api { - public class CountriesApi : AppAwareBackofficeApi, ICountriesApi + public class CountriesApi : BackofficeApi, ICountriesApi { IValidator Validator; @@ -39,7 +39,6 @@ namespace zero.Core.Api { using IAsyncDocumentSession session = Raven.OpenAsyncSession(); return await session.Query() - .Scope(Scope) .OrderByDescending(x => x.IsPreferred) .ThenBy(x => x.Name) .ToListAsync(); @@ -53,7 +52,6 @@ namespace zero.Core.Api using IAsyncDocumentSession session = Raven.OpenAsyncSession(); return await session.Query() - .Scope(Scope) .OrderByDescending(x => x.IsPreferred) .ThenBy(x => x.Name) .ToQueriedListAsync(query); diff --git a/zero.Core/Api/LanguagesApi.cs b/zero.Core/Api/LanguagesApi.cs index aff81eb6..9d202c29 100644 --- a/zero.Core/Api/LanguagesApi.cs +++ b/zero.Core/Api/LanguagesApi.cs @@ -12,7 +12,7 @@ using zero.Core.Extensions; namespace zero.Core.Api { - public class LanguagesApi : AppAwareBackofficeApi, ILanguagesApi + public class LanguagesApi : BackofficeApi, ILanguagesApi { IValidator Validator; @@ -43,7 +43,6 @@ namespace zero.Core.Api using IAsyncDocumentSession session = Raven.OpenAsyncSession(); return await session.Query() - .Scope(Scope) .OrderByDescending(x => x.CreatedDate) .ToListAsync(); } @@ -73,7 +72,7 @@ namespace zero.Core.Api using IAsyncDocumentSession session = Raven.OpenAsyncSession(); - return await session.Query().Scope(Scope).ToQueriedListAsync(query); + return await session.Query().ToQueriedListAsync(query); } diff --git a/zero.Core/Api/MailTemplatesApi.cs b/zero.Core/Api/MailTemplatesApi.cs index d0181a9b..e91d1583 100644 --- a/zero.Core/Api/MailTemplatesApi.cs +++ b/zero.Core/Api/MailTemplatesApi.cs @@ -9,7 +9,7 @@ using zero.Core.Extensions; namespace zero.Core.Api { - public class MailTemplatesApi : AppAwareBackofficeApi, IMailTemplatesApi + public class MailTemplatesApi : BackofficeApi, IMailTemplatesApi { protected IValidator Validator { get; private set; } @@ -31,7 +31,7 @@ namespace zero.Core.Api public async Task GetByKey(string key) { using IAsyncDocumentSession session = Raven.OpenAsyncSession(); - return await session.Query().Scope(Scope).FirstOrDefaultAsync(x => x.Key == key); + return await session.Query().FirstOrDefaultAsync(x => x.Key == key); } @@ -49,7 +49,7 @@ namespace zero.Core.Api { using (IAsyncDocumentSession session = Raven.OpenAsyncSession()) { - return await session.Query().Scope(Scope).ToListAsync(); + return await session.Query().ToListAsync(); } } @@ -62,7 +62,6 @@ namespace zero.Core.Api using (IAsyncDocumentSession session = Raven.OpenAsyncSession()) { return await session.Query() - .Scope(Scope) .ToQueriedListAsync(query); } } diff --git a/zero.Core/Api/MediaApi.cs b/zero.Core/Api/MediaApi.cs index 8584dc61..21a36c0d 100644 --- a/zero.Core/Api/MediaApi.cs +++ b/zero.Core/Api/MediaApi.cs @@ -17,7 +17,7 @@ using Raven.Client.Documents.Linq; namespace zero.Core.Api { - public class MediaApi : AppAwareBackofficeApi, IMediaApi + public class MediaApi : BackofficeApi, IMediaApi { protected const char PATH_SEPARATOR = '/'; @@ -52,7 +52,7 @@ namespace zero.Core.Api IMedia media = await session.LoadAsync(id); - if (media == null || (enforceAppId && media.AppId != Constants.Database.SharedAppId && media.AppId != Scope.AppId)) + if (media == null) //|| (enforceAppId && media.AppId != Constants.Database.SharedAppId && media.AppId != Scope.AppId)) // TODO appx fix { return null; } @@ -84,7 +84,6 @@ namespace zero.Core.Api using (IAsyncDocumentSession session = Raven.OpenAsyncSession()) { return await session.Query() - .Scope(Scope) .WhereIf(x => x.FolderId == query.FolderId, !query.FolderId.IsNullOrEmpty(), x => x.FolderId == null) .ToQueriedListAsync(query); } @@ -103,9 +102,7 @@ namespace zero.Core.Api using IAsyncDocumentSession session = Raven.OpenAsyncSession(); session.Advanced.MaxNumberOfRequestsPerSession = query.PageSize + 1; - IRavenQueryable dbQuery = session.Query() - .ProjectInto() - .Scope(Scope); + IRavenQueryable dbQuery = session.Query().ProjectInto(); if (query.Search.IsNullOrWhiteSpace() || !query.SearchIsGlobal) { @@ -260,7 +257,7 @@ namespace zero.Core.Api } - public interface IMediaApi : IAppAwareBackofficeApi + public interface IMediaApi : IBackofficeApi { /// /// Get media by Id diff --git a/zero.Core/Api/MediaFolderApi.cs b/zero.Core/Api/MediaFolderApi.cs index 478e021c..ef53e5db 100644 --- a/zero.Core/Api/MediaFolderApi.cs +++ b/zero.Core/Api/MediaFolderApi.cs @@ -12,7 +12,7 @@ using zero.Core.Validation; namespace zero.Core.Api { - public class MediaFolderApi : AppAwareBackofficeApi, IMediaFolderApi + public class MediaFolderApi : BackofficeApi, IMediaFolderApi { IValidator Validator; @@ -36,7 +36,6 @@ namespace zero.Core.Api using (IAsyncDocumentSession session = Raven.OpenAsyncSession()) { return await session.Query() - .Scope(Scope) .WhereIf(x => x.ParentId == parentId, !parentId.IsNullOrEmpty(), x => x.ParentId == null) .OrderByDescending(x => x.Name) .ToListAsync(); @@ -53,7 +52,6 @@ namespace zero.Core.Api using (IAsyncDocumentSession session = Raven.OpenAsyncSession()) { IList folders = await session.Query() - .Scope(Scope) .WhereIf(x => x.ParentId == parentId, !parentId.IsNullOrEmpty(), x => x.ParentId == null) .OrderByDescending(x => x.CreatedDate).ThenBy(x => x.Name) .ToListAsync(); @@ -65,7 +63,6 @@ namespace zero.Core.Api MediaFolder_ByHierarchy.Result result = await session.Query() .ProjectInto() .Include(x => x.Path.Select(p => p.Id)) - .Scope(Scope) .FirstOrDefaultAsync(x => x.Id == activeId); if (result != null) @@ -80,7 +77,6 @@ namespace zero.Core.Api IList children = await session.Query() .ProjectInto() - .Scope(Scope) .Where(x => x.Id.In(folderIds)) .ToListAsync(); @@ -135,7 +131,6 @@ namespace zero.Core.Api MediaFolder_ByHierarchy.Result result = await session.Query() .ProjectInto() .Include(x => x.Path.Select(p => p.Id)) - .Scope(Scope) .FirstOrDefaultAsync(x => x.Id == id); if (result == null) @@ -184,7 +179,7 @@ namespace zero.Core.Api } - public interface IMediaFolderApi : IAppAwareBackofficeApi + public interface IMediaFolderApi : IBackofficeApi { /// /// Get application by Id diff --git a/zero.Core/Api/PageTreeApi.cs b/zero.Core/Api/PageTreeApi.cs index 0b130e45..7d719a28 100644 --- a/zero.Core/Api/PageTreeApi.cs +++ b/zero.Core/Api/PageTreeApi.cs @@ -12,7 +12,7 @@ using zero.Core.Options; namespace zero.Core.Api { - public class PageTreeApi : AppAwareBackofficeApi, IPageTreeApi + public class PageTreeApi : BackofficeApi, IPageTreeApi { public PageTreeApi(IBackofficeStore store) : base(store) { } @@ -28,7 +28,6 @@ namespace zero.Core.Api IList pages = await session .Query() - .Scope(Scope) .WhereIf(x => x.ParentId == parentId, !parentId.IsNullOrEmpty(), x => x.ParentId == null) .OrderBy(x => x.Sort) .ToListAsync(); @@ -40,7 +39,6 @@ namespace zero.Core.Api Pages_ByHierarchy.Result result = await session.Query() .ProjectInto() .Include(x => x.Path.Select(p => p.Id)) - .Scope(Scope) .FirstOrDefaultAsync(x => x.Id == activeId); if (result != null) @@ -55,7 +53,6 @@ namespace zero.Core.Api IList children = await session.Query() .ProjectInto() - .Scope(Scope) .Where(x => x.Id.In(pageIds)) .ToListAsync(); diff --git a/zero.Core/Api/PagesApi.cs b/zero.Core/Api/PagesApi.cs index e2992b8f..fcda3cc4 100644 --- a/zero.Core/Api/PagesApi.cs +++ b/zero.Core/Api/PagesApi.cs @@ -15,7 +15,7 @@ using zero.Core.Options; namespace zero.Core.Api { - public class PagesApi : AppAwareBackofficeApi, IPagesApi + public class PagesApi : BackofficeApi, IPagesApi { const string RECYCLE_BIN_GROUP = "pages"; @@ -221,7 +221,6 @@ namespace zero.Core.Api Pages_WithChildren.Result childrenResult = await session.Query() .ProjectInto() .Include(x => x.Id) - .Scope(Scope) .Where(x => x.Id == oldParentId) .FirstOrDefaultAsync(); @@ -321,7 +320,7 @@ namespace zero.Core.Api page.IsActive = false; // validate app and parent - if (!Scope.IsAllowed(page.AppId) || (!page.ParentId.IsNullOrEmpty() && !ids.Contains(page.ParentId) && !parentIds.Contains(page.ParentId))) + if (!page.ParentId.IsNullOrEmpty() && !ids.Contains(page.ParentId) && !parentIds.Contains(page.ParentId)) { // TODO correct error message continue; @@ -369,7 +368,6 @@ namespace zero.Core.Api Pages_WithChildren.Result childrenResult = await session.Query() .ProjectInto() .Include(x => x.Id) - .Scope(Scope) .Where(x => x.Id == parentId) .FirstOrDefaultAsync(); diff --git a/zero.Core/Api/PreviewApi.cs b/zero.Core/Api/PreviewApi.cs index 8222b59c..8f33671d 100644 --- a/zero.Core/Api/PreviewApi.cs +++ b/zero.Core/Api/PreviewApi.cs @@ -6,7 +6,7 @@ using Rc = Raven.Client; namespace zero.Core.Api { - public class PreviewApi : AppAwareBackofficeApi, IPreviewApi + public class PreviewApi : BackofficeApi, IPreviewApi { IPreview Blueprint; diff --git a/zero.Core/Api/RecycleBinApi.cs b/zero.Core/Api/RecycleBinApi.cs index 0e21c311..df10c12d 100644 --- a/zero.Core/Api/RecycleBinApi.cs +++ b/zero.Core/Api/RecycleBinApi.cs @@ -9,7 +9,7 @@ using zero.Core.Utils; namespace zero.Core.Api { - public class RecycleBinApi : AppAwareBackofficeApi, IRecycleBinApi + public class RecycleBinApi : BackofficeApi, IRecycleBinApi { IRecycledEntity Blueprint; @@ -70,7 +70,6 @@ namespace zero.Core.Api using (IAsyncDocumentSession session = Raven.OpenAsyncSession()) { return await session.Query() - .Scope(Scope) .WhereIf(x => x.Group == query.Group, !query.Group.IsNullOrWhiteSpace()) .WhereIf(x => x.OperationId == query.OperationId, !query.OperationId.IsNullOrWhiteSpace()) .ToQueriedListAsync(query); @@ -84,7 +83,6 @@ namespace zero.Core.Api using (IAsyncDocumentSession session = Raven.OpenAsyncSession()) { return await session.Query() - .Scope(Scope) .Where(x => x.OperationId == operationId) .ToListAsync(); } @@ -99,7 +97,6 @@ namespace zero.Core.Api using (IAsyncDocumentSession session = Raven.OpenAsyncSession()) { return await session.Query() - .Scope(Scope) .Where(x => x.OperationId == operationId) .CountAsync(); } diff --git a/zero.Core/Api/SetupApi.cs b/zero.Core/Api/SetupApi.cs index 8708a33a..a45452d4 100644 --- a/zero.Core/Api/SetupApi.cs +++ b/zero.Core/Api/SetupApi.cs @@ -113,7 +113,7 @@ namespace zero.Core.Api await session.StoreAsync(app); // set app-id for user and store it - user.AppId = session.Advanced.GetDocumentId(app); + //user.AppId = session.Advanced.GetDocumentId(app); // TODO appx fix await session.StoreAsync(user); // save default user roles @@ -146,11 +146,10 @@ namespace zero.Core.Api await session.SaveChangesAsync(); } } - catch (Exception ex) + catch (Exception) { // TODO revert - - throw ex; + throw; } finally { @@ -209,7 +208,7 @@ namespace zero.Core.Api { CreatedDate = DateTimeOffset.Now, IsActive = true, - AppId = Constants.Database.SharedAppId, + //AppId = Constants.Database.SharedAppId, // TODO appx fix Alias = Safenames.Alias(country.Value), //LanguageId = defaultLanguage.Id, Code = country.Key.ToLowerInvariant(), @@ -233,7 +232,7 @@ namespace zero.Core.Api Name = "Administrator", Alias = Safenames.Alias("Administrator"), Sort = 0, - AppId = Constants.Database.SharedAppId, + //AppId = Constants.Database.SharedAppId, // TODO appx fix Icon = "fth-award", CreatedDate = DateTimeOffset.Now, IsActive = true, @@ -259,7 +258,6 @@ namespace zero.Core.Api Name = "Editor", Alias = Safenames.Alias("Editor"), Sort = 1, - AppId = Constants.Database.SharedAppId, Icon = "fth-feather", CreatedDate = DateTimeOffset.Now, IsActive = true, @@ -279,7 +277,6 @@ namespace zero.Core.Api Name = "Standard", Alias = Safenames.Alias("Standard"), Sort = 2, - AppId = Constants.Database.SharedAppId, Icon = "fth-users", CreatedDate = DateTimeOffset.Now, IsActive = true, diff --git a/zero.Core/Api/SpacesApi.cs b/zero.Core/Api/SpacesApi.cs index 2a85730f..d9bc3150 100644 --- a/zero.Core/Api/SpacesApi.cs +++ b/zero.Core/Api/SpacesApi.cs @@ -10,14 +10,13 @@ using zero.Core.Extensions; namespace zero.Core.Api { - public class SpacesApi : AppAwareBackofficeApi, ISpacesApi + public class SpacesApi : BackofficeApi, ISpacesApi { protected IPermissionsApi PermissionsApi { get; private set; } public SpacesApi(IBackofficeStore store, IPermissionsApi permissionsApi) : base(store) { - Scope.IncludeShared = true; PermissionsApi = permissionsApi; } @@ -52,7 +51,6 @@ namespace zero.Core.Api using (IAsyncDocumentSession session = Raven.OpenAsyncSession()) { return await session.Query() - .Scope(Scope) .Where(x => x.SpaceAlias == space.Alias) .WhereIf(x => x.Id == id, !id.IsNullOrEmpty()) .FirstOrDefaultAsync(); @@ -68,7 +66,6 @@ namespace zero.Core.Api using (IAsyncDocumentSession session = Raven.OpenAsyncSession()) { return await session.Query() - .Scope(Scope) .Where(x => x.SpaceAlias == space.Alias) .WhereIf(x => x.Id == id, !id.IsNullOrEmpty()) .FirstOrDefaultAsync(); @@ -84,7 +81,6 @@ namespace zero.Core.Api using (IAsyncDocumentSession session = Raven.OpenAsyncSession()) { return await session.Query() - .Scope(Scope) .Where(x => x.SpaceAlias == alias) .ToQueriedListAsync(query); } @@ -100,7 +96,6 @@ namespace zero.Core.Api using (IAsyncDocumentSession session = Raven.OpenAsyncSession()) { return await session.Query() - .Scope(Scope) .Where(x => x.SpaceAlias == space.Alias) .ToQueriedListAsync(query); } diff --git a/zero.Core/Api/TranslationsApi.cs b/zero.Core/Api/TranslationsApi.cs index 6db47554..736a6a4d 100644 --- a/zero.Core/Api/TranslationsApi.cs +++ b/zero.Core/Api/TranslationsApi.cs @@ -10,14 +10,13 @@ using zero.Core.Extensions; namespace zero.Core.Api { - public class TranslationsApi : AppAwareBackofficeApi, ITranslationsApi + public class TranslationsApi : BackofficeApi, ITranslationsApi { IValidator Validator; public TranslationsApi(IBackofficeStore store, IValidator validator) : base(store) { - Scope.IncludeShared = true; Validator = validator; } @@ -40,7 +39,7 @@ namespace zero.Core.Api public async Task> GetAll() { using IAsyncDocumentSession session = Raven.OpenAsyncSession(); - return await session.Query().OrderByDescending(x => x.CreatedDate).Scope(Scope).ToListAsync(); + return await session.Query().OrderByDescending(x => x.CreatedDate).ToListAsync(); } @@ -50,7 +49,7 @@ namespace zero.Core.Api query.SearchFor(entity => entity.Key, entity => entity.Value); using IAsyncDocumentSession session = Raven.OpenAsyncSession(); - return await session.Query().OrderByDescending(x => x.CreatedDate).Scope(Scope).ToQueriedListAsync(query); + return await session.Query().OrderByDescending(x => x.CreatedDate).ToQueriedListAsync(query); } diff --git a/zero.Core/Api/UserApi.cs b/zero.Core/Api/UserApi.cs index 3a079127..b76a07c3 100644 --- a/zero.Core/Api/UserApi.cs +++ b/zero.Core/Api/UserApi.cs @@ -10,7 +10,7 @@ using zero.Core.Extensions; namespace zero.Core.Api { - public class UserApi : AppAwareBackofficeApi, IUserApi + public class UserApi : BackofficeApi, IUserApi { protected UserManager UserManager { get; private set; } @@ -51,7 +51,6 @@ namespace zero.Core.Api { using IAsyncDocumentSession session = Raven.OpenAsyncSession(); return await session.Query() - .Scope(Scope) .OrderByDescending(x => x.CreatedDate) .ToListAsync(); } @@ -61,13 +60,11 @@ namespace zero.Core.Api public async Task> GetByQuery(ListQuery query) { string currentUserId = UserManager.GetUserId(Context.BackofficeUser); - HashSet appIds = new HashSet() { Constants.Database.SharedAppId, Scope.AppId }; query.SearchSelector = user => user.Name; using IAsyncDocumentSession session = Raven.OpenAsyncSession(); return await session.Query() - .Where(x => x.AppId.In(appIds) || x.Id == currentUserId) .ToQueriedListAsync(query); } @@ -160,7 +157,7 @@ namespace zero.Core.Api } - public interface IUserApi : IAppAwareBackofficeApi + public interface IUserApi : IBackofficeApi { /// /// Find user by id diff --git a/zero.Core/Api/UserRolesApi.cs b/zero.Core/Api/UserRolesApi.cs index 67cd186f..8ce7e5eb 100644 --- a/zero.Core/Api/UserRolesApi.cs +++ b/zero.Core/Api/UserRolesApi.cs @@ -15,7 +15,7 @@ using zero.Core.Validation; namespace zero.Core.Api { - public class UserRolesApi : AppAwareBackofficeApi, IUserRolesApi + public class UserRolesApi : BackofficeApi, IUserRolesApi { protected IHttpContextAccessor HttpContextAccessor { get; set; } @@ -63,7 +63,6 @@ namespace zero.Core.Api if (model.Id.IsNullOrEmpty()) { - model.AppId = Scope.AppId; model.CreatedDate = DateTimeOffset.Now; } @@ -109,7 +108,7 @@ namespace zero.Core.Api } - public interface IUserRolesApi : IAppAwareBackofficeApi + public interface IUserRolesApi : IBackofficeApi { /// /// Get all user roles diff --git a/zero.Core/Attributes/MapAppIdAttribute.cs b/zero.Core/Attributes/MapAppIdAttribute.cs deleted file mode 100644 index 8576eb7b..00000000 --- a/zero.Core/Attributes/MapAppIdAttribute.cs +++ /dev/null @@ -1,13 +0,0 @@ -using System; - -namespace zero.Core.Attributes -{ - /// - /// This attribute automatically inserts the current application id into this property (has to be a string) on entity save - /// - [AttributeUsage(AttributeTargets.Property, AllowMultiple = false)] - public class MapAppIdAttribute : Attribute - { - public MapAppIdAttribute() { } - } -} diff --git a/zero.Core/Constants.cs b/zero.Core/Constants.cs index 1194a41b..e4f422ec 100644 --- a/zero.Core/Constants.cs +++ b/zero.Core/Constants.cs @@ -28,14 +28,13 @@ public const string Email = "zero.claim.email"; public const string Permission = "zero.claim.permission"; public const string DefaultAppId = "zero.claim.defaultAppId"; - public const string AppId = "zero.claim.appId"; + public const string AppId = "zero.claim.appId"; // TODO appx fix public const string TicketExpires = "zero.claim.ticketExpires"; } } public static class Database { - public const string SharedAppId = "shared"; public const string ReservationPrefix = "zero."; public const string Expires = Raven.Client.Constants.Documents.Metadata.Expires; } diff --git a/zero.Core/Database/Indexes/MediaFolder_ByHierarchy.cs b/zero.Core/Database/Indexes/MediaFolder_ByHierarchy.cs index 5692aca3..541f9cee 100644 --- a/zero.Core/Database/Indexes/MediaFolder_ByHierarchy.cs +++ b/zero.Core/Database/Indexes/MediaFolder_ByHierarchy.cs @@ -8,12 +8,10 @@ namespace zero.Core.Database.Indexes { public class MediaFolder_ByHierarchy : AbstractIndexCreationTask { - public class Result : IZeroIdEntity, IAppAwareEntity, IZeroDbConventions + public class Result : IZeroIdEntity, IZeroDbConventions { public string Id { get; set; } - public string AppId { get; set; } - public string Name { get; set; } public List Path { get; set; } = new List(); @@ -34,7 +32,6 @@ namespace zero.Core.Database.Indexes { Id = item.Id, Name = item.Name, - AppId = item.AppId, Path = Recurse(item, x => LoadDocument(x.ParentId)) .Where(x => x != null && x.Id != null && x.Id != item.Id) .Reverse() diff --git a/zero.Core/Database/Indexes/MediaFolders_WithChildren.cs b/zero.Core/Database/Indexes/MediaFolders_WithChildren.cs index 7f396a42..401fced8 100644 --- a/zero.Core/Database/Indexes/MediaFolders_WithChildren.cs +++ b/zero.Core/Database/Indexes/MediaFolders_WithChildren.cs @@ -7,14 +7,12 @@ namespace zero.Core.Database.Indexes { public class MediaFolders_WithChildren : AbstractIndexCreationTask { - public class Result : IZeroIdEntity, IAppAwareEntity, IZeroDbConventions + public class Result : IZeroIdEntity, IZeroDbConventions { public string Id { get; set; } public string ParentId { get; set; } - public string AppId { get; set; } - public string Name { get; set; } public string[] ChildrenIds { get; set; } @@ -28,16 +26,14 @@ namespace zero.Core.Database.Indexes Id = item.Id, ParentId = item.ParentId, Name = item.Name, - AppId = item.AppId, ChildrenIds = new string[] { } }); - Reduce = results => results.GroupBy(x => new { x.ParentId, x.AppId }).Select(group => new Result() + Reduce = results => results.GroupBy(x => new { x.ParentId }).Select(group => new Result() { Id = group.Key.ParentId, ParentId = group.Key.ParentId, Name = String.Empty, - AppId = group.Key.AppId, ChildrenIds = group.Select(x => x.Id).ToArray() }); diff --git a/zero.Core/Database/Indexes/Media_ByParent.cs b/zero.Core/Database/Indexes/Media_ByParent.cs index e689ca4f..d218e8eb 100644 --- a/zero.Core/Database/Indexes/Media_ByParent.cs +++ b/zero.Core/Database/Indexes/Media_ByParent.cs @@ -12,7 +12,6 @@ namespace zero.Core.Database.Indexes AddMap(items => items.Select(item => new MediaListItem { Id = item.Id, - AppId = item.AppId, ParentId = item.ParentId, CreatedDate = item.CreatedDate, IsFolder = true, @@ -25,7 +24,6 @@ namespace zero.Core.Database.Indexes AddMap(items => items.Select(item => new MediaListItem { Id = item.Id, - AppId = item.AppId, ParentId = item.FolderId, CreatedDate = item.CreatedDate, IsFolder = false, @@ -36,7 +34,6 @@ namespace zero.Core.Database.Indexes })); StoreAllFields(FieldStorage.Yes); - Index(x => x.AppId, FieldIndexing.Exact); Index(x => x.ParentId, FieldIndexing.Exact); } } diff --git a/zero.Core/Database/Indexes/Pages_AsHistory.cs b/zero.Core/Database/Indexes/Pages_AsHistory.cs index ad21a3d5..4b33053d 100644 --- a/zero.Core/Database/Indexes/Pages_AsHistory.cs +++ b/zero.Core/Database/Indexes/Pages_AsHistory.cs @@ -8,12 +8,10 @@ namespace zero.Core.Database.Indexes { public class Pages_AsHistory : AbstractIndexCreationTask { - public class Result : IZeroIdEntity, IAppAwareEntity, IZeroDbConventions + public class Result : IZeroIdEntity, IZeroDbConventions { public string Id { get; set; } - public string AppId { get; set; } - public DateTimeOffset LastModified { get; set; } } @@ -24,7 +22,6 @@ namespace zero.Core.Database.Indexes .Select(x => new Result() { Id = x.Id, - AppId = x.AppId, LastModified = x.LastModifiedDate }); diff --git a/zero.Core/Database/Indexes/Pages_ByHierarchy.cs b/zero.Core/Database/Indexes/Pages_ByHierarchy.cs index 32c4273e..1472c0dc 100644 --- a/zero.Core/Database/Indexes/Pages_ByHierarchy.cs +++ b/zero.Core/Database/Indexes/Pages_ByHierarchy.cs @@ -8,12 +8,10 @@ namespace zero.Core.Database.Indexes { public class Pages_ByHierarchy : AbstractIndexCreationTask { - public class Result : IZeroIdEntity, IAppAwareEntity, IZeroDbConventions + public class Result : IZeroIdEntity, IZeroDbConventions { public string Id { get; set; } - public string AppId { get; set; } - public string Name { get; set; } public List Path { get; set; } = new List(); @@ -34,7 +32,6 @@ namespace zero.Core.Database.Indexes { Id = item.Id, Name = item.Name, - AppId = item.AppId, Path = Recurse(item, x => LoadDocument(x.ParentId)) .Where(x => x != null && x.Id != null && x.Id != item.Id) .Reverse() diff --git a/zero.Core/Database/Indexes/Pages_WithChildren.cs b/zero.Core/Database/Indexes/Pages_WithChildren.cs index 921bf422..24d99d0b 100644 --- a/zero.Core/Database/Indexes/Pages_WithChildren.cs +++ b/zero.Core/Database/Indexes/Pages_WithChildren.cs @@ -8,14 +8,12 @@ namespace zero.Core.Database.Indexes { public class Pages_WithChildren : AbstractIndexCreationTask { - public class Result : IZeroIdEntity, IAppAwareEntity, IZeroDbConventions + public class Result : IZeroIdEntity, IZeroDbConventions { public string Id { get; set; } public string ParentId { get; set; } - public string AppId { get; set; } - public string Name { get; set; } public string[] ChildrenIds { get; set; } @@ -29,16 +27,14 @@ namespace zero.Core.Database.Indexes Id = item.Id, ParentId = item.ParentId, Name = item.Name, - AppId = item.AppId, ChildrenIds = new string[] { } }); - Reduce = results => results.GroupBy(x => new { x.ParentId, x.AppId }).Select(group => new Result() + Reduce = results => results.GroupBy(x => new { x.ParentId }).Select(group => new Result() { Id = group.Key.ParentId, ParentId = group.Key.ParentId, Name = String.Empty, - AppId = group.Key.AppId, ChildrenIds = group.Select(x => x.Id).ToArray() }); diff --git a/zero.Core/Database/Indexes/Pages_WithUrl.cs b/zero.Core/Database/Indexes/Pages_WithUrl.cs index d9d5763a..88b7af91 100644 --- a/zero.Core/Database/Indexes/Pages_WithUrl.cs +++ b/zero.Core/Database/Indexes/Pages_WithUrl.cs @@ -11,8 +11,6 @@ namespace zero.Core.Database.Indexes { public string Id { get; set; } - public string AppId { get; set; } - public string ParentId { get; set; } public string Name { get; set; } @@ -26,14 +24,12 @@ namespace zero.Core.Database.Indexes Map = items => items.Select(item => new Result() { Id = item.Id, - AppId = item.AppId, Name = item.Name, ParentId = item.ParentId, Url = LoadDocument("routes." + item.Hash).Url }); Index(x => x.Id, FieldIndexing.Exact); - Index(x => x.AppId, FieldIndexing.Exact); Index(x => x.ParentId, FieldIndexing.Exact); StoreAllFields(FieldStorage.Yes); } diff --git a/zero.Core/Entities/Country.cs b/zero.Core/Entities/Country.cs index 0bf270dd..79e668f2 100644 --- a/zero.Core/Entities/Country.cs +++ b/zero.Core/Entities/Country.cs @@ -13,7 +13,7 @@ namespace zero.Core.Entities [Collection("Countries")] - public interface ICountry : IZeroEntity, IAppAwareShareableEntity, IZeroDbConventions + public interface ICountry : IZeroEntity, IZeroDbConventions { /// /// Preferred countries are displayed on top in lists diff --git a/zero.Core/Entities/IAppAwareEntity.cs b/zero.Core/Entities/IAppAwareEntity.cs deleted file mode 100644 index ad36cc24..00000000 --- a/zero.Core/Entities/IAppAwareEntity.cs +++ /dev/null @@ -1,16 +0,0 @@ -namespace zero.Core.Entities -{ - public interface IAppAwareEntity - { - /// - /// Id of the associated application (auto-filled) - /// - string AppId { get; set; } - } - - - public interface IAppAwareShareableEntity : IAppAwareEntity - { - - } -} diff --git a/zero.Core/Entities/Language.cs b/zero.Core/Entities/Language.cs index 336a7532..52f0b93b 100644 --- a/zero.Core/Entities/Language.cs +++ b/zero.Core/Entities/Language.cs @@ -18,7 +18,7 @@ namespace zero.Core.Entities } [Collection("Languages")] - public interface ILanguage : IZeroEntity, IAppAwareShareableEntity, IZeroDbConventions + public interface ILanguage : IZeroEntity, IZeroDbConventions { /// /// Language code (ISO 3166-1) diff --git a/zero.Core/Entities/MailTemplate.cs b/zero.Core/Entities/MailTemplate.cs index 81acb632..9eb185eb 100644 --- a/zero.Core/Entities/MailTemplate.cs +++ b/zero.Core/Entities/MailTemplate.cs @@ -32,7 +32,7 @@ namespace zero.Core.Entities [Collection("MailTemplates")] - public interface IMailTemplate : IZeroEntity, IAppAwareEntity, IZeroDbConventions + public interface IMailTemplate : IZeroEntity, IZeroDbConventions { /// /// Alias which is used to get the template in code diff --git a/zero.Core/Entities/Media/Media.cs b/zero.Core/Entities/Media/Media.cs index 0df91dab..046cebdc 100644 --- a/zero.Core/Entities/Media/Media.cs +++ b/zero.Core/Entities/Media/Media.cs @@ -45,7 +45,7 @@ namespace zero.Core.Entities /// A media file (can contain an image or other media like videos and documents) /// [Collection("Media")] - public interface IMedia : IZeroEntity, IAppAwareEntity, IZeroDbConventions + public interface IMedia : IZeroEntity, IZeroDbConventions { /// /// Id/name of the phyiscal folder which is stored on disk/cloud diff --git a/zero.Core/Entities/Media/MediaFolder.cs b/zero.Core/Entities/Media/MediaFolder.cs index 70bb5b87..34ae9bfd 100644 --- a/zero.Core/Entities/Media/MediaFolder.cs +++ b/zero.Core/Entities/Media/MediaFolder.cs @@ -14,7 +14,7 @@ namespace zero.Core.Entities /// A media folder contains media and other folders /// [Collection("MediaFolders")] - public interface IMediaFolder : IZeroEntity, IAppAwareEntity, IZeroDbConventions + public interface IMediaFolder : IZeroEntity, IZeroDbConventions { /// /// Parent folder id diff --git a/zero.Core/Entities/Media/MediaListItem.cs b/zero.Core/Entities/Media/MediaListItem.cs index 3e4eefd8..06aa544a 100644 --- a/zero.Core/Entities/Media/MediaListItem.cs +++ b/zero.Core/Entities/Media/MediaListItem.cs @@ -2,14 +2,12 @@ namespace zero.Core.Entities { - public class MediaListItem : IZeroIdEntity, IAppAwareEntity, IZeroDbConventions + public class MediaListItem : IZeroIdEntity, IZeroDbConventions { public string Id { get; set; } public string ParentId { get; set; } - public string AppId { get; set; } - public string Name { get; set; } public DateTimeOffset CreatedDate { get; set; } diff --git a/zero.Core/Entities/Pages/Page.cs b/zero.Core/Entities/Pages/Page.cs index 5279567c..325c108c 100644 --- a/zero.Core/Entities/Pages/Page.cs +++ b/zero.Core/Entities/Pages/Page.cs @@ -28,7 +28,7 @@ namespace zero.Core.Entities [Collection("Pages")] - public interface IPage : IZeroEntity, IAppAwareEntity, IZeroDbConventions + public interface IPage : IZeroEntity, IZeroDbConventions { /// /// Use this field (when filled out) instead of the alias for URL generation diff --git a/zero.Core/Entities/Preview.cs b/zero.Core/Entities/Preview.cs index d0255f72..a88a5250 100644 --- a/zero.Core/Entities/Preview.cs +++ b/zero.Core/Entities/Preview.cs @@ -13,7 +13,7 @@ namespace zero.Core.Entities [Collection("Previews")] - public interface IPreview : IZeroEntity, IAppAwareEntity, IZeroDbConventions + public interface IPreview : IZeroEntity, IZeroDbConventions { /// /// Id of the original entity diff --git a/zero.Core/Entities/RecycleBin/RecycledEntity.cs b/zero.Core/Entities/RecycleBin/RecycledEntity.cs index c026d6d4..34d8026c 100644 --- a/zero.Core/Entities/RecycleBin/RecycledEntity.cs +++ b/zero.Core/Entities/RecycleBin/RecycledEntity.cs @@ -19,7 +19,7 @@ namespace zero.Core.Entities [Collection("RecycleBin")] - public interface IRecycledEntity : IZeroEntity, IAppAwareEntity, IZeroDbConventions + public interface IRecycledEntity : IZeroEntity, IZeroDbConventions { /// /// Id of the recycled entity diff --git a/zero.Core/Entities/SelectModel.cs b/zero.Core/Entities/SelectModel.cs index bfdb3196..89610e7c 100644 --- a/zero.Core/Entities/SelectModel.cs +++ b/zero.Core/Entities/SelectModel.cs @@ -7,7 +7,5 @@ public string Name { get; set; } public bool IsActive { get; set; } - - public bool IsShared { get; set; } } } diff --git a/zero.Core/Entities/Spaces/Space.cs b/zero.Core/Entities/Spaces/Space.cs index cd189e05..d5458a1a 100644 --- a/zero.Core/Entities/Spaces/Space.cs +++ b/zero.Core/Entities/Spaces/Space.cs @@ -21,8 +21,6 @@ namespace zero.Core.Entities public string Icon { get; set; } public bool LineBelow { get; set; } - - public bool AllowShared { get; set; } } public interface ISpace @@ -44,7 +42,6 @@ namespace zero.Core.Entities Type Type { get; set; } SpaceView View { get; set; } - - bool AllowShared { get; set; } + } } \ No newline at end of file diff --git a/zero.Core/Entities/Spaces/SpaceContent.cs b/zero.Core/Entities/Spaces/SpaceContent.cs index a6838da8..65b3098e 100644 --- a/zero.Core/Entities/Spaces/SpaceContent.cs +++ b/zero.Core/Entities/Spaces/SpaceContent.cs @@ -18,7 +18,7 @@ namespace zero.Core.Entities /// The backoffice rendering is done by an IRenderer /// [Collection("SpaceContents")] - public interface ISpaceContent : IZeroEntity, IAppAwareShareableEntity, IZeroDbConventions + public interface ISpaceContent : IZeroEntity, IZeroDbConventions { /// /// Associated space diff --git a/zero.Core/Entities/Translation.cs b/zero.Core/Entities/Translation.cs index 51428c7d..f3b9763d 100644 --- a/zero.Core/Entities/Translation.cs +++ b/zero.Core/Entities/Translation.cs @@ -26,7 +26,7 @@ namespace zero.Core.Entities [Collection("Translations")] - public interface ITranslation : IZeroEntity, ILanguageAwareEntity, IAppAwareShareableEntity, IZeroDbConventions + public interface ITranslation : IZeroEntity, ILanguageAwareEntity, IZeroDbConventions { /// /// Key which can be used to query translations diff --git a/zero.Core/Entities/User/BackofficeUser.cs b/zero.Core/Entities/User/BackofficeUser.cs index 5d497a9c..dd9634a5 100644 --- a/zero.Core/Entities/User/BackofficeUser.cs +++ b/zero.Core/Entities/User/BackofficeUser.cs @@ -75,7 +75,7 @@ namespace zero.Core.Entities [Collection("BackofficeUsers")] - public interface IBackofficeUser : IZeroEntity, IAppAwareEntity, IZeroDbConventions, IIdentityUserWithRoles + public interface IBackofficeUser : IZeroEntity, IZeroDbConventions, IIdentityUserWithRoles { /// /// Currently selected app id for the backoffice diff --git a/zero.Core/Entities/User/BackofficeUserRole.cs b/zero.Core/Entities/User/BackofficeUserRole.cs index d3ae3590..b7b40cf6 100644 --- a/zero.Core/Entities/User/BackofficeUserRole.cs +++ b/zero.Core/Entities/User/BackofficeUserRole.cs @@ -18,7 +18,7 @@ namespace zero.Core.Entities [Collection("BackofficeUserRoles")] - public interface IBackofficeUserRole : IZeroEntity, IAppAwareShareableEntity, IZeroDbConventions, IIdentityUserRole + public interface IBackofficeUserRole : IZeroEntity, IZeroDbConventions, IIdentityUserRole { /// /// Additional description diff --git a/zero.Core/Entities/ZeroEntity.cs b/zero.Core/Entities/ZeroEntity.cs index dedccbd6..2fee44ab 100644 --- a/zero.Core/Entities/ZeroEntity.cs +++ b/zero.Core/Entities/ZeroEntity.cs @@ -9,9 +9,6 @@ namespace zero.Core.Entities /// public string Id { get; set; } - /// - public string AppId { get; set; } - /// public string Name { get; set; } @@ -44,7 +41,7 @@ namespace zero.Core.Entities } - public interface IZeroEntity : IZeroIdEntity, IAppAwareEntity + public interface IZeroEntity : IZeroIdEntity { /// /// Full name of the entity diff --git a/zero.Core/Extensions/IAppAwareEntityExtensions.cs b/zero.Core/Extensions/IAppAwareEntityExtensions.cs deleted file mode 100644 index 691a995e..00000000 --- a/zero.Core/Extensions/IAppAwareEntityExtensions.cs +++ /dev/null @@ -1,27 +0,0 @@ -using System; -using System.Globalization; -using System.Linq; -using zero.Core.Entities; - -namespace zero.Core.Extensions -{ - public static class IAppAwareEntityExtensions - { - public static bool InScope(this IAppAwareEntity model, string currentAppId) - { - bool includeShared = typeof(IAppAwareShareableEntity).IsAssignableFrom(model.GetType()); - - if (currentAppId.IsNullOrWhiteSpace() || model.AppId.IsNullOrWhiteSpace()) - { - return false; - } - - if (includeShared && model.AppId.Equals(Constants.Database.SharedAppId, StringComparison.InvariantCultureIgnoreCase)) - { - return true; - } - - return model.AppId.Equals(currentAppId, StringComparison.OrdinalIgnoreCase); - } - } -} diff --git a/zero.Core/Extensions/RavenAsyncDocumentQueryExtensions.cs b/zero.Core/Extensions/RavenAsyncDocumentQueryExtensions.cs deleted file mode 100644 index 8ba58bca..00000000 --- a/zero.Core/Extensions/RavenAsyncDocumentQueryExtensions.cs +++ /dev/null @@ -1,55 +0,0 @@ -using Raven.Client.Documents.Session; -using System; -using System.Collections.Generic; -using zero.Core.Api; -using zero.Core.Entities; - -namespace zero.Core.Extensions -{ - public static class RavenAsyncDocumentQueryExtensions - { - static Type _appAwareEntity = typeof(IAppAwareEntity); - - public static IAsyncDocumentQuery Scope(this IAsyncDocumentQuery source, string appId, bool includeShared = true) - { - if (appId.IsNullOrEmpty() || !_appAwareEntity.IsAssignableFrom(typeof(T))) - { - return source; - } - - HashSet ids = new HashSet(); - ids.Add(appId); - - if (includeShared) - { - ids.Add(Constants.Database.SharedAppId); - } - - return source.WhereIn(nameof(IAppAwareEntity.AppId), ids); - } - - - public static IAsyncDocumentQuery Scope(this IAsyncDocumentQuery source, ApiScope scope) - { - if (scope == null || scope.IsShared) - { - return source; - } - - if (scope.AppId.IsNullOrEmpty() || !_appAwareEntity.IsAssignableFrom(typeof(T))) - { - return source; - } - - HashSet ids = new HashSet(); - ids.Add(scope.AppId); - - if (scope.IncludeShared) - { - ids.Add(Constants.Database.SharedAppId); - } - - return source.WhereIn(nameof(IAppAwareEntity.AppId), ids); - } - } -} diff --git a/zero.Core/Extensions/RavenDocumentSessionExtensions.cs b/zero.Core/Extensions/RavenDocumentSessionExtensions.cs deleted file mode 100644 index 019b56ca..00000000 --- a/zero.Core/Extensions/RavenDocumentSessionExtensions.cs +++ /dev/null @@ -1,14 +0,0 @@ -using Raven.Client.Documents.Session; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using zero.Core.Entities; - -namespace zero.Core.Extensions -{ - public static class RavenDocumentSessionExtensions - { - - } -} diff --git a/zero.Core/Extensions/RavenQueryableExtensions.cs b/zero.Core/Extensions/RavenQueryableExtensions.cs index 3001aeb6..639f0931 100644 --- a/zero.Core/Extensions/RavenQueryableExtensions.cs +++ b/zero.Core/Extensions/RavenQueryableExtensions.cs @@ -12,63 +12,6 @@ namespace zero.Core.Extensions { public static class RavenQueryableExtensions { - static Type _appAwareEntity = typeof(IAppAwareEntity); - - public static IRavenQueryable Scope(this IRavenQueryable source, string appId, bool includeShared = true) - { - if (!_appAwareEntity.IsAssignableFrom(source.ElementType)) - { - return source; - } - - if (appId.IsNullOrEmpty()) - { - throw new ArgumentNullException("Application context did not successfully resolve yet"); - } - - //HashSet ids = new HashSet(); - //ids.Add(appId); - - //if (includeShared) - //{ - // ids.Add(Constants.Database.SharedAppId); - //} - - return source.Where(item => ((IAppAwareEntity)item).AppId == appId); - //return source.Where(item => (item as IAppAwareEntity).AppId.In(ids)); - } - - - public static IRavenQueryable Scope(this IRavenQueryable source, ApiScope scope) - { - if (scope == null || scope.IsShared) - { - return source; - } - - if (!_appAwareEntity.IsAssignableFrom(source.ElementType)) - { - return source; - } - - if (scope.AppId.IsNullOrEmpty()) - { - throw new ArgumentNullException("Application context did not successfully resolve yet"); - } - - //HashSet ids = new HashSet(); - //ids.Add(scope.AppId); - - //if (scope.IncludeShared) - //{ - // ids.Add(Constants.Database.SharedAppId); - //} - - return source.Where(item => ((IAppAwareEntity)item).AppId == scope.AppId); - //return source.Where(item => ((IAppAwareEntity)item).AppId.In(ids)); - } - - /// /// /// diff --git a/zero.Core/Extensions/ValidatorExtensions.cs b/zero.Core/Extensions/ValidatorExtensions.cs index 7b1509bd..a59f11f2 100644 --- a/zero.Core/Extensions/ValidatorExtensions.cs +++ b/zero.Core/Extensions/ValidatorExtensions.cs @@ -105,12 +105,9 @@ namespace zero.Core.Extensions { return ruleBuilder.MustAsync(async (entity, value, context, cancellation) => { - bool includeShared = typeof(IAppAwareShareableEntity).IsAssignableFrom(typeof(T)); - using IAsyncDocumentSession session = store.Raven.OpenAsyncSession(); bool any = await session.Advanced.AsyncDocumentQuery() - .Scope(entity.AppId, false) .WhereNotEquals(nameof(IZeroIdEntity.Id), entity.Id) .WhereEquals(context.Rule.PropertyName.ToPascalCaseId(), value) .AnyAsync(cancellation); @@ -127,12 +124,9 @@ namespace zero.Core.Extensions { return ruleBuilder.MustAsync(async (entity, value, context, cancellation) => { - bool includeShared = typeof(IAppAwareShareableEntity).IsAssignableFrom(typeof(T)); - using IAsyncDocumentSession session = store.Raven.OpenAsyncSession(); return await session.Advanced.AsyncDocumentQuery() - .Scope(entity.AppId, includeShared) .WhereNotEquals(nameof(IZeroIdEntity.Id), entity.Id) .WhereEquals(context.Rule.PropertyName.ToPascalCaseId(), expectedValue) .AnyAsync(cancellation); @@ -161,16 +155,8 @@ namespace zero.Core.Extensions return true; } - bool includeShared = typeof(IAppAwareShareableEntity).IsAssignableFrom(typeof(T)); - using IAsyncDocumentSession session = store.Raven.OpenAsyncSession(); TReference model = await session.LoadAsync(id); - - if (typeof(IAppAwareEntity).IsAssignableFrom(typeof(TReference))) - { - return model != null && ((IAppAwareEntity)model).InScope(entity.AppId); - } - return model != null; }).WithMessage("@errors.forms.reference_notfound"); } diff --git a/zero.Core/Identity/RavenScopedStores.cs b/zero.Core/Identity/RavenScopedStores.cs index f96dfb43..d73acaa4 100644 --- a/zero.Core/Identity/RavenScopedStores.cs +++ b/zero.Core/Identity/RavenScopedStores.cs @@ -8,7 +8,7 @@ using zero.Core.Extensions; namespace zero.Core.Identity { public class RavenScopedRoleStore : RavenRoleStore - where TRole : class, IIdentityUserRole, IAppAwareEntity + where TRole : class, IIdentityUserRole { protected IZeroContext Context { get; private set; } @@ -18,16 +18,16 @@ namespace zero.Core.Identity } /// - protected override IRavenQueryable ScopeQuery(IRavenQueryable query) => query.Scope(Context.AppId, false); + protected override IRavenQueryable ScopeQuery(IRavenQueryable query) => query; /// - protected override bool IsRolePartOfStore(TRole role) => role.AppId.Equals(Context.AppId, StringComparison.InvariantCultureIgnoreCase); + protected override bool IsRolePartOfStore(TRole role) => true; } public class RavenScopedUserStore : RavenUserStore - where TUser : class, IIdentityUser, IAppAwareEntity + where TUser : class, IIdentityUser { protected IZeroContext Context { get; private set; } @@ -37,20 +37,20 @@ namespace zero.Core.Identity } /// - protected override string GetReservationKey(TUser user) => Constants.Database.ReservationPrefix + typeof(TUser) + ':' + user.AppId + ':' + user.Email; + protected override string GetReservationKey(TUser user) => Constants.Database.ReservationPrefix + typeof(TUser) + ':' + user.Email; /// - protected override IRavenQueryable ScopeQuery(IRavenQueryable query) => query.Scope(Context.AppId, false); + protected override IRavenQueryable ScopeQuery(IRavenQueryable query) => query; /// - protected override bool IsUserPartOfStore(TUser user) => user.AppId.Equals(Context.AppId, StringComparison.InvariantCultureIgnoreCase); + protected override bool IsUserPartOfStore(TUser user) => true; } public class RavenScopedUserStore : RavenUserStore - where TUser : class, IIdentityUserWithRoles, IAppAwareEntity - where TRole : class, IIdentityUserRole, IAppAwareEntity + where TUser : class, IIdentityUserWithRoles + where TRole : class, IIdentityUserRole { protected IZeroContext Context { get; private set; } @@ -60,12 +60,12 @@ namespace zero.Core.Identity } /// - protected override string GetReservationKey(TUser user) => Constants.Database.ReservationPrefix + typeof(TUser) + ':' + user.AppId + ':' + user.Email; + protected override string GetReservationKey(TUser user) => Constants.Database.ReservationPrefix + typeof(TUser) + ':' + user.Email; /// - protected override IRavenQueryable ScopeQuery(IRavenQueryable query) => query.Scope(Context.AppId, false); + protected override IRavenQueryable ScopeQuery(IRavenQueryable query) => query; /// - protected override bool IsUserPartOfStore(TUser user) => user.AppId.Equals(Context.AppId, StringComparison.InvariantCultureIgnoreCase); + protected override bool IsUserPartOfStore(TUser user) => true; } } diff --git a/zero.Core/Identity/UserIdentity.cs b/zero.Core/Identity/UserIdentity.cs index 84dd8d2b..2442e6a0 100644 --- a/zero.Core/Identity/UserIdentity.cs +++ b/zero.Core/Identity/UserIdentity.cs @@ -107,7 +107,6 @@ namespace zero.Core.Identity Constants.Auth.Claims.Email, //Constants.Auth.Claims.Role, Constants.Auth.Claims.SecurityStamp, - Constants.Auth.Claims.AppId, Constants.Auth.Claims.IsZero }; } diff --git a/zero.Core/Routing/Page/PageRouteProvider.cs b/zero.Core/Routing/Page/PageRouteProvider.cs index 4ff42d19..fc952fee 100644 --- a/zero.Core/Routing/Page/PageRouteProvider.cs +++ b/zero.Core/Routing/Page/PageRouteProvider.cs @@ -63,7 +63,7 @@ namespace zero.Core.Routing Dictionary pages = await session.LoadAsync(ids); - if (!pages.TryGetValue(reference.Id, out IPage page) || page.AppId != route.AppId) + if (!pages.TryGetValue(reference.Id, out IPage page)) { return null; } @@ -95,13 +95,13 @@ namespace zero.Core.Routing List allRoutes = new List(); IList pages = await session.Query().ToListAsync(); - IEnumerable> groupedPages = pages.GroupBy(x => x.AppId); + //IEnumerable> groupedPages = pages. pages.GroupBy(x => x.AppId); - foreach (var group in groupedPages) - { - IList routes = TraversePageChildren(null, new List() { }, group); + //foreach (var group in groupedPages) + //{ + IList routes = TraversePageChildren(null, new List() { }, pages); allRoutes.AddRange(routes); - } + //} return allRoutes; } @@ -115,7 +115,6 @@ namespace zero.Core.Routing IRoute route = new Route() { Id = GetRouteId(page), - AppId = page.AppId, Url = UrlBuilder.GetUrl(page, parents), ProviderAlias = Alias }; diff --git a/zero.Core/Routing/Route.cs b/zero.Core/Routing/Route.cs index 5c348efa..fe61f6ba 100644 --- a/zero.Core/Routing/Route.cs +++ b/zero.Core/Routing/Route.cs @@ -1,8 +1,6 @@ -using System; -using System.Collections.Generic; +using System.Collections.Generic; using zero.Core.Attributes; using zero.Core.Entities; -using zero.Core.Utils; namespace zero.Core.Routing { @@ -12,9 +10,6 @@ namespace zero.Core.Routing /// public string Id { get; set; } - /// - public string AppId { get; set; } - /// public string Url { get; set; } @@ -52,7 +47,7 @@ namespace zero.Core.Routing [Collection("Routes")] - public interface IRoute : IZeroIdEntity, IZeroDbConventions, IAppAwareEntity + public interface IRoute : IZeroIdEntity, IZeroDbConventions { /// /// Generated URL based on the URL provider diff --git a/zero.Core/Routing/Routes.cs b/zero.Core/Routing/Routes.cs index 1dcd011d..daf1dd25 100644 --- a/zero.Core/Routing/Routes.cs +++ b/zero.Core/Routing/Routes.cs @@ -105,7 +105,7 @@ namespace zero.Core.Routing } IList routes = await session.Query() - .Where(x => x.AppId == appId) + // TODO appx fix .Where(x => (!x.AllowSuffix && x.Url == path) || (x.AllowSuffix && x.Url.In(parts))) .Include("References[].Id") .Include("Dependencies") diff --git a/zero.Core/Scoped.cs b/zero.Core/Scoped.cs deleted file mode 100644 index 2dff9a8b..00000000 --- a/zero.Core/Scoped.cs +++ /dev/null @@ -1,69 +0,0 @@ -using zero.Core.Api; - -namespace zero.Core -{ - public class Scoped where T : IAppAwareBackofficeApi - { - T Api; - IApplicationContext AppContext; - - public Scoped(T api, IApplicationContext appContext) - { - Api = api; - AppContext = appContext; - } - - - /// - /// Get Api with automatically resolved application - /// - public T Current - { - get - { - Api.Scope.AppId = AppContext.AppId; - Api.Scope.IsShared = false; - return Api; - } - } - - - /// - /// Get Api which has its scoped set to all applications (including shared) - /// - public T All - { - get - { - Api.Scope.AppId = null; - Api.Scope.IsShared = true; - return Api; - } - } - - - /// - /// Get Api with scope set to only shared entities - /// - public T Shared - { - get - { - Api.Scope.AppId = Constants.Database.SharedAppId; - Api.Scope.IsShared = false; - return Api; - } - } - - - /// - /// Get Api with scope set to the requested app id - /// - public T App(string id) - { - Api.Scope.AppId = id; - Api.Scope.IsShared = false; - return Api; - } - } -} diff --git a/zero.Core/Security/SchemedSignInManager.cs b/zero.Core/Security/SchemedSignInManager.cs index 3eb9f50b..23c58eab 100644 --- a/zero.Core/Security/SchemedSignInManager.cs +++ b/zero.Core/Security/SchemedSignInManager.cs @@ -46,7 +46,7 @@ namespace zero.Core.Security } string userAppId = principal.FindFirstValue(Constants.Auth.Claims.AppId); - return userAppId == null || userAppId == Constants.Database.SharedAppId || Zero.AppId.Equals(userAppId, StringComparison.InvariantCultureIgnoreCase); + return userAppId == null || Zero.AppId.Equals(userAppId, StringComparison.InvariantCultureIgnoreCase); } diff --git a/zero.Core/Security/ZeroBackofficeClaimsPrincipalFactory.cs b/zero.Core/Security/ZeroBackofficeClaimsPrincipalFactory.cs index ac4f5b23..3874e8c0 100644 --- a/zero.Core/Security/ZeroBackofficeClaimsPrincipalFactory.cs +++ b/zero.Core/Security/ZeroBackofficeClaimsPrincipalFactory.cs @@ -55,16 +55,16 @@ namespace zero.Core.Security .Select(x => x.NormalizedKey) .ToArray(); - string currentAppId = user.CurrentAppId ?? user.AppId; + string currentAppId = user.CurrentAppId; // ?? user.AppId; // TODO appx fix - if (!user.IsSuper && !appIds.Contains(currentAppId)) - { - currentAppId = user.AppId; - } + //if (!user.IsSuper && !appIds.Contains(currentAppId)) + //{ + // currentAppId = user.AppId; + //} claims.RemoveAll(x => x.Type == Constants.Auth.Claims.AppId); claims.Add(new Claim(Constants.Auth.Claims.AppId, currentAppId)); - claims.Add(new Claim(Constants.Auth.Claims.DefaultAppId, user.AppId)); + //claims.Add(new Claim(Constants.Auth.Claims.DefaultAppId, user.AppId)); return claims; } diff --git a/zero.Core/Security/ZeroClaimsPrinicipalFactory.cs b/zero.Core/Security/ZeroClaimsPrinicipalFactory.cs index 60bc949a..5d725d1e 100644 --- a/zero.Core/Security/ZeroClaimsPrinicipalFactory.cs +++ b/zero.Core/Security/ZeroClaimsPrinicipalFactory.cs @@ -101,7 +101,7 @@ namespace zero.Core.Security return null; } - if (appId is not null or Constants.Database.SharedAppId || Zero.AppId.Equals(appId, StringComparison.InvariantCultureIgnoreCase)) + if (appId is not null || Zero.AppId.Equals(appId, StringComparison.InvariantCultureIgnoreCase)) { return userIdentity; } @@ -137,7 +137,7 @@ namespace zero.Core.Security claims.Add(new Claim(Constants.Auth.Claims.Email, await UserManager.GetEmailAsync(user))); } - claims.Add(new Claim(Constants.Auth.Claims.AppId, user.AppId)); + //claims.Add(new Claim(Constants.Auth.Claims.AppId, user.AppId)); // TODO appx fix return claims; } diff --git a/zero.Core/Sync/SyncPseudo.cs b/zero.Core/Sync/SyncPseudo.cs index 9ac5105e..2155b5c7 100644 --- a/zero.Core/Sync/SyncPseudo.cs +++ b/zero.Core/Sync/SyncPseudo.cs @@ -9,75 +9,75 @@ using zero.Core.Extensions; namespace zero.Core.Sync { - public class SyncPseudo - { - public SyncPseudo() - { + //public class SyncPseudo + //{ + // public SyncPseudo() + // { - } + // } - public async Task OnCreate(IAsyncDocumentSession session, T model) where T : IZeroEntity - { - await OnSave(session, model, true); - } + // public async Task OnCreate(IAsyncDocumentSession session, T model) where T : IZeroEntity + // { + // await OnSave(session, model, true); + // } - public async Task OnUpdate(IAsyncDocumentSession session, T model) where T : IZeroEntity - { - await OnSave(session, model, false); - } + // public async Task OnUpdate(IAsyncDocumentSession session, T model) where T : IZeroEntity + // { + // await OnSave(session, model, false); + // } - async Task OnSave(IAsyncDocumentSession session, T model, bool isCreate = false) where T : IZeroEntity - { - string sharedId = Constants.Database.SharedAppId; + // async Task OnSave(IAsyncDocumentSession session, T model, bool isCreate = false) where T : IZeroEntity + // { + // string sharedId = Constants.Database.SharedAppId; - if (model.AppId != sharedId) - { - return; - } + // if (model.AppId != sharedId) + // { + // return; + // } - IList inheritedModels = new List(); - IList apps = await session.Query().Where(x => x.Id != sharedId).ToListAsync(); + // IList inheritedModels = new List(); + // IList apps = await session.Query().Where(x => x.Id != sharedId).ToListAsync(); - if (!isCreate) - { - string id = model.Id; - inheritedModels = await session.Query().Where(x => x.Blueprint != null && x.Blueprint.Id == id).ToListAsync(); - } + // if (!isCreate) + // { + // string id = model.Id; + // inheritedModels = await session.Query().Where(x => x.Blueprint != null && x.Blueprint.Id == id).ToListAsync(); + // } - foreach (IApplication app in apps) - { - T inheritedModel = inheritedModels.FirstOrDefault(x => x.AppId == app.Id); + // foreach (IApplication app in apps) + // { + // T inheritedModel = inheritedModels.FirstOrDefault(x => x.AppId == app.Id); - // the model does not yet exist in the app, so we need to create it - if (inheritedModel == null) - { - inheritedModel = model.Clone(); - inheritedModel.Id = null; - } - // we need to override allowed properties in the inherited model - else - { - // TODO correctly override properties - if (inheritedModel is ITranslation) - { - ((ITranslation)inheritedModel).Key = ((ITranslation)model).Key; - ((ITranslation)inheritedModel).Value = ((ITranslation)model).Value; - ((ITranslation)inheritedModel).LastModifiedById = ((ITranslation)model).LastModifiedById; - ((ITranslation)inheritedModel).LastModifiedDate = ((ITranslation)model).LastModifiedDate; - } - } + // // the model does not yet exist in the app, so we need to create it + // if (inheritedModel == null) + // { + // inheritedModel = model.Clone(); + // inheritedModel.Id = null; + // } + // // we need to override allowed properties in the inherited model + // else + // { + // // TODO correctly override properties + // if (inheritedModel is ITranslation) + // { + // ((ITranslation)inheritedModel).Key = ((ITranslation)model).Key; + // ((ITranslation)inheritedModel).Value = ((ITranslation)model).Value; + // ((ITranslation)inheritedModel).LastModifiedById = ((ITranslation)model).LastModifiedById; + // ((ITranslation)inheritedModel).LastModifiedDate = ((ITranslation)model).LastModifiedDate; + // } + // } - inheritedModel.AppId = app.Id; - inheritedModel.Blueprint = new BlueprintConfiguration() - { - Id = model.Id - }; + // inheritedModel.AppId = app.Id; + // inheritedModel.Blueprint = new BlueprintConfiguration() + // { + // Id = model.Id + // }; - await session.StoreAsync(inheritedModel); - } - } - } + // await session.StoreAsync(inheritedModel); + // } + // } + //} } diff --git a/zero.Core/zero.Core.csproj b/zero.Core/zero.Core.csproj index e607bc64..5e0d4f65 100644 --- a/zero.Core/zero.Core.csproj +++ b/zero.Core/zero.Core.csproj @@ -1,14 +1,11 @@  - - preview - net5.0 - - zero.Core 0.1.0 - // TODO + preview + net5.0 + true diff --git a/zero.Debug/Controllers/HomeController.cs b/zero.Debug/Controllers/HomeController.cs index 307e27a6..7693fd68 100644 --- a/zero.Debug/Controllers/HomeController.cs +++ b/zero.Debug/Controllers/HomeController.cs @@ -1,11 +1,5 @@ using Microsoft.AspNetCore.Mvc; -using Raven.Client.Documents; -using Raven.Client.Documents.Linq; -using Raven.Client.Documents.Session; -using System; using System.Threading.Tasks; -using zero.Core.Entities; -using zero.TestData; namespace zero.Debug.Controllers { @@ -26,99 +20,5 @@ namespace zero.Debug.Controllers result = "okay" }); } - - [HttpGet] - public async Task SavePages([FromServices] IDocumentStore raven) - { - using (IAsyncDocumentSession session = raven.OpenAsyncSession()) - { - Application app = await session.Query().Where(x => x.IsActive).FirstOrDefaultAsync(); - - await session.StoreAsync(new ContentPage() - { - CreatedDate = DateTimeOffset.Now, - Name = "Home", - Alias = "home", - IsActive = true, - PageTypeAlias = "root", - Text = "This is a text", - AppId = app.Id, - Meta = new MetaPagePartial() - { - TitleOverrideAll = "brothers Klika OG" - }, - Options = new OptionsPagePartial() - { - HideInNavigation = true - } - }); - - await session.StoreAsync(new ContentPage() - { - CreatedDate = DateTimeOffset.Now, - Name = "Products", - Alias = "products", - IsActive = true, - PageTypeAlias = "content", - Text = "Our products page", - AppId = app.Id - }); - - ContentPage newsPage = new ContentPage() - { - CreatedDate = DateTimeOffset.Now, - Name = "News", - Alias = "news", - IsActive = true, - PageTypeAlias = "content", - Text = "1 out of 100 news are good", - AppId = app.Id - }; - - await session.StoreAsync(newsPage); - - await session.StoreAsync(new NewsPage() - { - CreatedDate = DateTimeOffset.Now, - Name = "Our new website is online", - Alias = "xxxx", - IsActive = true, - PageTypeAlias = "news", - Text = "What the fuckk", - PublishDate = DateTimeOffset.Now.AddDays(3), - AppId = app.Id, - ParentId = newsPage.Id - }); - - await session.StoreAsync(new NewsPage() - { - CreatedDate = DateTimeOffset.Now, - Name = "This is a test news", - Alias = "xxx", - IsActive = false, - PageTypeAlias = "news", - Text = "What the fuckkii", - PublishDate = DateTimeOffset.Now.AddDays(-20), - AppId = app.Id, - ParentId = newsPage.Id - }); - - await session.StoreAsync(new RedirectPage() - { - CreatedDate = DateTimeOffset.Now, - Name = "Visit our website", - Alias = "xxx", - IsActive = true, - PageTypeAlias = "redirect", - AppId = app.Id, - ParentId = newsPage.Id, - Link = "https://brothers.studio" - }); - - await session.SaveChangesAsync(); - } - - return Ok(); - } } } \ No newline at end of file diff --git a/zero.Debug/Controllers/MigrationController.cs b/zero.Debug/Controllers/MigrationController.cs index 80be07f4..0cab9c28 100644 --- a/zero.Debug/Controllers/MigrationController.cs +++ b/zero.Debug/Controllers/MigrationController.cs @@ -23,128 +23,5 @@ namespace zero.Debug.Controllers { Raven = raven; } - - - [HttpGet] - public async Task SharedEntities() - { - async Task Handle() where T : IZeroIdEntity - { - return await SaveAll(); - } - - return Json(new - { - Applications = await Handle(), - Categories = await Handle(), - Channels = await Handle(), - Countries = await Handle(), - Currencies = await Handle(), - Customers = await Handle(), - Languages = await Handle(), - MailTemplates = await Handle(), - Manufacturers = await Handle(), - Media = await Handle(), - MediaFolders = await Handle(), - NumberTemplates = await Handle(), - OrderDetailStates = await Handle(), - Orders = await Handle(), - Pages = await Handle(), - ProductProperties = await Handle(), - Products = await Handle(), - RecycleBin = await Handle(), - ShippingOptions = await Handle(), - SpaceContents = await Handle(), - TaxRates = await Handle(), - Translations = await Handle(), - UserRoles = await Handle(), - Users = await Handle(), - }); - } - - - async Task> SaveAll() where T : IZeroIdEntity - { - HashSet changedIds = new HashSet(); - IList items; - - using (IAsyncDocumentSession session = Raven.OpenAsyncSession()) - { - items = await session.Query().ToListAsync(); - - foreach (T item in items) - { - if (Update(item, session.Advanced.GetLastModifiedFor(item))) - { - changedIds.Add(item.Id); - } - } - - await session.SaveChangesAsync(); - } - - return changedIds; - } - - - bool Update(T model, DateTime? modifiedDate) where T : IZeroIdEntity - { - IAppAwareEntity appAwareEntity = model as IAppAwareEntity; - IZeroEntity zeroEntity = model as IZeroEntity; - - bool hasChange = false; - - // set app id - if (appAwareEntity != null && appAwareEntity.AppId.IsNullOrEmpty()) - { - hasChange = true; - appAwareEntity.AppId = "shared"; - } - - // set unset Raven Ids - foreach (ObjectTraverser.Result item in ObjectTraverser.FindAttribute(model)) - { - string id = item.Property.GetValue(item.Parent, null) as string; - if (String.IsNullOrWhiteSpace(id)) - { - hasChange = true; - item.Property.SetValue(item.Parent, item.Item.Length.HasValue ? IdGenerator.Create(item.Item.Length.Value) : IdGenerator.Create()); - } - } - - string userId = HttpContext.User.Claims.FirstOrDefault(x => x.Type == Constants.Auth.Claims.UserId)?.Value; - - if (zeroEntity != null) - { - if (zeroEntity.CreatedById == null) - { - hasChange = true; - zeroEntity.CreatedDate = zeroEntity.CreatedDate == default ? DateTimeOffset.Now : zeroEntity.CreatedDate; - zeroEntity.CreatedById = userId; - } - if (model is ITranslation && zeroEntity.Name.IsNullOrEmpty()) - { - hasChange = true; - zeroEntity.Name = ((ITranslation)model).Key; - } - if (zeroEntity.Alias.IsNullOrEmpty()) - { - hasChange = true; - zeroEntity.Alias = Safenames.Alias(zeroEntity.Name); - } - if (zeroEntity.LastModifiedById == default) - { - hasChange = true; - zeroEntity.LastModifiedById = userId; - } - if (zeroEntity.LastModifiedDate == default) - { - hasChange = true; - zeroEntity.LastModifiedDate = modifiedDate.HasValue ? new DateTimeOffset(modifiedDate.Value) : zeroEntity.CreatedDate; - } - } - - return hasChange; - } } } \ No newline at end of file diff --git a/zero.Debug/Sync/BlueprintHandler.cs b/zero.Debug/Sync/BlueprintHandler.cs index e9051256..504ab556 100644 --- a/zero.Debug/Sync/BlueprintHandler.cs +++ b/zero.Debug/Sync/BlueprintHandler.cs @@ -17,7 +17,7 @@ namespace zero.Debug.Sync { public virtual async Task Handle(EntitySavedMessage message) { - await CreateBlueprints(message.Session, message.Model, message.IsCreate); + //await CreateBlueprints(message.Session, message.Model, message.IsCreate); } @@ -33,58 +33,58 @@ namespace zero.Debug.Sync } - protected virtual async Task CreateBlueprints(IAsyncDocumentSession session, T model, bool isCreate = false) - { - string sharedId = Constants.Database.SharedAppId; + //protected virtual async Task CreateBlueprints(IAsyncDocumentSession session, T model, bool isCreate = false) + //{ + // string sharedId = null; // Constants.Database.SharedAppId; - if (model.AppId != sharedId) - { - return; - } + // if (model.AppId != sharedId) + // { + // return; + // } - IList inheritedModels = new List(); - IList apps = await session.Query().Where(x => x.Id != sharedId).ToListAsync(); + // IList inheritedModels = new List(); + // IList apps = await session.Query().Where(x => x.Id != sharedId).ToListAsync(); - if (!isCreate) - { - string id = model.Id; - inheritedModels = await session.Query().Where(x => x.Blueprint != null && x.Blueprint.Id == id).ToListAsync(); - } + // if (!isCreate) + // { + // string id = model.Id; + // inheritedModels = await session.Query().Where(x => x.Blueprint != null && x.Blueprint.Id == id).ToListAsync(); + // } - foreach (IApplication app in apps) - { - bool exists = true; - T inheritedModel = inheritedModels.FirstOrDefault(x => x.AppId == app.Id); + // foreach (IApplication app in apps) + // { + // bool exists = true; + // T inheritedModel = inheritedModels.FirstOrDefault(x => x.AppId == app.Id); - // the model does not yet exist in the app, so we need to create it - if (inheritedModel == null) - { - exists = false; - inheritedModel = model.Clone(); - inheritedModel.Id = null; - } + // // the model does not yet exist in the app, so we need to create it + // if (inheritedModel == null) + // { + // exists = false; + // inheritedModel = model.Clone(); + // inheritedModel.Id = null; + // } - inheritedModel.AppId = app.Id; - inheritedModel.LastModifiedById = model.LastModifiedById; - inheritedModel.LastModifiedDate = model.LastModifiedDate; - inheritedModel.Blueprint = new BlueprintConfiguration() - { - Id = model.Id - }; + // inheritedModel.AppId = app.Id; + // inheritedModel.LastModifiedById = model.LastModifiedById; + // inheritedModel.LastModifiedDate = model.LastModifiedDate; + // inheritedModel.Blueprint = new BlueprintConfiguration() + // { + // Id = model.Id + // }; - // we need to override allowed properties in the inherited model - if (exists) - { - inheritedModel.Name = model.Name; - inheritedModel.Alias = Safenames.Alias(model.Name); - inheritedModel.IsActive = model.IsActive; - inheritedModel.Sort = model.Sort; - await OnBlueprintCreateAsync(model, inheritedModel); - OnBlueprintCreate(model, inheritedModel); - } + // // we need to override allowed properties in the inherited model + // if (exists) + // { + // inheritedModel.Name = model.Name; + // inheritedModel.Alias = Safenames.Alias(model.Name); + // inheritedModel.IsActive = model.IsActive; + // inheritedModel.Sort = model.Sort; + // await OnBlueprintCreateAsync(model, inheritedModel); + // OnBlueprintCreate(model, inheritedModel); + // } - await session.StoreAsync(inheritedModel); - } - } + // await session.StoreAsync(inheritedModel); + // } + //} } } diff --git a/zero.Debug/TestData/Documents/InvoiceDocument.cs b/zero.Debug/TestData/Documents/InvoiceDocument.cs index 5c946e54..2b76e350 100644 --- a/zero.Debug/TestData/Documents/InvoiceDocument.cs +++ b/zero.Debug/TestData/Documents/InvoiceDocument.cs @@ -1,6 +1,7 @@ using Raven.Client.Documents.Session; using System.Threading.Tasks; using zero.Commerce.Entities; +using zero.Core.Entities; using zero.Core.Validation; namespace zero.TestData diff --git a/zero.Debug/TestData/Documents/PrintDocument.cs b/zero.Debug/TestData/Documents/PrintDocument.cs index 8f2dc53c..2882d8ed 100644 --- a/zero.Debug/TestData/Documents/PrintDocument.cs +++ b/zero.Debug/TestData/Documents/PrintDocument.cs @@ -1,6 +1,7 @@ using Raven.Client.Documents.Session; using System.Threading.Tasks; using zero.Commerce.Entities; +using zero.Core.Entities; namespace zero.TestData { diff --git a/zero.Debug/TestData/Spaces/TeamMember.cs b/zero.Debug/TestData/Spaces/TeamMember.cs index 417cde8b..2cf5fbde 100644 --- a/zero.Debug/TestData/Spaces/TeamMember.cs +++ b/zero.Debug/TestData/Spaces/TeamMember.cs @@ -16,7 +16,6 @@ namespace zero.TestData Description = "Our team members"; Icon = "fth-users"; Type = typeof(TeamMember); - AllowShared = true; } } diff --git a/zero.Web/Controllers/BackofficeController.cs b/zero.Web/Controllers/BackofficeController.cs index bccbe568..c837e19f 100644 --- a/zero.Web/Controllers/BackofficeController.cs +++ b/zero.Web/Controllers/BackofficeController.cs @@ -26,9 +26,6 @@ namespace zero.Web.Controllers protected IZeroOptions Options => _options ?? (_options = HttpContext?.RequestServices?.GetService()); protected IToken Token => _token ?? (_token = HttpContext?.RequestServices?.GetService()); - static Type AppAwareType = typeof(IAppAwareEntity); - static Type AppAwareShareableType = typeof(IAppAwareShareableEntity); - /// /// Creates an edit model with appropriate options and permissions @@ -36,7 +33,6 @@ namespace zero.Web.Controllers public EditModel Edit(T data, bool typed = true, Action> transform = null) where T : IZeroIdEntity { Type type = typeof(T); - bool canBeShared = AppAwareShareableType.IsAssignableFrom(type); //ControllerContext.ActionDescriptor.FilterDescriptors[0]. @@ -48,10 +44,10 @@ namespace zero.Web.Controllers EditModel model = new EditModel(); model.Entity = data; model.Meta.Token = Token.Get(data); - model.Meta.IsAppAware = AppAwareType.IsAssignableFrom(type); - model.Meta.CanBeShared = canBeShared; + //model.Meta.IsAppAware = AppAwareType.IsAssignableFrom(type); // TODO appx + //model.Meta.CanBeShared = canBeShared; model.Meta.CanCreate = true; - model.Meta.CanCreateShared = canBeShared; + //model.Meta.CanCreateShared = canBeShared; model.Meta.CanEdit = true; model.Meta.CanDelete = true; @@ -69,15 +65,14 @@ namespace zero.Web.Controllers where TWrapper : EditModel, new() { Type type = typeof(T); - bool canBeShared = AppAwareShareableType.IsAssignableFrom(type); //ControllerContext.ActionDescriptor.FilterDescriptors[0]. data.Meta.Token = Token.Get(data.Entity); - data.Meta.IsAppAware = AppAwareType.IsAssignableFrom(type); - data.Meta.CanBeShared = canBeShared; + //data.Meta.IsAppAware = AppAwareType.IsAssignableFrom(type); // TODO appx + //data.Meta.CanBeShared = canBeShared; data.Meta.CanCreate = true; - data.Meta.CanCreateShared = canBeShared; + //data.Meta.CanCreateShared = canBeShared; data.Meta.CanEdit = true; data.Meta.CanDelete = true; diff --git a/zero.Web/Controllers/MailTemplatesController.cs b/zero.Web/Controllers/MailTemplatesController.cs index a640636a..e601c916 100644 --- a/zero.Web/Controllers/MailTemplatesController.cs +++ b/zero.Web/Controllers/MailTemplatesController.cs @@ -30,8 +30,7 @@ namespace zero.Commerce.Backoffice { Id = x.Id, Name = x.Name, - IsActive = x.IsActive, - IsShared = x.AppId == Constants.Database.SharedAppId + IsActive = x.IsActive }); diff --git a/zero.Web/ZeroBuilder.cs b/zero.Web/ZeroBuilder.cs index a5426f0f..0fc508b8 100644 --- a/zero.Web/ZeroBuilder.cs +++ b/zero.Web/ZeroBuilder.cs @@ -107,7 +107,6 @@ namespace zero.Web Services.AddScoped(); Services.AddScoped(); - Services.AddTransient(typeof(Scoped<>)); Services.AddScoped(); diff --git a/zero.Web/ZeroVue.cs b/zero.Web/ZeroVue.cs index acc13e46..3a17fe96 100644 --- a/zero.Web/ZeroVue.cs +++ b/zero.Web/ZeroVue.cs @@ -62,7 +62,7 @@ namespace zero.Web config.Alias = CreateAliases(); config.SettingsAreas = CreateSettingsAreas(); config.AppId = AppContext.AppId; - config.SharedAppId = Constants.Database.SharedAppId; + //config.SharedAppId = Constants.Database.SharedAppId; // TODO appx BackofficeUser user = await AuthenticationApi.GetUser(); diff --git a/zero.Web/zero.Web.csproj b/zero.Web/zero.Web.csproj index 781b2f94..7de1a05b 100644 --- a/zero.Web/zero.Web.csproj +++ b/zero.Web/zero.Web.csproj @@ -1,15 +1,11 @@  - - - preview - net5.0 - true - - zero.Web 0.1.0 - // TODO 2 + preview + net5.0 + true + true