This repository was archived by the owner on Nov 19, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathAnalyticsModule.swift
More file actions
62 lines (51 loc) · 1.73 KB
/
AnalyticsModule.swift
File metadata and controls
62 lines (51 loc) · 1.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
//
// File.swift
//
//
// Created by Tibor Bodecs on 2021. 12. 26..
//
import FeatherCore
import FeatherObjects
import Vapor
import AnalyticsObjects
public extension HookName {
// static let permission: HookName = "permission"
}
struct AnalyticsModule: FeatherModule {
static var bundleUrl: URL? {
Bundle.module.resourceURL?.appendingPathComponent("Bundle")
}
let router = AnalyticsRouter()
func boot(_ app: Application) throws {
app.migrations.add(AnalyticsMigrations.v1())
app.hooks.register(.installPermissions, use: installUserPermissionsHook)
app.hooks.register(.adminRoutes, use: router.adminRoutesHook)
app.hooks.register(.apiRoutes, use: router.apiRoutesHook)
app.hooks.register(.adminCss, use: adminCssHook, priority: 42)
app.hooks.register(.adminWidgets, use: adminWidgetsHook, priority: 300)
app.hooks.register(.webMiddlewares, use: webMiddlewaresHook)
}
func adminCssHook(args: HookArguments) -> [String] {
[
"/css/analytics/admin.css"
]
}
func adminWidgetsHook(args: HookArguments) -> [TemplateRepresentable] {
if args.req.checkPermission(Analytics.permission(for: .detail)) {
return [
AnalyticsAdminWidgetTemplate()
]
}
return []
}
func webMiddlewaresHook(args: HookArguments) -> [Middleware] {
[
AnalyticsLogMiddleware(),
]
}
func installUserPermissionsHook(args: HookArguments) -> [FeatherPermission.Create] {
var permissions = Analytics.availablePermissions()
permissions += Analytics.Log.availablePermissions()
return permissions.map { .init($0) }
}
}