Skip to content

Commit

Permalink
Permissions
Browse files Browse the repository at this point in the history
  • Loading branch information
pontusab committed Jan 20, 2025
1 parent 95f9e93 commit bdd9fdf
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 14 deletions.
23 changes: 13 additions & 10 deletions apps/web/src/db/queries/permissions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ export async function validateJobPermissions({
}

return {
type: "organization",
org,
project,
};
}
Expand All @@ -47,26 +45,31 @@ export async function validateJobPermissions({
.where(eq(users.apiKey, apiKey))
.get();

console.log("user", user);

if (!user) {
throw new Error("Invalid user token");
}

// Check if user is a member of the organization and project
const member = await db
.select()
.from(members)
.innerJoin(organizations, eq(members.organizationId, organizations.id))
.innerJoin(projects, eq(projects.organizationId, organizations.id))
.where(and(eq(members.userId, user.id), eq(projects.id, projectId)))
.from(projects)
.leftJoin(
members,
and(
eq(members.organizationId, projects.organizationId),
eq(members.userId, user.id),
),
)
.where(eq(projects.id, projectId))
.get();

if (!member) {
if (!member?.projects) {
throw new Error("User does not have access to this project");
}

return {
type: "user",
user,
member,
project: member.projects,
};
}
6 changes: 3 additions & 3 deletions apps/web/src/jobs/translate/translate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ export const translateTask = schemaTask({
concurrencyLimit: 10,
},
run: async (payload) => {
const { org, project } = await validateJobPermissions({
const { project } = await validateJobPermissions({
projectId: payload.projectId,
apiKey: payload.apiKey,
});

if (!org) {
if (!project) {
throw new Error("Permission denied");
}

Expand Down Expand Up @@ -87,7 +87,7 @@ export const translateTask = schemaTask({

await createTranslation({
projectId: project.id,
organizationId: org.id,
organizationId: project.organizationId,
sourceFormat: payload.sourceFormat,
branch: payload.branch,
commit: payload.commit,
Expand Down
2 changes: 1 addition & 1 deletion examples/yaml/locales/es.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ nav:
home: Inicio
about: Acerca de
contact: Contáctanos
settings: Ajustes
settings: Configuración
user:
greeting: ¡Hola, {name}!
profile:
Expand Down

0 comments on commit bdd9fdf

Please sign in to comment.