NestedReadAllAuthModifier

public final class NestedReadAllAuthModifier<
    A: AuthEndpoint,
    I: CorvusModel,
    U: CorvusModelAuthenticatable>:
ReadEndpoint

A class that wraps a component which utilizes an .auth() modifier. Differs from AuthModifier by authenticating on the user of an intermediate parent I of A.QuerySubject. Requires an object U that represents the user to authorize.

  • The return value of the .query(), so the type being operated on in the current component.

    Declaration

    Swift

    public typealias QuerySubject = A.QuerySubject
  • The KeyPath to the user property of the intermediate I which is to be authenticated.

    Declaration

    Swift

    public typealias UserKeyPath = KeyPath<
        I,
        I.Parent<U>
    >
  • The KeyPath to the intermediate I of the endpoint’s QuerySubject.

    Declaration

    Swift

    public typealias IntermediateKeyPath = KeyPath<
        A.QuerySubject,
        A.QuerySubject.Parent<I>
    >
  • The AuthEndpoint the .auth() modifier is attached to.

    Declaration

    Swift

    public let modifiedEndpoint: A
  • The path to the property to authenticate for.

    Declaration

    Swift

    public let userKeyPath: UserKeyPath
  • The path to the intermediate.

    Declaration

    Swift

    public let intermediateKeyPath: IntermediateKeyPath
  • Initializes the modifier with its underlying QueryEndpoint and its auth path, which is the keypath to the property to run authentication for.

    Declaration

    Swift

    public init(
        _ authEndpoint: A,
        intermediate: IntermediateKeyPath,
        user: UserKeyPath
    )

    Parameters

    queryEndpoint

    The QueryEndpoint which the modifer is attached to.

    intermediate

    A KeyPath to the intermediate.

    user

    A KeyPath which leads to the property to authenticate for.

    operationType

    The HTTP method of the wrapped component.

  • Returns the queryEndpoint‘s query.

    Throws

    An Abort error if the item is not found.

    Declaration

    Swift

    public func query(_ req: Request) throws -> QueryBuilder<QuerySubject>

    Parameters

    req

    An incoming Request.

    Return Value

    A QueryBuilder, which represents a Fluent query defined by the queryEndpoint.

  • A method which checks if the user U supplied in the Request is equal to the user belonging to the particular QuerySubject.

    Throws

    An Abort error if an item is not found.

    Declaration

    Swift

    public func handler(_ req: Request) throws ->
        EventLoopFuture<[QuerySubject]>

    Parameters

    req

    An incoming Request.

    Return Value

    An EventLoopFuture containing an eagerloaded value as defined by Element. If authentication fails or a user is not found, HTTP .unauthorized and .notFound are thrown respectively.