From 8a6313203d3bd2bb8dceb82ba82e7911f484fe17 Mon Sep 17 00:00:00 2001 From: Sebastian Date: Sun, 19 Mar 2017 12:15:27 +0100 Subject: [PATCH] Soft delete for schemas. --- .../Contents/MongoContentRepository.cs | 2 +- .../Schemas/MongoSchemaEntity.cs | 4 + .../Schemas/MongoSchemaRepository.cs | 15 +- .../MongoSchemaRepository_EventHandling.cs | 2 +- src/Squidex.Read/Schemas/ISchemaEntity.cs | 2 + .../Schemas/Repositories/ISchemaRepository.cs | 2 - .../Schemas/Services/ISchemaProvider.cs | 2 +- .../Implementations/CachingSchemaProvider.cs | 12 +- .../Config/Domain/StoreMongoDbModule.cs | 26 +- .../event-consumers-page.component.html | 2 +- .../app/theme/icomoon/demo-files/demo.css | 8 +- src/Squidex/app/theme/icomoon/demo.html | 388 +++++++---- .../app/theme/icomoon/fonts/icomoon.eot | Bin 15936 -> 16172 bytes .../app/theme/icomoon/fonts/icomoon.svg | 1 + .../app/theme/icomoon/fonts/icomoon.ttf | Bin 15772 -> 16008 bytes .../app/theme/icomoon/fonts/icomoon.woff | Bin 15848 -> 16084 bytes src/Squidex/app/theme/icomoon/selection.json | 654 +++++++++--------- src/Squidex/app/theme/icomoon/style.css | 106 +-- src/Squidex/appsettings.json | 3 +- .../Contents/ContentCommandHandlerTests.cs | 2 +- 20 files changed, 716 insertions(+), 515 deletions(-) diff --git a/src/Squidex.Read.MongoDb/Contents/MongoContentRepository.cs b/src/Squidex.Read.MongoDb/Contents/MongoContentRepository.cs index 341fb3695..99bcb9223 100644 --- a/src/Squidex.Read.MongoDb/Contents/MongoContentRepository.cs +++ b/src/Squidex.Read.MongoDb/Contents/MongoContentRepository.cs @@ -142,7 +142,7 @@ namespace Squidex.Read.MongoDb.Contents { var collection = GetCollection(schemaId); - var schemaEntity = await schemas.FindSchemaByIdAsync(schemaId); + var schemaEntity = await schemas.FindSchemaByIdAsync(schemaId, true); if (schemaEntity == null) { diff --git a/src/Squidex.Read.MongoDb/Schemas/MongoSchemaEntity.cs b/src/Squidex.Read.MongoDb/Schemas/MongoSchemaEntity.cs index a76e2ae6e..8e34fb03c 100644 --- a/src/Squidex.Read.MongoDb/Schemas/MongoSchemaEntity.cs +++ b/src/Squidex.Read.MongoDb/Schemas/MongoSchemaEntity.cs @@ -53,6 +53,10 @@ namespace Squidex.Read.MongoDb.Schemas [BsonElement] public bool IsPublished { get; set; } + [BsonRequired] + [BsonElement] + public bool IsDeleted { get; set; } + Schema ISchemaEntityWithSchema.Schema { get { return schema.Value; } diff --git a/src/Squidex.Read.MongoDb/Schemas/MongoSchemaRepository.cs b/src/Squidex.Read.MongoDb/Schemas/MongoSchemaRepository.cs index 58db8d1dc..c3767a308 100644 --- a/src/Squidex.Read.MongoDb/Schemas/MongoSchemaRepository.cs +++ b/src/Squidex.Read.MongoDb/Schemas/MongoSchemaRepository.cs @@ -49,14 +49,14 @@ namespace Squidex.Read.MongoDb.Schemas public async Task> QueryAllAsync(Guid appId) { - var entities = await Collection.Find(s => s.AppId == appId).ToListAsync(); + var entities = await Collection.Find(s => s.AppId == appId && !s.IsDeleted).ToListAsync(); return entities.OfType().ToList(); } public async Task> QueryAllWithSchemaAsync(Guid appId) { - var entities = await Collection.Find(s => s.AppId == appId).ToListAsync(); + var entities = await Collection.Find(s => s.AppId == appId && !s.IsDeleted).ToListAsync(); entities.ForEach(x => x.DeserializeSchema(serializer)); @@ -66,7 +66,7 @@ namespace Squidex.Read.MongoDb.Schemas public async Task FindSchemaAsync(Guid appId, string name) { var entity = - await Collection.Find(s => s.Name == name && s.AppId == appId) + await Collection.Find(s => s.Name == name && s.AppId == appId && !s.IsDeleted) .FirstOrDefaultAsync(); entity?.DeserializeSchema(serializer); @@ -84,14 +84,5 @@ namespace Squidex.Read.MongoDb.Schemas return entity; } - - public async Task FindSchemaIdAsync(Guid appId, string name) - { - var entity = - await Collection.Find(s => s.Name == name & s.AppId == appId) - .Project(Projection.Include(x => x.Id)).FirstOrDefaultAsync(); - - return entity?.Id; - } } } diff --git a/src/Squidex.Read.MongoDb/Schemas/MongoSchemaRepository_EventHandling.cs b/src/Squidex.Read.MongoDb/Schemas/MongoSchemaRepository_EventHandling.cs index 11fc3cc95..f0a94b350 100644 --- a/src/Squidex.Read.MongoDb/Schemas/MongoSchemaRepository_EventHandling.cs +++ b/src/Squidex.Read.MongoDb/Schemas/MongoSchemaRepository_EventHandling.cs @@ -91,7 +91,7 @@ namespace Squidex.Read.MongoDb.Schemas protected async Task On(SchemaDeleted @event, EnvelopeHeaders headers) { - await Collection.DeleteOneAsync(x => x.Id == headers.AggregateId()); + await Collection.UpdateAsync(@event, headers, e => e.IsDeleted = true); SchemaSaved?.Invoke(@event.AppId, @event.SchemaId); } diff --git a/src/Squidex.Read/Schemas/ISchemaEntity.cs b/src/Squidex.Read/Schemas/ISchemaEntity.cs index 5d01a6f54..d8ae691da 100644 --- a/src/Squidex.Read/Schemas/ISchemaEntity.cs +++ b/src/Squidex.Read/Schemas/ISchemaEntity.cs @@ -15,5 +15,7 @@ namespace Squidex.Read.Schemas string Label { get; } bool IsPublished { get; } + + bool IsDeleted { get; } } } diff --git a/src/Squidex.Read/Schemas/Repositories/ISchemaRepository.cs b/src/Squidex.Read/Schemas/Repositories/ISchemaRepository.cs index ddb4c743e..d540c343c 100644 --- a/src/Squidex.Read/Schemas/Repositories/ISchemaRepository.cs +++ b/src/Squidex.Read/Schemas/Repositories/ISchemaRepository.cs @@ -24,7 +24,5 @@ namespace Squidex.Read.Schemas.Repositories Task FindSchemaAsync(Guid appId, string name); Task FindSchemaAsync(Guid schemaId); - - Task FindSchemaIdAsync(Guid appId, string name); } } diff --git a/src/Squidex.Read/Schemas/Services/ISchemaProvider.cs b/src/Squidex.Read/Schemas/Services/ISchemaProvider.cs index 02dfcf03b..73b8a1df8 100644 --- a/src/Squidex.Read/Schemas/Services/ISchemaProvider.cs +++ b/src/Squidex.Read/Schemas/Services/ISchemaProvider.cs @@ -14,7 +14,7 @@ namespace Squidex.Read.Schemas.Services { public interface ISchemaProvider { - Task FindSchemaByIdAsync(Guid id); + Task FindSchemaByIdAsync(Guid id, bool provideDeleted = false); Task FindSchemaByNameAsync(Guid appId, string name); diff --git a/src/Squidex.Read/Schemas/Services/Implementations/CachingSchemaProvider.cs b/src/Squidex.Read/Schemas/Services/Implementations/CachingSchemaProvider.cs index d3e857e52..1d600f32f 100644 --- a/src/Squidex.Read/Schemas/Services/Implementations/CachingSchemaProvider.cs +++ b/src/Squidex.Read/Schemas/Services/Implementations/CachingSchemaProvider.cs @@ -32,7 +32,7 @@ namespace Squidex.Read.Schemas.Services.Implementations this.repository = repository; } - public async Task FindSchemaByIdAsync(Guid id) + public async Task FindSchemaByIdAsync(Guid id, bool provideDeleted = false) { var cacheKey = BuildIdCacheKey(id); @@ -48,6 +48,11 @@ namespace Squidex.Read.Schemas.Services.Implementations } } + if (result != null && result.IsDeleted && !provideDeleted) + { + result = null; + } + return result; } @@ -69,6 +74,11 @@ namespace Squidex.Read.Schemas.Services.Implementations } } + if (result != null && result.IsDeleted) + { + result = null; + } + return result; } diff --git a/src/Squidex/Config/Domain/StoreMongoDbModule.cs b/src/Squidex/Config/Domain/StoreMongoDbModule.cs index 935416d55..5999a9215 100644 --- a/src/Squidex/Config/Domain/StoreMongoDbModule.cs +++ b/src/Squidex/Config/Domain/StoreMongoDbModule.cs @@ -32,7 +32,8 @@ namespace Squidex.Config.Domain { public class StoreMongoDbModule : Module { - private const string MongoDatabaseName = "string"; + private const string MongoDatabaseName = "MongoDatabaseName"; + private const string MongoDatabaseNameContent = "MongoDatabaseNameContent"; private IConfiguration Configuration { get; } @@ -57,13 +58,24 @@ namespace Squidex.Config.Domain throw new ConfigurationException("You must specify the MongoDB connection string in the 'squidex:stores:mongoDb:connectionString' configuration section."); } - builder.Register(c => + var databaseNameContent = Configuration.GetValue("squidex:stores:mongoDb:databaseNameContent"); + + if (string.IsNullOrWhiteSpace(databaseNameContent)) { - var mongoDbClient = new MongoClient(connectionString); - var mongoDatabase = mongoDbClient.GetDatabase(databaseName); + databaseNameContent = databaseName; + } + + builder.Register(c => new MongoClient(connectionString)) + .As() + .SingleInstance(); - return mongoDatabase; - }).Named(MongoDatabaseName).SingleInstance(); + builder.Register(c => c.Resolve().GetDatabase(databaseName)) + .Named(MongoDatabaseName) + .SingleInstance(); + + builder.Register(c => c.Resolve().GetDatabase(databaseNameContent)) + .Named(MongoDatabaseNameContent) + .SingleInstance(); builder.Register>(c => { @@ -100,7 +112,7 @@ namespace Squidex.Config.Domain .SingleInstance(); builder.RegisterType() - .WithParameter(ResolvedParameter.ForNamed(MongoDatabaseName)) + .WithParameter(ResolvedParameter.ForNamed(MongoDatabaseNameContent)) .As() .As() .AsSelf() diff --git a/src/Squidex/app/features/administration/pages/event-consumers/event-consumers-page.component.html b/src/Squidex/app/features/administration/pages/event-consumers/event-consumers-page.component.html index c321d2c11..a5ddd01f7 100644 --- a/src/Squidex/app/features/administration/pages/event-consumers/event-consumers-page.component.html +++ b/src/Squidex/app/features/administration/pages/event-consumers/event-consumers-page.component.html @@ -39,7 +39,7 @@ - + {{eventConsumer.name}} diff --git a/src/Squidex/app/theme/icomoon/demo-files/demo.css b/src/Squidex/app/theme/icomoon/demo-files/demo.css index b9fadeca3..5b17a4076 100644 --- a/src/Squidex/app/theme/icomoon/demo-files/demo.css +++ b/src/Squidex/app/theme/icomoon/demo-files/demo.css @@ -147,19 +147,19 @@ p { font-size: 16px; } .fs1 { - font-size: 20px; + font-size: 28px; } .fs2 { - font-size: 32px; + font-size: 20px; } .fs3 { font-size: 32px; } .fs4 { - font-size: 24px; + font-size: 32px; } .fs5 { - font-size: 32px; + font-size: 24px; } .fs6 { font-size: 32px; diff --git a/src/Squidex/app/theme/icomoon/demo.html b/src/Squidex/app/theme/icomoon/demo.html index b5fbe6757..74a8b71f5 100644 --- a/src/Squidex/app/theme/icomoon/demo.html +++ b/src/Squidex/app/theme/icomoon/demo.html @@ -9,103 +9,231 @@
-

Font Name: icomoon (Glyphs: 61)

+

Font Name: icomoon (Glyphs: 62)

-

Grid Size: 20

+

Grid Size: 14

- + - icon-info + icon-bug
- - + +
liga:
-
-
-

Grid Size: 16

-
+
- + - icon-google + icon-control-Markdown
- - + +
liga:
-
+
- + - icon-unlocked + icon-control-Date
- - + +
liga:
-
+
- + - icon-lock + icon-control-DateTime
- - + +
liga:
-
+
- + - icon-reset + icon-angle-right
- - + + +
+
+ liga: + +
+
+
+
+ + + + icon-user-o +
+
+ + +
+
+ liga: + +
+
+
+
+ + + + icon-caret-right +
+
+ +
liga:
+
+
+ + + + icon-caret-left +
+
+ + +
+
+ liga: + +
+
+
+
+ + + + icon-caret-up +
+
+ + +
+
+ liga: + +
+
+
+
+ + + + icon-caret-down +
+
+ + +
+
+ liga: + +
+
+
+
+ + + + icon-angle-up +
+
+ + +
+
+ liga: + +
+
+
+
+ + + + icon-angle-down +
+
+ + +
+
+ liga: + +
+
+
+
+ + + + icon-angle-left +
+
+ + +
+
+ liga: + +
+
+
+
+

Grid Size: 20

- + - icon-pause + icon-info
- - + +
liga: @@ -114,14 +242,14 @@
- + - icon-play + icon-unlocked
- - + +
liga: @@ -130,14 +258,14 @@
- + - icon-settings2 + icon-lock
- - + +
liga: @@ -146,84 +274,78 @@
- + - icon-bin2 + icon-reset
- - + +
liga:
-
-
-

Grid Size: 32

-
+
- + - icon-control-Stars + icon-pause
- - + +
liga:
-
+
- + - icon-browser + icon-play
- - + +
liga:
-
-
-

Grid Size: 24

-
+
- + - icon-control-RichText + icon-settings2
- - + +
liga:
-
+
- + - icon-control-Date + icon-bin2
- - + +
liga: @@ -232,177 +354,183 @@
-

Grid Size: 14

-
+

Grid Size: 16

+
- + - icon-control-Markdown + icon-google
- - + +
liga:
-
+
- + - icon-control-Date + icon-unlocked
- - + +
liga:
-
+
- + - icon-control-DateTime + icon-lock
- - + +
liga:
-
+
- + - icon-angle-right + icon-reset
- - + +
liga:
-
+
- + - icon-user-o + icon-pause
- - + +
liga:
-
+
- + - icon-caret-right + icon-play
- - + +
liga:
-
+
- + - icon-caret-left + icon-settings2
- - + +
liga:
-
+
- + - icon-caret-up + icon-bin2
- - + +
liga:
-
+
+
+

Grid Size: 32

+
- + - icon-caret-down + icon-control-Stars
- - + +
liga:
-
+
- + - icon-angle-up + icon-browser
- - + +
liga:
+
+
+

Grid Size: 24

- + - icon-angle-down + icon-control-RichText
- - + +
liga: @@ -411,14 +539,14 @@
- + - icon-angle-left + icon-control-Date
- - + +
liga: diff --git a/src/Squidex/app/theme/icomoon/fonts/icomoon.eot b/src/Squidex/app/theme/icomoon/fonts/icomoon.eot index 5a7fab9e1492a6a1afb7e01add81e9899e43696f..8b55c3e1071272304a2e8d7149bab0a76df23b7c 100644 GIT binary patch delta 490 zcmX?5v!;$s$DV`i-?I1<%04I3=DgKI3YPVu|PcR(vgWLWa{5azL~TE+{B6khDgRJApZc6uaK9Rn>y2r^EZ(H0I0sLAiubTff*>nV3z@s zXJBTYoXqIJXghfcqc@}N<`0ZZE$W#VgcyXFmoiUc@L=!<>Jnko24Z$`F%fn?Mr9>6 zeMSQ|WkF>@B{f5cfVv)|J)<6@DNxST#LSw}R9(%)+{{RxQ4vT2wed5G8XJj;GAf#w z0cqx?V*CxFg5_LXY`pC3e5{4Zo}PZGnXG&qY`kpTj9m4_{6Y=Z7#Q{daYAx#Vu5(rrNa|X$kg{`UF~9E zV60$Zu&BsLO-$jl+1Ag%VEF;4&MX5cz{$kw#K2&s0pzP>9RQSX$xW;%V2EIh0`ji_`3iZ7xv4X~IDZ5AUx4b{3i69f7?^=F47N2O zc?M?Y$;pfkj5d>(FnTlEZ2rKw)IymNB+tMQR{EATp5Nvx12+qpf91U;JBR_IC(p4q aXLQ_r#hQh2@*SHNHU^L$$IV%`hZq4R^Fqb| diff --git a/src/Squidex/app/theme/icomoon/fonts/icomoon.svg b/src/Squidex/app/theme/icomoon/fonts/icomoon.svg index 18baff486..bedf0c72c 100644 --- a/src/Squidex/app/theme/icomoon/fonts/icomoon.svg +++ b/src/Squidex/app/theme/icomoon/fonts/icomoon.svg @@ -68,4 +68,5 @@ + \ No newline at end of file diff --git a/src/Squidex/app/theme/icomoon/fonts/icomoon.ttf b/src/Squidex/app/theme/icomoon/fonts/icomoon.ttf index 9454802ce8349c5bfdc6a2bccf5a11d766d7679d..b643593159f8edbdf2e7a67963dfa05818831696 100644 GIT binary patch delta 507 zcmbPJ-BDZ5z{tSBz|GLWz|3IaAFOZ0FT^Gf6xjpB3CX#M1>#|sjxaDV$^iKx>50V! zKw1FE2hkkqIhAQ|CErW|@+%k^EMqcK6I1xya`G7%tgZm%%`$)joJ_3F3=GyhK)y;w zZb`+vWPT?g-vFqGBPT!EGVy@sMhgZ88z5$A%T25(V2EUl0`d<4`3iZ7xv4X~IDZ5A z4}col3i69ffDQ!$yNroD+!<{rF?uuFZuVhZYEjR`AjBZVyp(wog9n2@P_YP`HW0Im zi;1xFF)Aym=`$LzDGMqKDybPl1l08y?HTnLO@VTzCT7-*rs`@Y=4M9njEX=KsEwad z)YwQ&lu^;d3`jFC72|IZ6)flCV&i3J=VL8Q_Vn~i&1B`{VB=-uX5^|b<`-(<7XvCv z=H}*><4R_HoWv~$WF`Ye|GoV;IosPOn{g7qs9BI)IZ%R?jg7U?m5JdWgHJh-$pRE= zlJhkZ<>wb$k<10w2sLPh7(b(@Pj)uQ+n~q-f(Q%mqw)MUUm3Vr!2By;ggL*1SU|@2 m$s$(fj82<#|s4l^(?$^iKx>50V! zKw1FE2hkkqIhARBSy#J&{0asJi;9fY#1uZ8ZT$=kmLGufW*I;MP9|0-1_mn)AYUaT zx1{3L8h!&H-v_9NB_}`GGI4SBMhgZ8>j0pFmfXaO0)`02C?Nj|kgt%Jn43D&i}N>- z{{^U_tsuX+1n5v8u&tT6!=2G)5~DYx&1N6Qr54H{e*i&P>08!#ew(ih+$>=JmG_qH sAO?t@{KLwe(Q&hZH4Ecp3!4@Ju-_dSBN)WMN|`1X+6ixdY_pUR00x^vWB>pF diff --git a/src/Squidex/app/theme/icomoon/fonts/icomoon.woff b/src/Squidex/app/theme/icomoon/fonts/icomoon.woff index 1d0cf049de34c1e44150f2d4417a2fac0d4ba780..0c72a003c94c73474a01278a52f0a91d52fc6aa1 100644 GIT binary patch delta 555 zcmaD+eWg~U+~3WOfsp|S?5;3ygXxaR7j4BSYKzp%C+8*>FfcG?0EI(9SUl{~k@Uo3 zkk}p|p96{o(sL@)fMQ1&7%XEz_^srdDH*AWDGUtO3P3exAk62Mlb-<;1d2rf`6?jH z$;9fMky}y$6srO12b#yo@h+L)DJMS}sLsx&1*oVEgb!$Lw8%}Y09tIz1LP}!aU^3@ zUSe)4P)rA?5vY!_ZKfCJ?}Gf|5}@WS6aV-#+D`Ui^k%f(JcDtmMLiRP5Q7l&Qszkv z9t{3K)go-#K+G;KCc@6gsH~)>&uGA=ET}A~q-F>aP}gI$XVhaf1Z6G8b4Q)Swk&{EVJH+1bEQfkY((LxhF*(RhBFuMFHQ zAW?=ZUxYcoLmA&ECs>&?I&Gd|#lpzKyq!U4@*L|H5t(&BX;4CNVvJxA11V)-0wx6E J&CWJU83Fwfaq0j7 delta 320 zcmcao`=VN;+~3WOfsp|SY+o>NgXuYw584S&zF@~PQCp;5E;%=`fPsNA11J>&!s20< z4yPv;gT(d#`5aIzke*YS1{6EOz+h1U!hKm+yE0M}Qy3VmY=COaK$y>FTYm;n5GYmx zf7`+*7HqT&OYM~7FDFZ`T>08!# zew(ih+(7$);L3YTb{IX`#oC x.FindAppByIdAsync(AppId)).Returns(Task.FromResult(appEntity.Object)); schemaEntity.Setup(x => x.Schema).Returns(schema); - schemaProvider.Setup(x => x.FindSchemaByIdAsync(SchemaId)).Returns(Task.FromResult(schemaEntity.Object)); + schemaProvider.Setup(x => x.FindSchemaByIdAsync(SchemaId, true)).Returns(Task.FromResult(schemaEntity.Object)); } [Fact]