X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=SL%2FDB%2FAuthGroup.pm;h=033178643262716556a9d7b92ff6f5f732a1f32c;hb=393cef65daf67853ed468b4778b7c738773d48f1;hp=8bd54506ca70fd844f7024a6d27b98266196cc33;hpb=a5ba22d29e683629d731fc0bfdfb72719e59a0b9;p=kivitendo-erp.git diff --git a/SL/DB/AuthGroup.pm b/SL/DB/AuthGroup.pm index 8bd54506c..033178643 100644 --- a/SL/DB/AuthGroup.pm +++ b/SL/DB/AuthGroup.pm @@ -1,17 +1,10 @@ -# This file has been auto-generated only because it didn't exist. -# Feel free to modify it at will; it will not be overwritten automatically. - package SL::DB::AuthGroup; use strict; use SL::DB::MetaSetup::AuthGroup; -use SL::DB::AuthGroupRight; - -# Creates get_all, get_all_count, get_all_iterator, delete_all and update_all. -__PACKAGE__->meta->make_manager_class; - -__PACKAGE__->meta->schema('auth'); +use SL::DB::Manager::AuthGroup; +use SL::DB::Helper::Util; __PACKAGE__->meta->add_relationship( users => { @@ -25,8 +18,100 @@ __PACKAGE__->meta->add_relationship( class => 'SL::DB::AuthGroupRight', column_map => { id => 'group_id' }, }, + clients => { + type => 'many to many', + map_class => 'SL::DB::AuthClientGroup', + map_from => 'group', + map_to => 'client', + }, ); __PACKAGE__->meta->initialize; +sub validate { + my ($self) = @_; + + my @errors; + push @errors, $::locale->text('The name is missing.') if !$self->name; + push @errors, $::locale->text('The name is not unique.') if !SL::DB::Helper::Util::is_unique($self, 'name'); + + return @errors; +} + +sub get_employees { + my @logins = map { $_->login } $_[0]->users; + return @logins ? @{ SL::DB::Manager::Employee->get_all(query => [ login => \@logins ]) } : (); +} + +sub rights_map { + my $self = shift; + + if (@_) { + my %new_rights = ref($_[0]) eq 'HASH' ? %{ $_[0] } : @_; + $self->rights([ map { SL::DB::AuthGroupRight->new(right => $_, granted => $new_rights{$_} ? 1 : 0) } $::auth->all_rights ]); + } + + return { + map({ ($_ => 0) } $::auth->all_rights), + map({ ($_->right => $_->granted) } @{ $self->rights || [] }) + }; +} + 1; +__END__ + +=pod + +=encoding utf8 + +=head1 NAME + +SL::DB::AuthGroup - RDBO model for auth.group + +=head1 SYNOPSIS + + # Outputting all rights granted to this group: + my $group = SL::DB::Manager::AuthGroup->get_first; + my %rights = %{ $group->rights_map }; + print "Granted rights:\n"; + print " $_\n" for sort grep { $rights{$_} } keys %rights; + + # Set a right to 'yes': + $group->rights_map(%{ $group->rights_map }, invoice_edit => 1); + $group->save; + +=head1 FUNCTIONS + +=over 4 + +=item C + +Returns all employees (as instances of L) whose +corresponding logins are members in this group. + +=item C + +Gets/sets the rights for this group as hashes. Returns a hash +references containing the right names as the keys and trueish/falsish +values for 'granted'/'not granted'. + +If C<$new_rights> is given as a hash reference or a plain hash then it +will also set all rights from this hash. + +=item C + +Validates the object before saving (checks uniqueness, attribute +presence etc). Returns a list of human-readable errors and an empty +list on success. + +=back + +=head1 BUGS + +Nothing here yet. + +=head1 AUTHOR + +Moritz Bunkus Em.bunkus@linet-services.deE + +=cut