View on
MetaCPAN
Doug Bell > Yancy-0.010 > Yancy::Controller::Yancy::MultiTenant

Download:
Yancy-0.010.tar.gz

Dependencies

Annotate this POD

Website

View/Report Bugs
Module Version: 0.010   Source   Latest Release: Yancy-0.011

NAME ^

Yancy::Controller::Yancy::MultiTenant - A controller to show a user only their content

VERSION ^

version 0.010

DESCRIPTION ^

This module contains routes to manage content owned by users. Each user is allowed to see and manage only their own content.

METHODS ^

list_items

List the items in a collection. A user only can see items owned by themselves.

add_item

Add a new item to the collection. This new item will be owned by the current user.

get_item

Get a single item from a collection. Users can only view items owned by them.

set_item

Update an item in a collection. Users can only update items that they own.

delete_item

Delete an item from a collection. Users can only delete items they own.

CONFIGURATION ^

To use this controller, you must add some additional configuration to your collections. This configuration will map collection fields to Mojolicious stash values. You must then set these stash values on every request so that users are restricted to their own content.

    use Mojolicious::Lite;
    plugin Yancy => {
        controller_class => 'Yancy::MultiTenant',
        collections => {
            blog => {
                # Map collection fields to stash values
                'x-stash-fields' => {
                    # collection field => stash field
                    user_id => 'current_user_id',
                },
                properties => {
                    id => { type => 'integer', readOnly => 1 },
                    user_id => { type => 'integer', readOnly => 1 },
                    title => { type => 'string' },
                    content => { type => 'string' },
                },
            },
        },
    };

    under '/' => sub {
        my ( $c ) = @_;
        # Pull out the current user's username from the session.
        # See Yancy::Plugin::Auth::Basic for a way to set the username
        $c->stash( current_user_id => $c->session( 'username' ) );
    };

SEE ALSO ^

Yancy::Controller::Yancy, Mojolicious::Controller

AUTHOR ^

Doug Bell <preaction@cpan.org>

COPYRIGHT AND LICENSE ^

This software is copyright (c) 2017 by Doug Bell.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.

syntax highlighting: