Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Staging -> main #595

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 23 additions & 16 deletions backend/src/main/kotlin/no/bekk/Application.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package no.bekk

import io.ktor.client.*
import no.bekk.plugins.*
import io.ktor.server.application.*
import io.ktor.server.plugins.contentnegotiation.*
Expand All @@ -20,23 +21,29 @@ private fun loadAppConfig(config: ApplicationConfig) {
airTable = AirTableConfig.apply {
baseUrl = config.propertyOrNull("airTable.baseUrl")?.getString() ?: throw IllegalStateException("Unable to initialize app config \"airTable.baseUrl\"")
}
sikkerhetskontroller = AirTableInstanceConfig(
accessToken = config.propertyOrNull("airTable.sikkerhetskontroller.accessToken")?.getString() ?: throw IllegalStateException("Unable to initialize app config \"airTable.sikkerhetskontroller.accessToken\""),
baseId = config.propertyOrNull("airTable.sikkerhetskontroller.baseId")?.getString() ?: throw IllegalStateException("Unable to initialize app config \"airTable.sikkerhetskontroller.baseId\""),
tableId = config.propertyOrNull("airTable.sikkerhetskontroller.tableId")?.getString() ?: throw IllegalStateException("Unable to initialize app config \"airTable.sikkerhetskontroller.tableId\""),
viewId = config.propertyOrNull("airTable.sikkerhetskontroller.viewId")?.getString(),
webhookId = config.propertyOrNull("airTable.sikkerhetskontroller.webhookId")?.getString(),
webhookSecret = config.propertyOrNull("airTable.sikkerhetskontroller.webhookSecret")?.getString(),

)
driftskontinuitet = AirTableInstanceConfig(
accessToken = config.propertyOrNull("airTable.driftskontinuitet.accessToken")?.getString() ?: throw IllegalStateException("Unable to initialize app config \"airTable.driftskontinuitet.accessToken\""),
baseId = config.propertyOrNull("airTable.driftskontinuitet.baseId")?.getString() ?: throw IllegalStateException("Unable to initialize app config \"airTable.driftskontinuitet.baseId\""),
tableId = config.propertyOrNull("airTable.driftskontinuitet.tableId")?.getString() ?: throw IllegalStateException("Unable to initialize app config \"airTable.driftskontinuitet.tableId\""),
viewId = config.propertyOrNull("airTable.driftskontinuitet.viewId")?.getString(),
webhookId = config.propertyOrNull("airTable.driftskontinuitet.webhookId")?.getString(),
webhookSecret = config.propertyOrNull("airTable.driftskontinuitet.webhookSecret")?.getString(),
)
tables = config.configList("tables").map { table ->

when (table.propertyOrNull("type")?.getString()) {
"AIRTABLE" -> AirTableInstanceConfig(
id = table.propertyOrNull("id")?.getString() ?: throw IllegalStateException("Unable to initialize app config \"id\""),
accessToken = table.propertyOrNull("accessToken")?.getString() ?: throw IllegalStateException("Unable to initialize app config \"accessToken\""),
baseId = table.propertyOrNull("baseId")?.getString() ?: throw IllegalStateException("Unable to initialize app config \"baseId\""),
tableId = table.propertyOrNull("tableId")?.getString() ?: throw IllegalStateException("Unable to initialize app config \"tableId\""),
viewId = table.propertyOrNull("viewId")?.getString(),
webhookId = table.propertyOrNull("webhookId")?.getString(),
webhookSecret = table.propertyOrNull("webhookSecret")?.getString(),
)
"YAML" -> YAMLInstanceConfig(
id = table.propertyOrNull("id")?.getString() ?: throw IllegalStateException("Unable to initialize app config \"id\""),
endpoint = table.propertyOrNull("endpoint")?.getString() ?: throw IllegalStateException("Unable to initialize app config \"baseId\""),
resourcePath = table.propertyOrNull("resourcePath")?.getString() ?: throw IllegalStateException("Unable to initialize app config \"tableId\""),
)
else -> throw IllegalStateException("Illegal type \"type\"")

}

}
}

// MicrosoftGraph config
Expand Down
20 changes: 17 additions & 3 deletions backend/src/main/kotlin/no/bekk/configuration/AppConfig.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package no.bekk.configuration

import io.ktor.client.*

