package MojoMojo::Controller::Attachment; use strict; use parent 'Catalyst::Controller'; use IO::File; use URI::Escape (); =head1 NAME MojoMojo::Controller::Attachment - Attachment controller =head1 DESCRIPTION MojoMojo supports attaching files to nodes. This controller handles administration and serving of these assets. =head1 ACTIONS =head2 auth Return whether the current user has attachment manipulation rights (upload/delete). =cut sub auth : Private { my ( $self, $c ) = @_; my $perms = $c->check_permissions( $c->stash->{'path'}, ( $c->user_exists ? $c->user->obj : undef ) ); return $perms->{'attachment'} } =head2 unauthorized Private action to return a 403 with an explanatory template. =cut sub unauthorized : Private { my ( $self, $c, $operation ) = @_; $c->stash->{template} = 'message.tt'; $c->stash->{message} = $c->loc('You do not have permissions to x attachments for this page', $operation); $c->response->status(403); # 403 Forbidden } =head2 default Private action to return a 404 not found page. =cut sub default : Private { my ( $self, $c ) = @_; $c->stash->{template} = 'message.tt'; $c->stash->{message} = $c->loc("Attachment not found."); return ( $c->res->status(404) ); } =head2 attachments Main attachment screen. Handles uploading of new attachments. =cut sub attachments : Global { my ( $self, $c ) = @_; $c->detach('unauthorized', ['view']) if not $c->check_view_permission; $c->stash->{template} = 'page/attachments.tt'; } =head2 list Display the list of attachments if the user has view permissions. B