/[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

Annotation of /trunk/lib/SQLSession/Model/Query.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 102 - (hide annotations)
Fri Feb 16 23:40:21 2007 UTC (17 years, 2 months ago) by dpavlin
File size: 2033 byte(s)
added concept of "parent" query if you started by editing existing one
1 dpavlin 1 use strict;
2     use warnings;
3    
4 dpavlin 15 package SQLSession::Model::Query;
5 dpavlin 1 use Jifty::DBI::Schema;
6     use SQLSession::Model::Database;
7 dpavlin 64 use SQLSession::Model::User;
8 dpavlin 61 use Scalar::Defer;
9 dpavlin 1
10     use SQLSession::Record schema {
11     column name =>
12     type is 'text',
13 dpavlin 14 label is 'Name of query',
14 dpavlin 1 distinct,
15 dpavlin 15 hints is 'Short name for this query',
16 dpavlin 1 mandatory;
17    
18     column sql_query =>
19     type is 'text',
20     label is 'SQL query',
21     mandatory,
22     distinct,
23     hints is 'Use this area to enter SQL query',
24     render as 'textarea';
25    
26     column on_database =>
27 dpavlin 21 refers_to SQLSession::Model::Database by 'id',
28 dpavlin 17 label is 'on database',
29     mandatory;
30 dpavlin 28
31     column note =>
32     type is 'text',
33     label is 'Note',
34     render as 'textarea',
35 dpavlin 61 since '0.0.2';
36 dpavlin 31
37     column visible =>
38     type is 'boolean',
39     default is 1,
40 dpavlin 61 indexed,
41     since '0.0.3';
42    
43     column owner =>
44     refers_to SQLSession::Model::User by 'id',
45     label is 'Query owner',
46     default is defer { Jifty->web->current_user->id || 0 },
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 dpavlin 102
56     column parent =>
57     refers_to SQLSession::Model::Query by 'id',
58     label is 'Originator query',
59     indexed,
60     since '0.0.7';
61    
62 dpavlin 1 };
63    
64 dpavlin 102 sub since { '0.0.1' }
65    
66 dpavlin 1 # Your model-specific methods go here.
67    
68 dpavlin 29 sub current_user_can {
69 dpavlin 61 my $self = shift;
70    
71     my ($action,$item,$name) = @_;
72    
73 dpavlin 92 # warn "current_user_can $action | $item | ", $name ? $name : 'NO NAME', "\n";
74 dpavlin 74
75 dpavlin 61 # prevent deep recursion for next rule
76 dpavlin 92 if ( $action && $item && $action eq 'read' && $item eq 'column' ) {
77     # return 1 if !defined($name); # special case for my group by query -- might be security hole!
78     return 1 if ( $name && $name =~ m/^(owner|visible)$/ );
79 dpavlin 61 }
80    
81     if ( $self->visible || $self->owner == $self->current_user->id ) {
82     return 1;
83     };
84    
85 dpavlin 74 return 1 if ( $self->visible && $self->current_user->role('edit'));
86     return 1 if ( $action eq 'create' && $self->current_user->role('edit'));
87 dpavlin 62
88 dpavlin 71 return 1 if ( $self->current_user->is_superuser );
89    
90 dpavlin 61 return 0;
91 dpavlin 29 }
92    
93 dpavlin 1 1;
94    

  ViewVC Help
Powered by ViewVC 1.1.26