1 package FS::access_user;
5 use FS::Record qw( qsearch qsearchs dbh );
7 use FS::access_usergroup;
9 @ISA = qw( FS::m2m_Common FS::Record );
13 FS::access_user - Object methods for access_user records
19 $record = new FS::access_user \%hash;
20 $record = new FS::access_user { 'column' => 'value' };
22 $error = $record->insert;
24 $error = $new_record->replace($old_record);
26 $error = $record->delete;
28 $error = $record->check;
32 An FS::access_user object represents an internal access user. FS::access_user inherits from
33 FS::Record. The following fields are currently supported:
37 =item usernum - primary key
55 Creates a new internal access user. To add the user to the database, see L<"insert">.
57 Note that this stores the hash reference, not a distinct copy of the hash it
58 points to. You can ask the object for a copy with the I<hash> method.
62 # the new method can be inherited from FS::Record, if a table method is defined
64 sub table { 'access_user'; }
68 Adds this record to the database. If there is an error, returns the error,
69 otherwise returns false.
73 # the insert method can be inherited from FS::Record
77 Delete this record from the database.
81 # the delete method can be inherited from FS::Record
83 =item replace OLD_RECORD
85 Replaces the OLD_RECORD with this one in the database. If there is an error,
86 returns the error, otherwise returns false.
90 # the replace method can be inherited from FS::Record
94 Checks all fields to make sure this is a valid internal access user. If there is
95 an error, returns the error, otherwise returns false. Called by the insert
100 # the check method should currently be supplied - FS::Record contains some
101 # data checking routines
107 $self->ut_numbern('usernum')
108 || $self->ut_text('username')
109 || $self->ut_text('_password')
110 || $self->ut_text('last')
111 || $self->ut_text('first')
113 return $error if $error;
120 Returns a name string for this user: "Last, First".
126 $self->get('last'). ', '. $self->first;
129 =item access_usergroup
133 sub access_usergroup {
135 qsearch( 'access_usergroup', { 'usernum' => $self->usernum } );
146 #=item access_groupnames
150 #sub access_groupnames {
156 Returns a list of agentnums this user can view (via group membership).
162 my $sth = dbh->prepare(
163 "SELECT DISTINCT agentnum FROM access_usergroup
164 JOIN access_groupagent USING ( groupnum )
166 ) or die dbh->errstr;
167 $sth->execute($self->usernum) or die $sth->errstr;
168 map { $_->[0] } @{ $sth->fetchall_arrayref };
173 Returns a hashref of agentnums this user can view.
179 { map { $_ => 1 } $self->agentnums };
184 Returns an sql fragement to select only agentnums this user can view.
191 join( ' OR ', map "agentnum = $_", $self->agentnums ).
197 Given a right name, returns true if this user has this right (currently via
198 group membership, eventually also via user overrides).
203 my( $self, $rightname ) = @_;
204 my $sth = dbh->prepare("
205 SELECT groupnum FROM access_usergroup
206 LEFT JOIN access_group USING ( groupnum )
207 LEFT JOIN access_right
208 ON ( access_group.groupnum = access_right.rightobjnum )
210 AND righttype = 'FS::access_group'
212 ") or die dbh->errstr;
213 $sth->execute($self->usernum, $rightname) or die $sth->errstr;
214 my $row = $sth->fetchrow_arrayref;
215 $row ? $row->[0] : '';
224 L<FS::Record>, schema.html from the base documentation.