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

fix(frontend): temporary guest link #2730

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
Open
1 change: 1 addition & 0 deletions backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@
"#graphql/*": "./src/graphql/*",
"#inputs/*": "./src/graphql/inputs/*",
"#models/*": "./src/graphql/models/*",
"#resolvers/*": "./src/graphql/resolvers/*",
"#src/*": "./src/*",
"#test/*": "./test/*",
"#types/*": "./src/graphql/types/*"
Expand Down
9 changes: 6 additions & 3 deletions backend/src/graphql/models/TableModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,22 @@ export const getAttendees = (meeting: MeetingInfo): Attendee[] => {

@ObjectType()
export class Table {
constructor(data: Pick<Table, 'id' | 'name' | 'public' | 'users'>) {
constructor(data: Pick<Table, 'id' | 'meetingID' | 'name' | 'public' | 'users'>) {
Object.assign(this, data)
}

static fromMeeting(meeting: Meeting, usersWithMeetings: UsersWithMeetings[]) {
const { id, name } = meeting
const { id, meetingID, name } = meeting
const users = usersWithMeetings.map((u) => new UserInMeeting(u))
return new Table({ id, name, public: meeting.public, users })
return new Table({ id, meetingID, name, public: meeting.public, users })
}

@Field(() => Int)
id: number

@Field(() => String)
meetingID: string

@Field()
name: string

Expand Down
18 changes: 8 additions & 10 deletions backend/src/graphql/resolvers/TableResolver.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ describe('TableResolver', () => {

describe('joinTableAsGuest', () => {
const query = `
query ($tableId: Int!, $userName: String!) {
query ($tableId: String!, $userName: String!) {
joinTableAsGuest(tableId: $tableId, userName: $userName)
}
`
Expand All @@ -349,7 +349,7 @@ describe('TableResolver', () => {
query,
variables: {
userName: 'Pinky Pie',
tableId: 25,
tableId: '25',
},
},
{ contextValue: mockContextValue() },
Expand Down Expand Up @@ -390,7 +390,7 @@ describe('TableResolver', () => {
query,
variables: {
userName: 'Pinky Pie',
tableId,
tableId: 'Pony Ville',
},
},
{ contextValue: mockContextValue() },
Expand Down Expand Up @@ -429,7 +429,7 @@ describe('TableResolver', () => {

describe('getTableName', () => {
const query = `
query ($tableId: Int!) {
query ($tableId: String!) {
getTableName(tableId: $tableId)
}
`
Expand All @@ -440,7 +440,7 @@ describe('TableResolver', () => {
{
query,
variables: {
tableId: 25,
tableId: '25',
},
},
{ contextValue: mockContextValue() },
Expand All @@ -458,15 +458,13 @@ describe('TableResolver', () => {
})

describe('table in DB', () => {
let tableId: number
beforeEach(async () => {
const meeting = await prisma.meeting.create({
await prisma.meeting.create({
data: {
name: 'Club of Rome',
meetingID: 'Club of Rome',
meetingID: 'club-of-rome',
},
})
tableId = meeting.id
})

afterEach(async () => {
Expand All @@ -479,7 +477,7 @@ describe('TableResolver', () => {
{
query,
variables: {
tableId,
tableId: 'club-of-rome',
},
},
{ contextValue: mockContextValue() },
Expand Down
16 changes: 8 additions & 8 deletions backend/src/graphql/resolvers/TableResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ export class TableResolver {

if (!dbMeeting) throw new Error('Meeting not found!')

const inviteLink = createInviteLink(dbMeeting.id)
const inviteLink = createInviteLink(dbMeeting.meetingID)

await createBBBMeeting(prisma)({
meetingID: dbMeeting.meetingID,
Expand Down Expand Up @@ -307,7 +307,7 @@ export class TableResolver {
(table.user && table.user.id === user.id) ||
table.users.some((e) => e.userId === user.id && e.role === 'MODERATOR')
) {
const inviteLink = createInviteLink(table.id)
const inviteLink = createInviteLink(table.meetingID)
const meeting = await createBBBMeeting(prisma)({
meetingID: table.meetingID,
name: table.name,
Expand Down Expand Up @@ -345,15 +345,15 @@ export class TableResolver {
@Query(() => String)
async joinTableAsGuest(
@Arg('userName') userName: string,
@Arg('tableId', () => Int) tableId: number,
@Arg('tableId', () => String) tableId: string,
@Ctx() context: AuthenticatedContext,
): Promise<string> {
const {
dataSources: { prisma },
} = context
const meeting = await prisma.meeting.findUnique({
where: {
id: tableId,
meetingID: tableId,
},
include: {
user: true,
Expand All @@ -370,15 +370,15 @@ export class TableResolver {

@Query(() => String)
async getTableName(
@Arg('tableId', () => Int) tableId: number,
@Arg('tableId', () => String) tableId: string,
@Ctx() context: AuthenticatedContext,
): Promise<string> {
const {
dataSources: { prisma },
} = context
const meeting = await prisma.meeting.findUnique({
where: {
id: tableId,
meetingID: tableId,
},
})
if (!meeting) throw new Error('Table does not exist')
Expand Down Expand Up @@ -643,7 +643,7 @@ const findUsersInMeetings =
})) as UsersWithMeetings[]
}

const createMeetingID = (prisma: PrismaClient) => async (): Promise<string> => {
export const createMeetingID = (prisma: PrismaClient) => async (): Promise<string> => {
let meetingID: string = uuidv4()
while (
await prisma.meeting.count({
Expand All @@ -657,7 +657,7 @@ const createMeetingID = (prisma: PrismaClient) => async (): Promise<string> => {
return meetingID
}

function createInviteLink(tableId: number) {
const createInviteLink = (tableId: string): string => {
return new URL(`join-table/${tableId}`, CONFIG.FRONTEND_URL).toString()
}

Expand Down
9 changes: 6 additions & 3 deletions backend/src/graphql/resolvers/dal/handleOpenTables.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,8 @@ describe('handleOpenTables', () => {
}),
expect.objectContaining({
name: 'Meeting 2',
meetingID: 'Meeting-2',
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
meetingID: expect.any(String),
createTime: null,
}),
]),
Expand All @@ -175,12 +176,14 @@ describe('handleOpenTables', () => {
expect.arrayContaining([
expect.objectContaining({
name: 'Meeting 1',
meetingID: 'Meeting-1',
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
meetingID: expect.any(String),
createTime: null,
}),
expect.objectContaining({
name: 'Meeting 2',
meetingID: 'Meeting-2',
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
meetingID: expect.any(String),
createTime: null,
}),
]),
Expand Down
2 changes: 2 additions & 0 deletions backend/src/graphql/resolvers/dal/handleOpenTables.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { getMeetings, MeetingInfo } from '#api/BBB'
import { createMeetingID } from '#resolvers/TableResolver'
import { pubSub } from '#src/graphql/pubSub'
import { prisma } from '#src/prisma'

Expand All @@ -15,6 +16,7 @@ export const handleOpenTables = async (): Promise<void> => {
},
},
data: {
meetingID: await createMeetingID(prisma)(),
attendeePW: null,
moderatorPW: null,
voiceBridge: null,
Expand Down
1 change: 1 addition & 0 deletions backend/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"#graphql/*": ["./src/graphql/*"],
"#inputs/*": ["./src/graphql/inputs/*"],
"#models/*": ["./src/graphql/models/*"],
"#resolvers/*": ["./src/graphql/resolvers/*"],
"#src/*": ["./src/*"],
"#test/*": ["./test/*"],
"#types/*": ["./src/graphql/types/*"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,11 @@ export type CreateTableModel = {
name: string
userIds: number[]
tableId?: number
meetingID?: string
}

const createTableModel = reactive<CreateTableModel>({
meetingID: '',
isPrivate: false,
name: '',
userIds: [],
Expand Down Expand Up @@ -76,6 +78,7 @@ const onSubmit = async () => {
}

createTableModel.tableId = table.id
createTableModel.meetingID = table.meetingID

stepControl.value?.next()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,13 @@ const pageContext = usePageContext()
const { META } = pageContext.publicEnv

const createTableModel = defineModel<CreateTableModel>({ required: true })
const meetingID = createTableModel.value.meetingID
const tableId = createTableModel.value.tableId

if (!meetingID) throw new Error('Meeting ID is required')
if (!tableId) throw new Error('Table ID is required')

const tableUrl = tablesStore.getJoinTableUrl(tableId, META.BASE_URL)
const tableUrl = tablesStore.getJoinTableUrl(meetingID, META.BASE_URL)

const props = defineProps<StepProps>()
const emit = defineEmits<StepEmits>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ export default interface MyTableSettings {
isPrivate: boolean
users: number[]
tableId?: number
meetingID?: string
}
2 changes: 2 additions & 0 deletions frontend/src/components/malltalk/settings/TableSettings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,14 @@ const tableSettings = reactive<MyTableSettings>({
name: myTable.value?.name || '',
isPrivate: !myTable.value?.public || false,
users: myTable.value?.users.map((u) => u.id) || [],
meetingID: myTable.value?.meetingID || '',
})

watch(myTable, (value) => {
tableSettings.name = value?.name || ''
tableSettings.isPrivate = !value?.public || false
tableSettings.users = value?.users.map((u) => u.id) || []
tableSettings.meetingID = value?.meetingID || ''
})

const steps: Step[] = [
Expand Down
21 changes: 18 additions & 3 deletions frontend/src/components/malltalk/settings/TableSettingsRoot.vue
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
</template>

<script setup lang="ts">
import { storeToRefs } from 'pinia'
import { navigate } from 'vike/client/router'
import { computed, ref, inject } from 'vue'
import { useI18n } from 'vue-i18n'
Expand Down Expand Up @@ -57,14 +58,28 @@ const pageContext = usePageContext()
const { META } = pageContext.publicEnv

const tableId = computed(() => {
return pageContext.routeParams?.id ? Number(pageContext.routeParams.id) : null
return pageContext.routeParams?.id ? pageContext.routeParams.id : ''
})

const tablesStore = useTablesStore()
const isModeratorData = inject<IsModeratorInjection>(IsModeratorSymbol, {
isModerator: ref(false),
})

const { getTables } = storeToRefs(tablesStore)
mahula marked this conversation as resolved.
Show resolved Hide resolved

const allTables = computed(() => {
const { mallTalkTables, permanentTables, projectTables } = getTables.value
return [...mallTalkTables, ...permanentTables, ...projectTables]
})

const meetingID = computed(() => {
if (!(tableId.value && allTables.value?.length)) return ''
const currentTable = allTables.value.find((t) => t.id.toString() === tableId.value.toString())
if (currentTable) return currentTable.meetingID
return ''
})

const copiedIndicator = ref(false)
let timerIndicator: ReturnType<typeof setTimeout> | null = null

Expand All @@ -74,8 +89,8 @@ const buttons = computed(() => [
text: t('dream-mall-panel.call.link'),
indicator: copiedIndicator.value,
action: () => {
if (tableId.value) {
copy(tablesStore.getJoinTableUrl(tableId.value, META.BASE_URL), t('copiedToClipboard'))
if (meetingID.value) {
copy(tablesStore.getJoinTableUrl(meetingID.value, META.BASE_URL), t('copiedToClipboard'))
copiedIndicator.value = true

if (timerIndicator) clearTimeout(timerIndicator)
Expand Down
6 changes: 5 additions & 1 deletion frontend/src/components/malltalk/setup/SubmitTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,12 @@ const pageContext = usePageContext()
const { META } = pageContext.publicEnv

const tableSettings = defineModel<MyTableSettings>({ required: true })

const tableId = tableSettings.value.tableId ?? 0
const tableUrl = tablesStore.getJoinTableUrl(tableId, META.BASE_URL)

const meetingID = tableSettings.value.meetingID ?? ''

const tableUrl = tablesStore.getJoinTableUrl(meetingID, META.BASE_URL)

const navigateToTable = async () => {
if (!tableId) return
Expand Down
4 changes: 4 additions & 0 deletions frontend/src/components/malltalk/setup/TableSetup.vue
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ const { defaultMyTableName } = storeToRefs(tablesStore)

const resetTableSettings = () => {
tableSettings.tableId = 0
tableSettings.meetingID = ''
tableSettings.name = defaultMyTableName.value
tableSettings.isPrivate = false
tableSettings.users = []
Expand All @@ -41,6 +42,7 @@ const tableSettings = reactive<MyTableSettings>({
isPrivate: false,
users: [],
tableId: 0,
meetingID: '',
})
resetTableSettings()

Expand Down Expand Up @@ -102,6 +104,8 @@ const onSubmit = async () => {
throw new Error(t('table.error'))
}

tableSettings.meetingID = table.meetingID

tableSettings.tableId = await tablesStore.joinMyTable()
if (!tableSettings.tableId) {
throw new Error(t('table.error'))
Expand Down
1 change: 1 addition & 0 deletions frontend/src/graphql/mutations/createMyTableMutation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export const createMyTableMutation = gql`
mutation ($name: String!, $isPublic: Boolean!, $userIds: [Int]) {
createMyTable(name: $name, isPublic: $isPublic, userIds: $userIds) {
id
meetingID
name
public
users {
Expand Down
1 change: 1 addition & 0 deletions frontend/src/graphql/mutations/createTableMutation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export const createTableMutation =
gql(`mutation CreateTable($isPublic: Boolean!, $name: String!, $userIds: [Int]) {
createTable(isPublic: $isPublic, name: $name, userIds: $userIds) {
id
meetingID
name
public
users {
Expand Down
1 change: 1 addition & 0 deletions frontend/src/graphql/mutations/updateMyTableMutation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export const updateMyTableMutation = gql`
mutation ($name: String!, $isPublic: Boolean!, $userIds: [Int]) {
updateMyTable(name: $name, isPublic: $isPublic, userIds: $userIds) {
id
meetingID
name
public
users {
Expand Down
Loading
Loading