1 |
dpavlin |
2 |
use strict; |
2 |
|
|
use warnings; |
3 |
|
|
|
4 |
|
|
package Grep::Model::Item; |
5 |
|
|
use Jifty::DBI::Schema; |
6 |
|
|
|
7 |
|
|
use Grep::Model::Feed; |
8 |
|
|
|
9 |
|
|
use Grep::Record schema { |
10 |
|
|
|
11 |
|
|
column in_feed => |
12 |
|
|
refers_to Grep::Model::Feed by 'id', |
13 |
|
|
is mandatory; |
14 |
|
|
|
15 |
|
|
column title => |
16 |
|
|
type is 'text', |
17 |
|
|
is mandatory; |
18 |
|
|
|
19 |
|
|
column link => |
20 |
|
|
type is 'text', |
21 |
|
|
is mandatory; |
22 |
|
|
|
23 |
|
|
column content => |
24 |
|
|
type is 'text', |
25 |
|
|
is mandatory; |
26 |
|
|
|
27 |
|
|
column summary => |
28 |
|
|
type is 'text'; |
29 |
|
|
|
30 |
|
|
column category => |
31 |
|
|
type is 'text'; |
32 |
|
|
|
33 |
|
|
column author => |
34 |
|
|
type is 'text'; |
35 |
|
|
|
36 |
|
|
column issued => |
37 |
|
|
type is 'timestamp', |
38 |
|
|
filters are qw( Jifty::Filter::DateTime Jifty::DBI::Filter::DateTime ); |
39 |
|
|
|
40 |
|
|
column modified => |
41 |
|
|
type is 'timestamp', |
42 |
|
|
filters are qw( Jifty::Filter::DateTime Jifty::DBI::Filter::DateTime ); |
43 |
|
|
|
44 |
|
|
}; |
45 |
|
|
|
46 |
dpavlin |
3 |
sub since { '0.0.1' } |
47 |
|
|
|
48 |
dpavlin |
2 |
# Your model-specific methods go here. |
49 |
|
|
|
50 |
dpavlin |
37 |
sub current_user_can { |
51 |
|
|
my $self = shift; |
52 |
|
|
my $what = shift; |
53 |
|
|
|
54 |
dpavlin |
63 |
my $uid = Jifty->web->current_user->id; |
55 |
dpavlin |
37 |
|
56 |
dpavlin |
63 |
return 1 if ( $uid && $what eq 'create' ); |
57 |
|
|
|
58 |
|
|
return 1 if ( $uid && ! $self->id ); |
59 |
|
|
|
60 |
|
|
my $owner_id = $self->in_feed->owner->id; |
61 |
|
|
|
62 |
dpavlin |
70 |
# Jifty->log->debug("current_user[$uid]_can($what) on Item ", $self->id || '???', " owner ", $owner_id || '???'); |
63 |
dpavlin |
63 |
|
64 |
dpavlin |
110 |
return 1 if ( $uid && $owner_id && $uid == $owner_id ); |
65 |
dpavlin |
37 |
} |
66 |
|
|
|
67 |
dpavlin |
127 |
sub after_create { |
68 |
|
|
my $self = shift; |
69 |
|
|
my $insert_return_value_ref = shift; |
70 |
|
|
|
71 |
|
|
return unless $$insert_return_value_ref; # bail if insert failed |
72 |
|
|
$self->load($$insert_return_value_ref); # load ourselves from db |
73 |
|
|
|
74 |
|
|
# Do whatever needs to be done here |
75 |
|
|
|
76 |
|
|
warn "after_create ", dump( $self->as_hash ); |
77 |
|
|
|
78 |
|
|
return; # return value is ignored |
79 |
|
|
} |
80 |
|
|
|
81 |
dpavlin |
2 |
1; |
82 |
|
|
|