| 1 | package Rapi::Blog::DB::Component::SafeResult; | ||
| 2 | |||
| 3 | use strict; | ||
| 4 | use warnings; | ||
| 5 | |||
| 6 | use parent 'DBIx::Class::Core'; | ||
| 7 | use RapidApp::Util ':all'; | ||
| 8 | |||
| 9 | our $ALLOW = 0; | ||
| 10 | |||
| 11 | sub _caller_not_allowed { | ||
| 12 | my $self = shift; | ||
| 13 | return 0 if ($ALLOW); | ||
| 14 | return $self->_caller_is_template; | ||
| 15 | } | ||
| 16 | |||
| 17 | sub _caller_is_template { | ||
| 18 | if(my $c = RapidApp->active_request_context) { | ||
| 19 | return 1 if($c->controller('RapidApp::Template')->Access->currently_viewing_template); | ||
| 20 | } | ||
| 21 | return 0; | ||
| 22 | } | ||
| 23 | |||
| 24 | sub insert { | ||
| 25 | my $self = shift; | ||
| 26 | $self->_caller_not_allowed and die "INSERT denied"; | ||
| 27 | $self->next::method(@_) | ||
| 28 | } | ||
| 29 | |||
| 30 | sub update { | ||
| 31 | my $self = shift; | ||
| 32 | $self->_caller_not_allowed and die "UPDATE denied"; | ||
| 33 | $self->next::method(@_) | ||
| 34 | } | ||
| 35 | |||
| 36 | sub delete { | ||
| 37 | my $self = shift; | ||
| 38 | $self->_caller_not_allowed and die "DELETE denied"; | ||
| 39 | $self->next::method(@_) | ||
| 40 | } | ||
| 41 | |||
| 42 | |||
| 43 | 1; |