@social-mail/social-mail-web-server 1.7.142 → 1.7.145

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (27) hide show
  1. package/dist/server/model/entities/WebSite.d.ts +1 -0
  2. package/dist/server/model/entities/WebSite.d.ts.map +1 -1
  3. package/dist/server/model/entities/WebSite.js +5 -1
  4. package/dist/server/model/entities/WebSite.js.map +1 -1
  5. package/dist/server/model/events/WebSiteEvents.d.ts +5 -0
  6. package/dist/server/model/events/WebSiteEvents.d.ts.map +1 -1
  7. package/dist/server/model/events/WebSiteEvents.js +25 -0
  8. package/dist/server/model/events/WebSiteEvents.js.map +1 -1
  9. package/dist/server/seed/ui/seed-ui.js +1 -1
  10. package/dist/server/workflows/SocialWorkflowContext.d.ts.map +1 -1
  11. package/dist/server/workflows/SocialWorkflowContext.js +2 -0
  12. package/dist/server/workflows/SocialWorkflowContext.js.map +1 -1
  13. package/dist/server/workflows/site/CopyTemplateWorkflow.d.ts +11 -0
  14. package/dist/server/workflows/site/CopyTemplateWorkflow.d.ts.map +1 -0
  15. package/dist/server/workflows/site/CopyTemplateWorkflow.js +142 -0
  16. package/dist/server/workflows/site/CopyTemplateWorkflow.js.map +1 -0
  17. package/dist/server/workflows/site/CreateSocialSiteWorkflow.d.ts.map +1 -1
  18. package/dist/server/workflows/site/CreateSocialSiteWorkflow.js +2 -1
  19. package/dist/server/workflows/site/CreateSocialSiteWorkflow.js.map +1 -1
  20. package/dist/tsconfig.tsbuildinfo +1 -1
  21. package/package.json +1 -1
  22. package/src/server/model/entities/WebSite.ts +3 -0
  23. package/src/server/model/events/WebSiteEvents.ts +32 -0
  24. package/src/server/seed/ui/seed-ui.ts +1 -1
  25. package/src/server/workflows/SocialWorkflowContext.ts +2 -0
  26. package/src/server/workflows/site/CopyTemplateWorkflow.ts +85 -0
  27. package/src/server/workflows/site/CreateSocialSiteWorkflow.ts +2 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@social-mail/social-mail-web-server",
