1 |
use strict; |
2 |
use warnings; |
3 |
|
4 |
package A3C::Model::StrixInstanceSelection; |
5 |
use Jifty::DBI::Schema; |
6 |
|
7 |
use Data::Dump qw/dump/; |
8 |
|
9 |
use A3C::Record schema { |
10 |
|
11 |
column instance => |
12 |
label is _('Instance identifier'), |
13 |
is mandatory, |
14 |
type is 'text', |
15 |
refers_to A3C::Model::StrixInstance by 'instance'; |
16 |
|
17 |
column by_user => |
18 |
label is ('Selected by user'), |
19 |
is mandatory, |
20 |
refers_to A3C::Model::User by 'id', |
21 |
default is defer { Jifty->web->current_user->id }; |
22 |
|
23 |
}; |
24 |
|
25 |
# Your model-specific methods go here. |
26 |
|
27 |
sub since { '0.0.4' }; |
28 |
|
29 |
sub validate_instance { |
30 |
my $self = shift; |
31 |
my $instance = shift; |
32 |
|
33 |
my $strix = A3C::Model::StrixInstanceSelection->new; |
34 |
$strix->load_by_cols( instance => $instance ); |
35 |
|
36 |
return ( 0, _('Instance %1 is allready selected', $instance) ) if $strix->id; |
37 |
return 1; |
38 |
} |
39 |
|
40 |
sub current_user_can { |
41 |
my $self = shift; |
42 |
my $op = shift; |
43 |
|
44 |
if ( $op eq 'create' ) { |
45 |
my %args = @_; |
46 |
return 1 if $args{by_user} == $self->current_user->id; |
47 |
} |
48 |
|
49 |
return 1 if $self->by_user->id == $self->current_user->id; |
50 |
|
51 |
return 0; |
52 |
} |
53 |
|
54 |
1; |
55 |
|