209 похожих чатов

Кто использовал CASL в проекте, где есть Prisma ORM ?

9 ответов

7 просмотров

я)

https://github.com/htchtc052/music-app/tree/main/backend/src/casl

Ayrat- Автор вопроса
Alik Kotov
я)

о, крутяк я вот засел за попытку всунуть КАСЛ в свой проект с Призмой, и чёт запутался. - Ability (которая везде в примерах) - нынче deprecated.. - CASL for Prisma - похож на сырой костыль на первый взгляд...

Ayrat
о, крутяк я вот засел за попытку всунуть КАСЛ в св...

Надо же) и что вместо него) Может выпилить пока не поздно и заменить каким нибудь isOwner в сервисах. тем более оно в основном для этого и нужно

Ayrat
о, крутяк я вот засел за попытку всунуть КАСЛ в св...

вроде оно все работает. другое дело, что чуток избыточно и для юнит тестов неудобно

Ayrat- Автор вопроса
Alik Kotov
screenshot

Спасибо, посмотрел. Получается, основная логика "кому чего можно" находится в ability.factory и оттуда тянется в Гард (policies.guard), который навешивается на нужные роуты Трека? + вдогонку ещё декоратор @CheckPolicies (но я пока не понял, для чего он)

Ayrat
screenshot Спасибо, посмотрел. Получается, основная логика "к...

Да основное кому чему можно в factory а guard проверяет полиции которые назначеные в декораторе. Сейчас попробую подробнее пояснить @CheckPolicies(ReadTrackHandler) Назначило роуту одну полицию ReadTrack далее идем в @UseGuards(PoliciesGuard) там есть return policyHandlers.every((handler) => handler.handle(ability)); Оно предполагает, что полиций может быть много, хотя нафига нужно. но в доках так. Ну мало ли какие случаи Далее он берет этот единственный handler и передает туда обьект ability где и зашиты правила. и которая уже связана именно с текущим authUser который заходит на роут Далее смотрим что внутри хендлера constructor(private track: Track) {} handle(ability: AppAbility) { return ability.can(Action.Read, subject('Track', this.track)); } А там применяем ability от лица authUser к треку куда заходим. Ну будто бы выполняем isOwner на этом треке. А трек берется из DI куда его засовывает провайдер export const ReadTrackProvider: Provider = { provide: ReadTrackHandler, inject: [REQUEST], useFactory: (request: RequestWithTrackInterface) => { const track: Track = request.track; return new ReadTrackHandler(track); }, }; вот в этой строчке return new ReadTrackHandler(track); А сам трек идет из requestWithTrack куда его миддваре по id роута запихнуло async use(req: RequestWithTrack, res: Response, next: NextFunction) { const id = parseInt(req.params.id); /// const track: Track = await this.tracksService.findWithFileById(id); .// req.track = track; next(); }

Похожие вопросы

Обсуждают сегодня

I arrived here after a Chico Crypto show highlighted the project & the Team - the fact that the Team had a long history of successfully working with household names gave me e...
Banter is Bullish
1
Is it a good price to buy hex now on 0,0019?
Patrick
29
It's unfortunate that the "Then why are you here" or "lol you must've bought high" mantras always come up. I already tried bringing up this subject in the price channel but si...
Leroy Gerrits
4
Lers say somehow tor got shut down What then?
Mark Keller
15
Are there any empirical studies out there about how probable and how much it costs to double spend BCH?
Joemar Taganna
11
Hey everyone how's it going? I messaged in dev chat the other day. I got some good reactions but never got through to a team member. I work for a cross-chain interoperability ...
Jake | BD CryptoLink.Tech
5
Gm, Oceaners🌟 We're going to #DappCon24 🇩🇪 between May 21-23 in Berlin to talk #blockchain future! If you're nearby, come by and say hello at our booth! Grab your tickets h...
KreigDK | Never DM first🌊
8
💧 Introducing Drip 💧 We’re thrilled to announce that after a successful month-long testing phase by our OG members on Discord, Drip is now rolling out to the entire community!...
Robin (will not DM first)
1
Jared Tate say DGB can fix 95% of cybersecurity vulnerability on internet today. This true admin? He say at 9 minute 30 second of video
Positif Vibes
11
What is the goal of Digibyte & how will we give it global appeal/ make everyday ppl want to hold it?
Valentenio x10
12
Карта сайта