Skip to content
This repository was archived by the owner on Jan 9, 2024. It is now read-only.

Commit 86efd9c

Browse files
committed
Updates for tenant system, make cloud tenants optional and add local tenant configuration
1 parent 28fca19 commit 86efd9c

File tree

10 files changed

+65
-24
lines changed

10 files changed

+65
-24
lines changed

src/main/kotlin/id/walt/db/models/WalletOperationHistories.kt

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
package id.walt.db.models
22

3+
import id.walt.crypto.utils.JsonUtils.toJsonObject
34
import id.walt.service.WalletService
45
import kotlinx.datetime.Clock
56
import kotlinx.datetime.Instant
67
import kotlinx.datetime.toKotlinInstant
78
import kotlinx.serialization.Serializable
8-
import kotlinx.serialization.encodeToString
99
import kotlinx.serialization.json.Json
10+
import kotlinx.serialization.json.JsonObject
11+
import kotlinx.serialization.json.jsonObject
1012
import kotlinx.uuid.UUID
1113
import kotlinx.uuid.exposed.KotlinxUUIDTable
1214
import kotlinx.uuid.generateUUID
@@ -28,15 +30,15 @@ data class WalletOperationHistory(
2830
val wallet: UUID,
2931
val timestamp: Instant,
3032
val operation: String,
31-
val data: String,
33+
val data: JsonObject,
3234
) {
3335
constructor(result: ResultRow) : this(
3436
id = result[WalletOperationHistories.id].value,
3537
account = result[WalletOperationHistories.account].value,
3638
wallet = result[WalletOperationHistories.wallet].value,
3739
timestamp = result[WalletOperationHistories.timestamp].toKotlinInstant(),
3840
operation = result[WalletOperationHistories.operation],
39-
data = result[WalletOperationHistories.data],
41+
data = Json.parseToJsonElement(result[WalletOperationHistories.data]).jsonObject,
4042
)
4143

4244
companion object {
@@ -45,7 +47,7 @@ data class WalletOperationHistory(
4547
wallet = wallet.walletId,
4648
timestamp = Clock.System.now(),
4749
operation = operation,
48-
data = Json.encodeToString(data)
50+
data = data.toJsonObject()
4951
)
5052
}
5153
}

src/main/kotlin/id/walt/service/WalletServiceManager.kt

