Yancy::Controller::Yancy::MultiTenant - A controller to show a user only their content
version 0.021
This module contains routes to manage content owned by users. Each user is allowed to see and manage only their own content.
List the items in a collection. A user only can see items owned by themselves.
Add a new item to the collection. This new item will be owned by the current user.
Get a single item from a collection. Users can only view items owned by them.
Update an item in a collection. Users can only update items that they own.
Delete an item from a collection. Users can only delete items they own.
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' ) ); };
Yancy::Controller::Yancy, Mojolicious::Controller
Doug Bell <preaction@cpan.org>
This software is copyright (c) 2018 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.
To install Yancy, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Yancy
CPAN shell
perl -MCPAN -e shell install Yancy
For more information on module installation, please visit the detailed CPAN module installation guide.