Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 69df38d3

Von Moritz Bunkus vor mehr als 11 Jahren hinzugefügt

  • ID 69df38d39da1a1fcbf59ebc8f3ddd29a1f82ec29
  • Vorgänger 91d2ef32
  • Nachfolger c2692077

Gruppenverwaltung auf Controllermodel umgestellt

Dabei auch Verknüpfung Gruppen <-> Mandanten implementiert.

Unterschiede anzeigen:

SL/DB/AuthGroup.pm
4 4

  
5 5
use SL::DB::MetaSetup::AuthGroup;
6 6
use SL::DB::Manager::AuthGroup;
7
use SL::DB::AuthGroupRight;
7
use SL::DB::Helper::Util;
8 8

  
9 9
__PACKAGE__->meta->add_relationship(
10 10
  users => {
......
28 28

  
29 29
__PACKAGE__->meta->initialize;
30 30

  
31
sub validate {
32
  my ($self) = @_;
33

  
34
  my @errors;
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');
37

  
38
  return @errors;
39
}
40

  
31 41
sub get_employees {
32 42
  my @logins = map { $_->login } $_[0]->users;
33 43
  return @logins ? @{ SL::DB::Manager::Employee->get_all(query => [ login => \@logins ]) } : ();
34 44
}
35 45

  
46
sub rights_map {
47
  my $self = shift;
48

  
49
  if (@_) {
50
    my %new_rights = ref($_[0]) eq 'HASH' ? %{ $_[0] } : @_;
51
    $self->rights([ map { SL::DB::AuthGroupRight->new(right => $_, granted => $new_rights{$_} ? 1 : 0) } SL::Auth::all_rights() ]);
52
  }
53

  
54
  return {
55
    map({ ($_        => 0)           } SL::Auth::all_rights()),
56
    map({ ($_->right => $_->granted) } @{ $self->rights || [] })
57
  };
58
}
59

  
36 60
1;
61
__END__
62

  
63
=pod
64

  
65
=encoding utf8
66

  
67
=head1 NAME
68

  
69
SL::DB::AuthGroup - RDBO model for auth.group
70

  
71
=head1 SYNOPSIS
72

  
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;
78

  
79
  # Set a right to 'yes':
80
  $group->rights_map(%{ $group->rights_map }, invoice_edit => 1);
81
  $group->save;
82

  
83
=head1 FUNCTIONS
84

  
85
=over 4
86

  
87
=item C<get_employees>
88

  
89
Returns all employees (as instances of L<SL::DB::Employee>) whose
90
corresponding logins are members in this group.
91

  
92
=item C<rights_map [$new_rights]>
93

  
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'.
97

  
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.
100

  
101
=item C<validate>
102

  
103
Validates the object before saving (checks uniqueness, attribute
104
presence etc). Returns a list of human-readable errors and an empty
105
list on success.
106

  
107
=back
108

  
109
=head1 BUGS
110

  
111
Nothing here yet.
112

  
113
=head1 AUTHOR
114

  
115
Moritz Bunkus E<lt>m.bunkus@linet-services.deE<gt>
116

  
117
=cut

Auch abrufbar als: Unified diff