1 package SL::DB::AuthGroup;
5 use SL::DB::MetaSetup::AuthGroup;
6 use SL::DB::Manager::AuthGroup;
7 use SL::DB::Helper::Util;
9 __PACKAGE__->meta->add_relationship(
11 type => 'many to many',
12 map_class => 'SL::DB::AuthUserGroup',
17 type => 'one to many',
18 class => 'SL::DB::AuthGroupRight',
19 column_map => { id => 'group_id' },
22 type => 'many to many',
23 map_class => 'SL::DB::AuthClientGroup',
29 __PACKAGE__->meta->initialize;
35 push @errors, $::locale->text('The name is missing.') if !$self->name;
36 push @errors, $::locale->text('The name is not unique.') if !SL::DB::Helper::Util::is_unique($self, 'name');
42 my @logins = map { $_->login } $_[0]->users;
43 return @logins ? @{ SL::DB::Manager::Employee->get_all(query => [ login => \@logins ]) } : ();
50 my %new_rights = ref($_[0]) eq 'HASH' ? %{ $_[0] } : @_;
51 $self->rights([ map { SL::DB::AuthGroupRight->new(right => $_, granted => $new_rights{$_} ? 1 : 0) } $::auth->all_rights ]);
55 map({ ($_ => 0) } $::auth->all_rights),
56 map({ ($_->right => $_->granted) } @{ $self->rights || [] })
69 SL::DB::AuthGroup - RDBO model for auth.group
73 # Outputting all rights granted to this group:
74 my $group = SL::DB::Manager::AuthGroup->get_first;
75 my %rights = %{ $group->rights_map };
76 print "Granted rights:\n";
77 print " $_\n" for sort grep { $rights{$_} } keys %rights;
79 # Set a right to 'yes':
80 $group->rights_map(%{ $group->rights_map }, invoice_edit => 1);
87 =item C<get_employees>
89 Returns all employees (as instances of L<SL::DB::Employee>) whose
90 corresponding logins are members in this group.
92 =item C<rights_map [$new_rights]>
94 Gets/sets the rights for this group as hashes. Returns a hash
95 references containing the right names as the keys and trueish/falsish
96 values for 'granted'/'not granted'.
98 If C<$new_rights> is given as a hash reference or a plain hash then it
99 will also set all rights from this hash.
103 Validates the object before saving (checks uniqueness, attribute
104 presence etc). Returns a list of human-readable errors and an empty
115 Moritz Bunkus E<lt>m.bunkus@linet-services.deE<gt>