Revision 3734c21e
Von Sven Schöling vor etwa 15 Jahren hinzugefügt
bin/mozilla/admin_groups.pl | ||
---|---|---|
34 | 34 |
|
35 | 35 |
use List::MoreUtils qw(uniq); |
36 | 36 |
|
37 |
use strict; |
|
38 |
|
|
37 | 39 |
sub edit_groups { |
38 |
$lxdebug->enter_sub(); |
|
40 |
$main::lxdebug->enter_sub(); |
|
41 |
|
|
42 |
my $form = $main::form; |
|
39 | 43 |
|
40 |
my @groups = sort { lc $a->{name} cmp lc $b->{name} } values %{ $auth->read_groups() }; |
|
44 |
my @groups = sort { lc $a->{name} cmp lc $b->{name} } values %{ $main::auth->read_groups() };
|
|
41 | 45 |
|
42 | 46 |
$form->header(); |
43 | 47 |
print $form->parse_html_template("admin/edit_groups", { 'GROUPS' => \@groups, |
44 | 48 |
'num_groups' => scalar @groups }); |
45 | 49 |
|
46 |
$lxdebug->leave_sub(); |
|
50 |
$main::lxdebug->leave_sub();
|
|
47 | 51 |
} |
48 | 52 |
|
49 | 53 |
sub add_group { |
50 |
$lxdebug->enter_sub(); |
|
54 |
$main::lxdebug->enter_sub(); |
|
55 |
|
|
56 |
my $form = $main::form; |
|
57 |
my $locale = $main::locale; |
|
51 | 58 |
|
52 | 59 |
delete $form->{group_id}; |
53 | 60 |
$form->{message} = $locale->text("The group has been added."); |
54 | 61 |
|
55 | 62 |
save_group(); |
56 | 63 |
|
57 |
$lxdebug->leave_sub(); |
|
64 |
$main::lxdebug->leave_sub();
|
|
58 | 65 |
} |
59 | 66 |
|
60 | 67 |
sub save_group { |
61 |
$lxdebug->enter_sub(); |
|
68 |
$main::lxdebug->enter_sub(); |
|
69 |
|
|
70 |
my $form = $main::form; |
|
71 |
my $locale = $main::locale; |
|
62 | 72 |
|
63 | 73 |
$form->isblank('name', $locale->text('The group name is missing.')); |
64 | 74 |
|
65 |
my $groups = $auth->read_groups(); |
|
75 |
my $groups = $main::auth->read_groups();
|
|
66 | 76 |
|
67 | 77 |
foreach my $group (values %{$groups}) { |
68 | 78 |
if (($form->{group_id} != $group->{id}) |
... | ... | |
88 | 98 |
|
89 | 99 |
my $is_new = !$form->{group_id}; |
90 | 100 |
|
91 |
$auth->save_group($group); |
|
101 |
$main::auth->save_group($group);
|
|
92 | 102 |
|
93 | 103 |
$form->{message} ||= $locale->text('The group has been saved.'); |
94 | 104 |
|
... | ... | |
99 | 109 |
edit_group(); |
100 | 110 |
} |
101 | 111 |
|
102 |
$lxdebug->leave_sub(); |
|
112 |
$main::lxdebug->leave_sub();
|
|
103 | 113 |
} |
104 | 114 |
|
105 | 115 |
sub edit_group { |
106 |
$lxdebug->enter_sub(); |
|
116 |
$main::lxdebug->enter_sub(); |
|
117 |
|
|
118 |
my $form = $main::form; |
|
119 |
my $locale = $main::locale; |
|
107 | 120 |
|
108 |
my $groups = $auth->read_groups(); |
|
121 |
my $groups = $main::auth->read_groups();
|
|
109 | 122 |
|
110 | 123 |
if (!$form->{group_id} || !$groups->{$form->{group_id}}) { |
111 | 124 |
$form->show_generic_error($locale->text("No group has been selected, or the group does not exist anymore.")); |
112 | 125 |
} |
113 | 126 |
|
114 |
$group = $groups->{$form->{group_id}}; |
|
127 |
my $group = $groups->{$form->{group_id}};
|
|
115 | 128 |
|
116 |
my %all_users = $auth->read_all_users(); |
|
129 |
my %all_users = $main::auth->read_all_users();
|
|
117 | 130 |
my %users_by_id = map { $_->{id} => $_ } values %all_users; |
118 | 131 |
|
119 | 132 |
my @members = uniq sort { lc $a->{login} cmp lc $b->{login} } @users_by_id{ @{ $group->{members} } }; |
... | ... | |
136 | 149 |
"name" => $group->{name}, |
137 | 150 |
"description" => $group->{description} }); |
138 | 151 |
|
139 |
$lxdebug->leave_sub(); |
|
152 |
$main::lxdebug->leave_sub();
|
|
140 | 153 |
} |
141 | 154 |
|
142 | 155 |
sub delete_group { |
143 |
$lxdebug->enter_sub(); |
|
156 |
$main::lxdebug->enter_sub();
|
|
144 | 157 |
|
145 |
my $groups = $auth->read_groups(); |
|
158 |
my $form = $main::form; |
|
159 |
my $locale = $main::locale; |
|
160 |
|
|
161 |
my $groups = $main::auth->read_groups(); |
|
146 | 162 |
|
147 | 163 |
if (!$form->{group_id} || !$groups->{$form->{group_id}}) { |
148 | 164 |
$form->show_generic_error($locale->text("No group has been selected, or the group does not exist anymore.")); |
149 | 165 |
} |
150 | 166 |
|
151 | 167 |
if ($form->{confirmed}) { |
152 |
$auth->delete_group($form->{"group_id"}); |
|
168 |
$main::auth->delete_group($form->{"group_id"});
|
|
153 | 169 |
|
154 | 170 |
$form->{message} = $locale->text("The group has been deleted."); |
155 | 171 |
edit_groups(); |
... | ... | |
160 | 176 |
print $form->parse_html_template("admin/delete_group_confirm", $groups->{$form->{group_id}}); |
161 | 177 |
} |
162 | 178 |
|
163 |
$lxdebug->leave_sub(); |
|
179 |
$main::lxdebug->leave_sub();
|
|
164 | 180 |
} |
165 | 181 |
|
166 | 182 |
sub add_to_group { |
167 |
$lxdebug->enter_sub(); |
|
183 |
$main::lxdebug->enter_sub(); |
|
184 |
|
|
185 |
my $form = $main::form; |
|
186 |
my $locale = $main::locale; |
|
168 | 187 |
|
169 | 188 |
$form->isblank('user_id_not_in_group', $locale->text('No user has been selected.')); |
170 | 189 |
|
171 |
my $groups = $auth->read_groups(); |
|
190 |
my $groups = $main::auth->read_groups();
|
|
172 | 191 |
|
173 | 192 |
if (!$form->{group_id} || !$groups->{$form->{group_id}}) { |
174 | 193 |
$form->show_generic_error($locale->text('No group has been selected, or the group does not exist anymore.')); |
175 | 194 |
} |
176 | 195 |
|
177 |
$group = $groups->{$form->{group_id}}; |
|
196 |
my $group = $groups->{$form->{group_id}};
|
|
178 | 197 |
$group->{members} = [ uniq @{ $group->{members} }, $form->{user_id_not_in_group} ]; |
179 | 198 |
|
180 |
$auth->save_group($group); |
|
199 |
$main::auth->save_group($group);
|
|
181 | 200 |
|
182 | 201 |
$form->{message} = $locale->text('The user has been added to this group.'); |
183 | 202 |
edit_group(); |
184 | 203 |
|
185 |
$lxdebug->leave_sub(); |
|
204 |
$main::lxdebug->leave_sub();
|
|
186 | 205 |
} |
187 | 206 |
|
188 | 207 |
sub remove_from_group { |
189 |
$lxdebug->enter_sub(); |
|
208 |
$main::lxdebug->enter_sub(); |
|
209 |
|
|
210 |
my $form = $main::form; |
|
211 |
my $locale = $main::locale; |
|
190 | 212 |
|
191 | 213 |
$form->isblank('user_id_in_group', $locale->text('No user has been selected.')); |
192 | 214 |
|
193 |
my $groups = $auth->read_groups(); |
|
215 |
my $groups = $main::auth->read_groups();
|
|
194 | 216 |
|
195 | 217 |
if (!$form->{group_id} || !$groups->{$form->{group_id}}) { |
196 | 218 |
$form->show_generic_error($locale->text('No group has been selected, or the group does not exist anymore.')); |
197 | 219 |
} |
198 | 220 |
|
199 |
$group = $groups->{$form->{group_id}}; |
|
221 |
my $group = $groups->{$form->{group_id}};
|
|
200 | 222 |
$group->{members} = [ uniq grep { $_ ne $form->{user_id_in_group} } @{ $group->{members} } ]; |
201 | 223 |
|
202 |
$auth->save_group($group); |
|
224 |
$main::auth->save_group($group);
|
|
203 | 225 |
|
204 | 226 |
$form->{message} = $locale->text('The user has been removed from this group.'); |
205 | 227 |
edit_group(); |
206 | 228 |
|
207 |
$lxdebug->leave_sub(); |
|
229 |
$main::lxdebug->leave_sub();
|
|
208 | 230 |
} |
209 | 231 |
|
210 | 232 |
sub edit_group_membership { |
211 |
$lxdebug->enter_sub(); |
|
233 |
$main::lxdebug->enter_sub();
|
|
212 | 234 |
|
213 |
my %users = $auth->read_all_users(); |
|
214 |
my $groups = $auth->read_groups(); |
|
235 |
my $form = $main::form; |
|
236 |
my $locale = $main::locale; |
|
237 |
|
|
238 |
my %users = $main::auth->read_all_users(); |
|
239 |
my $groups = $main::auth->read_groups(); |
|
215 | 240 |
$groups = [ sort { lc $a->{name} cmp lc $b->{name} } values %{ $groups } ]; |
216 | 241 |
|
217 | 242 |
my @headings = map { { 'title' => $_ } } map { $_->{name} } @{ $groups }; |
... | ... | |
245 | 270 |
$form->header(); |
246 | 271 |
print $form->parse_html_template('admin/edit_group_membership', { 'HEADINGS' => \@headings, 'USERS' => \@rows }); |
247 | 272 |
|
248 |
$lxdebug->leave_sub(); |
|
273 |
$main::lxdebug->leave_sub();
|
|
249 | 274 |
} |
250 | 275 |
|
251 | 276 |
sub save_group_membership { |
252 |
$lxdebug->enter_sub(); |
|
277 |
$main::lxdebug->enter_sub(); |
|
278 |
|
|
279 |
my $form = $main::form; |
|
280 |
my $locale = $main::locale; |
|
253 | 281 |
|
254 |
my %users = $auth->read_all_users(); |
|
255 |
my $groups = $auth->read_groups(); |
|
282 |
my %users = $main::auth->read_all_users();
|
|
283 |
my $groups = $main::auth->read_groups();
|
|
256 | 284 |
|
257 | 285 |
foreach my $group (values %{ $groups }) { |
258 | 286 |
$group->{members} = [ ]; |
... | ... | |
261 | 289 |
push @{ $group->{members} }, $user->{id} if ($form->{"u_$user->{id}_g_$group->{id}"}); |
262 | 290 |
} |
263 | 291 |
|
264 |
$auth->save_group($group); |
|
292 |
$main::auth->save_group($group);
|
|
265 | 293 |
} |
266 | 294 |
|
267 | 295 |
$form->{message} = $locale->text('The group memberships have been saved.'); |
268 | 296 |
|
269 | 297 |
edit_groups(); |
270 | 298 |
|
271 |
$lxdebug->leave_sub(); |
|
299 |
$main::lxdebug->leave_sub();
|
|
272 | 300 |
} |
273 | 301 |
|
274 | 302 |
1; |
Auch abrufbar als: Unified diff
admin_groups strict