summaryrefslogtreecommitdiff
path: root/FS
diff options
context:
space:
mode:
authorivan <ivan>2006-08-10 11:55:50 +0000
committerivan <ivan>2006-08-10 11:55:50 +0000
commit264ad081e68057c7bc30a8b2ad741b783e1342ff (patch)
treeee1376c0552c6a40f3c3d6cf05a4a25e6b16fcf8 /FS
parent6495ab5fb29dcdb8233f004b5d60d3d97db058b9 (diff)
agent-virtualize advertising sources
Diffstat (limited to 'FS')
-rw-r--r--FS/FS/AccessRight.pm5
-rw-r--r--FS/FS/Record.pm31
-rw-r--r--FS/FS/Schema.pm7
-rw-r--r--FS/FS/access_user.pm22
-rw-r--r--FS/FS/part_referral.pm24
5 files changed, 79 insertions, 10 deletions
diff --git a/FS/FS/AccessRight.pm b/FS/FS/AccessRight.pm
index 797a12a4d..888a6865b 100644
--- a/FS/FS/AccessRight.pm
+++ b/FS/FS/AccessRight.pm
@@ -136,8 +136,11 @@ assigned to users and/or groups.
'Import', #
'Export', #
- 'Configuration', #none of the configuraiton is agent-virtualized either
+ 'Edit advertising sources',
+ 'Edit global advertising sources',
+ 'Configuration', #most of the rest of the configuraiton is not
+ # agent-virtualized
);
sub rights {
diff --git a/FS/FS/Record.pm b/FS/FS/Record.pm
index 41e0eba51..a551bb8cc 100644
--- a/FS/FS/Record.pm
+++ b/FS/FS/Record.pm
@@ -10,6 +10,7 @@ use Locale::Country;
use DBI qw(:sql_types);
use DBIx::DBSchema 0.25;
use FS::UID qw(dbh getotaker datasrc driver_name);
+use FS::CurrentUser;
use FS::Schema qw(dbdef);
use FS::SearchCache;
use FS::Msgcat qw(gettext);
@@ -1620,6 +1621,36 @@ sub ut_foreign_keyn {
: '';
}
+=item ut_agentnum_acl
+
+Checks this column as an agentnum, taking into account the current users's
+ACLs.
+
+=cut
+
+sub ut_agentnum_acl {
+ my( $self, $field, $null_acl ) = @_;
+
+ my $error = $self->ut_foreign_keyn($field, 'agent', 'agentnum');
+ return "Illegal agentnum: $error" if $error;
+
+ my $curuser = $FS::CurrentUser::CurrentUser;
+
+ if ( $self->$field() ) {
+
+ return "Access deined"
+ unless $curuser->agentnum($self->$field());
+
+ } else {
+
+ return "Access denied"
+ unless $curuser->access_right($null_acl);
+
+ }
+
+ '';
+
+}
=item virtual_fields [ TABLE ]
diff --git a/FS/FS/Schema.pm b/FS/FS/Schema.pm
index e7505465e..e23ae737d 100644
--- a/FS/FS/Schema.pm
+++ b/FS/FS/Schema.pm
@@ -692,9 +692,10 @@ sub tables_hashref {
'part_referral' => {
'columns' => [
- 'refnum', 'serial', '', '', '', '',
- 'referral', 'varchar', '', $char_d, '', '',
- 'disabled', 'char', 'NULL', 1, '', '',
+ 'refnum', 'serial', '', '', '', '',
+ 'referral', 'varchar', '', $char_d, '', '',
+ 'disabled', 'char', 'NULL', 1, '', '',
+ 'agentnum', 'int', 'NULL', '', '', '',
],
'primary_key' => 'refnum',
'unique' => [],
diff --git a/FS/FS/access_user.pm b/FS/FS/access_user.pm
index 5d1e183e7..f32fa3a23 100644
--- a/FS/FS/access_user.pm
+++ b/FS/FS/access_user.pm
@@ -106,6 +106,10 @@ sub insert {
sub htpasswd_kludge {
my $self = shift;
+
+ #awful kludge to skip setting htpasswd for fs_* users
+ return '' if $self->username =~ /^fs_/;
+
unshift @_, '-c' unless -e $htpasswd_file;
if (
system('htpasswd', '-b', @_,
@@ -297,6 +301,24 @@ sub agentnums_sql {
' )';
}
+=item agentnum
+
+Returns true if the user can view the specified agent.
+
+=cut
+
+sub agentnum {
+ my( $self, $agentnum ) = @_;
+ my $sth = dbh->prepare(
+ "SELECT COUNT(*) FROM access_usergroup
+ JOIN access_groupagent USING ( groupnum )
+ WHERE usernum = ? AND agentnum = ?"
+ ) or die dbh->errstr;
+ $sth->execute($self->usernum, $agentnum) or die $sth->errstr;
+ $sth->fetchrow_arrayref->[0];
+}
+
+
=item access_right
Given a right name, returns true if this user has this right (currently via
diff --git a/FS/FS/part_referral.pm b/FS/FS/part_referral.pm
index c0858c0ed..b12cd628e 100644
--- a/FS/FS/part_referral.pm
+++ b/FS/FS/part_referral.pm
@@ -2,7 +2,8 @@ package FS::part_referral;
use strict;
use vars qw( @ISA );
-use FS::Record;
+use FS::Record qw(qsearchs);
+use FS::agent;
@ISA = qw( FS::Record );
@@ -40,6 +41,8 @@ The following fields are currently supported:
=item disabled - Disabled flag, empty or 'Y'
+=item agentnum - Optional agentnum (see L<FS::agent>)
+
=back
=head1 NOTE
@@ -95,17 +98,26 @@ sub check {
my $error = $self->ut_numbern('refnum')
|| $self->ut_text('referral')
+ || $self->ut_enum('disabled', [ '', 'Y' ] )
+ #|| $self->ut_foreign_keyn('agentnum', 'agent', 'agentnum')
+ || $self->ut_agentnum_acl('agentnum', 'Edit global advertising sources')
;
return $error if $error;
- if ( $self->dbdef_table->column('disabled') ) {
- $error = $self->ut_enum('disabled', [ '', 'Y' ] );
- return $error if $error;
- }
-
$self->SUPER::check;
}
+=item agent
+
+Returns the associated agent for this referral, if any, as an FS::agent object.
+
+=cut
+
+sub agent {
+ my $self = shift;
+ qsearchs('agent', { 'agentnum' => $self->agentnum } );
+}
+
=back
=head1 BUGS