+15
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,21 @@ object WalletServiceManager {
2626
fun createWallet(forAccount: UUID): UUID {
2727
val accountName = AccountsService.getNameFor(forAccount)
2828

29+
// TODO: remove testing code / lock behind dev-mode
30+
if (accountName?.contains("multi-wallet") == true) {
31+
val second = Wallets.insert {
32+
it[name] = "ABC Company wallet"
33+
it[createdOn] = Clock.System.now().toJavaInstant()
34+
}[Wallets.id].value
35+
36+
AccountWalletMappings.insert {
37+
it[account] = forAccount
38+
it[wallet] = second
39+
it[permissions] = AccountWalletPermissions.READ_ONLY
40+
it[addedOn] = Clock.System.now().toJavaInstant()
41+
}
42+
}
43+
2944
val walletId = Wallets.insert {
3045
it[name] = "Wallet of $accountName"
3146
it[createdOn] = Clock.System.now().toJavaInstant()

web/nuxt.config.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ export default defineNuxtConfig({
176176
runtimeConfig: {
177177
public: {
178178
projectId: process.env.ProjectId,
179-
issuerCallbackUrl: process.env.IssuerCallbackUrl ?? "http://localhost:3000"
179+
issuerCallbackUrl: process.env.IssuerCallbackUrl ?? "http://localhost:3000",
180180
}
181181
},
182182

web/src/app.config.ts

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
export default defineAppConfig({
2+
enableCloudTenants: false,
3+
localTenant: {
4+
name : "walt.id GmbH",
5+
logoImage : "/svg/waltid.svg",
6+
inWalletLogoImage : "/svg/walt-s.svg",
7+
bgImage : "/images/start-page-background.png",
8+
showWaltidLoadingSpinner : true,
9+
}
10+
})

web/src/app.vue

-2
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,8 @@ InitApp();
2929
const locale = useState<string>("locale.i18n");
3030
3131
const tenant = await (useTenant()).value
32-
const bgImg = tenant?.bgImg
3332
const name = tenant?.name
3433
const logoImg = tenant?.logoImage
35-
const showWaltidLoadingSpinner = tenant?.showWaltidLoadingSpinner
3634
</script>
3735

3836
<style lang="postcss">

web/src/composables/tenants.ts

+28-13
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,35 @@
11
export function useTenant() {
22
return useState("tenant-config", async () => {
3-
const baseTenantDomain = useRequestURL().host.replace(":3000", ":8080");
4-
console.log("Base tenant domain is: ", baseTenantDomain)
3+
console.log("Getting tenant config...");
4+
const config = useAppConfig();
5+
console.log("App config: ", config);
56

6-
const { data , error } = await useFetch("http://" + baseTenantDomain + "/config/wallet");
7-
console.log("Tenant configuration: ", data.value)
7+
if (config.enableCloudTenants) {
8+
const baseTenantDomain = useRequestURL().host.replace(":3000", ":8080");
9+
console.log("Base tenant domain is: ", baseTenantDomain);
810

9-
if (error.value) {
10-
console.log("Tenant error: ", error.value.message)
11-
throw createError({
12-
statusCode: 404,
13-
statusMessage: "Tenant error: " + error.value?.data?.message,
14-
fatal: true
15-
})
16-
}
11+
const { data, error } = await useFetch("http://" + baseTenantDomain + "/config/wallet");
12+
console.log("Tenant configuration: ", data.value);
13+
14+
if (error.value) {
15+
const dataMessage = error.value?.data?.message;
16+
const localErrorMessage = error.value?.message;
17+
18+
console.log("Tenant error, error message: ", dataMessage);
19+
console.log("Tenant error, data message: ", dataMessage);
1720

18-
return data.value;
21+
const errorMessage = dataMessage ? dataMessage : localErrorMessage;
22+
23+
throw createError({
24+
statusCode: 404,
25+
statusMessage: "Tenant error: " + errorMessage,
26+
fatal: true
27+
});
28+
}
29+
30+
return data.value;
31+
} else {
32+
return config.localTenant;
33+
}
1934
});
2035
}

web/src/pages/login.vue

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
<div class="mx-auto w-full max-w-sm lg:w-96 p-3 lg:backdrop-blur-md lg:rounded-3xl lg:shadow lg:bg-neutral-100 lg:bg-opacity-40">
55
<div class="">
66
<img alt="walt.id logo" class="h-24 lg:h-16 w-auto mx-auto mt-2" :src="logoImg" />
7-
<h2 class="mt-4 text-3xl font-bold tracking-tight text-gray-800">Sign in to your SSI wallet</h2>
7+
<h2 v-if="name?.includes('NEOM')" class="mt-4 text-3xl font-bold tracking-tight text-gray-800 text-center" style="direction: rtl;">تسجيل الدخول إلى محفظة SSI</h2> <!-- TODO: i18n system -->
8+
<h2 v-else class="mt-4 text-3xl font-bold tracking-tight text-gray-800">Sign in to your SSI wallet</h2>
89
<p class="mt-2 text-sm text-gray-600">
910
Or {{ " " }}
1011
<NuxtLink class="font-medium text-blue-600 hover:text-blue-500" to="/signup">sign up for your SSI wallet</NuxtLink>!

web/src/pages/signup.vue

+2-2
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ function validatePassword(): boolean {
219219
}
220220
221221
definePageMeta({
222-
title: "register to your wallet - walt.id",
222+
title: "Register for your wallet - walt.id",
223223
layout: "minimal",
224224
auth: {
225225
unauthenticatedOnly: true,
@@ -228,7 +228,7 @@ definePageMeta({
228228
});
229229
230230
useHead({
231-
title: "register to your wallet - walt.id",
231+
title: "Register for your wallet - walt.id",
232232
});
233233
</script>
234234

web/src/pages/wallet/[wallet]/exchange/presentation.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@
118118

119119
<Disclosure>
120120
<DisclosureButton class="py-2">
121-
<ButtonsWaltButton class="bg-gray-50 text-black">View presentation definition JSON</ButtonsWaltButton>
121+
<ButtonsWaltButton class="bg-gray-400 text-white">View presentation definition JSON</ButtonsWaltButton>
122122
</DisclosureButton>
123123
<DisclosurePanel class="text-gray-500 overflow-x-scroll pb-2">
124124
<pre>{{ presentationDefinition }}</pre>
File renamed without changes.

0 commit comments

Comments
 (0)