Ability Management Utility for Vapor Applications.
- 4.2.1
- macOS Mojave 10.14.1
Add the following to your dependencies in Package.swift.
.package(url: "https://github.com/rb-de0/HotSoda.git", from: "0.1.0")
To use HotSoda
, you first need to add Provider to Services.
try services.register(HotSodaProvider())
Conform Models that you want to manage abilities to AbilityProtected
.
extension User: AbilityProtected {
static func canCreate(on request: Request) -> Future<Void> {
...
}
func canRead(on request: Request) -> Future<User> {
...
}
func canUpdate(on request: Request) -> Future<User> {
...
}
func canDelete(on request: Request) -> Future<User> {
...
}
}
By using AbilityProtectedMiddleware, you can protect abilities for controlling models.
The model must be conformed AbilityProtected & Model & Parameter
.
router.protected(User.self, for: [.create]).post("users", use: UserController().store)
or
router.protect(User.self, for: [.create]) { router in
router.post("users", use: UserController().store)
}
Models through middleware is cached, so you can get models as follows without DB connections.
try request.requireControllable(User.self)
HotSoda is released under the MIT License. See the LICENSE file for more info.