Swiftpack.co - Package - rb-de0/HotSoda

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.

Github

link
Stars: 1
Help us keep the lights on

Used By

Total: 0

Releases

0.4.0.1 - Feb 10, 2019

  • Add some tests. No effect on this library.

0.4.0 - Feb 10, 2019

  • Removed behavior to convert ability check error to HotSodaError.

0.3.1 - Feb 2, 2019

  • Add protected router with configure block (#1) by moto0000

0.3.0 - Jan 30, 2019

0.2.0 - Jan 30, 2019