Skip to content

Commit

Permalink
merge: #2932
Browse files Browse the repository at this point in the history
2932: feat(auth-api, auth-portal): Show the owner of the workspace when you are an editor r=stack72 a=stack72

Also, show when you were invited to a workspace. Any existing invitations will be set to the date we run this migration as we don’t have a backward set of data on this

<img width="1225" alt="Screenshot 2023-11-03 at 18 28 23" src="https://github.com/systeminit/si/assets/227823/90c0f3b8-88a5-4bcf-bb0e-305c13a92733">



Co-authored-by: stack72 <[email protected]>
  • Loading branch information
si-bors-ng[bot] and stack72 authored Nov 3, 2023
2 parents 3a0e95d + 655374e commit fe1bd2b
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 1 deletion.
12 changes: 11 additions & 1 deletion app/auth-portal/src/components/WorkspaceLinkWidget.vue
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,16 @@
<div class="text-sm opacity-70 capsize">
<div class="truncate w-full">{{ workspace.instanceUrl }}</div>
</div>
<div
v-if="workspace.role !== 'OWNER'"
class="font-bold text-sm capsize"
>
Owner: {{ workspace.creatorUser.firstName }}
{{ workspace.creatorUser.lastName }}
</div>
<div v-if="workspace.role !== 'OWNER'" class="text-xs">
Invited: {{ formatters.timeAgo(workspace.invitedAt) }}
</div>
<div class="font-bold">Role: {{ toSentenceCase(workspace.role) }}</div>
<div class="flex items-center text-xs gap-md pt-xs">
<div class="flex items-center gap-xs">
Expand Down Expand Up @@ -126,7 +136,7 @@

<script setup lang="ts">
import { computed, PropType, ref } from "vue";
import { formatters } from "@si/vue-lib";
import { Icon, Stack } from "@si/vue-lib/design-system";
import clsx from "clsx";
import { useWorkspacesStore, WorkspaceId } from "@/store/workspaces.store";
Expand Down
5 changes: 5 additions & 0 deletions app/auth-portal/src/store/workspaces.store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,13 @@ export type Workspace = {
displayName: string;
slug: string;
createdByUserId: UserId;
creatorUser: {
firstName?: string;
lastName?: string;
};
createdAt: ISODateString;
role: string;
invitedAt: Date;
};

export type WorkspaceMember = {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
-- AlterTable
ALTER TABLE "WorkspaceMembers" ADD COLUMN "invited_at" TIMESTAMP(3);

-- Backfill the existing rows in the database
UPDATE "WorkspaceMembers"
SET "invited_at" = NOW() where "invited_at" IS NULL;
3 changes: 3 additions & 0 deletions bin/auth-api/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ model WorkspaceMembers {
// Role of the user
roleType RoleType @map("role_type")
// Invitation to workspace date
invitedAt DateTime? @map("invited_at")
@@unique([userId, workspaceId])
}

Expand Down
10 changes: 10 additions & 0 deletions bin/auth-api/src/services/workspaces.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export async function createWorkspace(creatorUser: User, instanceUrl = 'http://l
workspaceId: newWorkspace.id,
userId: creatorUser.id,
roleType: RoleType.OWNER,
invitedAt: new Date(),
},
});

Expand All @@ -71,17 +72,25 @@ export async function getUserWorkspaces(userId: UserId) {
UserMemberships: {
select: {
roleType: true,
invitedAt: true,
},
where: {
userId,
},
},
creatorUser: {
select: {
firstName: true,
lastName: true,
},
},
},
});

return _.map(workspaces, (w) => ({
..._.omit(w, "UserMemberships"),
role: w.UserMemberships[0].roleType,
invitedAt: w.UserMemberships[0].invitedAt,
}));
}

Expand Down Expand Up @@ -121,6 +130,7 @@ export async function inviteMember(email: string, id: WorkspaceId) {
workspaceId: id,
userId: user.id,
roleType: RoleType.EDITOR,
invitedAt: new Date(),
},
});
}
Expand Down

0 comments on commit fe1bd2b

Please sign in to comment.