1 package FS::svc_Radius_Mixin;
4 use base qw(FS::m2m_Common FS::svc_Common);
5 use FS::Record qw(qsearch);
7 use FS::radius_usergroup;
12 FS::svc_Radius_Mixin - partial base class for services with RADIUS groups
19 $self->SUPER::insert(@_)
20 || $self->process_m2m(
21 'link_table' => 'radius_usergroup',
22 'target_table' => 'radius_group',
23 'params' => $self->usergroup,
30 $old = $new->replace_old if !defined($old);
32 $old->usergroup; # make sure this is cached for exports
34 'link_table' => 'radius_usergroup',
35 'target_table' => 'radius_group',
36 'params' => $new->usergroup,
37 ) || $new->SUPER::replace($old, @_);
42 $self->SUPER::delete(@_)
43 || $self->process_m2m(
44 'link_table' => 'radius_usergroup',
45 'target_table' => 'radius_group',
53 if ( defined $value ) {
55 return $self->set('usergroup', $value);
58 return $self->set('usergroup', [ split(/\s*,\s*/, $value) ]);
61 $self->get('usergroup') ||
62 # if no argument is passed and usergroup is not set already,
63 # fetch this service's group assignments
64 $self->set('usergroup',
65 [ map { $_->groupnum }
66 qsearch('radius_usergroup', { svcnum => $self->svcnum }) ]
72 'usergroup' => \&usergroup
76 =item radius_groups METHOD
78 Returns a list of RADIUS groups for this service (see L<FS::radius_usergroup>).
79 METHOD is the field to return, and can be any method on L<FS::radius_group>.
80 Useful values for METHOD include 'groupnum', 'groupname', and
81 'long_description'. Defaults to 'groupname' for historical reasons.
87 my $method = shift || 'groupname';
88 my $groups = join(',', @{$self->usergroup}) || return ();
89 my @groups = qsearch({'table' => 'radius_group',
90 'extra_sql' => "where groupnum in ($groups)"});
91 return map {$_->$method} @groups;