/[A3C]/lib/A3C/Model/StrixInstanceSelection.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

Annotation of /lib/A3C/Model/StrixInstanceSelection.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 201 - (hide annotations)
Wed Jun 18 13:03:40 2008 UTC (15 years, 10 months ago) by dpavlin
File size: 1159 byte(s)
BUG FIX: allow *different* users to select same instance
1 dpavlin 157 use strict;
2     use warnings;
3    
4 dpavlin 174 package A3C::Model::StrixInstanceSelection;
5 dpavlin 157 use Jifty::DBI::Schema;
6    
7     use Data::Dump qw/dump/;
8    
9     use A3C::Record schema {
10    
11 dpavlin 174 column instance =>
12     label is _('Instance identifier'),
13 dpavlin 157 is mandatory,
14     type is 'text',
15 dpavlin 174 refers_to A3C::Model::StrixInstance by 'instance';
16 dpavlin 157
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 dpavlin 174 sub validate_instance {
30 dpavlin 157 my $self = shift;
31 dpavlin 174 my $instance = shift;
32 dpavlin 157
33 dpavlin 174 my $strix = A3C::Model::StrixInstanceSelection->new;
34 dpavlin 201 $strix->load_by_cols( instance => $instance, by_user => Jifty->web->current_user->id );
35 dpavlin 157
36 dpavlin 186 if ( $strix->id ) {
37     return ( 0, _('Instance %1 allready selected', $instance) );
38     } else {
39     eval {
40     Strix->dbh( $instance );
41     };
42     return 1 unless $@;
43     return ( 0, $@ );
44     }
45 dpavlin 157 }
46    
47     sub current_user_can {
48     my $self = shift;
49 dpavlin 158 my $op = shift;
50    
51     if ( $op eq 'create' ) {
52     my %args = @_;
53     return 1 if $args{by_user} == $self->current_user->id;
54     }
55    
56     return 1 if $self->by_user->id == $self->current_user->id;
57    
58 dpavlin 157 return 0;
59     }
60    
61     1;
62    

  ViewVC Help
Powered by ViewVC 1.1.26