Rapi-Blog
view release on metacpan or search on metacpan
lib/Rapi/Blog/DB/Result/User.pm view on Meta::CPAN
use utf8;
package Rapi::Blog::DB::Result::User;
# Created by DBIx::Class::Schema::Loader
# DO NOT MODIFY THE FIRST PART OF THIS FILE
use strict;
use warnings;
use Moose;
use MooseX::NonMoose;
use MooseX::MarkAsMethods autoclean => 1;
extends 'DBIx::Class::Core';
__PACKAGE__->load_components("InflateColumn::DateTime");
__PACKAGE__->table("user");
__PACKAGE__->add_columns(
"id",
{ data_type => "integer", is_auto_increment => 1, is_nullable => 0 },
"username",
{ data_type => "varchar", is_nullable => 0, size => 32 },
"full_name",
{
data_type => "varchar",
default_value => \"null",
is_nullable => 1,
size => 64,
},
"image",
{
data_type => "varchar",
default_value => \"null",
is_nullable => 1,
size => 255,
},
"email",
{
data_type => "varchar",
default_value => \"null",
is_nullable => 1,
size => 255,
},
"admin",
{ data_type => "boolean", default_value => 0, is_nullable => 0 },
"author",
{ data_type => "boolean", default_value => 0, is_nullable => 0 },
"comment",
{ data_type => "boolean", default_value => 1, is_nullable => 0 },
"disabled",
{ data_type => "boolean", default_value => 0, is_nullable => 0 },
);
__PACKAGE__->set_primary_key("id");
__PACKAGE__->add_unique_constraint("full_name_unique", ["full_name"]);
__PACKAGE__->add_unique_constraint("username_unique", ["username"]);
__PACKAGE__->has_many(
"comments",
"Rapi::Blog::DB::Result::Comment",
{ "foreign.user_id" => "self.id" },
{ cascade_copy => 0, cascade_delete => 0 },
);
__PACKAGE__->has_many(
"post_authors",
"Rapi::Blog::DB::Result::Post",
{ "foreign.author_id" => "self.id" },
{ cascade_copy => 0, cascade_delete => 0 },
);
__PACKAGE__->has_many(
"post_creators",
"Rapi::Blog::DB::Result::Post",
{ "foreign.creator_id" => "self.id" },
{ cascade_copy => 0, cascade_delete => 0 },
);
__PACKAGE__->has_many(
"post_updaters",
"Rapi::Blog::DB::Result::Post",
{ "foreign.updater_id" => "self.id" },
{ cascade_copy => 0, cascade_delete => 0 },
);
__PACKAGE__->has_many(
"preauth_actions",
"Rapi::Blog::DB::Result::PreauthAction",
{ "foreign.user_id" => "self.id" },
{ cascade_copy => 0, cascade_delete => 0 },
);
# Created by DBIx::Class::Schema::Loader v0.07049 @ 2018-10-27 23:38:05
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:2klRAJnak1zgM9iKuGRQCQ
use RapidApp::Util ':all';
__PACKAGE__->load_components('+RapidApp::DBIC::Component::TableSpec');
__PACKAGE__->load_components('+Rapi::Blog::DB::Component::SafeResult');
__PACKAGE__->add_virtual_columns( set_pw => {
data_type => "varchar",
is_nullable => 1,
sql => "SELECT NULL",
set_function => sub {} # This is a dummy designed to hook via AuthCore/linked_user_model
});
__PACKAGE__->apply_TableSpec;
sub insert {
my $self = shift;
# Fix GitHub Issue #1 - we want to do this perm check, however, if this insert is being
# generated via automatic inflation from the CoreSchema LinkedRow, this will result in
# a deep recursion (i.e. the current user *is* being inserted). For this case, we bail
# out of the perm check if we detect that a linkedRow sync is already in-progress
unless($self->{_pulling_linkedRow}) {
my $User = Rapi::Blog::Util->get_User;
die usererr "Create User: PERMISSION DENIED" if ($User && $User->id && !$User->admin);
}
$self->next::method(@_);
$self->_role_perm_sync;
$self
}
sub update {
my $self = shift;
my $User = Rapi::Blog::Util->get_User;
die usererr "Update User: PERMISSION DENIED" if (
$User && $User->id &&
!($User->admin || $self->id == $User->id)
);
$self->next::method(@_);
$self->_role_perm_sync;
$self
}
sub delete {
my $self = shift;
( run in 0.684 second using v1.01-cache-2.11-cpan-39bf76dae61 )