@raclettejs/core 0.1.19 → 0.1.21

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 (134) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/CONTRIBUTING.md +23 -0
  3. package/bin/cli.js +1 -1
  4. package/dev/README.md +4 -0
  5. package/dist/cli.js +135 -124
  6. package/dist/cli.js.map +4 -4
  7. package/dist/index.js +9 -8
  8. package/dist/index.js.map +4 -4
  9. package/package.json +12 -6
  10. package/raclette.default.config.yaml +60 -0
  11. package/services/backend/delay-api-debugger.sh +0 -0
  12. package/services/backend/package.json +1 -0
  13. package/services/backend/src/app.ts +4 -0
  14. package/services/backend/src/core/config/configService.ts +10 -1
  15. package/services/backend/src/core/events/eventEmitter.ts +32 -7
  16. package/services/backend/src/core/http/request-params.plugin.ts +2 -2
  17. package/services/backend/src/core/pluginSystem/pluginFastifyInstance.ts +4 -1
  18. package/services/backend/src/core/pluginSystem/pluginTypes.ts +3 -1
  19. package/services/backend/src/core/sockets/createSystemEventHandlers.ts +7 -0
  20. package/services/backend/src/core/sockets/index.ts +61 -13
  21. package/services/backend/src/core/sockets/socketManager.ts +452 -105
  22. package/services/backend/src/core/sockets/socketTypes.ts +13 -1
  23. package/services/backend/src/core/sockets/workSessionJoinPayload.ts +106 -0
  24. package/services/backend/src/corePlugins/raclette__core/backend/datatypes/account/routes/route.account.get.ts +3 -1
  25. package/services/backend/src/corePlugins/raclette__core/backend/datatypes/account/routes/route.account.getAll.ts +3 -1
  26. package/services/backend/src/corePlugins/raclette__core/backend/datatypes/account/routes/route.account.hardDelete.ts +16 -19
  27. package/services/backend/src/corePlugins/raclette__core/backend/datatypes/account/routes/route.account.patch.ts +3 -1
  28. package/services/backend/src/corePlugins/raclette__core/backend/datatypes/account/routes/route.account.post.ts +3 -1
  29. package/services/backend/src/corePlugins/raclette__core/backend/datatypes/account/routes/route.account.remove.ts +3 -1
  30. package/services/backend/src/corePlugins/raclette__core/backend/datatypes/composition/composition.service.ts +2 -3
  31. package/services/backend/src/corePlugins/raclette__core/backend/datatypes/composition/routes/route.composition.get.ts +3 -1
  32. package/services/backend/src/corePlugins/raclette__core/backend/datatypes/composition/routes/route.composition.getAll.ts +3 -1
  33. package/services/backend/src/corePlugins/raclette__core/backend/datatypes/composition/routes/route.composition.hardDelete.ts +16 -19
  34. package/services/backend/src/corePlugins/raclette__core/backend/datatypes/composition/routes/route.composition.patch.ts +3 -1
  35. package/services/backend/src/corePlugins/raclette__core/backend/datatypes/composition/routes/route.composition.post.bulk.ts +3 -1
  36. package/services/backend/src/corePlugins/raclette__core/backend/datatypes/composition/routes/route.composition.post.ts +3 -1
  37. package/services/backend/src/corePlugins/raclette__core/backend/datatypes/composition/routes/route.composition.remove.ts +3 -1
  38. package/services/backend/src/corePlugins/raclette__core/backend/datatypes/composition/routes/route.composition.restore.ts +12 -15
  39. package/services/backend/src/corePlugins/raclette__core/backend/datatypes/interactionLink/interactionLink.service.ts +2 -3
  40. package/services/backend/src/corePlugins/raclette__core/backend/datatypes/interactionLink/routes/route.interactionLink.get.ts +3 -1
  41. package/services/backend/src/corePlugins/raclette__core/backend/datatypes/interactionLink/routes/route.interactionLink.getAll.ts +4 -2
  42. package/services/backend/src/corePlugins/raclette__core/backend/datatypes/interactionLink/routes/route.interactionLink.hardDelete.ts +12 -17
  43. package/services/backend/src/corePlugins/raclette__core/backend/datatypes/interactionLink/routes/route.interactionLink.patch.ts +3 -1
  44. package/services/backend/src/corePlugins/raclette__core/backend/datatypes/interactionLink/routes/route.interactionLink.post.bulk.ts +3 -1
  45. package/services/backend/src/corePlugins/raclette__core/backend/datatypes/interactionLink/routes/route.interactionLink.post.ts +3 -1
  46. package/services/backend/src/corePlugins/raclette__core/backend/datatypes/interactionLink/routes/route.interactionLink.remove.ts +3 -1
  47. package/services/backend/src/corePlugins/raclette__core/backend/datatypes/interactionLink/routes/route.interactionLink.restore.ts +12 -15
  48. package/services/backend/src/corePlugins/raclette__core/backend/datatypes/project/project.service.ts +1 -0
  49. package/services/backend/src/corePlugins/raclette__core/backend/datatypes/project/routes/route.project.get.ts +3 -1
  50. package/services/backend/src/corePlugins/raclette__core/backend/datatypes/project/routes/route.project.getAll.ts +4 -2
  51. package/services/backend/src/corePlugins/raclette__core/backend/datatypes/project/routes/route.project.hardDelete.ts +3 -1
  52. package/services/backend/src/corePlugins/raclette__core/backend/datatypes/project/routes/route.project.patch.ts +3 -1
  53. package/services/backend/src/corePlugins/raclette__core/backend/datatypes/project/routes/route.project.post.ts +4 -2
  54. package/services/backend/src/corePlugins/raclette__core/backend/datatypes/project/routes/route.project.remove.ts +3 -1
  55. package/services/backend/src/corePlugins/raclette__core/backend/datatypes/tag/routes/route.tag.get.ts +1 -0
  56. package/services/backend/src/corePlugins/raclette__core/backend/datatypes/tag/routes/route.tag.getAll.ts +1 -0
  57. package/services/backend/src/corePlugins/raclette__core/backend/datatypes/tag/routes/route.tag.hardDelete.ts +10 -15
  58. package/services/backend/src/corePlugins/raclette__core/backend/datatypes/tag/routes/route.tag.patch.ts +3 -1
  59. package/services/backend/src/corePlugins/raclette__core/backend/datatypes/tag/routes/route.tag.post.bulk.ts +3 -1
  60. package/services/backend/src/corePlugins/raclette__core/backend/datatypes/tag/routes/route.tag.post.ts +3 -1
  61. package/services/backend/src/corePlugins/raclette__core/backend/datatypes/tag/routes/route.tag.remove.ts +3 -1
  62. package/services/backend/src/corePlugins/raclette__core/backend/datatypes/tag/routes/route.tag.restore.ts +12 -15
  63. package/services/backend/src/corePlugins/raclette__core/backend/datatypes/tag/tag.service.ts +1 -2
  64. package/services/backend/src/corePlugins/raclette__core/backend/datatypes/user/routes/route.user.get.ts +1 -0
  65. package/services/backend/src/corePlugins/raclette__core/backend/datatypes/user/routes/route.user.getAll.ts +1 -0
  66. package/services/backend/src/corePlugins/raclette__core/backend/datatypes/user/routes/route.user.hardDelete.ts +10 -15
  67. package/services/backend/src/corePlugins/raclette__core/backend/datatypes/user/routes/route.user.patch.ts +4 -6
  68. package/services/backend/src/corePlugins/raclette__core/backend/datatypes/user/routes/route.user.patchLastProject.ts +4 -2
  69. package/services/backend/src/corePlugins/raclette__core/backend/datatypes/user/routes/route.user.post.ts +3 -1
  70. package/services/backend/src/corePlugins/raclette__core/backend/datatypes/user/routes/route.user.remove.ts +3 -4
  71. package/services/backend/src/corePlugins/raclette__core/backend/datatypes/user/routes/route.user.restore.ts +12 -15
  72. package/services/backend/src/corePlugins/raclette__core/backend/datatypes/workSession/events/index.ts +45 -0
  73. package/services/backend/src/corePlugins/raclette__core/backend/datatypes/workSession/helpers/crud.ts +12 -0
  74. package/services/backend/src/corePlugins/raclette__core/backend/datatypes/workSession/helpers/payload.ts +21 -0
  75. package/services/backend/src/corePlugins/raclette__core/backend/datatypes/workSession/index.ts +55 -0
  76. package/services/backend/src/corePlugins/raclette__core/backend/datatypes/workSession/routes/index.ts +19 -0
  77. package/services/backend/src/corePlugins/raclette__core/backend/datatypes/workSession/routes/route.workSession.get.ts +53 -0
  78. package/services/backend/src/corePlugins/raclette__core/backend/datatypes/workSession/routes/route.workSession.getAll.ts +39 -0
  79. package/services/backend/src/corePlugins/raclette__core/backend/datatypes/workSession/routes/route.workSession.hardDelete.ts +53 -0
  80. package/services/backend/src/corePlugins/raclette__core/backend/datatypes/workSession/routes/route.workSession.patch.ts +58 -0
  81. package/services/backend/src/corePlugins/raclette__core/backend/datatypes/workSession/routes/route.workSession.post.ts +53 -0
  82. package/services/backend/src/corePlugins/raclette__core/backend/datatypes/workSession/routes/route.workSession.remove.ts +52 -0
  83. package/services/backend/src/corePlugins/raclette__core/backend/datatypes/workSession/workSession.model.ts +65 -0
  84. package/services/backend/src/corePlugins/raclette__core/backend/datatypes/workSession/workSession.schema.ts +125 -0
  85. package/services/backend/src/corePlugins/raclette__core/backend/datatypes/workSession/workSession.service.ts +351 -0
  86. package/services/backend/src/corePlugins/raclette__core/backend/index.ts +2 -0
  87. package/services/backend/src/corePlugins/raclette__core/frontend/generated-config.ts +159 -24
  88. package/services/backend/src/modules/authentication/index.ts +255 -4
  89. package/services/backend/src/modules/hooks/rate-limiter.ts +21 -0
  90. package/services/backend/src/types/custom-fastify.d.ts +17 -0
  91. package/services/backend/src/utils/request.utils.ts +4 -1
  92. package/services/backend/types/index.d.ts +15 -1
  93. package/services/backend/yarn.lock +13 -4
  94. package/services/frontend/index.html +1 -1
  95. package/services/frontend/provision/entrypoint.sh +0 -0
  96. package/services/frontend/src/core/lib/configService.ts +1 -1
  97. package/services/frontend/src/core/lib/dataHelper.ts +1 -1
  98. package/services/frontend/src/core/lib/eggs/snow.ts +49 -20
  99. package/services/frontend/src/core/lib/helpers/index.ts +1 -0
  100. package/services/frontend/src/core/lib/helpers/removeEmpty.ts +69 -0
  101. package/services/frontend/src/core/lib/httpClient.ts +19 -0
  102. package/services/frontend/src/core/main.ts +20 -10
  103. package/services/frontend/src/core/setup/socket.ts +4 -3
  104. package/services/frontend/src/core/setup/socketClient.ts +31 -3
  105. package/services/frontend/src/core/setup/socketEvents.ts +92 -8
  106. package/services/frontend/src/core/store/index.ts +5 -1
  107. package/services/frontend/src/core/store/reducers/compositions/index.ts +2 -2
  108. package/services/frontend/src/core/store/reducers/interactionLinks/index.ts +1 -1
  109. package/services/frontend/src/core/store/reducers/widgets/reducers.ts +1 -2
  110. package/services/frontend/src/core/store/types/index.ts +0 -1
  111. package/services/frontend/src/core/types/PluginRegistrar.ts +8 -6
  112. package/services/frontend/src/core/types/Store.ts +1 -0
  113. package/services/frontend/src/orchestrator/components/composition/WidgetsLayoutLoader.vue +68 -8
  114. package/services/frontend/src/orchestrator/components/menu/UserMenu.vue +17 -5
  115. package/services/frontend/src/orchestrator/components/welcomeScreen/AdminWelcomeScreen.vue +1 -1
  116. package/services/frontend/src/orchestrator/composables/index.ts +1 -0
  117. package/services/frontend/src/orchestrator/composables/usePluginApi.ts +0 -3
  118. package/services/frontend/src/orchestrator/composables/useRouteState.ts +23 -4
  119. package/services/frontend/src/orchestrator/composables/useWidgetLifecycle.ts +166 -0
  120. package/services/frontend/src/orchestrator/helpers/index.ts +1 -0
  121. package/services/frontend/src/orchestrator/i18n/de-DE.json +1 -1
  122. package/services/frontend/src/orchestrator/i18n/en-EU.json +1 -1
  123. package/services/frontend/src/orchestrator/i18n/sk.json +1 -1
  124. package/services/frontend/src/orchestrator/index.ts +34 -4
  125. package/services/frontend/src/orchestrator/router/routeParserHelper.ts +106 -1
  126. package/services/frontend/src/orchestrator/types/Widgets.ts +2 -0
  127. package/services/frontend/types.ts +1 -0
  128. package/src/README.md +404 -0
  129. package/src/types.ts +19 -5
  130. package/templates/README.md +0 -0
  131. package/types/index.ts +18 -4
  132. package/services/backend/.gitignore +0 -17
  133. package/services/frontend/.gitignore +0 -35
  134. package/yarn.lock +0 -2937
