1 |
use strict; |
2 |
use warnings; |
3 |
|
4 |
package Transports::Model::Destination::Schema; |
5 |
use Jifty::DBI::Schema; |
6 |
|
7 |
use Transports::Model::Landscape; |
8 |
|
9 |
column name => |
10 |
type is 'text', |
11 |
label is 'Destination client', |
12 |
is mandatory, |
13 |
since '0.0.7'; |
14 |
|
15 |
column landscape => |
16 |
refers_to Transports::Model::Landscape, |
17 |
label is 'Part of landscape', |
18 |
is mandatory, |
19 |
since '0.0.13'; |
20 |
|
21 |
# Your column definitions go here. See L<Jifty::DBI::Schema> for |
22 |
# documentation about how to write column definitions. |
23 |
|
24 |
package Transports::Model::Destination; |
25 |
use base qw/Transports::Record/; |
26 |
|
27 |
# Your model-specific methods go here. |
28 |
|
29 |
=head2 current_user_can ACTION |
30 |
|
31 |
admin and import can everything, users with permission on landscape can read. |
32 |
|
33 |
=cut |
34 |
|
35 |
sub current_user_can { |
36 |
my $self = shift; |
37 |
my $type = shift; |
38 |
|
39 |
return 1 if ($self->current_user->admin || $self->current_user->can_import); |
40 |
|
41 |
if ($type eq 'read') { |
42 |
|
43 |
my $l = Transports::Model::UserOnLandscape->new(); |
44 |
$l->load_by_cols( |
45 |
user_on => $self->current_user->id, |
46 |
landscape => $self->landscape->id, |
47 |
); |
48 |
|
49 |
if ($l->id) { |
50 |
return 1; |
51 |
} else { |
52 |
return undef; |
53 |
} |
54 |
} |
55 |
|
56 |
} |
57 |
|
58 |
1; |
59 |
|