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)

Models through middleware is cached, so you can get models as follows without DB connections.

try request.requireControllAllowed(User.self)

LICENSE

HotSoda is released under the MIT License. See the LICENSE file for more info.

Github

link
Stars: 0
Help us keep the lights on

Used By

Total: 0

Releases

0.1.0 - Nov 13, 2018