Gantry::Utils::TablePerms(3)

NAME
Gantry::Utils::TablePerms - enforces retrieve permssions on main listings

SYNOPSIS
    use Gantry::Utils::TablePerms;

    # ...
    sub do_main {
        #...
        my $perm_obj = Gantry::Utils::TablePerms->new(
            {
                site           => $self,
                real_location  => $real_location,
                header_options => \@header_options,
                row_options    => \@row_options,
            }
        );

        # useful accessors available after a call to the contstructor:
        my $limit_to_user_id = $perm_obj->limit_to_user_id;
        my $hide_all_data    = $perm_obj->hide_all_data;

        # other accessors available after a call to the contstructor:
        my $logged_in_user   = $perm_obj->logged_in_user;
        my $admin_user       = $perm_obj->admin_user;

        ROW:
        foreach my $row ( @rows ) {
            next ROW if $perm_obj->hide_all_data;
            my $real_options = $perm_obj->real_row_options( $row );
        }

    }

DESCRIPTION
This module factors out the common task of row level permission handling for do_main methods.

METHODS
There is only one method, which is not exported.

new This constructor method does a lot of grunt work surrounding the display of main listing table rows when you use row level permissions.

    If your "controller_config" method's hash has a 'permissions' key, this method enforces those permissions. Otherwise, it opens the table to full access. To keep people out in that case, auth the whole controlller.

    Parameters a single hash ref with these keys:

    gantry_site_object
        This is the invocant of your do_ method.

    real_location
        This is usually generated for you by bigtop. If not, use code like this:

            my $real_location = $self->location() || '';
            if ( $real_location ) {
                $real_location =~ s{/+$}{};
                $real_location .= '/';
            }

        The real location becomes the base URL for edit and delete links.

    header_options
        An array ref of options for the whole table. Each array element is a hash. The hashes have the same form as the ones in the "row_options", which are fully described below. The default type for header options is 'create'. Of course, ids are never added to header option links, since these do not apply to individual rows.

    row_options
        An array ref of options for each row. Each array element is a hash. Here's a full sample:

            [
                { text => 'Edit',    type => 'update',                       },
                { text => 'Special', type => 'retrieve', link => '/your/url' },
                { text => 'Make one like this', type => 'create',            },
                { text => 'Delete',  type => 'delete',                       },
            ]

        The keys:

        text
            What the user sees in the link text (if they are allowed to click it).

        type
            [optional defaults to 'retrieve']

            Pick from "create", "retrieve", "update", or "delete". 'create' links are subject to the 'c' flag in the crudcrudcrud permissions. 'retrieve' links are subject to the 'r' flag. 'update' links are subject to the 'u'. 'delete' links are subject to the 'd' flag. If no type is given the 'r' flag governs.

        link
            [optional]

            Defaults to "real_location/lctext/$id", where "real_location" is the first parameter and "lctext" is the text parameter with two changes. First, all spaces are replaced with underscores. Second, it is forced to lower case. So 'Make PDF' becomes 'make_pdf'.

            Note that all links will have "/$id" as their last URL path element.

real_header_options
    Parameters: none

    Returns: an array ref of header options for immediate use by main listing tempaltes.

real_row_options
    Parameter: a database row

    Returns: an array ref of row options suitable for immediate use by main listing templates.

GET ONLY ACCESSORS
The only accessors you really need are "limit_to_user_id", "hide_all_data", and "real_row_options" above.

limit_to_user_id
    This is the id number of the logged in user, but only if the main listing should be limited to rows owned by that user.

hide_all_data
    Inidcates that the table permissions prohibit the current user from seeing any rows in the table. Use this to make sure no data is actually fed to the template.

logged_in_user
    The id number of the currently logged in user (if anyone is logged in).

admin_user
    True if the user is an admin or if the page does not have table permissions.

gantry_site
    For internal use. Returns the site object you passed to the constructor.

AUTHOR
Phil Crow, <crow.phil@gmail.com>

COPYRIGHT AND LICENSE
Copyright (C) 2005-7, Phil Crow

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.6 or, at your option, any later version of Perl 5 you may have available.