Fix very faulty authorization
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
import { AttachmentId, PieceId, RepertoireId, Sha256 } from "common";
|
import { AttachmentId, PieceId, RepertoireId, Sha256 } from "common";
|
||||||
import api, { NotFound, Role, Unauthorized } from "common/the_api";
|
import api, { NotFound, Role, Unauthorized } from "common/the_api";
|
||||||
import { DateTime, Effect, HashSet, Option, pipe } from "effect";
|
import { DateTime, Effect, HashSet, Number, Option, pipe } from "effect";
|
||||||
import { sql } from "kysely";
|
import { sql } from "kysely";
|
||||||
import { implement } from "./api";
|
import { implement } from "./api";
|
||||||
import * as Authentication from "./services/Authentication";
|
import * as Authentication from "./services/Authentication";
|
||||||
@@ -17,7 +17,11 @@ const requireAuthenticated = pipe(
|
|||||||
const requireReadAccess = pipe(
|
const requireReadAccess = pipe(
|
||||||
Authentication.Authentication,
|
Authentication.Authentication,
|
||||||
Effect.flatMap(({ me }) => me),
|
Effect.flatMap(({ me }) => me),
|
||||||
Effect.flatMap((user) => HashSet.isSubset(user.roles, READ_ACCESS)
|
Effect.flatMap((user) => pipe(
|
||||||
|
HashSet.intersection(user.roles, READ_ACCESS),
|
||||||
|
HashSet.size,
|
||||||
|
Number.greaterThan(0),
|
||||||
|
)
|
||||||
? Effect.succeed(user)
|
? Effect.succeed(user)
|
||||||
: Effect.fail(Unauthorized.make())
|
: Effect.fail(Unauthorized.make())
|
||||||
),
|
),
|
||||||
@@ -26,7 +30,11 @@ const requireReadAccess = pipe(
|
|||||||
const requireWriteAccess = pipe(
|
const requireWriteAccess = pipe(
|
||||||
Authentication.Authentication,
|
Authentication.Authentication,
|
||||||
Effect.flatMap(({ me }) => me),
|
Effect.flatMap(({ me }) => me),
|
||||||
Effect.flatMap((user) => HashSet.isSubset(user.roles, WRITE_ACCESS)
|
Effect.flatMap((user) => pipe(
|
||||||
|
HashSet.intersection(user.roles, WRITE_ACCESS),
|
||||||
|
HashSet.size,
|
||||||
|
Number.greaterThan(0),
|
||||||
|
)
|
||||||
? Effect.succeed(user)
|
? Effect.succeed(user)
|
||||||
: Effect.fail(Unauthorized.make())
|
: Effect.fail(Unauthorized.make())
|
||||||
),
|
),
|
||||||
|
|||||||
Reference in New Issue
Block a user