/[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 61 - (show annotations)
Thu Jan 25 19:05:04 2007 UTC (17 years, 2 months ago) by dpavlin
File size: 1507 byte(s)
added columns owner and create_on for Query, some Upgrade code to create admin@example.com
user with admin and edit roles.
Added real current_user_can which is a bit more complicated whan minimal.
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 mandatory,
47 since '0.0.6';
48
49 column created_on =>
50 type is 'timestamp',
51 label is 'Created On',
52 default is defer { DateTime->now },
53 filters are 'Jifty::DBI::Filter::DateTime',
54 since '0.0.6';
55 };
56
57 # Your model-specific methods go here.
58
59 sub current_user_can {
60 my $self = shift;
61
62 my ($action,$item,$name) = @_;
63
64 # prevent deep recursion for next rule
65 if ( $action && $item && $name &&
66 $action eq 'read' && $item eq 'column' && ( $name eq 'owner' || $name eq 'visible' )
67 ) {
68 return 1;
69 }
70
71 if ( $self->visible || $self->owner == $self->current_user->id ) {
72 return 1;
73 };
74
75 return 0;
76 }
77
78 1;
79

  ViewVC Help
Powered by ViewVC 1.1.26