3
- "version": "1.7.142",
3
+ "version": "1.7.145",
4
4
  "description": "## Phase 1",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -53,6 +53,9 @@ export default class WebSite {
53
53
  @ReadOnlyJsonProperty
54
54
  public storeEnabled: boolean;
55
55
 
56
+ @JsonProperty({})
57
+ public templateID: number;
58
+
56
59
  /**
57
60
  * Will be set true when any file below listed folder id is modified
58
61
  */
@@ -13,6 +13,10 @@ import TempFileService from "../../storage/TempFileService.js";
13
13
  import { JSDOM } from 'jsdom';
14
14
  import { join } from "path";
15
15
  import Page from "@entity-access/server-pages/dist/Page.js";
16
+ import ChangeEntry from "@entity-access/entity-access/dist/model/changes/ChangeEntry.js";
17
+ import EntityAccessError from "@entity-access/entity-access/dist/common/EntityAccessError.js";
18
+ import WorkflowContext from "@entity-access/entity-access/dist/workflows/WorkflowContext.js";
19
+ import CopyTemplateWorkflow from "../../workflows/site/CopyTemplateWorkflow.js";
16
20
 
17
21
  export default class WebSiteEvents extends AuthenticatedEvents<WebSite> {
18
22
 
@@ -28,6 +32,9 @@ export default class WebSiteEvents extends AuthenticatedEvents<WebSite> {
28
32
  @Inject
29
33
  tfs: TempFileService;
30
34
 
35
+ @Inject
36
+ context: WorkflowContext;
37
+
31
38
  @ExternalQuery
32
39
  templates() {
33
40
  const db = ServiceProvider.resolve(this, SocialMailContext);
@@ -57,4 +64,29 @@ export default class WebSiteEvents extends AuthenticatedEvents<WebSite> {
57
64
  return query.where({ writeFileAccess }, (p) => (x) => Sql.text.likeAny(x.folder.path, p.writeFileAccess ));
58
65
  }
59
66
 
67
+ async afterInsert(entity: WebSite, entry: ChangeEntry<WebSite>) {
68
+ // copy template
69
+ if (entity.templateID) {
70
+ await this.copyTemplate(entity);
71
+ }
72
+ }
73
+
74
+ async copyTemplate(entity: WebSite) {
75
+
76
+ const { db } = this;
77
+
78
+ const template = await db.websiteFolders.where(entity, (p) => (x) => x.folderID === p.templateID && x.isTemplate === true)
79
+ .first();
80
+
81
+ if (!template) {
82
+ throw new EntityAccessError(`Invalid template ID`);
83
+ }
84
+
85
+ await this.context.queue(CopyTemplateWorkflow, {
86
+ folderID: entity.folderID,
87
+ templateID: entity.templateID
88
+ });
89
+
90
+ }
91
+
60
92
  }
@@ -3,7 +3,7 @@ import semver from "semver";
3
3
 
4
4
  export default async function seedUI(config: DBConfig) {
5
5
 
6
- const version = "1.4.124";
6
+ const version = "1.4.126";
7
7
 
8
8
  const existing = await config.getValue(UIPackageConfig, false);
9
9
  if (existing) {
@@ -42,6 +42,7 @@ import PendingPostReceiveWorkflow from "./pending/PendingPostReceiveWorkflow.js"
42
42
  import PendingReferencesWorkflow from "./pending/PendingReferencesWorkflow.js";
43
43
  import UpdatePendingModerationCountWorkflow from "./channel/moderation/UpdatePendingModerationCountWorkflow.js";
44
44
  import CreateSocialSiteWorkflow from "./site/CreateSocialSiteWorkflow.js";
45
+ import CopyTemplateWorkflow from "./site/CopyTemplateWorkflow.js";
45
46
 
46
47
  @RegisterSingleton
47
48
  export default class SocialWorkflowContext extends WorkflowContext {
@@ -91,6 +92,7 @@ export default class SocialWorkflowContext extends WorkflowContext {
91
92
  this.register(UpdatePendingModerationCountWorkflow);
92
93
 
93
94
  this.register(CreateSocialSiteWorkflow);
95
+ this.register(CopyTemplateWorkflow);
94
96
 
95
97
  // start processing...
96
98
  // this.start().catch((error) => console.error(error));
@@ -0,0 +1,85 @@
1
+ import Inject from "@entity-access/entity-access/dist/di/di.js";
2
+ import Workflow, { UniqueActivity } from "@entity-access/entity-access/dist/workflows/Workflow.js";
3
+ import SocialMailContext from "../../model/SocialMailContext.js";
4
+ import Sql from "@entity-access/entity-access/dist/sql/Sql.js";
5
+
6
+ export default class CopyTemplateWorkflow extends Workflow<{ folderID, templateID }> {
7
+
8
+ async run() {
9
+ return this.copy();
10
+ }
11
+
12
+ @UniqueActivity
13
+ async copy(
14
+ @Inject db?: SocialMailContext
15
+ ) {
16
+ // delete all files from current folder ..
17
+
18
+ const { folderID, templateID } = this.input;
19
+
20
+ const currentPath = `${folderID}/%`;
21
+
22
+ await using tx = await db.connection.createTransaction();
23
+
24
+ await db.appFiles
25
+ .where({ folderID, currentPath }, (p) => (x) => Sql.text.like(x.path, p.currentPath) && x.appFileID !== p.folderID )
26
+ .update(void 0, (p) => (x) => ({ isDeleted: true }));
27
+
28
+ await this.copyFolder(db, folderID, templateID);
29
+
30
+
31
+ await tx.commit();
32
+ }
33
+
34
+ async copyFolder(db: SocialMailContext, destFolderID: any, srcFolderID: any) {
35
+ const children = await db.appFiles
36
+ .where({ srcFolderID }, (p) => (x) => x.parentID === p.srcFolderID && x.isDeleted === false)
37
+ .toArray();
38
+
39
+ for (const element of children) {
40
+
41
+ const { name } = element;
42
+
43
+ let existing = await db.appFiles
44
+ .where({ name, destFolderID }, (p) => (x) => x.parentID === p.destFolderID
45
+ && x.name === p.name)
46
+ .first();
47
+
48
+ if (existing) {
49
+ if (existing.isFolder !== element.isFolder) {
50
+ // delete existing...
51
+ await db.appFiles.statements.update({ isDeleted: true,}, { appFileID: existing.appFileID});
52
+ existing = null;
53
+
54
+ } else {
55
+ if (existing.isDeleted) {
56
+ existing.isDeleted = false;
57
+ await db.appFiles.statements.update({ isDeleted: false,}, { appFileID: existing.appFileID});
58
+ }
59
+ }
60
+ }
61
+
62
+ if (!existing) {
63
+ existing = await db.appFiles.statements.insert({
64
+ ... element,
65
+ appFileID: void 0,
66
+ parentID: destFolderID
67
+ });
68
+ } else {
69
+
70
+ await db.appFiles.statements.update({
71
+ fileContentID: element.fileContentID,
72
+ contentType: element.contentType,
73
+ dateCreated: element.dateCreated,
74
+ dateUpdated: element.dateUpdated
75
+ });
76
+ }
77
+
78
+ if (existing.isFolder) {
79
+ await this.copyFolder(db, existing.appFileID, element.appFileID);
80
+ }
81
+
82
+ }
83
+ }
84
+
85
+ }
@@ -28,7 +28,7 @@ export default class CreateSocialSiteWorkflow extends Workflow<{ userID: number,
28
28
  const now = DateTime.now;
29
29
  const hosts = [] as WebSiteHost[];
30
30
 
31
- const { userID, domainName } = this.input;
31
+ const { userID, domainName, templateID } = this.input;
32
32
 
33
33
  // add a hosting domain..
34
34
 
@@ -98,6 +98,7 @@ export default class CreateSocialSiteWorkflow extends Workflow<{ userID: number,
98
98
  websiteFolder: db.websiteFolders.add({
99
99
  isStatic: true,
100
100
  hosts,
101
+ templateID,
101
102
  channelDomains
102
103
  }),
103
104
  });