object AppConfig {
lateinit var tables: TableConfig
lateinit var microsoftGraph: MicrosoftGraphConfig
Expand All @@ -11,22 +13,34 @@ object AppConfig {

object TableConfig {
lateinit var airTable: AirTableConfig
lateinit var sikkerhetskontroller: AirTableInstanceConfig
lateinit var driftskontinuitet: AirTableInstanceConfig
lateinit var tables: List<TableInstance>
}

object AirTableConfig {
lateinit var baseUrl: String
}

interface TableInstance {
val id: String
}

data class AirTableInstanceConfig (
override val id: String,
val accessToken: String,
val baseId: String,
val tableId: String,
var viewId: String? = null,
var webhookId: String? = null,
var webhookSecret: String? = null,
)
) : TableInstance

data class YAMLInstanceConfig (
override val id: String,
val endpoint: String? = null,
val resourcePath: String? = null
) : TableInstance



object MicrosoftGraphConfig {
lateinit var baseUrl: String
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package no.bekk.database

import io.ktor.server.plugins.*
import no.bekk.configuration.Database
import java.util.*
import java.sql.SQLException
Expand Down Expand Up @@ -104,7 +105,7 @@ object ContextRepository {
name = result.getString("name")
)
} else {
throw RuntimeException("Error getting context")
throw NotFoundException("Context with id $id not found")
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion backend/src/main/kotlin/no/bekk/routes/ContextRouting.kt
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ fun Route.contextRouting() {
val contextId = call.parameters["contextId"] ?: throw BadRequestException("Missing contextId")

if (!hasContextAccess(call, contextId)) {
call.respond(HttpStatusCode.Forbidden)
call.respond(HttpStatusCode.Unauthorized)
return@get
}
val context = ContextRepository.getContext(contextId)
Expand Down
63 changes: 28 additions & 35 deletions backend/src/main/kotlin/no/bekk/services/TableService.kt
Original file line number Diff line number Diff line change
@@ -1,46 +1,39 @@
package no.bekk.services

import io.ktor.client.*
import no.bekk.configuration.AirTableInstanceConfig
import no.bekk.configuration.AppConfig
import no.bekk.configuration.YAMLInstanceConfig
import no.bekk.providers.AirTableProvider
import no.bekk.providers.TableProvider
import no.bekk.providers.YamlProvider
import no.bekk.providers.clients.AirTableClient

object TableService {
private val providers: List<TableProvider> = listOf<TableProvider>(
AirTableProvider(
id = "570e9285-3228-4396-b82b-e9752e23cd73",
airtableClient = AirTableClient(
AppConfig.tables.sikkerhetskontroller.accessToken
),
baseId = AppConfig.tables.sikkerhetskontroller.baseId,
tableId = AppConfig.tables.sikkerhetskontroller.tableId,
viewId = AppConfig.tables.sikkerhetskontroller.viewId,
webhookId = AppConfig.tables.sikkerhetskontroller.webhookId,
webhookSecret = AppConfig.tables.sikkerhetskontroller.webhookSecret,
),
AirTableProvider(
id = "816cc808-9188-44a9-8f4b-5642fc2932c4",
airtableClient = AirTableClient(
AppConfig.tables.driftskontinuitet.accessToken
),
baseId = AppConfig.tables.driftskontinuitet.baseId,
tableId = AppConfig.tables.driftskontinuitet.tableId,
viewId = AppConfig.tables.driftskontinuitet.viewId,
webhookId = AppConfig.tables.driftskontinuitet.webhookId,
webhookSecret = AppConfig.tables.driftskontinuitet.webhookSecret,
),
// AirTableProvider(
// id = "test-table",
// airtableClient = AirTableClient(
// System.getenv("AIRTABLE_TEST_TOKEN")
// ),
// baseId = "appJFzRzW8GmaKuz3",
// tableId = "tblbiZLh6qn3k7wdt",
// viewId = "",
// webhookId = "achpY1AcPW93B9ucr",
// webhookSecret = System.getenv("AIRTABLE_WEBHOOK_SECRET")
// ),
)


private val providers: List<TableProvider> = AppConfig.tables.tables.map { table ->
when (table) {
is AirTableInstanceConfig -> AirTableProvider(
id = table.id,
airtableClient = AirTableClient(
table.accessToken
),
baseId = table.baseId,
tableId = table.tableId,
viewId = table.viewId,
webhookId = table.webhookId,
webhookSecret = table.webhookSecret,
)
is YAMLInstanceConfig -> YamlProvider(
id = table.id,
endpoint = table.endpoint,
resourcePath = table.resourcePath,
)
else -> throw Exception("Valid tabletype not found")

}
}


fun getTableProvider(tableId: String): TableProvider {
Expand Down
17 changes: 17 additions & 0 deletions backend/src/main/resources/application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,23 @@ airTable:
webhookId: "$DRIFTSKONTINUITET_WEBHOOK_ID:"
webhookSecret: "$DRIFTSKONTINUITET_WEBHOOK_SECRET:"

tables:
- id: "570e9285-3228-4396-b82b-e9752e23cd73"
type : "AIRTABLE"
accessToken: $AIRTABLE_ACCESS_TOKEN
baseId: "appzJQ8Tkmm8DobrJ"
tableId: "tblLZbUqA0XnUgC2v"
viewId: "viw2XliGUJu5448Hk"
webhookId: "$SIKKERHETSKONTROLLER_WEBHOOK_ID:"
webhookSecret: "$SIKKERHETSKONTROLLER_WEBHOOK_SECRET:"
- id: "816cc808-9188-44a9-8f4b-5642fc2932c4"
type: "AIRTABLE"
accessToken: $AIRTABLE_ACCESS_TOKEN
baseId: "appsIiBWlCCSsMmRB"
tableId: "tbl4pNqNp2wLyI6iv"
webhookId: "$DRIFTSKONTINUITET_WEBHOOK_ID:"
webhookSecret: "$DRIFTSKONTINUITET_WEBHOOK_SECRET:"

microsoftGraph:
baseUrl: "https://graph.microsoft.com"
memberOfPath: "/v1.0/me/memberOf/microsoft.graph.group"
Expand Down
2 changes: 1 addition & 1 deletion frontend/beCompliant/src/components/Table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ export function TableComponent({
<Tooltip label="Se mer">
<IconButton
aria-label="se mer"
icon="open_in_full"
icon="info"
size="md"
variant="ghost"
onClick={() => navigate(`${row.original.recordId}`)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ type Props = {
choices?: string[] | null;
isActivityPageView?: boolean;
answerExpiry: number | null;
disabled?: boolean;
};

export function CheckboxAnswer({
Expand All @@ -19,6 +20,7 @@ export function CheckboxAnswer({
choices,
isActivityPageView = false,
answerExpiry,
disabled,
}: Props) {
const handleOnChange = (e: React.ChangeEvent<HTMLInputElement>) => {
const newValue = e.target.checked
Expand All @@ -35,6 +37,8 @@ export function CheckboxAnswer({
isChecked={value === (choices?.[0] ?? 'checked')}
onChange={handleOnChange}
size="md"
disabled={disabled}
isDisabled={disabled}
>
{choices?.length === 2 && value
? value === (choices?.[0] ?? 'checked')
Expand Down
3 changes: 3 additions & 0 deletions frontend/beCompliant/src/components/answers/PercentAnswer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ type Props = {
submitAnswer: (newAnswer: string) => void;
isActivityPageView?: boolean;
answerExpiry: number | null;
disabled?: boolean;
};

export function PercentAnswer({
Expand All @@ -24,6 +25,7 @@ export function PercentAnswer({
submitAnswer,
isActivityPageView = false,
answerExpiry,
disabled,
}: Props) {
const initialValue = useRef(value).current;

Expand Down Expand Up @@ -55,6 +57,7 @@ export function PercentAnswer({
submitAnswer(value ?? '');
}
}}
disabled={disabled}
/>
</NumberInput>
<InputRightAddon
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ type Props = {
setAnswerInput: React.Dispatch<React.SetStateAction<string | undefined>>;
submitAnswer: (newAnswer: string) => void;
answerExpiry: number | null;
disabled?: boolean;
};

export function SingleSelectAnswer({
Expand All @@ -21,6 +22,7 @@ export function SingleSelectAnswer({
setAnswerInput,
submitAnswer,
answerExpiry,
disabled,
}: Props) {
const handleSelectionAnswer = (e: React.ChangeEvent<HTMLSelectElement>) => {
const newAnswer: string = e.target.value;
Expand Down Expand Up @@ -48,6 +50,8 @@ export function SingleSelectAnswer({
width="100%"
background={selectedAnswerBackgroundColor}
marginBottom={updated ? '0' : '6'}
disabled={disabled}
isDisabled={disabled}
>
{choices.map((choice) => (
<option value={choice} key={choice}>
Expand Down
11 changes: 10 additions & 1 deletion frontend/beCompliant/src/components/answers/TextAnswer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ type Props = {
setAnswerInput: React.Dispatch<React.SetStateAction<string | undefined>>;
submitAnswer: (newAnswer: string) => void;
answerExpiry: number | null;
disabled?: boolean;
};

export function TextAnswer({
Expand All @@ -18,6 +19,7 @@ export function TextAnswer({
setAnswerInput,
submitAnswer,
answerExpiry,
disabled,
}: Props) {
const initialValue = useRef(value).current;

Expand All @@ -41,9 +43,16 @@ export function TextAnswer({
submitAnswer(value ?? '');
}
}}
disabled={disabled}
/>
) : (
<Input value={value} onChange={handleTextAnswer} background="white" />
<Input
value={value}
onChange={handleTextAnswer}
background="white"
disabled={disabled}
isDisabled={disabled}
/>
)}
</Stack>
<LastUpdated
Expand Down
5 changes: 5 additions & 0 deletions frontend/beCompliant/src/components/answers/TimeAnswer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ type Props = {
submitAnswer: (newAnswer: string, unit?: string) => void;
isActivityPageView?: boolean;
answerExpiry: number | null;
disabled?: boolean;
};

export function TimeAnswer({
Expand All @@ -31,6 +32,7 @@ export function TimeAnswer({
submitAnswer,
isActivityPageView = false,
answerExpiry,
disabled,
}: Props) {
const initialValue = useRef(value).current;
const initialUnit = useRef(unit).current;
Expand Down Expand Up @@ -70,6 +72,7 @@ export function TimeAnswer({
submitAnswer(value ?? '', unit);
}
}}
disabled={disabled}
/>
<InputRightElement width="4.5rem">
<Select
Expand All @@ -79,6 +82,8 @@ export function TimeAnswer({
onChange={handleTimeAnswerUnit}
size="sm"
borderRightRadius="md"
disabled={disabled}
isDisabled={disabled}
>
{units?.map((u) => (
<option value={u} key={u}>
Expand Down
Loading
Loading