/[SQLSession]/trunk/lib/SQLSession/Model/Query.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/SQLSession/Model/Query.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 62 - (show annotations)
Thu Jan 25 19:16:18 2007 UTC (17 years, 4 months ago) by dpavlin
File size: 1545 byte(s)
if user has role edit it can do anything to this object
1 use strict;
2 use warnings;
3
4 package SQLSession::Model::Query;
5 use Jifty::DBI::Schema;
6 use SQLSession::Model::Database;
7 use Scalar::Defer;
8
9 use SQLSession::Record schema {
10 column name =>
11 type is 'text',
12 label is 'Name of query',
13 distinct,
14 hints is 'Short name for this query',
15 mandatory;
16
17 column sql_query =>
18 type is 'text',
19 label is 'SQL query',
20 mandatory,
21 distinct,
22 hints is 'Use this area to enter SQL query',
23 render as 'textarea';
24
25 column on_database =>
26 refers_to SQLSession::Model::Database by 'id',
27 label is 'on database',
28 mandatory;
29
30 column note =>
31 type is 'text',
32 label is 'Note',
33 render as 'textarea',
34 since '0.0.2';
35
36 column visible =>
37 type is 'boolean',
38 default is 1,
39 indexed,
40 since '0.0.3';
41
42 column owner =>
43 refers_to SQLSession::Model::User by 'id',
44 label is 'Query owner',
45 default is defer { Jifty->web->current_user->id || 0 },
46 since '0.0.6';
47
48 column created_on =>
49 type is 'timestamp',
50 label is 'Created On',
51 default is defer { DateTime->now },
52 filters are 'Jifty::DBI::Filter::DateTime',
53 since '0.0.6';
54 };
55
56 # Your model-specific methods go here.
57
58 sub current_user_can {
59 my $self = shift;
60
61 my ($action,$item,$name) = @_;
62
63 # prevent deep recursion for next rule
64 if ( $action && $item && $name &&
65 $action eq 'read' && $item eq 'column' && ( $name eq 'owner' || $name eq 'visible' )
66 ) {
67 return 1;
68 }
69
70 if ( $self->visible || $self->owner == $self->current_user->id ) {
71 return 1;
72 };
73
74 return 1 if ($self->current_user->role('edit'));
75
76 return 0;
77 }
78
79 1;
80

  ViewVC Help
Powered by ViewVC 1.1.26