HotSoda
Ability Management Utility for Vapor Applications.
Prerequisites
Swift
- 4.2.1
OS
- macOS Mojave 10.14.1
Installation
Add the following to your dependencies in Package.swift.
.package(url: "https://github.com/rb-de0/HotSoda.git", from: "0.1.0")
Usage
Provider
To use HotSoda
, you first need to add Provider to Services.
try services.register(HotSodaProvider())
AbilityProtected
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> {
...
}
}
AbilityProtectedMiddleware
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)
LICENSE
HotSoda is released under the MIT License. See the LICENSE file for more info.