@@ -2,7 +2,8 @@ import type { Static } from "@sinclair/typebox"
2
2
  import type { FastifyReply, FastifyRequest } from "fastify"
3
3
  import { PluginFastifyInstance } from "types"
4
4
  import { Type } from "@sinclair/typebox"
5
- import { ForbiddenError } from "@/utils/errors"
5
+
6
+ const permissions = ["user.isAdmin"]
6
7
 
7
8
  const ParamsSchema = Type.Object({
8
9
  _id: Type.String(),
@@ -17,21 +18,17 @@ export default (fastify: PluginFastifyInstance) => {
17
18
  reply: FastifyReply,
18
19
  ) => {
19
20
  try {
20
- if (req.user.isAdmin) {
21
- const { _id } = req.params
21
+ const { _id } = req.params
22
22
 
23
- const payload = await interactionLinkService.updateInteractionLink(
24
- fastify,
25
- req.requestParams,
26
- _id,
27
- { isDeleted: false },
28
- req.user._id,
29
- )
23
+ const payload = await interactionLinkService.updateInteractionLink(
24
+ fastify,
25
+ req.requestParams,
26
+ _id,
27
+ { isDeleted: false },
28
+ req.user._id,
29
+ )
30
30
 
31
- return payload
32
- } else {
33
- throw new ForbiddenError("Only admins can restore this core datatype")
34
- }
31
+ return payload
35
32
  } catch (error: any) {
36
33
  fastify.log.error(error.message)
37
34
  return reply.internalServerError(error.message)
@@ -40,7 +37,7 @@ export default (fastify: PluginFastifyInstance) => {
40
37
 
41
38
  return {
42
39
  handler,
43
- onRequest: [fastify.authenticate],
40
+ onRequest: [fastify.authenticate, fastify.checkPermissions(permissions)],
44
41
  config: {
45
42
  type: "dataRestore",
46
43
  broadcastChannels: ["interactionLinkRestored"],
@@ -87,6 +87,7 @@ export class ProjectService {
87
87
  options: QueryOptions = {},
88
88
  ): Promise<ProjectType[]> {
89
89
  try {
90
+ filter = { isDeleted: false, ...filter }
90
91
  // Start building the query
91
92
  let query = this.projectModel.find(filter)
92
93
 
@@ -3,6 +3,8 @@ import type { FastifyReply, FastifyRequest } from "fastify"
3
3
  import { PluginFastifyInstance } from "types"
4
4
  import { Type } from "@sinclair/typebox"
5
5
 
6
+ const permissions = ["user.isAdmin"]
7
+
6
8
  const ParamsSchema = Type.Object({
7
9
  _id: Type.String(),
8
10
  })
@@ -39,7 +41,7 @@ export default (fastify: PluginFastifyInstance) => {
39
41
 
40
42
  return {
41
43
  handler,
42
- onRequest: [fastify.authenticate],
44
+ onRequest: [fastify.authenticate, fastify.checkPermissions(permissions)],
43
45
  config: {
44
46
  type: "dataRead",
45
47
  },
@@ -1,5 +1,7 @@
1
1
  import type { FastifyReply, FastifyRequest } from "fastify"
2
- import { PluginFastifyInstance } from "types"
2
+ import type { PluginFastifyInstance } from "types"
3
+
4
+ const permissions = ["user.isAdmin"]
3
5
 
4
6
  export default (fastify: PluginFastifyInstance) => {
5
7
  const projectService = fastify.custom.projectService
@@ -24,7 +26,7 @@ export default (fastify: PluginFastifyInstance) => {
24
26
 
25
27
  return {
26
28
  handler,
27
- onRequest: [fastify.authenticate],
29
+ onRequest: [fastify.authenticate, fastify.checkPermissions(permissions)],
28
30
  config: {
29
31
  type: "dataRead",
30
32
  },
@@ -3,6 +3,8 @@ import type { FastifyReply, FastifyRequest } from "fastify"
3
3
  import { PluginFastifyInstance } from "types"
4
4
  import { Type } from "@sinclair/typebox"
5
5
 
6
+ const permissions = ["user.isAdmin"]
7
+
6
8
  const ParamsSchema = Type.Object({
7
9
  _id: Type.String(),
8
10
  })
@@ -35,7 +37,7 @@ export default (fastify: PluginFastifyInstance) => {
35
37
 
36
38
  return {
37
39
  handler,
38
- onRequest: [fastify.authenticate],
40
+ onRequest: [fastify.authenticate, fastify.checkPermissions(permissions)],
39
41
  config: {
40
42
  type: "dataHardDeleted",
41
43
  broadcastChannels: ["projectHardDeleted"],
@@ -5,6 +5,8 @@ import { PluginFastifyInstance } from "types"
5
5
  import { Type } from "@sinclair/typebox"
6
6
  import { projectSchema } from "../project.schema"
7
7
 
8
+ const permissions = ["user.isAdmin"]
9
+
8
10
  const ParamsSchema = Type.Object({
9
11
  _id: Type.String(),
10
12
  })
@@ -40,7 +42,7 @@ export default (fastify: PluginFastifyInstance) => {
40
42
 
41
43
  return {
42
44
  handler,
43
- onRequest: [fastify.authenticate],
45
+ onRequest: [fastify.authenticate, fastify.checkPermissions(permissions)],
44
46
  config: {
45
47
  type: "dataUpdate",
46
48
  broadcastChannels: ["projectUpdated"],
@@ -1,7 +1,9 @@
1
1
  import type { FastifyReply, FastifyRequest } from "fastify"
2
- import { PluginFastifyInstance } from "types"
2
+ import type { PluginFastifyInstance } from "types"
3
3
  import { projectCreateSchema, type ProjectCreate } from "../project.schema"
4
4
 
5
+ const permissions = ["user.isAdmin"]
6
+
5
7
  export default (fastify: PluginFastifyInstance) => {
6
8
  const projectService = fastify.custom.projectService
7
9
 
@@ -27,7 +29,7 @@ export default (fastify: PluginFastifyInstance) => {
27
29
 
28
30
  return {
29
31
  handler,
30
- // onRequest: [fastify.authenticate],
32
+ onRequest: [fastify.authenticate, fastify.checkPermissions(permissions)],
31
33
  config: {
32
34
  type: "dataCreate",
33
35
  broadcastChannels: ["projectCreated"],
@@ -3,6 +3,8 @@ import type { FastifyReply, FastifyRequest } from "fastify"
3
3
  import { PluginFastifyInstance } from "types"
4
4
  import { Type } from "@sinclair/typebox"
5
5
 
6
+ const permissions = ["user.isAdmin"]
7
+
6
8
  const ParamsSchema = Type.Object({
7
9
  _id: Type.String(),
8
10
  })
@@ -35,7 +37,7 @@ export default (fastify: PluginFastifyInstance) => {
35
37
 
36
38
  return {
37
39
  handler,
38
- onRequest: [fastify.authenticate],
40
+ onRequest: [fastify.authenticate, fastify.checkPermissions(permissions)],
39
41
  config: {
40
42
  type: "dataUpdate",
41
43
  broadcastChannels: ["projectDeleted"],
@@ -1,6 +1,7 @@
1
1
  import type { FastifyReply, FastifyRequest } from "fastify"
2
2
  import { PluginFastifyInstance } from "types"
3
3
  import { Type, type Static } from "@sinclair/typebox"
4
+ import { ForbiddenError } from "@/utils/errors"
4
5
 
5
6
  const ParamsSchema = Type.Object({
6
7
  _id: Type.Optional(Type.String()),
@@ -1,5 +1,6 @@
1
1
  import type { FastifyReply, FastifyRequest } from "fastify"
2
2
  import { PluginFastifyInstance } from "types"
3
+ import { ForbiddenError } from "@/utils/errors"
3
4
 
4
5
  export default (fastify: PluginFastifyInstance) => {
5
6
  const tagService = fastify.custom.tagService
@@ -2,7 +2,8 @@ import type { Static } from "@sinclair/typebox"
2
2
  import type { FastifyReply, FastifyRequest } from "fastify"
3
3
  import { PluginFastifyInstance } from "types"
4
4
  import { Type } from "@sinclair/typebox"
5
- import { ForbiddenError } from "@/utils/errors"
5
+
6
+ const permissions = ["user.isAdmin"]
6
7
 
7
8
  const ParamsSchema = Type.Object({
8
9
  _id: Type.String(),
@@ -17,21 +18,15 @@ export default (fastify: PluginFastifyInstance) => {
17
18
  reply: FastifyReply,
18
19
  ) => {
19
20
  try {
20
- if (req.user.isAdmin) {
21
- const { _id } = req.params
21
+ const { _id } = req.params
22
22
 
23
- const payloadWithTag = await tagService.hardDeleteTag(
24
- fastify,
25
- req.requestParams,
26
- _id,
27
- )
23
+ const payloadWithTag = await tagService.hardDeleteTag(
24
+ fastify,
25
+ req.requestParams,
26
+ _id,
27
+ )
28
28
 
29
- return payloadWithTag
30
- } else {
31
- throw new ForbiddenError(
32
- "Only admins can hard delete this core datatype",
33
- )
34
- }
29
+ return payloadWithTag
35
30
  } catch (error: any) {
36
31
  fastify.log.error(error.message)
37
32
  return reply.internalServerError(error.message)
@@ -40,7 +35,7 @@ export default (fastify: PluginFastifyInstance) => {
40
35
 
41
36
  return {
42
37
  handler,
43
- onRequest: [fastify.authenticate],
38
+ onRequest: [fastify.authenticate, fastify.checkPermissions(permissions)],
44
39
  config: {
45
40
  type: "dataHardDeleted",
46
41
  broadcastChannels: ["tagHardDeleted"],
@@ -4,6 +4,8 @@ import { PluginFastifyInstance } from "types"
4
4
  import { Type } from "@sinclair/typebox"
5
5
  import { tagUpdateSchema } from "../tag.schema"
6
6
 
7
+ const permissions = ["user.isAdmin"]
8
+
7
9
  const ParamsSchema = Type.Object({
8
10
  _id: Type.String(),
9
11
  })
@@ -40,7 +42,7 @@ export default (fastify: PluginFastifyInstance) => {
40
42
 
41
43
  return {
42
44
  handler,
43
- onRequest: [fastify.authenticate],
45
+ onRequest: [fastify.authenticate, fastify.checkPermissions(permissions)],
44
46
  config: {
45
47
  type: "dataUpdate",
46
48
  broadcastChannels: ["tagUpdated"],
@@ -3,6 +3,8 @@ import type { FastifyReply, FastifyRequest } from "fastify"
3
3
  import type { PluginFastifyInstance } from "types"
4
4
  import { tagCreateSchema } from "../tag.schema"
5
5
 
6
+ const permissions = ["user.isAdmin"]
7
+
6
8
  export default (fastify: PluginFastifyInstance) => {
7
9
  const tagService = fastify.custom.tagService
8
10
 
@@ -40,7 +42,7 @@ export default (fastify: PluginFastifyInstance) => {
40
42
 
41
43
  return {
42
44
  handler,
43
- onRequest: [fastify.authenticate],
45
+ onRequest: [fastify.authenticate, fastify.checkPermissions(permissions)],
44
46
  config: {
45
47
  type: "dataCreate",
46
48
  broadcastChannels: ["tagsCreated"],
@@ -4,6 +4,8 @@ import { PluginFastifyInstance } from "types"
4
4
  import { Type } from "@sinclair/typebox"
5
5
  import { tagCreateSchema, type TagCreate } from "../tag.schema"
6
6
 
7
+ const permissions = ["user.isAdmin"]
8
+
7
9
  const ParamsSchema = Type.Object({
8
10
  _id: Type.String(),
9
11
  project: Type.String(),
@@ -38,7 +40,7 @@ export default (fastify: PluginFastifyInstance) => {
38
40
 
39
41
  return {
40
42
  handler,
41
- onRequest: [fastify.authenticate],
43
+ onRequest: [fastify.authenticate, fastify.checkPermissions(permissions)],
42
44
  config: {
43
45
  type: "dataCreate",
44
46
  broadcastChannels: ["tagCreated"],
@@ -3,6 +3,8 @@ import type { FastifyReply, FastifyRequest } from "fastify"
3
3
  import { PluginFastifyInstance } from "types"
4
4
  import { Type } from "@sinclair/typebox"
5
5
 
6
+ const permissions = ["user.isAdmin"]
7
+
6
8
  const ParamsSchema = Type.Object({
7
9
  _id: Type.String(),
8
10
  })
@@ -33,7 +35,7 @@ export default (fastify: PluginFastifyInstance) => {
33
35
 
34
36
  return {
35
37
  handler,
36
- onRequest: [fastify.authenticate],
38
+ onRequest: [fastify.authenticate, fastify.checkPermissions(permissions)],
37
39
  config: {
38
40
  type: "dataUpdate",
39
41
  broadcastChannels: ["tagDeleted"],
@@ -2,7 +2,8 @@ import type { Static } from "@sinclair/typebox"
2
2
  import type { FastifyReply, FastifyRequest } from "fastify"
3
3
  import { PluginFastifyInstance } from "types"
4
4
  import { Type } from "@sinclair/typebox"
5
- import { ForbiddenError } from "@/utils/errors"
5
+
6
+ const permissions = ["user.isAdmin"]
6
7
 
7
8
  const ParamsSchema = Type.Object({
8
9
  _id: Type.String(),
@@ -17,21 +18,17 @@ export default (fastify: PluginFastifyInstance) => {
17
18
  reply: FastifyReply,
18
19
  ) => {
19
20
  try {
20
- if (req.user.isAdmin) {
21
- const { _id } = req.params
21
+ const { _id } = req.params
22
22
 
23
- const payload = await tagService.updateTag(
24
- fastify,
25
- req.requestParams,
26
- _id,
27
- { isDeleted: false },
28
- req.user._id,
29
- )
23
+ const payload = await tagService.updateTag(
24
+ fastify,
25
+ req.requestParams,
26
+ _id,
27
+ { isDeleted: false },
28
+ req.user._id,
29
+ )
30
30
 
31
- return payload
32
- } else {
33
- throw new ForbiddenError("Only admins can restore this core datatype")
34
- }
31
+ return payload
35
32
  } catch (error: any) {
36
33
  fastify.log.error(error.message)
37
34
  return reply.internalServerError(error.message)
@@ -40,7 +37,7 @@ export default (fastify: PluginFastifyInstance) => {
40
37
 
41
38
  return {
42
39
  handler,
43
- onRequest: [fastify.authenticate],
40
+ onRequest: [fastify.authenticate, fastify.checkPermissions(permissions)],
44
41
  config: {
45
42
  type: "dataRestore",
46
43
  broadcastChannels: ["tagRestored"],
@@ -133,8 +133,7 @@ export class TagService {
133
133
  options: QueryOptions = {},
134
134
  ): Promise<TagType[]> {
135
135
  try {
136
- if (filter.isDeleted !== true && filter.isDeleted !== "true")
137
- filter.isDeleted = false
136
+ filter = { isDeleted: false, ...filter }
138
137
  // Start building the query
139
138
  let query = this.tagModel.find(filter)
140
139
 
@@ -2,6 +2,7 @@ import type { Static } from "@sinclair/typebox"
2
2
  import type { FastifyReply, FastifyRequest } from "fastify"
3
3
  import { PluginFastifyInstance } from "types"
4
4
  import { Type } from "@sinclair/typebox"
5
+ import { ForbiddenError } from "@/utils/errors"
5
6
 
6
7
  const ParamsSchema = Type.Object({
7
8
  _id: Type.String(),
@@ -2,6 +2,7 @@ import type { Static } from "@sinclair/typebox"
2
2
  import type { FastifyReply, FastifyRequest } from "fastify"
3
3
  import { PluginFastifyInstance } from "types"
4
4
  import { Type } from "@sinclair/typebox"
5
+ import { ForbiddenError } from "@/utils/errors"
5
6
 
6
7
  const QuerySchema = Type.Object({
7
8
  account: Type.Optional(Type.String()),
@@ -2,7 +2,8 @@ import type { Static } from "@sinclair/typebox"
2
2
  import type { FastifyReply, FastifyRequest } from "fastify"
3
3
  import { PluginFastifyInstance } from "types"
4
4
  import { Type } from "@sinclair/typebox"
5
- import { ForbiddenError } from "@/utils/errors"
5
+
6
+ const permissions = ["user.isAdmin"]
6
7
 
7
8
  const ParamsSchema = Type.Object({
8
9
  _id: Type.String(),
@@ -17,21 +18,15 @@ export default (fastify: PluginFastifyInstance) => {
17
18
  reply: FastifyReply,
18
19
  ) => {
19
20
  try {
20
- if (req.user.isAdmin) {
21
- const { _id } = req.params
21
+ const { _id } = req.params
22
22
 
23
- const payloadWithUser = await userService.hardDeleteUser(
24
- fastify,
25
- req.requestParams,
26
- _id,
27
- )
23
+ const payloadWithUser = await userService.hardDeleteUser(
24
+ fastify,
25
+ req.requestParams,
26
+ _id,
27
+ )
28
28
 
29
- return payloadWithUser
30
- } else {
31
- throw new ForbiddenError(
32
- "Only admins can hard delete this core datatype",
33
- )
34
- }
29
+ return payloadWithUser
35
30
  } catch (error: any) {
36
31
  fastify.log.error(error.message)
37
32
  return reply.internalServerError(error.message)
@@ -40,7 +35,7 @@ export default (fastify: PluginFastifyInstance) => {
40
35
 
41
36
  return {
42
37
  handler,
43
- onRequest: [fastify.authenticate],
38
+ onRequest: [fastify.authenticate, fastify.checkPermissions(permissions)],
44
39
  config: {
45
40
  type: "dataHardDeleted",
46
41
  broadcastChannels: ["userHardDeleted"],
@@ -4,6 +4,8 @@ import type { PluginFastifyInstance } from "types"
4
4
  import { Type } from "@sinclair/typebox"
5
5
  import { userUpdateSchema } from "../user.schema"
6
6
 
7
+ const permissions = ["user.isAdmin"]
8
+
7
9
  const ParamsSchema = Type.Object({
8
10
  _id: Type.String(),
9
11
  })
@@ -22,15 +24,11 @@ export default (fastify: PluginFastifyInstance) => {
22
24
  reply: FastifyReply,
23
25
  ) => {
24
26
  try {
25
- let cleanBody = req.body
26
- if (!req.user.isAdmin) {
27
- delete cleanBody.tags
28
- }
29
27
  const payloadWithUser = await userService.updateUser(
30
28
  fastify,
31
29
  req.requestParams,
32
30
  req.params._id,
33
- cleanBody,
31
+ req.body,
34
32
  )
35
33
 
36
34
  return payloadWithUser
@@ -42,7 +40,7 @@ export default (fastify: PluginFastifyInstance) => {
42
40
 
43
41
  return {
44
42
  handler,
45
- onRequest: [fastify.authenticate],
43
+ onRequest: [fastify.authenticate, fastify.checkPermissions(permissions)],
46
44
  config: {
47
45
  type: "dataUpdate",
48
46
  broadcastChannels: ["userUpdated"],
@@ -1,7 +1,9 @@
1
1
  import type { FastifyReply, FastifyRequest } from "fastify"
2
- import { PluginFastifyInstance } from "types"
2
+ import type { PluginFastifyInstance } from "types"
3
3
  import { Type } from "@sinclair/typebox"
4
4
 
5
+ const permissions = ["user.isAdmin"]
6
+
5
7
  export default (fastify: PluginFastifyInstance) => {
6
8
  const userService = fastify.custom.userService
7
9
 
@@ -26,7 +28,7 @@ export default (fastify: PluginFastifyInstance) => {
26
28
 
27
29
  return {
28
30
  handler,
29
- onRequest: [fastify.authenticate],
31
+ onRequest: [fastify.authenticate, fastify.checkPermissions(permissions)],
30
32
  config: {
31
33
  type: "dataUpdate",
32
34
  broadcastChannels: ["userUpdated"],
@@ -2,6 +2,8 @@ import type { FastifyReply, FastifyRequest } from "fastify"
2
2
  import { PluginFastifyInstance } from "types"
3
3
  import { userCreateSchema, type UserCreate } from "../user.schema"
4
4
 
5
+ const permissions = ["user.isAdmin"]
6
+
5
7
  export default (fastify: PluginFastifyInstance) => {
6
8
  const userService = fastify.custom.userService
7
9
 
@@ -25,7 +27,7 @@ export default (fastify: PluginFastifyInstance) => {
25
27
 
26
28
  return {
27
29
  handler,
28
- onRequest: [fastify.authenticate],
30
+ onRequest: [fastify.authenticate, fastify.checkPermissions(permissions)],
29
31
  config: {
30
32
  type: "dataCreate",
31
33
  broadcastChannels: ["userCreated"],
@@ -4,6 +4,8 @@ import { PluginFastifyInstance } from "types"
4
4
  import { Type } from "@sinclair/typebox"
5
5
  import { ForbiddenError } from "@/utils/errors"
6
6
 
7
+ const permissions = ["user.isAdmin"]
8
+
7
9
  const ParamsSchema = Type.Object({
8
10
  _id: Type.String(),
9
11
  })
@@ -19,9 +21,6 @@ export default (fastify: PluginFastifyInstance) => {
19
21
  reply: FastifyReply,
20
22
  ) => {
21
23
  try {
22
- if (!req.user.isAdmin) {
23
- throw new ForbiddenError("Only Admins can use this feature")
24
- }
25
24
  if (req.user._id === req.params._id) {
26
25
  throw new ForbiddenError("A user cannot remove itself")
27
26
  }
@@ -41,7 +40,7 @@ export default (fastify: PluginFastifyInstance) => {
41
40
 
42
41
  return {
43
42
  handler,
44
- onRequest: [fastify.authenticate],
43
+ onRequest: [fastify.authenticate, fastify.checkPermissions(permissions)],
45
44
  config: {
46
45
  type: "dataDelete",
47
46
  broadcastChannels: ["userDeleted"],
@@ -2,7 +2,8 @@ import type { Static } from "@sinclair/typebox"
2
2
  import type { FastifyReply, FastifyRequest } from "fastify"
3
3
  import { PluginFastifyInstance } from "types"
4
4
  import { Type } from "@sinclair/typebox"
5
- import { ForbiddenError } from "@/utils/errors"
5
+
6
+ const permissions = ["user.isAdmin"]
6
7
 
7
8
  const ParamsSchema = Type.Object({
8
9
  _id: Type.String(),
@@ -17,21 +18,17 @@ export default (fastify: PluginFastifyInstance) => {
17
18
  reply: FastifyReply,
18
19
  ) => {
19
20
  try {
20
- if (req.user.isAdmin) {
21
- const { _id } = req.params
21
+ const { _id } = req.params
22
22
 
23
- const payload = await userService.updateUser(
24
- fastify,
25
- req.requestParams,
26
- _id,
27
- { isDeleted: false },
28
- req.user._id,
29
- )
23
+ const payload = await userService.updateUser(
24
+ fastify,
25
+ req.requestParams,
26
+ _id,
27
+ { isDeleted: false },
28
+ req.user._id,
29
+ )
30
30
 
31
- return payload
32
- } else {
33
- throw new ForbiddenError("Only admins can restore this core datatype")
34
- }
31
+ return payload
35
32
  } catch (error: any) {
36
33
  fastify.log.error(error.message)
37
34
  return reply.internalServerError(error.message)
@@ -40,7 +37,7 @@ export default (fastify: PluginFastifyInstance) => {
40
37
 
41
38
  return {
42
39
  handler,
43
- onRequest: [fastify.authenticate],
40
+ onRequest: [fastify.authenticate, fastify.checkPermissions(permissions)],
44
41
  config: {
45
42
  type: "dataRestore",
46
43
  broadcastChannels: ["userRestored"],
@@ -0,0 +1,45 @@
1
+ import type { AnyWorkSession } from "../workSession.schema"
2
+ import type { FrontendPayload } from "@c/payload/payloadTypes"
3
+ import { PluginFastifyInstance } from "types"
4
+
5
+ const registerEvents = (fastify: PluginFastifyInstance) => {
6
+ /**
7
+ * WorkSession created
8
+ */
9
+ const created = async (payload: FrontendPayload<AnyWorkSession>) => {
10
+ fastify.eventbus.emit("broadcastDataUpdated", payload)
11
+ fastify.eventbus.emit("broadcastWorkSessionCreated", payload)
12
+ fastify.log.info(
13
+ `[eventbus] workSession broadcast created ${payload.body.item._id}`,
14
+ )
15
+ }
16
+
17
+ /**
18
+ * WorkSession updated
19
+ */
20
+ const updated = async (payload: FrontendPayload<AnyWorkSession>) => {
21
+ fastify.eventbus.emit("broadcastDataUpdated", payload)
22
+ fastify.log.info(
23
+ `[eventbus] workSession broadcast updated ${payload.body.item._id}`,
24
+ )
25
+ }
26
+
27
+ /**
28
+ * WorkSession deleted
29
+ */
30
+ const deleted = async (payload: FrontendPayload<AnyWorkSession>) => {
31
+ fastify.eventbus.emit("broadcastWorkSessionDeleted", payload)
32
+ fastify.log.info(
33
+ `[eventbus] workSession broadcast deleted ${payload.body.item._id}`,
34
+ )
35
+ }
36
+
37
+ /**
38
+ * Register event handlers
39
+ */
40
+ fastify.eventbus.on("coreWorkSessionCreated", created)
41
+ fastify.eventbus.on("coreWorkSessionUpdated", updated)
42
+ fastify.eventbus.on("coreWorkSessionDeleted", deleted)
43
+ }
44
+
45
+ export default registerEvents
@@ -0,0 +1,12 @@
1
+ import type { PluginFastifyInstance } from "@raclettejs/core"
2
+
3
+ export const registerCrud = (fastify: PluginFastifyInstance) => {
4
+ const workSessionService = fastify.custom.workSessionService
5
+
6
+ fastify.registerCrudHandlers("workSession", {
7
+ create: workSessionService.createWorkSession,
8
+ read: workSessionService.readWorkSession,
9
+ update: workSessionService.updateWorkSession,
10
+ delete: workSessionService.removeWorkSession,
11
+ })
12
+ }