/[transports]/trunk/lib/Transports/Model/Transport.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Contents of /trunk/lib/Transports/Model/Transport.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 46 - (show annotations)
Tue May 30 18:09:51 2006 UTC (18 years ago) by dpavlin
File size: 2429 byte(s)
bunch of changes:
- added import operator user role (user_object->can_import),
  added import transort which sets return_code and optional comment - it can
  be executed by import operators or admins
- import operators will get just transports which aren't imported under /transports
1 use strict;
2 use warnings;
3
4 package Transports::Model::Transport::Schema;
5 use Jifty::DBI::Schema;
6
7 use Transports::Model::Source;
8 use Transports::Model::Destination;
9 use Transports::Model::User;
10 use Transports::Model::TransportClass;
11 use Transports::Model::ReturnCode;
12
13 # Your column definitions go here. See L<Jifty::DBI::Schema> for
14 # documentation about how to write column definitions.
15
16 column date =>
17 type is 'timestamp',
18 label is 'Date',
19 render_as 'unrendered',
20 since '0.0.1';
21
22 column class =>
23 refers_to Transports::Model::TransportClass,
24 label is 'Transport class',
25 is mandatory,
26 since '0.0.11';
27
28 column source =>
29 refers_to Transports::Model::Source,
30 label is 'Source client',
31 # render_as 'Combobox',
32 # sort_order is 'name',
33 # render_as 'select',
34 is mandatory,
35 since '0.0.6';
36
37 column destination =>
38 refers_to Transports::Model::Destination,
39 label is 'Destionation client',
40 is mandatory,
41 since '0.0.7';
42
43 column request_nr =>
44 type is 'text',
45 label is 'Change request nr',
46 is mandatory,
47 since '0.0.7';
48
49 column client_dependent =>
50 type is 'boolean',
51 label 'Client dependent',
52 is mandatory,
53 since '0.0.7',
54
55 column description =>
56 type is 'text',
57 label 'Description',
58 render_as 'textarea',
59 since '0.0.11';
60
61 column created_by =>
62 refers_to Transports::Model::User,
63 label is 'Request by',
64 since '0.0.7';
65
66 column return_code =>
67 refers_to Transports::Model::ReturnCode,
68 label is 'Return code',
69 since '0.0.12';
70
71 column comment =>
72 type is 'text',
73 render_as 'textarea',
74 since '0.0.12';
75
76 package Transports::Model::Transport;
77 use base qw/Transports::Record/;
78 use DateTime;
79
80 # Your model-specific methods go here.
81
82 =head2 create
83
84 Create new transport and fill-in C<date> and C<created_by>.
85
86 =cut
87
88 sub create {
89 my $self = shift;
90 my %args = (@_);
91
92 my $now = DateTime->now();
93 $args{'date'} = $now->ymd . " " . $now->hms;
94
95 if (! $args{created_by}) {
96 warn 'need $self->current_user' unless ($self->current_user);
97 $args{created_by} = $self->current_user->user_object;
98 }
99
100 my ($id) = $self->SUPER::create(%args);
101 return ($id);
102 }
103
104 =head2 current_user_can ACTION
105
106 Let everybody create, read and update, but not delete.
107
108 =cut
109
110 sub current_user_can {
111 my $self = shift;
112 my $type = shift;
113
114 # We probably want something like this eventually:
115 if ($type =~ /(?:create|read|update)/i) {
116 return 1;
117 } else {
118 return $self->SUPER::current_user_can($type, @_);
119 }
120 }
121
122
123 1;
124

  ViewVC Help
Powered by ViewVC 1.1.26