4 |
package Transports::Model::Source::Schema; |
package Transports::Model::Source::Schema; |
5 |
use Jifty::DBI::Schema; |
use Jifty::DBI::Schema; |
6 |
|
|
7 |
|
use Transports::Model::Landscape; |
8 |
|
|
9 |
# Your column definitions go here. See L<Jifty::DBI::Schema> for |
# Your column definitions go here. See L<Jifty::DBI::Schema> for |
10 |
# documentation about how to write column definitions. |
# documentation about how to write column definitions. |
11 |
|
|
15 |
is mandatory, |
is mandatory, |
16 |
since '0.0.6'; |
since '0.0.6'; |
17 |
|
|
18 |
|
column landscape => |
19 |
|
refers_to Transports::Model::Landscape, |
20 |
|
label is 'Part of landscape', |
21 |
|
since '0.0.13'; |
22 |
|
|
23 |
package Transports::Model::Source; |
package Transports::Model::Source; |
24 |
use base qw/Transports::Record/; |
use base qw/Transports::Record/; |
25 |
|
|
27 |
|
|
28 |
=head2 current_user_can ACTION |
=head2 current_user_can ACTION |
29 |
|
|
30 |
Let everybody create, read and update, but not delete. |
Everybody can read, admin and import can everything else. |
31 |
|
|
32 |
=cut |
=cut |
33 |
|
|
35 |
my $self = shift; |
my $self = shift; |
36 |
my $type = shift; |
my $type = shift; |
37 |
|
|
38 |
return 1 if ($self->current_user->admin); |
return 1 if ($type eq 'read' || $self->current_user->admin || $self->current_user->can_import); |
|
|
|
|
return 1 if ($type eq 'read'); |
|
|
|
|
|
# We probably want something like this eventually: |
|
|
if ($type =~ /(?:create|update)/i) { |
|
39 |
|
|
40 |
my $uos = Transports::Model::UserOnSource->new(); |
return $self->SUPER::current_user_can($type, @_); |
|
$uos->load_by_cols( |
|
|
user_on => $self->current_user->id, |
|
|
source => $self->id |
|
|
); |
|
|
return undef if ($self->current_user->id && ! $uos->id); |
|
|
|
|
|
return 1; |
|
|
} else { |
|
|
return $self->SUPER::current_user_can($type, @_); |
|
|
} |
|
41 |
} |
} |
42 |
|
|
43 |
1; |
1; |