mirror of
https://github.com/Litlyx/litlyx
synced 2025-12-10 07:48:37 +01:00
fix guest actions
This commit is contained in:
@@ -16,11 +16,17 @@ export function useGuestProjectsList() {
|
||||
return { ...guestProjects, guestProjects: guestProjects.data }
|
||||
}
|
||||
|
||||
|
||||
const activeProjectId = useFetch<string>(`/api/user/active_project`, {
|
||||
key: 'activeProjectId', ...signHeaders(),
|
||||
});
|
||||
|
||||
export const isGuest = computed(() => {
|
||||
if (!guestProjects.data.value) return false;
|
||||
const guestTarget = guestProjects.data.value.find(e => e._id.toString() == activeProjectId.data.value);
|
||||
if (guestTarget) return true;
|
||||
return false;
|
||||
});
|
||||
|
||||
export function useActiveProjectId() {
|
||||
return { ...activeProjectId, pid: activeProjectId.data }
|
||||
}
|
||||
|
||||
@@ -130,10 +130,13 @@ async function deleteChat(chat_id: string) {
|
||||
<div class="w-[10rem]">
|
||||
<img :src="'analyst.png'" class="w-full h-full">
|
||||
</div>
|
||||
<div class="poppins text-[1.2rem]">
|
||||
<div v-if="!isGuest" class="poppins text-[1.2rem]">
|
||||
How can i help you today?
|
||||
</div>
|
||||
<div class="grid grid-cols-2 gap-4 mt-6">
|
||||
<div v-if="isGuest" class="poppins text-[1.2rem]">
|
||||
Im not allowed to help guests :c
|
||||
</div>
|
||||
<div class="grid grid-cols-2 gap-4 mt-6" v-if="!isGuest">
|
||||
<div v-for="prompt of defaultPrompts" @click="currentText = prompt"
|
||||
class="bg-[#2f2f2f] hover:bg-[#424242] cursor-pointer p-4 rounded-lg poppins text-center">
|
||||
{{ prompt }}
|
||||
@@ -172,7 +175,7 @@ async function deleteChat(chat_id: string) {
|
||||
|
||||
|
||||
|
||||
<div class="flex gap-2 items-center absolute bottom-8 left-0 w-full px-10 xl:px-28">
|
||||
<div v-if="!isGuest" class="flex gap-2 items-center absolute bottom-8 left-0 w-full px-10 xl:px-28">
|
||||
<input @keydown="onKeyDown" v-model="currentText"
|
||||
class="bg-[#303030] w-full focus:outline-none px-4 py-2 rounded-lg" type="text">
|
||||
<div @click="sendMessage()"
|
||||
|
||||
@@ -55,7 +55,7 @@ async function addMember() {
|
||||
|
||||
<div class="flex flex-col gap-4">
|
||||
|
||||
<div @click="showAddMember = !showAddMember;"
|
||||
<div v-if="!isGuest" @click="showAddMember = !showAddMember;"
|
||||
class="flex items-center gap-2 bg-menu w-fit px-3 py-2 rounded-lg hover:bg-menu/80 cursor-pointer">
|
||||
<i class="fas fa-plus"></i>
|
||||
<div> Add member </div>
|
||||
|
||||
@@ -130,7 +130,7 @@ function getPremiumName(type: number) {
|
||||
<div class="poppins"> Expire date:</div>
|
||||
<div> {{ prettyExpireDate }}</div>
|
||||
</div>
|
||||
<div @click="onPlanUpgradeClick()"
|
||||
<div v-if="!isGuest" @click="onPlanUpgradeClick()"
|
||||
class="cursor-pointer flex items-center gap-2 text-[.9rem] text-white font-semibold bg-accent px-4 py-1 rounded-lg drop-shadow-[0_0_8px_#000000]">
|
||||
<div class="poppins"> Upgrade plan </div>
|
||||
<i class="fas fa-arrow-up-right"></i>
|
||||
@@ -168,7 +168,7 @@ function getPremiumName(type: number) {
|
||||
</div>
|
||||
|
||||
|
||||
<CardTitled title="Invoices" :sub="(invoices && invoices.length == 0) ? 'No invoices yet' : ''"
|
||||
<CardTitled v-if="!isGuest" title="Invoices" :sub="(invoices && invoices.length == 0) ? 'No invoices yet' : ''"
|
||||
class="p-4 mt-8 max-w-[72rem]">
|
||||
|
||||
<div class="flex flex-col gap-2">
|
||||
|
||||
@@ -3,7 +3,7 @@ import { ProjectModel } from "~/../shared/schema/ProjectSchema";
|
||||
import { LITLYX_PROJECT_ID } from '@data/LITLYX'
|
||||
import { hasAccessToProject } from "./utils/hasAccessToProject";
|
||||
|
||||
export async function getUserProjectFromId(project_id: string, user: AuthContext | undefined) {
|
||||
export async function getUserProjectFromId(project_id: string, user: AuthContext | undefined, allowGuest: boolean = true) {
|
||||
if (project_id == LITLYX_PROJECT_ID) {
|
||||
const project = await ProjectModel.findOne({ _id: project_id });
|
||||
return project;
|
||||
@@ -11,8 +11,9 @@ export async function getUserProjectFromId(project_id: string, user: AuthContext
|
||||
if (!user?.logged) return;
|
||||
const project = await ProjectModel.findById(project_id);
|
||||
if (!project) return;
|
||||
const hasAccess = await hasAccessToProject(user.id, project_id, project);
|
||||
const [hasAccess, role] = await hasAccessToProject(user.id, project_id, project);
|
||||
if (!hasAccess) return;
|
||||
if (role === 'GUEST' && !allowGuest) return false;
|
||||
return project;
|
||||
}
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ export default defineEventHandler(async event => {
|
||||
if (!project_id) return;
|
||||
|
||||
const user = getRequestUser(event);
|
||||
const project = await getUserProjectFromId(project_id, user);
|
||||
const project = await getUserProjectFromId(project_id, user, false);
|
||||
if (!project) return;
|
||||
|
||||
// if (!user?.logged) return;
|
||||
|
||||
@@ -8,8 +8,12 @@ export default defineEventHandler(async event => {
|
||||
if (!user?.logged) return;
|
||||
const project_id = getRequestProjectId(event);
|
||||
if (!project_id) return;
|
||||
const project = await ProjectModel.findOne({ _id: project_id, owner: user.id });
|
||||
const project = await ProjectModel.findOne({ _id: project_id });
|
||||
if (!project) return;
|
||||
|
||||
const [hasAccess] = await hasAccessToProject(user.id, project_id, project)
|
||||
if (!hasAccess) return;
|
||||
|
||||
const query = getQuery(event);
|
||||
|
||||
const { orderBy, order, page, limit, type } = query;
|
||||
|
||||
@@ -17,7 +17,7 @@ export default defineEventHandler(async event => {
|
||||
if (!project_id) return;
|
||||
|
||||
const user = getRequestUser(event);
|
||||
const project = await getUserProjectFromId(project_id, user);
|
||||
const project = await getUserProjectFromId(project_id, user, false);
|
||||
if (!project) return;
|
||||
|
||||
if (!project.customer_id) return [];
|
||||
|
||||
@@ -13,7 +13,7 @@ export default defineEventHandler(async event => {
|
||||
|
||||
const { project_id } = getQuery(event);
|
||||
|
||||
const hasAccess = await hasAccessToProject(userData.id, project_id as string);
|
||||
const [hasAccess] = await hasAccessToProject(userData.id, project_id as string);
|
||||
|
||||
if (!hasAccess) return setResponseStatus(event, 400, 'No access to project');
|
||||
|
||||
|
||||
Reference in New Issue
Block a user