1 |
use strict; |
use strict; |
2 |
use warnings; |
use warnings; |
3 |
|
|
4 |
package A3C::Model::StrixSiteSelection; |
package A3C::Model::StrixInstanceSelection; |
5 |
use Jifty::DBI::Schema; |
use Jifty::DBI::Schema; |
6 |
|
|
7 |
use Data::Dump qw/dump/; |
use Data::Dump qw/dump/; |
8 |
|
|
9 |
use A3C::Record schema { |
use A3C::Record schema { |
10 |
|
|
11 |
column strix => |
column instance => |
12 |
label is _('Site identifier'), |
label is _('Instance identifier'), |
13 |
is mandatory, |
is mandatory, |
14 |
type is 'text', |
type is 'text', |
15 |
refers_to A3C::Model::StrixSite by 'site'; |
is ajax_validates, |
16 |
|
refers_to A3C::Model::StrixInstance by 'instance'; |
17 |
|
|
18 |
column by_user => |
column by_user => |
19 |
label is ('Selected by user'), |
label is ('Selected by user'), |
27 |
|
|
28 |
sub since { '0.0.4' }; |
sub since { '0.0.4' }; |
29 |
|
|
30 |
sub validate_strix { |
sub validate_instance { |
31 |
my $self = shift; |
my $self = shift; |
32 |
my $site = shift; |
my $instance = shift; |
33 |
|
|
34 |
my $strix = A3C::Model::StrixSiteSelection->new; |
my $strix = A3C::Model::StrixInstanceSelection->new; |
35 |
$strix->load_by_cols( strix => $site ); |
$strix->load_by_cols( instance => $instance ); |
36 |
|
|
37 |
return ( 0, _('Site %1 is allready selected', $site) ) if $strix->id; |
if ( $strix->id ) { |
38 |
return 1; |
return ( 0, _('Instance %1 allready selected', $instance) ); |
39 |
|
} else { |
40 |
|
eval { |
41 |
|
Strix->dbh( $instance ); |
42 |
|
}; |
43 |
|
return 1 unless $@; |
44 |
|
return ( 0, $@ ); |
45 |
|
} |
46 |
} |
} |
47 |
|
|
48 |
sub current_user_can { |
sub current_user_can { |
49 |
my $self = shift; |
my $self = shift; |
50 |
# warn " current_user->id: ", $self->current_user->id, " == ", dump( $self->by_user->id ); |
my $op = shift; |
51 |
# FIXME just my sites |
|
52 |
#return 1 if $self->by_user->id == $self->current_user->id; |
if ( $op eq 'create' ) { |
53 |
return 1; |
my %args = @_; |
54 |
|
return 1 if $args{by_user} == $self->current_user->id; |
55 |
|
} |
56 |
|
|
57 |
|
return 1 if $self->by_user->id == $self->current_user->id; |
58 |
|
|
59 |
return 0; |
return 0; |
60 |
} |
} |
61 |
|
|