Skip to content

Commit

Permalink
Merge pull request #4645 from systeminit/victor/eng-2677-tos-updates
Browse files Browse the repository at this point in the history
fix: don't redirect to default workspace when tos needs updated
  • Loading branch information
vbustamante authored Sep 20, 2024
2 parents 4b4ba60 + 7b1ecc5 commit 024d4f4
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 9 deletions.
11 changes: 5 additions & 6 deletions app/auth-portal/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
<header class="flex p-md items-center">
<RouterLink
id="header-logo"
:to="{ name: 'home' }"
:to="{ name: 'workspaces' }"
class="mr-md shrink-0 relative"
>
<div id="header-logo-inner">
Expand Down Expand Up @@ -312,6 +312,10 @@ const hasCheckedOnboardingStatus = ref(false);
// could make sense to live in the router, but easier to interact with the auth loading state here
const router = useRouter();
const route = useRoute();
// onMounted for a component may run before this watch does,
// So a component may override these redirects if itself redirects navigation
// This can happen on DefaultWorkspacePage, for example
watch([checkAuthReq, route], () => {
// if we're still checking auth, do nothing
if (!checkAuthReq.value.isRequested || checkAuthReq.value.isPending) return;
Expand Down Expand Up @@ -346,33 +350,28 @@ watch([checkAuthReq, route], () => {
// Check that the user is not quarantined or suspended
if (user.value.quarantinedAt) {
if (!["quarantine-notice"].includes(currentRouteName)) {
saveLoginSuccessRedirect();
return router.push({ name: "quarantine-notice" });
}
return;
}
if (user.value.suspendedAt) {
if (!["suspension-notice"].includes(currentRouteName)) {
saveLoginSuccessRedirect();
return router.push({ name: "suspension-notice" });
}
return;
}
// If the user is not quarantined or suspended, do not allow them to go to the quarantine notice
if (currentRouteName === "quarantine-notice") {
saveLoginSuccessRedirect();
return router.push({ name: "workspaces" });
}
if (currentRouteName === "suspension-notice") {
saveLoginSuccessRedirect();
return router.push({ name: "workspaces" });
}
// check user has agreed to TOS
if (user.value.needsTosUpdate) {
if (currentRouteName !== "review-legal") {
saveLoginSuccessRedirect();
// eslint-disable-next-line @typescript-eslint/no-floating-promises
router.push({ name: "review-legal" });
}
Expand Down
12 changes: 10 additions & 2 deletions app/auth-portal/src/pages/DefaultWorkspacePage.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<template><div>Redirect to default workspace</div></template>

<script setup lang="ts">
<script lang="ts" setup>
import { computed, onMounted } from "vue";
import { useRouter } from "vue-router";
import { useWorkspacesStore } from "@/store/workspaces.store";
Expand All @@ -16,9 +16,17 @@ onMounted(async () => {
if (import.meta.env.SSR) return;
if (
!authStore.userIsLoggedIn ||
!authStore.user?.onboardingDetails?.reviewedProfile
!authStore.user ||
!authStore.user.onboardingDetails?.reviewedProfile
)
return;
if (authStore.user.needsTosUpdate) {
return router.push({
name: "review-legal",
});
}
// eslint-disable-next-line @typescript-eslint/no-floating-promises
await workspacesStore.LOAD_WORKSPACES();
if (defaultWorkspace.value) {
Expand Down
2 changes: 1 addition & 1 deletion app/auth-portal/src/pages/LoginPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
</RichText>
</template>

<script setup lang="ts">
<script lang="ts" setup>
import { onBeforeMount, onMounted } from "vue";
import { useRoute, useRouter } from "vue-router";
import { RichText } from "@si/vue-lib/design-system";
Expand Down
10 changes: 10 additions & 0 deletions bin/auth-api/src/routes/workspace.routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { validate } from "../lib/validation-helpers";
import { CustomRouteContext } from "../custom-state";
import { createSdfAuthToken } from "../services/auth.service";
import { tracker } from "../lib/tracker";
import { findLatestTosForUser } from "../services/tos.service";
import { extractAuthUser, router } from ".";

router.get("/workspaces", async (ctx) => {
Expand Down Expand Up @@ -355,6 +356,15 @@ router.get("/workspaces/:workspaceId/go", async (ctx) => {
}
}

const latestTos = await findLatestTosForUser(authUser);
if (latestTos > authUser.agreedTosVersion) {
throw new ApiError(
"Unauthorized",
"MissingTosAcceptance",
"Terms of Service have been updated, return to the SI auth portal to accept them.",
);
}

// generate a new single use authentication code that we will send to the instance
const connectCode = nanoid(24);
await setCache(
Expand Down

0 comments on commit 024d4f4

Please sign in to comment.