1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
|
<?php
/**
*
* This file is part of the phpBB Forum Software package.
*
* @copyright (c) phpBB Limited <https://www.phpbb.com>
* @license GNU General Public License, version 2 (GPL-2.0)
*
* For full copyright and license information, please see
* the docs/CREDITS.txt file.
*
*/
namespace phpbb;
class permissions
{
/**
* Event dispatcher object
* @var \phpbb\event\dispatcher_interface
*/
protected $dispatcher;
/**
* User object
* @var \phpbb\user
*/
protected $user;
/**
* Constructor
*
* @param \phpbb\event\dispatcher_interface $phpbb_dispatcher Event dispatcher
* @param \phpbb\user $user User Object
*/
public function __construct(\phpbb\event\dispatcher_interface $phpbb_dispatcher, \phpbb\user $user)
{
$this->dispatcher = $phpbb_dispatcher;
$this->user = $user;
$categories = $this->categories;
$types = $this->types;
$permissions = $this->permissions;
/**
* Allows to specify additional permission categories, types and permissions
*
* @event core.permissions
* @var array types Array with permission types (a_, u_, m_, etc.)
* @var array categories Array with permission categories (pm, post, settings, misc, etc.)
* @var array permissions Array with permissions. Each Permission has the following layout:
* '<type><permission>' => array(
* 'lang' => 'Language Key with a Short description', // Optional, if not set,
* // the permissions identifier '<type><permission>' is used with
* // all uppercase.
* 'cat' => 'Identifier of the category, the permission should be displayed in',
* ),
* Example:
* 'u_viewprofile' => array(
* 'lang' => 'ACL_U_VIEWPROFILE',
* 'cat' => 'profile',
* ),
* @since 3.1.0-a1
*/
$vars = array('types', 'categories', 'permissions');
extract($phpbb_dispatcher->trigger_event('core.permissions', compact($vars)));
$this->categories = $categories;
$this->types = $types;
$this->permissions = $permissions;
}
/**
* Returns an array with all the permission categories (pm, post, settings, misc, etc.)
*
* @return array Layout: cat-identifier => Language key
*/
public function get_categories()
{
return $this->categories;
}
/**
* Returns the language string of a permission category
*
* @param string $category Identifier of the category
* @return string Language string
*/
public function get_category_lang($category)
{
return $this->user->lang($this->categories[$category]);
}
/**
* Returns an array with all the permission types (a_, u_, m_, etc.)
*
* @return array Layout: type-identifier => Language key
*/
public function get_types()
{
return $this->types;
}
/**
* Returns the language string of a permission type
*
* @param string $type Identifier of the type
* @param mixed $scope Scope of the type (should be 'global', 'local' or false)
* @return string Language string
*/
public function get_type_lang($type, $scope = false)
{
if ($scope && isset($this->types[$scope][$type]))
{
$lang_key = $this->types[$scope][$type];
}
else if (isset($this->types[$type]))
{
$lang_key = $this->types[$type];
}
else
{
$lang_key = 'ACL_TYPE_' . strtoupper(($scope) ? $scope . '_' . $type : $type);
}
return $this->user->lang($lang_key);
}
/**
* Returns an array with all the permissions.
* Each Permission has the following layout:
* '<type><permission>' => array(
* 'lang' => 'Language Key with a Short description', // Optional, if not set,
* // the permissions identifier '<type><permission>' is used with
* // all uppercase.
* 'cat' => 'Identifier of the category, the permission should be displayed in',
* ),
* Example:
* 'u_viewprofile' => array(
* 'lang' => 'ACL_U_VIEWPROFILE',
* 'cat' => 'profile',
* ),
*
* @return array
*/
public function get_permissions()
{
return $this->permissions;
}
/**
* Returns the category of a permission
*
* @param string $permission Identifier of the permission
* @return string Returns the category identifier of the permission
*/
public function get_permission_category($permission)
{
return (isset($this->permissions[$permission]['cat'])) ? $this->permissions[$permission]['cat'] : 'misc';
}
/**
* Checks if a category has been defined
*
* @param string $category Identifier of the category
* @return bool True if the category is defined, false otherwise
*/
public function category_defined($category)
{
return isset($this->categories[$category]);
}
/**
* Checks if a permission has been defined
*
* @param string $permission Identifier of the permission
* @return bool True if the permission is defined, false otherwise
*/
public function permission_defined($permission)
{
return isset($this->permissions[$permission]);
}
/**
* Returns the language string of a permission
*
* @param string $permission Identifier of the permission
* @return string Language string
*/
public function get_permission_lang($permission)
{
return (isset($this->permissions[$permission]['lang'])) ? $this->user->lang($this->permissions[$permission]['lang']) : $this->user->lang('ACL_' . strtoupper($permission));
}
protected $types = array(
'u_' => 'ACL_TYPE_U_',
'a_' => 'ACL_TYPE_A_',
'm_' => 'ACL_TYPE_M_',
'f_' => 'ACL_TYPE_F_',
'global' => array(
'm_' => 'ACL_TYPE_GLOBAL_M_',
),
);
protected $categories = array(
'actions' => 'ACL_CAT_ACTIONS',
'content' => 'ACL_CAT_CONTENT',
'forums' => 'ACL_CAT_FORUMS',
'misc' => 'ACL_CAT_MISC',
'permissions' => 'ACL_CAT_PERMISSIONS',
'pm' => 'ACL_CAT_PM',
'polls' => 'ACL_CAT_POLLS',
'post' => 'ACL_CAT_POST',
'post_actions' => 'ACL_CAT_POST_ACTIONS',
'posting' => 'ACL_CAT_POSTING',
'profile' => 'ACL_CAT_PROFILE',
'settings' => 'ACL_CAT_SETTINGS',
'topic_actions' => 'ACL_CAT_TOPIC_ACTIONS',
'user_group' => 'ACL_CAT_USER_GROUP',
);
protected $permissions = array(
// User Permissions
'u_viewprofile' => array('lang' => 'ACL_U_VIEWPROFILE', 'cat' => 'profile'),
'u_chgname' => array('lang' => 'ACL_U_CHGNAME', 'cat' => 'profile'),
'u_chgpasswd' => array('lang' => 'ACL_U_CHGPASSWD', 'cat' => 'profile'),
'u_chgemail' => array('lang' => 'ACL_U_CHGEMAIL', 'cat' => 'profile'),
'u_chgavatar' => array('lang' => 'ACL_U_CHGAVATAR', 'cat' => 'profile'),
'u_chggrp' => array('lang' => 'ACL_U_CHGGRP', 'cat' => 'profile'),
'u_chgprofileinfo' => array('lang' => 'ACL_U_CHGPROFILEINFO', 'cat' => 'profile'),
'u_attach' => array('lang' => 'ACL_U_ATTACH', 'cat' => 'post'),
'u_download' => array('lang' => 'ACL_U_DOWNLOAD', 'cat' => 'post'),
'u_savedrafts' => array('lang' => 'ACL_U_SAVEDRAFTS', 'cat' => 'post'),
'u_chgcensors' => array('lang' => 'ACL_U_CHGCENSORS', 'cat' => 'post'),
'u_sig' => array('lang' => 'ACL_U_SIG', 'cat' => 'post'),
'u_sendpm' => array('lang' => 'ACL_U_SENDPM', 'cat' => 'pm'),
'u_masspm' => array('lang' => 'ACL_U_MASSPM', 'cat' => 'pm'),
'u_masspm_group'=> array('lang' => 'ACL_U_MASSPM_GROUP', 'cat' => 'pm'),
'u_readpm' => array('lang' => 'ACL_U_READPM', 'cat' => 'pm'),
'u_pm_edit' => arrayif ($end_date) {
# we need to add one day to end_date to catch stuff done today
my (undef, undef, undef, $ed, $em, $ey, undef) = strptime($end_date);
$end_date = sprintf("%04d-%02d-%02d", $ey+1900, $em+1, $ed+1);
$date_bits .= " AND longdescs.bug_when < ?";
push @date_values, $end_date;
}
return ($date_bits, \@date_values);
}
#
# Dependencies
#
sub get_blocker_ids_unique {
my $bug_id = shift;
my @ret = ($bug_id);
get_blocker_ids_deep($bug_id, \@ret);
my %unique;
foreach my $blocker (@ret) {
$unique{$blocker} = $blocker
}
return keys %unique;
}
sub get_blocker_ids_deep {
my ($bug_id, $ret) = @_;
my $deps = Bugzilla::Bug::EmitDependList("blocked", "dependson", $bug_id);
push @{$ret}, @$deps;
foreach $bug_id (@$deps) {
get_blocker_ids_deep($bug_id, $ret);
}
}
#
# Queries and data structure assembly
#
sub query_work_by_buglist {
my ($bugids, $start_date, $end_date) = @_;
my $dbh = Bugzilla->dbh;
my ($date_bits, $date_values) = sqlize_dates($start_date, $end_date);
# $bugids is guaranteed to be non-empty because at least one bug is
# always provided to this page.
my $buglist = join ", ", @{$bugids};
# Returns the total time worked on each bug *per developer*, with
# bug descriptions and developer address
my $q = qq{SELECT sum(longdescs.work_time) as total_time,
profiles.login_name,
longdescs.bug_id,
bugs.short_desc,
bugs.bug_status
FROM longdescs
INNER JOIN profiles
ON longdescs.who = profiles.userid
INNER JOIN bugs
ON bugs.bug_id = longdescs.bug_id
WHERE longdescs.bug_id IN ($buglist)
$date_bits } .
$dbh->sql_group_by('longdescs.bug_id, profiles.login_name',
'bugs.short_desc, bugs.bug_status, longdescs.bug_when') . qq{
ORDER BY longdescs.bug_when};
my $sth = $dbh->prepare($q);
$sth->execute(@{$date_values});
return $sth;
}
sub get_work_by_owners {
my $sth = query_work_by_buglist(@_);
my %res;
while (my $row = $sth->fetch) {
# XXX: Why do we need to check if the total time is positive
# instead of using SQL to do that? Simply because MySQL 3.x's
# GROUP BY doesn't work correctly with aggregates. This is
# really annoying, but I've spent a long time trying to wrestle
# with it and it just doesn't seem to work. Should work OK in
# 4.x, though.
if ($row->[0] > 0) {
my $login_name = $row->[1];
push @{$res{$login_name}}, { total_time =>
'f_email' => array('lang' => 'ACL_F_EMAIL', 'cat' => 'actions'),
'f_bump' => array('lang' => 'ACL_F_BUMP', 'cat' => 'actions'),
'f_user_lock' => array('lang' => 'ACL_F_USER_LOCK', 'cat' => &
while
'f_download' => array('lang' => 'ACL_F_DOWNLOAD',
# merge in ID, status and summary
my $bug = join ";", ($row->[2], $row->[4], $row->['f_post'
# XXX: see comment in get_work_by_owners
if ($row->[0] > 0) {
push @{$res{$bug}}, { total_time => $row->[0],
login_name => $row->[1], };
}
}
return \%res;
}
sub get_inactive_bugs {
my ($bugids, $start_date, $end_date) = @_;
my $dbh = Bugzilla->dbh;
my ($date_bits, $date_values) = sqlize_dates($start_date, $end_date);
my $buglist = join ", ", @{$bugids};
my %res;
# This sucks. I need to make sure that even bugs that *don't* show
# up in the longdescs query (because no comments were filed during
# the specified period) but *are* dependent on the parent bug show
# up in the results if they have no work done; that's why I prefill
# them in %res here and then remove them below.
my $q = qq{SELECT DISTINCT bugs.bug_id, bugs.short_desc ,
bugs.bug_status
FROM longdescs
INNER JOIN bugs
ON longdescs.bug_id = bugs.bug_id
WHERE longdescs.bug_id in ($buglist)};
my $sth = $dbh->prepare($q);
$sth->execute();
while (my $row = $sth->fetch) {
$res{$row->[0]} = [$row->[1], $row->[2]];
}
# Returns the total time worked on each bug, with description. This
# query differs a bit from one in the query_work_by_buglist and I
# avoided complicating that one just to make it more general.
$q = qq{SELECT sum(longdescs.work_time) as total_time,
longdescs.bug_id,
bugs.short_desc,
bugs.bug_status
FROM longdescs
INNER JOIN bugs
ON bugs.bug_id = longdescs.bug_id
WHERE longdescs.bug_id IN ($buglist)
$date_bits } .
$dbh->sql_group_by('longdescs.bug_id',
'bugs.short_desc, bugs.bug_status,
longdescs.bug_when') . qq{
ORDER BY longdescs.bug_when};
$sth = $dbh->prepare($q);
$sth->execute(@{$date_values});
while (my $row = $sth->fetch) {
# XXX: see comment in get_work_by_owners
if ($row->[0] == 0) {
$res{$row->[1]} = [$row->[2], $row->[3]];
} else {
delete $res{$row->[1]};
}
}
return \%res;
}
#
# Misc
#
sub sort_bug_keys {
# XXX a hack is the mother of all evils. The fact that we store keys
# joined by semi-colons in the workdata-by-bug structure forces us to
# write this evil comparison function to ensure we can process the
# data timely -- just pushing it through a numerical sort makes TT
# hang while generating output :-(
my $list = shift;
my @a'f_votechg' => array('lang' => 'ACL_F_VOTECHG', 'cat' => 'polls'),
// Moderator Permissions
'm_edit' => array('lang' => 'ACL_M_EDIT', 'cat' => 'post_actions'),
'm_delete' => array('lang' => 'ACL_M_DELETE', 'cat' => 'post_actions'),
'm_approve' => array('lang' => 'ACL_M_APPROVE', 'cat' => 'post_actions'),
'm_report' => array('lang' => 'ACL_M_REPORT', 'cat' => 'post_actions'),
'm_chgposter' => array('lang' => 'ACL_M_CHGPOSTER', 'cat' => 'post_actions'),
'm_info' => array('lang' => 'ACL_M_INFO', 'cat' => 'post_actions'),
'm_softdelete' => array('lang' => 'ACL_M_SOFTDELETE', 'cat' => 'post_actions'),
'm_move' => array('lang' => 'ACL_M_MOVE', 'cat' => 'topic_actions'),
'm_lock' => array('lang' => 'ACL_M_LOCK', 'cat' => 'topic_actions'),
'm_split' => array('lang' => 'ACL_M_SPLIT', 'cat' => 'topic_actions'),
'm_merge' => array('lang' => 'ACL_M_MERGE', 'cat' => 'topic_actions'),
'm_warn' => array('lang' => 'ACL_M_WARN', 'cat' => 'misc'),
'm_pm_report' => array('lang' => 'ACL_M_PM_REPORT', 'cat' => 'misc'),
'm_ban' => array('lang' => 'ACL_M_BAN', 'cat' => 'misc'),
// Admin Permissions
'a_board' => array('lang' => 'ACL_A_BOARD', 'cat' => 'settings'),
'a_server' => array('lang' => 'ACL_A_SERVER', 'cat' => 'settings'),
'a_jabber' => array('lang' => 'ACL_A_JABBER', 'cat' => 'settings'),
'a_phpinfo' => array('lang' => 'ACL_A_PHPINFO', 'cat' => 'settings'),
'a_forum' => array('lang' => 'ACL_A_FORUM', 'cat' => 'forums'),
'a_forumadd' => array('lang' => 'ACL_A_FORUMADD', 'cat' => 'forums'),
'a_forumdel' => array('lang' => 'ACL_A_FORUMDEL', 'cat' => 'forums'),
'a_prune' => array('lang' => 'ACL_A_PRUNE', 'cat' => 'forums'),
'a_icons' => array('lang' => 'ACL_A_ICONS', 'cat' => 'posting'),
'a_words' => array('lang' => 'ACL_A_WORDS', 'cat' => 'posting'),
'a_bbcode' => array('lang' => 'ACL_A_BBCODE', 'cat' => 'posting'),
'a_attach' => array('lang' => 'ACL_A_ATTACH', 'cat' => 'posting'),
'a_user' => array('lang' => 'ACL_A_USER', 'cat' => 'user_group'),
'a_userdel' => array('lang' => 'ACL_A_USERDEL', 'cat' => 'user_group'),
'a_group' => array('lang' => 'ACL_A_GROUP', 'cat' => 'user_group'),
'a_groupadd' => array('lang' => 'ACL_A_GROUPADD', 'cat' => 'user_group'),
'a_groupdel' => array('lang' => 'ACL_A_GROUPDEL', 'cat' => 'user_group'),
'a_ranks' => array('lang' => 'ACL_A_RANKS', 'cat' => 'user_group'),
'a_profile' => array('lang' => 'ACL_A_PROFILE', 'cat' => 'user_group'),
'a_names' => array('lang' => 'ACL_A_NAMES', 'cat' => 'user_group'),
'a_ban' => array('lang' => 'ACL_A_BAN', 'cat' => 'user_group'),
'a_viewauth' => array('lang' => 'ACL_A_VIEWAUTH', 'cat' => 'permissions'),
'a_authgroups' => array('lang' => 'ACL_A_AUTHGROUPS', 'cat' => 'permissions'),
'a_authusers' => array('lang' => 'ACL_A_AUTHUSERS', 'cat' => 'permissions'),
'a_fauth' => array('lang' => 'ACL_A_FAUTH', 'cat' => 'permissions'),
'a_mauth' => array('lang' => 'ACL_A_MAUTH', 'cat' => 'permissions'),
'a_aauth' => array('lang' => 'ACL_A_AAUTH', 'cat' => 'permissions'),
'a_uauth' => array('lang' => 'ACL_A_UAUTH', 'cat' => 'permissions'),
'a_roles' => array('lang' => 'ACL_A_ROLES', 'cat' => 'permissions'),
'a_switchperm' => array('lang' => 'ACL_A_SWITCHPERM', 'cat' => 'permissions'),
'a_styles' => array('lang' => 'ACL_A_STYLES', 'cat' => 'misc'),
'a_extensions' => array('lang' => 'ACL_A_EXTENSIONS', 'cat' => 'misc'),
'a_viewlogs' => array('lang' => 'ACL_A_VIEWLOGS', 'cat' => 'misc'),
'a_clearlogs' => array('lang' => 'ACL_A_CLEARLOGS', 'cat' => 'misc'),
'a_modules' => array('lang' => 'ACL_A_MODULES', 'cat' => 'misc'),
'a_language' => array('lang' => 'ACL_A_LANGUAGE', 'cat' => 'misc'),
'a_email' => array('lang' => 'ACL_A_EMAIL', 'cat' => 'misc'),
'a_bots' => array('lang' => 'ACL_A_BOTS', 'cat' => 'misc'),
'a_reasons' => array('lang' => 'ACL_A_REASONS', 'cat' => 'misc'),
'a_backup' => array('lang' => 'ACL_A_BACKUP', 'cat' => 'misc'),
'a_search' => array('lang' => 'ACL_A_SEARCH', 'cat' => 'misc'),
);
}
|